summaryrefslogtreecommitdiffstats
path: root/generator
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.pl@gmail.com>2010-10-18 10:26:53 -0200
committerHugo Parente Lima <hugo.pl@gmail.com>2010-10-18 10:53:55 -0200
commit6b57558fefd3a1e3913e8fe386a07da0d8aeedc3 (patch)
tree64ef1426a88b914f762be74e1e16ab4978ffeafb /generator
parent9078b47fcc5fec2d80a242e8a8f494b5b4c4efd1 (diff)
downloadshiboken-6b57558fefd3a1e3913e8fe386a07da0d8aeedc3.tar.gz
shiboken-6b57558fefd3a1e3913e8fe386a07da0d8aeedc3.tar.xz
shiboken-6b57558fefd3a1e3913e8fe386a07da0d8aeedc3.zip
Fix bug#411 - "Incorrect return statement generated in a function that returns a reference"
Reviewer: Luciano Wolf <luciano.wolf@openbossa.org> Marcelo Lira <marcelo.lira@openbossa.org>
Diffstat (limited to 'generator')
-rw-r--r--generator/cppgenerator.cpp43
1 files changed, 30 insertions, 13 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp
index 79cabead..e031f39a 100644
--- a/generator/cppgenerator.cpp
+++ b/generator/cppgenerator.cpp
@@ -490,14 +490,36 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
Indentation indentation(INDENT);
+ QString defaultReturnExpr;
+ if (func->type()) {
+ foreach (FunctionModification mod, func->modifications()) {
+ foreach (ArgumentModification argMod, mod.argument_mods) {
+ if (argMod.index == 0 && !argMod.replacedDefaultExpression.isEmpty()) {
+ QRegExp regex("%(\\d+)");
+ defaultReturnExpr = argMod.replacedDefaultExpression;
+ int offset = 0;
+ while ((offset = regex.indexIn(defaultReturnExpr, offset)) != -1) {
+ int argId = regex.cap(1).toInt() - 1;
+ if (argId < 0 || argId > func->arguments().count()) {
+ ReportHandler::warning("The expression used in return value contains an invalid index.");
+ break;
+ }
+ defaultReturnExpr.replace(regex.cap(0), func->arguments()[argId]->name());
+ }
+ }
+ }
+ }
+ if (defaultReturnExpr.isEmpty()) {
+ QTextStream s(&defaultReturnExpr);
+ writeMinimalConstructorCallArguments(s, func->type());
+ }
+ }
+
if (func->isAbstract() && func->isModifiedRemoved()) {
ReportHandler::warning("Pure virtual method \"" + func->ownerClass()->name() + "::" + func->minimalSignature() + "\" must be implement but was completely removed on typesystem.");
s << INDENT << "return";
- if (func->type()) {
- s << ' ';
- writeMinimalConstructorCallArguments(s, func->type());
- }
- s << ';' << endl;
+
+ s << ' ' << defaultReturnExpr << ';' << endl;
s << '}' << endl << endl;
return;
}
@@ -525,7 +547,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
s << "()' not implemented.\");" << endl;
s << INDENT << "return ";
if (func->type()) {
- writeMinimalConstructorCallArguments(s, func->type());
+ s << defaultReturnExpr;
}
} else {
if (func->allowThread()) {
@@ -630,10 +652,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
{
Indentation indent(INDENT);
s << INDENT << "PyErr_Print();" << endl;
- s << INDENT << "return ";
- if (type)
- writeMinimalConstructorCallArguments(s, func->type());
- s << ';' << endl;
+ s << INDENT << "return " << defaultReturnExpr << ';' << endl;
}
s << INDENT << '}' << endl;
@@ -676,9 +695,7 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
s << INDENT << "PyErr_Format(PyExc_TypeError, \"Invalid return value in function %s, expected %s, got %s.\", \""
<< func->ownerClass()->name() << '.' << func->name() << "\", " << desiredType
<< ", " PYTHON_RETURN_VAR "->ob_type->tp_name);" << endl;
- s << INDENT << "return ";
- writeMinimalConstructorCallArguments(s, func->type());
- s << ';' << endl;
+ s << INDENT << "return " << defaultReturnExpr << ';' << endl;
}
s << INDENT << "}" << endl;
}