diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-05-19 12:26:46 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-05-23 11:12:53 +0200 |
commit | 1cc547a413207677584e87d5851d8a4c3d35b6fa (patch) | |
tree | 7329bc73e11b2a208e5368fd93005ca4f045230b | |
parent | 109453d5bf09d1337b4cc0cb5d13dfa0f900a8f6 (diff) |
shiboken6: Generate converters for all smart pointee base classes
Introduce helper functions to recursively collect all base classes.
Amends 24cd62c9d18850707574ba7eb637ff24bee353a1.
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>
(cherry picked from commit ee47ccbd9a7310da01b421c51c956739df0acdf4)
-rw-r--r-- | sources/shiboken6/generator/shiboken/cppgenerator.cpp | 59 |
1 files changed, 32 insertions, 27 deletions
diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index 64d99ef74..5dd8978e1 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -1910,31 +1910,40 @@ void CppGenerator::writeContainerConverterFunctions(TextStream &s, writePythonToCppConversionFunctions(s, containerType); } +// Helpers to collect all smart pointer pointee 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) + result = targetClass->allTypeSystemAncestors(); + 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, {}, {}, {}); } } } @@ -4301,11 +4310,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; |