diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-03-13 17:59:35 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-06-16 00:07:01 +0200 |
commit | 44b5ad01f0da55a351e0855e1173acfbef77221d (patch) | |
tree | 2b00f9c8b46805d19ad026394562121ecb7e29a9 /src/tools/moc | |
parent | 3025dc597fd1026b7c1aae55fd576fda154ff1c1 (diff) |
moc: Handle attributes after meta-method tag
We so far only handled them if they came at the very start of the method
declaration.
This patch ensures that we also handle them after the meta-method tag
(but before the actual type).
Unifying parseFunction and parseMaybeFunction to avoid the need to
munally keep them in sync is left for another day.
Fixes: QTBUG-111330
Pick-to: 6.6 6.5 6.5.2 6.2
Change-Id: Ic94edb69f04b9150aea2c8e6d004a8b9e5cf12ec
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/tools/moc')
-rw-r--r-- | src/tools/moc/moc.cpp | 21 | ||||
-rw-r--r-- | src/tools/moc/moc.h | 1 |
2 files changed, 18 insertions, 4 deletions
diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 39fc5ca466..058df18f42 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -412,8 +412,7 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) def->isVirtual = false; def->isStatic = false; //skip modifiers and attributes - while (test(INLINE) || (test(STATIC) && (def->isStatic = true) == true) || - (test(VIRTUAL) && (def->isVirtual = true) == true) //mark as virtual + while (testForFunctionModifiers(def) || skipCxxAttributes() || testFunctionAttribute(def) || testFunctionRevision(def)) {} bool templateFunction = (lookup() == TEMPLATE); def->type = parseType(); @@ -429,6 +428,10 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) scopedFunctionName = def->type.isScoped; def->type = Type("int"); } else { + // we might have modifiers and attributes after a tag + // note that testFunctionAttribute is handled further below, + // and revisions and attributes must come first + while (testForFunctionModifiers(def)) {} Type tempType = parseType();; while (!tempType.name.isEmpty() && lookup() != LPAREN) { if (testFunctionAttribute(def->type.firstToken, def)) @@ -512,14 +515,20 @@ bool Moc::parseFunction(FunctionDef *def, bool inMacro) return true; } +bool Moc::testForFunctionModifiers(FunctionDef *def) +{ + return test(EXPLICIT) || test(INLINE) || + (test(STATIC) && (def->isStatic = true)) || + (test(VIRTUAL) && (def->isVirtual = true)); +} + // like parseFunction, but never aborts with an error bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def) { def->isVirtual = false; def->isStatic = false; //skip modifiers and attributes - while (test(EXPLICIT) || test(INLINE) || (test(STATIC) && (def->isStatic = true) == true) || - (test(VIRTUAL) && (def->isVirtual = true) == true) //mark as virtual + while (testForFunctionModifiers(def) || skipCxxAttributes() || testFunctionAttribute(def) || testFunctionRevision(def)) {} bool tilde = test(TILDE); def->type = parseType(); @@ -537,6 +546,10 @@ bool Moc::parseMaybeFunction(const ClassDef *cdef, FunctionDef *def) def->type = Type("int"); } } else { + // ### TODO: The condition before testForFunctionModifiers shoulnd't be necessary, + // but otherwise we end up with misparses + if (def->isSlot || def->isSignal || def->isInvokable) + while (testForFunctionModifiers(def)) {} Type tempType = parseType();; while (!tempType.name.isEmpty() && lookup() != LPAREN) { if (testFunctionAttribute(def->type.firstToken, def)) diff --git a/src/tools/moc/moc.h b/src/tools/moc/moc.h index 640e19e234..04f1c835ce 100644 --- a/src/tools/moc/moc.h +++ b/src/tools/moc/moc.h @@ -280,6 +280,7 @@ public: void checkSuperClasses(ClassDef *def); void checkProperties(ClassDef* cdef); + bool testForFunctionModifiers(FunctionDef *def); void checkListSizes(const ClassDef &def); }; |