diff options
-rw-r--r-- | tests/testmodifyfunction.cpp | 32 | ||||
-rw-r--r-- | tests/testmodifyfunction.h | 1 | ||||
-rw-r--r-- | typesystem.cpp | 14 | ||||
-rw-r--r-- | typesystem.h | 3 |
4 files changed, 45 insertions, 5 deletions
diff --git a/tests/testmodifyfunction.cpp b/tests/testmodifyfunction.cpp index d45815e6c..7fa8833f1 100644 --- a/tests/testmodifyfunction.cpp +++ b/tests/testmodifyfunction.cpp @@ -25,6 +25,38 @@ #include <QtTest/QTest> #include "testutil.h" +void TestModifyFunction::testRenameArgument() +{ + const char* cppCode ="\ + struct A {\ + void method(int myarg);\ + };\ + "; + const char* xmlCode = "\ + <typesystem package='Foo'> \ + <primitive-type name='int'/>\ + <object-type name='A'> \ + <modify-function signature='method(int)'>\ + <modify-argument index='1'>\ + <rename to='otherArg' />\ + </modify-argument>\ + </modify-function>\ + </object-type>\ + </typesystem>"; + TestUtil t(cppCode, xmlCode, false); + AbstractMetaClassList classes = t.builder()->classes(); + AbstractMetaClass* classA = classes.findClass("A"); + const AbstractMetaFunction* func = classA->findFunction("method"); + Q_ASSERT(func); + + FunctionModificationList modList = func->modifications(classA); + QVERIFY(modList.size() == 1); + FunctionModification mod = modList.at(0); + QVERIFY(mod.argument_mods.size() == 1); + + QCOMPARE(mod.argument_mods.at(0).renamed_to, QString("otherArg")); +} + void TestModifyFunction::testOwnershipTransfer() { const char* cppCode ="\ diff --git a/tests/testmodifyfunction.h b/tests/testmodifyfunction.h index f92180c02..40adf127f 100644 --- a/tests/testmodifyfunction.h +++ b/tests/testmodifyfunction.h @@ -32,6 +32,7 @@ class TestModifyFunction : public QObject private slots: void testOwnershipTransfer(); void testWithApiVersion(); + void testRenameArgument(); }; #endif diff --git a/typesystem.cpp b/typesystem.cpp index 6049ea060..3e8b2dc49 100644 --- a/typesystem.cpp +++ b/typesystem.cpp @@ -1120,15 +1120,16 @@ bool Handler::startElement(const QString &, const QString &n, case StackElement::Rename: case StackElement::Access: { if (topElement.type != StackElement::ModifyField - && topElement.type != StackElement::ModifyFunction) { - m_error = "Function or field modification parent required"; + && topElement.type != StackElement::ModifyFunction + && topElement.type != StackElement::ModifyArgument) { + m_error = "Function, field or argument modification parent required"; return false; } Modification *mod = 0; if (topElement.type == StackElement::ModifyFunction) mod = &m_functionMods.last(); - else + else if (topElement.type == StackElement::ModifyField) mod = &m_fieldMods.last(); QString modifier; @@ -1142,8 +1143,10 @@ bool Handler::startElement(const QString &, const QString &n, if (topElement.type == StackElement::ModifyFunction) mod->setRenamedTo(renamed_to); - else + else if (topElement.type == StackElement::ModifyField) mod->setRenamedTo(renamed_to); + else + m_functionMods.last().argument_mods.last().renamed_to = renamed_to; } else modifier = attributes["modifier"].toLower(); @@ -1169,7 +1172,8 @@ bool Handler::startElement(const QString &, const QString &n, return false; } - mod->modifiers |= modifierNames[modifier]; + if (mod) + mod->modifiers |= modifierNames[modifier]; } break; case StackElement::RemoveArgument: diff --git a/typesystem.h b/typesystem.h index 23b9d24cc..f8358a763 100644 --- a/typesystem.h +++ b/typesystem.h @@ -277,6 +277,9 @@ struct ArgumentModification //Api version double version; + + //New name + QString renamed_to; }; struct APIEXTRACTOR_API Modification |