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;
606 while (test(IDENTIFIER))
614 if (def->type.name ==
"auto" && test(ARROW))
615 def->type = parseType();
617 if (scopedFunctionName
619 const QByteArray msg =
"parsemaybe: Function declaration " + def->name
620 +
" contains extra qualification. Ignoring as signal or slot.";
621 warning(msg.constData());
626 QList<QByteArray> typeNameParts = normalizeType(def->type.name).split(
' ');
627 if (typeNameParts.contains(
"auto")) {
629 error(
"Function declared with auto as return type but missing trailing return type. "
630 "Return type deduction is not supported.");
634 if (def->type.referenceType == Type::Reference) {
635 QByteArray rawName = def->type.rawName;
636 def->type = Type(
"void");
637 def->type.rawName = rawName;
640 def->normalizedType = normalizeType(def->type.name);
668 if (Q_UNLIKELY(def.nonClassSignalList.size() > std::numeric_limits<
int>::max()))
669 error(
"number of signals defined in parent class(es) exceeds "
670 "std::numeric_limits<int>::max().");
672 if (Q_UNLIKELY(def.propertyList.size() > std::numeric_limits<
int>::max()))
673 error(
"number of bindable properties exceeds std::numeric_limits<int>::max().");
675 if (Q_UNLIKELY(def.classInfoList.size() > std::numeric_limits<
int>::max()))
676 error(
"number of times Q_CLASSINFO macro is used exceeds "
677 "std::numeric_limits<int>::max().");
679 if (Q_UNLIKELY(def.enumList.size() > std::numeric_limits<
int>::max()))
680 error(
"number of enumerations exceeds std::numeric_limits<int>::max().");
682 if (Q_UNLIKELY(def.superclassList.size() > std::numeric_limits<
int>::max()))
683 error(
"number of super classes exceeds std::numeric_limits<int>::max().");
685 if (Q_UNLIKELY(def.constructorList.size() > std::numeric_limits<
int>::max()))
686 error(
"number of constructor parameters exceeds std::numeric_limits<int>::max().");
688 if (Q_UNLIKELY(def.signalList.size() > std::numeric_limits<
int>::max()))
689 error(
"number of signals exceeds std::numeric_limits<int>::max().");
691 if (Q_UNLIKELY(def.slotList.size() > std::numeric_limits<
int>::max()))
692 error(
"number of declared slots exceeds std::numeric_limits<int>::max().");
694 if (Q_UNLIKELY(def.methodList.size() > std::numeric_limits<
int>::max()))
695 error(
"number of methods exceeds std::numeric_limits<int>::max().");
697 if (Q_UNLIKELY(def.publicList.size() > std::numeric_limits<
int>::max()))
698 error(
"number of public functions declared in this class exceeds "
699 "std::numeric_limits<int>::max().");
705 bool templateClass =
false;
710 qsizetype rewind = index;
711 if (test(IDENTIFIER)) {
712 QByteArray nsName = lexem();
713 QByteArrayList nested;
714 while (test(SCOPE)) {
716
717
718
719
722 nested.append(nsName);
728 }
else if (test(LPAREN)) {
731 }
else if (!test(SEMIC)) {
733 def.classname = nsName;
734 def.lineNumber = symbol().lineNum;
735 def.doGenerate = currentFilenames.size() <= 1;
738 def.begin = index - 1;
741 index = def.begin + 1;
745 for (
const QByteArray &ns : nested) {
746 NamespaceDef parentNs;
747 parentNs.classname = ns;
748 parentNs.qualified = def.qualified;
749 def.qualified += ns +
"::";
750 parentNs.begin = def.begin;
751 parentNs.end = def.end;
752 namespaceList += parentNs;
758 if (test(IDENTIFIER)) {
759 while (test(SCOPE)) {
766 }
else if (!test(SEMIC)) {
771 case Q_NAMESPACE_TOKEN:
774 case Q_NAMESPACE_EXPORT_TOKEN:
776 while (test(IDENTIFIER))
782 case Q_ENUM_NS_TOKEN:
786 error(
"Q_ENUM can't be used in a Q_NAMESPACE, use Q_ENUM_NS instead");
789 case Q_FLAG_NS_TOKEN:
793 error(
"Q_FLAG can't be used in a Q_NAMESPACE, use Q_FLAG_NS instead");
795 case Q_DECLARE_FLAGS_TOKEN:
798 case Q_CLASSINFO_TOKEN:
799 parseClassInfo(&def);
801 case Q_MOC_INCLUDE_TOKEN:
809 def.enumList += enumDef;
822 namespaceList += def;
824 if (!def.hasQNamespace && (!def.classInfoList.isEmpty() || !def.enumDeclarations.isEmpty()))
825 error(
"Namespace declaration lacks Q_NAMESPACE macro.");
832 templateClass =
false;
835 templateClass =
true;
837 case MOC_INCLUDE_BEGIN:
838 currentFilenames.push(symbol().unquotedLexem());
840 case MOC_INCLUDE_END:
841 currentFilenames.pop();
843 case Q_DECLARE_INTERFACE_TOKEN:
846 case Q_DECLARE_METATYPE_TOKEN:
849 case Q_MOC_INCLUDE_TOKEN:
853 if (test(NAMESPACE)) {
854 while (test(SCOPE) || test(IDENTIFIER))
864 if (currentFilenames.size() <= 1)
876 case Q_GADGET_EXPORT_TOKEN:
878 while (test(IDENTIFIER))
894 QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
895 classHash.insert(def.classname, def.qualified);
896 classHash.insert(def.qualified, def.qualified);
901 if ((t != CLASS && t != STRUCT)|| currentFilenames.size() > 1)
905 Symbol qmlRegistrationMacroSymbol =
{};
910 switch ((t = next())) {
913 if (test(Q_SIGNALS_TOKEN))
914 error(
"Signals cannot have access specifier");
918 if (test(Q_SIGNALS_TOKEN))
919 error(
"Signals cannot have access specifier");
923 if (test(Q_SIGNALS_TOKEN))
924 error(
"Signals cannot have access specifier");
932 if (t >= Q_META_TOKEN_BEGIN && t < Q_META_TOKEN_END)
933 error(
"Meta object features not supported for nested classes");
937 case Q_SIGNALS_TOKEN:
941 switch (lookup(-1)) {
948 error(
"Missing access specifier for slots");
954 error(
"Template classes not supported by Q_OBJECT");
955 if (def.classname !=
"Qt" && def.classname !=
"QObject" && def.superclassList.isEmpty())
956 error(
"Class contains Q_OBJECT macro but does not inherit from QObject");
958 case Q_GADGET_EXPORT_TOKEN:
960 while (test(IDENTIFIER))
967 error(
"Template classes not supported by Q_GADGET");
969 case Q_PROPERTY_TOKEN:
972 case QT_ANONYMOUS_PROPERTY_TOKEN:
975 case Q_PLUGIN_METADATA_TOKEN:
982 case Q_ENUM_NS_TOKEN:
983 error(
"Q_ENUM_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_ENUM instead");
989 case Q_FLAG_NS_TOKEN:
990 error(
"Q_FLAG_NS can't be used in a Q_OBJECT/Q_GADGET, use Q_FLAG instead");
992 case Q_DECLARE_FLAGS_TOKEN:
995 case Q_CLASSINFO_TOKEN:
998 case Q_MOC_INCLUDE_TOKEN:
1001 case Q_INTERFACES_TOKEN:
1004 case Q_PRIVATE_SLOT_TOKEN:
1007 case Q_PRIVATE_PROPERTY_TOKEN:
1010 case QT_ANONYMOUS_PRIVATE_PROPERTY_TOKEN:
1016 def.enumList += enumDef;
1023 const QByteArrayView lex = lexemView();
1024 if (lex.startsWith(
"QML_")) {
1025 if ( lex ==
"QML_ELEMENT" || lex ==
"QML_NAMED_ELEMENT"
1026 || lex ==
"QML_ANONYMOUS" || lex ==
"QML_VALUE_TYPE") {
1027 qmlRegistrationMacroSymbol = symbol();
1035 qsizetype rewind = index--;
1039 def.constructorList += funcDef;
1040 handleDefaultArguments(&def.constructorList, funcDef);
1046 def.publicList += funcDef;
1048 def.slotList += funcDef;
1049 handleDefaultArguments(&def.slotList, funcDef);
1053 def.signalList += funcDef;
1054 handleDefaultArguments(&def.signalList, funcDef);
1058 def.methodList += funcDef;
1059 handleDefaultArguments(&def.methodList, funcDef);
1073
1074
1075
1077 QByteArray msg(
"Potential QML registration macro was found, but no header containing it was included.\n"
1078 "This might cause runtime errors in QML applications\n"
1079 "Include <QtQmlIntegration/qqmlintegration.h> or <QtQml/qqmlregistration.h> to fix this.");
1080 if (qmlMacroWarningIsFatal)
1081 error(qmlRegistrationMacroSymbol, msg.constData());
1083 warning(qmlRegistrationMacroSymbol, msg.constData());
1087 && def.propertyList.isEmpty() && def.enumDeclarations.isEmpty())
1091 if (!def.hasQObject && !def.hasQGadget)
1092 error(
"Class declaration lacks Q_OBJECT macro.");
1095 if (!def.pluginData.iid.isEmpty())
1096 def.pluginData.metaArgs = metaArgs;
1098 if (def
.hasQObject && !def.superclassList.isEmpty())
1106 QHash<QByteArray, QByteArray> &classHash = def.hasQObject ? knownQObjectClasses : knownGadgets;
1107 classHash.insert(def.classname, def.qualified);
1108 classHash.insert(def.qualified, def.qualified);
1111 for (
const auto &n : std::as_const(namespaceList)) {
1112 if (!n.hasQNamespace)
1115 static_cast<BaseDef &>(def) =
static_cast<BaseDef>(n);
1116 def.qualified += def.classname;
1117 def.hasQNamespace =
true;
1118 auto it = std::find_if(classList.begin(), classList.end(), [&def](
const ClassDef &val) {
1119 return def.classname == val.classname && def.qualified == val.qualified;
1122 if (it != classList.end()) {
1123 it->classInfoList += def.classInfoList;
1124 Q_ASSERT(it->classInfoList.size() <= std::numeric_limits<
int>::max());
1125 it->enumDeclarations.insert(def.enumDeclarations);
1126 it->enumList += def.enumList;
1127 Q_ASSERT(it->enumList.size() <= std::numeric_limits<
int>::max());
1128 it->flagAliases.insert(def.flagAliases);
1130 knownGadgets.insert(def.classname, def.qualified);
1131 knownGadgets.insert(def.qualified, def.qualified);
1186 static const QByteArrayList candidates = make_candidates();
1188 QByteArrayList required;
1189 required.reserve(candidates.size());
1191 bool needsQProperty =
false;
1193 for (
const auto &candidate : candidates) {
1194 const QByteArray pattern = candidate +
'<';
1196 for (
const auto &c : classes) {
1197 for (
const auto &p : c.propertyList)
1198 needsQProperty |= !p.bind.isEmpty();
1199 if (any_type_contains(c.propertyList, pattern) ||
1200 any_arg_contains(c.slotList, pattern) ||
1201 any_arg_contains(c.signalList, pattern) ||
1202 any_arg_contains(c.methodList, pattern)) {
1203 required.push_back(candidate);
1210 required.push_back(
"QProperty");
1217 QByteArrayView fn = strippedFileName();
1219 fprintf(out,
"/****************************************************************************\n"
1220 "** Meta object code from reading C++ file '%s'\n**\n" , fn.constData());
1221 fprintf(out,
"** Created by: The Qt Meta Object Compiler version %d (Qt %s)\n**\n" ,
mocOutputRevision, QT_VERSION_STR);
1222 fprintf(out,
"** WARNING! All changes made in this file will be lost!\n"
1223 "*****************************************************************************/\n\n");
1229 if (includePath.size() && !includePath.endsWith(
'/'))
1231 for (QByteArray inc : std::as_const(includeFiles)) {
1232 if (!inc.isEmpty() && inc.at(0) !=
'<' && inc.at(0) !=
'"') {
1233 if (includePath.size() && includePath !=
"./")
1234 inc.prepend(includePath);
1235 inc =
'\"' + inc +
'\"';
1237 fprintf(out,
"#include %s\n", inc.constData());
1240 if (classList.size() && classList.constFirst().classname ==
"Qt")
1241 fprintf(out,
"#include <QtCore/qobject.h>\n");
1243 fprintf(out,
"#include <QtCore/qmetatype.h>\n");
1245 fprintf(out,
"#include <QtCore/qplugin.h>\n");
1247 const auto qtContainers = requiredQtContainers(classList);
1248 for (
const QByteArray &qtContainer : qtContainers)
1249 fprintf(out,
"#include <QtCore/%s>\n", qtContainer.constData());
1251 fprintf(out,
"\n#include <QtCore/qtmochelpers.h>\n");
1253 fprintf(out,
"\n#include <memory>\n\n");
1254 fprintf(out,
"\n#include <QtCore/qxptype_traits.h>\n");
1256 fprintf(out,
"#if !defined(Q_MOC_OUTPUT_REVISION)\n"
1257 "#error \"The header file '%s' doesn't include <QObject>.\"\n", fn.constData());
1259 fprintf(out,
"#error \"This file was generated using the moc from %s."
1260 " It\"\n#error \"cannot be used with the include files from"
1261 " this version of Qt.\"\n#error \"(The moc has changed too"
1262 " much.)\"\n", QT_VERSION_STR);
1263 fprintf(out,
"#endif\n\n");
1265#if QT_VERSION <= QT_VERSION_CHECK(7
, 0
, 0
)
1266 fprintf(out,
"#ifndef Q_CONSTINIT\n"
1267 "#define Q_CONSTINIT\n"
1272 for (ClassDef &cdef : classList) {
1273 QList<EnumDef> enumList;
1274 for (EnumDef def : std::as_const(cdef.enumList)) {
1275 if (cdef.enumDeclarations.contains(def.name)) {
1278 def.enumName = def.name;
1279 QByteArray alias = cdef.flagAliases.value(def.name);
1280 if (cdef.enumDeclarations.contains(alias)) {
1282 def.flags |= cdef.enumDeclarations[alias];
1286 cdef.enumList = enumList;
1289 fprintf(out,
"QT_WARNING_PUSH\n");
1290 fprintf(out,
"QT_WARNING_DISABLE_DEPRECATED\n");
1291 fprintf(out,
"QT_WARNING_DISABLE_GCC(\"-Wuseless-cast\")\n");
1294 for (
const ClassDef &def : std::as_const(classList)) {
1295 Generator generator(
this, &def, metaTypes, knownQObjectClasses, knownGadgets, out,
1296 requireCompleteTypes);
1297 generator.generateCode();
1300 if (Q_UNLIKELY(generator.registeredStringsCount() >= std::numeric_limits<
int>::max())) {
1301 error(
"internal limit exceeded: number of parsed strings is too big.");
1307 fprintf(out,
"QT_WARNING_POP\n");
1310 QJsonObject mocData;
1311 mocData[
"outputRevision"_L1] = mocOutputRevision;
1312 mocData[
"inputFile"_L1] = QLatin1StringView(fn.constData());
1314 QJsonArray classesJsonFormatted;
1316 for (
const ClassDef &cdef: std::as_const(classList))
1317 classesJsonFormatted.append(cdef.toJson());
1319 if (!classesJsonFormatted.isEmpty())
1320 mocData[
"classes"_L1] = classesJsonFormatted;
1323 fputs(jsonDoc.toJson().constData(), jsonOutput);
1454 auto checkIsFunction = [&](
const QByteArray &def,
const char *name) {
1455 if (def.endsWith(
')')) {
1456 QByteArray msg =
"Providing a function for ";
1458 msg +=
" in a property declaration is not be supported in Qt 6.";
1459 error(msg.constData());
1463 while (test(IDENTIFIER)) {
1464 const Symbol &lsym = symbol();
1465 const QByteArrayView l = lsym.lexemView();
1466 if (l[0] ==
'C' && l ==
"CONSTANT") {
1469 }
else if (l[0] ==
'F' && l ==
"FINAL") {
1472 }
else if (l[0] ==
'N' && l ==
"NAME") {
1474 propDef.name = lexem();
1476 }
else if (l[0] ==
'O' && l ==
"OVERRIDE") {
1479 }
else if (l[0] ==
'R' && l ==
"REQUIRED") {
1482 }
else if (l[0] ==
'R' && l ==
"REVISION" && test(LPAREN)) {
1486 }
else if (l[0] ==
'V' && l ==
"VIRTUAL") {
1493 v = lexemUntil(RPAREN);
1494 v = v.mid(1, v.size() - 2);
1495 }
else if (test(INTEGER_LITERAL)) {
1497 if (l !=
"REVISION")
1499 }
else if (test(DEFAULT)) {
1501 if (l !=
"READ" && l !=
"WRITE")
1507 v2 = lexemUntil(RPAREN);
1508 else if (v !=
"true" && v !=
"false")
1521 else if (l ==
"RESET")
1523 else if (l ==
"REVISION") {
1525 const int minor = v.toInt(&ok);
1526 if (!ok || !QTypeRevision::isValidSegment(minor))
1533 if (l ==
"SCRIPTABLE") {
1534 propDef.scriptable = v + v2;
1535 checkIsFunction(propDef.scriptable,
"SCRIPTABLE");
1536 }
else if (l ==
"STORED") {
1537 propDef.stored = v + v2;
1538 checkIsFunction(propDef.stored,
"STORED");
1542 case 'W':
if (l !=
"WRITE") error(lsym);
1545 case 'B':
if (l !=
"BINDABLE") error(lsym);
1548 case 'D':
if (l !=
"DESIGNABLE") error(lsym);
1549 propDef.designable = v + v2;
1550 checkIsFunction(propDef.designable,
"DESIGNABLE");
1552 case 'N':
if (l !=
"NOTIFY") error(lsym);
1555 case 'U':
if (l !=
"USER") error(lsym);
1556 propDef.user = v + v2;
1557 checkIsFunction(propDef.user,
"USER");
1563 if (propDef
.constant && !propDef.write.isNull()) {
1564 const QByteArray msg =
"Property declaration " + propDef.name
1565 +
" is both WRITEable and CONSTANT. CONSTANT will be ignored.";
1567 warning(msg.constData());
1569 if (propDef
.constant && !propDef.notify.isNull()) {
1570 const QByteArray msg =
"Property declaration " + propDef.name
1571 +
" is both NOTIFYable and CONSTANT. CONSTANT will be ignored.";
1573 warning(msg.constData());
1575 if (propDef
.constant && !propDef.bind.isNull()) {
1576 const QByteArray msg =
"Property declaration " + propDef.name
1577 +
" is both BINDable and CONSTANT. CONSTANT will be ignored.";
1579 warning(msg.constData());
1581 if (propDef.read ==
"default" && propDef.bind.isNull()) {
1582 const QByteArray msg =
"Property declaration " + propDef.name
1583 +
" is not BINDable but default-READable. READ will be ignored.";
1585 warning(msg.constData());
1587 if (propDef.write ==
"default" && propDef.bind.isNull()) {
1588 const QByteArray msg =
"Property declaration " + propDef.name
1589 +
" is not BINDable but default-WRITEable. WRITE will be ignored.";
1591 warning(msg.constData());
1594 const QByteArray msg =
"Issue with property declaration " + propDef.name
1595 +
": VIRTUAL is redundant when overriding a property. The OVERRIDE "
1596 "must only be used when actually overriding an existing property; using it on a "
1597 "new property is an error.";
1598 error(msg.constData());
1601 const QByteArray msg =
"Issue with property declaration " + propDef.name
1602 +
": OVERRIDE is redundant when property is marked FINAL";
1603 error(msg.constData());
1606 const QByteArray msg =
"Issue with property declaration " + propDef.name
1607 +
": The VIRTUAL cannot be combined with FINAL, as these attributes are mutually "
1609 error(msg.constData());
1626 QByteArray metaData;
1627 while (test(IDENTIFIER)) {
1628 QByteArray l = lexem();
1630 next(STRING_LITERAL);
1631 def->pluginData.iid = unquotedLexem();
1632 }
else if (l ==
"URI") {
1633 next(STRING_LITERAL);
1634 def->pluginData.uri = unquotedLexem();
1635 }
else if (l ==
"FILE") {
1636 next(STRING_LITERAL);
1637 QByteArrayView metaDataFile = unquotedLexemView();
1638 QFileInfo fi(QFileInfo(QString::fromLocal8Bit(currentFilenames.top())).dir(),
1639 QString::fromLocal8Bit(metaDataFile));
1640 for (
const IncludePath &p : std::as_const(includes)) {
1643 if (p.isFrameworkPath)
1646 fi.setFile(QString::fromLocal8Bit(p.path), QString::fromLocal8Bit(metaDataFile));
1654 const QByteArray msg =
"Plugin Metadata file " + lexemView()
1655 +
" does not exist. Declaration will be ignored";
1656 error(msg.constData());
1659 QFile file(fi.canonicalFilePath());
1660 if (!file.open(QFile::ReadOnly)) {
1661 QByteArray msg =
"Plugin Metadata file " + lexemView() +
" could not be opened: "
1662 + file.errorString().toUtf8();
1663 error(msg.constData());
1666 parsedPluginMetadataFiles.append(fi.canonicalFilePath());
1667 metaData = file.readAll();
1671 if (!metaData.isEmpty()) {
1672 def->pluginData.metaData = QJsonDocument::fromJson(metaData);
1673 if (!def->pluginData.metaData.isObject()) {
1674 const QByteArray msg =
"Plugin Metadata file " + lexemView()
1675 +
" does not contain a valid JSON object. Declaration will be ignored";
1676 warning(msg.constData());
1677 def->pluginData.iid = QByteArray();
1678 def->pluginData.uri = QByteArray();
1793 while (test(IDENTIFIER)) {
1795 iface += ClassDef::Interface(lexem());
1796 while (test(SCOPE)) {
1797 iface.last().className += lexemView();
1799 iface.last().className += lexemView();
1801 while (test(COLON)) {
1803 iface += ClassDef::Interface(lexem());
1804 while (test(SCOPE)) {
1805 iface.last().className += lexemView();
1807 iface.last().className += lexemView();
1811 for (qsizetype i = 0; i < iface.size(); ++i) {
1812 const QByteArray iid = interface2IdMap.value(iface.at(i).className);
1814 error(
"Undefined interface");
1816 iface[i].interfaceId = iid;
1818 def->interfaceList += iface;
1912 switch(symbols.at(index-1).token) {
1913 case LBRACE: ++braceCount;
break;
1914 case LBRACK: ++brackCount;
break;
1915 case LPAREN: ++parenCount;
break;
1916 case LANGLE: ++angleCount;
break;
1924 qsizetype possible = -1;
1926 while (index < symbols.size()) {
1927 Token t = symbols.at(index++).token;
1929 case LBRACE: ++braceCount;
break;
1930 case RBRACE: --braceCount;
break;
1931 case LBRACK: ++brackCount;
break;
1932 case RBRACK: --brackCount;
break;
1933 case LPAREN: ++parenCount;
break;
1934 case RPAREN: --parenCount;
break;
1936 if (parenCount == 0 && braceCount == 0)
1940 if (parenCount == 0 && braceCount == 0)
1944 if (parenCount == 0 && braceCount == 0) {
1955 && (target != RANGLE || angleCount <= 0)) {
1956 if (target != COMMA || angleCount <= 0)
1961 if (target == COMMA && t == EQ && possible != -1) {
1966 if (braceCount < 0 || brackCount < 0 || parenCount < 0
1967 || (target == RANGLE && angleCount < 0)) {
1972 if (braceCount <= 0 && t == SEMIC) {
1978 if (target == COMMA && angleCount != 0 && possible != -1) {
1988 Q_ASSERT(!def->superclassList.isEmpty());
1989 const QByteArray &firstSuperclass = def->superclassList.at(0).classname;
1991 if (!knownQObjectClasses.contains(firstSuperclass)) {
1994 const QByteArray msg
1997 +
" contains the Q_OBJECT macro and inherits from "
1998 + def->superclassList.value(0)
1999 +
" but that is not a known QObject subclass. You may get compilation errors.";
2000 warning(msg.constData());
2005 auto isRegisteredInterface = [&def](QByteArrayView super) {
2006 auto matchesSuperClass = [&super](
const auto &ifaces) {
2007 return !ifaces.isEmpty() && ifaces.first().className == super;
2009 return std::any_of(def->interfaceList.cbegin(), def->interfaceList.cend(), matchesSuperClass);
2012 const auto end = def->superclassList.cend();
2013 auto it = def->superclassList.cbegin() + 1;
2014 for (; it != end; ++it) {
2015 const QByteArray &superClass = it->classname;
2016 if (knownQObjectClasses.contains(superClass)) {
2017 const QByteArray msg
2020 +
" inherits from two QObject subclasses "
2024 +
". This is not supported!";
2025 warning(msg.constData());
2028 if (interface2IdMap.contains(superClass)) {
2029 if (!isRegisteredInterface(superClass)) {
2030 const QByteArray msg
2033 +
" implements the interface "
2035 +
" but does not list it in Q_INTERFACES. qobject_cast to "
2037 +
" will not work!";
2038 warning(msg.constData());
2050 QDuplicateTracker<QByteArray> definedProperties(cdef->propertyList.size());
2051 auto hasNoAttributes = [&](
const PropertyDef &p) {
2052 if (definedProperties.hasSeen(p.name)) {
2053 QByteArray msg =
"The property '" + p.name +
"' is defined multiple times in class " + cdef->classname +
".";
2054 warning(msg.constData());
2057 if (p.read.isEmpty() && p.member.isEmpty() && p.bind.isEmpty()) {
2058 QByteArray msg =
"Property declaration " + p.name +
" has neither an associated QProperty<> member"
2059 ", nor a READ accessor function nor an associated MEMBER variable. The property will be invalid.";
2060 const auto &sym = p.location >= 0 ? symbolAt(p.location) : Symbol();
2061 warning(sym, msg.constData());
2062 if (p.write.isEmpty())
2067 cdef->propertyList.removeIf(hasNoAttributes);
2069 for (PropertyDef &p : cdef->propertyList) {
2070 for (
const FunctionDef &f : std::as_const(cdef->publicList)) {
2071 if (f.name != p.read)
2075 if (f.arguments.size())
2077 PropertyDef::Specification spec = PropertyDef::ValueSpec;
2078 QByteArray tmp = f.normalizedType;
2079 if (p.type ==
"QByteArray" && tmp ==
"const char *")
2081 if (tmp.left(6) ==
"const ")
2083 if (p.type != tmp && tmp.endsWith(
'*')) {
2085 spec = PropertyDef::PointerSpec;
2086 }
else if (f.type.name.endsWith(
'&')) {
2087 spec = PropertyDef::ReferenceSpec;
2094 if (!p.notify.isEmpty()) {
2096 for (
int j = 0; j <
int(cdef->signalList.size()); ++j) {
2097 const FunctionDef &f = cdef->signalList.at(j);
2098 if (f.name != p.notify) {
2105 p.notifyId = notifyId;
2106 if (notifyId == -1) {
2107 const int index =
int(cdef->nonClassSignalList.indexOf(p.notify));
2109 cdef->nonClassSignalList << p.notify;
2110 p.notifyId =
int(-1 - cdef->nonClassSignalList.size());
2112 p.notifyId =
int(-2 - index);
2122 cls[
"className"_L1] = QString::fromUtf8(classname.constData());
2123 cls[
"qualifiedClassName"_L1] = QString::fromUtf8(qualified.constData());
2124 cls[
"lineNumber"_L1] = lineNumber;
2126 cls[
"final"_L1] =
true;
2128 QJsonArray classInfos;
2129 for (
const auto &info: std::as_const(classInfoList)) {
2130 QJsonObject infoJson;
2131 infoJson[
"name"_L1] = QString::fromUtf8(info.name);
2132 infoJson[
"value"_L1] = QString::fromUtf8(info.value);
2133 classInfos.append(infoJson);
2136 if (classInfos.size())
2137 cls[
"classInfos"_L1] = classInfos;
2139 int methodIndex = 0;
2140 const auto appendFunctions
2141 = [&cls, &methodIndex](
const QString &type,
const QList<
FunctionDef> &funcs) {
2142 QJsonArray jsonFuncs;
2144 for (
const FunctionDef &fdef: funcs)
2145 jsonFuncs.append(fdef.toJson(methodIndex++));
2147 if (!jsonFuncs.isEmpty())
2148 cls[type] = jsonFuncs;
2152 appendFunctions(
"signals"_L1, signalList);
2153 appendFunctions(
"slots"_L1, slotList);
2154 appendFunctions(
"methods"_L1, methodList);
2158 appendFunctions(
"constructors"_L1, constructorList);
2162 for (
const PropertyDef &propDef: std::as_const(propertyList))
2163 props.append(propDef.toJson());
2165 if (!props.isEmpty())
2166 cls[
"properties"_L1] = props;
2169 cls[
"object"_L1] =
true;
2171 cls[
"gadget"_L1] =
true;
2173 cls[
"namespace"_L1] =
true;
2175 QJsonArray superClasses;
2177 for (
const auto &super: std::as_const(superclassList)) {
2178 QJsonObject superCls;
2179 superCls[
"name"_L1] = QString::fromUtf8(super.classname);
2180 if (super.classname != super.qualified)
2181 superCls[
"fullyQualifiedName"_L1] = QString::fromUtf8(super.qualified);
2182 FunctionDef::accessToJson(&superCls, super.access);
2183 superClasses.append(superCls);
2186 if (!superClasses.isEmpty())
2187 cls[
"superClasses"_L1] = superClasses;
2190 for (
const EnumDef &enumDef: std::as_const(enumList))
2191 enums.append(enumDef.toJson(*
this));
2192 if (!enums.isEmpty())
2193 cls[
"enums"_L1] = enums;
2196 for (
const QList<Interface> &ifaceList : interfaceList) {
2197 QJsonArray jsonList;
2198 for (
const Interface &iface: ifaceList) {
2199 QJsonObject ifaceJson;
2200 ifaceJson[
"id"_L1] = QString::fromUtf8(iface.interfaceId);
2201 ifaceJson[
"className"_L1] = QString::fromUtf8(iface.className);
2202 jsonList.append(ifaceJson);
2204 ifaces.append(jsonList);
2206 if (!ifaces.isEmpty())
2207 cls[
"interfaces"_L1] = ifaces;