diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-01-26 11:01:16 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-01-27 12:41:30 +0100 |
commit | e7739fde3909eddb40fa397376cad4781f8edabf (patch) | |
tree | b465c498944d092b4114b15c37606a5fe3e5a024 | |
parent | 7a23278e056f3e59a86c7a1b48c6fd26d2096877 (diff) |
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 <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r-- | sources/shiboken6/generator/generator.cpp | 32 | ||||
-rw-r--r-- | sources/shiboken6/generator/generator.h | 1 |
2 files changed, 33 insertions, 0 deletions
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) |