aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-09-30 12:27:12 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-02-05 11:48:54 +0100
commit919ee9a8677a1f0838af3f7d3d59e18179c42242 (patch)
treeaf0b74dcf67511477199d5dedb267cd51c3e88eb /sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
parent242f0fa7269e9baf331679dc413c28471b1f7d05 (diff)
shiboken: Make it possible to specify smartpointer instantiations
Add an attribute "instantiations" to the smart-pointer-type element, which allows to specify a comma-separated list of instantiation types for which wrappers should be generated in the module. This avoids clashes of indexes. Task-number: PYSIDE-1024 Change-Id: Iac4b93b91ca4982064beef4c5abafc547052e7f1 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp')
-rw-r--r--sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp68
1 files changed, 48 insertions, 20 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
index 59ea3b079..514027242 100644
--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
@@ -2286,6 +2286,26 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
return nullptr;
}
+ QScopedPointer<AbstractMetaType> metaType(new AbstractMetaType);
+ metaType->setIndirectionsV(typeInfo.indirectionsV());
+ metaType->setReferenceType(typeInfo.referenceType());
+ metaType->setConstant(typeInfo.isConstant());
+ metaType->setVolatile(typeInfo.isVolatile());
+ metaType->setOriginalTypeDescription(_typei.toString());
+
+ const auto &templateArguments = typeInfo.instantiations();
+ for (int t = 0, size = templateArguments.size(); t < size; ++t) {
+ const TypeInfo &ti = templateArguments.at(t);
+ AbstractMetaType *targType = translateTypeStatic(ti, currentClass, d, flags, &errorMessage);
+ if (!targType) {
+ if (errorMessageIn)
+ *errorMessageIn = msgCannotTranslateTemplateArgument(t, ti, errorMessage);
+ return nullptr;
+ }
+
+ metaType->addInstantiation(targType, true);
+ }
+
if (types.size() > 1) {
const bool sameType = std::all_of(types.cbegin() + 1, types.cend(),
[typeEntryType](const TypeEntry *e) {
@@ -2295,43 +2315,51 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
*errorMessageIn = msgAmbiguousVaryingTypesFound(qualifiedName, types);
return nullptr;
}
- // Ambiguous primitive types are possible (when including type systems).
- if (typeEntryType != TypeEntry::PrimitiveType) {
+ // Ambiguous primitive/smart pointer types are possible (when
+ // including type systems).
+ if (typeEntryType != TypeEntry::PrimitiveType
+ && typeEntryType != TypeEntry::SmartPointerType) {
if (errorMessageIn)
*errorMessageIn = msgAmbiguousTypesFound(qualifiedName, types);
return nullptr;
}
}
- auto *metaType = new AbstractMetaType;
- metaType->setTypeEntry(type);
- metaType->setIndirectionsV(typeInfo.indirectionsV());
- metaType->setReferenceType(typeInfo.referenceType());
- metaType->setConstant(typeInfo.isConstant());
- metaType->setVolatile(typeInfo.isVolatile());
- metaType->setOriginalTypeDescription(_typei.toString());
-
- const auto &templateArguments = typeInfo.instantiations();
- for (int t = 0, size = templateArguments.size(); t < size; ++t) {
- const TypeInfo &ti = templateArguments.at(t);
- AbstractMetaType *targType = translateTypeStatic(ti, currentClass, d, flags, &errorMessage);
- if (!targType) {
+ if (typeEntryType == TypeEntry::SmartPointerType) {
+ // Find a matching instantiation
+ if (metaType->instantiations().size() != 1) {
if (errorMessageIn)
- *errorMessageIn = msgCannotTranslateTemplateArgument(t, ti, errorMessage);
- delete metaType;
+ *errorMessageIn = msgInvalidSmartPointerType(_typei);
return nullptr;
}
-
- metaType->addInstantiation(targType, true);
+ auto instantiationType = metaType->instantiations().constFirst()->typeEntry();
+ if (instantiationType->type() == TypeEntry::TemplateArgumentType) {
+ // Member functions of the template itself, SharedPtr(const SharedPtr &)
+ type = instantiationType;
+ } else {
+ auto it = std::find_if(types.cbegin(), types.cend(),
+ [instantiationType](const TypeEntry *e) {
+ auto smartPtr = static_cast<const SmartPointerTypeEntry *>(e);
+ return smartPtr->matchesInstantiation(instantiationType);
+ });
+ if (it == types.cend()) {
+ if (errorMessageIn)
+ *errorMessageIn = msgCannotFindSmartPointerInstantion(_typei);
+ return nullptr;
+ }
+ type =*it;
+ }
}
+ metaType->setTypeEntry(type);
+
// The usage pattern *must* be decided *after* the possible template
// instantiations have been determined, or else the absence of
// such instantiations will break the caching scheme of
// AbstractMetaType::cppSignature().
metaType->decideUsagePattern();
- return metaType;
+ return metaType.take();
}
AbstractMetaType *AbstractMetaBuilder::translateType(const TypeInfo &_typei,