diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-03-02 11:31:36 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2010-03-02 14:44:59 -0300 |
commit | aeb0fe66f39b46ddb2e963067c91b426f9a013d0 (patch) | |
tree | 3afa0ed5be03f7ed626c146c7ea402ac17f24e40 | |
parent | ea999da07ab6d244ffb982d7a3c86da1a8976f44 (diff) |
Adds extended conversions writer functions.
Adds the functions responsible for writing code for functions that
supports extensible conversions.
-rw-r--r-- | cppgenerator.cpp | 50 | ||||
-rw-r--r-- | cppgenerator.h | 4 |
2 files changed, 54 insertions, 0 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index f5cdad8ca..84e7e9e25 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -1673,6 +1673,56 @@ void CppGenerator::writeSpecialCastFunction(QTextStream& s, const AbstractMetaCl s << "}\n\n"; } +void CppGenerator::writeExtendedIsConvertibleFunction(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions) +{ + s << "static bool " << extendedIsConvertibleFunctionName(externalType) << "(PyObject* pyobj)" << endl; + s << '{' << endl; + s << INDENT << "return "; + bool isFirst = true; + foreach (const AbstractMetaClass* metaClass, conversions) { + Indentation indent(INDENT); + if (isFirst) + isFirst = false; + else + s << endl << INDENT << " || "; + s << cpythonCheckFunction(metaClass->typeEntry()) << "(pyobj)"; + } + s << ';' << endl; + s << '}' << endl; +} + +void CppGenerator::writeExtendedToCppFunction(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions) +{ + s << "static void* " << extendedToCppFunctionName(externalType) << "(PyObject* pyobj)" << endl; + s << '{' << endl; + s << INDENT << "void* cptr = 0;" << endl; + bool isFirst = true; + foreach (const AbstractMetaClass* metaClass, conversions) { + s << INDENT; + if (isFirst) + isFirst = false; + else + s << "else "; + s << "if (" << cpythonCheckFunction(metaClass->typeEntry()) << "(pyobj))" << endl; + Indentation indent(INDENT); + s << INDENT << "cptr = new " << externalType->name() << '('; + writeToCppConversion(s, metaClass, "pyobj"); + s << ");" << endl; + } + s << INDENT << "return cptr;" << endl; + s << '}' << endl; +} + +void CppGenerator::writeExtendedConverterInitialization(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions) +{ + s << INDENT << "// Extended implicit conversions for " << externalType->targetLangPackage() << '.' << externalType->name() << endl; + s << INDENT << "shiboType = reinterpret_cast<Shiboken::SbkBaseWrapperType*>("; + s << cppApiVariableName(externalType->targetLangPackage()) << '['; + s << getTypeIndexVariableName(externalType) << "]);" << endl; + s << INDENT << "shiboType->ext_isconvertible = " << extendedIsConvertibleFunctionName(externalType) << ';' << endl; + s << INDENT << "shiboType->ext_tocpp = " << extendedToCppFunctionName(externalType) << ';' << endl; +} + QString CppGenerator::multipleInheritanceInitializerFunctionName(const AbstractMetaClass* metaClass) { if (!hasMultipleInheritanceInAncestry(metaClass)) diff --git a/cppgenerator.h b/cppgenerator.h index 2230d6ba2..1df870d81 100644 --- a/cppgenerator.h +++ b/cppgenerator.h @@ -149,6 +149,10 @@ private: /// Writes the implementation of special cast functions, used when we need to cast a class with mulltiple inheritance. void writeSpecialCastFunction(QTextStream& s, const AbstractMetaClass* metaClass); + void writeExtendedIsConvertibleFunction(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions); + void writeExtendedToCppFunction(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions); + void writeExtendedConverterInitialization(QTextStream& s, const TypeEntry* externalType, const QList<const AbstractMetaClass*>& conversions); + void writeParentChildManagement(QTextStream& s, const AbstractMetaFunction* func); void writeReturnValueHeuristics(QTextStream& s, const AbstractMetaFunction* func, const QString& self = "self"); /** |