From 08f29f0d8f456eb1f994b05c21fd04468c95329c Mon Sep 17 00:00:00 2001 From: Marcelo Lira Date: Thu, 4 Aug 2011 17:31:48 -0300 Subject: Included tests for added function signatures very similar to already existing ones. Specifically this causes the situation when there is in C++ a function with an argument that is a reference to a Value Type, and the user adds a very similar function with the same type, but passed as value. Example: C++ : function(const TYPE& a, int b) Added: function(TYPE) The return type of ShibokenGenerator::getArgumentReplacement() method was modified, because the argument object is more useful than its index. --- generator/shibokengenerator.cpp | 32 ++++++++++++++++++++++---------- generator/shibokengenerator.h | 8 +++++--- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'generator') diff --git a/generator/shibokengenerator.cpp b/generator/shibokengenerator.cpp index eacc5e54d..3e5b8eabb 100644 --- a/generator/shibokengenerator.cpp +++ b/generator/shibokengenerator.cpp @@ -1201,11 +1201,11 @@ void ShibokenGenerator::processCodeSnip(QString& code, const AbstractMetaClass* replaceTypeCheckTypeSystemVariable(code); } -QMap ShibokenGenerator::getArgumentReplacement(const AbstractMetaFunction* func, - bool usePyArgs, TypeSystem::Language language, - const AbstractMetaArgument* lastArg) +ShibokenGenerator::ArgumentVarReplacementList ShibokenGenerator::getArgumentReplacement(const AbstractMetaFunction* func, + bool usePyArgs, TypeSystem::Language language, + const AbstractMetaArgument* lastArg) { - QMap argReplacement; + ArgumentVarReplacementList argReplacements; TypeSystem::Language convLang = (language == TypeSystem::TargetLangCode) ? TypeSystem::NativeCode : TypeSystem::TargetLangCode; int removed = 0; @@ -1236,9 +1236,10 @@ QMap ShibokenGenerator::getArgumentReplacement(const AbstractMetaF argValue = arg->name(); } if (!argValue.isEmpty()) - argReplacement[i+1] = argValue; + argReplacements << ArgumentVarReplacementPair(arg, argValue); + } - return argReplacement; + return argReplacements; } void ShibokenGenerator::writeCodeSnips(QTextStream& s, @@ -1387,10 +1388,21 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, // Replaces template %ARGUMENT_NAMES and %# variables by argument variables and values. // Replaces template variables %# for individual arguments. - QMap argReplacements = getArgumentReplacement(func, usePyArgs, language, lastArg); - code.replace("%ARGUMENT_NAMES", QStringList(argReplacements.values()).join(", ")); - foreach (int i, argReplacements.keys()) - code.replace(QString("%%1").arg(i), argReplacements[i]); + ArgumentVarReplacementList argReplacements = getArgumentReplacement(func, usePyArgs, language, lastArg); + + QStringList args; + foreach (ArgumentVarReplacementPair pair, argReplacements) + args << pair.second; + code.replace("%ARGUMENT_NAMES", args.join(", ")); + + foreach (ArgumentVarReplacementPair pair, argReplacements) { + const AbstractMetaArgument* arg = pair.first; + int idx = arg->argumentIndex() + 1; + QString replacement = pair.second; + if (isWrapperType(arg->type()) && isPointer(arg->type())) + code.replace(QString("%%1.").arg(idx), QString("%1->").arg(replacement)); + code.replace(QString("%%1").arg(idx), replacement); + } if (language == TypeSystem::NativeCode) { // Replaces template %PYTHON_ARGUMENTS variable with a pointer to the Python tuple diff --git a/generator/shibokengenerator.h b/generator/shibokengenerator.h index 2c4dc888a..674bbeab2 100644 --- a/generator/shibokengenerator.h +++ b/generator/shibokengenerator.h @@ -114,9 +114,11 @@ public: QString functionReturnType(const AbstractMetaFunction* func, Options options = NoOption) const; /// Utility function for writeCodeSnips. - static QMap getArgumentReplacement(const AbstractMetaFunction* func, - bool usePyArgs, TypeSystem::Language language, - const AbstractMetaArgument* lastArg); + typedef QPair ArgumentVarReplacementPair; + typedef QList ArgumentVarReplacementList; + ArgumentVarReplacementList getArgumentReplacement(const AbstractMetaFunction* func, + bool usePyArgs, TypeSystem::Language language, + const AbstractMetaArgument* lastArg); /// Write user's custom code snippets at class or module level. void writeCodeSnips(QTextStream& s, -- cgit v1.2.3