aboutsummaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2011-08-04 17:31:48 -0300
committerHugo Parente Lima <hugo.pl@gmail.com>2012-03-08 16:17:08 -0300
commit08f29f0d8f456eb1f994b05c21fd04468c95329c (patch)
tree857a3dee162eec94d3ffd624ec4fba3f7c5e21d8 /generator
parenteda3572089e71e0c5065831438c4999486838547 (diff)
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.
Diffstat (limited to 'generator')
-rw-r--r--generator/shibokengenerator.cpp32
-rw-r--r--generator/shibokengenerator.h8
2 files changed, 27 insertions, 13 deletions
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<int, QString> 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<int, QString> argReplacement;
+ ArgumentVarReplacementList argReplacements;
TypeSystem::Language convLang = (language == TypeSystem::TargetLangCode)
? TypeSystem::NativeCode : TypeSystem::TargetLangCode;
int removed = 0;
@@ -1236,9 +1236,10 @@ QMap<int, QString> 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<int, QString> 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<int, QString> getArgumentReplacement(const AbstractMetaFunction* func,
- bool usePyArgs, TypeSystem::Language language,
- const AbstractMetaArgument* lastArg);
+ typedef QPair<const AbstractMetaArgument*, QString> ArgumentVarReplacementPair;
+ typedef QList<ArgumentVarReplacementPair> 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,