diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2011-08-03 14:35:35 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:17:08 -0300 |
commit | f2e0002c8ebc7a68fca731bfbde1d32415f5a240 (patch) | |
tree | 54bd01c50ada4bb89e71f24a2dedb7cb7c91dc64 /generator | |
parent | 699f6db172df37631dec7a884a25df8cc62343b8 (diff) |
Fixed type system variable replacement for arguments removed with conversion rule.
Also added an array argument modification test, and moved
AutoArrayPointer from libpyside to libshiboken.
Reviewed by Hugo Parente <hugo.lima@openbossa.org>
Reviewed by Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'generator')
-rw-r--r-- | generator/cppgenerator.cpp | 20 | ||||
-rw-r--r-- | generator/shibokengenerator.cpp | 21 | ||||
-rw-r--r-- | generator/shibokengenerator.h | 1 |
3 files changed, 24 insertions, 18 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index 827ec28e3..efbf6ef96 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -726,7 +726,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream&s, const AbstractMetaFun ac << INDENT; if (!func->conversionRule(TypeSystem::TargetLangCode, arg->argumentIndex() + 1).isEmpty()) { // Has conversion rule. - ac << arg->name() << "_out"; + ac << QString("%1"CONV_RULE_OUT_VAR_SUFFIX).arg(arg->name()); } else { QString argName = arg->name(); if (avoidProtectedHack()) { @@ -2021,17 +2021,16 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f int removedArgs = 0; for (int i = 0; i < maxArgs + removedArgs; i++) { const AbstractMetaArgument* arg = func->arguments().at(i); + bool hasConversionRule = !func->conversionRule(TypeSystem::NativeCode, arg->argumentIndex() + 1).isEmpty(); if (func->argumentRemoved(i + 1)) { - // If some argument with default value is removed from a // method signature, the said value must be explicitly // added to the method call. removedArgs++; // If have conversion rules I will use this for removed args - bool hasConversionRule = !func->conversionRule(TypeSystem::NativeCode, arg->argumentIndex() + 1).isEmpty(); if (hasConversionRule) { - userArgs << arg->name() + "_out"; + userArgs << QString("%1"CONV_RULE_OUT_VAR_SUFFIX).arg(arg->name()); } else { if (arg->defaultValueExpression().isEmpty()) badModifications = true; @@ -2040,14 +2039,9 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f } } else { int idx = arg->argumentIndex() - removedArgs; - QString argName; - - bool hasConversionRule = !func->conversionRule(TypeSystem::NativeCode, arg->argumentIndex() + 1).isEmpty(); - if (hasConversionRule) { - argName = arg->name() + "_out"; - } else { - argName = QString(CPP_ARG"%1").arg(idx); - } + QString argName = hasConversionRule + ? QString("%1"CONV_RULE_OUT_VAR_SUFFIX).arg(arg->name()) + : QString(CPP_ARG"%1").arg(idx); userArgs << argName; } } @@ -2073,7 +2067,7 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f if (!arg->defaultValueExpression().isEmpty()) otherArgs.prepend(guessScopeForDefaultValue(func, arg)); else if (hasConversionRule) - otherArgs.prepend(arg->name() + "_out"); + otherArgs.prepend(QString("%1"CONV_RULE_OUT_VAR_SUFFIX).arg(arg->name())); else badModifications = true; } diff --git a/generator/shibokengenerator.cpp b/generator/shibokengenerator.cpp index 05d374ea4..eacc5e54d 100644 --- a/generator/shibokengenerator.cpp +++ b/generator/shibokengenerator.cpp @@ -1081,7 +1081,7 @@ void ShibokenGenerator::writeArgumentNames(QTextStream &s, && (!func->conversionRule(TypeSystem::NativeCode, arguments.at(j)->argumentIndex() + 1).isEmpty() || !func->conversionRule(TypeSystem::TargetLangCode, arguments.at(j)->argumentIndex() + 1).isEmpty()) && !func->isConstructor()) { - s << "_out"; + s << CONV_RULE_OUT_VAR_SUFFIX; } argCount++; @@ -1206,20 +1206,31 @@ QMap<int, QString> ShibokenGenerator::getArgumentReplacement(const AbstractMetaF const AbstractMetaArgument* lastArg) { QMap<int, QString> argReplacement; + TypeSystem::Language convLang = (language == TypeSystem::TargetLangCode) + ? TypeSystem::NativeCode : TypeSystem::TargetLangCode; int removed = 0; for (int i = 0; i < func->arguments().size(); ++i) { const AbstractMetaArgument* arg = func->arguments().at(i); QString argValue; if (language == TypeSystem::TargetLangCode) { + bool hasConversionRule = !func->conversionRule(convLang, i+1).isEmpty(); bool argRemoved = func->argumentRemoved(i+1); removed = removed + (int) argRemoved; if (argRemoved || (lastArg && arg->argumentIndex() > lastArg->argumentIndex())) argValue = arg->defaultValueExpression(); + + if (argRemoved && hasConversionRule && argValue.isEmpty()) + argValue = QString("%1"CONV_RULE_OUT_VAR_SUFFIX).arg(arg->name()); + if (!argRemoved && argValue.isEmpty()) { - if (arg->type()->typeEntry()->isCustom()) - argValue = usePyArgs ? QString(PYTHON_ARGS"[%1]").arg(i - removed) : PYTHON_ARG; - else - argValue = QString(CPP_ARG"%1").arg(i - removed); + int argPos = i - removed; + if (arg->type()->typeEntry()->isCustom()) { + argValue = usePyArgs ? QString(PYTHON_ARGS"[%1]").arg(argPos) : PYTHON_ARG; + } else { + argValue = hasConversionRule + ? QString("%1"CONV_RULE_OUT_VAR_SUFFIX).arg(arg->name()) + : QString(CPP_ARG"%1").arg(argPos); + } } } else { argValue = arg->name(); diff --git a/generator/shibokengenerator.h b/generator/shibokengenerator.h index 605b205e6..2c4dc888a 100644 --- a/generator/shibokengenerator.h +++ b/generator/shibokengenerator.h @@ -24,6 +24,7 @@ #ifndef SHIBOKENGENERATOR_H #define SHIBOKENGENERATOR_H +#define CONV_RULE_OUT_VAR_SUFFIX "_out" #define CPP_ARG "cppArg" #define CPP_ARG0 CPP_ARG"0" #define CPP_RETURN_VAR "cppResult" |