summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--abstractmetabuilder.cpp10
-rw-r--r--tests/testmodifyfunction.cpp37
-rw-r--r--tests/testmodifyfunction.h1
3 files changed, 47 insertions, 1 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index 9fc1674d..c3ebe3b0 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -1945,8 +1945,16 @@ AbstractMetaFunction* AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
//use relace-default-expression for set default value
QString replacedExpression;
- if (m_currentClass)
+ if (m_currentClass) {
replacedExpression = metaFunction->replacedDefaultExpression(m_currentClass, i + 1);
+ } else {
+ FunctionModificationList mods = TypeDatabase::instance()->functionModifications(metaFunction->minimalSignature());
+ if (!mods.isEmpty()) {
+ QList<ArgumentModification> argMods = mods.first().argument_mods;
+ if (!argMods.isEmpty())
+ replacedExpression = argMods.first().replacedDefaultExpression;
+ }
+ }
bool hasDefaultValue = false;
if (arg->defaultValue() || !replacedExpression.isEmpty()) {
diff --git a/tests/testmodifyfunction.cpp b/tests/testmodifyfunction.cpp
index 245a3e16..93dae753 100644
--- a/tests/testmodifyfunction.cpp
+++ b/tests/testmodifyfunction.cpp
@@ -201,6 +201,43 @@ void TestModifyFunction::testWithApiVersion()
QVERIFY(func->ownership(func->ownerClass(), TypeSystem::TargetLangCode, 0) != TypeSystem::CppOwnership);
}
+void TestModifyFunction::testGlobalFunctionModification()
+{
+ const char* cppCode ="\
+ struct A {};\
+ void function(A* a = 0);\
+ ";
+ const char* xmlCode = "\
+ <typesystem package='Foo'> \
+ <primitive-type name='A'/>\
+ <function signature='function(A*)'>\
+ <modify-function signature='function(A*)'>\
+ <modify-argument index='1'>\
+ <replace-type modified-type='A'/>\
+ <replace-default-expression with='A()'/>\
+ </modify-argument>\
+ </modify-function>\
+ </function>\
+ </typesystem>";
+
+ TestUtil t(cppCode, xmlCode, false);
+ QCOMPARE(t.builder()->globalFunctions().size(), 1);
+
+ FunctionModificationList mods = TypeDatabase::instance()->functionModifications("function(A*)");
+ QCOMPARE(mods.count(), 1);
+ QList<ArgumentModification> argMods = mods.first().argument_mods;
+ QCOMPARE(argMods.count(), 1);
+ ArgumentModification argMod = argMods.first();
+ QCOMPARE(argMod.replacedDefaultExpression, QString("A()"));
+
+ const AbstractMetaFunction* func = t.builder()->globalFunctions().first();
+ QVERIFY(func);
+ QCOMPARE(func->arguments().count(), 1);
+ const AbstractMetaArgument* arg = func->arguments().first();
+ QCOMPARE(arg->type()->cppSignature(), QString("A *"));
+ QCOMPARE(arg->originalDefaultValueExpression(), QString("0"));
+ QCOMPARE(arg->defaultValueExpression(), QString("A()"));
+}
QTEST_APPLESS_MAIN(TestModifyFunction)
diff --git a/tests/testmodifyfunction.h b/tests/testmodifyfunction.h
index 95b7b6a7..d72a41dd 100644
--- a/tests/testmodifyfunction.h
+++ b/tests/testmodifyfunction.h
@@ -34,6 +34,7 @@ class TestModifyFunction : public QObject
void testWithApiVersion();
void testRenameArgument();
void invalidateAfterUse();
+ void testGlobalFunctionModification();
};
#endif