From 17a82a3123c8f0d21aa4e32e295f729d862e65f4 Mon Sep 17 00:00:00 2001 From: renato araujo Date: Wed, 21 Oct 2009 10:47:15 -0300 Subject: Implemented support to conversion-rule tag. Reviwed by: Marcelo Lira --- generators/boostpython/boostpythongenerator.cpp | 14 ++++++++--- generators/boostpython/cppgenerator.cpp | 32 ++++++++++++++++++++----- generators/boostpython/hppgenerator.cpp | 2 +- 3 files changed, 38 insertions(+), 10 deletions(-) (limited to 'generators') diff --git a/generators/boostpython/boostpythongenerator.cpp b/generators/boostpython/boostpythongenerator.cpp index 9c64a510b..d266d395a 100644 --- a/generators/boostpython/boostpythongenerator.cpp +++ b/generators/boostpython/boostpythongenerator.cpp @@ -51,7 +51,7 @@ QString BoostPythonGenerator::argumentString(const AbstractMetaFunction *cppFunc QString modifiedType = cppFunction->typeReplaced(cppArgument->argumentIndex() + 1); QString arg; - if (modifiedType.isEmpty()) + if ((options & OriginalTypeDescription) || modifiedType.isEmpty()) arg = translateType(cppArgument->type(), cppFunction->implementingClass(), options); else arg = modifiedType.replace('$', '.'); @@ -196,13 +196,21 @@ void BoostPythonGenerator::writeArgumentNames(QTextStream &s, if (argCount > 0) s << ", "; + QString argName = arguments.at(j)->argumentName(); + if (((options & Generator::VirtualCall) == 0) && + (!func->conversionRule(TypeSystem::NativeCode, arguments.at(j)->argumentIndex() + 1).isEmpty() || + !func->conversionRule(TypeSystem::TargetLangCode, arguments.at(j)->argumentIndex() + 1).isEmpty()) + ) + argName += "_out"; + if ((options & Generator::BoxedPrimitive) && !arguments.at(j)->type()->isReference() && (arguments.at(j)->type()->isQObject() || arguments.at(j)->type()->isObject())) { - s << "PySide::ptr( " << arguments.at(j)->argumentName() << ")"; + + s << "PySide::ptr( " << argName << ")"; } else { - s << arguments.at(j)->argumentName(); + s << argName; } argCount++; } diff --git a/generators/boostpython/cppgenerator.cpp b/generators/boostpython/cppgenerator.cpp index e3c3b75b8..f144e297a 100644 --- a/generators/boostpython/cppgenerator.cpp +++ b/generators/boostpython/cppgenerator.cpp @@ -35,6 +35,16 @@ static Indentor INDENT; // utiliy functions +inline void writeConversionRule(QTextStream &s, TypeSystem::Language lang, const AbstractMetaFunction *function, const AbstractMetaArgument *arg) +{ + QString convRule = function->conversionRule(lang, arg->argumentIndex() + 1); + if (!convRule.isEmpty()) { + convRule.replace("%in", arg->argumentName()); + convRule.replace("%out", arg->argumentName() + "_out"); + s << convRule; + } +} + inline QString getMethodPointerString(const AbstractMetaFunction* func) { QString className; @@ -685,8 +695,12 @@ void CppGenerator::writeVirtualMethodImplHead(QTextStream& s, const AbstractMeta if (func->type()) s << "python::object __result = "; - s << "method("; - writeArgumentNames(s, func, BoxedPrimitive); + foreach(AbstractMetaArgument *arg, func->arguments()) { + writeConversionRule(s, TypeSystem::TargetLangCode, func, arg); + } + + s << INDENT << "method("; + writeArgumentNames(s, func, Generator::Options(Generator::BoxedPrimitive | Generator::SkipRemovedArguments)); s << ");" << endl; QString typeName = getFunctionReturnType(func); @@ -741,7 +755,7 @@ void CppGenerator::writeVirtualMethodImpl(QTextStream& s, const AbstractMetaFunc QString prefix = getWrapperName(func->ownerClass()) + "::"; s << functionSignature(func, prefix, "", - Options(Generator::OriginalTypeDescription) | Generator::SkipDefaultValues) + Options(Generator::OriginalTypeDescription) | Generator::SkipDefaultValues | Generator::VirtualCall) << endl << "{" << endl; writeVirtualMethodImplHead(s, func); @@ -782,7 +796,7 @@ void CppGenerator::writeVirtualMethodImplFoot(QTextStream& s, const AbstractMeta s << INDENT << "py_allow_threads allow_threads;" << endl; s << INDENT << returnKeyword << func->implementingClass()->qualifiedCppName() << "::"; - writeFunctionCall(s, func); + writeFunctionCall(s, func, Generator::VirtualCall); s << ';' << endl; } s << INDENT << '}' << endl; @@ -792,7 +806,9 @@ void CppGenerator::writeVirtualDefaultFunction(QTextStream &s, const AbstractMet { Indentation indentation(INDENT); QString returnKeyword = func->type() ? QLatin1String("return ") : QString(); - QString defaultMethodSignature = signatureForDefaultVirtualMethod(func, getWrapperName(func->ownerClass()) + "::", "_default", Generator::SkipDefaultValues); + Generator::Options opt = Generator::Options(Generator::SkipDefaultValues); + QString defaultMethodSignature = signatureForDefaultVirtualMethod(func, getWrapperName(func->ownerClass()) + "::", "_default", + opt | Generator::SkipRemovedArguments | Generator::VirtualCall); s << defaultMethodSignature << endl << '{' << endl; if (func->allowThread()) @@ -807,9 +823,13 @@ void CppGenerator::writeVirtualDefaultFunction(QTextStream &s, const AbstractMet } } + foreach(AbstractMetaArgument *arg, func->arguments()) { + writeConversionRule(s, TypeSystem::NativeCode, func, arg); + } + if (!hasVirtualEndCode) { s << INDENT << returnKeyword << "self." << func->implementingClass()->qualifiedCppName() << "::"; - writeFunctionCall(s, func); + writeFunctionCall(s, func, opt); s << ";" << endl; } else { writeCodeSnips(s, getCodeSnips(func), diff --git a/generators/boostpython/hppgenerator.cpp b/generators/boostpython/hppgenerator.cpp index 2bdfae454..334cee505 100644 --- a/generators/boostpython/hppgenerator.cpp +++ b/generators/boostpython/hppgenerator.cpp @@ -170,7 +170,7 @@ void HppGenerator::writeFunction(QTextStream &s, const AbstractMetaFunction* fun if (func->isVirtual() && !func->isAbstract() && !func->isConstructor() && !func->ownerClass()->hasPrivateDestructor() && func->implementingClass() == func->ownerClass()) { - s << INDENT << "static " << signatureForDefaultVirtualMethod(func, "", "_default", Generator::SkipName) << ';' << endl; + s << INDENT << "static " << signatureForDefaultVirtualMethod(func, "", "_default", Generator::Options( Generator::SkipName | Generator::SkipRemovedArguments) ) << ';' << endl; } if (func->isConstructor()) { -- cgit v1.2.3