diff options
author | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-11-16 00:19:04 -0300 |
---|---|---|
committer | Marcelo Lira <marcelo.lira@openbossa.org> | 2009-11-18 09:22:51 -0300 |
commit | 88f1e3aa4f3677687355813f4ff326d273a17e48 (patch) | |
tree | 0612d934d305708084826c0cc498f8a1712d9851 | |
parent | 2807ddf87ab5d85698011a4260c833c7fc577fe2 (diff) | |
download | shiboken-88f1e3aa4f3677687355813f4ff326d273a17e48.tar.gz shiboken-88f1e3aa4f3677687355813f4ff326d273a17e48.tar.xz shiboken-88f1e3aa4f3677687355813f4ff326d273a17e48.zip |
Added the getAncestorMultipleInheritance method to CppGenerator,
it returns a QStringList with the names of all classes that are
multiple parents for the current class or any of its ancestors.
The purpose is to get a list of all possible casts that could
change the memory address of the base pointer of a class.
-rw-r--r-- | cppgenerator.cpp | 16 | ||||
-rw-r--r-- | cppgenerator.h | 3 |
2 files changed, 16 insertions, 3 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp index e3574d7c..2d41edb2 100644 --- a/cppgenerator.cpp +++ b/cppgenerator.cpp @@ -1080,12 +1080,22 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f } } +QStringList CppGenerator::getAncestorMultipleInheritance(const AbstractMetaClass* metaClass) +{ + QStringList result = metaClass->baseClassNames(); + if (!result.isEmpty()) { + foreach (const AbstractMetaClass* pClass, getBaseClasses(metaClass)) + result.append(getAncestorMultipleInheritance(pClass)); + } + return result; +} void CppGenerator::writeMultipleInheritanceInitializerFunction(QTextStream& s, const AbstractMetaClass* metaClass) { QString className = metaClass->qualifiedCppName(); + QStringList ancestors = getAncestorMultipleInheritance(metaClass); s << "static int mi_offsets[] = { "; - for (int i = 0; i < metaClass->baseClassNames().size(); i++) + for (int i = 0; i < ancestors.size(); i++) s << "-1, "; s << "-1 };" << endl; s << "int*" << endl; @@ -1097,9 +1107,9 @@ void CppGenerator::writeMultipleInheritanceInitializerFunction(QTextStream& s, c s << INDENT << "const " << className << "* class_ptr = reinterpret_cast<const " << className << "*>(cptr);" << endl; s << INDENT << "size_t base = (size_t) class_ptr;" << endl; int i = 0; - foreach (QString parentName, metaClass->baseClassNames()) { + foreach (QString ancestor, ancestors) { s << INDENT << "mi_offsets[" << i << "] = "; - s << "((size_t) static_cast<const " << parentName << "*>(class_ptr)) - base;" << endl; + s << "((size_t) static_cast<const " << ancestor << "*>(class_ptr)) - base;" << endl; i++; } } diff --git a/cppgenerator.h b/cppgenerator.h index 87df8e4a..4e7709da 100644 --- a/cppgenerator.h +++ b/cppgenerator.h @@ -121,6 +121,9 @@ private: */ QString multipleInheritanceInitializerFunctionName(const AbstractMetaClass* metaClass); + /// Returns a list of all classes to which the given class could be casted. + QStringList getAncestorMultipleInheritance(const AbstractMetaClass* metaClass); + /// Returns true if the given class supports the python sequence protocol bool supportsSequenceProtocol(const AbstractMetaClass* metaClass); // Maps special function names to function parameters and return types |