diff options
author | Hugo Parente Lima <hugo.pl@gmail.com> | 2011-04-11 16:30:35 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:15:20 -0300 |
commit | 68dde475dd98b191a6bd3d6151cb7ab5f6410242 (patch) | |
tree | e9317023e0b41804efba6c273450dd0929af94a5 /generator | |
parent | e6a322e777ab36bbed430a8836e0f656de49963d (diff) |
Fix bug 823 - "Shiboken doesn't support function call overloads"
Diffstat (limited to 'generator')
-rw-r--r-- | generator/cppgenerator.cpp | 25 | ||||
-rw-r--r-- | generator/shibokengenerator.cpp | 3 |
2 files changed, 22 insertions, 6 deletions
diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index f932c8447..67ea7e370 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -361,6 +361,10 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl if (rfunc->isConstructor()) writeConstructorWrapper(s, overloads); + // call operators + if (rfunc->name() == "operator()") + writeMethodWrapper(s, overloads); + if (!rfunc->isConstructor() && !rfunc->isOperatorOverload()) { writeMethodWrapper(s, overloads); if (OverloadData::hasStaticAndInstanceFunctions(overloads)) { @@ -1157,7 +1161,7 @@ void CppGenerator::writeMethodWrapper(QTextStream& s, const AbstractMetaFunction int minArgs = overloadData.minArgs(); int maxArgs = overloadData.maxArgs(); bool usePyArgs = pythonFunctionWrapperUsesListOfArguments(overloadData); - bool usesNamedArguments = overloadData.hasArgumentWithDefaultValue(); + bool usesNamedArguments = overloadData.hasArgumentWithDefaultValue() || rfunc->isCallOperator(); s << "static PyObject* "; s << cpythonFunctionName(rfunc) << "(PyObject* self"; @@ -1243,7 +1247,10 @@ void CppGenerator::writeMethodWrapper(QTextStream& s, const AbstractMetaFunction * Solves #119 - QDataStream <</>> operators not working for QPixmap * http://bugs.openbossa.org/show_bug.cgi?id=119 */ - bool callExtendedReverseOperator = hasReturnValue && !rfunc->isInplaceOperator() && rfunc->isOperatorOverload(); + bool callExtendedReverseOperator = hasReturnValue + && !rfunc->isInplaceOperator() + && !rfunc->isCallOperator() + && rfunc->isOperatorOverload(); if (callExtendedReverseOperator) { QString revOpName = ShibokenGenerator::pythonOperatorFunctionName(rfunc).insert(2, 'r'); if (rfunc->isBinaryOperator()) { @@ -1610,7 +1617,7 @@ void CppGenerator::writeOverloadedFunctionDecisor(QTextStream& s, const Overload // Ensure that the direct overload that called this reverse // is called. - if (rfunc->isOperatorOverload()) { + if (rfunc->isOperatorOverload() && !rfunc->isCallOperator()) { s << INDENT << "if (isReverse && overloadId == -1) {" << endl; { Indentation indent(INDENT); @@ -1749,7 +1756,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(QTextStream& s, const Ov s << "numArgs >= " << (startArg + sequenceArgCount) << " && "; } - if (refFunc->isOperatorOverload()) + if (refFunc->isOperatorOverload() && !refFunc->isCallOperator()) s << (refFunc->isReverseOperator() ? "" : "!") << "isReverse && "; s << typeChecks << ") {" << endl; @@ -2071,7 +2078,7 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f + "::" + func->minimalSignature() + "\" with the modifications described in the type system file"), NULL); } - } else if (func->isOperatorOverload()) { + } else if (func->isOperatorOverload() && !func->isCallOperator()) { QByteArray firstArg("(*" CPP_SELF_VAR ")"); if (func->isPointerOperator()) firstArg.remove(1, 1); // remove the de-reference operator @@ -2455,6 +2462,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass* QString tp_as_number('0'); QString tp_as_sequence('0'); QString tp_hash('0'); + QString tp_call('0'); QString cppClassName = metaClass->qualifiedCppName(); QString className = cpythonTypeName(metaClass).replace(QRegExp("_Type$"), ""); QString baseClassName('0'); @@ -2541,6 +2549,11 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass* if (!metaClass->typeEntry()->hashFunction().isEmpty()) tp_hash = '&' + cpythonBaseName(metaClass) + "_HashFunc"; + const AbstractMetaFunction* callOp = metaClass->findFunction("operator()"); + if (callOp && !callOp->isModifiedRemoved()) + tp_call = '&' + cpythonFunctionName(callOp); + + s << "// Class Definition -----------------------------------------------" << endl; s << "extern \"C\" {" << endl; s << "static SbkObjectType " << className + "_Type" << " = { { {" << endl; @@ -2559,7 +2572,7 @@ void CppGenerator::writeClassDefinition(QTextStream& s, const AbstractMetaClass* s << INDENT << "/*tp_as_sequence*/ " << tp_as_sequence << ',' << endl; s << INDENT << "/*tp_as_mapping*/ 0," << endl; s << INDENT << "/*tp_hash*/ " << tp_hash << ',' << endl; - s << INDENT << "/*tp_call*/ 0," << endl; + s << INDENT << "/*tp_call*/ " << tp_call << ',' << endl; s << INDENT << "/*tp_str*/ " << m_tpFuncs["__str__"] << ',' << endl; s << INDENT << "/*tp_getattro*/ " << tp_getattro << ',' << endl; s << INDENT << "/*tp_setattro*/ " << tp_setattro << ',' << endl; diff --git a/generator/shibokengenerator.cpp b/generator/shibokengenerator.cpp index 9546da775..fd814dfe2 100644 --- a/generator/shibokengenerator.cpp +++ b/generator/shibokengenerator.cpp @@ -118,6 +118,9 @@ void ShibokenGenerator::initPrimitiveTypesCorrespondences() // Python operators m_pythonOperators.clear(); + // call operator + m_pythonOperators["operator()"] = "call"; + // Arithmetic operators m_pythonOperators["operator+"] = "add"; m_pythonOperators["operator-"] = "sub"; |