aboutsummaryrefslogtreecommitdiffstats
path: root/cppgenerator.cpp
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.lima@openbossa.org>2010-04-07 17:31:22 -0300
committerHugo Parente Lima <hugo.lima@openbossa.org>2010-04-08 18:37:52 -0300
commit62c909a374789f16ad97014464f91821f714cea6 (patch)
tree63b1c0cd2aa2301984022db067a0809fdf9c3683 /cppgenerator.cpp
parent0650666ccfe1ac83b20a4ffffa1d8b61669c2dd8 (diff)
Better error messages when reimplementing virtual methods.
Diffstat (limited to 'cppgenerator.cpp')
-rw-r--r--cppgenerator.cpp42
1 files changed, 27 insertions, 15 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 561d8dc95..ae4a055cc 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -529,22 +529,34 @@ void CppGenerator::writeVirtualMethodNative(QTextStream &s, const AbstractMetaFu
}
s << INDENT << '}' << endl;
- s << INDENT << "// Check return type" << endl;
- s << INDENT << "bool typeIsValid = ";
- if (func->typeReplaced(0).isEmpty())
- s << cpythonCheckFunction(func->type());
- else
- s << guessCPythonCheckFunction(func->typeReplaced(0));
- s << "(" << PYTHON_RETURN_VAR << ");" << endl;
- if (func->type()->isQObject() || func->type()->isObject() || func->type()->isValuePointer()) {
- s << INDENT << "typeIsValid = typeIsValid || (" << PYTHON_RETURN_VAR << " == Py_None);" << endl;
+ if (func->type()) {
+ s << INDENT << "// Check return type" << endl;
+ s << INDENT << "bool typeIsValid = ";
+ QString desiredType;
+ if (func->typeReplaced(0).isEmpty()) {
+ s << cpythonCheckFunction(func->type());
+ // SbkType would return null when the type is a container.
+ if (func->type()->typeEntry()->isContainer())
+ desiredType = '"' + reinterpret_cast<const ContainerTypeEntry*>(func->type()->typeEntry())->typeName() + '"';
+ else
+ desiredType = "SbkType<" + func->type()->cppSignature() + " >()->tp_name";
+ } else {
+ s << guessCPythonCheckFunction(func->typeReplaced(0));
+ desiredType = '"' + func->typeReplaced(0) + '"';
+ }
+ s << "(" << PYTHON_RETURN_VAR << ");" << endl;
+ if (func->type()->isQObject() || func->type()->isObject() || func->type()->isValuePointer())
+ s << INDENT << "typeIsValid = typeIsValid || (" << PYTHON_RETURN_VAR << " == Py_None);" << endl;
+
+ s << INDENT << "if (!typeIsValid) {" << endl;
+ s << INDENT << 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 << INDENT << "return ";
+ writeMinimalConstructorCallArguments(s, func->type());
+ s << INDENT << INDENT << ";" << endl;
+ s << INDENT << "}" << endl;
}
- s << INDENT << "if (!typeIsValid) {" << endl;
- s << INDENT << INDENT << "PyErr_SetString(PyExc_TypeError, \"Invalid return value in function " << func->ownerClass()->name() << "." << func->name() << "\");" << endl;
- s << INDENT << INDENT << "return ";
- writeMinimalConstructorCallArguments(s, func->type());
- s << INDENT << INDENT << ";" << endl;
- s << INDENT << "}" << endl;
bool hasConversionRule = !func->conversionRule(TypeSystem::NativeCode, 0).isEmpty();
if (hasConversionRule) {