mirror of
https://github.com/logos-co/logos-cpp-sdk.git
synced 2026-09-02 02:31:14 +00:00
lidlTypeToQt mapped BOTH `int` and `uint` to plain `int`. Everywhere else in the stack a LIDL int/uint is 64-bit — int64_t/uint64_t in C++ impls, i64/u64 in the Rust SDK — so the Qt spelling broke the one-type-per-LIDL-type rule and lost data: a Qt consumer reading a `uint` return got a SIGNED 32-bit value, so anything above 2^31 came back wrong and anything above 2^63 was never expressible. int -> qlonglong, uint -> qulonglong, and returnConversion() gains the matching accessors (toLongLong / toULongLong instead of toInt). qlonglong/qulonglong rather than qint64/quint64 so the generated introspection JSON uses the same names Qt's own metaobject normalisation produces — otherwise a cdylib module's generated `signature` and a legacy module's QMetaObject-derived one would disagree for the same LIDL type. Nothing looks these strings up: the only QMetaType::fromName call in the stack is for "LogosResult". This changes two generated surfaces: the Qt consumer wrapper signatures and the introspection JSON. Passing an int argument still converts implicitly, so callers keep compiling; code that assigns a wrapper's return into an `int` narrows and may warn, which is the bug being surfaced rather than a regression. Tests: 168/168, with the type-mapping and client-emitter expectations updated to the 64-bit spelling. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
101 lines
3.8 KiB
C++
101 lines
3.8 KiB
C++
#include "lidl_emit_common.h"
|
|
|
|
QString lidlToPascalCase(const QString& name)
|
|
{
|
|
QString out;
|
|
bool cap = true;
|
|
for (QChar c : name) {
|
|
if (!c.isLetterOrNumber()) { cap = true; continue; }
|
|
if (cap) { out.append(c.toUpper()); cap = false; }
|
|
else { out.append(c.toLower()); }
|
|
}
|
|
if (out.isEmpty()) return QString("Module");
|
|
return out;
|
|
}
|
|
|
|
QString lidlTypeToQt(const TypeExpr& te)
|
|
{
|
|
switch (te.kind) {
|
|
case TypeExpr::Primitive:
|
|
if (te.name == "void") return "void";
|
|
if (te.name == "tstr") return "QString";
|
|
if (te.name == "bstr") return "QByteArray";
|
|
// 64-bit, and unsigned stays unsigned. LIDL int/uint are int64_t/uint64_t
|
|
// everywhere else (C++ impls, Rust's i64/u64), so spelling them `int`
|
|
// here broke the 1-1 mapping and truncated: a Qt consumer reading a
|
|
// `uint` return got a SIGNED 32-bit value. qlonglong/qulonglong rather
|
|
// than qint64/quint64 so the generated introspection matches the names
|
|
// Qt's own metaobject normalisation produces.
|
|
if (te.name == "int") return "qlonglong";
|
|
if (te.name == "uint") return "qulonglong";
|
|
if (te.name == "float64") return "double";
|
|
if (te.name == "bool") return "bool";
|
|
if (te.name == "result") return "LogosResult";
|
|
if (te.name == "any") return "QVariant";
|
|
return "QVariant";
|
|
case TypeExpr::Array:
|
|
if (te.elements.size() == 1
|
|
&& te.elements[0].kind == TypeExpr::Primitive
|
|
&& te.elements[0].name == "tstr") {
|
|
return "QStringList";
|
|
}
|
|
return "QVariantList";
|
|
case TypeExpr::Map:
|
|
return "QVariantMap";
|
|
case TypeExpr::Optional:
|
|
return "QVariant";
|
|
case TypeExpr::Named:
|
|
return "QVariant";
|
|
}
|
|
return "QVariant";
|
|
}
|
|
|
|
bool lidlIsStdConvertible(const TypeExpr& te)
|
|
{
|
|
if (te.kind == TypeExpr::Primitive) {
|
|
return te.name == "tstr" || te.name == "bstr"
|
|
|| te.name == "int" || te.name == "uint"
|
|
|| te.name == "float64" || te.name == "bool";
|
|
}
|
|
if (te.kind == TypeExpr::Array && te.elements.size() == 1) {
|
|
const TypeExpr& elem = te.elements[0];
|
|
if (elem.kind == TypeExpr::Primitive) {
|
|
return elem.name == "tstr" || elem.name == "bstr"
|
|
|| elem.name == "int" || elem.name == "uint"
|
|
|| elem.name == "float64" || elem.name == "bool";
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
QString lidlTypeToStd(const TypeExpr& te)
|
|
{
|
|
if (te.kind == TypeExpr::Primitive) {
|
|
if (te.name == "tstr") return "std::string";
|
|
if (te.name == "bstr") return "std::vector<uint8_t>";
|
|
if (te.name == "int") return "int64_t";
|
|
if (te.name == "uint") return "uint64_t";
|
|
if (te.name == "float64") return "double";
|
|
if (te.name == "bool") return "bool";
|
|
if (te.name == "result") return "LogosResult";
|
|
if (te.name == "any") return "QVariant";
|
|
return "QVariant";
|
|
}
|
|
if (te.kind == TypeExpr::Array && te.elements.size() == 1) {
|
|
const TypeExpr& elem = te.elements[0];
|
|
if (elem.kind == TypeExpr::Primitive) {
|
|
if (elem.name == "tstr") return "std::vector<std::string>";
|
|
if (elem.name == "bstr") return "std::vector<std::vector<uint8_t>>";
|
|
if (elem.name == "int") return "std::vector<int64_t>";
|
|
if (elem.name == "uint") return "std::vector<uint64_t>";
|
|
if (elem.name == "float64") return "std::vector<double>";
|
|
if (elem.name == "bool") return "std::vector<bool>";
|
|
}
|
|
return "QVariantList";
|
|
}
|
|
if (te.kind == TypeExpr::Map) return "QVariantMap";
|
|
if (te.kind == TypeExpr::Optional) return "QVariant";
|
|
if (te.kind == TypeExpr::Named) return "QVariant";
|
|
return "QVariant";
|
|
}
|