summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcelo Lira <marcelo.lira@openbossa.org>2009-11-17 10:40:14 -0300
committerMarcelo Lira <marcelo.lira@openbossa.org>2009-11-18 09:22:51 -0300
commit3f3e7a567129990e05ca9d5a2e641438b888f713 (patch)
tree6371096344bb720299d4f36e694c61bd5deed3a2
parent1dacb1f53874fe0e78fae1a613f1d3167c97efc7 (diff)
downloadshiboken-3f3e7a567129990e05ca9d5a2e641438b888f713.tar.gz
shiboken-3f3e7a567129990e05ca9d5a2e641438b888f713.tar.xz
shiboken-3f3e7a567129990e05ca9d5a2e641438b888f713.zip
Modified the multiple inheritance initializer function to consider
cases where the pointer is casted to void* and then casted to a parent pointer, and after that to a grandparent pointer. The multiple inheritance initializer is now using a STL set object to avoid registering the same offset multiple times.
-rw-r--r--cppgenerator.cpp36
1 files changed, 29 insertions, 7 deletions
diff --git a/cppgenerator.cpp b/cppgenerator.cpp
index 4bfb6187..50b47b5a 100644
--- a/cppgenerator.cpp
+++ b/cppgenerator.cpp
@@ -88,6 +88,12 @@ void CppGenerator::generateClass(QTextStream &s, const AbstractMetaClass *metaCl
// headers
s << "// default includes" << endl;
s << "#include <shiboken.h>" << endl;
+
+ // The multiple inheritance initialization function
+ // needs the 'set' class from C++ STL.
+ if (hasMultipleInheritanceInAncestry(metaClass))
+ s << "#include <set>" << endl;
+
s << "#include \"" << moduleName().toLower() << "_python.h\"" << endl << endl;
QString converterImpl;
@@ -1082,8 +1088,12 @@ void CppGenerator::writeMethodCall(QTextStream& s, const AbstractMetaFunction* f
QStringList CppGenerator::getAncestorMultipleInheritance(const AbstractMetaClass* metaClass)
{
- QStringList result = metaClass->baseClassNames();
- if (!result.isEmpty()) {
+ QStringList result;
+ if (!metaClass->baseClassNames().isEmpty()) {
+ foreach (QString base, metaClass->baseClassNames()) {
+ result.append(QString("((size_t) static_cast<const %1*>(class_ptr)) - base").arg(base));
+ result.append(QString("((size_t) static_cast<const %1*>((%2*)((void*)class_ptr))) - base").arg(base).arg(metaClass->name()));
+ }
foreach (const AbstractMetaClass* pClass, getBaseClasses(metaClass))
result.append(getAncestorMultipleInheritance(pClass));
}
@@ -1104,14 +1114,26 @@ void CppGenerator::writeMultipleInheritanceInitializerFunction(QTextStream& s, c
s << INDENT << "if (mi_offsets[0] == -1) {" << endl;
{
Indentation indent(INDENT);
+ s << INDENT << "std::set<int> offsets;" << endl;
+ s << INDENT << "std::set<int>::iterator it;" << endl;
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 ancestor, ancestors) {
- s << INDENT << "mi_offsets[" << i << "] = ";
- s << "((size_t) static_cast<const " << ancestor << "*>(class_ptr)) - base;" << endl;
- i++;
+
+ foreach (QString ancestor, ancestors)
+ s << INDENT << "offsets.insert(" << ancestor << ");" << endl;
+
+ s << endl;
+ s << INDENT << "offsets.erase(0);" << endl;
+ s << endl;
+
+ s << INDENT << "int i = 0;" << endl;
+ s << INDENT << "for (it = offsets.begin(); it != offsets.end(); it++) {" << endl;
+ {
+ Indentation indent(INDENT);
+ s << INDENT << "mi_offsets[i] = *it;" << endl;
+ s << INDENT << "i++;" << endl;
}
+ s << INDENT << '}' << endl;
}
s << INDENT << '}' << endl;
s << INDENT << "return mi_offsets;" << endl;