summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--abstractmetabuilder.cpp31
-rw-r--r--abstractmetabuilder.h1
-rw-r--r--abstractmetalang.cpp52
-rw-r--r--abstractmetalang.h32
-rw-r--r--tests/testaddfunction.cpp27
-rw-r--r--tests/testaddfunction.h1
6 files changed, 79 insertions, 65 deletions
diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp
index 9b57e1e1..01c9e761 100644
--- a/abstractmetabuilder.cpp
+++ b/abstractmetabuilder.cpp
@@ -1565,7 +1565,6 @@ 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);
metaArguments.append(metaArg);
@@ -1595,9 +1594,32 @@ AbstractMetaFunction* AbstractMetaBuilder::traverseFunction(const AddedFunction&
}
metaFunction->setOriginalAttributes(metaFunction->attributes());
+ fixArgumentNames(metaFunction);
return metaFunction;
}
+void AbstractMetaBuilder::fixArgumentNames(AbstractMetaFunction* func)
+{
+ if (func->arguments().isEmpty())
+ return;
+ foreach (FunctionModification mod, func->modifications(m_currentClass)) {
+ foreach (ArgumentModification argMod, mod.argument_mods) {
+ if (!argMod.renamed_to.isEmpty()) {
+ AbstractMetaArgument* arg = func->arguments().at(argMod.index - 1);
+ arg->setOriginalName(arg->name());
+ arg->setName(argMod.renamed_to, false);
+ }
+ }
+ }
+
+ int i = 1;
+ foreach (AbstractMetaArgument* arg, func->arguments()) {
+ if (arg->name().isEmpty())
+ arg->setName("arg__" + QString::number(i), false);
+ ++i;
+ }
+}
+
AbstractMetaFunction* AbstractMetaBuilder::traverseFunction(FunctionModelItem functionItem)
{
QString functionName = functionItem->name();
@@ -1759,12 +1781,17 @@ AbstractMetaFunction* AbstractMetaBuilder::traverseFunction(FunctionModelItem fu
}
//Check for missing argument name
- if (hasDefaultValue && !metaArg->hasName() && !metaFunction->isOperatorOverload() && !metaFunction->isSignal() && metaFunction->argumentName(i+1, false, m_currentClass).isEmpty()) {
+ if (hasDefaultValue
+ && !metaArg->hasName()
+ && !metaFunction->isOperatorOverload()
+ && !metaFunction->isSignal()
+ && metaFunction->argumentName(i+1, false, m_currentClass).isEmpty()) {
ReportHandler::warning(QString("Argument %1 on function '%2::%3' has default expressiont but does not have name.").arg(i+1).arg(className).arg(metaFunction->minimalSignature()));
}
}
+ fixArgumentNames(metaFunction);
return metaFunction;
}
diff --git a/abstractmetabuilder.h b/abstractmetabuilder.h
index d19ce8f1..487cadef 100644
--- a/abstractmetabuilder.h
+++ b/abstractmetabuilder.h
@@ -231,6 +231,7 @@ private:
void sortLists();
AbstractMetaArgumentList reverseList(const AbstractMetaArgumentList& list);
void setInclude(TypeEntry* te, const QString& fileName) const;
+ void fixArgumentNames(AbstractMetaFunction* func);
AbstractMetaClassList m_metaClasses;
AbstractMetaClassList m_templates;
diff --git a/abstractmetalang.cpp b/abstractmetalang.cpp
index 5b824cfe..4c0b2766 100644
--- a/abstractmetalang.cpp
+++ b/abstractmetalang.cpp
@@ -83,41 +83,11 @@ QString AbstractMetaType::cppSignature() const
*/
AbstractMetaArgument *AbstractMetaArgument::copy() const
{
- AbstractMetaArgument *cpy = new AbstractMetaArgument;
- cpy->setName(AbstractMetaVariable::name());
- cpy->setDefaultValueExpression(defaultValueExpression());
- cpy->setOriginalDefaultValueExpression(originalDefaultValueExpression());
+ AbstractMetaArgument* cpy = new AbstractMetaArgument(*this);
cpy->setType(type()->copy());
- cpy->setArgumentIndex(argumentIndex());
-
return cpy;
}
-
-QString AbstractMetaArgument::argumentName() const
-{
- QString n = AbstractMetaVariable::name();
- if (n.isEmpty())
- return QString("arg__%2").arg(m_argumentIndex + 1);
- return n;
-}
-
-
-QString AbstractMetaArgument::indexedName() const
-{
- QString n = AbstractMetaVariable::name();
- if (n.isEmpty())
- return argumentName();
- return QString("%1%2").arg(n).arg(m_argumentIndex);
-}
-
-QString AbstractMetaArgument::name() const
-{
- Q_ASSERT_X(0, "AbstractMetaArgument::name()", "use argumentName() or indexedName() instead");
- return QString();
-}
-
-
/*******************************************************************************
* AbstractMetaFunction
*/
@@ -335,7 +305,7 @@ QString AbstractMetaFunction::signature() const
// We need to have the argument names in the qdoc files
s += " ";
- s += a->argumentName();
+ s += a->name();
}
s += ")";
@@ -701,21 +671,7 @@ bool AbstractMetaFunction::hasModifications(const AbstractMetaClass *implementor
QString AbstractMetaFunction::argumentName(int index, bool create, const AbstractMetaClass *implementor) const
{
- foreach (FunctionModification mod, modifications(implementor)) {
- foreach (ArgumentModification argMod, mod.argument_mods) {
- if ((argMod.index == index) && !argMod.renamed_to.isEmpty()) {
- return argMod.renamed_to;
- }
- }
- }
-
- AbstractMetaArgumentList args = arguments();
- if ((index > 0) && (args.size() > index)) {
- if (create || args[index]->hasName())
- return args[index]->argumentName();
- }
-
- return QString();
+ return m_arguments[--index]->name();
}
bool AbstractMetaFunction::hasInjectedCode() const
@@ -951,7 +907,7 @@ QString AbstractMetaFunction::targetLangSignature(bool minimal) const
if (!minimal) {
s += " ";
- s += m_arguments.at(i)->argumentName();
+ s += m_arguments.at(i)->name();
}
++j;
}
diff --git a/abstractmetalang.h b/abstractmetalang.h
index ba72b35c..ed7157c8 100644
--- a/abstractmetalang.h
+++ b/abstractmetalang.h
@@ -606,7 +606,7 @@ private:
class APIEXTRACTOR_API AbstractMetaVariable
{
public:
- AbstractMetaVariable() : m_type(0) {}
+ AbstractMetaVariable() : m_type(0), m_hasName(false) {}
AbstractMetaType *type() const
{
@@ -621,11 +621,23 @@ public:
{
return m_name;
}
- void setName(const QString &name)
+ void setName(const QString &name, bool realName = true)
{
m_name = name;
+ m_hasName = realName;
+ }
+ bool hasName() const
+ {
+ return m_hasName;
+ }
+ QString originalName() const
+ {
+ return m_originalName;
+ }
+ void setOriginalName(const QString& name)
+ {
+ m_originalName = name;
}
-
void setDocumentation(const Documentation& doc)
{
m_doc = doc;
@@ -636,8 +648,10 @@ public:
}
private:
+ QString m_originalName;
QString m_name;
AbstractMetaType *m_type;
+ bool m_hasName;
Documentation m_doc;
};
@@ -682,20 +696,8 @@ public:
m_argumentIndex = argIndex;
}
- QString argumentName() const;
- QString indexedName() const;
-
AbstractMetaArgument *copy() const;
-
- bool hasName() const
- {
- return !AbstractMetaVariable::name().isEmpty();
- }
-
private:
- // Just to force people to call argumentName() And indexedName();
- QString name() const;
-
QString m_expression;
QString m_originalExpression;
int m_argumentIndex;
diff --git a/tests/testaddfunction.cpp b/tests/testaddfunction.cpp
index e2be5a15..0346a636 100644
--- a/tests/testaddfunction.cpp
+++ b/tests/testaddfunction.cpp
@@ -352,6 +352,33 @@ void TestAddFunction::testAddFunctionWithApiVersion()
QCOMPARE(globalFuncs.count(), 1);
}
+void TestAddFunction::testModifyAddedFunction()
+{
+ const char cppCode[] = "class Foo { };";
+ const char xmlCode[] = "\
+ <typesystem package='Package'>\
+ <primitive-type name='float'/>\
+ <primitive-type name='int'/>\
+ <value-type name='Foo'>\
+ <add-function signature='method(float, int)'>\
+ <inject-code class='target' position='beginning'>custom_code();</inject-code>\
+ <modify-argument index='2'>\
+ <replace-default-expression with='0' />\
+ <rename to='varName' />\
+ </modify-argument>\
+ </add-function>\
+ </value-type>\
+ </typesystem>";
+ TestUtil t(cppCode, xmlCode);
+ AbstractMetaClassList classes = t.builder()->classes();
+ AbstractMetaClass* foo = classes.findClass("Foo");
+ const AbstractMetaFunction* method = foo->findFunction("method");
+ QCOMPARE(method->arguments().size(), 2);
+ AbstractMetaArgument* arg = method->arguments().at(1);
+ QCOMPARE(arg->defaultValueExpression(), QString("0"));
+ QCOMPARE(arg->name(), QString("varName"));
+ QCOMPARE(method->argumentName(2), QString("varName"));
+}
QTEST_APPLESS_MAIN(TestAddFunction)
diff --git a/tests/testaddfunction.h b/tests/testaddfunction.h
index 37c064cf..09d80622 100644
--- a/tests/testaddfunction.h
+++ b/tests/testaddfunction.h
@@ -41,6 +41,7 @@ private slots:
void testAddStaticFunction();
void testAddGlobalFunction();
void testAddFunctionWithApiVersion();
+ void testModifyAddedFunction();
};
#endif