Revision control

- --- .upstream/generator.cpp 2023-07-06 09:09:24.454402160 +0200
- +++ generator.cpp 2023-08-22 14:06:36.819992506 +0200
+ --- .upstream/generator.cpp 2024-02-01 11:08:00.055494626 +0100
+ +++ generator.cpp 2024-02-05 14:18:32.229391845 +0100
@@ -4,7 +4,9 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "generator.h"
+#if 0 // -- QtScxml
#include "cbordevice.h"
+#endif // -- QtScxml
#include "outputrevision.h"
#include "utils.h"
#include <QtCore/qmetatype.h>
@@ -25,6 +27,29 @@
using namespace QtMiscUtils;
+// -- QtScxml
+void fprintf(QIODevice &out, const char *fmt, ...)
+{
+ va_list argp;
+ va_start(argp, fmt);
+ const int bufSize = 4096;
+ char buf[bufSize];
+ vsnprintf(buf, bufSize, fmt, argp);
+ va_end(argp);
+ out.write(buf);
+}
+
+void fputc(char c, QIODevice &out)
+{
+ out.write(&c, 1);
+}
+
+void fputs(const char *s, QIODevice &out)
+{
+ out.write(s);
+}
+// -- QtScxml
+
uint nameToBuiltinType(const QByteArray &name)
{
if (name.isEmpty())
@@ -57,22 +82,25 @@
return nullptr;
}
- Generator::Generator(Moc *moc, ClassDef *classDef, const QList<QByteArray> &metaTypes,
- const QHash<QByteArray, QByteArray> &knownQObjectClasses,
- const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile,
- bool requireCompleteTypes)
- : parser(moc),
- out(outfile),
- cdef(classDef),
- metaTypes(metaTypes),
- knownQObjectClasses(knownQObjectClasses),
- knownGadgets(knownGadgets),
- requireCompleteTypes(requireCompleteTypes)
- {
- if (cdef->superclassList.size())
- - purestSuperClass = cdef->superclassList.constFirst().first;
+ - purestSuperClass = cdef->superclassList.constFirst().classname;
+// -- QtScxml
+Generator::Generator(ClassDef *classDef, const QList<QByteArray> &metaTypes,
+ const QHash<QByteArray, QByteArray> &knownQObjectClasses,
+ const QHash<QByteArray, QByteArray> &knownGadgets,
+ QIODevice &outfile,
+ bool requireCompleteTypes)
+ : out(outfile),
+ cdef(classDef),
+ metaTypes(metaTypes),
+ knownQObjectClasses(knownQObjectClasses),
+ knownGadgets(knownGadgets),
+ requireCompleteTypes(requireCompleteTypes)
+{
+ if (cdef->superclassList.size())
- + purestSuperClass = cdef->superclassList.constFirst().first;
+ + purestSuperClass = cdef->superclassList.constFirst().classname;
}
+// -- QtScxml
+#if 0 // -- QtScxml
static inline qsizetype lengthOfEscapeSequence(const QByteArray &s, qsizetype i)
{
if (s.at(i) != '\\' || i >= s.size() - 1)
@@ -98,7 +126,7 @@
// Prints \a s to \a out, breaking it into lines of at most ColumnWidth. The
// opening and closing quotes are NOT included (it's up to the caller).
-static void printStringWithIndentation(FILE *out, const QByteArray &s)
+static void printStringWithIndentation(QIODevice &out, const QByteArray &s) // -- QtScxml
{
static constexpr int ColumnWidth = 72;
const qsizetype len = s.size();
@@ -116,6 +144,7 @@
idx += spanLen;
} while (idx < len);
}
+#endif // -- QtSxcml
void Generator::strreg(const QByteArray &s)
{
@@ -270,12 +299,21 @@
qualifiedClassNameIdentifier.constData(), qualifiedClassNameIdentifier.constData());
{
char comma = 0;
- for (const QByteArray &str : strings) {
+// -- QtScxml
+ for (qsizetype i = 0, end = strings.size(); i < end; ++i) {
if (comma)
fputc(comma, out);
- printStringWithIndentation(out, str);
+ fprintf(out, "\n {");
+ const QByteArray s = strings.at(i);
+ const qsizetype len = s.size();
+ for (qsizetype charPos = 0; charPos < len; ++charPos)
+ fprintf(out, "char(0x%.2x),", static_cast<quint8>(s.at(charPos)));
+ const bool isLast = (i == end - 1);
+ fprintf(out, "char(0)%s // %d: %s", isLast ? "}" : "},", i, s.constData());
comma = ',';
}
+// -- QtScxml
+
}
fprintf(out, "\n);\n"
"#else // !QT_MOC_HAS_STRINGDATA\n");
@@ -298,8 +336,10 @@
qsizetype methodCount = 0;
if (qAddOverflow(cdef->signalList.size(), cdef->slotList.size(), &methodCount)
|| qAddOverflow(cdef->methodList.size(), methodCount, &methodCount)) {
- parser->error("internal limit exceeded: the total number of member functions"
+// -- QtScxml
+ qFatal("internal limit exceeded: the total number of member functions"
" (including signals and slots) is too big.");
+// -- QtScxml
}
fprintf(out, " %4" PRIdQSIZETYPE ", %4d, // methods\n", methodCount, methodCount ? index : 0);
@@ -346,7 +386,9 @@
if (qAddOverflow(cdef->propertyList.size(), cdef->enumList.size(), &propEnumCount)
|| qAddOverflow(propEnumCount, qsizetype(1), &propEnumCount)
|| propEnumCount >= std::numeric_limits<int>::max()) {
- parser->error("internal limit exceeded: number of property and enum metatypes is too big.");
+// -- QtScxml
+ qFatal("internal limit exceeded: number of property and enum metatypes is too big.");
+// -- QtScxml
}
int initialMetaTypeOffset = int(propEnumCount);
@@ -585,7 +627,7 @@
fprintf(out, "\nvoid *%s::qt_metacast(const char *_clname)\n{\n", cdef->qualified.constData());
fprintf(out, " if (!_clname) return nullptr;\n");
fprintf(out, " if (!strcmp(_clname, qt_meta_stringdata_%s.stringdata0))\n"
- " return static_cast<void*>(this);\n",
+ " return static_cast<void*>(this);\n",
qualifiedClassNameIdentifier.constData());
// for all superclasses but the first one
- @@ -632,7 +674,9 @@
+ @@ -631,7 +673,9 @@
//
// Generate plugin meta data
//
+#if 0 // -- QtScxml
generatePluginMetaData();
+#endif // -- QtScxml
//
// Generate function to make sure the non-class signals exist in the parent classes
- @@ -1084,6 +1128,13 @@
+ @@ -1100,6 +1144,13 @@
const FunctionDef &f = methodList.at(methodindex);
Q_ASSERT(!f.normalizedType.isEmpty());
fprintf(out, " case %d: ", methodindex);
+ // -- QtScxml
+ if (f.implementation) {
+ fprintf(out, f.implementation, "_o", methodindex);
+ fprintf(out, " break;\n");
+ continue;
+ }
+ // -- QtScxml
if (f.normalizedType != "void")
fprintf(out, "{ %s _r = ", noRef(f.normalizedType).constData());
fprintf(out, "_t->");
- @@ -1162,6 +1213,10 @@
+ @@ -1178,6 +1229,10 @@
const FunctionDef &f = cdef->signalList.at(methodindex);
if (f.wasCloned || !f.inPrivateClass.isEmpty() || f.isStatic)
continue;
+ // -- QtScxml
+ if (f.mangledName.isEmpty())
+ continue;
+ // -- QtScxml
anythingUsed = true;
fprintf(out, " {\n");
fprintf(out, " using _t = %s (%s::*)(",f.type.rawName.constData() , cdef->classname.constData());
- @@ -1184,7 +1239,7 @@
+ @@ -1200,7 +1255,7 @@
else
fprintf(out, ");\n");
fprintf(out, " if (_t _q_method = &%s::%s; *reinterpret_cast<_t *>(_a[1]) == _q_method) {\n",
- cdef->classname.constData(), f.name.constData());
+ cdef->classname.constData(), f.mangledName.constData()); // -- QtScxml
fprintf(out, " *result = %d;\n", methodindex);
fprintf(out, " return;\n");
fprintf(out, " }\n }\n");
- @@ -1279,8 +1334,11 @@
+ @@ -1295,8 +1350,11 @@
fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s().value(); break;\n",
propindex, p.type.constData(), prefix.constData(), p.bind.constData());
else if (!p.read.isEmpty())
- fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s(); break;\n",
- propindex, p.type.constData(), prefix.constData(), p.read.constData());
+ // -- QtScxml
+ fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s%s; break;\n",
+ propindex, p.type.constData(), prefix.constData(), p.read.constData(),
+ p.read.endsWith(')') ? "" : "()");
+ // -- QtScxml
else
fprintf(out, " case %d: *reinterpret_cast< %s*>(_v) = %s%s; break;\n",
propindex, p.type.constData(), prefix.constData(), p.member.constData());
- @@ -1412,6 +1470,10 @@
+ @@ -1428,6 +1486,10 @@
{
if (def->wasCloned || def->isAbstract)
return;
+// -- QtScxml
+ if (def->implementation)
+ return;
+// -- QtScxml
fprintf(out, "\n// SIGNAL %d\n%s %s::%s(",
index, def->type.name.constData(), cdef->qualified.constData(), def->name.constData());
- @@ -1460,10 +1522,8 @@
+ @@ -1476,10 +1538,8 @@
if (def->normalizedType == "void") {
fprintf(out, "nullptr");
} else {
- if (def->returnTypeIsVolatile)
- fprintf(out, "const_cast<void*>(reinterpret_cast<const volatile void*>(std::addressof(_t0)))");
- else
- fprintf(out, "const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t0)))");
+ // -- QtScxml removed unused returnTypeIsVolatile
+ fprintf(out, "const_cast<void*>(reinterpret_cast<const void*>(std::addressof(_t0)))");
}
int i;
for (i = 1; i < offset; ++i)
- @@ -1478,6 +1538,36 @@
+ @@ -1494,6 +1554,36 @@
fprintf(out, "}\n");
}
+// -- QtScxml
+void Generator::generateAccessorDefs()
+{
+ for (int propindex = 0; propindex < cdef->propertyList.size(); ++propindex) {
+ const PropertyDef &p = cdef->propertyList.at(propindex);
+ if (p.read.isEmpty() || p.mangledName.isEmpty())
+ continue;
+
+ fprintf(out, "bool %s::%s() const\n{\n return %s;\n}\n\n", cdef->classname.constData(),
+ p.mangledName.constData(), p.read.constData());
+ }
+}
+
+void Generator::generateSignalDefs()
+{
+ for (int methodindex = 0; methodindex < cdef->signalList.size(); ++methodindex) {
+ const FunctionDef &f = cdef->signalList.at(methodindex);
+ if (!f.implementation || f.mangledName.isEmpty())
+ continue;
+
+ fprintf(out, "void %s::%s(bool _t1)\n{\n", cdef->classname.constData(),
+ f.mangledName.constData());
+ fprintf(out, " void *_a[] = { nullptr, "
+ "const_cast<void*>(reinterpret_cast<const void*>(&_t1)) };\n ");
+ fprintf(out, f.implementation, "this", methodindex);
+ fprintf(out, "\n}\n\n");
+ }
+}
+
+#if 0
static CborError jsonValueToCbor(CborEncoder *parent, const QJsonValue &v);
static CborError jsonObjectToCbor(CborEncoder *parent, const QJsonObject &o)
{
- @@ -1613,7 +1703,11 @@
+ @@ -1629,7 +1719,11 @@
#define CBOR_ENCODER_WRITER_CONTROL 1
#define CBOR_ENCODER_WRITE_FUNCTION CborDevice::callback
+#endif
+// -- QtScxml
QT_END_NAMESPACE
+#if 0 // -- QtScxml
#include "cborencoder.c"
+#endif // -- QtScxml