From 3649c91f1bdad3ce7db3ff895ae40edf06fc232e Mon Sep 17 00:00:00 2001 From: Renato Filho Date: Wed, 9 Jun 2010 11:11:37 -0300 Subject: Enable warning for arguments without name. Reviewer: Luciano Wolf , Marcelo Lira --- abstractmetabuilder.cpp | 4 ++++ abstractmetalang.cpp | 18 ++++++++++++++++++ abstractmetalang.h | 12 ++++++++++++ tests/testmodifyfunction.cpp | 7 +------ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/abstractmetabuilder.cpp b/abstractmetabuilder.cpp index d40e07cb0..5c326abb9 100644 --- a/abstractmetabuilder.cpp +++ b/abstractmetabuilder.cpp @@ -1633,6 +1633,10 @@ AbstractMetaFunction* AbstractMetaBuilder::traverseFunction(FunctionModelItem fu } AbstractMetaArgument* metaArgument = createMetaArgument(); metaArgument->setType(metaType); + + if (arg->name().isEmpty() && metaFunction->argumentName(i).isEmpty()) + ReportHandler::warning(QString("Argument %1 on function '%2::%3' declared without name.").arg(i).arg(className).arg(functionItem->name())); + metaArgument->setName(arg->name()); metaArgument->setArgumentIndex(i); metaArguments << metaArgument; diff --git a/abstractmetalang.cpp b/abstractmetalang.cpp index 068256528..4a7571359 100644 --- a/abstractmetalang.cpp +++ b/abstractmetalang.cpp @@ -699,6 +699,24 @@ bool AbstractMetaFunction::hasModifications(const AbstractMetaClass *implementor return !modifications(implementor).isEmpty(); } +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(); +} + bool AbstractMetaFunction::hasInjectedCode() const { foreach (const FunctionModification mod, modifications(ownerClass())) { diff --git a/abstractmetalang.h b/abstractmetalang.h index 6609eb936..ba72b35cb 100644 --- a/abstractmetalang.h +++ b/abstractmetalang.h @@ -687,6 +687,11 @@ public: AbstractMetaArgument *copy() const; + bool hasName() const + { + return !AbstractMetaVariable::name().isEmpty(); + } + private: // Just to force people to call argumentName() And indexedName(); QString name() const; @@ -694,6 +699,8 @@ private: QString m_expression; QString m_originalExpression; int m_argumentIndex; + + friend class AbstractMetaClass; }; @@ -1068,6 +1075,11 @@ public: bool hasSignatureModifications() const; FunctionModificationList modifications(const AbstractMetaClass* implementor = 0) const; + /** + * Return the argument name if there is a modification the renamed value will be returned + */ + QString argumentName(int index, bool create = true, const AbstractMetaClass *cl = 0) const; + // If this function stems from an interface, this returns the // interface that declares it. const AbstractMetaClass *interfaceClass() const diff --git a/tests/testmodifyfunction.cpp b/tests/testmodifyfunction.cpp index 7fa8833f1..930ccdca8 100644 --- a/tests/testmodifyfunction.cpp +++ b/tests/testmodifyfunction.cpp @@ -49,12 +49,7 @@ void TestModifyFunction::testRenameArgument() 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")); + QCOMPARE(func->argumentName(1), QString("otherArg")); } void TestModifyFunction::testOwnershipTransfer() -- cgit v1.2.3