diff options
-rw-r--r-- | abstractmetabuilder.cpp | 3 | ||||
-rw-r--r-- | abstractmetalang.h | 7 | ||||
-rw-r--r-- | tests/testaddfunction.cpp | 31 | ||||
-rw-r--r-- | tests/testaddfunction.h | 1 | ||||
-rw-r--r-- | typesystem.cpp | 13 | ||||
-rw-r--r-- | typesystem.h | 11 |
6 files changed, 62 insertions, 4 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp index 6ce0232ec..bc78cdd31 100644 --- a/abstractmetabuilder.cpp +++ b/abstractmetabuilder.cpp @@ -1884,6 +1884,9 @@ void AbstractMetaBuilder::decideUsagePattern(AbstractMetaType *metaType) } else if (type->isVoid()) { metaType->setTypeUsagePattern(AbstractMetaType::NativePointerPattern); + } else if (type->isVarargs()) { + metaType->setTypeUsagePattern(AbstractMetaType::VarargsPattern); + } else if (type->isString() && metaType->indirections() == 0 && (metaType->isConstant() == metaType->isReference() diff --git a/abstractmetalang.h b/abstractmetalang.h index eb51dc643..061d91365 100644 --- a/abstractmetalang.h +++ b/abstractmetalang.h @@ -320,6 +320,7 @@ public: NativePointerPattern, ContainerPattern, VariantPattern, + VarargsPattern, JObjectWrapperPattern, ArrayPattern, ThreadPattern @@ -456,6 +457,12 @@ public: return m_pattern == VariantPattern; } + // return true if the type was originally a varargs + bool isVarargs() const + { + return m_pattern == VarargsPattern; + } + // return true if the type was originally a JObjectWrapper or const JObjectWrapper & bool isJObjectWrapper() const { diff --git a/tests/testaddfunction.cpp b/tests/testaddfunction.cpp index 3188ca23d..5cdb74ecc 100644 --- a/tests/testaddfunction.cpp +++ b/tests/testaddfunction.cpp @@ -194,7 +194,6 @@ void TestAddFunction::testAddFunctionWithoutParenteses() QVERIFY(addedFunc); QVERIFY(addedFunc->hasInjectedCode()); QCOMPARE(addedFunc->injectedCodeSnips(CodeSnip::Any, TypeSystem::TargetLangCode).count(), 1); - } void TestAddFunction::testAddFunctionWithDefaultArgs() @@ -260,6 +259,36 @@ void TestAddFunction::testAddFunctionAtModuleLevel() QCOMPARE(snip.code(), QString("custom_code();")); } +void TestAddFunction::testAddFunctionWithVarargs() +{ + const char sig1[] = "func(int,char,...)"; + AddedFunction f1(sig1, "void"); + + QCOMPARE(f1.name(), QString("func")); + QCOMPARE(f1.arguments().count(), 3); + QVERIFY(!f1.isConstant()); + + const char cppCode[] = "struct A {};"; + const char xmlCode[] = "\ + <typesystem package=\"Foo\">\ + <primitive-type name='int'/> \ + <primitive-type name='char'/> \ + <value-type name='A'>\ + <add-function signature='func(int,char,...)'/>\ + </value-type>\ + </typesystem>"; + + TestUtil t(cppCode, xmlCode, false); + AbstractMetaClassList classes = t.builder()->classes(); + AbstractMetaClass* classA = classes.findClass("A"); + QVERIFY(classA); + const AbstractMetaFunction* addedFunc = classA->findFunction("func"); + QVERIFY(addedFunc); + const AbstractMetaArgument* arg = addedFunc->arguments().last(); + QVERIFY(arg->type()->isVarargs()); + QVERIFY(arg->type()->typeEntry()->isVarargs()); +} + QTEST_APPLESS_MAIN(TestAddFunction) #include "testaddfunction.moc" diff --git a/tests/testaddfunction.h b/tests/testaddfunction.h index 276184da1..56815cf99 100644 --- a/tests/testaddfunction.h +++ b/tests/testaddfunction.h @@ -37,6 +37,7 @@ private slots: void testAddFunctionWithoutParenteses(); void testAddFunctionWithDefaultArgs(); void testAddFunctionAtModuleLevel(); + void testAddFunctionWithVarargs(); }; #endif diff --git a/typesystem.cpp b/typesystem.cpp index 1a5fbffd7..7c58dab56 100644 --- a/typesystem.cpp +++ b/typesystem.cpp @@ -1695,6 +1695,7 @@ TypeDatabase::TypeDatabase() : m_suppressWarnings(true) addType(e); addType(new VoidTypeEntry()); + addType(new VarargsTypeEntry()); } QString TypeDatabase::modifiedTypesystemFilepath(const QString &ts_file) @@ -2109,9 +2110,15 @@ static AddedFunction::TypeInfo parseType(const QString& signature, int startPos QRegExp regex("\\w"); int length = signature.length(); int start = signature.indexOf(regex, startPos); - if (start == -1) { // error - if (endPos) - *endPos = length; + if (start == -1) { + if (signature.mid(startPos + 1, 3) == "...") { // varargs + if (endPos) + *endPos = startPos + 4; + result.name = "..."; + } else { // error + if (endPos) + *endPos = length; + } return result; } diff --git a/typesystem.h b/typesystem.h index 28a3cb85f..21c770889 100644 --- a/typesystem.h +++ b/typesystem.h @@ -581,6 +581,7 @@ public: enum Type { PrimitiveType, VoidType, + VarargsType, FlagsType, EnumType, TemplateArgumentType, @@ -681,6 +682,10 @@ public: { return m_type == VoidType; } + bool isVarargs() const + { + return m_type == VarargsType; + } bool isThread() const { return m_type == ThreadType; @@ -924,6 +929,12 @@ public: VoidTypeEntry() : TypeEntry("void", VoidType) { } }; +class APIEXTRACTOR_API VarargsTypeEntry : public TypeEntry +{ +public: + VarargsTypeEntry() : TypeEntry("...", VarargsType) { } +}; + class APIEXTRACTOR_API TemplateArgumentEntry : public TypeEntry { public: |