47 if (token == COLON || token == LBRACE)
49 if (token == SEMIC || token == RANGLE)
56 if (!test(IDENTIFIER))
58 QByteArray name = lexem();
64 if (!test(IDENTIFIER))
67 }
else if (test(IDENTIFIER)) {
68 const QByteArray lex = lexem();
69 if (lex !=
"final" && lex !=
"sealed" && lex !=
"Q_DECL_FINAL")
73 def->qualified += name;
75 def->qualified += lexem();
76 if (test(IDENTIFIER)) {
78 def->qualified += name;
81 def->classname = name;
82 def->lineNumber = symbol().lineNum;
84 if (test(IDENTIFIER)) {
85 const QByteArray lex = lexem();
86 if (lex !=
"final" && lex !=
"sealed" && lex !=
"Q_DECL_FINAL")
96 else if (test(PROTECTED))
101 const Type type = parseType();
106 def->superclassList.push_back({type.name, toFullyQualified(type.name), access});
108 }
while (test(COMMA));
110 if (!def->superclassList.isEmpty()
111 && knownGadgets.contains(def->superclassList.constFirst().classname)) {
113 knownGadgets.insert(def->classname, def->qualified);
114 knownGadgets.insert(def->qualified, def->qualified);
119 def->begin = index - 1;
120 bool foundRBrace =
until(RBRACE
);
122 index = def->begin + 1;
129 bool hasSignedOrUnsigned =
false;
131 type.firstToken = lookup();
137 hasSignedOrUnsigned =
true;
141 type.name += lexem();
143 if (lookup(0) == VOLATILE)
144 type.isVolatile =
true;
146 case Q_MOC_COMPAT_TOKEN:
147 case Q_INVOKABLE_TOKEN:
148 case Q_SCRIPTABLE_TOKEN:
149 case Q_SIGNALS_TOKEN:
153 type.name += lexem();
176 if (hasSignedOrUnsigned) {
185 type.name += lexem();
187 if (test(LONG) || test(INT) || test(DOUBLE)) {
198 type.name += lexem();
199 isVoid |= (lookup(0) == VOID);
208 if (type.name.isEmpty()) {
212 type.name += lexemUntil(RANGLE);
215 type.name += lexem();
216 type.isScoped =
true;
221 while (test(CONST) || test(VOLATILE) || test(SIGNED) || test(UNSIGNED)
222 || test(STAR) || test(AND) || test(ANDAND)) {
224 type.name += lexem();
225 if (lookup(0) == AND)
226 type.referenceType = Type::Reference;
227 else if (lookup(0) == ANDAND)
228 type.referenceType = Type::RValueReference;
229 else if (lookup(0) == STAR)
230 type.referenceType = Type::Pointer;
232 type.rawName = type.name;
234 if (isVoid && type.referenceType == Type::NoReference) {
306 arg.type = parseType();
307 if (arg.type.name ==
"void")
309 if (test(IDENTIFIER))
311 while (test(LBRACK)) {
312 arg.rightType += lexemUntil(RBRACK);
314 if (test(CONST) || test(VOLATILE)) {
315 arg.rightType +=
' ';
316 arg.rightType += lexem();
318 arg.normalizedType = normalizeType(QByteArray(arg.type.name +
' ' + arg.rightType));
319 arg.typeNameForCast = QByteArray(
"std::add_pointer_t<"+arg.normalizedType+
">");
322 def->arguments += arg;
327 if (!def->arguments.isEmpty()
328 && def->arguments.constLast().normalizedType ==
"QPrivateSignal") {
329 def->arguments.removeLast();
332 if (def->arguments.size() == 1
333 && def->arguments.constLast().normalizedType ==
"QMethodRawArguments") {
334 def->arguments.removeLast();
338 if (Q_UNLIKELY(def->arguments.size() >= std::numeric_limits<
int>::max()))
339 error(
"number of function arguments exceeds std::numeric_limits<int>::max()");
386 QByteArray revisionString = lexemUntil(RPAREN);
387 revisionString.remove(0, 1);
388 revisionString.chop(1);
389 const QList<QByteArray> majorMinor = revisionString.split(
',');
390 switch (majorMinor.size()) {
393 const int revision = revisionString.toInt(&ok);
394 if (!ok || !QTypeRevision::isValidSegment(revision))
395 error(
"Invalid revision");
400 const int major = majorMinor[0].toInt(&ok);
401 if (!ok || !QTypeRevision::isValidSegment(major))
402 error(
"Invalid major version");
403 const int minor = majorMinor[1].toInt(&ok);
404 if (!ok || !QTypeRevision::isValidSegment(minor))
405 error(
"Invalid minor version");
409 error(
"Invalid revision");
433 bool templateFunction = (lookup() == TEMPLATE);
434 def->type = parseType();
435 if (def->type.name.isEmpty()) {
436 if (templateFunction)
437 error(
"Template function as signal or slot");
441 bool scopedFunctionName =
false;
446 Type tempType = parseType();
447 while (!tempType.name.isEmpty() && lookup() != LPAREN) {
448 if (testFunctionAttribute(def->type.firstToken, def))
450 else if (def->type.firstToken == Q_SIGNALS_TOKEN)
452 else if (def->type.firstToken == Q_SLOTS_TOKEN)
455 if (!def->tag.isEmpty())
457 def->tag += def->type.name;
459 def->type = tempType;
460 tempType = parseType();
462 next(LPAREN,
"Not a signal or slot declaration");
463 def->name = tempType.name;
464 scopedFunctionName = tempType.isScoped;
472 while (test(IDENTIFIER))
477 while (test(IDENTIFIER))
489 if (def->type.name ==
"auto" && test(ARROW))
490 def->type = parseType();
503 if (scopedFunctionName) {
504 const QByteArray msg =
"Function declaration " + def->name
505 +
" contains extra qualification. Ignoring as signal or slot.";
506 warning(msg.constData());
510 QList<QByteArray> typeNameParts = normalizeType(def->type.name).split(
' ');
511 if (typeNameParts.contains(
"auto")) {
513 error(
"Function declared with auto as return type but missing trailing return type. "
514 "Return type deduction is not supported.");
518 if (def->type.referenceType == Type::Reference) {
519 QByteArray rawName = def->type.rawName;
520 def->type = Type(
"void");
521 def->type.rawName = rawName;
524 def->normalizedType = normalizeType(def->type.name);
543 bool tilde = test(TILDE);
544 def->type = parseType();
545 if (def->type.name.isEmpty())
547 bool scopedFunctionName =
false;
549 def->name = def->type.name;
550 scopedFunctionName = def->type.isScoped;
551 if (def->name == cdef->classname) {
564 Type tempType = parseType();
565 while (!tempType.name.isEmpty() && lookup() != LPAREN) {
566 if (testFunctionAttribute(def->type.firstToken, def))
568 else if (def->type.name ==
"Q_SIGNAL")
570 else if (def->type.name ==
"Q_SLOT")
573 if (!def->tag.isEmpty())
575 def->tag += def->type.name;
577 def->type = tempType;
578 tempType = parseType();
582 def->name = tempType.name;
583 scopedFunctionName = tempType.isScoped;
587 if (def->type.referenceType == Type::Reference) {
588 QByteArray rawName = def->type.rawName;
589 def->type = Type(
"void");
590 def->type.rawName = rawName;
593 def->normalizedType = normalizeType(def->type.name);
601 if (scopedFunctionName
603 const QByteArray msg =
"parsemaybe: Function declaration " + def->name
604 +
" contains extra qualification. Ignoring as signal or slot.";
605 warning(msg.constData());
635 if (Q_UNLIKELY(def.nonClassSignalList.size() > std::numeric_limits<
int>::max()))
636 error(
"number of signals defined in parent class(es) exceeds "
637 "std::numeric_limits<int>::max().");
639 if (Q_UNLIKELY(def.propertyList.size() > std::numeric_limits<
int>::max()))
640 error(
"number of bindable properties exceeds std::numeric_limits<int>::max().");
642 if (Q_UNLIKELY(def.classInfoList.size() > std::numeric_limits<
int>::max()))
643 error(
"number of times Q_CLASSINFO macro is used exceeds "
644 "std::numeric_limits<int>::max().");
646 if (Q_UNLIKELY(def.enumList.size() > std::numeric_limits<
int>::max()))
647 error(
"number of enumerations exceeds std::numeric_limits<int>::max().");
649 if (Q_UNLIKELY(def.superclassList.size() > std::numeric_limits<
int>::max()))
650 error(
"number of super classes exceeds std::numeric_limits<int>::max().");
652 if (Q_UNLIKELY(def.constructorList.size() > std::numeric_limits<
int>::max()))
653 error(
"number of constructor parameters exceeds std::numeric_limits<int>::max().");
655 if (Q_UNLIKELY(def.signalList.size() > std::numeric_limits<
int>::max()))
656 error(
"number of signals exceeds std::numeric_limits<int>::max().");
658 if (Q_UNLIKELY(def.slotList.size() > std::numeric_limits<
int>::max()))
659 error(
"number of declared slots exceeds std::numeric_limits<int>::max().");
661 if (Q_UNLIKELY(def.methodList.size() > std::numeric_limits<
int>::max()))
662 error(
"number of methods exceeds std::numeric_limits<int>::max().");
664 if (Q_UNLIKELY(def.publicList.size() > std::numeric_limits<
int>::max()))
665 error(
"number of public functions declared in this class exceeds "
666 "std::numeric_limits<int>::max().");
672 bool templateClass =
false;
677 qsizetype rewind = index;
678 if (test(IDENTIFIER)) {
679 QByteArray nsName = lexem();
680 QByteArrayList nested;
681 while (test(SCOPE)) {
683
684
685
686
689 nested.append(nsName);
695 }
else if (test(LPAREN)) {
698 }
else if (!test(SEMIC)) {
700 def.classname = nsName;
701 def.lineNumber = symbol().lineNum;
702 def.doGenerate = currentFilenames.size() <= 1;
705 def.begin = index - 1;
708 index = def.begin + 1;
712 for (
const QByteArray &ns : nested) {
713 NamespaceDef parentNs;
714 parentNs.classname = ns;
715 parentNs.qualified = def.qualified;
716 def.qualified += ns +
"::";
717 parentNs.begin = def.begin;
718 parentNs.end = def.end;
719 namespaceList += parentNs;
725 if (test(IDENTIFIER)) {
726 while (test(SCOPE)) {
733 }
else if (!test(SEMIC)) {
738 case Q_NAMESPACE_TOKEN:
741 case Q_NAMESPACE_EXPORT_TOKEN:
743 while (test(IDENTIFIER))
749 case Q_ENUM_NS_TOKEN:
753 error(
"Q_ENUM can't be used in a Q_NAMESPACE, use Q_ENUM_NS instead");
756 case Q_FLAG_NS_TOKEN:
757 parseEnumOrFlag(&def, EnumIsFlag);
760 error(
"Q_FLAG can't be used in a Q_NAMESPACE, use Q_FLAG_NS instead");
762 case Q_DECLARE_FLAGS_TOKEN:
765 case Q_CLASSINFO_TOKEN:
766 parseClassInfo(&def);
768 case Q_MOC_INCLUDE_TOKEN:
776 def.enumList += enumDef;
789 namespaceList += def;
791 if (!def.hasQNamespace && (!def.classInfoList.isEmpty() || !def.enumDeclarations.isEmpty()))
792 error(
"Namespace declaration lacks Q_NAMESPACE macro.");
799 templateClass =
false;
802 templateClass =
true;
804 case MOC_INCLUDE_BEGIN:
805 currentFilenames.push(symbol().unquotedLexem());
807 case MOC_INCLUDE_END:
808 currentFilenames.pop();
810 case Q_DECLARE_INTERFACE_TOKEN:
813 case Q_DECLARE_METATYPE_TOKEN:
816 case Q_MOC_INCLUDE_TOKEN:
820 if (test(NAMESPACE)) {
821 while (test(SCOPE) || test(IDENTIFIER))
831 if (currentFilenames.size() <= 1)
843 case Q_GADGET_EXPORT_TOKEN:
845 while (test(IDENTIFIER))
861 QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
862 classHash.insert(def.classname, def.qualified);
863 classHash.insert(def.qualified, def.qualified);
868 if ((t != CLASS && t != STRUCT)|| currentFilenames.size() > 1)
872 Symbol qmlRegistrationMacroSymbol =
{};
877 switch ((t = next())) {
880 if (test(Q_SIGNALS_TOKEN))
881 error(
"Signals cannot have access specifier");
885 if (test(Q_SIGNALS_TOKEN))
886 error(
"Signals cannot have access specifier");
890 if (test(Q_SIGNALS_TOKEN))
891 error(
"Signals cannot have access specifier");
899 if (t >= Q_META_TOKEN_BEGIN && t < Q_META_TOKEN_END)
900 error(
"Meta object features not supported for nested classes");
904 case Q_SIGNALS_TOKEN:
908 switch (lookup(-1)) {
915 error(
"Missing access specifier for slots");
921 error(
"Template classes not supported by Q_OBJECT");
922 if (def.classname !=
"Qt" && def.classname !=
"QObject" && def.superclassList.isEmpty())
923 error(
"Class contains Q_OBJECT macro but does not inherit from QObject");
925 case Q_GADGET_EXPORT_TOKEN:
927 while (test(IDENTIFIER))
934 error(
"Template classes not supported by Q_GADGET");
936 case Q_PROPERTY_TOKEN:
939 case QT_ANONYMOUS_PROPERTY_TOKEN:
942 case Q_PLUGIN_METADATA_TOKEN:
949 case Q_ENUM_NS_TOKEN:
950 error(
"Q_ENUM_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_ENUM instead");
954 parseEnumOrFlag(&def, EnumIsFlag);
956 case Q_FLAG_NS_TOKEN:
957 error(
"Q_FLAG_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_FLAG instead");
959 case Q_DECLARE_FLAGS_TOKEN:
962 case Q_CLASSINFO_TOKEN:
965 case Q_MOC_INCLUDE_TOKEN:
968 case Q_INTERFACES_TOKEN:
971 case Q_PRIVATE_SLOT_TOKEN:
974 case Q_PRIVATE_PROPERTY_TOKEN:
977 case QT_ANONYMOUS_PRIVATE_PROPERTY_TOKEN:
983 def.enumList += enumDef;
990 const QByteArray lex = lexem();
991 if (lex.startsWith(
"QML_")) {
992 if ( lex ==
"QML_ELEMENT" || lex ==
"QML_NAMED_ELEMENT"
993 || lex ==
"QML_ANONYMOUS" || lex ==
"QML_VALUE_TYPE") {
994 qmlRegistrationMacroSymbol = symbol();
1002 qsizetype rewind = index--;
1006 def.constructorList += funcDef;
1007 handleDefaultArguments(&def.constructorList, funcDef);
1013 def.publicList += funcDef;
1015 def.slotList += funcDef;
1016 handleDefaultArguments(&def.slotList, funcDef);
1020 def.signalList += funcDef;
1021 handleDefaultArguments(&def.signalList, funcDef);
1025 def.methodList += funcDef;
1026 handleDefaultArguments(&def.methodList, funcDef);
1040
1041
1042
1044 QByteArray msg(
"Potential QML registration macro was found, but no header containing it was included.\n"
1045 "This might cause runtime errors in QML applications\n"
1046 "Include <QtQmlIntegration/qqmlintegration.h> or <QtQml/qqmlregistration.h> to fix this.");
1047 warning(qmlRegistrationMacroSymbol, msg.constData());
1051 && def.propertyList.isEmpty() && def.enumDeclarations.isEmpty())
1055 if (!def.hasQObject && !def.hasQGadget)
1056 error(
"Class declaration lacks Q_OBJECT macro.");
1059 if (!def.pluginData.iid.isEmpty())
1060 def.pluginData.metaArgs = metaArgs;
1062 if (def
.hasQObject && !def.superclassList.isEmpty())
1070 QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
1071 classHash.insert(def.classname, def.qualified);
1072 classHash.insert(def.qualified, def.qualified);
1075 for (
const auto &n : std::as_const(namespaceList)) {
1076 if (!n.hasQNamespace)
1079 static_cast<BaseDef &>(def) =
static_cast<BaseDef>(n);
1080 def.qualified += def.classname;
1081 def.hasQNamespace =
true;
1082 auto it = std::find_if(classList.begin(), classList.end(), [&def](
const ClassDef &val) {
1083 return def.classname == val.classname && def.qualified == val.qualified;
1086 if (it != classList.end()) {
1087 it->classInfoList += def.classInfoList;
1088 Q_ASSERT(it->classInfoList.size() <= std::numeric_limits<
int>::max());
1089 it->enumDeclarations.insert(def.enumDeclarations);
1090 it->enumList += def.enumList;
1091 Q_ASSERT(it->enumList.size() <= std::numeric_limits<
int>::max());
1092 it->flagAliases.insert(def.flagAliases);
1094 knownGadgets.insert(def.classname, def.qualified);
1095 knownGadgets.insert(def.qualified, def.qualified);
1150 static const QByteArrayList candidates = make_candidates();
1152 QByteArrayList required;
1153 required.reserve(candidates.size());
1155 bool needsQProperty =
false;
1157 for (
const auto &candidate : candidates) {
1158 const QByteArray pattern = candidate +
'<';
1160 for (
const auto &c : classes) {
1161 for (
const auto &p : c.propertyList)
1162 needsQProperty |= !p.bind.isEmpty();
1163 if (any_type_contains(c.propertyList, pattern) ||
1164 any_arg_contains(c.slotList, pattern) ||
1165 any_arg_contains(c.signalList, pattern) ||
1166 any_arg_contains(c.methodList, pattern)) {
1167 required.push_back(candidate);
1174 required.push_back(
"QProperty");
1181 QByteArrayView fn = strippedFileName();
1183 fprintf(out,
"/****************************************************************************\n"
1184 "** Meta object code from reading C++ file '%s'\n**\n" , fn.constData());
1185 fprintf(out,
"** Created by: The Qt Meta Object Compiler version %d (Qt %s)\n**\n" , mocOutputRevision, QT_VERSION_STR);
1186 fprintf(out,
"** WARNING! All changes made in this file will be lost!\n"
1187 "*****************************************************************************/\n\n");
1193 if (includePath.size() && !includePath.endsWith(
'/'))
1195 for (QByteArray inc : std::as_const(includeFiles)) {
1196 if (!inc.isEmpty() && inc.at(0) !=
'<' && inc.at(0) !=
'"') {
1197 if (includePath.size() && includePath !=
"./")
1198 inc.prepend(includePath);
1199 inc =
'\"' + inc +
'\"';
1201 fprintf(out,
"#include %s\n", inc.constData());
1204 if (classList.size() && classList.constFirst().classname ==
"Qt")
1205 fprintf(out,
"#include <QtCore/qobject.h>\n");
1207 fprintf(out,
"#include <QtCore/qmetatype.h>\n");
1209 fprintf(out,
"#include <QtCore/qplugin.h>\n");
1211 const auto qtContainers = requiredQtContainers(classList);
1212 for (
const QByteArray &qtContainer : qtContainers)
1213 fprintf(out,
"#include <QtCore/%s>\n", qtContainer.constData());
1215 fprintf(out,
"\n#include <QtCore/qtmochelpers.h>\n");
1217 fprintf(out,
"\n#include <memory>\n\n");
1218 fprintf(out,
"\n#include <QtCore/qxptype_traits.h>\n");
1220 fprintf(out,
"#if !defined(Q_MOC_OUTPUT_REVISION)\n"
1221 "#error \"The header file '%s' doesn't include <QObject>.\"\n", fn.constData());
1223 fprintf(out,
"#error \"This file was generated using the moc from %s."
1224 " It\"\n#error \"cannot be used with the include files from"
1225 " this version of Qt.\"\n#error \"(The moc has changed too"
1226 " much.)\"\n", QT_VERSION_STR);
1227 fprintf(out,
"#endif\n\n");
1229#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
)
1230 fprintf(out,
"#ifndef Q_CONSTINIT\n"
1231 "#define Q_CONSTINIT\n"
1235 fprintf(out,
"QT_WARNING_PUSH\n");
1236 fprintf(out,
"QT_WARNING_DISABLE_DEPRECATED\n");
1237 fprintf(out,
"QT_WARNING_DISABLE_GCC(\"-Wuseless-cast\")\n");
1240 for (ClassDef &def : classList) {
1241 Generator generator(
this, &def, metaTypes, knownQObjectClasses, knownGadgets, out,
1242 requireCompleteTypes);
1243 generator.generateCode();
1246 if (Q_UNLIKELY(generator.registeredStringsCount() >= std::numeric_limits<
int>::max())) {
1247 error(
"internal limit exceeded: number of parsed strings is too big.");
1253 fprintf(out,
"QT_WARNING_POP\n");
1256 QJsonObject mocData;
1257 mocData[
"outputRevision"_L1] = mocOutputRevision;
1258 mocData[
"inputFile"_L1] = QLatin1StringView(fn.constData());
1260 QJsonArray classesJsonFormatted;
1262 for (
const ClassDef &cdef: std::as_const(classList))
1263 classesJsonFormatted.append(cdef.toJson());
1265 if (!classesJsonFormatted.isEmpty())
1266 mocData[
"classes"_L1] = classesJsonFormatted;
1269 fputs(jsonDoc.toJson().constData(), jsonOutput);
1399 auto checkIsFunction = [&](
const QByteArray &def,
const char *name) {
1400 if (def.endsWith(
')')) {
1401 QByteArray msg =
"Providing a function for ";
1403 msg +=
" in a property declaration is not be supported in Qt 6.";
1404 error(msg.constData());
1408 while (test(IDENTIFIER)) {
1409 const Symbol &lsym = symbol();
1410 const QByteArray l = lsym.lexem();
1411 if (l[0] ==
'C' && l ==
"CONSTANT") {
1414 }
else if (l[0] ==
'F' && l ==
"FINAL") {
1417 }
else if (l[0] ==
'N' && l ==
"NAME") {
1419 propDef.name = lexem();
1421 }
else if (l[0] ==
'R' && l ==
"REQUIRED") {
1424 }
else if (l[0] ==
'R' && l ==
"REVISION" && test(LPAREN)) {
1432 v = lexemUntil(RPAREN);
1433 v = v.mid(1, v.size() - 2);
1434 }
else if (test(INTEGER_LITERAL)) {
1436 if (l !=
"REVISION")
1438 }
else if (test(DEFAULT)) {
1440 if (l !=
"READ" && l !=
"WRITE")
1446 v2 = lexemUntil(RPAREN);
1447 else if (v !=
"true" && v !=
"false")
1460 else if (l ==
"RESET")
1462 else if (l ==
"REVISION") {
1464 const int minor = v.toInt(&ok);
1465 if (!ok || !QTypeRevision::isValidSegment(minor))
1472 if (l ==
"SCRIPTABLE") {
1473 propDef.scriptable = v + v2;
1474 checkIsFunction(propDef.scriptable,
"SCRIPTABLE");
1475 }
else if (l ==
"STORED") {
1476 propDef.stored = v + v2;
1477 checkIsFunction(propDef.stored,
"STORED");
1481 case 'W':
if (l !=
"WRITE") error(lsym);
1484 case 'B':
if (l !=
"BINDABLE") error(lsym);
1487 case 'D':
if (l !=
"DESIGNABLE") error(lsym);
1488 propDef.designable = v + v2;
1489 checkIsFunction(propDef.designable,
"DESIGNABLE");
1491 case 'N':
if (l !=
"NOTIFY") error(lsym);
1494 case 'U':
if (l !=
"USER") error(lsym);
1495 propDef.user = v + v2;
1496 checkIsFunction(propDef.user,
"USER");
1502 if (propDef
.constant && !propDef.write.isNull()) {
1503 const QByteArray msg =
"Property declaration " + propDef.name
1504 +
" is both WRITEable and CONSTANT. CONSTANT will be ignored.";
1506 warning(msg.constData());
1508 if (propDef
.constant && !propDef.notify.isNull()) {
1509 const QByteArray msg =
"Property declaration " + propDef.name
1510 +
" is both NOTIFYable and CONSTANT. CONSTANT will be ignored.";
1512 warning(msg.constData());
1514 if (propDef
.constant && !propDef.bind.isNull()) {
1515 const QByteArray msg =
"Property declaration " + propDef.name
1516 +
" is both BINDable and CONSTANT. CONSTANT will be ignored.";
1518 warning(msg.constData());
1520 if (propDef.read ==
"default" && propDef.bind.isNull()) {
1521 const QByteArray msg =
"Property declaration " + propDef.name
1522 +
" is not BINDable but default-READable. READ will be ignored.";
1524 warning(msg.constData());
1526 if (propDef.write ==
"default" && propDef.bind.isNull()) {
1527 const QByteArray msg =
"Property declaration " + propDef.name
1528 +
" is not BINDable but default-WRITEable. WRITE will be ignored.";
1530 warning(msg.constData());
1547 QByteArray metaData;
1548 while (test(IDENTIFIER)) {
1549 QByteArray l = lexem();
1551 next(STRING_LITERAL);
1552 def->pluginData.iid = unquotedLexem();
1553 }
else if (l ==
"URI") {
1554 next(STRING_LITERAL);
1555 def->pluginData.uri = unquotedLexem();
1556 }
else if (l ==
"FILE") {
1557 next(STRING_LITERAL);
1558 QByteArray metaDataFile = unquotedLexem();
1559 QFileInfo fi(QFileInfo(QString::fromLocal8Bit(currentFilenames.top())).dir(),
1560 QString::fromLocal8Bit(metaDataFile));
1561 for (
const IncludePath &p : std::as_const(includes)) {
1564 if (p.isFrameworkPath)
1567 fi.setFile(QString::fromLocal8Bit(p.path.constData()), QString::fromLocal8Bit(metaDataFile.constData()));
1575 const QByteArray msg =
"Plugin Metadata file " + lexem()
1576 +
" does not exist. Declaration will be ignored";
1577 error(msg.constData());
1580 QFile file(fi.canonicalFilePath());
1581 if (!file.open(QFile::ReadOnly)) {
1582 QByteArray msg =
"Plugin Metadata file " + lexem() +
" could not be opened: "
1583 + file.errorString().toUtf8();
1584 error(msg.constData());
1587 parsedPluginMetadataFiles.append(fi.canonicalFilePath());
1588 metaData = file.readAll();
1592 if (!metaData.isEmpty()) {
1593 def->pluginData.metaData = QJsonDocument::fromJson(metaData);
1594 if (!def->pluginData.metaData.isObject()) {
1595 const QByteArray msg =
"Plugin Metadata file " + lexem()
1596 +
" does not contain a valid JSON object. Declaration will be ignored";
1597 warning(msg.constData());
1598 def->pluginData.iid = QByteArray();
1599 def->pluginData.uri = QByteArray();
1714 while (test(IDENTIFIER)) {
1716 iface += ClassDef::Interface(lexem());
1717 while (test(SCOPE)) {
1718 iface.last().className += lexem();
1720 iface.last().className += lexem();
1722 while (test(COLON)) {
1724 iface += ClassDef::Interface(lexem());
1725 while (test(SCOPE)) {
1726 iface.last().className += lexem();
1728 iface.last().className += lexem();
1732 for (qsizetype i = 0; i < iface.size(); ++i) {
1733 const QByteArray iid = interface2IdMap.value(iface.at(i).className);
1735 error(
"Undefined interface");
1737 iface[i].interfaceId = iid;
1739 def->interfaceList += iface;
1833 switch(symbols.at(index-1).token) {
1834 case LBRACE: ++braceCount;
break;
1835 case LBRACK: ++brackCount;
break;
1836 case LPAREN: ++parenCount;
break;
1837 case LANGLE: ++angleCount;
break;
1845 qsizetype possible = -1;
1847 while (index < symbols.size()) {
1848 Token t = symbols.at(index++).token;
1850 case LBRACE: ++braceCount;
break;
1851 case RBRACE: --braceCount;
break;
1852 case LBRACK: ++brackCount;
break;
1853 case RBRACK: --brackCount;
break;
1854 case LPAREN: ++parenCount;
break;
1855 case RPAREN: --parenCount;
break;
1857 if (parenCount == 0 && braceCount == 0)
1861 if (parenCount == 0 && braceCount == 0)
1865 if (parenCount == 0 && braceCount == 0) {
1876 && (target != RANGLE || angleCount <= 0)) {
1877 if (target != COMMA || angleCount <= 0)
1882 if (target == COMMA && t == EQ && possible != -1) {
1887 if (braceCount < 0 || brackCount < 0 || parenCount < 0
1888 || (target == RANGLE && angleCount < 0)) {
1893 if (braceCount <= 0 && t == SEMIC) {
1899 if (target == COMMA && angleCount != 0 && possible != -1) {
1909 Q_ASSERT(!def->superclassList.isEmpty());
1910 const QByteArray &firstSuperclass = def->superclassList.at(0).classname;
1912 if (!knownQObjectClasses.contains(firstSuperclass)) {
1915 const QByteArray msg
1918 +
" contains the Q_OBJECT macro and inherits from "
1919 + def->superclassList.value(0)
1920 +
" but that is not a known QObject subclass. You may get compilation errors.";
1921 warning(msg.constData());
1926 auto isRegisteredInterface = [&def](QByteArrayView super) {
1927 auto matchesSuperClass = [&super](
const auto &ifaces) {
1928 return !ifaces.isEmpty() && ifaces.first().className == super;
1930 return std::any_of(def->interfaceList.cbegin(), def->interfaceList.cend(), matchesSuperClass);
1933 const auto end = def->superclassList.cend();
1934 auto it = def->superclassList.cbegin() + 1;
1935 for (; it != end; ++it) {
1936 const QByteArray &superClass = it->classname;
1937 if (knownQObjectClasses.contains(superClass)) {
1938 const QByteArray msg
1941 +
" inherits from two QObject subclasses "
1945 +
". This is not supported!";
1946 warning(msg.constData());
1949 if (interface2IdMap.contains(superClass)) {
1950 if (!isRegisteredInterface(superClass)) {
1951 const QByteArray msg
1954 +
" implements the interface "
1956 +
" but does not list it in Q_INTERFACES. qobject_cast to "
1958 +
" will not work!";
1959 warning(msg.constData());
1971 QDuplicateTracker<QByteArray> definedProperties(cdef->propertyList.size());
1972 auto hasNoAttributes = [&](
const PropertyDef &p) {
1973 if (definedProperties.hasSeen(p.name)) {
1974 QByteArray msg =
"The property '" + p.name +
"' is defined multiple times in class " + cdef->classname +
".";
1975 warning(msg.constData());
1978 if (p.read.isEmpty() && p.member.isEmpty() && p.bind.isEmpty()) {
1979 QByteArray msg =
"Property declaration " + p.name +
" has neither an associated QProperty<> member"
1980 ", nor a READ accessor function nor an associated MEMBER variable. The property will be invalid.";
1981 const auto &sym = p.location >= 0 ? symbolAt(p.location) : Symbol();
1982 warning(sym, msg.constData());
1983 if (p.write.isEmpty())
1988 cdef->propertyList.removeIf(hasNoAttributes);
1990 for (PropertyDef &p : cdef->propertyList) {
1991 for (
const FunctionDef &f : std::as_const(cdef->publicList)) {
1992 if (f.name != p.read)
1996 if (f.arguments.size())
1998 PropertyDef::Specification spec = PropertyDef::ValueSpec;
1999 QByteArray tmp = f.normalizedType;
2000 if (p.type ==
"QByteArray" && tmp ==
"const char *")
2002 if (tmp.left(6) ==
"const ")
2004 if (p.type != tmp && tmp.endsWith(
'*')) {
2006 spec = PropertyDef::PointerSpec;
2007 }
else if (f.type.name.endsWith(
'&')) {
2008 spec = PropertyDef::ReferenceSpec;
2015 if (!p.notify.isEmpty()) {
2017 for (
int j = 0; j <
int(cdef->signalList.size()); ++j) {
2018 const FunctionDef &f = cdef->signalList.at(j);
2019 if (f.name != p.notify) {
2026 p.notifyId = notifyId;
2027 if (notifyId == -1) {
2028 const int index =
int(cdef->nonClassSignalList.indexOf(p.notify));
2030 cdef->nonClassSignalList << p.notify;
2031 p.notifyId =
int(-1 - cdef->nonClassSignalList.size());
2033 p.notifyId =
int(-2 - index);
2043 cls[
"className"_L1] = QString::fromUtf8(classname.constData());
2044 cls[
"qualifiedClassName"_L1] = QString::fromUtf8(qualified.constData());
2045 cls[
"lineNumber"_L1] = lineNumber;
2047 QJsonArray classInfos;
2048 for (
const auto &info: std::as_const(classInfoList)) {
2049 QJsonObject infoJson;
2050 infoJson[
"name"_L1] = QString::fromUtf8(info.name);
2051 infoJson[
"value"_L1] = QString::fromUtf8(info.value);
2052 classInfos.append(infoJson);
2055 if (classInfos.size())
2056 cls[
"classInfos"_L1] = classInfos;
2058 int methodIndex = 0;
2059 const auto appendFunctions
2060 = [&cls, &methodIndex](
const QString &type,
const QList<
FunctionDef> &funcs) {
2061 QJsonArray jsonFuncs;
2063 for (
const FunctionDef &fdef: funcs)
2064 jsonFuncs.append(fdef.toJson(methodIndex++));
2066 if (!jsonFuncs.isEmpty())
2067 cls[type] = jsonFuncs;
2071 appendFunctions(
"signals"_L1, signalList);
2072 appendFunctions(
"slots"_L1, slotList);
2073 appendFunctions(
"methods"_L1, methodList);
2077 appendFunctions(
"constructors"_L1, constructorList);
2081 for (
const PropertyDef &propDef: std::as_const(propertyList))
2082 props.append(propDef.toJson());
2084 if (!props.isEmpty())
2085 cls[
"properties"_L1] = props;
2088 cls[
"object"_L1] =
true;
2090 cls[
"gadget"_L1] =
true;
2092 cls[
"namespace"_L1] =
true;
2094 QJsonArray superClasses;
2096 for (
const auto &super: std::as_const(superclassList)) {
2097 QJsonObject superCls;
2098 superCls[
"name"_L1] = QString::fromUtf8(super.classname);
2099 if (super.classname != super.qualified)
2100 superCls[
"fullyQualifiedName"_L1] = QString::fromUtf8(super.qualified);
2101 FunctionDef::accessToJson(&superCls, super.access);
2102 superClasses.append(superCls);
2105 if (!superClasses.isEmpty())
2106 cls[
"superClasses"_L1] = superClasses;
2109 for (
const EnumDef &enumDef: std::as_const(enumList))
2110 enums.append(enumDef.toJson(*
this));
2111 if (!enums.isEmpty())
2112 cls[
"enums"_L1] = enums;
2115 for (
const QList<Interface> &ifaceList : interfaceList) {
2116 QJsonArray jsonList;
2117 for (
const Interface &iface: ifaceList) {
2118 QJsonObject ifaceJson;
2119 ifaceJson[
"id"_L1] = QString::fromUtf8(iface.interfaceId);
2120 ifaceJson[
"className"_L1] = QString::fromUtf8(iface.className);
2121 jsonList.append(ifaceJson);
2123 ifaces.append(jsonList);
2125 if (!ifaces.isEmpty())
2126 cls[
"interfaces"_L1] = ifaces;