aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-05-19 12:26:46 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-05-19 14:26:43 +0200
commitee47ccbd9a7310da01b421c51c956739df0acdf4 (patch)
tree5d2e334f0c3958b9c74f2249c22f81b2a285c52f
parent14c6809ec52ea0583e310825c158fe0e0ab68883 (diff)
shiboken6: Generate converters for all smart pointee base classes
Introduce helper functions to recursively collect all base classes. Amends 24cd62c9d18850707574ba7eb637ff24bee353a1. Pick-to: 6.3 6.2 5.15 Fixes: PYSIDE-1933 Task-number: SIDE-1397 Change-Id: I7c205d226d77c113f5a1e90a2e93e96fe4c54e5e Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
-rw-r--r--sources/shiboken6/generator/shiboken/cppgenerator.cpp73
1 files changed, 46 insertions, 27 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
index 1eb4d6a33..6c2648cbf 100644
--- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp
+++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp
@@ -1945,31 +1945,54 @@ void CppGenerator::writeContainerConverterFunctions(TextStream &s,
writePythonToCppConversionFunctions(s, containerType);
}
+// Helpers to collect all smart pointer pointee base classes
+bool collectBaseClasses(const AbstractMetaClass *c, AbstractMetaClassCList &list)
+{
+ const auto bases = c->typeSystemBaseClasses();
+ for (auto *base : bases) {
+ if (!list.contains(base))
+ list.append(base);
+ }
+ return false; // let recurseClassHierarchy() traverse all base classes
+}
+
+static AbstractMetaClassCList findSmartPointeeBaseClasses(const ApiExtractorResult &api,
+ const AbstractMetaType &smartPointerType)
+{
+ AbstractMetaClassCList result;
+ auto *instantiationsTe = smartPointerType.instantiations().at(0).typeEntry();
+ auto targetClass = AbstractMetaClass::findClass(api.classes(), instantiationsTe);
+ if (targetClass == nullptr)
+ return result;
+ recurseClassHierarchy(targetClass,
+ [&result](const AbstractMetaClass *c) {
+ return collectBaseClasses(c, result);
+ });
+ return result;
+}
+
void CppGenerator::writeSmartPointerConverterFunctions(TextStream &s,
const AbstractMetaType &smartPointerType) const
{
- auto targetClass = AbstractMetaClass::findClass(api().classes(),
- smartPointerType.instantiations().at(0).typeEntry());
-
- if (targetClass) {
- const auto *smartPointerTypeEntry =
- static_cast<const SmartPointerTypeEntry *>(
- smartPointerType.typeEntry());
-
- // TODO: Missing conversion to smart pointer pointer type:
-
- s << "// Register smartpointer conversion for all derived classes\n";
- const auto classes = targetClass->typeSystemBaseClasses();
- for (auto base : classes) {
- auto *baseTe = base->typeEntry();
- if (smartPointerTypeEntry->matchesInstantiation(baseTe)) {
- if (auto opt = findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) {
- const auto smartTargetType = opt.value();
- s << "// SmartPointer derived class: "
- << smartTargetType.cppSignature() << "\n";
- writePythonToCppConversionFunctions(s, smartPointerType,
- smartTargetType, {}, {}, {});
- }
+ const auto baseClasses = findSmartPointeeBaseClasses(api(), smartPointerType);
+ if (baseClasses.isEmpty())
+ return;
+
+ auto *smartPointerTypeEntry =
+ static_cast<const SmartPointerTypeEntry *>(smartPointerType.typeEntry());
+
+ // TODO: Missing conversion to smart pointer pointer type:
+
+ s << "// Register smartpointer conversion for all derived classes\n";
+ for (auto *base : baseClasses) {
+ auto *baseTe = base->typeEntry();
+ if (smartPointerTypeEntry->matchesInstantiation(baseTe)) {
+ if (auto opt = findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) {
+ const auto smartTargetType = opt.value();
+ s << "// SmartPointer derived class: "
+ << smartTargetType.cppSignature() << "\n";
+ writePythonToCppConversionFunctions(s, smartPointerType,
+ smartTargetType, {}, {}, {});
}
}
}
@@ -4328,11 +4351,7 @@ void CppGenerator::writeSmartPointerConverterInitialization(TextStream &s, const
writeAddPythonToCppConversion(s, targetConverter, toCpp, isConv);
};
- auto klass = AbstractMetaClass::findClass(api().classes(), type.instantiations().at(0).typeEntry());
- if (!klass)
- return;
-
- const auto classes = klass->typeSystemBaseClasses();
+ const auto classes = findSmartPointeeBaseClasses(api(), type);
if (classes.isEmpty())
return;