diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-04-21 15:07:41 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2017-04-21 15:13:38 +0200 |
commit | 00c61832d70f39438b8a60292786650b78d97357 (patch) | |
tree | 63280ea9a8fb54a8966b82e274426e9d88a37811 | |
parent | 1c21ef10828bb7e4fa9b404c7389af5c093a25e7 (diff) | |
parent | 4d80579c49a40cbbb24bef2cb4cbe4520b7b4ca9 (diff) |
Merge remote-tracking branch 'origin/5.6' into 5.9
Change-Id: I3000fca52e7447c2b53b07a0aca8edc24aa903cb
-rw-r--r-- | generator/shiboken2/cppgenerator.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/generator/shiboken2/cppgenerator.cpp b/generator/shiboken2/cppgenerator.cpp index 28a0e4b..df2fd4a 100644 --- a/generator/shiboken2/cppgenerator.cpp +++ b/generator/shiboken2/cppgenerator.cpp @@ -259,11 +259,24 @@ void CppGenerator::generateClass(QTextStream &s, GeneratorContext &classContext) if (hasMultipleInheritanceInAncestry(metaClass)) s << "#include <set>" << endl; - s << "#include \"" << getModuleHeaderFileName() << '"' << endl << endl; + s << endl << "// module include" << endl << "#include \"" << getModuleHeaderFileName() << '"' << endl; QString headerfile = fileNameForContext(classContext); headerfile.replace(QLatin1String(".cpp"), QLatin1String(".h")); - s << "#include \"" << headerfile << '"' << endl; + s << endl << "// main header" << endl << "#include \"" << headerfile << '"' << endl; + + // PYSIDE-500: Use also includes for inherited wrapper classes, because + // with the protected hack, we sometimes need to cast inherited wrappers. + s << endl << "// inherited wrapper classes" << endl; + AbstractMetaClass *basis = metaClass->baseClass(); + for (; basis; basis = basis->baseClass()) { + GeneratorContext basisContext(basis); + QString headerfile = fileNameForContext(basisContext); + headerfile.replace(QLatin1String(".cpp"), QLatin1String(".h")); + s << "#include \"" << headerfile << '"' << endl; + } + + s << endl << "// inner classes" << endl; const AbstractMetaClassList &innerClasses = metaClass->innerClasses(); for (AbstractMetaClass *innerClass : innerClasses) { GeneratorContext innerClassContext(innerClass); @@ -3171,11 +3184,18 @@ void CppGenerator::writeMethodCall(QTextStream &s, const AbstractMetaFunction *f if (func->isConstant()) { if (avoidProtectedHack()) { mc << "const_cast<const ::"; - if (func->ownerClass()->hasProtectedMembers()) + if (func->ownerClass()->hasProtectedMembers()) { + // PYSIDE-500: Need a special wrapper cast when inherited + const QString selfWrapCast = func->ownerClass() == func->implementingClass() + ? QLatin1String(CPP_SELF_VAR) + : QLatin1String("reinterpret_cast<") + wrapperName(func->ownerClass()) + QLatin1String(" *>(" CPP_SELF_VAR ")"); mc << wrapperName(func->ownerClass()); - else + mc << "*>(" << selfWrapCast << ")->"; + } + else { mc << methodCallClassName; - mc << "*>(" << selfVarCast << ")->"; + mc << "*>(" << selfVarCast << ")->"; + } } else { mc << "const_cast<const ::" << methodCallClassName; mc << "*>(" << selfVarCast << ")->"; |