diff options
author | renato <renato.filho@openbossa.org> | 2009-12-08 15:58:11 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-08 16:55:09 -0300 |
commit | 00a880f4d61a6a32f3e1dcaa4a692a6e430c123a (patch) | |
tree | cd720a51170898d35a2b384f3040ebd6f9b718f8 | |
parent | 6d16532a7d504cd1fcd7553957e7e53beac7fc37 (diff) |
Fixed support for modify args in add-function tag.
Created tests.
Reviewed by Hugo Lima <hugo.lima@openbossa.org>
-rw-r--r-- | abstractmetabuilder.cpp | 30 | ||||
-rw-r--r-- | tests/testaddfunction.cpp | 34 | ||||
-rw-r--r-- | tests/testaddfunction.h | 3 | ||||
-rw-r--r-- | typesystem.cpp | 3 |
4 files changed, 64 insertions, 6 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp index f3636d594..45e24f282 100644 --- a/abstractmetabuilder.cpp +++ b/abstractmetabuilder.cpp @@ -1406,6 +1406,8 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(const AddedFunction& metaFunction->setType(translateType(addedFunc.returnType())); QList<AddedFunction::TypeInfo> args = addedFunc.arguments(); + AbstractMetaArgumentList metaArguments; + for (int i = 0; i < args.count(); ++i) { AddedFunction::TypeInfo& typeInfo = args[i]; AbstractMetaArgument* metaArg = createMetaArgument(); @@ -1413,10 +1415,33 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(const AddedFunction& decideUsagePattern(type); metaArg->setType(type); metaArg->setArgumentIndex(i); + metaArg->setName(typeInfo.name); metaArg->setDefaultValueExpression(typeInfo.defaultValue); metaArg->setOriginalDefaultValueExpression(typeInfo.defaultValue); - metaArg->setName(typeInfo.name); - metaFunction->addArgument(metaArg); + metaArguments.append(metaArg); + } + + metaFunction->setArguments(metaArguments); + + // Find the correct default values + for (int i = 0; i < metaArguments.size(); ++i) { + AbstractMetaArgument *metaArg = metaArguments.at(i); + + //use relace-default-expression for set default value + QString replacedExpression; + if (m_currentClass) + replacedExpression = metaFunction->replacedDefaultExpression(m_currentClass, i + 1); + + if (!replacedExpression.isEmpty()) { + QString expr = replacedExpression; + if (!metaFunction->removedDefaultExpression(m_currentClass, i + 1)) { + metaArg->setDefaultValueExpression(expr); + metaArg->setOriginalDefaultValueExpression(expr); + + if (metaArg->type()->isEnum() || metaArg->type()->isFlags()) + m_enumDefaultArguments << QPair<AbstractMetaArgument *, AbstractMetaFunction *>(metaArg, metaFunction); + } + } } return metaFunction; @@ -1565,7 +1590,6 @@ AbstractMetaFunction *AbstractMetaBuilder::traverseFunction(FunctionModelItem fu expr = fixDefaultValue(arg, metaArg->type(), metaFunction, m_currentClass, i); metaArg->setOriginalDefaultValueExpression(expr); - QString replacedExpression = metaFunction->replacedDefaultExpression(m_currentClass, i + 1); if (metaFunction->removedDefaultExpression(m_currentClass, i + 1)) { expr = ""; } else if (!replacedExpression.isEmpty()) { diff --git a/tests/testaddfunction.cpp b/tests/testaddfunction.cpp index 113fbf47c..781736ba4 100644 --- a/tests/testaddfunction.cpp +++ b/tests/testaddfunction.cpp @@ -167,7 +167,7 @@ void TestAddFunction::testAddFunctionCodeSnippets() QVERIFY(addedFunc->hasInjectedCode()); } -void TestAddFunction::testFunctionWithoutParenteses() +void TestAddFunction::testAddFunctionWithoutParenteses() { const char sig1[] = "func"; AddedFunction f1(sig1, "void"); @@ -197,6 +197,38 @@ void TestAddFunction::testFunctionWithoutParenteses() } +void TestAddFunction::testAddFunctionWithDefaultArgs() +{ + const char sig1[] = "func"; + AddedFunction f1(sig1, "void"); + + QCOMPARE(f1.name(), QString("func")); + QCOMPARE(f1.arguments().count(), 0); + QCOMPARE(f1.isConstant(), false); + + const char cppCode[] = "struct A { };"; + const char xmlCode[] = "\ + <typesystem package=\"Foo\">\ + <primitive-type name='int'/> \ + <value-type name='A'>\ + <add-function signature='func(int, int)'>\ + <modify-argument index='2'>\ + <replace-default-expression with='2'/> \ + </modify-argument> \ + </add-function>\ + </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); + AbstractMetaArgument *arg = addedFunc->arguments()[1]; + QCOMPARE(arg->defaultValueExpression(), QString("2")); +} + QTEST_APPLESS_MAIN(TestAddFunction) #include "testaddfunction.moc" diff --git a/tests/testaddfunction.h b/tests/testaddfunction.h index 5600da7dc..98c0f83ba 100644 --- a/tests/testaddfunction.h +++ b/tests/testaddfunction.h @@ -34,7 +34,8 @@ private slots: void testAddFunctionConstructor(); void testAddFunctionTagDefaultValues(); void testAddFunctionCodeSnippets(); - void testFunctionWithoutParenteses(); + void testAddFunctionWithoutParenteses(); + void testAddFunctionWithDefaultArgs(); }; #endif diff --git a/typesystem.cpp b/typesystem.cpp index b4bdc3ff7..2e1fe0e52 100644 --- a/typesystem.cpp +++ b/typesystem.cpp @@ -1053,7 +1053,8 @@ bool Handler::startElement(const QString &, const QString &n, break; case StackElement::ModifyArgument: { - if (topElement.type != StackElement::ModifyFunction) { + if (topElement.type != StackElement::ModifyFunction + && topElement.type != StackElement::AddFunction) { m_error = QString::fromLatin1("argument modification requires function" " modification as parent, was %1") .arg(topElement.type, 0, 16); |