diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor')
64 files changed, 756 insertions, 689 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index 499f79874..aa57c1b06 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -139,7 +139,7 @@ const AbstractMetaEnumList &AbstractMetaBuilder::globalEnums() const return d->m_globalEnums; } -const QHash<const TypeEntry *, AbstractMetaEnum> &AbstractMetaBuilder::typeEntryToEnumsHash() const +const QHash<TypeEntryCPtr, AbstractMetaEnum> &AbstractMetaBuilder::typeEntryToEnumsHash() const { return d->m_enums; } @@ -149,13 +149,13 @@ void AbstractMetaBuilderPrivate::checkFunctionModifications() const auto &entries = TypeDatabase::instance()->entries(); for (auto it = entries.cbegin(), end = entries.cend(); it != end; ++it) { - const TypeEntry *entry = it.value(); - if (!entry) + TypeEntryCPtr entry = it.value(); + if (entry.isNull()) continue; if (!entry->isComplex() || !entry->generateCode()) continue; - auto centry = static_cast<const ComplexTypeEntry *>(entry); + auto centry = qSharedPointerCast<const ComplexTypeEntry>(entry); if (!centry->generateCode()) continue; @@ -205,8 +205,8 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::argumentToClass(const ArgumentMod auto type = translateType(argument->type(), currentClass); if (!type.has_value()) return returned; - const TypeEntry *entry = type->typeEntry(); - if (entry && entry->isComplex()) + TypeEntryCPtr entry = type->typeEntry(); + if (!entry.isNull() && entry->isComplex()) returned = AbstractMetaClass::findClass(m_metaClasses, entry); return returned; } @@ -274,7 +274,7 @@ void AbstractMetaBuilderPrivate::traverseOperatorFunction(const FunctionModelIte firstArgumentIsSelf = false; } else { auto type = translateType(item->type(), currentClass); - const TypeEntry *retType = type.has_value() ? type->typeEntry() : nullptr; + const auto retType = type.has_value() ? type->typeEntry() : TypeEntryCPtr{}; AbstractMetaClass *otherArgClass = argumentToClass(itemArguments.at(1), currentClass); if (otherArgClass && retType && (retType->isValue() || retType->isObject()) @@ -378,7 +378,7 @@ bool AbstractMetaBuilderPrivate::traverseStreamOperator(const FunctionModelItem } funcClass->addFunction(AbstractMetaFunctionCPtr(streamFunction)); - auto *funcTe = funcClass->typeEntry(); + auto funcTe = funcClass->typeEntry(); if (funcClass == streamClass) funcTe->addArgumentInclude(streamedClass->typeEntry()->include()); else @@ -527,8 +527,8 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom, if (func->accessPolicy() != Access::Public || func->name().startsWith(u"operator")) continue; - FunctionTypeEntry *funcEntry = types->findFunctionType(func->name()); - if (!funcEntry || !funcEntry->generateCode()) + FunctionTypeEntryPtr funcEntry = types->findFunctionType(func->name()); + if (funcEntry.isNull() || !funcEntry->generateCode()) continue; AbstractMetaFunction *metaFunc = traverseFunction(func, nullptr); @@ -582,7 +582,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom, ReportHandler::startProgress("Detecting inconsistencies in typesystem (" + QByteArray::number(allEntries.size()) + ")..."); for (auto it = allEntries.cbegin(), end = allEntries.cend(); it != end; ++it) { - TypeEntry *entry = it.value(); + TypeEntryPtr entry = it.value(); if (!entry->isPrimitive()) { if ((entry->isValue() || entry->isObject()) && !types->shouldDropTypeEntry(entry->qualifiedCppName()) @@ -592,7 +592,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom, && !AbstractMetaClass::findClass(m_metaClasses, entry)) { qCWarning(lcShiboken, "%s", qPrintable(msgTypeNotDefined(entry))); } else if (entry->generateCode() && entry->type() == TypeEntry::FunctionType) { - auto fte = static_cast<const FunctionTypeEntry *>(entry); + auto fte = qSharedPointerCast<const FunctionTypeEntry>(entry); const QStringList &signatures = fte->signatures(); for (const QString &signature : signatures) { bool ok = false; @@ -610,7 +610,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom, } } } else if (entry->isEnum() && entry->generateCode()) { - auto enumEntry = static_cast<const EnumTypeEntry *>(entry); + const auto enumEntry = qSharedPointerCast<const EnumTypeEntry>(entry); AbstractMetaClass *cls = AbstractMetaClass::findClass(m_metaClasses, enumEntry->parent()); @@ -828,11 +828,11 @@ std::optional<AbstractMetaEnum> { QString qualifiedName = enumItem->qualifiedName().join(colonColon()); - TypeEntry *typeEntry = nullptr; - const TypeEntry *enclosingTypeEntry = enclosing ? enclosing->typeEntry() : nullptr; + TypeEntryPtr typeEntry; + const auto enclosingTypeEntry = enclosing ? enclosing->typeEntry() : TypeEntryCPtr{}; if (enumItem->accessPolicy() == Access::Private) { - typeEntry = new EnumTypeEntry(enumItem->qualifiedName().constLast(), - QVersionNumber(0, 0), enclosingTypeEntry); + typeEntry.reset(new EnumTypeEntry(enumItem->qualifiedName().constLast(), + QVersionNumber(0, 0), enclosingTypeEntry)); TypeDatabase::instance()->addType(typeEntry); } else if (enumItem->enumKind() != AnonymousEnum) { typeEntry = TypeDatabase::instance()->findType(qualifiedName); @@ -890,7 +890,7 @@ std::optional<AbstractMetaEnum> metaEnum.setHasQEnumsDeclaration(true); } - auto *enumTypeEntry = static_cast<EnumTypeEntry *>(typeEntry); + auto enumTypeEntry = qSharedPointerCast<EnumTypeEntry>(typeEntry); metaEnum.setTypeEntry(enumTypeEntry); metaEnum.setAccess(enumItem->accessPolicy()); if (metaEnum.access() == Access::Private) @@ -916,10 +916,9 @@ std::optional<AbstractMetaEnum> const bool isScopedEnum = enumItem->enumKind() == EnumClass; const EnumeratorList &enumerators = enumItem->enumerators(); for (const EnumeratorModelItem &e : enumerators) { - auto enumValue = - new EnumValueTypeEntry(e->name(), e->stringValue(), - enumTypeEntry, isScopedEnum, - enumTypeEntry->version()); + EnumValueTypeEntryPtr enumValue(new EnumValueTypeEntry(e->name(), e->stringValue(), + enumTypeEntry, isScopedEnum, + enumTypeEntry->version())); TypeDatabase::instance()->addType(enumValue); if (e->value().isNullValue()) enumTypeEntry->setNullValue(enumValue); @@ -948,11 +947,11 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelIt // If this is the alias for a primitive type // we store the aliased type on the alias // TypeEntry - PrimitiveTypeEntry *ptype = types->findPrimitiveType(className); + const auto ptype = types->findPrimitiveType(className); const auto &targetNames = typeDef->type().qualifiedName(); - PrimitiveTypeEntry *pTarget = targetNames.size() == 1 - ? types->findPrimitiveType(targetNames.constFirst()) : nullptr; - if (ptype) { + const auto pTarget = targetNames.size() == 1 + ? types->findPrimitiveType(targetNames.constFirst()) : PrimitiveTypeEntryPtr{}; + if (!ptype.isNull()) { ptype->setReferencedTypeEntry(pTarget); return nullptr; } @@ -961,7 +960,7 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelIt // (like size_t = unsigned)? Add it to the type DB. if (pTarget && isCppPrimitive(basicReferencedNonBuiltinTypeEntry(pTarget)) && currentClass == nullptr) { - auto *pte = new PrimitiveTypeEntry(className, {}, nullptr); + PrimitiveTypeEntryPtr pte(new PrimitiveTypeEntry(className, {}, {})); pte->setReferencedTypeEntry(pTarget); pte->setBuiltIn(true); types->addType(pte); @@ -969,8 +968,8 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelIt } // If we haven't specified anything for the typedef, then we don't care - ComplexTypeEntry *type = types->findComplexType(fullClassName); - if (!type) + auto type = types->findComplexType(fullClassName); + if (type.isNull()) return nullptr; auto *metaClass = new AbstractMetaClass; @@ -992,7 +991,7 @@ void AbstractMetaBuilderPrivate::traverseTypesystemTypedefs() { const auto &entries = TypeDatabase::instance()->typedefEntries(); for (auto it = entries.begin(), end = entries.end(); it != end; ++it) { - TypedefEntry *te = it.value(); + TypedefEntryPtr te = it.value(); auto *metaClass = new AbstractMetaClass; metaClass->setTypeDef(true); metaClass->setTypeEntry(te->target()); @@ -1032,14 +1031,14 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem + colonColon() + fullClassName; } - ComplexTypeEntry *type = TypeDatabase::instance()->findComplexType(fullClassName); + const auto type = TypeDatabase::instance()->findComplexType(fullClassName); AbstractMetaBuilder::RejectReason reason = AbstractMetaBuilder::NoReason; if (TypeDatabase::instance()->isClassRejected(fullClassName)) { reason = AbstractMetaBuilder::GenerationDisabled; - } else if (!type) { - TypeEntry *te = TypeDatabase::instance()->findType(fullClassName); - if (te && !te->isComplex()) { + } else if (type.isNull()) { + TypeEntryPtr te = TypeDatabase::instance()->findType(fullClassName); + if (!te.isNull() && !te->isComplex()) { reason = AbstractMetaBuilder::RedefinedToNotClass; // Set the default include file name if (!te->include().isValid()) @@ -1098,7 +1097,7 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem auto param_type = new TemplateArgumentEntry(param->name(), type->version(), argumentParent); param_type->setOrdinal(i); - template_args.append(param_type); + template_args.append(TypeEntryCPtr(param_type)); } metaClass->setTemplateArguments(template_args); @@ -1305,8 +1304,8 @@ void AbstractMetaBuilderPrivate::fixReturnTypeOfConversionOperator(AbstractMetaF if (castTo.startsWith(u"const ")) castTo.remove(0, 6); - TypeEntry *retType = types->findType(castTo); - if (!retType) + TypeEntryPtr retType = types->findType(castTo); + if (retType.isNull()) return; AbstractMetaType metaType(retType); @@ -1521,7 +1520,7 @@ bool AbstractMetaBuilderPrivate::setupInheritance(AbstractMetaClass *metaClass) // we only support our own containers and ONLY if there is only one baseclass if (baseClasses.size() == 1 && baseClasses.constFirst().contains(u'<')) { TypeInfo info; - ComplexTypeEntry *baseContainerType; + ComplexTypeEntryPtr baseContainerType; auto *templ = findTemplateClass(baseClasses.constFirst(), metaClass, &info, &baseContainerType); if (templ) { @@ -1736,7 +1735,7 @@ bool AbstractMetaBuilderPrivate::traverseAddedMemberFunction(const AddedFunction if (metaFunction->name() == metaClass->name()) { metaFunction->setFunctionType(AbstractMetaFunction::ConstructorFunction); if (fargs.size() == 1) { - const TypeEntry *te = fargs.constFirst().type().typeEntry(); + const auto te = fargs.constFirst().type().typeEntry(); if (te->isCustom()) metaFunction->setExplicit(true); if (te->name() == metaFunction->name()) @@ -2182,10 +2181,10 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio return metaFunction; } -static const TypeEntry *findTypeEntryUsingContext(const AbstractMetaClass *metaClass, - const QString& qualifiedName) +static TypeEntryCPtr findTypeEntryUsingContext(const AbstractMetaClass *metaClass, + const QString& qualifiedName) { - const TypeEntry *type = nullptr; + TypeEntryCPtr type; QStringList context = metaClass->qualifiedCppName().split(colonColon()); while (!type && !context.isEmpty()) { type = TypeDatabase::instance()->findType(context.join(colonColon()) + colonColon() + qualifiedName); @@ -2232,7 +2231,7 @@ TypeEntryCList AbstractMetaBuilderPrivate::findTypeEntriesHelper(const QString & // of the parameters. if (currentClass) { const auto &template_args = currentClass->templateArguments(); - for (const TypeEntry *te : template_args) { + for (const auto &te : template_args) { if (te->name() == qualifiedName) return {te}; } @@ -2258,9 +2257,11 @@ TypeEntryCList AbstractMetaBuilderPrivate::findTypeEntries(const QString &qualif // Resolve entries added by metabuilder (for example, "GLenum") to match // the signatures for modifications. for (qsizetype i = 0, size = types.size(); i < size; ++i) { - const auto *e = types.at(i); - if (e->isPrimitive()) - types[i] = basicReferencedNonBuiltinTypeEntry(e->asPrimitive()); + const auto &e = types.at(i); + if (e->isPrimitive()) { + const auto pte = qSharedPointerCast<const PrimitiveTypeEntry>(e); + types[i] = basicReferencedNonBuiltinTypeEntry(pte); + } } if (types.size() == 1) @@ -2268,7 +2269,7 @@ TypeEntryCList AbstractMetaBuilderPrivate::findTypeEntries(const QString &qualif const auto typeEntryType = types.constFirst()->type(); const bool sameType = std::all_of(types.cbegin() + 1, types.cend(), - [typeEntryType](const TypeEntry *e) { + [typeEntryType](const TypeEntryCPtr &e) { return e->type() == typeEntryType; }); @@ -2330,8 +2331,8 @@ static AbstractMetaFunctionPtr addMethod(AbstractMetaClass *s, const QString &returnTypeName, const QString &name, bool isConst = true) { - auto *typeEntry = TypeDatabase::instance()->findPrimitiveType(returnTypeName); - Q_ASSERT(typeEntry); + auto typeEntry = TypeDatabase::instance()->findPrimitiveType(returnTypeName); + Q_ASSERT(!typeEntry.isNull()); AbstractMetaType returnType(typeEntry); returnType.decideUsagePattern(); return addMethod(s, returnType, name, isConst); @@ -2339,7 +2340,7 @@ static AbstractMetaFunctionPtr // Create the instantiation type of a smart pointer static AbstractMetaType instantiationType(const AbstractMetaClass *s, - const SmartPointerTypeEntry *ste) + const SmartPointerTypeEntryCPtr &ste) { AbstractMetaType type(s->templateArguments().constFirst()); if (ste->smartPointerType() != TypeSystem::SmartPointerType::ValueHandle) @@ -2350,7 +2351,7 @@ static AbstractMetaType instantiationType(const AbstractMetaClass *s, // Create the pointee argument of a smart pointer constructor or reset() static AbstractMetaArgument pointeeArgument(const AbstractMetaClass *s, - const SmartPointerTypeEntry *ste) + const SmartPointerTypeEntryCPtr &ste) { AbstractMetaArgument pointee; pointee.setType(instantiationType(s, ste)); @@ -2360,7 +2361,8 @@ static AbstractMetaArgument pointeeArgument(const AbstractMetaClass *s, // Add the smart pointer constructors. For MSVC, (when not specifying // <system-header>), clang only sees the default constructor. -static void fixSmartPointerConstructors(AbstractMetaClass *s, const SmartPointerTypeEntry *ste) +static void fixSmartPointerConstructors(AbstractMetaClass *s, + const SmartPointerTypeEntryCPtr &ste) { const auto ctors = s->queryFunctions(FunctionQueryOption::Constructors); bool seenDefaultConstructor = false; @@ -2389,7 +2391,8 @@ static void fixSmartPointerConstructors(AbstractMetaClass *s, const SmartPointer } // Similarly, add the smart pointer reset() functions -static void fixSmartPointerReset(AbstractMetaClass *s, const SmartPointerTypeEntry *ste) +static void fixSmartPointerReset(AbstractMetaClass *s, + const SmartPointerTypeEntryCPtr &ste) { const QString resetMethodName = ste->resetMethod(); const auto functions = s->findFunctions(resetMethodName); @@ -2417,7 +2420,8 @@ static void fixSmartPointerReset(AbstractMetaClass *s, const SmartPointerTypeEnt } // Add the relevant missing smart pointer functions. -static void fixSmartPointerClass(AbstractMetaClass *s, const SmartPointerTypeEntry *ste) +static void fixSmartPointerClass(AbstractMetaClass *s, + const SmartPointerTypeEntryCPtr &ste) { fixSmartPointerConstructors(s, ste); @@ -2445,16 +2449,16 @@ static void fixSmartPointerClass(AbstractMetaClass *s, const SmartPointerTypeEnt } // Create a missing smart pointer class -static AbstractMetaClass *createSmartPointerClass(const SmartPointerTypeEntry *ste, +static AbstractMetaClass *createSmartPointerClass(const SmartPointerTypeEntryCPtr &ste, const AbstractMetaClassList &allClasses) { auto *result = new AbstractMetaClass(); - result->setTypeEntry(const_cast<SmartPointerTypeEntry *>(ste)); - auto *templateArg = new TemplateArgumentEntry(u"T"_s, ste->version(), - typeSystemTypeEntry(ste)); + result->setTypeEntry(qSharedPointerConstCast<SmartPointerTypeEntry>(ste)); + TypeEntryCPtr templateArg(new TemplateArgumentEntry(u"T"_s, ste->version(), + typeSystemTypeEntry(ste))); result->setTemplateArguments({templateArg}); fixSmartPointerClass(result, ste); - auto *enclosingTe = ste->parent(); + auto enclosingTe = ste->parent(); if (!enclosingTe->isTypeSystem()) { auto *enclosing = AbstractMetaClass::findClass(allClasses, enclosingTe); if (enclosing == nullptr) @@ -2470,7 +2474,7 @@ static AbstractMetaClass *createSmartPointerClass(const SmartPointerTypeEntry *s void AbstractMetaBuilderPrivate::fixSmartPointers() { const auto smartPointerTypes = TypeDatabase::instance()->smartPointerTypes(); - for (auto *ste : smartPointerTypes) { + for (const auto &ste : smartPointerTypes) { const AbstractMetaClass *smartPointerClass = AbstractMetaClass::findClass(m_smartPointers, ste); if (smartPointerClass) { @@ -2597,8 +2601,9 @@ std::optional<AbstractMetaType> arrayType.setArrayElementCount(int(elems)); } auto elementTypeEntry = elementType->typeEntry(); - arrayType.setTypeEntry(new ArrayTypeEntry(elementTypeEntry, elementTypeEntry->version(), - elementTypeEntry->parent())); + TypeEntryCPtr at(new ArrayTypeEntry(elementTypeEntry, elementTypeEntry->version(), + elementTypeEntry->parent())); + arrayType.setTypeEntry(at); arrayType.decideUsagePattern(); elementType = arrayType; @@ -2633,7 +2638,7 @@ std::optional<AbstractMetaType> return {}; } - const TypeEntry *type = types.constFirst(); + TypeEntryCPtr type = types.constFirst(); const TypeEntry::Type typeEntryType = type->type(); AbstractMetaType metaType; @@ -2652,7 +2657,7 @@ std::optional<AbstractMetaType> if (!targType.has_value()) { const QString value = ti.qualifiedName().join(colonColon()); if (isNumber(value)) { - auto *module = typeSystemTypeEntry(type); + auto module = typeSystemTypeEntry(type); TypeDatabase::instance()->addConstantValueTypeEntry(value, module); targType = translateTypeStatic(ti, currentClass, d, flags, &errorMessage); } @@ -2679,8 +2684,8 @@ std::optional<AbstractMetaType> type = instantiationType; } else { auto it = std::find_if(types.cbegin(), types.cend(), - [instantiationType](const TypeEntry *e) { - auto smartPtr = static_cast<const SmartPointerTypeEntry *>(e); + [instantiationType](const TypeEntryCPtr &e) { + auto smartPtr = qSharedPointerCast<const SmartPointerTypeEntry>(e); return smartPtr->matchesInstantiation(instantiationType); }); if (it == types.cend()) { @@ -2838,7 +2843,7 @@ QString AbstractMetaBuilderPrivate::fixDefaultValue(QString expr, const Abstract // "QList<FormatRange>()" -> "QList<QTextLayout::FormatRange>()" if (type.instantiations().size() != 1) return expr; // Only simple types are handled, not QMap<int, int>. - auto *innerTypeEntry = type.instantiations().constFirst().typeEntry(); + auto innerTypeEntry = type.instantiations().constFirst().typeEntry(); if (!innerTypeEntry->isComplex()) return expr; const QString &qualifiedInnerTypeName = innerTypeEntry->qualifiedCppName(); @@ -2892,7 +2897,7 @@ QString AbstractMetaBuilderPrivate::fixDefaultValue(QString expr, const Abstract } } // Is this a class constructor "Class(Field)"? Expand it. - auto *te = type.typeEntry(); + const auto te = type.typeEntry(); if (!te->isComplex()) return expr; const QString &qualifiedTypeName = te->qualifiedCppName(); @@ -2921,10 +2926,10 @@ bool AbstractMetaBuilderPrivate::isEnum(const FileModelItem &dom, const QStringL AbstractMetaClass *AbstractMetaBuilderPrivate::findTemplateClass(const QString &name, const AbstractMetaClass *context, TypeInfo *info, - ComplexTypeEntry **baseContainerType) const + ComplexTypeEntryPtr *baseContainerType) const { if (baseContainerType) - *baseContainerType = nullptr; + baseContainerType->reset(); auto *types = TypeDatabase::instance(); QStringList scope = context->typeEntry()->qualifiedCppName().split(colonColon()); @@ -2997,7 +3002,7 @@ std::optional<AbstractMetaType> returned.setOriginalTemplateType(metaType); if (returned.typeEntry()->isTemplateArgument()) { - const auto *tae = static_cast<const TemplateArgumentEntry*>(returned.typeEntry()); + const auto tae = qSharedPointerCast<const TemplateArgumentEntry>(returned.typeEntry()); // If the template is intantiated with void we special case this as rejecting the functions that use this // parameter from the instantiation. @@ -3028,7 +3033,7 @@ std::optional<AbstractMetaType> } AbstractMetaClass * - AbstractMetaBuilder::inheritTemplateClass(ComplexTypeEntry *te, + AbstractMetaBuilder::inheritTemplateClass(const ComplexTypeEntryPtr &te, const AbstractMetaClass *templateClass, const AbstractMetaTypeList &templateTypes, InheritTemplateFlags flags) @@ -3054,7 +3059,7 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass, for (const TypeInfo &i : info.instantiations()) { QString typeName = i.qualifiedName().join(colonColon()); TypeDatabase *typeDb = TypeDatabase::instance(); - TypeEntry *t = nullptr; + TypeEntryPtr t; // Check for a non-type template integer parameter, that is, for a base // "template <int R, int C> Matrix<R, C>" and subclass // "typedef Matrix<2,3> Matrix2x3;". If so, create dummy entries of @@ -3168,7 +3173,7 @@ AbstractMetaFunctionPtr f->setOriginalName(subclass->name()); } - ComplexTypeEntry *te = subclass->typeEntry(); + ComplexTypeEntryPtr te = subclass->typeEntry(); const FunctionModificationList mods = function->modifications(templateClass); for (auto mod : mods) { @@ -3403,7 +3408,7 @@ void AbstractMetaBuilderPrivate::dumpLog() const // Add a dependency of the class associated with typeEntry on clazz. template <class MetaClass> static bool addClassDependency(const QList<MetaClass *> &classList, - const TypeEntry *typeEntry, + const TypeEntryCPtr &typeEntry, MetaClass *clazz, Graph<MetaClass *> *graph) { @@ -3568,7 +3573,7 @@ static bool matchHeader(const QString &headerPath, const QString &fileName) && fileName.startsWith(headerPath, caseSensitivity); } -void AbstractMetaBuilderPrivate::setInclude(TypeEntry *te, const QString &path) const +void AbstractMetaBuilderPrivate::setInclude(const TypeEntryPtr &te, const QString &path) const { auto it = m_resolveIncludeHash.find(path); if (it == m_resolveIncludeHash.end()) { diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h index 563db8f6e..04069cefc 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h @@ -8,6 +8,7 @@ #include "apiextractorflags.h" #include "header_paths.h" #include "typesystem_enums.h" +#include "typesystem_typedefs.h" #include "clangparser/compilersupport.h" @@ -50,7 +51,7 @@ public: AbstractMetaClassList takeSmartPointers(); const AbstractMetaFunctionCList &globalFunctions() const; const AbstractMetaEnumList &globalEnums() const; - const QHash<const TypeEntry *, AbstractMetaEnum> &typeEntryToEnumsHash() const; + const QHash<TypeEntryCPtr, AbstractMetaEnum> &typeEntryToEnumsHash() const; bool build(const QByteArrayList &arguments, ApiExtractorFlags apiExtractorFlags = {}, @@ -94,7 +95,7 @@ public: const AbstractMetaTypeList &templateTypes); static AbstractMetaClass * - inheritTemplateClass(ComplexTypeEntry *te, + inheritTemplateClass(const ComplexTypeEntryPtr &te, const AbstractMetaClass *templateClass, const AbstractMetaTypeList &templateTypes, InheritTemplateFlags flags = {}); diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp index f41104a77..960d7578c 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_helpers.cpp @@ -89,15 +89,15 @@ QString AbstractMetaBuilderPrivate::fixEnumDefault(const AbstractMetaType &type, if (isIntegerConstant(expr)) return expr; - const auto *typeEntry = type.typeEntry(); - const EnumTypeEntry *enumTypeEntry = nullptr; - const FlagsTypeEntry *flagsTypeEntry = nullptr; + const auto typeEntry = type.typeEntry(); + EnumTypeEntryCPtr enumTypeEntry; + FlagsTypeEntryCPtr flagsTypeEntry; if (typeEntry->isFlags()) { - flagsTypeEntry = static_cast<const FlagsTypeEntry *>(typeEntry); + flagsTypeEntry = qSharedPointerCast<const FlagsTypeEntry>(typeEntry); enumTypeEntry = flagsTypeEntry->originator(); } else { Q_ASSERT(typeEntry->isEnum()); - enumTypeEntry = static_cast<const EnumTypeEntry *>(typeEntry); + enumTypeEntry = qSharedPointerCast<const EnumTypeEntry>(typeEntry); } // Use the enum's qualified name (would otherwise be "QFlags<Enum>") if (!enumTypeEntry->qualifiedCppName().contains(u"::")) diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h index 3593094f8..5a6aee3a9 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h @@ -158,7 +158,7 @@ public: AbstractMetaClass *findTemplateClass(const QString& name, const AbstractMetaClass *context, TypeInfo *info = Q_NULLPTR, - ComplexTypeEntry **baseContainerType = Q_NULLPTR) const; + ComplexTypeEntryPtr *baseContainerType = nullptr) const; AbstractMetaClassCList getBaseClasses(const AbstractMetaClass *metaClass) const; static bool inheritTemplate(AbstractMetaClass *subclass, @@ -188,7 +188,7 @@ public: static bool isEnum(const FileModelItem &dom, const QStringList &qualifiedName); void sortLists(); - void setInclude(TypeEntry *te, const QString &path) const; + void setInclude(const TypeEntryPtr &te, const QString &path) const; static void fixArgumentNames(AbstractMetaFunction *func, const FunctionModificationList &mods); void fillAddedFunctions(AbstractMetaClass *metaClass); @@ -212,7 +212,7 @@ public: RejectMap m_rejectedFunctions; RejectMap m_rejectedFields; - QHash<const TypeEntry *, AbstractMetaEnum> m_enums; + QHash<TypeEntryCPtr, AbstractMetaEnum> m_enums; QList<NamespaceModelItem> m_scopes; diff --git a/sources/shiboken6/ApiExtractor/abstractmetaenum.cpp b/sources/shiboken6/ApiExtractor/abstractmetaenum.cpp index 87ec88311..e44d4ef7e 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetaenum.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetaenum.cpp @@ -103,7 +103,7 @@ public: AbstractMetaEnumValueList m_enumValues; - EnumTypeEntry *m_typeEntry = nullptr; + EnumTypeEntryPtr m_typeEntry; Documentation m_doc; EnumKind m_enumKind = CEnum; @@ -263,12 +263,12 @@ void AbstractMetaEnum::setHasQEnumsDeclaration(bool on) d->m_hasQenumsDeclaration = on; } -EnumTypeEntry *AbstractMetaEnum::typeEntry() const +EnumTypeEntryPtr AbstractMetaEnum::typeEntry() const { return d->m_typeEntry; } -void AbstractMetaEnum::setTypeEntry(EnumTypeEntry *entry) +void AbstractMetaEnum::setTypeEntry(const EnumTypeEntryPtr &entry) { if (d->m_typeEntry != entry) d->m_typeEntry = entry; diff --git a/sources/shiboken6/ApiExtractor/abstractmetaenum.h b/sources/shiboken6/ApiExtractor/abstractmetaenum.h index 4b69ba560..0e356c1aa 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetaenum.h +++ b/sources/shiboken6/ApiExtractor/abstractmetaenum.h @@ -7,6 +7,7 @@ #include "abstractmetalang_typedefs.h" #include "enclosingclassmixin.h" #include "parser/codemodel_enums.h" +#include "typesystem_typedefs.h" #include <QtCore/QSharedDataPointer> #include <QtCore/QString> @@ -96,8 +97,8 @@ public: bool hasQEnumsDeclaration() const; void setHasQEnumsDeclaration(bool on); - EnumTypeEntry *typeEntry() const; - void setTypeEntry(EnumTypeEntry *entry); + EnumTypeEntryPtr typeEntry() const; + void setTypeEntry(const EnumTypeEntryPtr &entry); bool isSigned() const; void setSigned(bool s); diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp index 0dae7a4c4..03e795ec2 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp @@ -71,7 +71,7 @@ public: mutable QString m_cachedModifiedName; QString m_unresolvedSignature; - FunctionTypeEntry *m_typeEntry = nullptr; + FunctionTypeEntryPtr m_typeEntry; AbstractMetaFunction::FunctionType m_functionType = AbstractMetaFunction::NormalFunction; AbstractMetaType m_type; QString m_modifiedTypeName; @@ -224,8 +224,7 @@ bool AbstractMetaFunction::returnsBool() const { if (d->m_type.typeUsagePattern() != AbstractMetaType::PrimitivePattern) return false; - const auto *pte = d->m_type.typeEntry()->asPrimitive(); - return basicReferencedTypeEntry(pte)->name() == u"bool"; + return basicReferencedTypeEntry(d->m_type.typeEntry())->name() == u"bool"; } bool AbstractMetaFunction::isOperatorBool() const @@ -1081,12 +1080,12 @@ void AbstractMetaFunction::setPropertySpecIndex(int i) d->m_propertySpecIndex = i; } -FunctionTypeEntry *AbstractMetaFunction::typeEntry() const +FunctionTypeEntryPtr AbstractMetaFunction::typeEntry() const { return d->m_typeEntry; } -void AbstractMetaFunction::setTypeEntry(FunctionTypeEntry *typeEntry) +void AbstractMetaFunction::setTypeEntry(const FunctionTypeEntryPtr &typeEntry) { d->m_typeEntry = typeEntry; } diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.h b/sources/shiboken6/ApiExtractor/abstractmetafunction.h index 1e7016d41..78f52a8e0 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.h +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.h @@ -380,9 +380,9 @@ public: int propertySpecIndex() const; void setPropertySpecIndex(int i); - FunctionTypeEntry *typeEntry() const; + FunctionTypeEntryPtr typeEntry() const; - void setTypeEntry(FunctionTypeEntry *typeEntry); + void setTypeEntry(const FunctionTypeEntryPtr &typeEntry); bool isCallOperator() const; diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp index 7e96573c4..c9d929a29 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp @@ -56,11 +56,6 @@ public: { } - ~AbstractMetaClassPrivate() - { - qDeleteAll(m_templateArgs); - } - void addFunction(const AbstractMetaFunctionCPtr &function); static AbstractMetaFunction * createFunction(const QString &name, AbstractMetaFunction::FunctionType t, @@ -112,7 +107,7 @@ public: QStringList m_baseClassNames; // Base class names from C++, including rejected TypeEntryCList m_templateArgs; - ComplexTypeEntry *m_typeEntry = nullptr; + ComplexTypeEntryPtr m_typeEntry; SourceLocation m_sourceLocation; UsingMembers m_usingMembers; @@ -533,7 +528,7 @@ bool AbstractMetaClass::isInlineNamespace() const { bool result = false; if (d->m_typeEntry->isNamespace()) { - auto *nte = static_cast<const NamespaceTypeEntry *>(d->m_typeEntry); + const auto nte = qSharedPointerCast<const NamespaceTypeEntry>(d->m_typeEntry); result = nte->isInlineNamespace(); } return result; @@ -621,17 +616,17 @@ void AbstractMetaClass::setBaseClassNames(const QStringList &names) d->m_baseClassNames = names; } -const ComplexTypeEntry *AbstractMetaClass::typeEntry() const +ComplexTypeEntryCPtr AbstractMetaClass::typeEntry() const { return d->m_typeEntry; } -ComplexTypeEntry *AbstractMetaClass::typeEntry() +ComplexTypeEntryPtr AbstractMetaClass::typeEntry() { return d->m_typeEntry; } -void AbstractMetaClass::setTypeEntry(ComplexTypeEntry *type) +void AbstractMetaClass::setTypeEntry(const ComplexTypeEntryPtr &type) { d->m_typeEntry = type; } @@ -838,8 +833,8 @@ AbstractMetaFunction * static AbstractMetaType boolType() { - auto *boolType = TypeDatabase::instance()->findType(u"bool"_s); - Q_ASSERT(boolType); + auto boolType = TypeDatabase::instance()->findType(u"bool"_s); + Q_ASSERT(!boolType.isNull()); AbstractMetaType result(boolType); result.decideUsagePattern(); return result; @@ -1030,7 +1025,7 @@ static bool classHasParentManagement(const AbstractMetaClass *c) return flags.testFlag(ComplexTypeEntry::ParentManagement); } -const TypeEntry *AbstractMetaClass::parentManagementEntry() const +TypeEntryCPtr AbstractMetaClass::parentManagementEntry() const { if (isObjectType()) { if (auto *c = recurseClassHierarchy(this, classHasParentManagement)) @@ -1350,10 +1345,10 @@ static void addExtraIncludeForType(AbstractMetaClass *metaClass, const AbstractM { Q_ASSERT(metaClass); - const TypeEntry *entry = type.typeEntry(); + const auto entry = type.typeEntry(); if (entry && entry->include().isValid()) { - ComplexTypeEntry *class_entry = metaClass->typeEntry(); + const auto class_entry = metaClass->typeEntry(); class_entry->addArgumentInclude(entry->include()); } @@ -1733,7 +1728,7 @@ const AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassCLi } AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &classes, - const TypeEntry *typeEntry) + const TypeEntryCPtr &typeEntry) { for (AbstractMetaClass *c : classes) { if (c->typeEntry() == typeEntry) @@ -1743,7 +1738,7 @@ AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassList &cla } const AbstractMetaClass *AbstractMetaClass::findClass(const AbstractMetaClassCList &classes, - const TypeEntry *typeEntry) + const TypeEntryCPtr &typeEntry) { for (auto c : classes) { if (c->typeEntry() == typeEntry) diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.h b/sources/shiboken6/ApiExtractor/abstractmetalang.h index 8e8c451c4..e0654b69f 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken6/ApiExtractor/abstractmetalang.h @@ -114,8 +114,8 @@ public: bool canAddDefaultCopyConstructor() const; /// Return type entry of the base class that declares the parent management - const TypeEntry *parentManagementEntry() const; - bool hasParentManagement() const { return parentManagementEntry() != nullptr; } + TypeEntryCPtr parentManagementEntry() const; + bool hasParentManagement() const { return !parentManagementEntry().isNull(); } void addSynthesizedComparisonOperators(); @@ -248,9 +248,9 @@ public: const QStringList &baseClassNames() const; void setBaseClassNames(const QStringList &names); - const ComplexTypeEntry *typeEntry() const; - ComplexTypeEntry *typeEntry(); - void setTypeEntry(ComplexTypeEntry *type); + ComplexTypeEntryCPtr typeEntry() const; + ComplexTypeEntryPtr typeEntry(); + void setTypeEntry(const ComplexTypeEntryPtr &type); /// Returns the global hash function as found by the code parser QString hashFunction() const; @@ -323,9 +323,9 @@ public: static const AbstractMetaClass *findClass(const AbstractMetaClassCList &classes, QStringView name); static AbstractMetaClass *findClass(const AbstractMetaClassList &classes, - const TypeEntry *typeEntry); + const TypeEntryCPtr &typeEntry); static const AbstractMetaClass *findClass(const AbstractMetaClassCList &classes, - const TypeEntry *typeEntry); + const TypeEntryCPtr &typeEntry); const AbstractMetaClass *findBaseClass(const QString &qualifiedName) const; static std::optional<AbstractMetaEnumValue> findEnumValue(const AbstractMetaClassList &classes, diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp index c3f6a71ec..19e030330 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp @@ -105,7 +105,7 @@ const QSet<QString> &AbstractMetaType::cppPrimitiveTypes() class AbstractMetaTypeData : public QSharedData { public: - AbstractMetaTypeData(const TypeEntry *t); + AbstractMetaTypeData(const TypeEntryCPtr &t); int actualIndirections() const; bool passByConstRef() const; @@ -120,7 +120,7 @@ public: template <class Predicate> bool generateOpaqueContainer(Predicate p) const; - const TypeEntry *m_typeEntry; + TypeEntryCPtr m_typeEntry; AbstractMetaTypeList m_instantiations; mutable QString m_cachedCppSignature; mutable QString m_cachedPythonSignature; @@ -142,7 +142,7 @@ public: AbstractMetaTypeList m_children; }; -AbstractMetaTypeData::AbstractMetaTypeData(const TypeEntry *t) : +AbstractMetaTypeData::AbstractMetaTypeData(const TypeEntryCPtr &t) : m_typeEntry(t), m_constant(false), m_volatile(false), @@ -151,7 +151,8 @@ AbstractMetaTypeData::AbstractMetaTypeData(const TypeEntry *t) : { } -AbstractMetaType::AbstractMetaType(const TypeEntry *t) : d(new AbstractMetaTypeData(t)) +AbstractMetaType::AbstractMetaType(const TypeEntryCPtr &t) : + d(new AbstractMetaTypeData(t)) { Q_ASSERT(t); } @@ -251,12 +252,12 @@ bool AbstractMetaType::applyArrayModification(QString *errorMessage) return true; } -const TypeEntry *AbstractMetaType::typeEntry() const +TypeEntryCPtr AbstractMetaType::typeEntry() const { return d->m_typeEntry; } -void AbstractMetaType::setTypeEntry(const TypeEntry *type) +void AbstractMetaType::setTypeEntry(const TypeEntryCPtr &type) { if (d->m_typeEntry != type) d->m_typeEntry = type; @@ -742,8 +743,8 @@ AbstractMetaType AbstractMetaType::createVoid() { static QScopedPointer<AbstractMetaType> metaType; if (metaType.isNull()) { - static const TypeEntry *voidTypeEntry = TypeDatabase::instance()->findType(u"void"_s); - Q_ASSERT(voidTypeEntry); + static TypeEntryCPtr voidTypeEntry = TypeDatabase::instance()->findType(u"void"_s); + Q_ASSERT(!voidTypeEntry.isNull()); metaType.reset(new AbstractMetaType(voidTypeEntry)); metaType->decideUsagePattern(); } @@ -870,7 +871,7 @@ bool AbstractMetaType::isValueTypeWithCopyConstructorOnly() const { bool result = false; if (d->m_typeEntry->isComplex()) { - const auto *cte = static_cast<const ComplexTypeEntry *>(d->m_typeEntry); + const auto cte = qSharedPointerCast<const ComplexTypeEntry>(d->m_typeEntry); result = cte->isValueTypeWithCopyConstructorOnly(); } return result; @@ -908,7 +909,7 @@ AbstractMetaType::fromString(QString typeSignature, QString *errorMessage) return it.value(); } -AbstractMetaType AbstractMetaType::fromTypeEntry(const TypeEntry *typeEntry) +AbstractMetaType AbstractMetaType::fromTypeEntry(const TypeEntryCPtr &typeEntry) { QString typeName = typeEntry->qualifiedCppName(); if (typeName.startsWith(u"::")) @@ -939,7 +940,7 @@ bool AbstractMetaTypeData::generateOpaqueContainer(Predicate pred) const return false; if (m_indirections.size() > 1) return false; - auto *containerTypeEntry = static_cast<const ContainerTypeEntry *>(m_typeEntry); + auto containerTypeEntry = qSharedPointerCast<const ContainerTypeEntry>(m_typeEntry); auto kind = containerTypeEntry->containerKind(); if (kind != ContainerTypeEntry::ListContainer) return false; @@ -949,7 +950,7 @@ bool AbstractMetaTypeData::generateOpaqueContainer(Predicate pred) const const QString signature = instantation.cppSignature(); bool result = false; - auto *instTypEntry = instantation.typeEntry(); + auto instTypEntry = instantation.typeEntry(); switch (instTypEntry->type()) { case TypeEntry::PrimitiveType: case TypeEntry::FlagsType: @@ -966,7 +967,7 @@ bool AbstractMetaTypeData::generateOpaqueContainer(Predicate pred) const } // Simple predicate for checking whether an opaque container should be generated -static bool opaqueContainerPredicate(const ContainerTypeEntry *t, +static bool opaqueContainerPredicate(const ContainerTypeEntryCPtr &t, const QString &signature) { return t->generateOpaqueContainer(signature); @@ -982,7 +983,7 @@ bool AbstractMetaType::generateOpaqueContainer() const // (cf AbstractMetaFunction::generateOpaqueContainerReturn()) bool AbstractMetaType::generateOpaqueContainerForGetter(const QString &modifiedType) const { - auto predicate = [&modifiedType](const ContainerTypeEntry *t, const QString &signature) { + auto predicate = [&modifiedType](const ContainerTypeEntryCPtr &t, const QString &signature) { return t->opaqueContainerName(signature) == modifiedType; }; return d->generateOpaqueContainer(predicate); diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.h b/sources/shiboken6/ApiExtractor/abstractmetatype.h index 1d1845a34..237c33d20 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.h +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.h @@ -7,6 +7,7 @@ #include "abstractmetalang_enums.h" #include "abstractmetalang_typedefs.h" #include "parser/codemodel_enums.h" +#include "typedatabase_typedefs.h" #include <QtCore/qobjectdefs.h> #include <QtCore/QSharedDataPointer> @@ -46,7 +47,7 @@ public: Q_ENUM(TypeUsagePattern) AbstractMetaType(); - explicit AbstractMetaType(const TypeEntry *t); + explicit AbstractMetaType(const TypeEntryCPtr &t); AbstractMetaType(const AbstractMetaType &); AbstractMetaType &operator=(const AbstractMetaType &); AbstractMetaType(AbstractMetaType &&); @@ -146,8 +147,8 @@ public: bool applyArrayModification(QString *errorMessage); - const TypeEntry *typeEntry() const; - void setTypeEntry(const TypeEntry *type); + TypeEntryCPtr typeEntry() const; + void setTypeEntry(const TypeEntryCPtr &type); void setOriginalTypeDescription(const QString &otd); QString originalTypeDescription() const; @@ -183,7 +184,7 @@ public: static std::optional<AbstractMetaType> fromString(QString typeSignature, QString *errorMessage = nullptr); /// Creates an AbstractMetaType object from a TypeEntry. - static AbstractMetaType fromTypeEntry(const TypeEntry *typeEntry); + static AbstractMetaType fromTypeEntry(const TypeEntryCPtr &typeEntry); /// Creates an AbstractMetaType object from an AbstractMetaClass. static AbstractMetaType fromAbstractMetaClass(const AbstractMetaClass *metaClass); diff --git a/sources/shiboken6/ApiExtractor/apiextractor.cpp b/sources/shiboken6/ApiExtractor/apiextractor.cpp index 62b12362e..2e22f21e3 100644 --- a/sources/shiboken6/ApiExtractor/apiextractor.cpp +++ b/sources/shiboken6/ApiExtractor/apiextractor.cpp @@ -41,7 +41,6 @@ struct InstantiationCollectContext AbstractMetaTypeList instantiatedContainers; InstantiatedSmartPointers instantiatedSmartPointers; QStringList instantiatedContainersNames; - QList<const TypeEntry *> m_synthesizedTypeEntries; }; struct ApiExtractorPrivate @@ -312,7 +311,6 @@ std::optional<ApiExtractorResult> ApiExtractor::run(ApiExtractorFlags flags) data->m_flags = flags; qSwap(data->m_instantiatedContainers, collectContext.instantiatedContainers); qSwap(data->m_instantiatedSmartPointers, collectContext.instantiatedSmartPointers); - qSwap(data->m_synthesizedTypeEntries, collectContext.m_synthesizedTypeEntries); return ApiExtractorResult(data); } @@ -358,7 +356,7 @@ AbstractMetaFunctionPtr templateClass, subclass); } -AbstractMetaClass *ApiExtractor::inheritTemplateClass(ComplexTypeEntry *te, +AbstractMetaClass *ApiExtractor::inheritTemplateClass(const ComplexTypeEntryPtr &te, const AbstractMetaClass *templateClass, const AbstractMetaTypeList &templateTypes, InheritTemplateFlags flags) @@ -410,7 +408,7 @@ AbstractMetaType canonicalSmartPtrInstantiation(const AbstractMetaType &type) return fixedType; } -static inline const TypeEntry *pointeeTypeEntry(const AbstractMetaType &smartPtrType) +static inline TypeEntryCPtr pointeeTypeEntry(const AbstractMetaType &smartPtrType) { return smartPtrType.instantiations().constFirst().typeEntry(); } @@ -486,7 +484,7 @@ static FunctionModification invalidateArgMod(const AbstractMetaFunctionCPtr &f, } static void addOwnerModification(const AbstractMetaFunctionCList &functions, - ComplexTypeEntry *typeEntry) + const ComplexTypeEntryPtr &typeEntry) { for (const auto &f : functions) { if (!f->arguments().isEmpty() @@ -507,9 +505,9 @@ void ApiExtractorPrivate::addInstantiatedSmartPointer(InstantiationCollectContex Q_ASSERT(smp.smartPointer); const auto &instantiatedType = type.instantiations().constFirst(); - auto *ste = static_cast<const SmartPointerTypeEntry *>(smp.smartPointer->typeEntry()); + const auto ste = qSharedPointerCast<const SmartPointerTypeEntry>(smp.smartPointer->typeEntry()); QString name = ste->getTargetName(smp.type); - auto *parentTypeEntry = ste->parent(); + auto parentTypeEntry = ste->parent(); InheritTemplateFlags flags; auto colonPos = name.lastIndexOf(u"::"); @@ -525,9 +523,10 @@ void ApiExtractorPrivate::addInstantiatedSmartPointer(InstantiationCollectContex flags.setFlag(InheritTemplateFlag::SetEnclosingClass); } - auto *typedefEntry = new TypedefEntry(name, ste->name(), ste->version(), parentTypeEntry); + TypedefEntryPtr typedefEntry(new TypedefEntry(name, ste->name(), ste->version(), + parentTypeEntry)); typedefEntry->setTargetLangPackage(ste->targetLangPackage()); - auto *instantiationEntry = TypeDatabase::initializeTypeDefEntry(typedefEntry, ste); + auto instantiationEntry = TypeDatabase::initializeTypeDefEntry(typedefEntry, ste); smp.specialized = ApiExtractor::inheritTemplateClass(instantiationEntry, smp.smartPointer, {instantiatedType}, flags); @@ -550,8 +549,6 @@ void ApiExtractorPrivate::addInstantiatedSmartPointer(InstantiationCollectContex } context.instantiatedSmartPointers.append(smp); - context.m_synthesizedTypeEntries.append(typedefEntry); - context.m_synthesizedTypeEntries.append(instantiationEntry); } void @@ -599,10 +596,10 @@ ApiExtractorPrivate::collectInstantiatedContainersAndSmartPointers(Instantiation // the current package or, for primitive types, if the container is in the // current package. static bool generateOpaqueContainer(const AbstractMetaType &type, - const TypeSystemTypeEntry *moduleEntry) + const TypeSystemTypeEntryCPtr &moduleEntry) { - auto *te = type.instantiations().constFirst().typeEntry(); - auto *typeModuleEntry = typeSystemTypeEntry(te); + auto te = type.instantiations().constFirst().typeEntry(); + auto typeModuleEntry = typeSystemTypeEntry(te); return typeModuleEntry == moduleEntry || (te->isPrimitive() && typeSystemTypeEntry(type.typeEntry()) == moduleEntry); } @@ -612,9 +609,9 @@ void ApiExtractorPrivate::collectInstantiatedOpqaqueContainers(InstantiationColl // Add all instantiations of opaque containers for types from the current // module. auto *td = TypeDatabase::instance(); - const auto *moduleEntry = TypeDatabase::instance()->defaultTypeSystemType(); + const auto moduleEntry = TypeDatabase::instance()->defaultTypeSystemType(); const auto &containers = td->containerTypes(); - for (const auto *container : containers) { + for (const auto &container : containers) { for (const auto &oc : container->opaqueContainers()) { QString errorMessage; const QString typeName = container->qualifiedCppName() + u'<' @@ -635,12 +632,12 @@ static void getCode(QStringList &code, const CodeSnipList &codeSnips) code.append(snip.code()); } -static void getCode(QStringList &code, const TypeEntry *type) +static void getCode(QStringList &code, const TypeEntryCPtr &type) { if (type->isComplex()) - getCode(code, static_cast<const ComplexTypeEntry *>(type)->codeSnips()); + getCode(code, qSharedPointerCast<const ComplexTypeEntry>(type)->codeSnips()); else if (type->isTypeSystem()) - getCode(code, static_cast<const TypeSystemTypeEntry *>(type)->codeSnips()); + getCode(code, qSharedPointerCast<const TypeSystemTypeEntry>(type)->codeSnips()); auto customConversion = CustomConversion::getCustomConversion(type); if (customConversion.isNull()) @@ -662,16 +659,16 @@ void ApiExtractorPrivate::collectContainerTypesFromSnippets(InstantiationCollect QStringList snips; auto *td = TypeDatabase::instance(); const PrimitiveTypeEntryCList &primitiveTypeList = td->primitiveTypes(); - for (const PrimitiveTypeEntry *type : primitiveTypeList) + for (const auto &type : primitiveTypeList) getCode(snips, type); const ContainerTypeEntryCList &containerTypeList = td->containerTypes(); - for (const ContainerTypeEntry *type : containerTypeList) + for (const auto &type : containerTypeList) getCode(snips, type); for (auto metaClass : m_builder->classes()) getCode(snips, metaClass->typeEntry()); - const TypeSystemTypeEntry *moduleEntry = td->defaultTypeSystemType(); - Q_ASSERT(moduleEntry); + const auto moduleEntry = td->defaultTypeSystemType(); + Q_ASSERT(!moduleEntry.isNull()); getCode(snips, moduleEntry); for (const auto &func : m_builder->globalFunctions()) diff --git a/sources/shiboken6/ApiExtractor/apiextractor.h b/sources/shiboken6/ApiExtractor/apiextractor.h index 5fa540693..51df5e45a 100644 --- a/sources/shiboken6/ApiExtractor/apiextractor.h +++ b/sources/shiboken6/ApiExtractor/apiextractor.h @@ -8,6 +8,7 @@ #include "apiextractorflags.h" #include "header_paths.h" #include "clangparser/compilersupport.h" +#include "typesystem_typedefs.h" #include <QtCore/QFileInfoList> #include <QtCore/QStringList> @@ -78,7 +79,7 @@ public: /// Forwards to AbstractMetaBuilder::inheritTemplateClass() static AbstractMetaClass * - inheritTemplateClass(ComplexTypeEntry *te, + inheritTemplateClass(const ComplexTypeEntryPtr &te, const AbstractMetaClass *templateClass, const AbstractMetaTypeList &templateTypes, InheritTemplateFlags flags = {}); diff --git a/sources/shiboken6/ApiExtractor/apiextractorresult.cpp b/sources/shiboken6/ApiExtractor/apiextractorresult.cpp index 8067290d1..a0917d64e 100644 --- a/sources/shiboken6/ApiExtractor/apiextractorresult.cpp +++ b/sources/shiboken6/ApiExtractor/apiextractorresult.cpp @@ -18,7 +18,6 @@ ApiExtractorResultData::~ApiExtractorResultData() qDeleteAll(m_templates); for (auto &smp : m_instantiatedSmartPointers) delete smp.specialized; - qDeleteAll(m_synthesizedTypeEntries); } ApiExtractorResult::ApiExtractorResult() : d(new ApiExtractorResultData) @@ -80,17 +79,18 @@ void ApiExtractorResult::setFlags(ApiExtractorFlags f) d->m_flags = f; } -std::optional<AbstractMetaEnum> ApiExtractorResult::findAbstractMetaEnum(const TypeEntry *typeEntry) const +std::optional<AbstractMetaEnum> + ApiExtractorResult::findAbstractMetaEnum(TypeEntryCPtr typeEntry) const { - if (typeEntry && typeEntry->isFlags()) - typeEntry = static_cast<const FlagsTypeEntry *>(typeEntry)->originator(); + if (!typeEntry.isNull() && typeEntry->isFlags()) + typeEntry = qSharedPointerCast<const FlagsTypeEntry>(typeEntry)->originator(); const auto it = d->m_enums.constFind(typeEntry); if (it == d->m_enums.constEnd()) return {}; return it.value(); } -AbstractMetaFunctionCList ApiExtractorResult::implicitConversions(const TypeEntry *type) const +AbstractMetaFunctionCList ApiExtractorResult::implicitConversions(const TypeEntryCPtr &type) const { if (type->isValue()) { if (auto metaClass = AbstractMetaClass::findClass(d->m_metaClasses, type)) diff --git a/sources/shiboken6/ApiExtractor/apiextractorresult.h b/sources/shiboken6/ApiExtractor/apiextractorresult.h index 8c32f2b57..f85fca9f0 100644 --- a/sources/shiboken6/ApiExtractor/apiextractorresult.h +++ b/sources/shiboken6/ApiExtractor/apiextractorresult.h @@ -7,6 +7,7 @@ #include "apiextractorflags.h" #include "abstractmetatype.h" #include "abstractmetalang_typedefs.h" +#include "typesystem_typedefs.h" #include <QtCore/QExplicitlySharedDataPointer> @@ -44,14 +45,15 @@ public: const InstantiatedSmartPointers &instantiatedSmartPointers() const; // Query functions for the generators - std::optional<AbstractMetaEnum> findAbstractMetaEnum(const TypeEntry *typeEntry) const; + std::optional<AbstractMetaEnum> + findAbstractMetaEnum(TypeEntryCPtr typeEntry) const; /// Retrieves a list of constructors used in implicit conversions /// available on the given type. The TypeEntry must be a value-type /// or else it will return an empty list. /// \param type a TypeEntry that is expected to be a value-type /// \return a list of constructors that could be used as implicit converters - AbstractMetaFunctionCList implicitConversions(const TypeEntry *type) const; + AbstractMetaFunctionCList implicitConversions(const TypeEntryCPtr &type) const; AbstractMetaFunctionCList implicitConversions(const AbstractMetaType &metaType) const; ApiExtractorFlags flags() const; diff --git a/sources/shiboken6/ApiExtractor/apiextractorresultdata_p.h b/sources/shiboken6/ApiExtractor/apiextractorresultdata_p.h index 2750b0c37..05d548d6d 100644 --- a/sources/shiboken6/ApiExtractor/apiextractorresultdata_p.h +++ b/sources/shiboken6/ApiExtractor/apiextractorresultdata_p.h @@ -22,8 +22,7 @@ public: AbstractMetaEnumList m_globalEnums; AbstractMetaTypeList m_instantiatedContainers; InstantiatedSmartPointers m_instantiatedSmartPointers; - QHash<const TypeEntry *, AbstractMetaEnum> m_enums; - QList<const TypeEntry *> m_synthesizedTypeEntries; // not exposed, just for ownership + QHash<TypeEntryCPtr, AbstractMetaEnum> m_enums; ApiExtractorFlags m_flags; }; diff --git a/sources/shiboken6/ApiExtractor/arraytypeentry.h b/sources/shiboken6/ApiExtractor/arraytypeentry.h index d520fa0b3..5b9bb191e 100644 --- a/sources/shiboken6/ApiExtractor/arraytypeentry.h +++ b/sources/shiboken6/ApiExtractor/arraytypeentry.h @@ -11,11 +11,11 @@ class ArrayTypeEntryPrivate; class ArrayTypeEntry : public TypeEntry { public: - explicit ArrayTypeEntry(const TypeEntry *nested_type, const QVersionNumber &vr, - const TypeEntry *parent); + explicit ArrayTypeEntry(const TypeEntryCPtr &nested_type, const QVersionNumber &vr, + const TypeEntryCPtr &parent); - void setNestedTypeEntry(TypeEntry *nested); - const TypeEntry *nestedTypeEntry() const; + void setNestedTypeEntry(const TypeEntryPtr &nested); + TypeEntryCPtr nestedTypeEntry() const; TypeEntry *clone() const override; diff --git a/sources/shiboken6/ApiExtractor/codesnip.cpp b/sources/shiboken6/ApiExtractor/codesnip.cpp index e442a18a6..81977ceb1 100644 --- a/sources/shiboken6/ApiExtractor/codesnip.cpp +++ b/sources/shiboken6/ApiExtractor/codesnip.cpp @@ -13,8 +13,8 @@ using namespace Qt::StringLiterals; QString TemplateInstance::expandCode() const { - TemplateEntry *templateEntry = TypeDatabase::instance()->findTemplate(m_name); - if (!templateEntry) { + const auto templateEntry = TypeDatabase::instance()->findTemplate(m_name); + if (templateEntry.isNull()) { const QString m = u"<insert-template> referring to non-existing template '"_s + m_name + u"'."_s; throw Exception(m); diff --git a/sources/shiboken6/ApiExtractor/complextypeentry.h b/sources/shiboken6/ApiExtractor/complextypeentry.h index 9e46634bc..bad7cdf91 100644 --- a/sources/shiboken6/ApiExtractor/complextypeentry.h +++ b/sources/shiboken6/ApiExtractor/complextypeentry.h @@ -52,7 +52,7 @@ public: }; explicit ComplexTypeEntry(const QString &entryName, Type t, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); bool isComplex() const override; @@ -135,9 +135,9 @@ public: QString hashFunction() const; void setHashFunction(const QString &hashFunction); - void setBaseContainerType(const ComplexTypeEntry *baseContainer); + void setBaseContainerType(const ComplexTypeEntryCPtr &baseContainer); - const ComplexTypeEntry *baseContainerType() const; + ComplexTypeEntryCPtr baseContainerType() const; TypeSystem::ExceptionHandling exceptionHandling() const; void setExceptionHandling(TypeSystem::ExceptionHandling e); @@ -151,7 +151,7 @@ public: TypeEntry *clone() const override; - void useAsTypedef(const ComplexTypeEntry *source); + void useAsTypedef(const ComplexTypeEntryCPtr &source); TypeSystem::SnakeCase snakeCase() const; void setSnakeCase(TypeSystem::SnakeCase sc); diff --git a/sources/shiboken6/ApiExtractor/constantvaluetypeentry.h b/sources/shiboken6/ApiExtractor/constantvaluetypeentry.h index d88c2b07f..a16a7ad12 100644 --- a/sources/shiboken6/ApiExtractor/constantvaluetypeentry.h +++ b/sources/shiboken6/ApiExtractor/constantvaluetypeentry.h @@ -12,7 +12,7 @@ class ConstantValueTypeEntry : public TypeEntry { public: explicit ConstantValueTypeEntry(const QString& name, - const TypeEntry *parent); + const TypeEntryCPtr &parent); TypeEntry *clone() const override; diff --git a/sources/shiboken6/ApiExtractor/containertypeentry.h b/sources/shiboken6/ApiExtractor/containertypeentry.h index b8b01cf68..8acf038fd 100644 --- a/sources/shiboken6/ApiExtractor/containertypeentry.h +++ b/sources/shiboken6/ApiExtractor/containertypeentry.h @@ -28,7 +28,7 @@ public: }; explicit ContainerTypeEntry(const QString &entryName, ContainerKind containerKind, - const QVersionNumber &vr, const TypeEntry *parent); + const QVersionNumber &vr, const TypeEntryCPtr &parent); ContainerKind containerKind() const; diff --git a/sources/shiboken6/ApiExtractor/customconversion.cpp b/sources/shiboken6/ApiExtractor/customconversion.cpp index e9eca5130..4632e4e76 100644 --- a/sources/shiboken6/ApiExtractor/customconversion.cpp +++ b/sources/shiboken6/ApiExtractor/customconversion.cpp @@ -11,12 +11,12 @@ using namespace Qt::StringLiterals; -CustomConversion::CustomConversion(const TypeEntry *ownerType) : +CustomConversion::CustomConversion(const TypeEntryCPtr &ownerType) : m_ownerType(ownerType) { } -const TypeEntry *CustomConversion::ownerType() const +TypeEntryCPtr CustomConversion::ownerType() const { return m_ownerType; } @@ -73,12 +73,12 @@ TargetToNativeConversion::TargetToNativeConversion(const QString &sourceTypeName { } -const TypeEntry *TargetToNativeConversion::sourceType() const +TypeEntryCPtr TargetToNativeConversion::sourceType() const { return m_sourceType; } -void TargetToNativeConversion::setSourceType(const TypeEntry *sourceType) +void TargetToNativeConversion::setSourceType(const TypeEntryCPtr &sourceType) { m_sourceType = sourceType; } @@ -99,7 +99,7 @@ QString TargetToNativeConversion::sourceTypeCheck() const return m_sourceTypeCheck; if (m_sourceType != nullptr && m_sourceType->isCustom()) { - const auto *cte = static_cast<const CustomTypeEntry *>(m_sourceType); + const auto cte = qSharedPointerCast<const CustomTypeEntry>(m_sourceType); if (cte->hasCheckFunction()) { QString result = cte->checkFunction(); if (result != u"true") // For PyObject, which is always true @@ -131,14 +131,14 @@ void TargetToNativeConversion::formatDebug(QDebug &debug) const debug << ')'; } -CustomConversionPtr CustomConversion::getCustomConversion(const TypeEntry *type) +CustomConversionPtr CustomConversion::getCustomConversion(const TypeEntryCPtr &type) { if (type->isPrimitive()) - return static_cast<const PrimitiveTypeEntry *>(type)->customConversion(); + return qSharedPointerCast<const PrimitiveTypeEntry>(type)->customConversion(); if (type->isContainer()) - return static_cast<const ContainerTypeEntry *>(type)->customConversion(); + return qSharedPointerCast<const ContainerTypeEntry>(type)->customConversion(); if (type->isValue()) - return static_cast<const ValueTypeEntry *>(type)->customConversion(); + return qSharedPointerCast<const ValueTypeEntry>(type)->customConversion(); return {}; } diff --git a/sources/shiboken6/ApiExtractor/customconversion.h b/sources/shiboken6/ApiExtractor/customconversion.h index ed085bdce..fd0a67759 100644 --- a/sources/shiboken6/ApiExtractor/customconversion.h +++ b/sources/shiboken6/ApiExtractor/customconversion.h @@ -21,8 +21,8 @@ public: const QString &sourceTypeCheck, const QString &conversion = {}); - const TypeEntry *sourceType() const; - void setSourceType(const TypeEntry *sourceType); + TypeEntryCPtr sourceType() const; + void setSourceType(const TypeEntryCPtr &sourceType); bool isCustomType() const; QString sourceTypeName() const; QString sourceTypeCheck() const; @@ -32,7 +32,7 @@ public: void formatDebug(QDebug &d) const; private: - const TypeEntry *m_sourceType = nullptr; + TypeEntryCPtr m_sourceType; QString m_sourceTypeName; QString m_sourceTypeCheck; QString m_conversion; @@ -43,9 +43,9 @@ using TargetToNativeConversions = QList<TargetToNativeConversion>; class CustomConversion { public: - explicit CustomConversion(const TypeEntry *ownerType); + explicit CustomConversion(const TypeEntryCPtr &ownerType); - const TypeEntry *ownerType() const; + TypeEntryCPtr ownerType() const; QString nativeToTargetConversion() const; void setNativeToTargetConversion(const QString &nativeToTargetConversion); @@ -63,12 +63,12 @@ public: const QString &conversion = QString()); /// Return the custom conversion of a type; helper for type system parser - static CustomConversionPtr getCustomConversion(const TypeEntry *type); + static CustomConversionPtr getCustomConversion(const TypeEntryCPtr &type); void formatDebug(QDebug &debug) const; private: - const TypeEntry *m_ownerType; + TypeEntryCPtr m_ownerType; QString m_nativeToTargetConversion; TargetToNativeConversions m_targetToNativeConversions; bool m_replaceOriginalTargetToNativeConversions = false; diff --git a/sources/shiboken6/ApiExtractor/customtypenentry.h b/sources/shiboken6/ApiExtractor/customtypenentry.h index e0dda4387..a57bb858f 100644 --- a/sources/shiboken6/ApiExtractor/customtypenentry.h +++ b/sources/shiboken6/ApiExtractor/customtypenentry.h @@ -10,7 +10,7 @@ class CustomTypeEntry : public TypeEntry { public: explicit CustomTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); TypeEntry *clone() const override; diff --git a/sources/shiboken6/ApiExtractor/docparser.cpp b/sources/shiboken6/ApiExtractor/docparser.cpp index 4b092593c..908e8576b 100644 --- a/sources/shiboken6/ApiExtractor/docparser.cpp +++ b/sources/shiboken6/ApiExtractor/docparser.cpp @@ -89,7 +89,7 @@ bool DocParser::skipForQuery(const AbstractMetaFunctionCPtr &func) DocModificationList DocParser::getDocModifications(const AbstractMetaClass *cppClass, const AbstractMetaFunctionCPtr &func) { - auto *te = cppClass->typeEntry(); + auto te = cppClass->typeEntry(); if (func.isNull()) return te->docModifications(); diff --git a/sources/shiboken6/ApiExtractor/enumtypeentry.h b/sources/shiboken6/ApiExtractor/enumtypeentry.h index 16e0362aa..14bab50cf 100644 --- a/sources/shiboken6/ApiExtractor/enumtypeentry.h +++ b/sources/shiboken6/ApiExtractor/enumtypeentry.h @@ -8,15 +8,13 @@ #include "typesystem_enums.h" class EnumTypeEntryPrivate; -class EnumValueTypeEntry; -class FlagsTypeEntry; class EnumTypeEntry : public TypeEntry { public: explicit EnumTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); TypeSystem::PythonEnumType pythonEnumType() const; void setPythonEnumType(TypeSystem::PythonEnumType t); @@ -25,11 +23,11 @@ public: QString qualifier() const; - const EnumValueTypeEntry *nullValue() const; - void setNullValue(const EnumValueTypeEntry *n); + EnumValueTypeEntryCPtr nullValue() const; + void setNullValue(const EnumValueTypeEntryCPtr &n); - void setFlags(FlagsTypeEntry *flags); - FlagsTypeEntry *flags() const; + void setFlags(const FlagsTypeEntryPtr &flags); + FlagsTypeEntryPtr flags() const; QString cppType() const; void setCppType(const QString &t); diff --git a/sources/shiboken6/ApiExtractor/enumvaluetypeentry.h b/sources/shiboken6/ApiExtractor/enumvaluetypeentry.h index 70c05fa8d..006b84e0a 100644 --- a/sources/shiboken6/ApiExtractor/enumvaluetypeentry.h +++ b/sources/shiboken6/ApiExtractor/enumvaluetypeentry.h @@ -15,12 +15,12 @@ class EnumValueTypeEntryPrivate; class EnumValueTypeEntry : public TypeEntry { public: - explicit EnumValueTypeEntry(const QString& name, const QString &value, - const EnumTypeEntry *enclosingEnum, + explicit EnumValueTypeEntry(const QString& name, const QString& value, + const EnumTypeEntryCPtr &enclosingEnum, bool isScopedEnum, const QVersionNumber &vr); QString value() const; - const EnumTypeEntry *enclosingEnum() const; + EnumTypeEntryCPtr enclosingEnum() const; TypeEntry *clone() const override; diff --git a/sources/shiboken6/ApiExtractor/flagstypeentry.h b/sources/shiboken6/ApiExtractor/flagstypeentry.h index 172407d1b..b784b64e6 100644 --- a/sources/shiboken6/ApiExtractor/flagstypeentry.h +++ b/sources/shiboken6/ApiExtractor/flagstypeentry.h @@ -13,7 +13,7 @@ class FlagsTypeEntry : public TypeEntry { public: explicit FlagsTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); QString originalName() const; void setOriginalName(const QString &s); @@ -21,8 +21,8 @@ public: QString flagsName() const; void setFlagsName(const QString &name); - EnumTypeEntry *originator() const; - void setOriginator(EnumTypeEntry *e); + EnumTypeEntryPtr originator() const; + void setOriginator(const EnumTypeEntryPtr &e); TypeEntry *clone() const override; diff --git a/sources/shiboken6/ApiExtractor/functiontypeentry.h b/sources/shiboken6/ApiExtractor/functiontypeentry.h index a2da28645..0901ff017 100644 --- a/sources/shiboken6/ApiExtractor/functiontypeentry.h +++ b/sources/shiboken6/ApiExtractor/functiontypeentry.h @@ -14,7 +14,7 @@ class FunctionTypeEntry : public TypeEntry public: explicit FunctionTypeEntry(const QString& name, const QString& signature, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); const QStringList &signatures() const; bool hasSignature(const QString& signature) const; diff --git a/sources/shiboken6/ApiExtractor/messages.cpp b/sources/shiboken6/ApiExtractor/messages.cpp index 06c10a49b..247bb7db0 100644 --- a/sources/shiboken6/ApiExtractor/messages.cpp +++ b/sources/shiboken6/ApiExtractor/messages.cpp @@ -210,7 +210,7 @@ QString msgUnnamedArgumentDefaultExpression(const AbstractMetaClass *context, return result; } -QString msgClassOfEnumNotFound(const EnumTypeEntry *entry) +QString msgClassOfEnumNotFound(const EnumTypeEntryCPtr &entry) { QString result; QTextStream str(&result); @@ -233,7 +233,7 @@ QString msgNoEnumTypeEntry(const EnumModelItem &enumItem, QString msgNoEnumTypeConflict(const EnumModelItem &enumItem, const QString &className, - const TypeEntry *t) + const TypeEntryCPtr &t) { QString result; QDebug debug(&result); // Use the debug operator for TypeEntry::Type @@ -347,7 +347,7 @@ QString msgSkippingField(const VariableModelItem &field, const QString &classNam static const char msgCompilationError[] = "This could potentially lead to compilation errors."; -QString msgTypeNotDefined(const TypeEntry *entry) +QString msgTypeNotDefined(const TypeEntryCPtr &entry) { QString result; QTextStream str(&result); @@ -356,7 +356,7 @@ QString msgTypeNotDefined(const TypeEntry *entry) return result; } -QString msgGlobalFunctionNotDefined(const FunctionTypeEntry *fte, +QString msgGlobalFunctionNotDefined(const FunctionTypeEntryCPtr &fte, const QString &signature, const QStringList &candidates) { @@ -383,7 +383,7 @@ QString msgStrippingArgument(const FunctionModelItem &f, int i, return result; } -QString msgEnumNotDefined(const EnumTypeEntry *t) +QString msgEnumNotDefined(const EnumTypeEntryCPtr &t) { QString result; QTextStream str(&result); @@ -676,13 +676,13 @@ QString msgConversionTypesDiffer(const QString &varType, const QString &conversi return result; } -QString msgCannotFindSmartPointerGetter(const SmartPointerTypeEntry *te) +QString msgCannotFindSmartPointerGetter(const SmartPointerTypeEntryCPtr &te) { return u"Getter \""_s + te->getter() + u"()\" of smart pointer \""_s + te->name() + u"\" not found."_s; } -QString msgCannotFindSmartPointerMethod(const SmartPointerTypeEntry *te, const QString &m) +QString msgCannotFindSmartPointerMethod(const SmartPointerTypeEntryCPtr &te, const QString &m) { return u"Method \""_s + m + u"()\" of smart pointer \""_s + te->name() + u"\" not found."_s; @@ -743,14 +743,14 @@ QString msgCyclicDependency(const QString &funcName, const QString &graphName, // shibokengenerator.cpp -QString msgClassNotFound(const TypeEntry *t) +QString msgClassNotFound(const TypeEntryCPtr &t) { return u"Could not find class \""_s + t->qualifiedCppName() + u"\" in the code model. Maybe it is forward declared?"_s; } -QString msgEnclosingClassNotFound(const TypeEntry *t) +QString msgEnclosingClassNotFound(const TypeEntryCPtr &t) { QString result; QTextStream str(&result); @@ -922,14 +922,14 @@ QString msgInvalidTargetLanguageApiName(const QString &name) + name + u"\"."_s; } -QString msgUnknownCheckFunction(const TypeEntry *t) +QString msgUnknownCheckFunction(const TypeEntryCPtr &t) { return u"Unknown check function for type: '"_s + t->qualifiedCppName() + u"'."_s; } QString msgArgumentClassNotFound(const AbstractMetaFunctionCPtr &func, - const TypeEntry *t) + const TypeEntryCPtr &t) { QString result; QTextStream(&result) << "Internal Error: Class \"" << t->qualifiedCppName() @@ -937,7 +937,7 @@ QString msgArgumentClassNotFound(const AbstractMetaFunctionCPtr &func, return result; } -QString msgMissingCustomConversion(const TypeEntry *t) +QString msgMissingCustomConversion(const TypeEntryCPtr &t) { QString result; QTextStream(&result) << "Entry \"" << t->qualifiedCppName() diff --git a/sources/shiboken6/ApiExtractor/messages.h b/sources/shiboken6/ApiExtractor/messages.h index 896ca1b82..17255f717 100644 --- a/sources/shiboken6/ApiExtractor/messages.h +++ b/sources/shiboken6/ApiExtractor/messages.h @@ -55,7 +55,7 @@ QString msgArgumentOutOfRange(int number, int minValue, int maxValue); QString msgArgumentRemovalFailed(const AbstractMetaFunction *func, int n, const QString &why); -QString msgClassOfEnumNotFound(const EnumTypeEntry *entry); +QString msgClassOfEnumNotFound(const EnumTypeEntryCPtr &entry); QString msgNoEnumTypeEntry(const EnumModelItem &enumItem, const QString &className); @@ -63,7 +63,7 @@ QString msgNoEnumTypeEntry(const EnumModelItem &enumItem, QString msgNoEnumTypeConflict(const EnumModelItem &enumItem, const QString &className, - const TypeEntry *t); + const TypeEntryCPtr &t); QString msgNamespaceNoTypeEntry(const NamespaceModelItem &item, const QString &fullName); @@ -91,9 +91,9 @@ QString msgSkippingFunction(const FunctionModelItem &functionItem, QString msgSkippingField(const VariableModelItem &field, const QString &className, const QString &type); -QString msgTypeNotDefined(const TypeEntry *entry); +QString msgTypeNotDefined(const TypeEntryCPtr &entry); -QString msgGlobalFunctionNotDefined(const FunctionTypeEntry *fte, +QString msgGlobalFunctionNotDefined(const FunctionTypeEntryCPtr &fte, const QString &signature, const QStringList &candidates); @@ -101,7 +101,7 @@ QString msgStrippingArgument(const FunctionModelItem &f, int i, const QString &originalSignature, const ArgumentModelItem &arg); -QString msgEnumNotDefined(const EnumTypeEntry *t); +QString msgEnumNotDefined(const EnumTypeEntryCPtr &t); QString msgUnknownBase(const AbstractMetaClass *metaClass, const QString &baseClassName); @@ -186,9 +186,9 @@ QString msgCannotUseEnumAsInt(const QString &name); QString msgConversionTypesDiffer(const QString &varType, const QString &conversionType); -QString msgCannotFindSmartPointerGetter(const SmartPointerTypeEntry *); +QString msgCannotFindSmartPointerGetter(const SmartPointerTypeEntryCPtr &); -QString msgCannotFindSmartPointerMethod(const SmartPointerTypeEntry *te, const QString &m); +QString msgCannotFindSmartPointerMethod(const SmartPointerTypeEntryCPtr &te, const QString &m); QString msgMethodNotFound(const AbstractMetaClass *klass, const QString &name); @@ -215,9 +215,9 @@ QString msgCyclicDependency(const QString &funcName, const QString &graphName, const AbstractMetaFunctionCList &cyclic, const AbstractMetaFunctionCList &involvedConversions); -QString msgClassNotFound(const TypeEntry *t); +QString msgClassNotFound(const TypeEntryCPtr &t); -QString msgEnclosingClassNotFound(const TypeEntry *t); +QString msgEnclosingClassNotFound(const TypeEntryCPtr &t); QString msgUnknownOperator(const AbstractMetaFunction *func); @@ -243,12 +243,12 @@ QString msgDuplicateBuiltInTypeEntry(const QString &name); QString msgDuplicateTypeEntry(const QString &name); QString msgInvalidTargetLanguageApiName(const QString &name); -QString msgUnknownCheckFunction(const TypeEntry *t); +QString msgUnknownCheckFunction(const TypeEntryCPtr &t); QString msgArgumentClassNotFound(const AbstractMetaFunctionCPtr &func, - const TypeEntry *t); + const TypeEntryCPtr &t); -QString msgMissingCustomConversion(const TypeEntry *t); +QString msgMissingCustomConversion(const TypeEntryCPtr &t); QString msgUnknownArrayPointerConversion(const QString &s); diff --git a/sources/shiboken6/ApiExtractor/namespacetypeentry.h b/sources/shiboken6/ApiExtractor/namespacetypeentry.h index dd0656009..6ffd38430 100644 --- a/sources/shiboken6/ApiExtractor/namespacetypeentry.h +++ b/sources/shiboken6/ApiExtractor/namespacetypeentry.h @@ -12,12 +12,12 @@ class NamespaceTypeEntry : public ComplexTypeEntry { public: explicit NamespaceTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); TypeEntry *clone() const override; - const NamespaceTypeEntry *extends() const; - void setExtends(const NamespaceTypeEntry *e); + NamespaceTypeEntryCPtr extends() const; + void setExtends(const NamespaceTypeEntryCPtr &e); const QRegularExpression &filePattern() const; // restrict files void setFilePattern(const QRegularExpression &r); @@ -33,6 +33,7 @@ public: bool isInlineNamespace() const; void setInlineNamespace(bool i); + static bool isVisibleScope(const TypeEntryCPtr &e); static bool isVisibleScope(const TypeEntry *e); #ifndef QT_NO_DEBUG_STREAM diff --git a/sources/shiboken6/ApiExtractor/objecttypeentry.h b/sources/shiboken6/ApiExtractor/objecttypeentry.h index a9df6b4fb..da91e8ff4 100644 --- a/sources/shiboken6/ApiExtractor/objecttypeentry.h +++ b/sources/shiboken6/ApiExtractor/objecttypeentry.h @@ -10,7 +10,7 @@ class ObjectTypeEntry : public ComplexTypeEntry { public: explicit ObjectTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); TypeEntry *clone() const override; diff --git a/sources/shiboken6/ApiExtractor/primitivetypeentry.h b/sources/shiboken6/ApiExtractor/primitivetypeentry.h index 1ed60a855..6faaf7a61 100644 --- a/sources/shiboken6/ApiExtractor/primitivetypeentry.h +++ b/sources/shiboken6/ApiExtractor/primitivetypeentry.h @@ -16,7 +16,7 @@ class PrimitiveTypeEntry : public TypeEntry { public: explicit PrimitiveTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); QString defaultConstructor() const; void setDefaultConstructor(const QString& defaultConstructor); @@ -28,13 +28,13 @@ public: * \return the type referenced by the typedef, or a null pointer * if the current object is not an typedef */ - PrimitiveTypeEntry *referencedTypeEntry() const; + PrimitiveTypeEntryPtr referencedTypeEntry() const; /** * Defines type referenced by this entry. * \param referencedTypeEntry type referenced by this entry */ - void setReferencedTypeEntry(PrimitiveTypeEntry *referencedTypeEntry); + void setReferencedTypeEntry(PrimitiveTypeEntryPtr referencedTypeEntry); /// Returns whether this entry references another entry. bool referencesType() const; @@ -60,12 +60,13 @@ protected: /// i.e. a type that is not an typedef'ed. /// \return the most basic non-typedef'ed primitive type represented /// by this typedef or self in case it is not a reference. -const PrimitiveTypeEntry *basicReferencedTypeEntry(const PrimitiveTypeEntry *e); +PrimitiveTypeEntryCPtr basicReferencedTypeEntry(const PrimitiveTypeEntryCPtr &e); +PrimitiveTypeEntryCPtr basicReferencedTypeEntry(const TypeEntryCPtr &e); /// Finds the basic primitive type that the typedef represents /// and was explicitly specified in the type system. /// \return the basic primitive type that was explicitly specified in /// the type system. -const PrimitiveTypeEntry *basicReferencedNonBuiltinTypeEntry(const PrimitiveTypeEntry *e); +PrimitiveTypeEntryCPtr basicReferencedNonBuiltinTypeEntry(const PrimitiveTypeEntryCPtr &e); #endif // PRIMITIVETYPEENTRY_H diff --git a/sources/shiboken6/ApiExtractor/propertyspec.cpp b/sources/shiboken6/ApiExtractor/propertyspec.cpp index 6882c8a79..cdba25148 100644 --- a/sources/shiboken6/ApiExtractor/propertyspec.cpp +++ b/sources/shiboken6/ApiExtractor/propertyspec.cpp @@ -70,7 +70,7 @@ void QPropertySpec::setType(const AbstractMetaType &t) d->m_type = t; } -const TypeEntry *QPropertySpec::typeEntry() const +TypeEntryCPtr QPropertySpec::typeEntry() const { return d->m_type.typeEntry(); } diff --git a/sources/shiboken6/ApiExtractor/propertyspec.h b/sources/shiboken6/ApiExtractor/propertyspec.h index b32d6c08a..5e44a918d 100644 --- a/sources/shiboken6/ApiExtractor/propertyspec.h +++ b/sources/shiboken6/ApiExtractor/propertyspec.h @@ -6,6 +6,8 @@ class AbstractMetaType; +#include "typesystem_typedefs.h" + #include <QtCore/QStringList> #include <QtCore/QSharedDataPointer> @@ -54,7 +56,7 @@ public: const AbstractMetaType &type() const; void setType(const AbstractMetaType &t); - const TypeEntry *typeEntry() const; + TypeEntryCPtr typeEntry() const; QString name() const; void setName(const QString &name); diff --git a/sources/shiboken6/ApiExtractor/qtdocparser.cpp b/sources/shiboken6/ApiExtractor/qtdocparser.cpp index c5e99bb39..b98226733 100644 --- a/sources/shiboken6/ApiExtractor/qtdocparser.cpp +++ b/sources/shiboken6/ApiExtractor/qtdocparser.cpp @@ -57,7 +57,7 @@ static void formatFunctionUnqualifiedArgTypeQuery(QTextStream &str, case AbstractMetaType::FlagsPattern: { // Modify qualified name "QFlags<Qt::AlignmentFlag>" with name "Alignment" // to "Qt::Alignment" as seen by qdoc. - const auto *flagsEntry = static_cast<const FlagsTypeEntry *>(metaType.typeEntry()); + const auto flagsEntry = qSharedPointerCast<const FlagsTypeEntry>(metaType.typeEntry()); QString name = flagsEntry->qualifiedCppName(); if (name.endsWith(u'>') && name.startsWith(u"QFlags<")) { const int lastColon = name.lastIndexOf(u':'); diff --git a/sources/shiboken6/ApiExtractor/smartpointertypeentry.h b/sources/shiboken6/ApiExtractor/smartpointertypeentry.h index 3a2fc1c6a..7b712fe35 100644 --- a/sources/shiboken6/ApiExtractor/smartpointertypeentry.h +++ b/sources/shiboken6/ApiExtractor/smartpointertypeentry.h @@ -11,7 +11,7 @@ class SmartPointerTypeEntryPrivate; struct SmartPointerInstantiation { QString name; // user defined name - const TypeEntry *typeEntry; + TypeEntryCPtr typeEntry; }; class SmartPointerTypeEntry : public ComplexTypeEntry @@ -24,7 +24,7 @@ public: TypeSystem::SmartPointerType type, const QString &refCountMethodName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); TypeSystem::SmartPointerType smartPointerType() const; @@ -43,7 +43,7 @@ public: const Instantiations &instantiations() const; void setInstantiations(const Instantiations &i); - bool matchesInstantiation(const TypeEntry *e) const; + bool matchesInstantiation(const TypeEntryCPtr &e) const; QString getTargetName(const AbstractMetaType &metaType) const; diff --git a/sources/shiboken6/ApiExtractor/templateargumententry.h b/sources/shiboken6/ApiExtractor/templateargumententry.h index 6f191b595..9f2338022 100644 --- a/sources/shiboken6/ApiExtractor/templateargumententry.h +++ b/sources/shiboken6/ApiExtractor/templateargumententry.h @@ -12,7 +12,7 @@ class TemplateArgumentEntry : public TypeEntry { public: explicit TemplateArgumentEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); int ordinal() const; void setOrdinal(int o); diff --git a/sources/shiboken6/ApiExtractor/tests/testcodeinjection.cpp b/sources/shiboken6/ApiExtractor/tests/testcodeinjection.cpp index c5d00345f..bb8c6882b 100644 --- a/sources/shiboken6/ApiExtractor/tests/testcodeinjection.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testcodeinjection.cpp @@ -66,7 +66,7 @@ void TestCodeInjections::testReadFile() QString code = classA->typeEntry()->codeSnips().constFirst().code(); QVERIFY(code.indexOf(expected) != -1); QVERIFY(classA->typeEntry()->isValue()); - auto *vte = static_cast<const ValueTypeEntry *>(classA->typeEntry()); + auto vte = qSharedPointerCast<const ValueTypeEntry>(classA->typeEntry()); code = vte->targetConversionRule(); QVERIFY(code.indexOf(expected) != -1); } diff --git a/sources/shiboken6/ApiExtractor/tests/testcontainer.cpp b/sources/shiboken6/ApiExtractor/tests/testcontainer.cpp index a4ac27cca..4f8dcd4b7 100644 --- a/sources/shiboken6/ApiExtractor/tests/testcontainer.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testcontainer.cpp @@ -36,7 +36,7 @@ void TestContainer::testContainerType() QVERIFY(classA); auto baseContainer = classA->typeEntry()->baseContainerType(); QVERIFY(baseContainer); - QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer)->containerKind(), + QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer.data())->containerKind(), ContainerTypeEntry::ListContainer); } diff --git a/sources/shiboken6/ApiExtractor/tests/testconversionruletag.cpp b/sources/shiboken6/ApiExtractor/tests/testconversionruletag.cpp index c17dda953..0f3edcfe5 100644 --- a/sources/shiboken6/ApiExtractor/tests/testconversionruletag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testconversionruletag.cpp @@ -39,9 +39,9 @@ void TestConversionRuleTag::testConversionRuleTagWithFile() AbstractMetaClassList classes = builder->classes(); const AbstractMetaClass *classA = AbstractMetaClass::findClass(classes, u"A"); QVERIFY(classA); - const ComplexTypeEntry *typeEntry = classA->typeEntry(); + const auto typeEntry = classA->typeEntry(); QVERIFY(typeEntry->isValue()); - auto *vte = static_cast<const ValueTypeEntry *>(typeEntry); + auto vte = qSharedPointerCast<const ValueTypeEntry>(typeEntry); QVERIFY(vte->hasTargetConversionRule()); QCOMPARE(vte->targetConversionRule(), QLatin1String(conversionData)); } @@ -87,8 +87,8 @@ void TestConversionRuleTag::testConversionRuleTagReplace() QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); QVERIFY(!builder.isNull()); auto *typeDb = TypeDatabase::instance(); - auto *typeA = typeDb->findPrimitiveType(u"A"_s); - QVERIFY(typeA); + auto typeA = typeDb->findPrimitiveType(u"A"_s); + QVERIFY(!typeA.isNull()); QVERIFY(typeA->hasCustomConversion()); auto conversion = typeA->customConversion(); @@ -114,8 +114,8 @@ void TestConversionRuleTag::testConversionRuleTagReplace() toNative = conversion->targetToNativeConversions().at(1); QCOMPARE(toNative.sourceTypeName(), u"B"); QVERIFY(!toNative.isCustomType()); - auto *typeB = typeDb->findType(u"B"_s); - QVERIFY(typeB); + auto typeB = typeDb->findType(u"B"_s); + QVERIFY(!typeB.isNull()); QCOMPARE(toNative.sourceType(), typeB); QCOMPARE(toNative.sourceTypeCheck(), u"CheckIfInputObjectIsB(%IN)"); QCOMPARE(toNative.conversion().trimmed(), u"%OUT = %IN.createA();"); @@ -158,7 +158,7 @@ if (!TargetDateTimeAPI) TargetDateTime_IMPORT;\n\ QVERIFY(classA); QVERIFY(classA->typeEntry()->isValue()); - auto *vte = static_cast<const ValueTypeEntry *>(classA->typeEntry()); + auto vte = qSharedPointerCast<const ValueTypeEntry>(classA->typeEntry()); QVERIFY(vte->hasCustomConversion()); auto conversion = vte->customConversion(); @@ -218,8 +218,8 @@ void TestConversionRuleTag::testConversionRuleTagWithInsertTemplate() QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode)); QVERIFY(!builder.isNull()); auto *typeDb = TypeDatabase::instance(); - auto *typeA = typeDb->findPrimitiveType(u"A"_s); - QVERIFY(typeA); + auto typeA = typeDb->findPrimitiveType(u"A"_s); + QVERIFY(!typeA.isNull()); QVERIFY(typeA->hasCustomConversion()); auto conversion = typeA->customConversion(); diff --git a/sources/shiboken6/ApiExtractor/tests/testenum.cpp b/sources/shiboken6/ApiExtractor/tests/testenum.cpp index e54f1ce38..e45da9e70 100644 --- a/sources/shiboken6/ApiExtractor/tests/testenum.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testenum.cpp @@ -485,9 +485,9 @@ namespace Test2 const auto namespaceEnums = testNamespace->enums(); if (namespaceEnums.size() != 2) return -4; - QList<const EnumTypeEntry *> enumTypeEntries{ - static_cast<const EnumTypeEntry *>(namespaceEnums.at(0).typeEntry()), - static_cast<const EnumTypeEntry *>(namespaceEnums.at(1).typeEntry())}; + QList<EnumTypeEntryCPtr > enumTypeEntries{ + qSharedPointerCast<const EnumTypeEntry>(namespaceEnums.at(0).typeEntry()), + qSharedPointerCast<const EnumTypeEntry>(namespaceEnums.at(1).typeEntry())}; if (enumTypeEntries.constFirst()->flags()) std::swap(enumTypeEntries[0], enumTypeEntries[1]); fixture->testEnum = AbstractMetaType(enumTypeEntries.at(0)); diff --git a/sources/shiboken6/ApiExtractor/tests/testextrainclude.cpp b/sources/shiboken6/ApiExtractor/tests/testextrainclude.cpp index e54d3b914..048626d2a 100644 --- a/sources/shiboken6/ApiExtractor/tests/testextrainclude.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testextrainclude.cpp @@ -49,8 +49,8 @@ void TestExtraInclude::testGlobalExtraIncludes() QVERIFY(AbstractMetaClass::findClass(classes, u"A")); auto *td = TypeDatabase::instance(); - const TypeSystemTypeEntry *module = td->defaultTypeSystemType(); - QVERIFY(module); + TypeSystemTypeEntryCPtr module = td->defaultTypeSystemType(); + QVERIFY(!module.isNull()); QCOMPARE(module->name(), u"Foo"); QList<Include> includes = module->extraIncludes(); diff --git a/sources/shiboken6/ApiExtractor/tests/testfunctiontag.cpp b/sources/shiboken6/ApiExtractor/tests/testfunctiontag.cpp index 0e78d61bb..4a98047f1 100644 --- a/sources/shiboken6/ApiExtractor/tests/testfunctiontag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testfunctiontag.cpp @@ -25,7 +25,7 @@ void TestFunctionTag::testFunctionTagForSpecificSignature() QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); QVERIFY(!builder.isNull()); - const TypeEntry *func = TypeDatabase::instance()->findType(u"globalFunction"_s); + TypeEntryCPtr func = TypeDatabase::instance()->findType(u"globalFunction"_s); QVERIFY(func); QCOMPARE(builder->globalFunctions().size(), 1); } @@ -43,8 +43,8 @@ void TestFunctionTag::testFunctionTagForAllSignatures() QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); QVERIFY(!builder.isNull()); - const TypeEntry *func = TypeDatabase::instance()->findType(u"globalFunction"_s); - QVERIFY(func); + TypeEntryCPtr func = TypeDatabase::instance()->findType(u"globalFunction"_s); + QVERIFY(!func.isNull()); QCOMPARE(builder->globalFunctions().size(), 2); } @@ -58,8 +58,8 @@ void TestFunctionTag::testRenameGlobalFunction() QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false)); QVERIFY(!builder.isNull()); - const TypeEntry *func = TypeDatabase::instance()->findType(u"global_function_with_ugly_name"_s); - QVERIFY(func); + TypeEntryCPtr func = TypeDatabase::instance()->findType(u"global_function_with_ugly_name"_s); + QVERIFY(!func.isNull()); QCOMPARE(builder->globalFunctions().size(), 1); const auto metaFunc = builder->globalFunctions().constFirst(); diff --git a/sources/shiboken6/ApiExtractor/tests/testinserttemplate.cpp b/sources/shiboken6/ApiExtractor/tests/testinserttemplate.cpp index 3b7fe05d4..ffab76923 100644 --- a/sources/shiboken6/ApiExtractor/tests/testinserttemplate.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testinserttemplate.cpp @@ -52,10 +52,9 @@ void TestInsertTemplate::testInsertTemplateOnModuleInjectCode() AbstractMetaClassList classes = builder->classes(); QVERIFY(classes.isEmpty()); - const TypeSystemTypeEntry *module = TypeDatabase::instance()->defaultTypeSystemType(); - QVERIFY(module); + TypeSystemTypeEntryCPtr module = TypeDatabase::instance()->defaultTypeSystemType(); + QVERIFY(!module.isNull()); QCOMPARE(module->name(), u"Foo"); - QVERIFY(module); QCOMPARE(module->codeSnips().size(), 1); QString code = module->codeSnips().constFirst().code().trimmed(); QVERIFY(code.contains(u"code template content")); diff --git a/sources/shiboken6/ApiExtractor/tests/testnestedtypes.cpp b/sources/shiboken6/ApiExtractor/tests/testnestedtypes.cpp index 1dacb41f5..f6daab0b8 100644 --- a/sources/shiboken6/ApiExtractor/tests/testnestedtypes.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testnestedtypes.cpp @@ -105,10 +105,10 @@ void TestNestedTypes::testDuplicationOfNestedTypes() QCOMPARE(cls1->name(), u"SomeClass"); QCOMPARE(cls1->qualifiedCppName(), u"Namespace::SomeClass"); - auto *t1 = TypeDatabase::instance()->findType(u"Namespace::SomeClass"_s); - QVERIFY(t1); - auto *t2 = TypeDatabase::instance()->findType(u"SomeClass"_s); - QVERIFY(!t2); + auto t1 = TypeDatabase::instance()->findType(u"Namespace::SomeClass"_s); + QVERIFY(!t1.isNull()); + auto t2 = TypeDatabase::instance()->findType(u"SomeClass"_s); + QVERIFY(t2.isNull()); } QTEST_APPLESS_MAIN(TestNestedTypes) diff --git a/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp b/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp index 60f2a38dd..ba2b25829 100644 --- a/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testprimitivetypetag.cpp @@ -30,8 +30,8 @@ void TestPrimitiveTypeTag::testPrimitiveTypeDefaultConstructor() const AbstractMetaClass *classB = AbstractMetaClass::findClass(classes, u"B"); QVERIFY(classB); - auto *typeEntry = TypeDatabase::instance()->findPrimitiveType(u"A"_s); - QVERIFY(typeEntry); + auto typeEntry = TypeDatabase::instance()->findPrimitiveType(u"A"_s); + QVERIFY(!typeEntry.isNull()); QVERIFY(typeEntry->hasDefaultConstructor()); QCOMPARE(typeEntry->defaultConstructor(), u"A()"); } diff --git a/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp b/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp index 948f9d3b7..a798c4339 100644 --- a/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testresolvetype.cpp @@ -257,11 +257,11 @@ public: QVERIFY(testClass); auto *tdb = TypeDatabase::instance(); - auto *int32TEntry = tdb->findType(u"int32_t"_s); - QVERIFY2(int32TEntry, "int32_t not found"); + auto int32TEntry = tdb->findType(u"int32_t"_s); + QVERIFY2(!int32TEntry.isNull(), "int32_t not found"); QVERIFY(int32TEntry->isPrimitive()); - auto *int32T = static_cast<const PrimitiveTypeEntry *>(int32TEntry); - auto *basicType = int32T->basicReferencedTypeEntry(); + auto int32T = qSharedPointerCast<const PrimitiveTypeEntry>(int32TEntry); + auto basicType = basicReferencedTypeEntry(int32T); QVERIFY2(basicType != int32T, "Typedef for int32_t not found. Check the system include paths."); } diff --git a/sources/shiboken6/ApiExtractor/tests/testtemplates.cpp b/sources/shiboken6/ApiExtractor/tests/testtemplates.cpp index 321f4aa51..65c95e378 100644 --- a/sources/shiboken6/ApiExtractor/tests/testtemplates.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testtemplates.cpp @@ -373,8 +373,8 @@ typedef BaseTemplateClass<TypeOne> TypeOneClass; QCOMPARE(one->templateBaseClass(), base); QCOMPARE(one->functions().size(), base->functions().size()); QVERIFY(one->isTypeDef()); - const ComplexTypeEntry *oneType = one->typeEntry(); - const ComplexTypeEntry *baseType = base->typeEntry(); + auto oneType = one->typeEntry(); + auto baseType = base->typeEntry(); QCOMPARE(oneType->baseContainerType(), baseType); QCOMPARE(one->baseClassNames(), QStringList(u"BaseTemplateClass<TypeOne>"_s)); @@ -418,8 +418,8 @@ typedef Vector<int> IntVector; auto *vector = AbstractMetaClass::findClass(classes, u"IntVector"); QVERIFY(vector); auto baseContainer = vector->typeEntry()->baseContainerType(); - QVERIFY(baseContainer); - QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer)->containerKind(), + QVERIFY(!baseContainer.isNull()); + QCOMPARE(reinterpret_cast<const ContainerTypeEntry*>(baseContainer.data())->containerKind(), ContainerTypeEntry::ListContainer); QCOMPARE(vector->functions().size(), 4); diff --git a/sources/shiboken6/ApiExtractor/tests/testtyperevision.cpp b/sources/shiboken6/ApiExtractor/tests/testtyperevision.cpp index 47c2327d8..1ebe71ef6 100644 --- a/sources/shiboken6/ApiExtractor/tests/testtyperevision.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testtyperevision.cpp @@ -44,11 +44,11 @@ void TestTypeRevision::testRevisionAttr() auto rev3 = rev2->findEnum(u"Rev_3"_s); QVERIFY(rev3.has_value()); QCOMPARE(rev3->typeEntry()->revision(), 3); - FlagsTypeEntry *rev4 = rev3->typeEntry()->flags(); + auto rev4 = rev3->typeEntry()->flags(); QCOMPARE(rev4->revision(), 4); auto rev5 = rev2->findEnum(u"Rev_5"_s); QVERIFY(rev5.has_value()); - const EnumTypeEntry *revEnumTypeEntry = rev5->typeEntry(); + EnumTypeEntryCPtr revEnumTypeEntry = rev5->typeEntry(); QCOMPARE(revEnumTypeEntry->revision(), 5); QCOMPARE(revEnumTypeEntry->flags()->revision(), 5); } diff --git a/sources/shiboken6/ApiExtractor/typedatabase.cpp b/sources/shiboken6/ApiExtractor/typedatabase.cpp index c37d4fc53..c185907b0 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken6/ApiExtractor/typedatabase.cpp @@ -102,10 +102,10 @@ static const PythonTypes &builtinPythonTypes() struct TypeDatabasePrivate { - const TypeSystemTypeEntry *defaultTypeSystemType() const; - TypeEntry *findType(const QString &name) const; + TypeSystemTypeEntryCPtr defaultTypeSystemType() const; + TypeEntryPtr findType(const QString &name) const; TypeEntryCList findCppTypes(const QString &name) const; - bool addType(TypeEntry *e, QString *errorMessage = nullptr); + bool addType(TypeEntryPtr e, QString *errorMessage = nullptr); bool parseFile(QIODevice *device, TypeDatabase *db, bool generate = true); static bool parseFile(const TypeDatabaseParserContextPtr &context, QIODevice *device, bool generate = true); @@ -116,24 +116,24 @@ struct TypeDatabasePrivate QString modifiedTypesystemFilepath(const QString& tsFile, const QString ¤tPath) const; - void addBuiltInType(TypeEntry *e); - PrimitiveTypeEntry *addBuiltInPrimitiveType(const QString &name, - const TypeSystemTypeEntry *root, + void addBuiltInType(const TypeEntryPtr &e); + PrimitiveTypeEntryPtr addBuiltInPrimitiveType(const QString &name, + const TypeSystemTypeEntryCPtr &root, const QString &rootPackage, - CustomTypeEntry *targetLang); + const CustomTypeEntryPtr &targetLang); void addBuiltInCppStringPrimitiveType(const QString &name, const QString &viewName, - const TypeSystemTypeEntry *root, + const TypeSystemTypeEntryCPtr &root, const QString &rootPackage, - CustomTypeEntry *targetLang); + const CustomTypeEntryPtr &targetLang); void addBuiltInPrimitiveTypes(); void addBuiltInContainerTypes(const TypeDatabaseParserContextPtr &context); TypeEntryMultiMapConstIteratorRange findTypeRange(const QString &name) const; template <class Predicate> TypeEntryCList findTypesHelper(const QString &name, Predicate pred) const; template <class Type, class Predicate> - QList<const Type *> findTypesByTypeHelper(Predicate pred) const; - TypeEntry *resolveTypeDefEntry(TypedefEntry *typedefEntry, QString *errorMessage); + QList<QSharedPointer<const Type> > findTypesByTypeHelper(Predicate pred) const; + TypeEntryPtr resolveTypeDefEntry(const TypedefEntryPtr &typedefEntry, QString *errorMessage); template <class String> bool isSuppressedWarningHelper(const String &s) const; bool resolveSmartPointerInstantiations(const TypeDatabaseParserContextPtr &context); @@ -146,7 +146,7 @@ struct TypeDatabasePrivate TypedefEntryMap m_typedefEntries; TemplateEntryMap m_templates; QList<QRegularExpression> m_suppressedWarnings; - QList<const TypeSystemTypeEntry *> m_typeSystemEntries; // maintain order, default is first. + QList<TypeSystemTypeEntryCPtr > m_typeSystemEntries; // maintain order, default is first. AddedFunctionList m_globalUserFunctions; FunctionModificationList m_functionMods; @@ -165,10 +165,10 @@ struct TypeDatabasePrivate TypeDatabase::TypeDatabase() : d(new TypeDatabasePrivate) { - d->addBuiltInType(new VoidTypeEntry()); - d->addBuiltInType(new VarargsTypeEntry()); + d->addBuiltInType(TypeEntryPtr(new VoidTypeEntry())); + d->addBuiltInType(TypeEntryPtr(new VarargsTypeEntry())); for (const auto &pt : builtinPythonTypes()) - d->addBuiltInType(new PythonTypeEntry(pt.name, pt.checkFunction, pt.type)); + d->addBuiltInType(TypeEntryPtr(new PythonTypeEntry(pt.name, pt.checkFunction, pt.type))); for (const auto &p : predefinedTemplates()) addTemplate(p.name, p.content); @@ -338,8 +338,8 @@ QStringList TypeDatabase::typesystemKeywords() const IncludeList TypeDatabase::extraIncludes(const QString& className) const { - ComplexTypeEntry *typeEntry = findComplexType(className); - return typeEntry ? typeEntry->extraIncludes() : IncludeList(); + auto typeEntry = findComplexType(className); + return typeEntry.isNull() ? IncludeList() : typeEntry->extraIncludes(); } const QStringList &TypeDatabase::systemIncludes() const @@ -354,11 +354,11 @@ void TypeDatabase::addSystemInclude(const QString &name) // Add a lookup for the short name excluding inline namespaces // so that "std::shared_ptr" finds "std::__1::shared_ptr" as well. -// Note: This inserts duplicate TypeEntry * into m_entries. -void TypeDatabase::addInlineNamespaceLookups(const NamespaceTypeEntry *n) +// Note: This inserts duplicate TypeEntryPtr into m_entries. +void TypeDatabase::addInlineNamespaceLookups(const NamespaceTypeEntryCPtr &n) { TypeEntryList additionalEntries; // Store before modifying the hash - for (TypeEntry *entry : std::as_const(d->m_entries)) { + for (const auto &entry : std::as_const(d->m_entries)) { if (entry->isChildOf(n)) additionalEntries.append(entry); } @@ -366,7 +366,7 @@ void TypeDatabase::addInlineNamespaceLookups(const NamespaceTypeEntry *n) d->m_entries.insert(ae->shortName(), ae); } -ContainerTypeEntry *TypeDatabase::findContainerType(const QString &name) const +ContainerTypeEntryPtr TypeDatabase::findContainerType(const QString &name) const { QString template_name = name; @@ -374,48 +374,48 @@ ContainerTypeEntry *TypeDatabase::findContainerType(const QString &name) const if (pos > 0) template_name = name.left(pos); - auto *type_entry = findType(template_name); + auto type_entry = findType(template_name); if (type_entry && type_entry->isContainer()) - return static_cast<ContainerTypeEntry*>(type_entry); - return nullptr; + return qSharedPointerCast<ContainerTypeEntry>(type_entry); + return {}; } -static bool inline useType(const TypeEntry *t) +static bool inline useType(const TypeEntryCPtr &t) { return !t->isPrimitive() - || static_cast<const PrimitiveTypeEntry *>(t)->preferredTargetLangType(); + || qSharedPointerCast<const PrimitiveTypeEntry>(t)->preferredTargetLangType(); } -FunctionTypeEntry *TypeDatabase::findFunctionType(const QString &name) const +FunctionTypeEntryPtr TypeDatabase::findFunctionType(const QString &name) const { const auto entries = d->findTypeRange(name); - for (TypeEntry *entry : entries) { + for (const TypeEntryPtr &entry : entries) { if (entry->type() == TypeEntry::FunctionType && useType(entry)) - return static_cast<FunctionTypeEntry*>(entry); + return qSharedPointerCast<FunctionTypeEntry>(entry); } - return nullptr; + return {}; } -void TypeDatabase::addTypeSystemType(const TypeSystemTypeEntry *e) +void TypeDatabase::addTypeSystemType(const TypeSystemTypeEntryCPtr &e) { d->m_typeSystemEntries.append(e); } -const TypeSystemTypeEntry *TypeDatabase::findTypeSystemType(const QString &name) const +TypeSystemTypeEntryCPtr TypeDatabase::findTypeSystemType(const QString &name) const { for (auto entry : d->m_typeSystemEntries) { if (entry->name() == name) return entry; } - return nullptr; + return {}; } -const TypeSystemTypeEntry *TypeDatabase::defaultTypeSystemType() const +TypeSystemTypeEntryCPtr TypeDatabase::defaultTypeSystemType() const { return d->defaultTypeSystemType(); } -const TypeSystemTypeEntry *TypeDatabasePrivate::defaultTypeSystemType() const +TypeSystemTypeEntryCPtr TypeDatabasePrivate::defaultTypeSystemType() const { return m_typeSystemEntries.value(0, nullptr); } @@ -426,19 +426,19 @@ QString TypeDatabase::defaultPackageName() const return d->m_typeSystemEntries.constFirst()->name(); } -TypeEntry *TypeDatabase::findType(const QString &name) const +TypeEntryPtr TypeDatabase::findType(const QString& name) const { return d->findType(name); } -TypeEntry *TypeDatabasePrivate::findType(const QString &name) const +TypeEntryPtr TypeDatabasePrivate::findType(const QString& name) const { const auto entries = findTypeRange(name); - for (TypeEntry *entry : entries) { + for (const auto &entry : entries) { if (useType(entry)) return entry; } - return nullptr; + return {}; } template <class Predicate> @@ -446,7 +446,7 @@ TypeEntryCList TypeDatabasePrivate::findTypesHelper(const QString &name, Predica { TypeEntryCList result; const auto entries = findTypeRange(name); - for (TypeEntry *entry : entries) { + for (const auto &entry : entries) { if (pred(entry)) result.append(entry); } @@ -454,12 +454,12 @@ TypeEntryCList TypeDatabasePrivate::findTypesHelper(const QString &name, Predica } template<class Type, class Predicate> -QList<const Type *> TypeDatabasePrivate::findTypesByTypeHelper(Predicate pred) const +QList<QSharedPointer<const Type> > TypeDatabasePrivate::findTypesByTypeHelper(Predicate pred) const { - QList<const Type *> result; - for (auto *entry : m_entries) { + QList<QSharedPointer<const Type> > result; + for (const auto &entry : m_entries) { if (pred(entry)) - result.append(static_cast<const Type *>(entry)); + result.append(qSharedPointerCast<const Type>(entry)); } return result; } @@ -469,7 +469,7 @@ TypeEntryCList TypeDatabase::findTypes(const QString &name) const return d->findTypesHelper(name, useType); } -static bool useCppType(const TypeEntry *t) +static bool useCppType(const TypeEntryCPtr &t) { bool result = false; switch (t->type()) { @@ -521,19 +521,19 @@ TypeEntryMultiMapConstIteratorRange TypeDatabasePrivate::findTypeRange(const QSt PrimitiveTypeEntryCList TypeDatabase::primitiveTypes() const { - auto pred = [](const TypeEntry *t) { return t->isPrimitive(); }; + auto pred = [](const TypeEntryCPtr &t) { return t->isPrimitive(); }; return d->findTypesByTypeHelper<PrimitiveTypeEntry>(pred); } ContainerTypeEntryCList TypeDatabase::containerTypes() const { - auto pred = [](const TypeEntry *t) { return t->isContainer(); }; + auto pred = [](const TypeEntryCPtr &t) { return t->isContainer(); }; return d->findTypesByTypeHelper<ContainerTypeEntry>(pred); } SmartPointerTypeEntryList TypeDatabase::smartPointerTypes() const { - auto pred = [](const TypeEntry *t) { return t->isSmartPointer(); }; + auto pred = [](const TypeEntryCPtr &t) { return t->isSmartPointer(); }; return d->findTypesByTypeHelper<SmartPointerTypeEntry>(pred); } @@ -590,22 +590,22 @@ bool TypeDatabase::isEnumRejected(const QString& className, const QString& enumN return findRejection(d->m_rejections, TypeRejection::Enum, className, enumName, reason); } -TypeEntry *TypeDatabasePrivate::resolveTypeDefEntry(TypedefEntry *typedefEntry, +TypeEntryPtr TypeDatabasePrivate::resolveTypeDefEntry(const TypedefEntryPtr &typedefEntry, QString *errorMessage) { QString sourceName = typedefEntry->sourceType(); const int lessThanPos = sourceName.indexOf(u'<'); if (lessThanPos != -1) sourceName.truncate(lessThanPos); - ComplexTypeEntry *source = nullptr; - for (TypeEntry *e : findTypeRange(sourceName)) { + ComplexTypeEntryPtr source; + for (const auto &e : findTypeRange(sourceName)) { switch (e->type()) { case TypeEntry::BasicValueType: case TypeEntry::ContainerType: case TypeEntry::ObjectType: case TypeEntry::SmartPointerType: - source = dynamic_cast<ComplexTypeEntry *>(e); - Q_ASSERT(source); + source = qSharedPointerDynamicCast<ComplexTypeEntry>(e); + Q_ASSERT(!source.isNull()); break; default: break; @@ -622,27 +622,27 @@ TypeEntry *TypeDatabasePrivate::resolveTypeDefEntry(TypedefEntry *typedefEntry, return TypeDatabase::initializeTypeDefEntry(typedefEntry, source); } -ComplexTypeEntry * - TypeDatabase::initializeTypeDefEntry(TypedefEntry *typedefEntry, - const ComplexTypeEntry *source) +ComplexTypeEntryPtr + TypeDatabase::initializeTypeDefEntry(const TypedefEntryPtr &typedefEntry, + const ComplexTypeEntryCPtr &source) { - auto *result = static_cast<ComplexTypeEntry *>(source->clone()); + ComplexTypeEntryPtr result(static_cast<ComplexTypeEntry *>(source->clone())); result->useAsTypedef(typedefEntry); typedefEntry->setSource(source); typedefEntry->setTarget(result); return result; } -bool TypeDatabase::addType(TypeEntry *e, QString *errorMessage) +bool TypeDatabase::addType(const TypeEntryPtr &e, QString *errorMessage) { return d->addType(e, errorMessage); } -bool TypeDatabasePrivate::addType(TypeEntry *e, QString *errorMessage) +bool TypeDatabasePrivate::addType(TypeEntryPtr e, QString *errorMessage) { if (e->type() == TypeEntry::TypedefType) { - e = resolveTypeDefEntry(static_cast<TypedefEntry *>(e), errorMessage); - if (Q_UNLIKELY(!e)) + e = resolveTypeDefEntry(qSharedPointerCast<TypedefEntry>(e), errorMessage); + if (Q_UNLIKELY(e.isNull())) return false; } m_entries.insert(e->qualifiedCppName(), e); @@ -650,11 +650,11 @@ bool TypeDatabasePrivate::addType(TypeEntry *e, QString *errorMessage) } // Add a dummy value entry for non-type template parameters -ConstantValueTypeEntry * +ConstantValueTypeEntryPtr TypeDatabase::addConstantValueTypeEntry(const QString &value, - const TypeEntry *parent) + const TypeEntryCPtr &parent) { - auto result = new ConstantValueTypeEntry(value, parent); + ConstantValueTypeEntryPtr result(new ConstantValueTypeEntry(value, parent)); result->setCodeGeneration(TypeEntry::GenerateNothing); addType(result); return result; @@ -684,10 +684,10 @@ bool TypeDatabase::isReturnTypeRejected(const QString& className, const QString& return findRejection(d->m_rejections, TypeRejection::ReturnType, className, typeName, reason); } -FlagsTypeEntry *TypeDatabase::findFlagsType(const QString &name) const +FlagsTypeEntryPtr TypeDatabase::findFlagsType(const QString &name) const { - TypeEntry *fte = findType(name); - if (!fte) { + TypeEntryPtr fte = findType(name); + if (fte.isNull()) { fte = d->m_flagsEntries.value(name); if (!fte) { //last hope, search for flag without scope inside of flags hash @@ -700,27 +700,27 @@ FlagsTypeEntry *TypeDatabase::findFlagsType(const QString &name) const } } } - return static_cast<FlagsTypeEntry *>(fte); + return qSharedPointerCast<FlagsTypeEntry>(fte); } -void TypeDatabase::addFlagsType(FlagsTypeEntry *fte) +void TypeDatabase::addFlagsType(FlagsTypeEntryPtr fte) { d->m_flagsEntries[fte->originalName()] = fte; } -TemplateEntry *TypeDatabase::findTemplate(const QString &name) const +TemplateEntryPtr TypeDatabase::findTemplate(const QString &name) const { return d->m_templates[name]; } -void TypeDatabase::addTemplate(TemplateEntry *t) +void TypeDatabase::addTemplate(const TemplateEntryPtr &t) { d->m_templates[t->name()] = t; } void TypeDatabase::addTemplate(const QString &name, const QString &code) { - auto *te = new TemplateEntry(name); + TemplateEntryPtr te(new TemplateEntry(name)); te->addCode(code); addTemplate(te); } @@ -750,7 +750,7 @@ void TypeDatabase::addGlobalUserFunctionModifications(const FunctionModification d->m_functionMods << functionModifications; } -QString TypeDatabase::globalNamespaceClassName(const TypeEntry * /*entry*/) +QString TypeDatabase::globalNamespaceClassName(const TypeEntryCPtr & /*entry*/) { return u"Global"_s; } @@ -1062,12 +1062,12 @@ bool TypeDatabasePrivate::resolveSmartPointerInstantiations(const TypeDatabasePa return true; } -PrimitiveTypeEntry *TypeDatabase::findPrimitiveType(const QString& name) const +PrimitiveTypeEntryPtr TypeDatabase::findPrimitiveType(const QString& name) const { const auto entries = d->findTypeRange(name); - for (TypeEntry *entry : entries) { + for (const auto &entry : entries) { if (entry->isPrimitive()) { - auto *pe = static_cast<PrimitiveTypeEntry *>(entry); + auto pe = qSharedPointerCast<PrimitiveTypeEntry>(entry); if (pe->preferredTargetLangType()) return pe; } @@ -1076,22 +1076,22 @@ PrimitiveTypeEntry *TypeDatabase::findPrimitiveType(const QString& name) const return nullptr; } -ComplexTypeEntry *TypeDatabase::findComplexType(const QString& name) const +ComplexTypeEntryPtr TypeDatabase::findComplexType(const QString& name) const { const auto entries = d->findTypeRange(name); - for (TypeEntry *entry : entries) { + for (const auto &entry : entries) { if (entry->isComplex() && useType(entry)) - return static_cast<ComplexTypeEntry*>(entry); + return qSharedPointerCast<ComplexTypeEntry>(entry); } return nullptr; } -ObjectTypeEntry *TypeDatabase::findObjectType(const QString& name) const +ObjectTypeEntryPtr TypeDatabase::findObjectType(const QString& name) const { const auto entries = d->findTypeRange(name); - for (TypeEntry *entry : entries) { - if (entry && entry->isObject() && useType(entry)) - return static_cast<ObjectTypeEntry*>(entry); + for (const auto &entry : entries) { + if (!entry.isNull() && entry->isObject() && useType(entry)) + return qSharedPointerCast<ObjectTypeEntry>(entry); } return nullptr; } @@ -1100,25 +1100,25 @@ NamespaceTypeEntryList TypeDatabase::findNamespaceTypes(const QString& name) con { NamespaceTypeEntryList result; const auto entries = d->findTypeRange(name); - for (TypeEntry *entry : entries) { + for (const auto &entry : entries) { if (entry->isNamespace()) - result.append(static_cast<NamespaceTypeEntry*>(entry)); + result.append(qSharedPointerCast<NamespaceTypeEntry>(entry)); } return result; } -NamespaceTypeEntry *TypeDatabase::findNamespaceType(const QString& name, +NamespaceTypeEntryPtr TypeDatabase::findNamespaceType(const QString& name, const QString &fileName) const { const auto entries = findNamespaceTypes(name); // Preferably check on matching file name first, if a pattern was given. if (!fileName.isEmpty()) { - for (NamespaceTypeEntry *entry : entries) { + for (const auto &entry : entries) { if (entry->hasPattern() && entry->matchesFile(fileName)) return entry; } } - for (NamespaceTypeEntry *entry : entries) { + for (const auto &entry : entries) { if (!entry->hasPattern()) return entry; } @@ -1139,7 +1139,7 @@ void TypeDatabase::setDropTypeEntries(QStringList dropTypeEntries) static bool computeTypeIndexes = true; static int maxTypeIndex; -static bool typeEntryLessThan(const TypeEntry *t1, const TypeEntry *t2) +static bool typeEntryLessThan(const TypeEntryCPtr &t1, const TypeEntryCPtr &t2) { if (t1->revision() < t2->revision()) return true; @@ -1157,7 +1157,7 @@ static void _computeTypeIndexes() const auto &allEntries = tdb->entries(); list.reserve(allEntries.size()); for (auto tit = allEntries.cbegin(), end = allEntries.cend(); tit != end; ++tit) { - TypeEntry *entry = tit.value(); + TypeEntryPtr entry = tit.value(); if (entry->isPrimitive() || entry->isContainer() || entry->isFunction() @@ -1176,7 +1176,7 @@ static void _computeTypeIndexes() std::sort(list.begin(), list.end(), typeEntryLessThan); maxTypeIndex = 0; - for (TypeEntry *e : std::as_const(list)) + for (const TypeEntryPtr &e : std::as_const(list)) e->setSbkIndex(maxTypeIndex++); computeTypeIndexes = false; } @@ -1311,9 +1311,9 @@ void TypeDatabasePrivate::formatDebug(QDebug &d) const struct formatPrimitiveEntry { - explicit formatPrimitiveEntry(const PrimitiveTypeEntry *e) : m_pe(e) {} + explicit formatPrimitiveEntry(const PrimitiveTypeEntryCPtr &e) : m_pe(e) {} - const PrimitiveTypeEntry *m_pe; + PrimitiveTypeEntryCPtr m_pe; }; QDebug operator<<(QDebug debug, const formatPrimitiveEntry &fe) @@ -1340,7 +1340,7 @@ QDebug operator<<(QDebug debug, const formatPrimitiveEntry &fe) // Sort primitive types for displaying; base type and typedef'ed types struct PrimitiveFormatListEntry { - const PrimitiveTypeEntry *baseType; + PrimitiveTypeEntryCPtr baseType; PrimitiveTypeEntryCList typedefs; }; @@ -1351,7 +1351,7 @@ static bool operator<(const PrimitiveFormatListEntry &e1, const PrimitiveFormatL using PrimitiveFormatListEntries = QList<PrimitiveFormatListEntry>; -static qsizetype indexOf(const PrimitiveFormatListEntries &e, const PrimitiveTypeEntry *needle) +static qsizetype indexOf(const PrimitiveFormatListEntries &e, const PrimitiveTypeEntryCPtr &needle) { for (qsizetype i = 0, size = e.size(); i < size; ++i) { if (e.at(i).baseType == needle) @@ -1368,10 +1368,10 @@ void TypeDatabase::formatBuiltinTypes(QDebug debug) const // Determine base types and their typedef'ed types QList<PrimitiveFormatListEntry> primitiveEntries; - for (auto *e : std::as_const(d->m_entries)) { + for (auto &e : std::as_const(d->m_entries)) { if (e->isPrimitive()) { - auto *pe = static_cast<const PrimitiveTypeEntry *>(e); - auto *basic = basicReferencedTypeEntry(pe); + auto pe = qSharedPointerCast<const PrimitiveTypeEntry>(e); + auto basic = basicReferencedTypeEntry(pe); if (basic != pe) { const auto idx = indexOf(primitiveEntries, basic); if (idx != -1) @@ -1388,24 +1388,24 @@ void TypeDatabase::formatBuiltinTypes(QDebug debug) const for (const auto &e : std::as_const(primitiveEntries)) { debug << "Primitive: " << formatPrimitiveEntry(e.baseType) << '\n'; - for (auto *pe : e.typedefs) + for (const auto &pe : e.typedefs) debug << " " << formatPrimitiveEntry(pe) << '\n'; } } -void TypeDatabasePrivate::addBuiltInType(TypeEntry *e) +void TypeDatabasePrivate::addBuiltInType(const TypeEntryPtr &e) { e->setBuiltIn(true); addType(e); } -PrimitiveTypeEntry * +PrimitiveTypeEntryPtr TypeDatabasePrivate::addBuiltInPrimitiveType(const QString &name, - const TypeSystemTypeEntry *root, + const TypeSystemTypeEntryCPtr &root, const QString &rootPackage, - CustomTypeEntry *targetLang) + const CustomTypeEntryPtr &targetLang) { - auto *result = new PrimitiveTypeEntry(name, {}, root); + PrimitiveTypeEntryPtr result(new PrimitiveTypeEntry(name, {}, root)); result->setTargetLangApiType(targetLang); result->setTargetLangPackage(rootPackage); addBuiltInType(result); @@ -1414,37 +1414,37 @@ PrimitiveTypeEntry * void TypeDatabasePrivate::addBuiltInCppStringPrimitiveType(const QString &name, const QString &viewName, - const TypeSystemTypeEntry *root, + const TypeSystemTypeEntryCPtr &root, const QString &rootPackage, - CustomTypeEntry *targetLang) + const CustomTypeEntryPtr &targetLang) { - auto *stringType = addBuiltInPrimitiveType(name, root, rootPackage, - targetLang); - auto *viewType = addBuiltInPrimitiveType(viewName, root, rootPackage, - nullptr); + auto stringType = addBuiltInPrimitiveType(name, root, rootPackage, + targetLang); + auto viewType = addBuiltInPrimitiveType(viewName, root, rootPackage, + nullptr); viewType->setViewOn(stringType); } void TypeDatabasePrivate::addBuiltInPrimitiveTypes() { - auto *root = defaultTypeSystemType(); + auto root = defaultTypeSystemType(); const QString &rootPackage = root->name(); // C++ primitive types - auto *pyLongEntry = findType(u"PyLong"_s); - Q_ASSERT(pyLongEntry && pyLongEntry->isCustom()); - auto *pyLongCustomEntry = static_cast<CustomTypeEntry *>(pyLongEntry); - auto *pyBoolEntry = findType(u"PyBool"_s); - Q_ASSERT(pyBoolEntry && pyBoolEntry->isCustom()); - auto *sbkCharEntry = findType(u"SbkChar"_s); - Q_ASSERT(sbkCharEntry && sbkCharEntry->isCustom()); - auto *sbkCharCustomEntry = static_cast<CustomTypeEntry *>(sbkCharEntry); - - auto *pyBoolCustomEntry = static_cast<CustomTypeEntry *>(pyBoolEntry); + auto pyLongEntry = findType(u"PyLong"_s); + Q_ASSERT(!pyLongEntry.isNull() && pyLongEntry->isCustom()); + auto pyLongCustomEntry = qSharedPointerCast<CustomTypeEntry>(pyLongEntry); + auto pyBoolEntry = findType(u"PyBool"_s); + Q_ASSERT(!pyBoolEntry.isNull() && pyBoolEntry->isCustom()); + auto sbkCharEntry = findType(u"SbkChar"_s); + Q_ASSERT(!sbkCharEntry.isNull() && sbkCharEntry->isCustom()); + auto sbkCharCustomEntry = qSharedPointerCast<CustomTypeEntry>(sbkCharEntry); + + auto pyBoolCustomEntry = qSharedPointerCast<CustomTypeEntry>(pyBoolEntry); for (const auto &t : AbstractMetaType::cppIntegralTypes()) { if (!m_entries.contains(t)) { - CustomTypeEntry *targetLangApi = pyLongCustomEntry; + CustomTypeEntryPtr targetLangApi = pyLongCustomEntry; if (t == u"bool") targetLangApi = pyBoolCustomEntry; else if (AbstractMetaType::cppCharTypes().contains(t)) @@ -1453,17 +1453,17 @@ void TypeDatabasePrivate::addBuiltInPrimitiveTypes() } } - auto *pyFloatEntry = findType(u"PyFloat"_s); - Q_ASSERT(pyFloatEntry && pyFloatEntry->isCustom()); - auto *pyFloatCustomEntry = static_cast<CustomTypeEntry *>(pyFloatEntry); + auto pyFloatEntry = findType(u"PyFloat"_s); + Q_ASSERT(!pyFloatEntry.isNull() && pyFloatEntry->isCustom()); + auto pyFloatCustomEntry = qSharedPointerCast<CustomTypeEntry>(pyFloatEntry); for (const auto &t : AbstractMetaType::cppFloatTypes()) { if (!m_entries.contains(t)) addBuiltInPrimitiveType(t, root, rootPackage, pyFloatCustomEntry); } - auto *pyUnicodeEntry = findType(u"PyUnicode"_s); - Q_ASSERT(pyUnicodeEntry && pyUnicodeEntry->isCustom()); - auto *pyUnicodeCustomEntry = static_cast<CustomTypeEntry *>(pyUnicodeEntry); + auto pyUnicodeEntry = findType(u"PyUnicode"_s); + Q_ASSERT(!pyUnicodeEntry.isNull() && pyUnicodeEntry->isCustom()); + auto pyUnicodeCustomEntry = qSharedPointerCast<CustomTypeEntry>(pyUnicodeEntry); const QString stdString = u"std::string"_s; if (!m_entries.contains(stdString)) { diff --git a/sources/shiboken6/ApiExtractor/typedatabase.h b/sources/shiboken6/ApiExtractor/typedatabase.h index 2c2914e43..11ed26002 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.h +++ b/sources/shiboken6/ApiExtractor/typedatabase.h @@ -86,20 +86,20 @@ public: const QStringList &systemIncludes() const; void addSystemInclude(const QString &name); - void addInlineNamespaceLookups(const NamespaceTypeEntry *n); + void addInlineNamespaceLookups(const NamespaceTypeEntryCPtr &n); - PrimitiveTypeEntry *findPrimitiveType(const QString &name) const; - ComplexTypeEntry *findComplexType(const QString &name) const; - ObjectTypeEntry *findObjectType(const QString &name) const; + PrimitiveTypeEntryPtr findPrimitiveType(const QString &name) const; + ComplexTypeEntryPtr findComplexType(const QString &name) const; + ObjectTypeEntryPtr findObjectType(const QString &name) const; NamespaceTypeEntryList findNamespaceTypes(const QString &name) const; - NamespaceTypeEntry *findNamespaceType(const QString &name, const QString &fileName = QString()) const; - ContainerTypeEntry *findContainerType(const QString &name) const; - FunctionTypeEntry *findFunctionType(const QString &name) const; - const TypeSystemTypeEntry *findTypeSystemType(const QString &name) const; - const TypeSystemTypeEntry *defaultTypeSystemType() const; + NamespaceTypeEntryPtr findNamespaceType(const QString &name, const QString &fileName = QString()) const; + ContainerTypeEntryPtr findContainerType(const QString &name) const; + FunctionTypeEntryPtr findFunctionType(const QString &name) const; + TypeSystemTypeEntryCPtr findTypeSystemType(const QString &name) const; + TypeSystemTypeEntryCPtr defaultTypeSystemType() const; QString defaultPackageName() const; - TypeEntry *findType(const QString &name) const; + TypeEntryPtr findType(const QString &name) const; TypeEntryCList findTypes(const QString &name) const; TypeEntryCList findCppTypes(const QString &name) const; @@ -125,21 +125,21 @@ public: bool isReturnTypeRejected(const QString &className, const QString &typeName, QString *reason = nullptr) const; - bool addType(TypeEntry *e, QString *errorMessage = nullptr); - ConstantValueTypeEntry *addConstantValueTypeEntry(const QString &value, - const TypeEntry *parent); - void addTypeSystemType(const TypeSystemTypeEntry *e); + bool addType(const TypeEntryPtr &e, QString *errorMessage = nullptr); + ConstantValueTypeEntryPtr addConstantValueTypeEntry(const QString &value, + const TypeEntryCPtr &parent); + void addTypeSystemType(const TypeSystemTypeEntryCPtr &e); - static ComplexTypeEntry * - initializeTypeDefEntry(TypedefEntry *typedefEntry, - const ComplexTypeEntry *source); + static ComplexTypeEntryPtr + initializeTypeDefEntry(const TypedefEntryPtr &typedefEntry, + const ComplexTypeEntryCPtr &source); - FlagsTypeEntry *findFlagsType(const QString &name) const; - void addFlagsType(FlagsTypeEntry *fte); + FlagsTypeEntryPtr findFlagsType(const QString &name) const; + void addFlagsType(FlagsTypeEntryPtr fte); - TemplateEntry *findTemplate(const QString &name) const; + TemplateEntryPtr findTemplate(const QString &name) const; - void addTemplate(TemplateEntry *t); + void addTemplate(const TemplateEntryPtr &t); void addTemplate(const QString &name, const QString &code); AddedFunctionList globalUserFunctions() const; @@ -159,7 +159,7 @@ public: bool isSuppressedWarning(QStringView s) const; - static QString globalNamespaceClassName(const TypeEntry *te); + static QString globalNamespaceClassName(const TypeEntryCPtr &te); // Top level file parsing bool parseFile(const QString &filename, bool generate = true); @@ -194,6 +194,7 @@ private: }; #ifndef QT_NO_DEBUG_STREAM +QDebug operator<<(QDebug d, const TypeEntryCPtr &te); QDebug operator<<(QDebug d, const TypeEntry *te); QDebug operator<<(QDebug d, const TypeDatabase &db); #endif diff --git a/sources/shiboken6/ApiExtractor/typedatabase_p.h b/sources/shiboken6/ApiExtractor/typedatabase_p.h index 4d16040cf..04c1df145 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase_p.h +++ b/sources/shiboken6/ApiExtractor/typedatabase_p.h @@ -4,15 +4,16 @@ #ifndef TYPEDATABASE_P_H #define TYPEDATABASE_P_H +#include "typesystem_typedefs.h" + #include <QtCore/QHash> #include <QtCore/QString> class TypeDatabase; -class SmartPointerTypeEntry; struct TypeDatabaseParserContext { - using SmartPointerInstantiations = QHash<SmartPointerTypeEntry *, QString>; + using SmartPointerInstantiations = QHash<SmartPointerTypeEntryPtr, QString>; TypeDatabase *db; SmartPointerInstantiations smartPointerInstantiations; diff --git a/sources/shiboken6/ApiExtractor/typedatabase_typedefs.h b/sources/shiboken6/ApiExtractor/typedatabase_typedefs.h index 6821076cc..f00c61570 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase_typedefs.h +++ b/sources/shiboken6/ApiExtractor/typedatabase_typedefs.h @@ -10,7 +10,7 @@ #include <QtCore/QString> #include <QtCore/QList> -using TemplateEntryMap =QMap<QString, TemplateEntry *>; +using TemplateEntryMap =QMap<QString, TemplateEntryPtr>; template <class Key, class Value> struct QMultiMapConstIteratorRange // A range of iterator for a range-based for loop @@ -24,10 +24,10 @@ struct QMultiMapConstIteratorRange // A range of iterator for a range-based for ConstIterator m_end; }; -using TypeEntryMultiMap = QMultiMap<QString, TypeEntry *>; -using TypeEntryMultiMapConstIteratorRange = QMultiMapConstIteratorRange<QString, TypeEntry *>; +using TypeEntryMultiMap = QMultiMap<QString, TypeEntryPtr>; +using TypeEntryMultiMapConstIteratorRange = QMultiMapConstIteratorRange<QString, TypeEntryPtr>; -using TypeEntryMap = QMap<QString, TypeEntry *>; -using TypedefEntryMap = QMap<QString, TypedefEntry *>; +using TypeEntryMap = QMap<QString, TypeEntryPtr>; +using TypedefEntryMap = QMap<QString, TypedefEntryPtr>; #endif // TYPEDATABASE_TYPEDEFS_H diff --git a/sources/shiboken6/ApiExtractor/typedefentry.h b/sources/shiboken6/ApiExtractor/typedefentry.h index e0eaf5efc..44646972c 100644 --- a/sources/shiboken6/ApiExtractor/typedefentry.h +++ b/sources/shiboken6/ApiExtractor/typedefentry.h @@ -14,18 +14,18 @@ public: explicit TypedefEntry(const QString &entryName, const QString &sourceType, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); QString sourceType() const; void setSourceType(const QString &s); TypeEntry *clone() const override; - const ComplexTypeEntry *source() const; - void setSource(const ComplexTypeEntry *source); + ComplexTypeEntryCPtr source() const; + void setSource(const ComplexTypeEntryCPtr &source); - ComplexTypeEntry *target() const; - void setTarget(ComplexTypeEntry *target); + ComplexTypeEntryPtr target() const; + void setTarget(ComplexTypeEntryPtr target); #ifndef QT_NO_DEBUG_STREAM void formatDebug(QDebug &d) const override; diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index 95c817897..a5f8ad36c 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -38,7 +38,7 @@ using namespace Qt::StringLiterals; -static QString buildName(const QString &entryName, const TypeEntry *parent) +static QString buildName(const QString &entryName, const TypeEntryCPtr &parent) { return parent == nullptr || parent->type() == TypeEntry::TypeSystemType ? entryName : parent->name() + u"::"_s + entryName; @@ -51,12 +51,12 @@ class TypeEntryPrivate { public: explicit TypeEntryPrivate(const QString &entryName, TypeEntry::Type t, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); virtual ~TypeEntryPrivate() = default; QString shortName() const; - const TypeEntry *m_parent; + TypeEntryCPtr m_parent; QString m_name; // C++ fully qualified mutable QString m_cachedShortName; // C++ excluding inline namespaces QString m_entryName; @@ -68,8 +68,8 @@ public: QVersionNumber m_version; SourceLocation m_sourceLocation; // XML file TypeEntry::CodeGeneration m_codeGeneration = TypeEntry::GenerateCode; - TypeEntry *m_viewOn = nullptr; - CustomTypeEntry *m_targetLangApiType = nullptr; + TypeEntryPtr m_viewOn; + CustomTypeEntryPtr m_targetLangApiType; int m_revision = 0; int m_sbkIndex = 0; TypeEntry::Type m_type; @@ -79,7 +79,7 @@ public: }; TypeEntryPrivate::TypeEntryPrivate(const QString &entryName, TypeEntry::Type t, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : m_parent(parent), m_name(buildName(entryName, parent)), m_entryName(entryName), @@ -89,7 +89,7 @@ TypeEntryPrivate::TypeEntryPrivate(const QString &entryName, TypeEntry::Type t, } TypeEntry::TypeEntry(const QString &entryName, TypeEntry::Type t, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new TypeEntryPrivate(entryName, t, vr, parent)) { } @@ -140,7 +140,7 @@ QVersionNumber TypeEntry::version() const return m_d->m_version; } -bool isCppPrimitive(const TypeEntry *e) +bool isCppPrimitive(const TypeEntryCPtr &e) { if (!e->isPrimitive()) return false; @@ -148,8 +148,7 @@ bool isCppPrimitive(const TypeEntry *e) if (e->type() == TypeEntry::VoidType) return true; - const PrimitiveTypeEntry *referencedType = - basicReferencedTypeEntry(e->asPrimitive()); + PrimitiveTypeEntryCPtr referencedType = basicReferencedTypeEntry(e); const QString &typeName = referencedType->name(); return AbstractMetaType::cppPrimitiveTypes().contains(typeName); } @@ -159,17 +158,17 @@ TypeEntry::Type TypeEntry::type() const return m_d->m_type; } -const TypeEntry *TypeEntry::parent() const +TypeEntryCPtr TypeEntry::parent() const { return m_d->m_parent; } -void TypeEntry::setParent(const TypeEntry *p) +void TypeEntry::setParent(const TypeEntryCPtr &p) { m_d->m_parent = p; } -bool TypeEntry::isChildOf(const TypeEntry *p) const +bool TypeEntry::isChildOf(const TypeEntryCPtr &p) const { for (auto e = m_d->m_parent; e; e = e->parent()) { if (e == p) @@ -178,16 +177,16 @@ bool TypeEntry::isChildOf(const TypeEntry *p) const return false; } -const TypeSystemTypeEntry *typeSystemTypeEntry(const TypeEntry *e) +TypeSystemTypeEntryCPtr typeSystemTypeEntry(TypeEntryCPtr e) { for (; e; e = e->parent()) { if (e->type() == TypeEntry::TypeSystemType) - return static_cast<const TypeSystemTypeEntry *>(e); + return qSharedPointerCast<const TypeSystemTypeEntry>(e); } - return nullptr; + return {}; } -const TypeEntry *targetLangEnclosingEntry(const TypeEntry *e) +TypeEntryCPtr targetLangEnclosingEntry(const TypeEntryCPtr &e) { auto result = e->parent(); while (result && result->type() != TypeEntry::TypeSystemType @@ -320,11 +319,11 @@ QString TypeEntry::name() const QString TypeEntryPrivate::shortName() const { if (m_cachedShortName.isEmpty()) { - QVarLengthArray<const TypeEntry *> parents; + QVarLengthArray<TypeEntryCPtr > parents; bool foundInlineNamespace = false; for (auto p = m_parent; p != nullptr && p->type() != TypeEntry::TypeSystemType; p = p->parent()) { if (p->type() == TypeEntry::NamespaceType - && static_cast<const NamespaceTypeEntry *>(p)->isInlineNamespace()) { + && qSharedPointerCast<const NamespaceTypeEntry>(p)->isInlineNamespace()) { foundInlineNamespace = true; } else { parents.append(p); @@ -389,7 +388,7 @@ QString TypeEntry::qualifiedCppName() const return m_d->m_name; } -const CustomTypeEntry *TypeEntry::targetLangApiType() const +CustomTypeEntryCPtr TypeEntry::targetLangApiType() const { return m_d->m_targetLangApiType; } @@ -399,7 +398,7 @@ bool TypeEntry::hasTargetLangApiType() const return m_d->m_targetLangApiType != nullptr; } -void TypeEntry::setTargetLangApiType(CustomTypeEntry *cte) +void TypeEntry::setTargetLangApiType(const CustomTypeEntryPtr &cte) { m_d->m_targetLangApiType = cte; } @@ -459,17 +458,11 @@ void TypeEntry::setSourceLocation(const SourceLocation &sourceLocation) m_d->m_sourceLocation = sourceLocation; } -const PrimitiveTypeEntry *TypeEntry::asPrimitive() const -{ - Q_ASSERT(m_d->m_type == PrimitiveType); - return static_cast<const PrimitiveTypeEntry *>(this); -} - -bool isUserPrimitive(const TypeEntry *e) +bool isUserPrimitive(const TypeEntryCPtr &e) { if (!e->isPrimitive()) return false; - const auto *type = basicReferencedTypeEntry(e->asPrimitive()); + const auto type = basicReferencedTypeEntry(e); return !isCppPrimitive(type) && type->qualifiedCppName() != u"std::string"; } @@ -479,21 +472,21 @@ bool TypeEntry::isWrapperType() const return isObject() || isValue() || isSmartPointer(); } -bool isCppIntegralPrimitive(const TypeEntry *e) +bool isCppIntegralPrimitive(const TypeEntryCPtr &e) { if (!isCppPrimitive(e)) return false; - const auto *type = basicReferencedTypeEntry(e->asPrimitive()); + const auto type = basicReferencedTypeEntry(e); return AbstractMetaType::cppIntegralTypes().contains(type->qualifiedCppName()); } -bool isExtendedCppPrimitive(const TypeEntry *e) +bool isExtendedCppPrimitive(const TypeEntryCPtr &e) { if (isCppPrimitive(e)) return true; if (!e->isPrimitive()) return false; - const auto *type = basicReferencedTypeEntry(e->asPrimitive()); + const auto type = basicReferencedTypeEntry(e); const QString &name = type->qualifiedCppName(); return name == u"std::string" || name == u"std::wstring"; } @@ -544,12 +537,12 @@ bool TypeEntry::isComplex() const return false; } -TypeEntry *TypeEntry::viewOn() const +TypeEntryPtr TypeEntry::viewOn() const { return m_d->m_viewOn; } -void TypeEntry::setViewOn(TypeEntry *v) +void TypeEntry::setViewOn(const TypeEntryPtr &v) { m_d->m_viewOn = v; } @@ -560,7 +553,7 @@ TypeEntry *TypeEntry::clone() const } // Take over parameters relevant for typedefs -void TypeEntry::useAsTypedef(const TypeEntry *source) +void TypeEntry::useAsTypedef(const TypeEntryCPtr &source) { // XML Typedefs are in the global namespace for now. m_d->m_parent = typeSystemTypeEntry(source); @@ -583,7 +576,7 @@ public: }; CustomTypeEntry::CustomTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new CustomTypeEntryPrivate(entryName, CustomType, vr, parent)) { } @@ -669,7 +662,7 @@ public: }; TypeSystemTypeEntry::TypeSystemTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new TypeSystemTypeEntryPrivate(entryName, TypeSystemType, vr, parent)) { } @@ -757,7 +750,7 @@ public: }; TemplateArgumentEntry::TemplateArgumentEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new TemplateArgumentEntryPrivate(entryName, TemplateArgumentType, vr, parent)) { } @@ -789,30 +782,30 @@ TemplateArgumentEntry::TemplateArgumentEntry(TemplateArgumentEntryPrivate *d) : class ArrayTypeEntryPrivate : public TypeEntryPrivate { public: - explicit ArrayTypeEntryPrivate(const TypeEntry *nested_type, const QVersionNumber &vr, - const TypeEntry *parent) : + explicit ArrayTypeEntryPrivate(const TypeEntryCPtr &nested_type, const QVersionNumber &vr, + const TypeEntryCPtr &parent) : TypeEntryPrivate(u"Array"_s, TypeEntry::ArrayType, vr, parent), m_nestedType(nested_type) { } - const TypeEntry *m_nestedType; + TypeEntryCPtr m_nestedType; }; -ArrayTypeEntry::ArrayTypeEntry(const TypeEntry *nested_type, const QVersionNumber &vr, - const TypeEntry *parent) : +ArrayTypeEntry::ArrayTypeEntry(const TypeEntryCPtr &nested_type, const QVersionNumber &vr, + const TypeEntryCPtr &parent) : TypeEntry(new ArrayTypeEntryPrivate(nested_type, vr, parent)) { Q_ASSERT(nested_type); } -void ArrayTypeEntry::setNestedTypeEntry(TypeEntry *nested) +void ArrayTypeEntry::setNestedTypeEntry(const TypeEntryPtr &nested) { S_D(ArrayTypeEntry); d->m_nestedType = nested; } -const TypeEntry *ArrayTypeEntry::nestedTypeEntry() const +TypeEntryCPtr ArrayTypeEntry::nestedTypeEntry() const { S_D(const ArrayTypeEntry); return d->m_nestedType; @@ -840,7 +833,7 @@ class PrimitiveTypeEntryPrivate : public TypeEntryPrivate { public: PrimitiveTypeEntryPrivate(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntryPrivate(entryName, TypeEntry::PrimitiveType, vr, parent), m_preferredTargetLangType(true) { @@ -848,12 +841,12 @@ public: QString m_defaultConstructor; CustomConversionPtr m_customConversion; - PrimitiveTypeEntry *m_referencedTypeEntry = nullptr; + PrimitiveTypeEntryPtr m_referencedTypeEntry; uint m_preferredTargetLangType : 1; }; PrimitiveTypeEntry::PrimitiveTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new PrimitiveTypeEntryPrivate(entryName, vr, parent)) { } @@ -876,29 +869,35 @@ bool PrimitiveTypeEntry::hasDefaultConstructor() const return !d->m_defaultConstructor.isEmpty(); } -PrimitiveTypeEntry *PrimitiveTypeEntry::referencedTypeEntry() const +PrimitiveTypeEntryPtr PrimitiveTypeEntry::referencedTypeEntry() const { S_D(const PrimitiveTypeEntry); return d->m_referencedTypeEntry; } -void PrimitiveTypeEntry::setReferencedTypeEntry(PrimitiveTypeEntry *referencedTypeEntry) +void PrimitiveTypeEntry::setReferencedTypeEntry(PrimitiveTypeEntryPtr referencedTypeEntry) { S_D(PrimitiveTypeEntry); d->m_referencedTypeEntry = referencedTypeEntry; } -const PrimitiveTypeEntry *basicReferencedTypeEntry(const PrimitiveTypeEntry *e) +PrimitiveTypeEntryCPtr basicReferencedTypeEntry(const PrimitiveTypeEntryCPtr &e) { - auto *result = e; - while (auto *referenced = result->referencedTypeEntry()) + auto result = e; + while (auto referenced = result->referencedTypeEntry()) result = referenced; return result; } -const PrimitiveTypeEntry *basicReferencedNonBuiltinTypeEntry(const PrimitiveTypeEntry *e) +PrimitiveTypeEntryCPtr basicReferencedTypeEntry(const TypeEntryCPtr &e) { - auto *result = e; + Q_ASSERT(e->isPrimitive()); + return basicReferencedTypeEntry(qSharedPointerCast<const PrimitiveTypeEntry>(e)); +} + +PrimitiveTypeEntryCPtr basicReferencedNonBuiltinTypeEntry(const PrimitiveTypeEntryCPtr &e) +{ + auto result = e; for (; result->referencedTypeEntry() ; result = result->referencedTypeEntry()) { if (!result->isBuiltIn()) break; @@ -959,16 +958,16 @@ class EnumTypeEntryPrivate : public TypeEntryPrivate public: using TypeEntryPrivate::TypeEntryPrivate; - const EnumValueTypeEntry *m_nullValue = nullptr; + EnumValueTypeEntryCPtr m_nullValue; QStringList m_rejectedEnums; - FlagsTypeEntry *m_flags = nullptr; + FlagsTypeEntryPtr m_flags; QString m_cppType; TypeSystem::PythonEnumType m_pythonEnumType = TypeSystem::PythonEnumType::Unspecified; }; EnumTypeEntry::EnumTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new EnumTypeEntryPrivate(entryName, EnumType, vr, parent)) { } @@ -1002,25 +1001,25 @@ QString EnumTypeEntry::qualifier() const parentEntry->name() : QString(); } -const EnumValueTypeEntry *EnumTypeEntry::nullValue() const +EnumValueTypeEntryCPtr EnumTypeEntry::nullValue() const { S_D(const EnumTypeEntry); return d->m_nullValue; } -void EnumTypeEntry::setNullValue(const EnumValueTypeEntry *n) +void EnumTypeEntry::setNullValue(const EnumValueTypeEntryCPtr &n) { S_D(EnumTypeEntry); d->m_nullValue = n; } -void EnumTypeEntry::setFlags(FlagsTypeEntry *flags) +void EnumTypeEntry::setFlags(const FlagsTypeEntryPtr &flags) { S_D(EnumTypeEntry); d->m_flags = flags; } -FlagsTypeEntry *EnumTypeEntry::flags() const +FlagsTypeEntryPtr EnumTypeEntry::flags() const { S_D(const EnumTypeEntry); return d->m_flags; @@ -1072,7 +1071,7 @@ class EnumValueTypeEntryPrivate : public TypeEntryPrivate { public: EnumValueTypeEntryPrivate(const QString &name, const QString &value, - const EnumTypeEntry *enclosingEnum, + const EnumTypeEntryCPtr &enclosingEnum, bool isScopedEnum, const QVersionNumber &vr) : TypeEntryPrivate(name, TypeEntry::EnumValue, vr, @@ -1083,11 +1082,11 @@ public: } QString m_value; - const EnumTypeEntry *m_enclosingEnum; + EnumTypeEntryCPtr m_enclosingEnum; }; EnumValueTypeEntry::EnumValueTypeEntry(const QString &name, const QString &value, - const EnumTypeEntry *enclosingEnum, + const EnumTypeEntryCPtr &enclosingEnum, bool isScopedEnum, const QVersionNumber &vr) : TypeEntry(new EnumValueTypeEntryPrivate(name, value, enclosingEnum, isScopedEnum, vr)) @@ -1100,7 +1099,7 @@ QString EnumValueTypeEntry::value() const return d->m_value; } -const EnumTypeEntry *EnumValueTypeEntry::enclosingEnum() const +EnumTypeEntryCPtr EnumValueTypeEntry::enclosingEnum() const { S_D(const EnumValueTypeEntry); return d->m_enclosingEnum; @@ -1125,11 +1124,11 @@ public: QString m_originalName; QString m_flagsName; - EnumTypeEntry *m_enum = nullptr; + EnumTypeEntryPtr m_enum; }; FlagsTypeEntry::FlagsTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new FlagsTypeEntryPrivate(entryName, FlagsType, vr, parent)) { } @@ -1171,13 +1170,13 @@ void FlagsTypeEntry::setFlagsName(const QString &name) d->m_flagsName = name; } -EnumTypeEntry *FlagsTypeEntry::originator() const +EnumTypeEntryPtr FlagsTypeEntry::originator() const { S_D(const FlagsTypeEntry); return d->m_enum; } -void FlagsTypeEntry::setOriginator(EnumTypeEntry *e) +void FlagsTypeEntry::setOriginator(const EnumTypeEntryPtr &e) { S_D(FlagsTypeEntry); d->m_enum = e; @@ -1191,7 +1190,7 @@ TypeEntry *FlagsTypeEntry::clone() const // ----------------- ConstantValueTypeEntry ConstantValueTypeEntry::ConstantValueTypeEntry(const QString& name, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(name, ConstantValueType, QVersionNumber(0, 0), parent) { } @@ -1207,7 +1206,7 @@ class ComplexTypeEntryPrivate : public TypeEntryPrivate public: ComplexTypeEntryPrivate(const QString &entryName, TypeEntry::Type t, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntryPrivate(entryName, t, vr, parent), m_qualifiedCppName(buildName(entryName, parent)), m_polymorphicBase(false), @@ -1241,7 +1240,7 @@ public: ComplexTypeEntry::CopyableFlag m_copyableFlag = ComplexTypeEntry::Unknown; QString m_hashFunction; - const ComplexTypeEntry *m_baseContainerType = nullptr; + ComplexTypeEntryCPtr m_baseContainerType; // For class functions TypeSystem::ExceptionHandling m_exceptionHandling = TypeSystem::ExceptionHandling::Unspecified; TypeSystem::AllowThread m_allowThread = TypeSystem::AllowThread::Unspecified; @@ -1256,7 +1255,7 @@ public: ComplexTypeEntry::ComplexTypeEntry(const QString &entryName, TypeEntry::Type t, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new ComplexTypeEntryPrivate(entryName, t, vr, parent)) { } @@ -1583,13 +1582,13 @@ void ComplexTypeEntry::setHashFunction(const QString &hashFunction) d->m_hashFunction = hashFunction; } -void ComplexTypeEntry::setBaseContainerType(const ComplexTypeEntry *baseContainer) +void ComplexTypeEntry::setBaseContainerType(const ComplexTypeEntryCPtr &baseContainer) { S_D(ComplexTypeEntry); d->m_baseContainerType = baseContainer; } -const ComplexTypeEntry *ComplexTypeEntry::baseContainerType() const +ComplexTypeEntryCPtr ComplexTypeEntry::baseContainerType() const { S_D(const ComplexTypeEntry); return d->m_baseContainerType; @@ -1681,7 +1680,7 @@ TypeEntry *ComplexTypeEntry::clone() const } // Take over parameters relevant for typedefs -void ComplexTypeEntry::useAsTypedef(const ComplexTypeEntry *source) +void ComplexTypeEntry::useAsTypedef(const ComplexTypeEntryCPtr &source) { S_D(ComplexTypeEntry); TypeEntry::useAsTypedef(source); @@ -1709,7 +1708,7 @@ public: TypedefEntryPrivate(const QString &entryName, const QString &sourceType, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : ComplexTypeEntryPrivate(entryName, TypeEntry::TypedefType, vr, parent), m_sourceType(sourceType) @@ -1717,12 +1716,12 @@ public: } QString m_sourceType; - const ComplexTypeEntry *m_source = nullptr; - ComplexTypeEntry *m_target = nullptr; + ComplexTypeEntryCPtr m_source; + ComplexTypeEntryPtr m_target; }; TypedefEntry::TypedefEntry(const QString &entryName, const QString &sourceType, - const QVersionNumber &vr, const TypeEntry *parent) : + const QVersionNumber &vr, const TypeEntryCPtr &parent) : ComplexTypeEntry(new TypedefEntryPrivate(entryName, sourceType, vr, parent)) { } @@ -1745,25 +1744,25 @@ TypeEntry *TypedefEntry::clone() const return new TypedefEntry(new TypedefEntryPrivate(*d)); } -const ComplexTypeEntry *TypedefEntry::source() const +ComplexTypeEntryCPtr TypedefEntry::source() const { S_D(const TypedefEntry); return d->m_source; } -void TypedefEntry::setSource(const ComplexTypeEntry *source) +void TypedefEntry::setSource(const ComplexTypeEntryCPtr &source) { S_D(TypedefEntry); d->m_source = source; } -ComplexTypeEntry *TypedefEntry::target() const +ComplexTypeEntryPtr TypedefEntry::target() const { S_D(const TypedefEntry); return d->m_target; } -void TypedefEntry::setTarget(ComplexTypeEntry *target) +void TypedefEntry::setTarget(ComplexTypeEntryPtr target) { S_D(TypedefEntry); d->m_target = target; @@ -1784,7 +1783,7 @@ public: ContainerTypeEntryPrivate(const QString &entryName, ContainerTypeEntry::ContainerKind containerKind, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : ComplexTypeEntryPrivate(entryName, TypeEntry::ContainerType, vr, parent), m_containerKind(containerKind) { @@ -1805,7 +1804,7 @@ public: ContainerTypeEntry::ContainerTypeEntry(const QString &entryName, ContainerKind containerKind, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : ComplexTypeEntry(new ContainerTypeEntryPrivate(entryName, containerKind, vr, parent)) { setCodeGeneration(GenerateForSubclass); @@ -1884,7 +1883,7 @@ public: const QString &getterName, TypeSystem::SmartPointerType type, const QString &refCountMethodName, - const QVersionNumber &vr, const TypeEntry *parent) : + const QVersionNumber &vr, const TypeEntryCPtr &parent) : ComplexTypeEntryPrivate(entryName, TypeEntry::SmartPointerType, vr, parent), m_getterName(getterName), m_refCountMethodName(refCountMethodName), @@ -1892,7 +1891,7 @@ public: { } - qsizetype instantiationIndex(const TypeEntry *t) const; + qsizetype instantiationIndex(const TypeEntryCPtr &t) const; QString m_getterName; QString m_refCountMethodName; @@ -1903,7 +1902,7 @@ public: TypeSystem::SmartPointerType m_smartPointerType; }; -qsizetype SmartPointerTypeEntryPrivate::instantiationIndex(const TypeEntry *t) const +qsizetype SmartPointerTypeEntryPrivate::instantiationIndex(const TypeEntryCPtr &t) const { for (qsizetype i = 0, size = m_instantiations.size(); i < size; ++i) { if (m_instantiations.at(i).typeEntry == t) @@ -1916,7 +1915,8 @@ SmartPointerTypeEntry::SmartPointerTypeEntry(const QString &entryName, const QString &getterName, TypeSystem::SmartPointerType smartPointerType, const QString &refCountMethodName, - const QVersionNumber &vr, const TypeEntry *parent) : + const QVersionNumber &vr, + const TypeEntryCPtr &parent) : ComplexTypeEntry(new SmartPointerTypeEntryPrivate(entryName, getterName, smartPointerType, refCountMethodName, vr, parent)) { @@ -1999,7 +1999,7 @@ SmartPointerTypeEntry::SmartPointerTypeEntry(SmartPointerTypeEntryPrivate *d) : { } -bool SmartPointerTypeEntry::matchesInstantiation(const TypeEntry *e) const +bool SmartPointerTypeEntry::matchesInstantiation(const TypeEntryCPtr &e) const { S_D(const SmartPointerTypeEntry); // No instantiations specified, or match @@ -2018,7 +2018,7 @@ static QString fixSmartPointerName(QString name) QString SmartPointerTypeEntry::getTargetName(const AbstractMetaType &metaType) const { S_D(const SmartPointerTypeEntry); - auto *instantiatedTe = metaType.instantiations().constFirst().typeEntry(); + auto instantiatedTe = metaType.instantiations().constFirst().typeEntry(); const auto index = d->instantiationIndex(instantiatedTe); if (index != -1 && !d->m_instantiations.at(index).name.isEmpty()) return d->m_instantiations.at(index).name; @@ -2040,7 +2040,7 @@ public: using ComplexTypeEntryPrivate::ComplexTypeEntryPrivate; QRegularExpression m_filePattern; - const NamespaceTypeEntry *m_extends = nullptr; + NamespaceTypeEntryCPtr m_extends; TypeSystem::Visibility m_visibility = TypeSystem::Visibility::Auto; bool m_hasPattern = false; bool m_inlineNamespace = false; @@ -2048,7 +2048,7 @@ public: }; NamespaceTypeEntry::NamespaceTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : ComplexTypeEntry(new NamespaceTypeEntryPrivate(entryName, NamespaceType, vr, parent)) { } @@ -2059,13 +2059,13 @@ TypeEntry *NamespaceTypeEntry::clone() const return new NamespaceTypeEntry(new NamespaceTypeEntryPrivate(*d)); } -const NamespaceTypeEntry *NamespaceTypeEntry::extends() const +NamespaceTypeEntryCPtr NamespaceTypeEntry::extends() const { S_D(const NamespaceTypeEntry); return d->m_extends; } -void NamespaceTypeEntry::setExtends(const NamespaceTypeEntry *e) +void NamespaceTypeEntry::setExtends(const NamespaceTypeEntryCPtr &e) { S_D(NamespaceTypeEntry); d->m_extends = e; @@ -2128,6 +2128,11 @@ void NamespaceTypeEntry::setInlineNamespace(bool i) d->m_inlineNamespace = i; } +bool NamespaceTypeEntry::isVisibleScope(const TypeEntryCPtr &e) +{ + return isVisibleScope(e.data()); +} + bool NamespaceTypeEntry::isVisibleScope(const TypeEntry *e) { return e->type() != TypeEntry::NamespaceType @@ -2158,7 +2163,7 @@ public: }; ValueTypeEntry::ValueTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : ComplexTypeEntry(new ValueTypeEntryPrivate(entryName, BasicValueType, vr, parent)) { } @@ -2216,7 +2221,7 @@ ValueTypeEntry::ValueTypeEntry(ComplexTypeEntryPrivate *d) : } ValueTypeEntry::ValueTypeEntry(const QString &entryName, Type t, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : ComplexTypeEntry(entryName, t, vr, parent) { } @@ -2227,7 +2232,7 @@ class FunctionTypeEntryPrivate : public TypeEntryPrivate public: FunctionTypeEntryPrivate(const QString &entryName, const QString &signature, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntryPrivate(entryName, TypeEntry::FunctionType, vr, parent), m_signatures(signature) { @@ -2239,7 +2244,7 @@ public: FunctionTypeEntry::FunctionTypeEntry(const QString &entryName, const QString &signature, const QVersionNumber &vr, - const TypeEntry *parent) : + const TypeEntryCPtr &parent) : TypeEntry(new FunctionTypeEntryPrivate(entryName, signature, vr, parent)) { } @@ -2287,7 +2292,7 @@ FunctionTypeEntry::FunctionTypeEntry(FunctionTypeEntryPrivate *d) : // ----------------- ObjectTypeEntry ObjectTypeEntry::ObjectTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent) + const TypeEntryCPtr &parent) : ComplexTypeEntry(entryName, ObjectType, vr, parent) { } @@ -2363,7 +2368,7 @@ void TypeEntry::formatDebug(QDebug &debug) const void PrimitiveTypeEntry::formatDebug(QDebug &debug) const { TypeEntry::formatDebug(debug); - if (auto *e = referencedTypeEntry()) { + if (auto e = referencedTypeEntry(); !e.isNull()) { debug << ", references"; for (; e != nullptr; e = e->referencedTypeEntry()) debug << ":\"" << e->qualifiedCppName() <<'"'; @@ -2471,7 +2476,7 @@ void SmartPointerTypeEntry::formatDebug(QDebug &debug) const if (!d->m_instantiations.isEmpty()) { debug << "type=" << d->m_type << ", instantiations[" << d->m_instantiations.size() << "]=("; - for (auto i : d->m_instantiations) { + for (const auto &i : d->m_instantiations) { debug << i.typeEntry->name() << ','; if (!i.name.isEmpty()) debug << "=\"" << i.name << '"'; @@ -2494,6 +2499,12 @@ QDebug operator<<(QDebug d, const TypeEntry *te) return d; } +QDebug operator<<(QDebug d, const TypeEntryCPtr &te) +{ + d << te.data(); + return d; +} + QDebug operator<<(QDebug d, const TemplateEntry *te) { QDebugStateSaver saver(d); @@ -2508,4 +2519,10 @@ QDebug operator<<(QDebug d, const TemplateEntry *te) d << ')'; return d; } + +QDebug operator<<(QDebug d, const TemplateEntryCPtr &te) +{ + d << te.data(); + return d; +} #endif // QT_NO_DEBUG_STREAM diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h index e207fe9ea..a2e4debc8 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.h +++ b/sources/shiboken6/ApiExtractor/typesystem.h @@ -5,6 +5,7 @@ #define TYPESYSTEM_H #include "include.h" +#include "typesystem_typedefs.h" #include <QtCore/qobjectdefs.h> #include <QtCore/QString> @@ -61,14 +62,14 @@ public: Q_ENUM(CodeGeneration) explicit TypeEntry(const QString &entryName, Type t, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); virtual ~TypeEntry(); Type type() const; - const TypeEntry *parent() const; - void setParent(const TypeEntry *p); - bool isChildOf(const TypeEntry *p) const; + TypeEntryCPtr parent() const; + void setParent(const TypeEntryCPtr &); + bool isChildOf(const TypeEntryCPtr &p) const; bool isPrimitive() const; bool isEnum() const; @@ -129,9 +130,9 @@ public: /// be a JNI name, for Python it should represent the CPython type name. /// \return string representing the target language API name /// Currently used only for PrimitiveTypeEntry (attribute "target"). - const CustomTypeEntry *targetLangApiType() const; + CustomTypeEntryCPtr targetLangApiType() const; bool hasTargetLangApiType() const; - void setTargetLangApiType(CustomTypeEntry *cte); + void setTargetLangApiType(const CustomTypeEntryPtr &cte); QString targetLangApiName() const; // The type's name in TargetLang @@ -160,18 +161,16 @@ public: // View on: Type to use for function argument conversion, fex // std::string_view -> std::string for foo(std::string_view). // cf AbstractMetaType::viewOn() - TypeEntry *viewOn() const; - void setViewOn(TypeEntry *v); + TypeEntryPtr viewOn() const; + void setViewOn(const TypeEntryPtr &v); virtual TypeEntry *clone() const; - void useAsTypedef(const TypeEntry *source); + void useAsTypedef(const TypeEntryCPtr &source); SourceLocation sourceLocation() const; void setSourceLocation(const SourceLocation &sourceLocation); - const PrimitiveTypeEntry *asPrimitive() const; - // Query functions for generators /// Returns true if the type passed has a Python wrapper for it. /// Although namespace has a Python wrapper, it's not considered a type. @@ -195,22 +194,22 @@ private: QScopedPointer<TypeEntryPrivate> m_d; }; -const TypeSystemTypeEntry *typeSystemTypeEntry(const TypeEntry *e); +TypeSystemTypeEntryCPtr typeSystemTypeEntry(TypeEntryCPtr e); // cf AbstractMetaClass::targetLangEnclosingClass() -const TypeEntry *targetLangEnclosingEntry(const TypeEntry *e); +TypeEntryCPtr targetLangEnclosingEntry(const TypeEntryCPtr &e); -bool isCppPrimitive(const TypeEntry *e); +bool isCppPrimitive(const TypeEntryCPtr &e); /// Returns true if the type is a primitive but not a C++ primitive. -bool isUserPrimitive(const TypeEntry *e); +bool isUserPrimitive(const TypeEntryCPtr &e); /// Returns true if the type is a C++ integral primitive, /// i.e. bool, char, int, long, and their unsigned counterparts. -bool isCppIntegralPrimitive(const TypeEntry *e); +bool isCppIntegralPrimitive(const TypeEntryCPtr &e); /// Returns true if the type is an extended C++ primitive, a void*, /// a const char*, or a std::string (cf isCppPrimitive()). -bool isExtendedCppPrimitive(const TypeEntry *e); +bool isExtendedCppPrimitive(const TypeEntryCPtr &e); #endif // TYPESYSTEM_H diff --git a/sources/shiboken6/ApiExtractor/typesystem_typedefs.h b/sources/shiboken6/ApiExtractor/typesystem_typedefs.h index 25003938f..ca652252d 100644 --- a/sources/shiboken6/ApiExtractor/typesystem_typedefs.h +++ b/sources/shiboken6/ApiExtractor/typesystem_typedefs.h @@ -5,10 +5,15 @@ #define TYPESYSTEM_TYPEDEFS_H #include <QtCore/QList> +#include <QtCore/QSharedPointer> +class ArrayTypeEntry; class ComplexTypeEntry; class ConstantValueTypeEntry; class ContainerTypeEntry; +class CustomTypeEntry; +class EnumTypeEntry; +class EnumValueTypeEntry; class FlagsTypeEntry; class FunctionTypeEntry; class NamespaceTypeEntry; @@ -19,12 +24,51 @@ class TemplateEntry; class TypeEntry; class TypedefEntry; class TypeSystemTypeEntry; +class ValueTypeEntry; -using ContainerTypeEntryCList = QList<const ContainerTypeEntry *>; -using NamespaceTypeEntryList = QList<NamespaceTypeEntry *>; -using PrimitiveTypeEntryCList = QList<const PrimitiveTypeEntry *>; -using SmartPointerTypeEntryList = QList<const SmartPointerTypeEntry *>; -using TypeEntryList = QList<TypeEntry *>; -using TypeEntryCList = QList<const TypeEntry *>; +using ArrayTypeEntryPtr = QSharedPointer<ArrayTypeEntry>; +using ComplexTypeEntryPtr = QSharedPointer<ComplexTypeEntry>; +using ConstantValueTypeEntryPtr = QSharedPointer<ConstantValueTypeEntry>; +using ContainerTypeEntryPtr = QSharedPointer<ContainerTypeEntry>; +using CustomTypeEntryPtr = QSharedPointer<CustomTypeEntry>; +using EnumTypeEntryPtr = QSharedPointer<EnumTypeEntry>; +using EnumValueTypeEntryPtr = QSharedPointer<EnumValueTypeEntry>; +using FlagsTypeEntryPtr = QSharedPointer<FlagsTypeEntry>; +using FunctionTypeEntryPtr = QSharedPointer<FunctionTypeEntry>; +using NamespaceTypeEntryPtr = QSharedPointer<NamespaceTypeEntry>; +using ObjectTypeEntryPtr = QSharedPointer<ObjectTypeEntry>; +using PrimitiveTypeEntryPtr = QSharedPointer<PrimitiveTypeEntry>; +using SmartPointerTypeEntryPtr = QSharedPointer<SmartPointerTypeEntry>; +using TemplateEntryPtr = QSharedPointer<TemplateEntry>; +using TypeEntryPtr = QSharedPointer<TypeEntry>; +using TypedefEntryPtr = QSharedPointer<TypedefEntry>; +using TypeSystemTypeEntryPtr = QSharedPointer<TypeSystemTypeEntry>; +using ValueTypeEntryPtr = QSharedPointer<ValueTypeEntry>; + +using ArrayTypeEntryCPtr = QSharedPointer<const ArrayTypeEntry>; +using ComplexTypeEntryCPtr = QSharedPointer<const ComplexTypeEntry>; +using ConstantValueTypeEntryCPtr = QSharedPointer<const ConstantValueTypeEntry>; +using ContainerTypeEntryCPtr = QSharedPointer<const ContainerTypeEntry>; +using CustomTypeEntryCPtr = QSharedPointer<const CustomTypeEntry>; +using EnumTypeEntryCPtr = QSharedPointer<const EnumTypeEntry>; +using EnumValueTypeEntryCPtr = QSharedPointer<const EnumValueTypeEntry>; +using FlagsTypeEntryCPtr = QSharedPointer<const FlagsTypeEntry>; +using FunctionTypeEntryCPtr = QSharedPointer<const FunctionTypeEntry>; +using NamespaceTypeEntryCPtr = QSharedPointer<const NamespaceTypeEntry>; +using ObjectTypeEntryCPtr = QSharedPointer<const ObjectTypeEntry>; +using PrimitiveTypeEntryCPtr = QSharedPointer<const PrimitiveTypeEntry>; +using SmartPointerTypeEntryCPtr = QSharedPointer<const SmartPointerTypeEntry>; +using TemplateEntryCPtr = QSharedPointer<const TemplateEntry>; +using TypeEntryCPtr = QSharedPointer<const TypeEntry>; +using TypedefEntryCPtr = QSharedPointer<const TypedefEntry>; +using TypeSystemTypeEntryCPtr = QSharedPointer<const TypeSystemTypeEntry>; +using ValueTypeEntryCPtr = QSharedPointer<const ValueTypeEntry>; + +using ContainerTypeEntryCList = QList<ContainerTypeEntryCPtr>; +using NamespaceTypeEntryList = QList<NamespaceTypeEntryPtr>; +using PrimitiveTypeEntryCList = QList<PrimitiveTypeEntryCPtr>; +using SmartPointerTypeEntryList = QList<SmartPointerTypeEntryCPtr>; +using TypeEntryList = QList<TypeEntryPtr>; +using TypeEntryCList = QList<TypeEntryCPtr>; #endif // TYPESYSTEM_TYPEDEFS_H diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp index cf73a9bb0..1977e49f8 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp @@ -880,7 +880,7 @@ bool TypeSystemParser::endElement(StackElement element) toNative.setSourceType(m_context->db->findType(toNative.sourceTypeName())); } } - purgeEmptyCodeSnips(&static_cast<TypeSystemTypeEntry *>(top->entry)->codeSnips()); + purgeEmptyCodeSnips(&qSharedPointerCast<TypeSystemTypeEntry>(top->entry)->codeSnips()); break; case StackElement::FunctionTypeEntry: TypeDatabase::instance()->addGlobalUserFunctionModifications(top->functionMods); @@ -892,7 +892,7 @@ bool TypeSystemParser::endElement(StackElement element) case StackElement::NamespaceTypeEntry: { Q_ASSERT(top->entry); Q_ASSERT(top->entry->isComplex()); - auto *centry = static_cast<ComplexTypeEntry *>(top->entry); + auto centry = qSharedPointerCast<ComplexTypeEntry>(top->entry); purgeEmptyCodeSnips(¢ry->codeSnips()); centry->setAddedFunctions(top->addedFunctions); centry->setFunctionModifications(top->functionMods); @@ -902,13 +902,13 @@ bool TypeSystemParser::endElement(StackElement element) break; case StackElement::TypedefTypeEntry: { - auto *centry = static_cast<TypedefEntry *>(top->entry)->target(); + auto centry = qSharedPointerCast<TypedefEntry>(top->entry)->target(); centry->setAddedFunctions(centry->addedFunctions() + top->addedFunctions); centry->setFunctionModifications(centry->functionModifications() + top->functionMods); centry->setFieldModifications(centry->fieldModifications() + top->fieldMods); centry->setDocModification(centry->docModifications() + top->docModifications); if (top->entry->isComplex()) { - auto *cte = static_cast<const ComplexTypeEntry *>(top->entry); + auto cte = qSharedPointerCast<const ComplexTypeEntry>(top->entry); centry->setCodeSnips(centry->codeSnips() + cte->codeSnips()); } } @@ -1068,12 +1068,12 @@ CodeSnipAbstract *TypeSystemParser::injectCodeTarget(qsizetype offset) const } case ParserState::TypeEntryCodeInjection: Q_ASSERT(top->entry->isComplex()); - return &static_cast<ComplexTypeEntry *>(top->entry)->codeSnips().last(); + return &qSharedPointerCast<ComplexTypeEntry>(top->entry)->codeSnips().last(); case ParserState::TypeSystemCodeInjection: Q_ASSERT(top->entry->isTypeSystem()); - return &static_cast<TypeSystemTypeEntry *>(top->entry)->codeSnips().last(); + return &qSharedPointerCast<TypeSystemTypeEntry>(top->entry)->codeSnips().last(); case ParserState::Template: - return m_templateEntry; + return m_templateEntry.data(); default: break; } @@ -1210,7 +1210,7 @@ static bool shouldDropTypeEntry(const TypeDatabase *db, QString name) { for (auto i = stack.size() - 1; i >= 0; --i) { - if (auto *entry = stack.at(i)->entry) { + if (auto entry = stack.at(i)->entry) { if (entry->type() == TypeEntry::TypeSystemType) { if (db->shouldDropTypeEntry(name)) // Unqualified return true; @@ -1237,7 +1237,7 @@ static QString checkSignatureError(const QString& signature, const QString& tag) return QString(); } -inline const TypeEntry *TypeSystemParser::currentParentTypeEntry() const +inline TypeEntryCPtr TypeSystemParser::currentParentTypeEntry() const { const auto size = m_contextStack.size(); return size > 1 ? m_contextStack.at(size - 2)->entry : nullptr; @@ -1246,15 +1246,15 @@ inline const TypeEntry *TypeSystemParser::currentParentTypeEntry() const bool TypeSystemParser::checkRootElement() { for (auto i = m_contextStack.size() - 1; i >= 0; --i) { - auto *e = m_contextStack.at(i)->entry; - if (e && e->isTypeSystem()) + auto e = m_contextStack.at(i)->entry; + if (!e.isNull() && e->isTypeSystem()) return true; } m_error = msgNoRootTypeSystemEntry(); return false; } -static TypeEntry *findViewedType(const QString &name) +static TypeEntryPtr findViewedType(const QString &name) { const auto range = TypeDatabase::instance()->entries().equal_range(name); for (auto i = range.first; i != range.second; ++i) { @@ -1271,7 +1271,8 @@ static TypeEntry *findViewedType(const QString &name) return nullptr; } -bool TypeSystemParser::applyCommonAttributes(const ConditionalStreamReader &reader, TypeEntry *type, +bool TypeSystemParser::applyCommonAttributes(const ConditionalStreamReader &reader, + const TypeEntryPtr &type, QXmlStreamAttributes *attributes) { type->setSourceLocation(SourceLocation(m_currentFile, @@ -1283,8 +1284,8 @@ bool TypeSystemParser::applyCommonAttributes(const ConditionalStreamReader &read type->setRevision(attributes->takeAt(i).value().toInt()); } else if (name == u"view-on") { const QString name = attributes->takeAt(i).value().toString(); - TypeEntry *views = findViewedType(name); - if (views == nullptr) { + TypeEntryPtr views = findViewedType(name); + if (views.isNull()) { m_error = msgCannotFindView(name, type->name()); return false; } @@ -1294,14 +1295,14 @@ bool TypeSystemParser::applyCommonAttributes(const ConditionalStreamReader &read return true; } -CustomTypeEntry *TypeSystemParser::parseCustomTypeEntry(const ConditionalStreamReader &, +CustomTypeEntryPtr TypeSystemParser::parseCustomTypeEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { if (!checkRootElement()) return nullptr; - auto *result = new CustomTypeEntry(name, since, m_contextStack.top()->entry); + CustomTypeEntryPtr result(new CustomTypeEntry(name, since, m_contextStack.top()->entry)); for (auto i = attributes->size() - 1; i >= 0; --i) { const auto name = attributes->at(i).qualifiedName(); if (name == checkFunctionAttribute()) @@ -1310,18 +1311,18 @@ CustomTypeEntry *TypeSystemParser::parseCustomTypeEntry(const ConditionalStreamR return result; } -FlagsTypeEntry * +FlagsTypeEntryPtr TypeSystemParser::parseFlagsEntry(const ConditionalStreamReader &reader, - EnumTypeEntry *enumEntry, QString flagName, + const EnumTypeEntryPtr &enumEntry, QString flagName, const QVersionNumber &since, QXmlStreamAttributes *attributes) { if (!checkRootElement()) return nullptr; - auto ftype = new FlagsTypeEntry(u"QFlags<"_s + enumEntry->name() + u'>', - since, - typeSystemTypeEntry(currentParentTypeEntry())); + FlagsTypeEntryPtr ftype(new FlagsTypeEntry(u"QFlags<"_s + enumEntry->name() + u'>', + since, + typeSystemTypeEntry(currentParentTypeEntry()))); ftype->setOriginator(enumEntry); ftype->setTargetLangPackage(enumEntry->targetLangPackage()); // Try toenumEntry get the guess the qualified flag name @@ -1359,7 +1360,7 @@ FlagsTypeEntry * return ftype; } -SmartPointerTypeEntry * +SmartPointerTypeEntryPtr TypeSystemParser::parseSmartPointerEntry(const ConditionalStreamReader &reader, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) @@ -1422,8 +1423,8 @@ SmartPointerTypeEntry * return nullptr; } - auto *type = new SmartPointerTypeEntry(name, getter, smartPointerType, - refCountMethodName, since, currentParentTypeEntry()); + SmartPointerTypeEntryPtr type(new SmartPointerTypeEntry(name, getter, smartPointerType, + refCountMethodName, since, currentParentTypeEntry())); if (!applyCommonAttributes(reader, type, attributes)) return nullptr; applyComplexTypeAttributes(reader, type, attributes); @@ -1434,14 +1435,14 @@ SmartPointerTypeEntry * return type; } -PrimitiveTypeEntry * +PrimitiveTypeEntryPtr TypeSystemParser::parsePrimitiveTypeEntry(const ConditionalStreamReader &reader, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { if (!checkRootElement()) return nullptr; - auto *type = new PrimitiveTypeEntry(name, since, currentParentTypeEntry()); + PrimitiveTypeEntryPtr type (new PrimitiveTypeEntry(name, since, currentParentTypeEntry())); QString targetLangApiName; if (!applyCommonAttributes(reader, type, attributes)) return nullptr; @@ -1464,19 +1465,19 @@ PrimitiveTypeEntry * } if (!targetLangApiName.isEmpty()) { - auto *e = m_context->db->findType(targetLangApiName); - if (e == nullptr || !e->isCustom()) { + auto e = m_context->db->findType(targetLangApiName); + if (e.isNull() || !e->isCustom()) { m_error = msgInvalidTargetLanguageApiName(targetLangApiName); return nullptr; } - type->setTargetLangApiType(static_cast<CustomTypeEntry *>(e)); + type->setTargetLangApiType(qSharedPointerCast<CustomTypeEntry>(e)); } type->setTargetLangPackage(m_defaultPackage); return type; } // "int:QList_int;QString:QList_QString" -static bool parseOpaqueContainers(QStringView s, ContainerTypeEntry *cte) +static bool parseOpaqueContainers(QStringView s, ContainerTypeEntryPtr cte) { const auto entries = s.split(u';'); for (const auto &entry : entries) { @@ -1490,7 +1491,7 @@ static bool parseOpaqueContainers(QStringView s, ContainerTypeEntry *cte) return true; } -ContainerTypeEntry * +ContainerTypeEntryPtr TypeSystemParser::parseContainerTypeEntry(const ConditionalStreamReader &reader, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) @@ -1509,8 +1510,8 @@ ContainerTypeEntry * return nullptr; } attributes->removeAt(typeIndex); - auto *type = new ContainerTypeEntry(name, containerTypeOpt.value(), - since, currentParentTypeEntry()); + ContainerTypeEntryPtr type(new ContainerTypeEntry(name, containerTypeOpt.value(), + since, currentParentTypeEntry())); if (!applyCommonAttributes(reader, type, attributes)) return nullptr; applyComplexTypeAttributes(reader, type, attributes); @@ -1530,14 +1531,14 @@ ContainerTypeEntry * return type; } -EnumTypeEntry * +EnumTypeEntryPtr TypeSystemParser::parseEnumTypeEntry(const ConditionalStreamReader &reader, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { if (!checkRootElement()) return nullptr; - auto *entry = new EnumTypeEntry(name, since, currentParentTypeEntry()); + EnumTypeEntryPtr entry(new EnumTypeEntry(name, since, currentParentTypeEntry())); applyCommonAttributes(reader, entry, attributes); entry->setTargetLangPackage(m_defaultPackage); @@ -1582,16 +1583,16 @@ EnumTypeEntry * } -NamespaceTypeEntry * +NamespaceTypeEntryPtr TypeSystemParser::parseNamespaceTypeEntry(const ConditionalStreamReader &reader, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { if (!checkRootElement()) return nullptr; - std::unique_ptr<NamespaceTypeEntry> result(new NamespaceTypeEntry(name, since, currentParentTypeEntry())); + NamespaceTypeEntryPtr result(new NamespaceTypeEntry(name, since, currentParentTypeEntry())); auto visibility = TypeSystem::Visibility::Unspecified; - applyCommonAttributes(reader, result.get(), attributes); + applyCommonAttributes(reader, result, attributes); for (auto i = attributes->size() - 1; i >= 0; --i) { const auto attributeName = attributes->at(i).qualifiedName(); if (attributeName == u"files") { @@ -1606,7 +1607,7 @@ NamespaceTypeEntry * const auto extendsPackageName = attributes->at(i).value(); auto allEntries = TypeDatabase::instance()->findNamespaceTypes(name); auto extendsIt = std::find_if(allEntries.cbegin(), allEntries.cend(), - [extendsPackageName] (const NamespaceTypeEntry *e) { + [extendsPackageName] (const NamespaceTypeEntryCPtr &e) { return e->targetLangPackage() == extendsPackageName; }); if (extendsIt == allEntries.cend()) { @@ -1634,24 +1635,24 @@ NamespaceTypeEntry * if (visibility != TypeSystem::Visibility::Unspecified) result->setVisibility(visibility); // Handle legacy "generate" before the common handling - applyComplexTypeAttributes(reader, result.get(), attributes); + applyComplexTypeAttributes(reader, result, attributes); if (result->extends() && !result->hasPattern()) { m_error = msgExtendingNamespaceRequiresPattern(name); - return nullptr; + return {}; } - return result.release(); + return result; } -ValueTypeEntry * +ValueTypeEntryPtr TypeSystemParser::parseValueTypeEntry(const ConditionalStreamReader &reader, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) { if (!checkRootElement()) return nullptr; - auto *typeEntry = new ValueTypeEntry(name, since, currentParentTypeEntry()); + ValueTypeEntryPtr typeEntry(new ValueTypeEntry(name, since, currentParentTypeEntry())); if (!applyCommonAttributes(reader, typeEntry, attributes)) return nullptr; applyComplexTypeAttributes(reader, typeEntry, attributes); @@ -1662,7 +1663,7 @@ ValueTypeEntry * return typeEntry; } -FunctionTypeEntry * +FunctionTypeEntryPtr TypeSystemParser::parseFunctionTypeEntry(const ConditionalStreamReader &reader, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes) @@ -1693,10 +1694,10 @@ FunctionTypeEntry * return nullptr; } - TypeEntry *existingType = m_context->db->findType(name); + TypeEntryPtr existingType = m_context->db->findType(name); - if (!existingType) { - auto *result = new FunctionTypeEntry(name, signature, since, currentParentTypeEntry()); + if (existingType.isNull()) { + FunctionTypeEntryPtr result(new FunctionTypeEntry(name, signature, since, currentParentTypeEntry())); result->setSnakeCase(snakeCase); applyCommonAttributes(reader, result, attributes); return result; @@ -1708,12 +1709,12 @@ FunctionTypeEntry * return nullptr; } - auto *result = reinterpret_cast<FunctionTypeEntry *>(existingType); + auto result = qSharedPointerCast<FunctionTypeEntry>(existingType); result->addSignature(signature); return result; } -TypedefEntry * +TypedefEntryPtr TypeSystemParser::parseTypedefEntry(const ConditionalStreamReader &reader, const QString &name, StackElement topElement, const QVersionNumber &since, @@ -1732,7 +1733,7 @@ TypedefEntry * return nullptr; } const QString sourceType = attributes->takeAt(sourceIndex).value().toString(); - auto result = new TypedefEntry(name, sourceType, since, currentParentTypeEntry()); + TypedefEntryPtr result(new TypedefEntry(name, sourceType, since, currentParentTypeEntry())); if (!applyCommonAttributes(reader, result, attributes)) return nullptr; applyComplexTypeAttributes(reader, result, attributes); @@ -1740,7 +1741,7 @@ TypedefEntry * } void TypeSystemParser::applyComplexTypeAttributes(const ConditionalStreamReader &reader, - ComplexTypeEntry *ctype, + const ComplexTypeEntryPtr &ctype, QXmlStreamAttributes *attributes) const { bool generate = true; @@ -2002,7 +2003,7 @@ bool TypeSystemParser::parseModifyDocumentation(const ConditionalStreamReader &, } // m_exceptionHandling -TypeSystemTypeEntry *TypeSystemParser::parseRootElement(const ConditionalStreamReader &, +TypeSystemTypeEntryPtr TypeSystemParser::parseRootElement(const ConditionalStreamReader &, const QVersionNumber &since, QXmlStreamAttributes *attributes) { @@ -2045,18 +2046,18 @@ TypeSystemTypeEntry *TypeSystemParser::parseRootElement(const ConditionalStreamR } if (m_defaultPackage.isEmpty()) { // Extending default, see addBuiltInContainerTypes() - auto *moduleEntry = const_cast<TypeSystemTypeEntry *>(m_context->db->defaultTypeSystemType()); - Q_ASSERT(moduleEntry); + auto moduleEntry = qSharedPointerConstCast<TypeSystemTypeEntry>(m_context->db->defaultTypeSystemType()); + Q_ASSERT(!moduleEntry.isNull()); m_defaultPackage = moduleEntry->name(); return moduleEntry; } - auto *moduleEntry = - const_cast<TypeSystemTypeEntry *>(m_context->db->findTypeSystemType(m_defaultPackage)); - const bool add = moduleEntry == nullptr; + auto moduleEntry = + qSharedPointerConstCast<TypeSystemTypeEntry>(m_context->db->findTypeSystemType(m_defaultPackage)); + const bool add = moduleEntry.isNull(); if (add) { - moduleEntry = new TypeSystemTypeEntry(m_defaultPackage, since, - currentParentTypeEntry()); + moduleEntry.reset(new TypeSystemTypeEntry(m_defaultPackage, since, + currentParentTypeEntry())); } moduleEntry->setCodeGeneration(m_generate); moduleEntry->setSnakeCase(snakeCase); @@ -2097,7 +2098,7 @@ bool TypeSystemParser::loadTypesystem(const ConditionalStreamReader &, bool TypeSystemParser::parseRejectEnumValue(const ConditionalStreamReader &, QXmlStreamAttributes *attributes) { - if (!m_currentEnum) { + if (m_currentEnum.isNull()) { m_error = u"<reject-enum-value> node must be used inside a <enum-type> node"_s; return false; } @@ -2169,9 +2170,9 @@ bool TypeSystemParser::parseCustomConversion(const ConditionalStreamReader &, return true; } - ValueTypeEntry *valueTypeEntry = nullptr; + ValueTypeEntryPtr valueTypeEntry; if (top->entry->isValue()) { - valueTypeEntry = static_cast<ValueTypeEntry *>(top->entry); + valueTypeEntry = qSharedPointerCast<ValueTypeEntry>(top->entry); if (valueTypeEntry->hasTargetConversionRule() || valueTypeEntry->hasCustomConversion()) { m_error = u"Types can have only one conversion rule"_s; return false; @@ -2205,11 +2206,11 @@ bool TypeSystemParser::parseCustomConversion(const ConditionalStreamReader &, CustomConversionPtr customConversion(new CustomConversion(top->entry)); if (top->entry->isPrimitive()) - static_cast<PrimitiveTypeEntry *>(top->entry)->setCustomConversion(customConversion); + qSharedPointerCast<PrimitiveTypeEntry>(top->entry)->setCustomConversion(customConversion); else if (top->entry->isContainer()) - static_cast<ContainerTypeEntry *>(top->entry)->setCustomConversion(customConversion); + qSharedPointerCast<ContainerTypeEntry>(top->entry)->setCustomConversion(customConversion); else if (top->entry->isValue()) - static_cast<ValueTypeEntry *>(top->entry)->setCustomConversion(customConversion); + qSharedPointerCast<ValueTypeEntry>(top->entry)->setCustomConversion(customConversion); customConversionsForReview.append(customConversion); return true; } @@ -2604,7 +2605,7 @@ bool TypeSystemParser::parseAddPyMethodDef(const ConditionalStreamReader &, m_error = u"add-pymethoddef requires at least a name and a function attribute"_s; return false; } - static_cast<ComplexTypeEntry *>(m_contextStack.top()->entry)->addPyMethodDef(def); + qSharedPointerCast<ComplexTypeEntry>(m_contextStack.top()->entry)->addPyMethodDef(def); return true; } @@ -2638,7 +2639,7 @@ bool TypeSystemParser::parseProperty(const ConditionalStreamReader &, StackEleme m_error = u"<property> element is missing required attibutes (name/type/get)."_s; return false; } - static_cast<ComplexTypeEntry *>(m_contextStack.top()->entry)->addProperty(property); + qSharedPointerCast<ComplexTypeEntry>(m_contextStack.top()->entry)->addProperty(property); return true; } @@ -2719,7 +2720,7 @@ bool TypeSystemParser::parseModifyFunction(const ConditionalStreamReader &reader // Child of global <function> const auto &top = m_contextStack.top(); if (originalSignature.isEmpty() && top->entry->isFunction()) { - auto f = static_cast<const FunctionTypeEntry *>(top->entry); + auto f = qSharedPointerCast<const FunctionTypeEntry>(top->entry); originalSignature = f->signatures().value(0); } @@ -2960,10 +2961,10 @@ bool TypeSystemParser::parseInjectCode(const ConditionalStreamReader &, } break; case StackElement::Root: - static_cast<TypeSystemTypeEntry *>(m_contextStack.top()->entry)->addCodeSnip(snip); + qSharedPointerCast<TypeSystemTypeEntry>(m_contextStack.top()->entry)->addCodeSnip(snip); break; default: - static_cast<ComplexTypeEntry *>(m_contextStack.top()->entry)->addCodeSnip(snip); + qSharedPointerCast<ComplexTypeEntry>(m_contextStack.top()->entry)->addCodeSnip(snip); break; } return true; @@ -2971,7 +2972,7 @@ bool TypeSystemParser::parseInjectCode(const ConditionalStreamReader &, bool TypeSystemParser::parseInclude(const ConditionalStreamReader &, StackElement topElement, - TypeEntry *entry, QXmlStreamAttributes *attributes) + const TypeEntryPtr &entry, QXmlStreamAttributes *attributes) { QString fileName; Include::IncludeType location = Include::IncludePath; @@ -3070,8 +3071,8 @@ bool TypeSystemParser::checkDuplicatedTypeEntry(const ConditionalStreamReader &r { if (t == StackElement::PrimitiveTypeEntry || t == StackElement::FunctionTypeEntry) return true; - const auto *duplicated = m_context->db->findType(name); - if (!duplicated || duplicated->isNamespace()) + const auto duplicated = m_context->db->findType(name); + if (duplicated.isNull() || duplicated->isNamespace()) return true; if (duplicated->isBuiltIn()) { qCWarning(lcShiboken, "%s", @@ -3202,8 +3203,8 @@ bool TypeSystemParser::startElement(const ConditionalStreamReader &reader, Stack // types (which we need to do in order to support fake meta objects) if (element != StackElement::PrimitiveTypeEntry && element != StackElement::FunctionTypeEntry) { - TypeEntry *tmp = m_context->db->findType(name); - if (tmp && !tmp->isNamespace()) + TypeEntryPtr tmp = m_context->db->findType(name); + if (!tmp.isNull() && !tmp->isNamespace()) qCWarning(lcShiboken).noquote().nospace() << "Duplicate type entry: '" << name << '\''; } @@ -3269,7 +3270,7 @@ bool TypeSystemParser::startElement(const ConditionalStreamReader &reader, Stack case StackElement::InterfaceTypeEntry: { if (!checkRootElement()) return false; - auto *ce = new ObjectTypeEntry(name, versionRange.since, currentParentTypeEntry()); + ComplexTypeEntryPtr ce(new ObjectTypeEntry(name, versionRange.since, currentParentTypeEntry())); top->entry = ce; applyCommonAttributes(reader, top->entry, &attributes); applyComplexTypeAttributes(reader, ce, &attributes); @@ -3475,8 +3476,7 @@ bool TypeSystemParser::startElement(const ConditionalStreamReader &reader, Stack m_error = msgMissingAttribute(nameAttribute()); return false; } - m_templateEntry = - new TemplateEntry(attributes.takeAt(nameIndex).value().toString()); + m_templateEntry.reset(new TemplateEntry(attributes.takeAt(nameIndex).value().toString())); } break; case StackElement::InsertTemplate: diff --git a/sources/shiboken6/ApiExtractor/typesystemparser_p.h b/sources/shiboken6/ApiExtractor/typesystemparser_p.h index 3dab6f1b7..7d47c31e4 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser_p.h +++ b/sources/shiboken6/ApiExtractor/typesystemparser_p.h @@ -6,6 +6,7 @@ #include "typesystem.h" #include "typedatabase.h" #include "typedatabase_p.h" +#include "typesystem_typedefs.h" #include "codesnip.h" #include <QtCore/QStack> @@ -120,7 +121,7 @@ struct StackElementContext FunctionModificationList functionMods; FieldModificationList fieldMods; DocModificationList docModifications; - TypeEntry *entry = nullptr; + TypeEntryPtr entry; int addedFunctionModificationIndex = -1; }; @@ -144,7 +145,7 @@ private: bool parseXml(ConditionalStreamReader &reader); bool setupSmartPointerInstantiations(); bool startElement(const ConditionalStreamReader &reader, StackElement element); - SmartPointerTypeEntry *parseSmartPointerEntry(const ConditionalStreamReader &, + SmartPointerTypeEntryPtr parseSmartPointerEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes); @@ -154,43 +155,44 @@ private: bool importFileElement(const QXmlStreamAttributes &atts); - const TypeEntry *currentParentTypeEntry() const; + TypeEntryCPtr currentParentTypeEntry() const; bool checkRootElement(); - bool applyCommonAttributes(const ConditionalStreamReader &reader, TypeEntry *type, + bool applyCommonAttributes(const ConditionalStreamReader &reader, + const TypeEntryPtr &type, QXmlStreamAttributes *attributes); - PrimitiveTypeEntry * + PrimitiveTypeEntryPtr parsePrimitiveTypeEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *); - CustomTypeEntry * + CustomTypeEntryPtr parseCustomTypeEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *); - ContainerTypeEntry * + ContainerTypeEntryPtr parseContainerTypeEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *); - EnumTypeEntry * + EnumTypeEntryPtr parseEnumTypeEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *); - FlagsTypeEntry * - parseFlagsEntry(const ConditionalStreamReader &, EnumTypeEntry *enumEntry, + FlagsTypeEntryPtr + parseFlagsEntry(const ConditionalStreamReader &, const EnumTypeEntryPtr &enumEntry, QString flagName, const QVersionNumber &since, QXmlStreamAttributes *); - NamespaceTypeEntry * + NamespaceTypeEntryPtr parseNamespaceTypeEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *attributes); - ValueTypeEntry * + ValueTypeEntryPtr parseValueTypeEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *); - FunctionTypeEntry * + FunctionTypeEntryPtr parseFunctionTypeEntry(const ConditionalStreamReader &, const QString &name, const QVersionNumber &since, QXmlStreamAttributes *); - TypedefEntry * + TypedefEntryPtr parseTypedefEntry(const ConditionalStreamReader &, const QString &name, StackElement topElement, const QVersionNumber &since, QXmlStreamAttributes *); - void applyComplexTypeAttributes(const ConditionalStreamReader &, ComplexTypeEntry *ctype, + void applyComplexTypeAttributes(const ConditionalStreamReader &, const ComplexTypeEntryPtr &ctype, QXmlStreamAttributes *) const; bool parseRenameFunction(const ConditionalStreamReader &, QString *name, QXmlStreamAttributes *); @@ -198,7 +200,7 @@ private: QXmlStreamAttributes *); bool parseModifyDocumentation(const ConditionalStreamReader &, StackElement topElement, QXmlStreamAttributes *); - TypeSystemTypeEntry * + TypeSystemTypeEntryPtr parseRootElement(const ConditionalStreamReader &, const QVersionNumber &since, QXmlStreamAttributes *); bool loadTypesystem(const ConditionalStreamReader &, QXmlStreamAttributes *); @@ -237,7 +239,7 @@ private: bool readFileSnippet(QXmlStreamAttributes *attributes, CodeSnip *snip); bool parseInjectCode(const ConditionalStreamReader &, StackElement topElement, QXmlStreamAttributes *); bool parseInclude(const ConditionalStreamReader &, StackElement topElement, - TypeEntry *entry, QXmlStreamAttributes *); + const TypeEntryPtr &entry, QXmlStreamAttributes *); bool parseSystemInclude(const ConditionalStreamReader &, QXmlStreamAttributes *); TemplateInstance *parseInsertTemplate(const ConditionalStreamReader &, StackElement topElement, @@ -260,9 +262,9 @@ private: QString m_error; const TypeEntry::CodeGeneration m_generate; - EnumTypeEntry *m_currentEnum = nullptr; + EnumTypeEntryPtr m_currentEnum; TemplateInstancePtr m_templateInstance; - TemplateEntry *m_templateEntry = nullptr; + TemplateEntryPtr m_templateEntry; ContextStack m_contextStack; QString m_currentSignature; diff --git a/sources/shiboken6/ApiExtractor/typesystemtypeentry.h b/sources/shiboken6/ApiExtractor/typesystemtypeentry.h index a861381b1..bd69058d2 100644 --- a/sources/shiboken6/ApiExtractor/typesystemtypeentry.h +++ b/sources/shiboken6/ApiExtractor/typesystemtypeentry.h @@ -12,7 +12,7 @@ class TypeSystemTypeEntry : public TypeEntry { public: explicit TypeSystemTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); TypeEntry *clone() const override; diff --git a/sources/shiboken6/ApiExtractor/valuetypeentry.h b/sources/shiboken6/ApiExtractor/valuetypeentry.h index 5ad060d4c..97bc26803 100644 --- a/sources/shiboken6/ApiExtractor/valuetypeentry.h +++ b/sources/shiboken6/ApiExtractor/valuetypeentry.h @@ -11,7 +11,7 @@ class ValueTypeEntry : public ComplexTypeEntry { public: explicit ValueTypeEntry(const QString &entryName, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); bool hasCustomConversion() const; void setCustomConversion(const CustomConversionPtr &customConversion); @@ -33,7 +33,7 @@ public: protected: explicit ValueTypeEntry(const QString &entryName, Type t, const QVersionNumber &vr, - const TypeEntry *parent); + const TypeEntryCPtr &parent); explicit ValueTypeEntry(ComplexTypeEntryPrivate *d); }; |