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 QByteArrayView lex = lexemView();
69 if (lex !=
"final" && lex !=
"sealed" && lex !=
"Q_DECL_FINAL")
75 def->qualified += name;
77 def->qualified += lexemView();
78 if (test(IDENTIFIER)) {
80 def->qualified += name;
83 def->classname = name;
84 def->lineNumber = symbol().lineNum;
86 if (test(IDENTIFIER)) {
87 const QByteArrayView lex = lexemView();
88 if (lex !=
"final" && lex !=
"sealed" && lex !=
"Q_DECL_FINAL")
100 else if (test(PROTECTED))
105 const Type type = parseType();
110 def->superclassList.push_back({type.name, toFullyQualified(type.name), access});
112 }
while (test(COMMA));
114 if (!def->superclassList.isEmpty()
115 && knownGadgets.contains(def->superclassList.constFirst().classname)) {
117 knownGadgets.insert(def->classname, def->qualified);
118 knownGadgets.insert(def->qualified, def->qualified);
123 def->begin = index - 1;
124 bool foundRBrace =
until(RBRACE
);
126 index = def->begin + 1;
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) {
315 arg.type = parseType();
316 if (arg.type.name ==
"void")
318 if (test(IDENTIFIER))
320 while (test(LBRACK)) {
321 arg.rightType += lexemUntil(RBRACK);
323 if (test(CONST) || test(VOLATILE)) {
324 arg.rightType +=
' ';
325 arg.rightType += lexemView();
327 arg.normalizedType = normalizeType(QByteArray(arg.type.name +
' ' + arg.rightType));
330 def->arguments += arg;
335 if (!def->arguments.isEmpty()
336 && def->arguments.constLast().normalizedType ==
"QPrivateSignal") {
337 def->arguments.removeLast();
340 if (def->arguments.size() == 1
341 && def->arguments.constLast().normalizedType ==
"QMethodRawArguments") {
342 def->arguments.removeLast();
346 if (Q_UNLIKELY(def->arguments.size() >= std::numeric_limits<
int>::max()))
347 error(
"number of function arguments exceeds std::numeric_limits<int>::max()");
394 QByteArray revisionString = lexemUntil(RPAREN);
395 revisionString.remove(0, 1);
396 revisionString.chop(1);
397 const QList<QByteArray> majorMinor = revisionString.split(
',');
398 switch (majorMinor.size()) {
401 const int revision = revisionString.toInt(&ok);
402 if (!ok || !QTypeRevision::isValidSegment(revision))
403 error(
"Invalid revision");
408 const int major = majorMinor[0].toInt(&ok);
409 if (!ok || !QTypeRevision::isValidSegment(major))
410 error(
"Invalid major version");
411 const int minor = majorMinor[1].toInt(&ok);
412 if (!ok || !QTypeRevision::isValidSegment(minor))
413 error(
"Invalid minor version");
417 error(
"Invalid revision");
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);
553 bool tilde = test(TILDE);
554 def->type = parseType();
555 if (def->type.name.isEmpty())
557 bool scopedFunctionName =
false;
559 def->name = def->type.name;
561 scopedFunctionName = def->type.isScoped;
562 if (def->name == cdef->classname) {
575 Type tempType = parseType();
576 while (!tempType.name.isEmpty() && lookup() != LPAREN) {
577 if (testFunctionAttribute(def->type.firstToken, def))
579 else if (def->type.name ==
"Q_SIGNAL")
581 else if (def->type.name ==
"Q_SLOT")
584 if (!def->tag.isEmpty())
586 def->tag += def->type.name;
588 def->type = tempType;
589 tempType = parseType();
593 def->name = tempType.name;
595 scopedFunctionName = tempType.isScoped;
599 if (def->type.referenceType == Type::Reference) {
600 QByteArray rawName = def->type.rawName;
601 def->type = Type(
"void");
602 def->type.rawName = rawName;
605 def->normalizedType = normalizeType(def->type.name);
613 if (scopedFunctionName
615 const QByteArray msg =
"parsemaybe: Function declaration " + def->name
616 +
" contains extra qualification. Ignoring as signal or slot.";
617 warning(msg.constData());
647 if (Q_UNLIKELY(def.nonClassSignalList.size() > std::numeric_limits<
int>::max()))
648 error(
"number of signals defined in parent class(es) exceeds "
649 "std::numeric_limits<int>::max().");
651 if (Q_UNLIKELY(def.propertyList.size() > std::numeric_limits<
int>::max()))
652 error(
"number of bindable properties exceeds std::numeric_limits<int>::max().");
654 if (Q_UNLIKELY(def.classInfoList.size() > std::numeric_limits<
int>::max()))
655 error(
"number of times Q_CLASSINFO macro is used exceeds "
656 "std::numeric_limits<int>::max().");
658 if (Q_UNLIKELY(def.enumList.size() > std::numeric_limits<
int>::max()))
659 error(
"number of enumerations exceeds std::numeric_limits<int>::max().");
661 if (Q_UNLIKELY(def.superclassList.size() > std::numeric_limits<
int>::max()))
662 error(
"number of super classes exceeds std::numeric_limits<int>::max().");
664 if (Q_UNLIKELY(def.constructorList.size() > std::numeric_limits<
int>::max()))
665 error(
"number of constructor parameters exceeds std::numeric_limits<int>::max().");
667 if (Q_UNLIKELY(def.signalList.size() > std::numeric_limits<
int>::max()))
668 error(
"number of signals exceeds std::numeric_limits<int>::max().");
670 if (Q_UNLIKELY(def.slotList.size() > std::numeric_limits<
int>::max()))
671 error(
"number of declared slots exceeds std::numeric_limits<int>::max().");
673 if (Q_UNLIKELY(def.methodList.size() > std::numeric_limits<
int>::max()))
674 error(
"number of methods exceeds std::numeric_limits<int>::max().");
676 if (Q_UNLIKELY(def.publicList.size() > std::numeric_limits<
int>::max()))
677 error(
"number of public functions declared in this class exceeds "
678 "std::numeric_limits<int>::max().");
684 bool templateClass =
false;
689 qsizetype rewind = index;
690 if (test(IDENTIFIER)) {
691 QByteArray nsName = lexem();
692 QByteArrayList nested;
693 while (test(SCOPE)) {
695
696
697
698
701 nested.append(nsName);
707 }
else if (test(LPAREN)) {
710 }
else if (!test(SEMIC)) {
712 def.classname = nsName;
713 def.lineNumber = symbol().lineNum;
714 def.doGenerate = currentFilenames.size() <= 1;
717 def.begin = index - 1;
720 index = def.begin + 1;
724 for (
const QByteArray &ns : nested) {
725 NamespaceDef parentNs;
726 parentNs.classname = ns;
727 parentNs.qualified = def.qualified;
728 def.qualified += ns +
"::";
729 parentNs.begin = def.begin;
730 parentNs.end = def.end;
731 namespaceList += parentNs;
737 if (test(IDENTIFIER)) {
738 while (test(SCOPE)) {
745 }
else if (!test(SEMIC)) {
750 case Q_NAMESPACE_TOKEN:
753 case Q_NAMESPACE_EXPORT_TOKEN:
755 while (test(IDENTIFIER))
761 case Q_ENUM_NS_TOKEN:
765 error(
"Q_ENUM can't be used in a Q_NAMESPACE, use Q_ENUM_NS instead");
768 case Q_FLAG_NS_TOKEN:
769 parseEnumOrFlag(&def, EnumIsFlag);
772 error(
"Q_FLAG can't be used in a Q_NAMESPACE, use Q_FLAG_NS instead");
774 case Q_DECLARE_FLAGS_TOKEN:
777 case Q_CLASSINFO_TOKEN:
778 parseClassInfo(&def);
780 case Q_MOC_INCLUDE_TOKEN:
788 def.enumList += enumDef;
801 namespaceList += def;
803 if (!def.hasQNamespace && (!def.classInfoList.isEmpty() || !def.enumDeclarations.isEmpty()))
804 error(
"Namespace declaration lacks Q_NAMESPACE macro.");
811 templateClass =
false;
814 templateClass =
true;
816 case MOC_INCLUDE_BEGIN:
817 currentFilenames.push(symbol().unquotedLexem());
819 case MOC_INCLUDE_END:
820 currentFilenames.pop();
822 case Q_DECLARE_INTERFACE_TOKEN:
825 case Q_DECLARE_METATYPE_TOKEN:
828 case Q_MOC_INCLUDE_TOKEN:
832 if (test(NAMESPACE)) {
833 while (test(SCOPE) || test(IDENTIFIER))
843 if (currentFilenames.size() <= 1)
855 case Q_GADGET_EXPORT_TOKEN:
857 while (test(IDENTIFIER))
873 QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
874 classHash.insert(def.classname, def.qualified);
875 classHash.insert(def.qualified, def.qualified);
880 if ((t != CLASS && t != STRUCT)|| currentFilenames.size() > 1)
884 Symbol qmlRegistrationMacroSymbol =
{};
889 switch ((t = next())) {
892 if (test(Q_SIGNALS_TOKEN))
893 error(
"Signals cannot have access specifier");
897 if (test(Q_SIGNALS_TOKEN))
898 error(
"Signals cannot have access specifier");
902 if (test(Q_SIGNALS_TOKEN))
903 error(
"Signals cannot have access specifier");
911 if (t >= Q_META_TOKEN_BEGIN && t < Q_META_TOKEN_END)
912 error(
"Meta object features not supported for nested classes");
916 case Q_SIGNALS_TOKEN:
920 switch (lookup(-1)) {
927 error(
"Missing access specifier for slots");
933 error(
"Template classes not supported by Q_OBJECT");
934 if (def.classname !=
"Qt" && def.classname !=
"QObject" && def.superclassList.isEmpty())
935 error(
"Class contains Q_OBJECT macro but does not inherit from QObject");
937 case Q_GADGET_EXPORT_TOKEN:
939 while (test(IDENTIFIER))
946 error(
"Template classes not supported by Q_GADGET");
948 case Q_PROPERTY_TOKEN:
951 case QT_ANONYMOUS_PROPERTY_TOKEN:
954 case Q_PLUGIN_METADATA_TOKEN:
961 case Q_ENUM_NS_TOKEN:
962 error(
"Q_ENUM_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_ENUM instead");
966 parseEnumOrFlag(&def, EnumIsFlag);
968 case Q_FLAG_NS_TOKEN:
969 error(
"Q_FLAG_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_FLAG instead");
971 case Q_DECLARE_FLAGS_TOKEN:
974 case Q_CLASSINFO_TOKEN:
977 case Q_MOC_INCLUDE_TOKEN:
980 case Q_INTERFACES_TOKEN:
983 case Q_PRIVATE_SLOT_TOKEN:
986 case Q_PRIVATE_PROPERTY_TOKEN:
989 case QT_ANONYMOUS_PRIVATE_PROPERTY_TOKEN:
995 def.enumList += enumDef;
1002 const QByteArrayView lex = lexemView();
1003 if (lex.startsWith(
"QML_")) {
1004 if ( lex ==
"QML_ELEMENT" || lex ==
"QML_NAMED_ELEMENT"
1005 || lex ==
"QML_ANONYMOUS" || lex ==
"QML_VALUE_TYPE") {
1006 qmlRegistrationMacroSymbol = symbol();
1014 qsizetype rewind = index--;
1018 def.constructorList += funcDef;
1019 handleDefaultArguments(&def.constructorList, funcDef);
1025 def.publicList += funcDef;
1027 def.slotList += funcDef;
1028 handleDefaultArguments(&def.slotList, funcDef);
1032 def.signalList += funcDef;
1033 handleDefaultArguments(&def.signalList, funcDef);
1037 def.methodList += funcDef;
1038 handleDefaultArguments(&def.methodList, funcDef);
1052
1053
1054
1056 QByteArray msg(
"Potential QML registration macro was found, but no header containing it was included.\n"
1057 "This might cause runtime errors in QML applications\n"
1058 "Include <QtQmlIntegration/qqmlintegration.h> or <QtQml/qqmlregistration.h> to fix this.");
1059 if (qmlMacroWarningIsFatal)
1060 error(qmlRegistrationMacroSymbol, msg.constData());
1062 warning(qmlRegistrationMacroSymbol, msg.constData());
1066 && def.propertyList.isEmpty() && def.enumDeclarations.isEmpty())
1070 if (!def.hasQObject && !def.hasQGadget)
1071 error(
"Class declaration lacks Q_OBJECT macro.");
1074 if (!def.pluginData.iid.isEmpty())
1075 def.pluginData.metaArgs = metaArgs;
1077 if (def
.hasQObject && !def.superclassList.isEmpty())
1085 QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
1086 classHash.insert(def.classname, def.qualified);
1087 classHash.insert(def.qualified, def.qualified);
1090 for (
const auto &n : std::as_const(namespaceList)) {
1091 if (!n.hasQNamespace)
1094 static_cast<BaseDef &>(def) =
static_cast<BaseDef>(n);
1095 def.qualified += def.classname;
1096 def.hasQNamespace =
true;
1097 auto it = std::find_if(classList.begin(), classList.end(), [&def](
const ClassDef &val) {
1098 return def.classname == val.classname && def.qualified == val.qualified;
1101 if (it != classList.end()) {
1102 it->classInfoList += def.classInfoList;
1103 Q_ASSERT(it->classInfoList.size() <= std::numeric_limits<
int>::max());
1104 it->enumDeclarations.insert(def.enumDeclarations);
1105 it->enumList += def.enumList;
1106 Q_ASSERT(it->enumList.size() <= std::numeric_limits<
int>::max());
1107 it->flagAliases.insert(def.flagAliases);
1109 knownGadgets.insert(def.classname, def.qualified);
1110 knownGadgets.insert(def.qualified, def.qualified);
1165 static const QByteArrayList candidates = make_candidates();
1167 QByteArrayList required;
1168 required.reserve(candidates.size());
1170 bool needsQProperty =
false;
1172 for (
const auto &candidate : candidates) {
1173 const QByteArray pattern = candidate +
'<';
1175 for (
const auto &c : classes) {
1176 for (
const auto &p : c.propertyList)
1177 needsQProperty |= !p.bind.isEmpty();
1178 if (any_type_contains(c.propertyList, pattern) ||
1179 any_arg_contains(c.slotList, pattern) ||
1180 any_arg_contains(c.signalList, pattern) ||
1181 any_arg_contains(c.methodList, pattern)) {
1182 required.push_back(candidate);
1189 required.push_back(
"QProperty");
1196 QByteArrayView fn = strippedFileName();
1198 fprintf(out,
"/****************************************************************************\n"
1199 "** Meta object code from reading C++ file '%s'\n**\n" , fn.constData());
1200 fprintf(out,
"** Created by: The Qt Meta Object Compiler version %d (Qt %s)\n**\n" , mocOutputRevision, QT_VERSION_STR);
1201 fprintf(out,
"** WARNING! All changes made in this file will be lost!\n"
1202 "*****************************************************************************/\n\n");
1208 if (includePath.size() && !includePath.endsWith(
'/'))
1210 for (QByteArray inc : std::as_const(includeFiles)) {
1211 if (!inc.isEmpty() && inc.at(0) !=
'<' && inc.at(0) !=
'"') {
1212 if (includePath.size() && includePath !=
"./")
1213 inc.prepend(includePath);
1214 inc =
'\"' + inc +
'\"';
1216 fprintf(out,
"#include %s\n", inc.constData());
1219 if (classList.size() && classList.constFirst().classname ==
"Qt")
1220 fprintf(out,
"#include <QtCore/qobject.h>\n");
1222 fprintf(out,
"#include <QtCore/qmetatype.h>\n");
1224 fprintf(out,
"#include <QtCore/qplugin.h>\n");
1226 const auto qtContainers = requiredQtContainers(classList);
1227 for (
const QByteArray &qtContainer : qtContainers)
1228 fprintf(out,
"#include <QtCore/%s>\n", qtContainer.constData());
1230 fprintf(out,
"\n#include <QtCore/qtmochelpers.h>\n");
1232 fprintf(out,
"\n#include <memory>\n\n");
1233 fprintf(out,
"\n#include <QtCore/qxptype_traits.h>\n");
1235 fprintf(out,
"#if !defined(Q_MOC_OUTPUT_REVISION)\n"
1236 "#error \"The header file '%s' doesn't include <QObject>.\"\n", fn.constData());
1238 fprintf(out,
"#error \"This file was generated using the moc from %s."
1239 " It\"\n#error \"cannot be used with the include files from"
1240 " this version of Qt.\"\n#error \"(The moc has changed too"
1241 " much.)\"\n", QT_VERSION_STR);
1242 fprintf(out,
"#endif\n\n");
1244#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
)
1245 fprintf(out,
"#ifndef Q_CONSTINIT\n"
1246 "#define Q_CONSTINIT\n"
1250 fprintf(out,
"QT_WARNING_PUSH\n");
1251 fprintf(out,
"QT_WARNING_DISABLE_DEPRECATED\n");
1252 fprintf(out,
"QT_WARNING_DISABLE_GCC(\"-Wuseless-cast\")\n");
1255 for (ClassDef &def : classList) {
1256 Generator generator(
this, &def, metaTypes, knownQObjectClasses, knownGadgets, out,
1257 requireCompleteTypes);
1258 generator.generateCode();
1261 if (Q_UNLIKELY(generator.registeredStringsCount() >= std::numeric_limits<
int>::max())) {
1262 error(
"internal limit exceeded: number of parsed strings is too big.");
1268 fprintf(out,
"QT_WARNING_POP\n");
1271 QJsonObject mocData;
1272 mocData[
"outputRevision"_L1] = mocOutputRevision;
1273 mocData[
"inputFile"_L1] = QLatin1StringView(fn.constData());
1275 QJsonArray classesJsonFormatted;
1277 for (
const ClassDef &cdef: std::as_const(classList))
1278 classesJsonFormatted.append(cdef.toJson());
1280 if (!classesJsonFormatted.isEmpty())
1281 mocData[
"classes"_L1] = classesJsonFormatted;
1284 fputs(jsonDoc.toJson().constData(), jsonOutput);
1415 auto checkIsFunction = [&](
const QByteArray &def,
const char *name) {
1416 if (def.endsWith(
')')) {
1417 QByteArray msg =
"Providing a function for ";
1419 msg +=
" in a property declaration is not be supported in Qt 6.";
1420 error(msg.constData());
1424 while (test(IDENTIFIER)) {
1425 const Symbol &lsym = symbol();
1426 const QByteArrayView l = lsym.lexemView();
1427 if (l[0] ==
'C' && l ==
"CONSTANT") {
1430 }
else if (l[0] ==
'F' && l ==
"FINAL") {
1433 }
else if (l[0] ==
'N' && l ==
"NAME") {
1435 propDef.name = lexem();
1437 }
else if (l[0] ==
'R' && l ==
"REQUIRED") {
1440 }
else if (l[0] ==
'R' && l ==
"REVISION" && test(LPAREN)) {
1448 v = lexemUntil(RPAREN);
1449 v = v.mid(1, v.size() - 2);
1450 }
else if (test(INTEGER_LITERAL)) {
1452 if (l !=
"REVISION")
1454 }
else if (test(DEFAULT)) {
1456 if (l !=
"READ" && l !=
"WRITE")
1462 v2 = lexemUntil(RPAREN);
1463 else if (v !=
"true" && v !=
"false")
1476 else if (l ==
"RESET")
1478 else if (l ==
"REVISION") {
1480 const int minor = v.toInt(&ok);
1481 if (!ok || !QTypeRevision::isValidSegment(minor))
1488 if (l ==
"SCRIPTABLE") {
1489 propDef.scriptable = v + v2;
1490 checkIsFunction(propDef.scriptable,
"SCRIPTABLE");
1491 }
else if (l ==
"STORED") {
1492 propDef.stored = v + v2;
1493 checkIsFunction(propDef.stored,
"STORED");
1497 case 'W':
if (l !=
"WRITE") error(lsym);
1500 case 'B':
if (l !=
"BINDABLE") error(lsym);
1503 case 'D':
if (l !=
"DESIGNABLE") error(lsym);
1504 propDef.designable = v + v2;
1505 checkIsFunction(propDef.designable,
"DESIGNABLE");
1507 case 'N':
if (l !=
"NOTIFY") error(lsym);
1510 case 'U':
if (l !=
"USER") error(lsym);
1511 propDef.user = v + v2;
1512 checkIsFunction(propDef.user,
"USER");
1518 if (propDef
.constant && !propDef.write.isNull()) {
1519 const QByteArray msg =
"Property declaration " + propDef.name
1520 +
" is both WRITEable and CONSTANT. CONSTANT will be ignored.";
1522 warning(msg.constData());
1524 if (propDef
.constant && !propDef.notify.isNull()) {
1525 const QByteArray msg =
"Property declaration " + propDef.name
1526 +
" is both NOTIFYable and CONSTANT. CONSTANT will be ignored.";
1528 warning(msg.constData());
1530 if (propDef
.constant && !propDef.bind.isNull()) {
1531 const QByteArray msg =
"Property declaration " + propDef.name
1532 +
" is both BINDable and CONSTANT. CONSTANT will be ignored.";
1534 warning(msg.constData());
1536 if (propDef.read ==
"default" && propDef.bind.isNull()) {
1537 const QByteArray msg =
"Property declaration " + propDef.name
1538 +
" is not BINDable but default-READable. READ will be ignored.";
1540 warning(msg.constData());
1542 if (propDef.write ==
"default" && propDef.bind.isNull()) {
1543 const QByteArray msg =
"Property declaration " + propDef.name
1544 +
" is not BINDable but default-WRITEable. WRITE will be ignored.";
1546 warning(msg.constData());
1563 QByteArray metaData;
1564 while (test(IDENTIFIER)) {
1565 QByteArray l = lexem();
1567 next(STRING_LITERAL);
1568 def->pluginData.iid = unquotedLexem();
1569 }
else if (l ==
"URI") {
1570 next(STRING_LITERAL);
1571 def->pluginData.uri = unquotedLexem();
1572 }
else if (l ==
"FILE") {
1573 next(STRING_LITERAL);
1574 QByteArrayView metaDataFile = unquotedLexemView();
1575 QFileInfo fi(QFileInfo(QString::fromLocal8Bit(currentFilenames.top())).dir(),
1576 QString::fromLocal8Bit(metaDataFile));
1577 for (
const IncludePath &p : std::as_const(includes)) {
1580 if (p.isFrameworkPath)
1583 fi.setFile(QString::fromLocal8Bit(p.path), QString::fromLocal8Bit(metaDataFile));
1591 const QByteArray msg =
"Plugin Metadata file " + lexemView()
1592 +
" does not exist. Declaration will be ignored";
1593 error(msg.constData());
1596 QFile file(fi.canonicalFilePath());
1597 if (!file.open(QFile::ReadOnly)) {
1598 QByteArray msg =
"Plugin Metadata file " + lexemView() +
" could not be opened: "
1599 + file.errorString().toUtf8();
1600 error(msg.constData());
1603 parsedPluginMetadataFiles.append(fi.canonicalFilePath());
1604 metaData = file.readAll();
1608 if (!metaData.isEmpty()) {
1609 def->pluginData.metaData = QJsonDocument::fromJson(metaData);
1610 if (!def->pluginData.metaData.isObject()) {
1611 const QByteArray msg =
"Plugin Metadata file " + lexemView()
1612 +
" does not contain a valid JSON object. Declaration will be ignored";
1613 warning(msg.constData());
1614 def->pluginData.iid = QByteArray();
1615 def->pluginData.uri = QByteArray();
1849 switch(symbols.at(index-1).token) {
1850 case LBRACE: ++braceCount;
break;
1851 case LBRACK: ++brackCount;
break;
1852 case LPAREN: ++parenCount;
break;
1853 case LANGLE: ++angleCount;
break;
1861 qsizetype possible = -1;
1863 while (index < symbols.size()) {
1864 Token t = symbols.at(index++).token;
1866 case LBRACE: ++braceCount;
break;
1867 case RBRACE: --braceCount;
break;
1868 case LBRACK: ++brackCount;
break;
1869 case RBRACK: --brackCount;
break;
1870 case LPAREN: ++parenCount;
break;
1871 case RPAREN: --parenCount;
break;
1873 if (parenCount == 0 && braceCount == 0)
1877 if (parenCount == 0 && braceCount == 0)
1881 if (parenCount == 0 && braceCount == 0) {
1892 && (target != RANGLE || angleCount <= 0)) {
1893 if (target != COMMA || angleCount <= 0)
1898 if (target == COMMA && t == EQ && possible != -1) {
1903 if (braceCount < 0 || brackCount < 0 || parenCount < 0
1904 || (target == RANGLE && angleCount < 0)) {
1909 if (braceCount <= 0 && t == SEMIC) {
1915 if (target == COMMA && angleCount != 0 && possible != -1) {
1925 Q_ASSERT(!def->superclassList.isEmpty());
1926 const QByteArray &firstSuperclass = def->superclassList.at(0).classname;
1928 if (!knownQObjectClasses.contains(firstSuperclass)) {
1931 const QByteArray msg
1934 +
" contains the Q_OBJECT macro and inherits from "
1935 + def->superclassList.value(0)
1936 +
" but that is not a known QObject subclass. You may get compilation errors.";
1937 warning(msg.constData());
1942 auto isRegisteredInterface = [&def](QByteArrayView super) {
1943 auto matchesSuperClass = [&super](
const auto &ifaces) {
1944 return !ifaces.isEmpty() && ifaces.first().className == super;
1946 return std::any_of(def->interfaceList.cbegin(), def->interfaceList.cend(), matchesSuperClass);
1949 const auto end = def->superclassList.cend();
1950 auto it = def->superclassList.cbegin() + 1;
1951 for (; it != end; ++it) {
1952 const QByteArray &superClass = it->classname;
1953 if (knownQObjectClasses.contains(superClass)) {
1954 const QByteArray msg
1957 +
" inherits from two QObject subclasses "
1961 +
". This is not supported!";
1962 warning(msg.constData());
1965 if (interface2IdMap.contains(superClass)) {
1966 if (!isRegisteredInterface(superClass)) {
1967 const QByteArray msg
1970 +
" implements the interface "
1972 +
" but does not list it in Q_INTERFACES. qobject_cast to "
1974 +
" will not work!";
1975 warning(msg.constData());
1987 QDuplicateTracker<QByteArray> definedProperties(cdef->propertyList.size());
1988 auto hasNoAttributes = [&](
const PropertyDef &p) {
1989 if (definedProperties.hasSeen(p.name)) {
1990 QByteArray msg =
"The property '" + p.name +
"' is defined multiple times in class " + cdef->classname +
".";
1991 warning(msg.constData());
1994 if (p.read.isEmpty() && p.member.isEmpty() && p.bind.isEmpty()) {
1995 QByteArray msg =
"Property declaration " + p.name +
" has neither an associated QProperty<> member"
1996 ", nor a READ accessor function nor an associated MEMBER variable. The property will be invalid.";
1997 const auto &sym = p.location >= 0 ? symbolAt(p.location) : Symbol();
1998 warning(sym, msg.constData());
1999 if (p.write.isEmpty())
2004 cdef->propertyList.removeIf(hasNoAttributes);
2006 for (PropertyDef &p : cdef->propertyList) {
2007 for (
const FunctionDef &f : std::as_const(cdef->publicList)) {
2008 if (f.name != p.read)
2012 if (f.arguments.size())
2014 PropertyDef::Specification spec = PropertyDef::ValueSpec;
2015 QByteArray tmp = f.normalizedType;
2016 if (p.type ==
"QByteArray" && tmp ==
"const char *")
2018 if (tmp.left(6) ==
"const ")
2020 if (p.type != tmp && tmp.endsWith(
'*')) {
2022 spec = PropertyDef::PointerSpec;
2023 }
else if (f.type.name.endsWith(
'&')) {
2024 spec = PropertyDef::ReferenceSpec;
2031 if (!p.notify.isEmpty()) {
2033 for (
int j = 0; j <
int(cdef->signalList.size()); ++j) {
2034 const FunctionDef &f = cdef->signalList.at(j);
2035 if (f.name != p.notify) {
2042 p.notifyId = notifyId;
2043 if (notifyId == -1) {
2044 const int index =
int(cdef->nonClassSignalList.indexOf(p.notify));
2046 cdef->nonClassSignalList << p.notify;
2047 p.notifyId =
int(-1 - cdef->nonClassSignalList.size());
2049 p.notifyId =
int(-2 - index);
2059 cls[
"className"_L1] = QString::fromUtf8(classname.constData());
2060 cls[
"qualifiedClassName"_L1] = QString::fromUtf8(qualified.constData());
2061 cls[
"lineNumber"_L1] = lineNumber;
2063 cls[
"final"_L1] =
true;
2065 QJsonArray classInfos;
2066 for (
const auto &info: std::as_const(classInfoList)) {
2067 QJsonObject infoJson;
2068 infoJson[
"name"_L1] = QString::fromUtf8(info.name);
2069 infoJson[
"value"_L1] = QString::fromUtf8(info.value);
2070 classInfos.append(infoJson);
2073 if (classInfos.size())
2074 cls[
"classInfos"_L1] = classInfos;
2076 int methodIndex = 0;
2077 const auto appendFunctions
2078 = [&cls, &methodIndex](
const QString &type,
const QList<
FunctionDef> &funcs) {
2079 QJsonArray jsonFuncs;
2081 for (
const FunctionDef &fdef: funcs)
2082 jsonFuncs.append(fdef.toJson(methodIndex++));
2084 if (!jsonFuncs.isEmpty())
2085 cls[type] = jsonFuncs;
2089 appendFunctions(
"signals"_L1, signalList);
2090 appendFunctions(
"slots"_L1, slotList);
2091 appendFunctions(
"methods"_L1, methodList);
2095 appendFunctions(
"constructors"_L1, constructorList);
2099 for (
const PropertyDef &propDef: std::as_const(propertyList))
2100 props.append(propDef.toJson());
2102 if (!props.isEmpty())
2103 cls[
"properties"_L1] = props;
2106 cls[
"object"_L1] =
true;
2108 cls[
"gadget"_L1] =
true;
2110 cls[
"namespace"_L1] =
true;
2112 QJsonArray superClasses;
2114 for (
const auto &super: std::as_const(superclassList)) {
2115 QJsonObject superCls;
2116 superCls[
"name"_L1] = QString::fromUtf8(super.classname);
2117 if (super.classname != super.qualified)
2118 superCls[
"fullyQualifiedName"_L1] = QString::fromUtf8(super.qualified);
2119 FunctionDef::accessToJson(&superCls, super.access);
2120 superClasses.append(superCls);
2123 if (!superClasses.isEmpty())
2124 cls[
"superClasses"_L1] = superClasses;
2127 for (
const EnumDef &enumDef: std::as_const(enumList))
2128 enums.append(enumDef.toJson(*
this));
2129 if (!enums.isEmpty())
2130 cls[
"enums"_L1] = enums;
2133 for (
const QList<Interface> &ifaceList : interfaceList) {
2134 QJsonArray jsonList;
2135 for (
const Interface &iface: ifaceList) {
2136 QJsonObject ifaceJson;
2137 ifaceJson[
"id"_L1] = QString::fromUtf8(iface.interfaceId);
2138 ifaceJson[
"className"_L1] = QString::fromUtf8(iface.className);
2139 jsonList.append(ifaceJson);
2141 ifaces.append(jsonList);
2143 if (!ifaces.isEmpty())
2144 cls[
"interfaces"_L1] = ifaces;