From e7739fde3909eddb40fa397376cad4781f8edabf Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 26 Jan 2022 11:01:16 +0100 Subject: shiboken6: Automatically generate opaque containers for the specified types Previously, shiboken6 would only generate opaque containers if the instantiation is actually used in the module API. Change that to always generate them for the instantiation types from the respective module. [ChangeLog][shiboken6] Opaque containers are now always generated for the specified types. Task-number: PYSIDE-1605 Task-number: PYSIDE-1790 Change-Id: I21ce637712f2d1e21b7c7a04151c3b67fa7b28c0 Reviewed-by: Qt CI Bot Reviewed-by: Cristian Maureira-Fredes Reviewed-by: Christian Tismer --- sources/shiboken6/generator/generator.cpp | 32 +++++++++++++++++++++++++++++++ sources/shiboken6/generator/generator.h | 1 + 2 files changed, 33 insertions(+) diff --git a/sources/shiboken6/generator/generator.cpp b/sources/shiboken6/generator/generator.cpp index 35ecbc780..b984905b0 100644 --- a/sources/shiboken6/generator/generator.cpp +++ b/sources/shiboken6/generator/generator.cpp @@ -341,12 +341,44 @@ void Generator::collectInstantiatedContainersAndSmartPointers(const AbstractMeta void Generator::collectInstantiatedContainersAndSmartPointers() { + collectInstantiatedOpqaqueContainers(); for (const auto &func : m_d->api.globalFunctions()) collectInstantiatedContainersAndSmartPointers(func); for (auto metaClass : m_d->api.classes()) collectInstantiatedContainersAndSmartPointers(metaClass); } +// Whether to generate an opaque container: If the instantiation type is in +// the current package or, for primitive types, if the container is in the +// current package. +static bool generateOpaqueContainer(const AbstractMetaType &type, + const TypeSystemTypeEntry *moduleEntry) +{ + auto *te = type.instantiations().constFirst().typeEntry(); + auto *typeModuleEntry = te->typeSystemTypeEntry(); + return typeModuleEntry == moduleEntry + || (te->isPrimitive() && type.typeEntry()->typeSystemTypeEntry() == moduleEntry); +} + +void Generator::collectInstantiatedOpqaqueContainers() +{ + // Add all instantiations of opaque containers for types from the current + // module. + auto *td = TypeDatabase::instance(); + const auto *moduleEntry = TypeDatabase::instance()->defaultTypeSystemType(); + const auto &containers = td->containerTypes(); + for (const auto *container : containers) { + for (const auto &oc : container->opaqueContainers()) { + QString errorMessage; + const QString typeName = container->qualifiedCppName() + u'<' + + oc.instantiation + u'>'; + auto typeOpt = AbstractMetaType::fromString(typeName, &errorMessage); + if (typeOpt.has_value() && generateOpaqueContainer(typeOpt.value(), moduleEntry)) + addInstantiatedContainersAndSmartPointers(typeOpt.value(), u"opaque containers"_qs); + } + } +} + AbstractMetaTypeList Generator::instantiatedContainers() const { return m_d->instantiatedContainers; diff --git a/sources/shiboken6/generator/generator.h b/sources/shiboken6/generator/generator.h index 6d10dcb1f..21a0df885 100644 --- a/sources/shiboken6/generator/generator.h +++ b/sources/shiboken6/generator/generator.h @@ -374,6 +374,7 @@ private: void collectInstantiatedContainersAndSmartPointers(const AbstractMetaFunctionCPtr &func); void collectInstantiatedContainersAndSmartPointers(const AbstractMetaClass *metaClass); void collectInstantiatedContainersAndSmartPointers(); + void collectInstantiatedOpqaqueContainers(); }; Q_DECLARE_OPERATORS_FOR_FLAGS(Generator::Options) -- cgit v1.2.3