diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-08 12:59:40 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-12-08 13:48:22 -0300 |
commit | b27f6f347dc19db7706b69c0e7c22e74dea2853b (patch) | |
tree | 223206ee3b3009bd3103d7dc38a2bd28a44f5915 /shibokengenerator.cpp | |
parent | dd1680a72c7709439f0ea5b91d1ac6f7957c1179 (diff) |
Fixed inconsistency on type system variables and added a new one.
The %# group of type system variables are meant to be replaced by
C++ arguments and %PYARG_# by Python arguments. For some reason %0
is replaced by the Python return variable and %PYARG_0 is considered
invalid by the replacement system. Now %PYARG_0 is replaced by
the Python return variable and %0 by the C++ version.
The %CONVERTTOCPP type system variable was added.
Fixed ShibokenGenerator::injectedCodeHasReturnValueAttribution to
consider a return value attribution when the user does "%PYARG_0 = ..."
instead of "%0 = ...".
The changes were documented and all the test bindings inject codes
were updated to use the modified variables properly.
Reviewed by Hugo Lima <hugo.lima@openbossa.org>
Diffstat (limited to 'shibokengenerator.cpp')
-rw-r--r-- | shibokengenerator.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/shibokengenerator.cpp b/shibokengenerator.cpp index feb14b968..2094749fc 100644 --- a/shibokengenerator.cpp +++ b/shibokengenerator.cpp @@ -848,6 +848,7 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, const AbstractMetaClass* context) { static QRegExp toPythonRegex("%CONVERTTOPYTHON\\[([^\\[]*)\\]"); + static QRegExp toCppRegex("%CONVERTTOCPP\\[([^\\[]*)\\]"); static QRegExp pyArgsRegex("%PYARG_(\\d+)"); // detect is we should use pyargs instead of args as variable name for python arguments @@ -884,8 +885,12 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, // replace "toPython "converters code.replace(toPythonRegex, "Shiboken::Converter<\\1 >::toPython"); + // replace "toCpp "converters + code.replace(toCppRegex, "Shiboken::Converter<\\1 >::toCpp"); + if (func) { // replace %PYARG_# variables + code.replace("%PYARG_0", retvalVariableName()); if (snip.language == TypeSystem::TargetLangCode) { if (numArgs > 1) { code.replace(pyArgsRegex, "pyargs[\\1-1]"); @@ -920,10 +925,15 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, } // replace template variable for return variable name - if (func->isConstructor()) + if (func->isConstructor()) { + code.replace("%0.", QString("%1->").arg("cptr")); code.replace("%0", "cptr"); - else - code.replace("%0", retvalVariableName()); + } else if (func->type()) { + QString pyRetVal = cpythonWrapperCPtr(func->type(), retvalVariableName()); + if (func->type()->typeEntry()->isValue() || func->type()->typeEntry()->isObject()) + code.replace("%0.", QString("%1->").arg(pyRetVal)); + code.replace("%0", pyRetVal); + } // replace template variable for self Python object QString pySelf; @@ -953,7 +963,7 @@ void ShibokenGenerator::writeCodeSnips(QTextStream& s, } } - // replace template variables for individual arguments + // replace template variables %# for individual arguments int removed = 0; for (int i = 0; i < func->arguments().size(); i++) { const AbstractMetaArgument* arg = func->arguments().at(i); @@ -1099,7 +1109,7 @@ bool ShibokenGenerator::injectedCodeCallsPythonOverride(const AbstractMetaFuncti bool ShibokenGenerator::injectedCodeHasReturnValueAttribution(const AbstractMetaFunction* func) { - static QRegExp retValAttributionRegexCheck("%0\\s*=[^=]\\s*.+"); + static QRegExp retValAttributionRegexCheck("%PYARG_0\\s*=[^=]\\s*.+"); CodeSnipList snips = func->injectedCodeSnips(CodeSnip::Any, TypeSystem::TargetLangCode); foreach (CodeSnip snip, snips) { if (retValAttributionRegexCheck.indexIn(snip.code()) != -1) |