diff options
Diffstat (limited to 'sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp')
| -rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp | 68 |
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, |
