133 bool hasSignedOrUnsigned =
false;
135 type.firstToken = lookup();
141 hasSignedOrUnsigned =
true;
145 type.name += lexemView();
147 if (lookup(0) == VOLATILE)
148 type.isVolatile =
true;
150 case Q_MOC_COMPAT_TOKEN:
151 case Q_INVOKABLE_TOKEN:
152 case Q_SCRIPTABLE_TOKEN:
153 case Q_SIGNALS_TOKEN:
157 type.name += lexemView();
180 if (hasSignedOrUnsigned) {
189 type.name += lexemView();
191 if (test(LONG) || test(INT) || test(DOUBLE)) {
202 type.name += lexemView();
203 isVoid |= (lookup(0) == VOID);
212 if (type.name.isEmpty()) {
216 type.name += lexemUntil(RANGLE);
219 type.name += lexemView();
220 type.isScoped =
true;
225 while (test(CONST) || test(VOLATILE) || test(SIGNED) || test(UNSIGNED)
226 || test(STAR) || test(AND) || test(ANDAND)) {
228 type.name += lexemView();
229 if (lookup(0) == AND)
230 type.referenceType = Type::Reference;
231 else if (lookup(0) == ANDAND)
232 type.referenceType = Type::RValueReference;
233 else if (lookup(0) == STAR)
234 type.referenceType = Type::Pointer;
236 type.rawName = type.name;
238 if (isVoid && type.referenceType == Type::NoReference) {
441 bool templateFunction = (lookup() == TEMPLATE);
442 def->type = parseType();
443 if (def->type.name.isEmpty()) {
444 if (templateFunction)
445 error(
"Template function as signal or slot");
449 bool scopedFunctionName =
false;
454 Type tempType = parseType();
455 while (!tempType.name.isEmpty() && lookup() != LPAREN) {
456 if (testFunctionAttribute(def->type.firstToken, def))
458 else if (def->type.firstToken == Q_SIGNALS_TOKEN)
460 else if (def->type.firstToken == Q_SLOTS_TOKEN)
463 if (!def->tag.isEmpty())
465 def->tag += def->type.name;
467 def->type = tempType;
468 tempType = parseType();
470 next(LPAREN,
"Not a signal or slot declaration");
471 def->name = tempType.name;
474 scopedFunctionName = tempType.isScoped;
482 while (test(IDENTIFIER))
487 while (test(IDENTIFIER))
499 if (def->type.name ==
"auto" && test(ARROW))
500 def->type = parseType();
513 if (scopedFunctionName) {
514 const QByteArray msg =
"Function declaration " + def->name
515 +
" contains extra qualification. Ignoring as signal or slot.";
516 warning(msg.constData());
520 QList<QByteArray> typeNameParts = normalizeType(def->type.name).split(
' ');
521 if (typeNameParts.contains(
"auto")) {
523 error(
"Function declared with auto as return type but missing trailing return type. "
524 "Return type deduction is not supported.");
528 if (def->type.referenceType == Type::Reference) {
529 QByteArray rawName = def->type.rawName;
530 def->type = Type(
"void");
531 def->type.rawName = rawName;
534 def->normalizedType = normalizeType(def->type.name);
778 bool templateClass =
false;
783 qsizetype rewind = index;
784 if (test(IDENTIFIER)) {
785 QByteArray nsName = lexem();
786 QByteArrayList nested;
787 while (test(SCOPE)) {
789
790
791
792
795 nested.append(nsName);
801 }
else if (test(LPAREN)) {
804 }
else if (!test(SEMIC)) {
806 def.classname = nsName;
807 def.lineNumber = symbol().lineNum;
808 def.doGenerate = currentFilenames.size() <= 1;
811 def.begin = index - 1;
814 index = def.begin + 1;
818 for (
const QByteArray &ns : nested) {
819 NamespaceDef parentNs;
820 parentNs.classname = ns;
821 parentNs.qualified = def.qualified;
822 def.qualified += ns +
"::";
823 parentNs.begin = def.begin;
824 parentNs.end = def.end;
825 namespaceList += parentNs;
831 if (test(IDENTIFIER)) {
832 while (test(SCOPE)) {
839 }
else if (!test(SEMIC)) {
844 case Q_NAMESPACE_EXPORT_TOKEN:
846 while (test(IDENTIFIER))
850 case Q_NAMESPACE_TOKEN:
852 if (moduleUnitKind == ModuleUnitKind::ImplementationUnit)
853 error(
"Q_NAMESPACE is not supported in a module implementation unit");
854 if (inPrivateModuleFragment)
855 error(
"Q_NAMESPACE is not supported in a private module fragment");
858 case Q_ENUM_NS_TOKEN:
862 error(
"Q_ENUM can't be used in a Q_NAMESPACE, use Q_ENUM_NS instead");
865 case Q_FLAG_NS_TOKEN:
869 error(
"Q_FLAG can't be used in a Q_NAMESPACE, use Q_FLAG_NS instead");
871 case Q_DECLARE_FLAGS_TOKEN:
874 case Q_CLASSINFO_TOKEN:
875 parseClassInfo(&def);
877 case Q_MOC_INCLUDE_TOKEN:
885 def.enumList += enumDef;
898 namespaceList += def;
900 if (!def.hasQNamespace && (!def.classInfoList.isEmpty() || !def.enumDeclarations.isEmpty()))
901 error(
"Namespace declaration lacks Q_NAMESPACE macro.");
908 templateClass =
false;
911 templateClass =
true;
913 case MOC_INCLUDE_BEGIN:
919 if (hasGlobalModuleFragment && moduleUnitKind == ModuleUnitKind::NotAModule
920 && currentFilenames.size() == 1) {
921 moduleFragmentIncludes += symbol().lexem();
924 currentFilenames.push(symbol().unquotedLexem());
926 case MOC_INCLUDE_END:
927 currentFilenames.pop();
929 case Q_DECLARE_INTERFACE_TOKEN:
932 case Q_DECLARE_METATYPE_TOKEN:
935 case Q_MOC_INCLUDE_TOKEN:
939 if (test(NAMESPACE)) {
940 while (test(SCOPE) || test(IDENTIFIER))
950 if (currentFilenames.size() <= 1)
962 case Q_GADGET_EXPORT_TOKEN:
964 while (test(IDENTIFIER))
980 QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
981 classHash.insert(def.classname, def.qualified);
982 classHash.insert(def.qualified, def.qualified);
986 const qsizetype afterExport = index;
987 if (currentFilenames.size() == 1 && test(IDENTIFIER) && lexem() ==
"module")
988 parseModuleDeclaration(index,
true);
994 if (currentFilenames.size() == 1 && lexem() ==
"module") {
995 const qsizetype afterModule = index;
999 parsePrivateModuleFragment(afterModule);
1003 const bool precededByBareModuleFragment = afterModule == 3
1004 && symbols.at(afterModule - 2).token == SEMIC
1005 && symbols.at(afterModule - 3).token == IDENTIFIER
1006 && symbols.at(afterModule - 3).lexem() ==
"module";
1007 const bool isModuleCandidate = afterModule < 2
1008 || precededByBareModuleFragment
1009 || (hasGlobalModuleFragment
1010 && symbols.at(afterModule - 2).token == MOC_INCLUDE_END);
1011 if (isModuleCandidate)
1012 parseModuleDeclaration(afterModule,
false);
1018 if ((t != CLASS && t != STRUCT)|| currentFilenames.size() > 1)
1022 Symbol qmlRegistrationMacroSymbol =
{};
1027 switch ((t = next())) {
1030 if (test(Q_SIGNALS_TOKEN))
1031 error(
"Signals cannot have access specifier");
1035 if (test(Q_SIGNALS_TOKEN))
1036 error(
"Signals cannot have access specifier");
1040 if (test(Q_SIGNALS_TOKEN))
1041 error(
"Signals cannot have access specifier");
1049 if (t >= Q_META_TOKEN_BEGIN && t < Q_META_TOKEN_END)
1050 error(
"Meta object features not supported for nested classes");
1054 case Q_SIGNALS_TOKEN:
1058 switch (lookup(-1)) {
1065 error(
"Missing access specifier for slots");
1068 case Q_OBJECT_TOKEN:
1071 error(
"Template classes not supported by Q_OBJECT");
1072 if (def.classname !=
"Qt" && def.classname !=
"QObject" && def.superclassList.isEmpty())
1073 error(
"Class contains Q_OBJECT macro but does not inherit from QObject");
1074 if (moduleUnitKind == ModuleUnitKind::ImplementationUnit)
1075 error(
"Q_OBJECT is not supported in a module implementation unit");
1076 if (inPrivateModuleFragment)
1077 error(
"Q_OBJECT is not supported in a private module fragment");
1079 case Q_GADGET_EXPORT_TOKEN:
1081 while (test(IDENTIFIER))
1085 case Q_GADGET_TOKEN:
1088 error(
"Template classes not supported by Q_GADGET");
1089 if (moduleUnitKind == ModuleUnitKind::ImplementationUnit)
1090 error(
"Q_GADGET is not supported in a module implementation unit");
1091 if (inPrivateModuleFragment)
1092 error(
"Q_GADGET is not supported in a private module fragment");
1094 case Q_PROPERTY_TOKEN:
1097 case QT_ANONYMOUS_PROPERTY_TOKEN:
1100 case Q_PLUGIN_METADATA_TOKEN:
1107 case Q_ENUM_NS_TOKEN:
1108 error(
"Q_ENUM_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_ENUM instead");
1114 case Q_FLAG_NS_TOKEN:
1115 error(
"Q_FLAG_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_FLAG instead");
1117 case Q_DECLARE_FLAGS_TOKEN:
1120 case Q_CLASSINFO_TOKEN:
1123 case Q_MOC_INCLUDE_TOKEN:
1126 case Q_INTERFACES_TOKEN:
1129 case Q_PRIVATE_SLOT_TOKEN:
1132 case Q_PRIVATE_PROPERTY_TOKEN:
1135 case QT_ANONYMOUS_PRIVATE_PROPERTY_TOKEN:
1141 def.enumList += enumDef;
1148 const QByteArrayView lex = lexemView();
1149 if (lex.startsWith(
"QML_")) {
1150 if ( lex ==
"QML_ELEMENT" || lex ==
"QML_NAMED_ELEMENT"
1151 || lex ==
"QML_ANONYMOUS" || lex ==
"QML_VALUE_TYPE") {
1152 qmlRegistrationMacroSymbol = symbol();
1160 qsizetype rewind = index--;
1164 def.constructorList += funcDef;
1165 handleDefaultArguments(&def.constructorList, funcDef);
1171 def.publicList += funcDef;
1173 def.slotList += funcDef;
1174 handleDefaultArguments(&def.slotList, funcDef);
1178 def.signalList += funcDef;
1179 handleDefaultArguments(&def.signalList, funcDef);
1183 def.methodList += funcDef;
1184 handleDefaultArguments(&def.methodList, funcDef);
1198
1199
1200
1202 QByteArray msg(
"Potential QML registration macro was found, but no header containing it was included.\n"
1203 "This might cause runtime errors in QML applications\n"
1204 "Include <QtQmlIntegration/qqmlintegration.h> or <QtQml/qqmlregistration.h> to fix this.");
1205 if (qmlMacroWarningIsFatal)
1206 error(qmlRegistrationMacroSymbol, msg.constData());
1208 warning(qmlRegistrationMacroSymbol, msg.constData());
1212 && def.propertyList.isEmpty() && def.enumDeclarations.isEmpty())
1216 if (!def.hasQObject && !def.hasQGadget)
1217 error(
"Class declaration lacks Q_OBJECT macro.");
1220 if (!def.pluginData.iid.isEmpty())
1221 def.pluginData.metaArgs = metaArgs;
1223 if (def
.hasQObject && !def.superclassList.isEmpty())
1231 QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
1232 classHash.insert(def.classname, def.qualified);
1233 classHash.insert(def.qualified, def.qualified);
1236 for (
const auto &n : std::as_const(namespaceList)) {
1237 if (!n.hasQNamespace)
1240 static_cast<BaseDef &>(def) =
static_cast<BaseDef>(n);
1241 def.qualified += def.classname;
1242 def.hasQNamespace =
true;
1243 auto it = std::find_if(classList.begin(), classList.end(), [&def](
const ClassDef &val) {
1244 return def.classname == val.classname && def.qualified == val.qualified;
1247 if (it != classList.end()) {
1248 it->classInfoList += def.classInfoList;
1249 Q_ASSERT(it->classInfoList.size() <= std::numeric_limits<
int>::max());
1250 it->enumDeclarations.insert(def.enumDeclarations);
1251 it->enumList += def.enumList;
1252 Q_ASSERT(it->enumList.size() <= std::numeric_limits<
int>::max());
1253 it->flagAliases.insert(def.flagAliases);
1255 knownGadgets.insert(def.classname, def.qualified);
1256 knownGadgets.insert(def.qualified, def.qualified);
1342 QByteArrayView fn = strippedFileName();
1344 fprintf(out,
"/****************************************************************************\n"
1345 "** Meta object code from reading C++ file '%s'\n**\n" , fn.constData());
1346 fprintf(out,
"** Created by: The Qt Meta Object Compiler version %d (Qt %s)\n**\n" , mocOutputRevision, QT_VERSION_STR);
1347 fprintf(out,
"** WARNING! All changes made in this file will be lost!\n"
1348 "*****************************************************************************/\n\n");
1355 fprintf(out,
"module;\n\n");
1356 for (
const QByteArray &inc : std::as_const(moduleFragmentIncludes))
1357 fprintf(out,
"#include \"%s\"\n", inc.constData());
1362 if (includePath.size() && !includePath.endsWith(
'/'))
1364 for (QByteArray inc : std::as_const(includeFiles)) {
1365 if (!inc.isEmpty() && inc.at(0) !=
'<' && inc.at(0) !=
'"') {
1366 if (includePath.size() && includePath !=
"./")
1367 inc.prepend(includePath);
1368 inc =
'\"' + inc +
'\"';
1370 fprintf(out,
"#include %s\n", inc.constData());
1373 if (classList.size() && classList.constFirst().classname ==
"Qt")
1374 fprintf(out,
"#include <QtCore/qobject.h>\n");
1376 fprintf(out,
"#include <QtCore/qmetatype.h>\n");
1378 fprintf(out,
"#include <QtCore/qplugin.h>\n");
1380 const auto qtContainers = requiredQtContainers(classList);
1381 for (
const QByteArray &qtContainer : qtContainers)
1382 fprintf(out,
"#include <QtCore/%s>\n", qtContainer.constData());
1384 fprintf(out,
"\n#include <QtCore/qtmochelpers.h>\n");
1386 fprintf(out,
"\n#include <memory>\n\n");
1387 fprintf(out,
"\n#include <QtCore/qxptype_traits.h>\n");
1390 fprintf(out,
"\nmodule %s;\n", moduleName.constData());
1398 fprintf(out,
"import :%s;\n", modulePartitionName.constData());
1404 fprintf(out,
"#if !defined(Q_MOC_OUTPUT_REVISION)\n"
1405 "#error \"The header file '%s' doesn't include <QObject>.\"\n", fn.constData());
1406 fprintf(out,
"#elif Q_MOC_OUTPUT_REVISION != %d\n", mocOutputRevision);
1407 fprintf(out,
"#error \"This file was generated using the moc from %s."
1408 " It\"\n#error \"cannot be used with the include files from"
1409 " this version of Qt.\"\n#error \"(The moc has changed too"
1410 " much.)\"\n", QT_VERSION_STR);
1411 fprintf(out,
"#endif\n\n");
1413#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
)
1414 fprintf(out,
"#ifndef Q_CONSTINIT\n"
1415 "#define Q_CONSTINIT\n"
1420 for (ClassDef &cdef : classList) {
1421 QList<EnumDef> enumList;
1422 for (EnumDef def : std::as_const(cdef.enumList)) {
1423 if (cdef.enumDeclarations.contains(def.name)) {
1426 def.enumName = def.name;
1427 QByteArray alias = cdef.flagAliases.value(def.name);
1428 if (cdef.enumDeclarations.contains(alias)) {
1430 def.flags |= cdef.enumDeclarations[alias];
1434 cdef.enumList = enumList;
1437 fprintf(out,
"QT_WARNING_PUSH\n");
1438 fprintf(out,
"QT_WARNING_DISABLE_DEPRECATED\n");
1439 fprintf(out,
"QT_WARNING_DISABLE_GCC(\"-Wuseless-cast\")\n");
1442 for (
const ClassDef &def : std::as_const(classList)) {
1443 Generator generator(
this, &def, metaTypes, knownQObjectClasses, knownGadgets, out,
1444 requireCompleteTypes);
1445 generator.generateCode();
1448 if (Q_UNLIKELY(generator.registeredStringsCount() >= std::numeric_limits<
int>::max())) {
1449 error(
"internal limit exceeded: number of parsed strings is too big.");
1455 fprintf(out,
"QT_WARNING_POP\n");
1458 QJsonObject mocData;
1459 mocData[
"outputRevision"_L1] = mocOutputRevision;
1460 mocData[
"inputFile"_L1] = QLatin1StringView(fn.constData());
1463 QByteArray moduleId = moduleName;
1464 if (!modulePartitionName.isEmpty())
1465 moduleId +=
':' + modulePartitionName;
1466 mocData[
"module"_L1] = QLatin1StringView(moduleId.constData(), moduleId.size());
1469 QJsonArray classesJsonFormatted;
1471 for (
const ClassDef &cdef: std::as_const(classList))
1472 classesJsonFormatted.append(cdef.toJson());
1474 if (!classesJsonFormatted.isEmpty())
1475 mocData[
"classes"_L1] = classesJsonFormatted;
1478 fputs(jsonDoc.toJson().constData(), jsonOutput);
1609 auto checkIsFunction = [&](
const QByteArray &def,
const char *name) {
1610 if (def.endsWith(
')')) {
1611 QByteArray msg =
"Providing a function for ";
1613 msg +=
" in a property declaration is not be supported in Qt 6.";
1614 error(msg.constData());
1618 while (test(IDENTIFIER)) {
1619 const Symbol &lsym = symbol();
1620 const QByteArrayView l = lsym.lexemView();
1621 if (l[0] ==
'C' && l ==
"CONSTANT") {
1624 }
else if (l[0] ==
'F' && l ==
"FINAL") {
1627 }
else if (l[0] ==
'N' && l ==
"NAME") {
1629 propDef.name = lexem();
1631 }
else if (l[0] ==
'O' && l ==
"OVERRIDE") {
1634 }
else if (l[0] ==
'R' && l ==
"REQUIRED") {
1637 }
else if (l[0] ==
'R' && l ==
"REVISION" && test(LPAREN)) {
1641 }
else if (l[0] ==
'V' && l ==
"VIRTUAL") {
1648 v = lexemUntil(RPAREN);
1649 v = v.mid(1, v.size() - 2);
1650 }
else if (test(INTEGER_LITERAL)) {
1652 if (l !=
"REVISION")
1654 }
else if (test(DEFAULT)) {
1656 if (l !=
"READ" && l !=
"WRITE")
1662 v2 = lexemUntil(RPAREN);
1663 else if (v !=
"true" && v !=
"false")
1676 else if (l ==
"RESET")
1678 else if (l ==
"REVISION") {
1680 const int minor = v.toInt(&ok);
1681 if (!ok || !QTypeRevision::isValidSegment(minor))
1688 if (l ==
"SCRIPTABLE") {
1689 propDef.scriptable = v + v2;
1690 checkIsFunction(propDef.scriptable,
"SCRIPTABLE");
1691 }
else if (l ==
"STORED") {
1692 propDef.stored = v + v2;
1693 checkIsFunction(propDef.stored,
"STORED");
1697 case 'W':
if (l !=
"WRITE") error(lsym);
1700 case 'B':
if (l !=
"BINDABLE") error(lsym);
1703 case 'D':
if (l !=
"DESIGNABLE") error(lsym);
1704 propDef.designable = v + v2;
1705 checkIsFunction(propDef.designable,
"DESIGNABLE");
1707 case 'N':
if (l !=
"NOTIFY") error(lsym);
1710 case 'U':
if (l !=
"USER") error(lsym);
1711 propDef.user = v + v2;
1712 checkIsFunction(propDef.user,
"USER");
1718 if (propDef
.constant && !propDef.write.isNull()) {
1719 const QByteArray msg =
"Property declaration " + propDef.name
1720 +
" is both WRITEable and CONSTANT. CONSTANT will be ignored.";
1722 warning(msg.constData());
1724 if (propDef
.constant && !propDef.notify.isNull()) {
1725 const QByteArray msg =
"Property declaration " + propDef.name
1726 +
" is both NOTIFYable and CONSTANT. CONSTANT will be ignored.";
1728 warning(msg.constData());
1730 if (propDef
.constant && !propDef.bind.isNull()) {
1731 const QByteArray msg =
"Property declaration " + propDef.name
1732 +
" is both BINDable and CONSTANT. CONSTANT will be ignored.";
1734 warning(msg.constData());
1736 if (propDef.read ==
"default" && propDef.bind.isNull()) {
1737 const QByteArray msg =
"Property declaration " + propDef.name
1738 +
" is not BINDable but default-READable. READ will be ignored.";
1740 warning(msg.constData());
1742 if (propDef.write ==
"default" && propDef.bind.isNull()) {
1743 const QByteArray msg =
"Property declaration " + propDef.name
1744 +
" is not BINDable but default-WRITEable. WRITE will be ignored.";
1746 warning(msg.constData());
1749 const QByteArray msg =
"Issue with property declaration " + propDef.name
1750 +
": VIRTUAL is redundant when overriding a property. The OVERRIDE "
1751 "must only be used when actually overriding an existing property; using it on a "
1752 "new property is an error.";
1753 error(msg.constData());
1756 const QByteArray msg =
"Issue with property declaration " + propDef.name
1757 +
": OVERRIDE is redundant when property is marked FINAL";
1758 error(msg.constData());
1761 const QByteArray msg =
"Issue with property declaration " + propDef.name
1762 +
": The VIRTUAL cannot be combined with FINAL, as these attributes are mutually "
1764 error(msg.constData());
1781 QByteArray metaData;
1782 while (test(IDENTIFIER)) {
1783 QByteArray l = lexem();
1785 next(STRING_LITERAL);
1786 def->pluginData.iid = unquotedLexem();
1787 }
else if (l ==
"URI") {
1788 next(STRING_LITERAL);
1789 def->pluginData.uri = unquotedLexem();
1790 }
else if (l ==
"FILE") {
1791 next(STRING_LITERAL);
1792 QByteArrayView metaDataFile = unquotedLexemView();
1793 QFileInfo fi(QFileInfo(QString::fromLocal8Bit(currentFilenames.top())).dir(),
1794 QString::fromLocal8Bit(metaDataFile));
1795 for (
const IncludePath &p : std::as_const(includes)) {
1798 if (p.isFrameworkPath)
1801 fi.setFile(QString::fromLocal8Bit(p.path), QString::fromLocal8Bit(metaDataFile));
1809 const QByteArray msg =
"Plugin Metadata file " + lexemView()
1810 +
" does not exist. Declaration will be ignored";
1811 error(msg.constData());
1814 QFile file(fi.canonicalFilePath());
1815 if (!file.open(QFile::ReadOnly)) {
1816 QByteArray msg =
"Plugin Metadata file " + lexemView() +
" could not be opened: "
1817 + file.errorString().toUtf8();
1818 error(msg.constData());
1821 parsedPluginMetadataFiles.append(fi.canonicalFilePath());
1822 metaData = file.readAll();
1826 if (!metaData.isEmpty()) {
1827 def->pluginData.metaData = QJsonDocument::fromJson(metaData);
1828 if (!def->pluginData.metaData.isObject()) {
1829 const QByteArray msg =
"Plugin Metadata file " + lexemView()
1830 +
" does not contain a valid JSON object. Declaration will be ignored";
1831 warning(msg.constData());
1832 def->pluginData.iid = QByteArray();
1833 def->pluginData.uri = QByteArray();
2143 Q_ASSERT(!def->superclassList.isEmpty());
2144 const QByteArray &firstSuperclass = def->superclassList.at(0).classname;
2146 if (!knownQObjectClasses.contains(firstSuperclass)) {
2149 const QByteArray msg
2152 +
" contains the Q_OBJECT macro and inherits from "
2153 + def->superclassList.value(0)
2154 +
" but that is not a known QObject subclass. You may get compilation errors.";
2155 warning(msg.constData());
2160 auto isRegisteredInterface = [&def](QByteArrayView super) {
2161 auto matchesSuperClass = [&super](
const auto &ifaces) {
2162 return !ifaces.isEmpty() && ifaces.first().className == super;
2164 return std::any_of(def->interfaceList.cbegin(), def->interfaceList.cend(), matchesSuperClass);
2167 const auto end = def->superclassList.cend();
2168 auto it = def->superclassList.cbegin() + 1;
2169 for (; it != end; ++it) {
2170 const QByteArray &superClass = it->classname;
2171 if (knownQObjectClasses.contains(superClass)) {
2172 const QByteArray msg
2175 +
" inherits from two QObject subclasses "
2179 +
". This is not supported!";
2180 warning(msg.constData());
2183 if (interface2IdMap.contains(superClass)) {
2184 if (!isRegisteredInterface(superClass)) {
2185 const QByteArray msg
2188 +
" implements the interface "
2190 +
" but does not list it in Q_INTERFACES. qobject_cast to "
2192 +
" will not work!";
2193 warning(msg.constData());
2205 QDuplicateTracker<QByteArray> definedProperties(cdef->propertyList.size());
2206 auto hasNoAttributes = [&](
const PropertyDef &p) {
2207 if (definedProperties.hasSeen(p.name)) {
2208 QByteArray msg =
"The property '" + p.name +
"' is defined multiple times in class " + cdef->classname +
".";
2209 warning(msg.constData());
2212 if (p.read.isEmpty() && p.member.isEmpty() && p.bind.isEmpty()) {
2213 QByteArray msg =
"Property declaration " + p.name +
" has neither an associated QProperty<> member"
2214 ", nor a READ accessor function nor an associated MEMBER variable. The property will be invalid.";
2215 const auto &sym = p.location >= 0 ? symbolAt(p.location) : Symbol();
2216 warning(sym, msg.constData());
2217 if (p.write.isEmpty())
2222 cdef->propertyList.removeIf(hasNoAttributes);
2224 for (PropertyDef &p : cdef->propertyList) {
2225 for (
const FunctionDef &f : std::as_const(cdef->publicList)) {
2226 if (f.name != p.read)
2230 if (f.arguments.size())
2232 PropertyDef::Specification spec = PropertyDef::ValueSpec;
2233 QByteArray tmp = f.normalizedType;
2234 if (p.type ==
"QByteArray" && tmp ==
"const char *")
2236 if (tmp.left(6) ==
"const ")
2238 if (p.type != tmp && tmp.endsWith(
'*')) {
2240 spec = PropertyDef::PointerSpec;
2241 }
else if (f.type.name.endsWith(
'&')) {
2242 spec = PropertyDef::ReferenceSpec;
2249 if (!p.notify.isEmpty()) {
2251 for (
int j = 0; j <
int(cdef->signalList.size()); ++j) {
2252 const FunctionDef &f = cdef->signalList.at(j);
2253 if (f.name != p.notify) {
2260 p.notifyId = notifyId;
2261 if (notifyId == -1) {
2262 const int index =
int(cdef->nonClassSignalList.indexOf(p.notify));
2264 cdef->nonClassSignalList << p.notify;
2265 p.notifyId =
int(-1 - cdef->nonClassSignalList.size());
2267 p.notifyId =
int(-2 - index);
2277 cls[
"className"_L1] = QString::fromUtf8(classname.constData());
2278 cls[
"qualifiedClassName"_L1] = QString::fromUtf8(qualified.constData());
2279 cls[
"lineNumber"_L1] = lineNumber;
2281 cls[
"final"_L1] =
true;
2283 QJsonArray classInfos;
2284 for (
const auto &info: std::as_const(classInfoList)) {
2285 QJsonObject infoJson;
2286 infoJson[
"name"_L1] = QString::fromUtf8(info.name);
2287 infoJson[
"value"_L1] = QString::fromUtf8(info.value);
2288 classInfos.append(infoJson);
2291 if (classInfos.size())
2292 cls[
"classInfos"_L1] = classInfos;
2294 int methodIndex = 0;
2295 const auto appendFunctions
2296 = [&cls, &methodIndex](
const QString &type,
const QList<
FunctionDef> &funcs) {
2297 QJsonArray jsonFuncs;
2299 for (
const FunctionDef &fdef: funcs)
2300 jsonFuncs.append(fdef.toJson(methodIndex++));
2302 if (!jsonFuncs.isEmpty())
2303 cls[type] = jsonFuncs;
2307 appendFunctions(
"signals"_L1, signalList);
2308 appendFunctions(
"slots"_L1, slotList);
2309 appendFunctions(
"methods"_L1, methodList);
2313 appendFunctions(
"constructors"_L1, constructorList);
2317 for (
const PropertyDef &propDef: std::as_const(propertyList))
2318 props.append(propDef.toJson());
2320 if (!props.isEmpty())
2321 cls[
"properties"_L1] = props;
2324 cls[
"object"_L1] =
true;
2326 cls[
"gadget"_L1] =
true;
2328 cls[
"namespace"_L1] =
true;
2330 QJsonArray superClasses;
2332 for (
const auto &super: std::as_const(superclassList)) {
2333 QJsonObject superCls;
2334 superCls[
"name"_L1] = QString::fromUtf8(super.classname);
2335 if (super.classname != super.qualified)
2336 superCls[
"fullyQualifiedName"_L1] = QString::fromUtf8(super.qualified);
2337 FunctionDef::accessToJson(&superCls, super.access);
2338 superClasses.append(superCls);
2341 if (!superClasses.isEmpty())
2342 cls[
"superClasses"_L1] = superClasses;
2345 for (
const EnumDef &enumDef: std::as_const(enumList))
2346 enums.append(enumDef.toJson(*
this));
2347 if (!enums.isEmpty())
2348 cls[
"enums"_L1] = enums;
2351 for (
const QList<Interface> &ifaceList : interfaceList) {
2352 QJsonArray jsonList;
2353 for (
const Interface &iface: ifaceList) {
2354 QJsonObject ifaceJson;
2355 ifaceJson[
"id"_L1] = QString::fromUtf8(iface.interfaceId);
2356 ifaceJson[
"className"_L1] = QString::fromUtf8(iface.className);
2357 jsonList.append(ifaceJson);
2359 ifaces.append(jsonList);
2361 if (!ifaces.isEmpty())
2362 cls[
"interfaces"_L1] = ifaces;