diff options
Diffstat (limited to 'src/tools/moc')
-rw-r--r-- | src/tools/moc/generator.cpp | 14 | ||||
-rw-r--r-- | src/tools/moc/generator.h | 2 | ||||
-rw-r--r-- | src/tools/moc/moc.cpp | 56 | ||||
-rw-r--r-- | src/tools/moc/moc.h | 75 | ||||
-rw-r--r-- | src/tools/moc/parser.h | 6 | ||||
-rwxr-xr-x | src/tools/moc/util/generate.sh | 2 | ||||
-rw-r--r-- | src/tools/moc/util/generate_keywords.pro | 2 |
7 files changed, 86 insertions, 71 deletions
diff --git a/src/tools/moc/generator.cpp b/src/tools/moc/generator.cpp index c8882343f4..02c1fbd394 100644 --- a/src/tools/moc/generator.cpp +++ b/src/tools/moc/generator.cpp @@ -619,7 +619,7 @@ void Generator::generateCode() fprintf(out, "// a) You are using a NOTIFY signal that does not exist. Fix it.\n"); fprintf(out, "// b) You are using a NOTIFY signal that does exist (in a parent class) but has a non-empty parameter list. This is a moc limitation.\n"); fprintf(out, "Q_DECL_UNUSED static void checkNotifySignalValidity_%s(%s *t) {\n", qualifiedClassNameIdentifier.constData(), cdef->qualified.constData()); - for (const QByteArray &nonClassSignal : cdef->nonClassSignalList) + for (const QByteArray &nonClassSignal : qAsConst(cdef->nonClassSignalList)) fprintf(out, " t->%s();\n", nonClassSignal.constData()); fprintf(out, "}\n"); } @@ -1194,9 +1194,9 @@ void Generator::generateStaticMetacall() #ifndef QT_NO_DEBUG fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); #endif - fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + fprintf(out, " auto *_t = static_cast<%s *>(_o);\n", cdef->classname.constData()); } else { - fprintf(out, " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + fprintf(out, " auto *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData()); } fprintf(out, " Q_UNUSED(_t)\n"); fprintf(out, " switch (_id) {\n"); @@ -1359,9 +1359,9 @@ void Generator::generateStaticMetacall() #ifndef QT_NO_DEBUG fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); #endif - fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + fprintf(out, " auto *_t = static_cast<%s *>(_o);\n", cdef->classname.constData()); } else { - fprintf(out, " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + fprintf(out, " auto *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData()); } fprintf(out, " Q_UNUSED(_t)\n"); if (needTempVarForGet) @@ -1405,9 +1405,9 @@ void Generator::generateStaticMetacall() #ifndef QT_NO_DEBUG fprintf(out, " Q_ASSERT(staticMetaObject.cast(_o));\n"); #endif - fprintf(out, " %s *_t = static_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + fprintf(out, " auto *_t = static_cast<%s *>(_o);\n", cdef->classname.constData()); } else { - fprintf(out, " %s *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData(), cdef->classname.constData()); + fprintf(out, " auto *_t = reinterpret_cast<%s *>(_o);\n", cdef->classname.constData()); } fprintf(out, " Q_UNUSED(_t)\n"); fprintf(out, " void *_v = _a[0];\n"); diff --git a/src/tools/moc/generator.h b/src/tools/moc/generator.h index 134166580b..eae0353199 100644 --- a/src/tools/moc/generator.h +++ b/src/tools/moc/generator.h @@ -39,7 +39,7 @@ class Generator ClassDef *cdef; QVector<uint> meta_data; public: - Generator(ClassDef *classDef, const QVector<QByteArray> &metaTypes, const QHash<QByteArray, QByteArray> &knownQObjectClasses, const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile = 0); + Generator(ClassDef *classDef, const QVector<QByteArray> &metaTypes, const QHash<QByteArray, QByteArray> &knownQObjectClasses, const QHash<QByteArray, QByteArray> &knownGadgets, FILE *outfile = nullptr); void generateCode(); private: bool registerableMetaType(const QByteArray &propertyType); diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 76816960ff..2f52dd6ca0 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -159,6 +159,7 @@ Type Moc::parseType() bool isVoid = false; type.firstToken = lookup(); for (;;) { + skipCxxAttributes(); switch (next()) { case SIGNED: case UNSIGNED: @@ -188,8 +189,11 @@ Type Moc::parseType() } break; } + + skipCxxAttributes(); test(ENUM) || test(CLASS) || test(STRUCT); for(;;) { + skipCxxAttributes(); switch (next()) { case IDENTIFIER: // void mySlot(unsigned myArg) @@ -260,7 +264,7 @@ bool Moc::parseEnum(EnumDef *def) { bool isTypdefEnum = false; // typedef enum { ... } Foo; - if (test(CLASS)) + if (test(CLASS) || test(STRUCT)) def->isEnumClass = true; if (test(IDENTIFIER)) { @@ -281,6 +285,7 @@ bool Moc::parseEnum(EnumDef *def) break; next(IDENTIFIER); def->values += lexem(); + skipCxxAttributes(); } while (test(EQ) ? until(COMMA) : test(COMMA)); next(RBRACE); if (isTypdefEnum) { @@ -356,6 +361,15 @@ bool Moc::testFunctionAttribute(Token tok, FunctionDef *def) return false; } +bool Moc::skipCxxAttributes() +{ + auto rewind = index; + if (test(LBRACK) && test(LBRACK) && until(RBRACK) && test(RBRACK)) + return true; + index = rewind; + return false; +} + bool Moc::testFunctionRevision(FunctionDef *def) { if (test(Q_REVISION_TOKEN)) { @@ -381,7 +395,7 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) //skip modifiers and attributes while (test(INLINE) || (test(STATIC) && (def->isStatic = true) == true) || (test(VIRTUAL) && (def->isVirtual = true) == true) //mark as virtual - || testFunctionAttribute(def) || testFunctionRevision(def)) {} + || skipCxxAttributes() || testFunctionAttribute(def) || testFunctionRevision(def)) {} bool templateFunction = (lookup() == TEMPLATE); def->type = parseType(); if (def->type.name.isEmpty()) { @@ -454,10 +468,11 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) until(RBRACE); else if ((def->isAbstract = test(EQ))) until(SEMIC); + else if (skipCxxAttributes()) + until(SEMIC); else error(); } - if (scopedFunctionName) { const QByteArray msg = "Function declaration " + def->name + " contains extra qualification. Ignoring as signal or slot."; @@ -475,7 +490,7 @@ bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def) //skip modifiers and attributes while (test(EXPLICIT) || test(INLINE) || (test(STATIC) && (def->isStatic = true) == true) || (test(VIRTUAL) && (def->isVirtual = true) == true) //mark as virtual - || testFunctionAttribute(def) || testFunctionRevision(def)) {} + || skipCxxAttributes() || testFunctionAttribute(def) || testFunctionRevision(def)) {} bool tilde = test(TILDE); def->type = parseType(); if (def->type.name.isEmpty()) @@ -565,6 +580,7 @@ void Moc::parse() } else if (!test(SEMIC)) { NamespaceDef def; def.classname = nsName; + def.doGenerate = currentFilenames.size() <= 1; next(LBRACE); def.begin = index - 1; @@ -572,25 +588,22 @@ void Moc::parse() def.end = index; index = def.begin + 1; - const bool parseNamespace = currentFilenames.size() <= 1; - if (parseNamespace) { - for (int i = namespaceList.size() - 1; i >= 0; --i) { - if (inNamespace(&namespaceList.at(i))) { - def.qualified.prepend(namespaceList.at(i).classname + "::"); - } - } - for (const QByteArray &ns : nested) { - NamespaceDef parentNs; - parentNs.classname = ns; - parentNs.qualified = def.qualified; - def.qualified += ns + "::"; - parentNs.begin = def.begin; - parentNs.end = def.end; - namespaceList += parentNs; + for (int i = namespaceList.size() - 1; i >= 0; --i) { + if (inNamespace(&namespaceList.at(i))) { + def.qualified.prepend(namespaceList.at(i).classname + "::"); } } + for (const QByteArray &ns : nested) { + NamespaceDef parentNs; + parentNs.classname = ns; + parentNs.qualified = def.qualified; + def.qualified += ns + "::"; + parentNs.begin = def.begin; + parentNs.end = def.end; + namespaceList += parentNs; + } - while (parseNamespace && inNamespace(&def) && hasNext()) { + while (inNamespace(&def) && hasNext()) { switch (next()) { case NAMESPACE: if (test(IDENTIFIER)) { @@ -915,7 +928,8 @@ void Moc::parse() } else { knownGadgets.insert(def.classname, def.qualified); knownGadgets.insert(def.qualified, def.qualified); - classList += def; + if (n.doGenerate) + classList += def; } } } diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index d98c73e1a0..2bba8a5bb9 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -83,57 +83,53 @@ Q_DECLARE_TYPEINFO(ArgumentDef, Q_MOVABLE_TYPE); struct FunctionDef { - FunctionDef(): returnTypeIsVolatile(false), access(Private), isConst(false), isVirtual(false), isStatic(false), - inlineCode(false), wasCloned(false), isCompat(false), isInvokable(false), - isScriptable(false), isSlot(false), isSignal(false), isPrivateSignal(false), - isConstructor(false), isDestructor(false), isAbstract(false), revision(0) {} Type type; + QVector<ArgumentDef> arguments; QByteArray normalizedType; QByteArray tag; QByteArray name; - bool returnTypeIsVolatile; - - QVector<ArgumentDef> arguments; + QByteArray inPrivateClass; enum Access { Private, Protected, Public }; - Access access; - bool isConst; - bool isVirtual; - bool isStatic; - bool inlineCode; - bool wasCloned; - - QByteArray inPrivateClass; - bool isCompat; - bool isInvokable; - bool isScriptable; - bool isSlot; - bool isSignal; - bool isPrivateSignal; - bool isConstructor; - bool isDestructor; - bool isAbstract; - - int revision; + Access access = Private; + int revision = 0; + + bool isConst = false; + bool isVirtual = false; + bool isStatic = false; + bool inlineCode = false; + bool wasCloned = false; + + bool returnTypeIsVolatile = false; + + bool isCompat = false; + bool isInvokable = false; + bool isScriptable = false; + bool isSlot = false; + bool isSignal = false; + bool isPrivateSignal = false; + bool isConstructor = false; + bool isDestructor = false; + bool isAbstract = false; }; Q_DECLARE_TYPEINFO(FunctionDef, Q_MOVABLE_TYPE); struct PropertyDef { - PropertyDef():notifyId(-1), constant(false), final(false), gspec(ValueSpec), revision(0){} - QByteArray name, type, member, read, write, reset, designable, scriptable, editable, stored, user, notify, inPrivateClass; - int notifyId; // -1 means no notifyId, >= 0 means signal defined in this class, < -1 means signal not defined in this class - bool constant; - bool final; - enum Specification { ValueSpec, ReferenceSpec, PointerSpec }; - Specification gspec; bool stdCppSet() const { QByteArray s("set"); s += toupper(name[0]); s += name.mid(1); return (s == write); } - int revision; + + QByteArray name, type, member, read, write, reset, designable, scriptable, editable, stored, user, notify, inPrivateClass; + int notifyId = -1; // -1 means no notifyId, >= 0 means signal defined in this class, < -1 means signal not defined in this class + enum Specification { ValueSpec, ReferenceSpec, PointerSpec }; + Specification gspec = ValueSpec; + int revision = 0; + bool constant = false; + bool final = false; }; Q_DECLARE_TYPEINFO(PropertyDef, Q_MOVABLE_TYPE); @@ -169,9 +165,6 @@ struct ClassDef : BaseDef { }; QVector<QVector<Interface> >interfaceList; - bool hasQObject = false; - bool hasQGadget = false; - struct PluginData { QByteArray iid; QMap<QString, QJsonArray> metaArgs; @@ -181,17 +174,21 @@ struct ClassDef : BaseDef { QVector<FunctionDef> constructorList; QVector<FunctionDef> signalList, slotList, methodList, publicList; QVector<QByteArray> nonClassSignalList; - int notifyableProperties = 0; QVector<PropertyDef> propertyList; + int notifyableProperties = 0; int revisionedMethods = 0; int revisionedProperties = 0; + bool hasQObject = false; + bool hasQGadget = false; + }; Q_DECLARE_TYPEINFO(ClassDef, Q_MOVABLE_TYPE); Q_DECLARE_TYPEINFO(ClassDef::Interface, Q_MOVABLE_TYPE); struct NamespaceDef : BaseDef { bool hasQNamespace = false; + bool doGenerate = false; }; Q_DECLARE_TYPEINFO(NamespaceDef, Q_MOVABLE_TYPE); @@ -260,6 +257,8 @@ public: bool testFunctionAttribute(Token tok, FunctionDef *def); bool testFunctionRevision(FunctionDef *def); + bool skipCxxAttributes(); + void checkSuperClasses(ClassDef *def); void checkProperties(ClassDef* cdef); }; diff --git a/src/tools/moc/parser.h b/src/tools/moc/parser.h index bedcbbf7e2..63f4cf0d9a 100644 --- a/src/tools/moc/parser.h +++ b/src/tools/moc/parser.h @@ -69,9 +69,9 @@ public: inline const Symbol &symbol() { return symbols.at(index-1);} Q_NORETURN void error(int rollback); - Q_NORETURN void error(const char *msg = 0); - void warning(const char * = 0); - void note(const char * = 0); + Q_NORETURN void error(const char *msg = nullptr); + void warning(const char * = nullptr); + void note(const char * = nullptr); }; diff --git a/src/tools/moc/util/generate.sh b/src/tools/moc/util/generate.sh index 3894be1309..5460d28924 100755 --- a/src/tools/moc/util/generate.sh +++ b/src/tools/moc/util/generate.sh @@ -27,6 +27,8 @@ ## ############################################################################# +set -ex + qmake make cat licenseheader.txt > ../keywords.cpp diff --git a/src/tools/moc/util/generate_keywords.pro b/src/tools/moc/util/generate_keywords.pro index 88e5553f54..2bbc3ced61 100644 --- a/src/tools/moc/util/generate_keywords.pro +++ b/src/tools/moc/util/generate_keywords.pro @@ -1,4 +1,4 @@ CONFIG -= moc -mac:CONFIG -= app_bundle +CONFIG += cmdline SOURCES += generate_keywords.cpp |