From f499c71c3b3f78920be192d35df7e2c8d18e2f1b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 11 Nov 2022 09:38:22 +0100 Subject: shiboken6: Use smart pointers for the TypeEntry classes TypeEntry instances were previously stored and passed as raw pointers, which made it difficult to track ownership, particularly when synthesized classes were added. Change it to use QSharedPointer. Change-Id: I3612efbc5d467ebeac9aa5dda86c7439bbd03ddd Reviewed-by: Christian Tismer Reviewed-by: Shyamnath Premnadh --- .../shiboken6/ApiExtractor/abstractmetabuilder.cpp | 157 +++++++------ .../shiboken6/ApiExtractor/abstractmetabuilder.h | 5 +- .../ApiExtractor/abstractmetabuilder_helpers.cpp | 10 +- .../shiboken6/ApiExtractor/abstractmetabuilder_p.h | 6 +- .../shiboken6/ApiExtractor/abstractmetaenum.cpp | 6 +- sources/shiboken6/ApiExtractor/abstractmetaenum.h | 5 +- .../ApiExtractor/abstractmetafunction.cpp | 9 +- .../shiboken6/ApiExtractor/abstractmetafunction.h | 4 +- .../shiboken6/ApiExtractor/abstractmetalang.cpp | 29 +-- sources/shiboken6/ApiExtractor/abstractmetalang.h | 14 +- .../shiboken6/ApiExtractor/abstractmetatype.cpp | 29 +-- sources/shiboken6/ApiExtractor/abstractmetatype.h | 9 +- sources/shiboken6/ApiExtractor/apiextractor.cpp | 43 ++-- sources/shiboken6/ApiExtractor/apiextractor.h | 3 +- .../shiboken6/ApiExtractor/apiextractorresult.cpp | 10 +- .../shiboken6/ApiExtractor/apiextractorresult.h | 6 +- .../ApiExtractor/apiextractorresultdata_p.h | 3 +- sources/shiboken6/ApiExtractor/arraytypeentry.h | 8 +- sources/shiboken6/ApiExtractor/codesnip.cpp | 4 +- sources/shiboken6/ApiExtractor/complextypeentry.h | 8 +- .../ApiExtractor/constantvaluetypeentry.h | 2 +- .../shiboken6/ApiExtractor/containertypeentry.h | 2 +- .../shiboken6/ApiExtractor/customconversion.cpp | 18 +- sources/shiboken6/ApiExtractor/customconversion.h | 14 +- sources/shiboken6/ApiExtractor/customtypenentry.h | 2 +- sources/shiboken6/ApiExtractor/docparser.cpp | 2 +- sources/shiboken6/ApiExtractor/enumtypeentry.h | 12 +- .../shiboken6/ApiExtractor/enumvaluetypeentry.h | 6 +- sources/shiboken6/ApiExtractor/flagstypeentry.h | 6 +- sources/shiboken6/ApiExtractor/functiontypeentry.h | 2 +- sources/shiboken6/ApiExtractor/messages.cpp | 24 +- sources/shiboken6/ApiExtractor/messages.h | 24 +- .../shiboken6/ApiExtractor/namespacetypeentry.h | 7 +- sources/shiboken6/ApiExtractor/objecttypeentry.h | 2 +- .../shiboken6/ApiExtractor/primitivetypeentry.h | 11 +- sources/shiboken6/ApiExtractor/propertyspec.cpp | 2 +- sources/shiboken6/ApiExtractor/propertyspec.h | 4 +- sources/shiboken6/ApiExtractor/qtdocparser.cpp | 2 +- .../shiboken6/ApiExtractor/smartpointertypeentry.h | 6 +- .../shiboken6/ApiExtractor/templateargumententry.h | 2 +- .../ApiExtractor/tests/testcodeinjection.cpp | 2 +- .../shiboken6/ApiExtractor/tests/testcontainer.cpp | 2 +- .../ApiExtractor/tests/testconversionruletag.cpp | 18 +- sources/shiboken6/ApiExtractor/tests/testenum.cpp | 6 +- .../ApiExtractor/tests/testextrainclude.cpp | 4 +- .../ApiExtractor/tests/testfunctiontag.cpp | 10 +- .../ApiExtractor/tests/testinserttemplate.cpp | 5 +- .../ApiExtractor/tests/testnestedtypes.cpp | 8 +- .../ApiExtractor/tests/testprimitivetypetag.cpp | 4 +- .../ApiExtractor/tests/testresolvetype.cpp | 8 +- .../shiboken6/ApiExtractor/tests/testtemplates.cpp | 8 +- .../ApiExtractor/tests/testtyperevision.cpp | 4 +- sources/shiboken6/ApiExtractor/typedatabase.cpp | 256 ++++++++++----------- sources/shiboken6/ApiExtractor/typedatabase.h | 45 ++-- sources/shiboken6/ApiExtractor/typedatabase_p.h | 5 +- .../shiboken6/ApiExtractor/typedatabase_typedefs.h | 10 +- sources/shiboken6/ApiExtractor/typedefentry.h | 10 +- sources/shiboken6/ApiExtractor/typesystem.cpp | 227 +++++++++--------- sources/shiboken6/ApiExtractor/typesystem.h | 33 ++- .../shiboken6/ApiExtractor/typesystem_typedefs.h | 56 ++++- .../shiboken6/ApiExtractor/typesystemparser.cpp | 160 ++++++------- .../shiboken6/ApiExtractor/typesystemparser_p.h | 40 ++-- .../shiboken6/ApiExtractor/typesystemtypeentry.h | 2 +- sources/shiboken6/ApiExtractor/valuetypeentry.h | 4 +- sources/shiboken6/generator/generator.cpp | 26 +-- sources/shiboken6/generator/generator.h | 6 +- .../shiboken6/generator/qtdoc/qtdocgenerator.cpp | 4 +- sources/shiboken6/generator/qtdoc/qtdocgenerator.h | 2 +- .../shiboken6/generator/shiboken/cppgenerator.cpp | 158 ++++++------- .../shiboken6/generator/shiboken/cppgenerator.h | 21 +- .../generator/shiboken/cppgenerator_container.cpp | 2 +- .../generator/shiboken/generatorargument.cpp | 2 +- .../generator/shiboken/headergenerator.cpp | 34 ++- .../shiboken6/generator/shiboken/headergenerator.h | 2 +- .../shiboken6/generator/shiboken/overloaddata.cpp | 10 +- .../generator/shiboken/shibokengenerator.cpp | 94 ++++---- .../generator/shiboken/shibokengenerator.h | 34 +-- 77 files changed, 952 insertions(+), 888 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 &AbstractMetaBuilder::typeEntryToEnumsHash() const +const QHash &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(entry); + auto centry = qSharedPointerCast(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(entry); + auto fte = qSharedPointerCast(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(entry); + const auto enumEntry = qSharedPointerCast(entry); AbstractMetaClass *cls = AbstractMetaClass::findClass(m_metaClasses, enumEntry->parent()); @@ -828,11 +828,11 @@ std::optional { 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 metaEnum.setHasQEnumsDeclaration(true); } - auto *enumTypeEntry = static_cast(typeEntry); + auto enumTypeEntry = qSharedPointerCast(typeEntry); metaEnum.setTypeEntry(enumTypeEntry); metaEnum.setAccess(enumItem->accessPolicy()); if (metaEnum.access() == Access::Private) @@ -916,10 +916,9 @@ std::optional 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(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 // ), 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(ste)); - auto *templateArg = new TemplateArgumentEntry(u"T"_s, ste->version(), - typeSystemTypeEntry(ste)); + result->setTypeEntry(qSharedPointerConstCast(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 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 return {}; } - const TypeEntry *type = types.constFirst(); + TypeEntryCPtr type = types.constFirst(); const TypeEntry::Type typeEntryType = type->type(); AbstractMetaType metaType; @@ -2652,7 +2657,7 @@ std::optional 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 type = instantiationType; } else { auto it = std::find_if(types.cbegin(), types.cend(), - [instantiationType](const TypeEntry *e) { - auto smartPtr = static_cast(e); + [instantiationType](const TypeEntryCPtr &e) { + auto smartPtr = qSharedPointerCast(e); return smartPtr->matchesInstantiation(instantiationType); }); if (it == types.cend()) { @@ -2838,7 +2843,7 @@ QString AbstractMetaBuilderPrivate::fixDefaultValue(QString expr, const Abstract // "QList()" -> "QList()" if (type.instantiations().size() != 1) return expr; // Only simple types are handled, not QMap. - 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 returned.setOriginalTemplateType(metaType); if (returned.typeEntry()->isTemplateArgument()) { - const auto *tae = static_cast(returned.typeEntry()); + const auto tae = qSharedPointerCast(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 } 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 Matrix" 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 static bool addClassDependency(const QList &classList, - const TypeEntry *typeEntry, + const TypeEntryCPtr &typeEntry, MetaClass *clazz, Graph *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 &typeEntryToEnumsHash() const; + const QHash &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(typeEntry); + flagsTypeEntry = qSharedPointerCast(typeEntry); enumTypeEntry = flagsTypeEntry->originator(); } else { Q_ASSERT(typeEntry->isEnum()); - enumTypeEntry = static_cast(typeEntry); + enumTypeEntry = qSharedPointerCast(typeEntry); } // Use the enum's qualified name (would otherwise be "QFlags") 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 m_enums; + QHash m_enums; QList 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 #include @@ -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(d->m_typeEntry); + const auto nte = qSharedPointerCast(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 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 &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 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 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(d->m_typeEntry); + const auto cte = qSharedPointerCast(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(m_typeEntry); + auto containerTypeEntry = qSharedPointerCast(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 #include @@ -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 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 m_synthesizedTypeEntries; }; struct ApiExtractorPrivate @@ -312,7 +311,6 @@ std::optional 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(smp.smartPointer->typeEntry()); + const auto ste = qSharedPointerCast(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(type)->codeSnips()); + getCode(code, qSharedPointerCast(type)->codeSnips()); else if (type->isTypeSystem()) - getCode(code, static_cast(type)->codeSnips()); + getCode(code, qSharedPointerCast(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 #include @@ -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 ApiExtractorResult::findAbstractMetaEnum(const TypeEntry *typeEntry) const +std::optional + ApiExtractorResult::findAbstractMetaEnum(TypeEntryCPtr typeEntry) const { - if (typeEntry && typeEntry->isFlags()) - typeEntry = static_cast(typeEntry)->originator(); + if (!typeEntry.isNull() && typeEntry->isFlags()) + typeEntry = qSharedPointerCast(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 @@ -44,14 +45,15 @@ public: const InstantiatedSmartPointers &instantiatedSmartPointers() const; // Query functions for the generators - std::optional findAbstractMetaEnum(const TypeEntry *typeEntry) const; + std::optional + 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 m_enums; - QList m_synthesizedTypeEntries; // not exposed, just for ownership + QHash 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" 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(m_sourceType); + const auto cte = qSharedPointerCast(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(type)->customConversion(); + return qSharedPointerCast(type)->customConversion(); if (type->isContainer()) - return static_cast(type)->customConversion(); + return qSharedPointerCast(type)->customConversion(); if (type->isValue()) - return static_cast(type)->customConversion(); + return qSharedPointerCast(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; 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 #include @@ -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" with name "Alignment" // to "Qt::Alignment" as seen by qdoc. - const auto *flagsEntry = static_cast(metaType.typeEntry()); + const auto flagsEntry = qSharedPointerCast(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(classA->typeEntry()); + auto vte = qSharedPointerCast(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(baseContainer)->containerKind(), + QCOMPARE(reinterpret_cast(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(typeEntry); + auto vte = qSharedPointerCast(typeEntry); QVERIFY(vte->hasTargetConversionRule()); QCOMPARE(vte->targetConversionRule(), QLatin1String(conversionData)); } @@ -87,8 +87,8 @@ void TestConversionRuleTag::testConversionRuleTagReplace() QScopedPointer 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(classA->typeEntry()); + auto vte = qSharedPointerCast(classA->typeEntry()); QVERIFY(vte->hasCustomConversion()); auto conversion = vte->customConversion(); @@ -218,8 +218,8 @@ void TestConversionRuleTag::testConversionRuleTagWithInsertTemplate() QScopedPointer 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 enumTypeEntries{ - static_cast(namespaceEnums.at(0).typeEntry()), - static_cast(namespaceEnums.at(1).typeEntry())}; + QList enumTypeEntries{ + qSharedPointerCast(namespaceEnums.at(0).typeEntry()), + qSharedPointerCast(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 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 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 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 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(int32TEntry); - auto *basicType = int32T->basicReferencedTypeEntry(); + auto int32T = qSharedPointerCast(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 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"_s)); @@ -418,8 +418,8 @@ typedef Vector IntVector; auto *vector = AbstractMetaClass::findClass(classes, u"IntVector"); QVERIFY(vector); auto baseContainer = vector->typeEntry()->baseContainerType(); - QVERIFY(baseContainer); - QCOMPARE(reinterpret_cast(baseContainer)->containerKind(), + QVERIFY(!baseContainer.isNull()); + QCOMPARE(reinterpret_cast(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 TypeEntryCList findTypesHelper(const QString &name, Predicate pred) const; template - QList findTypesByTypeHelper(Predicate pred) const; - TypeEntry *resolveTypeDefEntry(TypedefEntry *typedefEntry, QString *errorMessage); + QList > findTypesByTypeHelper(Predicate pred) const; + TypeEntryPtr resolveTypeDefEntry(const TypedefEntryPtr &typedefEntry, QString *errorMessage); template bool isSuppressedWarningHelper(const String &s) const; bool resolveSmartPointerInstantiations(const TypeDatabaseParserContextPtr &context); @@ -146,7 +146,7 @@ struct TypeDatabasePrivate TypedefEntryMap m_typedefEntries; TemplateEntryMap m_templates; QList m_suppressedWarnings; - QList m_typeSystemEntries; // maintain order, default is first. + QList 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(type_entry); - return nullptr; + return qSharedPointerCast(type_entry); + return {}; } -static bool inline useType(const TypeEntry *t) +static bool inline useType(const TypeEntryCPtr &t) { return !t->isPrimitive() - || static_cast(t)->preferredTargetLangType(); + || qSharedPointerCast(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(entry); + return qSharedPointerCast(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 @@ -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 -QList TypeDatabasePrivate::findTypesByTypeHelper(Predicate pred) const +QList > TypeDatabasePrivate::findTypesByTypeHelper(Predicate pred) const { - QList result; - for (auto *entry : m_entries) { + QList > result; + for (const auto &entry : m_entries) { if (pred(entry)) - result.append(static_cast(entry)); + result.append(qSharedPointerCast(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(pred); } ContainerTypeEntryCList TypeDatabase::containerTypes() const { - auto pred = [](const TypeEntry *t) { return t->isContainer(); }; + auto pred = [](const TypeEntryCPtr &t) { return t->isContainer(); }; return d->findTypesByTypeHelper(pred); } SmartPointerTypeEntryList TypeDatabase::smartPointerTypes() const { - auto pred = [](const TypeEntry *t) { return t->isSmartPointer(); }; + auto pred = [](const TypeEntryCPtr &t) { return t->isSmartPointer(); }; return d->findTypesByTypeHelper(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(e); - Q_ASSERT(source); + source = qSharedPointerDynamicCast(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(source->clone()); + ComplexTypeEntryPtr result(static_cast(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(e), errorMessage); - if (Q_UNLIKELY(!e)) + e = resolveTypeDefEntry(qSharedPointerCast(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(fte); + return qSharedPointerCast(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(entry); + auto pe = qSharedPointerCast(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(entry); + return qSharedPointerCast(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(entry); + for (const auto &entry : entries) { + if (!entry.isNull() && entry->isObject() && useType(entry)) + return qSharedPointerCast(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(entry)); + result.append(qSharedPointerCast(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; -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 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(e); - auto *basic = basicReferencedTypeEntry(pe); + auto pe = qSharedPointerCast(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(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(sbkCharEntry); - - auto *pyBoolCustomEntry = static_cast(pyBoolEntry); + auto pyLongEntry = findType(u"PyLong"_s); + Q_ASSERT(!pyLongEntry.isNull() && pyLongEntry->isCustom()); + auto pyLongCustomEntry = qSharedPointerCast(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(sbkCharEntry); + + auto pyBoolCustomEntry = qSharedPointerCast(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(pyFloatEntry); + auto pyFloatEntry = findType(u"PyFloat"_s); + Q_ASSERT(!pyFloatEntry.isNull() && pyFloatEntry->isCustom()); + auto pyFloatCustomEntry = qSharedPointerCast(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(pyUnicodeEntry); + auto pyUnicodeEntry = findType(u"PyUnicode"_s); + Q_ASSERT(!pyUnicodeEntry.isNull() && pyUnicodeEntry->isCustom()); + auto pyUnicodeCustomEntry = qSharedPointerCast(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 #include class TypeDatabase; -class SmartPointerTypeEntry; struct TypeDatabaseParserContext { - using SmartPointerInstantiations = QHash; + using SmartPointerInstantiations = QHash; 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 #include -using TemplateEntryMap =QMap; +using TemplateEntryMap =QMap; template 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; -using TypeEntryMultiMapConstIteratorRange = QMultiMapConstIteratorRange; +using TypeEntryMultiMap = QMultiMap; +using TypeEntryMultiMapConstIteratorRange = QMultiMapConstIteratorRange; -using TypeEntryMap = QMap; -using TypedefEntryMap = QMap; +using TypeEntryMap = QMap; +using TypedefEntryMap = QMap; #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(e); + return qSharedPointerCast(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 parents; + QVarLengthArray 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(p)->isInlineNamespace()) { + && qSharedPointerCast(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(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(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 #include @@ -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 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 +#include +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; -using NamespaceTypeEntryList = QList; -using PrimitiveTypeEntryCList = QList; -using SmartPointerTypeEntryList = QList; -using TypeEntryList = QList; -using TypeEntryCList = QList; +using ArrayTypeEntryPtr = QSharedPointer; +using ComplexTypeEntryPtr = QSharedPointer; +using ConstantValueTypeEntryPtr = QSharedPointer; +using ContainerTypeEntryPtr = QSharedPointer; +using CustomTypeEntryPtr = QSharedPointer; +using EnumTypeEntryPtr = QSharedPointer; +using EnumValueTypeEntryPtr = QSharedPointer; +using FlagsTypeEntryPtr = QSharedPointer; +using FunctionTypeEntryPtr = QSharedPointer; +using NamespaceTypeEntryPtr = QSharedPointer; +using ObjectTypeEntryPtr = QSharedPointer; +using PrimitiveTypeEntryPtr = QSharedPointer; +using SmartPointerTypeEntryPtr = QSharedPointer; +using TemplateEntryPtr = QSharedPointer; +using TypeEntryPtr = QSharedPointer; +using TypedefEntryPtr = QSharedPointer; +using TypeSystemTypeEntryPtr = QSharedPointer; +using ValueTypeEntryPtr = QSharedPointer; + +using ArrayTypeEntryCPtr = QSharedPointer; +using ComplexTypeEntryCPtr = QSharedPointer; +using ConstantValueTypeEntryCPtr = QSharedPointer; +using ContainerTypeEntryCPtr = QSharedPointer; +using CustomTypeEntryCPtr = QSharedPointer; +using EnumTypeEntryCPtr = QSharedPointer; +using EnumValueTypeEntryCPtr = QSharedPointer; +using FlagsTypeEntryCPtr = QSharedPointer; +using FunctionTypeEntryCPtr = QSharedPointer; +using NamespaceTypeEntryCPtr = QSharedPointer; +using ObjectTypeEntryCPtr = QSharedPointer; +using PrimitiveTypeEntryCPtr = QSharedPointer; +using SmartPointerTypeEntryCPtr = QSharedPointer; +using TemplateEntryCPtr = QSharedPointer; +using TypeEntryCPtr = QSharedPointer; +using TypedefEntryCPtr = QSharedPointer; +using TypeSystemTypeEntryCPtr = QSharedPointer; +using ValueTypeEntryCPtr = QSharedPointer; + +using ContainerTypeEntryCList = QList; +using NamespaceTypeEntryList = QList; +using PrimitiveTypeEntryCList = QList; +using SmartPointerTypeEntryList = QList; +using TypeEntryList = QList; +using TypeEntryCList = QList; #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(top->entry)->codeSnips()); + purgeEmptyCodeSnips(&qSharedPointerCast(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(top->entry); + auto centry = qSharedPointerCast(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(top->entry)->target(); + auto centry = qSharedPointerCast(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(top->entry); + auto cte = qSharedPointerCast(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(top->entry)->codeSnips().last(); + return &qSharedPointerCast(top->entry)->codeSnips().last(); case ParserState::TypeSystemCodeInjection: Q_ASSERT(top->entry->isTypeSystem()); - return &static_cast(top->entry)->codeSnips().last(); + return &qSharedPointerCast(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(e)); + type->setTargetLangApiType(qSharedPointerCast(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 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(existingType); + auto result = qSharedPointerCast(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(m_context->db->defaultTypeSystemType()); - Q_ASSERT(moduleEntry); + auto moduleEntry = qSharedPointerConstCast(m_context->db->defaultTypeSystemType()); + Q_ASSERT(!moduleEntry.isNull()); m_defaultPackage = moduleEntry->name(); return moduleEntry; } - auto *moduleEntry = - const_cast(m_context->db->findTypeSystemType(m_defaultPackage)); - const bool add = moduleEntry == nullptr; + auto moduleEntry = + qSharedPointerConstCast(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" node must be used inside a 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(top->entry); + valueTypeEntry = qSharedPointerCast(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(top->entry)->setCustomConversion(customConversion); + qSharedPointerCast(top->entry)->setCustomConversion(customConversion); else if (top->entry->isContainer()) - static_cast(top->entry)->setCustomConversion(customConversion); + qSharedPointerCast(top->entry)->setCustomConversion(customConversion); else if (top->entry->isValue()) - static_cast(top->entry)->setCustomConversion(customConversion); + qSharedPointerCast(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(m_contextStack.top()->entry)->addPyMethodDef(def); + qSharedPointerCast(m_contextStack.top()->entry)->addPyMethodDef(def); return true; } @@ -2638,7 +2639,7 @@ bool TypeSystemParser::parseProperty(const ConditionalStreamReader &, StackEleme m_error = u" element is missing required attibutes (name/type/get)."_s; return false; } - static_cast(m_contextStack.top()->entry)->addProperty(property); + qSharedPointerCast(m_contextStack.top()->entry)->addProperty(property); return true; } @@ -2719,7 +2720,7 @@ bool TypeSystemParser::parseModifyFunction(const ConditionalStreamReader &reader // Child of global const auto &top = m_contextStack.top(); if (originalSignature.isEmpty() && top->entry->isFunction()) { - auto f = static_cast(top->entry); + auto f = qSharedPointerCast(top->entry); originalSignature = f->signatures().value(0); } @@ -2960,10 +2961,10 @@ bool TypeSystemParser::parseInjectCode(const ConditionalStreamReader &, } break; case StackElement::Root: - static_cast(m_contextStack.top()->entry)->addCodeSnip(snip); + qSharedPointerCast(m_contextStack.top()->entry)->addCodeSnip(snip); break; default: - static_cast(m_contextStack.top()->entry)->addCodeSnip(snip); + qSharedPointerCast(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 @@ -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); }; diff --git a/sources/shiboken6/generator/generator.cpp b/sources/shiboken6/generator/generator.cpp index 5975e54e6..b1accb74b 100644 --- a/sources/shiboken6/generator/generator.cpp +++ b/sources/shiboken6/generator/generator.cpp @@ -177,7 +177,7 @@ void Generator::setOutputDirectory(const QString &outDir) bool Generator::generateFileForContext(const GeneratorContext &context) { const AbstractMetaClass *cls = context.metaClass(); - auto *typeEntry = cls->typeEntry(); + auto typeEntry = cls->typeEntry(); if (!shouldGenerate(typeEntry)) return true; @@ -233,14 +233,14 @@ bool Generator::generate() for (auto cls : m_d->api.classes()) { if (!generateFileForContext(contextForClass(cls))) return false; - auto *te = cls->typeEntry(); + auto te = cls->typeEntry(); if (shouldGenerate(te) && te->isPrivate()) m_d->m_hasPrivateClasses = true; } for (const auto &smp: m_d->api.instantiatedSmartPointers()) { const AbstractMetaClass *pointeeClass = nullptr; - const auto *instantiatedType = smp.type.instantiations().constFirst().typeEntry(); + const auto instantiatedType = smp.type.instantiations().constFirst().typeEntry(); if (instantiatedType->isComplex()) // not a C++ primitive pointeeClass = AbstractMetaClass::findClass(m_d->api.classes(), instantiatedType); if (!generateFileForContext(contextForSmartPointer(smp.specialized, smp.type, @@ -251,7 +251,7 @@ bool Generator::generate() return finishGeneration(); } -bool Generator::shouldGenerate(const TypeEntry *typeEntry) const +bool Generator::shouldGenerate(const TypeEntryCPtr &typeEntry) const { return typeEntry->shouldGenerate(); } @@ -276,11 +276,11 @@ bool Generator::avoidProtectedHack() const return m_d->m_avoidProtectedHack; } -QString Generator::getFullTypeName(const TypeEntry *type) +QString Generator::getFullTypeName(TypeEntryCPtr type) { QString result = type->qualifiedCppName(); if (type->isArray()) - type = static_cast(type)->nestedTypeEntry(); + type = qSharedPointerCast(type)->nestedTypeEntry(); if (!isCppPrimitive(type)) result.prepend(u"::"_s); return result; @@ -365,7 +365,7 @@ std::optional return minimalConstructor(api, type.typeEntry()); if (type.typeEntry()->isComplex()) { - auto cType = static_cast(type.typeEntry()); + auto cType = qSharedPointerCast(type.typeEntry()); if (cType->hasDefaultConstructor()) return DefaultValue(DefaultValue::Custom, cType->defaultConstructor()); auto klass = AbstractMetaClass::findClass(api.classes(), cType); @@ -390,7 +390,7 @@ std::optional std::optional Generator::minimalConstructor(const ApiExtractorResult &api, - const TypeEntry *type, + const TypeEntryCPtr &type, QString *errorString) { if (!type) @@ -404,8 +404,8 @@ std::optional } if (type->isEnum()) { - const auto enumEntry = static_cast(type); - if (const auto *nullValue = enumEntry->nullValue()) + const auto enumEntry = qSharedPointerCast(type); + if (const auto nullValue = enumEntry->nullValue(); !nullValue.isNull()) return DefaultValue(DefaultValue::Enum, nullValue->name()); return DefaultValue(DefaultValue::Custom, u"static_cast< ::"_s + type->qualifiedCppName() @@ -418,7 +418,7 @@ std::optional } if (type->isPrimitive()) { - QString ctor = static_cast(type)->defaultConstructor(); + QString ctor = qSharedPointerCast(type)->defaultConstructor(); // If a non-C++ (i.e. defined by the user) primitive type does not have // a default constructor defined by the user, the empty constructor is // heuristically returned. If this is wrong the build of the generated @@ -461,7 +461,7 @@ std::optional if (!metaClass) return {}; - auto cType = static_cast(metaClass->typeEntry()); + auto cType = qSharedPointerCast(metaClass->typeEntry()); if (cType->hasDefaultConstructor()) return DefaultValue(DefaultValue::Custom, cType->defaultConstructor()); @@ -489,7 +489,7 @@ std::optional for (qsizetype i = 0, size = arguments.size(); suitable && i < size && !arguments.at(i).hasOriginalDefaultValueExpression(); ++i) { const AbstractMetaArgument &arg = arguments.at(i); - const TypeEntry *aType = arg.type().typeEntry(); + TypeEntryCPtr aType = arg.type().typeEntry(); suitable &= aType != cType; simple &= isCppPrimitive(aType) || aType->isEnum() || arg.type().isPointer(); } diff --git a/sources/shiboken6/generator/generator.h b/sources/shiboken6/generator/generator.h index 34ab84a37..8bfbb49ad 100644 --- a/sources/shiboken6/generator/generator.h +++ b/sources/shiboken6/generator/generator.h @@ -130,7 +130,7 @@ protected: static QString getFileNameBaseForSmartPointer(const AbstractMetaType &smartPointerType); /// Returns true if the generator should generate any code for the AbstractMetaClass. - virtual bool shouldGenerate(const TypeEntry *t) const; + virtual bool shouldGenerate(const TypeEntryCPtr &t) const; /** * Translate metatypes to binding source format. @@ -151,7 +151,7 @@ protected: static QString packageName(); // Returns the full name of the type. - static QString getFullTypeName(const TypeEntry *type); + static QString getFullTypeName(TypeEntryCPtr type); static QString getFullTypeName(const AbstractMetaType &type); static QString getFullTypeName(const AbstractMetaClass *metaClass); @@ -168,7 +168,7 @@ protected: * Returns a null string if it fails. */ static std::optional - minimalConstructor(const ApiExtractorResult &api, const TypeEntry *type, + minimalConstructor(const ApiExtractorResult &api, const TypeEntryCPtr &type, QString *errorString = nullptr); static std::optional minimalConstructor(const ApiExtractorResult &api, const AbstractMetaType &type, diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp index 61f736e74..dee776cd4 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.cpp @@ -85,7 +85,7 @@ static bool functionSort(const AbstractMetaFunctionCPtr &func1, const AbstractMe return func1->name() < func2->name(); } -static inline QVersionNumber versionOf(const TypeEntry *te) +static inline QVersionNumber versionOf(const TypeEntryCPtr &te) { if (te) { const auto version = te->version(); @@ -108,7 +108,7 @@ QString QtDocGenerator::fileNameSuffix() return u".rst"_s; } -bool QtDocGenerator::shouldGenerate(const TypeEntry *te) const +bool QtDocGenerator::shouldGenerate(const TypeEntryCPtr &te) const { return Generator::shouldGenerate(te) && te->type() != TypeEntry::SmartPointerType; diff --git a/sources/shiboken6/generator/qtdoc/qtdocgenerator.h b/sources/shiboken6/generator/qtdoc/qtdocgenerator.h index 08a359322..1c82610a2 100644 --- a/sources/shiboken6/generator/qtdoc/qtdocgenerator.h +++ b/sources/shiboken6/generator/qtdoc/qtdocgenerator.h @@ -44,7 +44,7 @@ public: QtXmlToSphinxLink resolveLink(const QtXmlToSphinxLink &) const override; protected: - bool shouldGenerate(const TypeEntry *) const override; + bool shouldGenerate(const TypeEntryCPtr &) const override; static QString fileNameSuffix(); QString fileNameForContext(const GeneratorContext &context) const override; void generateClass(TextStream &ts, const GeneratorContext &classContext) override; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index fbe7f183e..47fb271f9 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -186,9 +186,9 @@ const ProtocolEntries &sequenceProtocols() // Return name of function to create PyObject wrapping a container static QString opaqueContainerCreationFunc(const AbstractMetaType &type) { - const auto *containerTypeEntry = - static_cast(type.typeEntry()); - const auto *instantiationTypeEntry = + const auto containerTypeEntry = + qSharedPointerCast(type.typeEntry()); + const auto instantiationTypeEntry = type.instantiations().constFirst().typeEntry(); QString result = u"create"_s; if (type.isConstant()) @@ -284,9 +284,9 @@ QList CppGenerator::BoolCastFunctionOptional CppGenerator::boolCast(const AbstractMetaClass *metaClass) const { - const auto *te = metaClass->typeEntry(); + const auto te = metaClass->typeEntry(); if (te->isSmartPointer()) { - auto *ste = static_cast(te); + auto ste = qSharedPointerCast(te); auto valueCheckMethod = ste->valueCheckMethod(); if (!valueCheckMethod.isEmpty()) { @@ -324,8 +324,8 @@ CppGenerator::BoolCastFunctionOptional } std::optional - CppGenerator::findSmartPointerInstantiation(const SmartPointerTypeEntry *pointer, - const TypeEntry *pointee) const + CppGenerator::findSmartPointerInstantiation(const SmartPointerTypeEntryCPtr &pointer, + const TypeEntryCPtr &pointee) const { for (const auto &smp : api().instantiatedSmartPointers()) { const auto &i = smp.type; @@ -472,7 +472,7 @@ static bool _shouldInheritInt(const AbstractMetaEnum &cppEnum) static QString BuildEnumFlagInfo(const AbstractMetaEnum &cppEnum) { - auto *enumType = cppEnum.typeEntry(); + auto enumType = cppEnum.typeEntry(); QString result = _plainName(enumType->name()); auto flags = enumType->flags(); auto decision = enumType->pythonEnumType(); @@ -503,7 +503,7 @@ static bool generateRichComparison(const GeneratorContext &c) { auto *metaClass = c.metaClass(); if (c.forSmartPointer()) { - auto *te = static_cast(metaClass->typeEntry()); + auto te = qSharedPointerCast(metaClass->typeEntry()); return te->smartPointerType() == TypeSystem::SmartPointerType::Shared; } @@ -622,7 +622,7 @@ static bool needsTypeDiscoveryFunction(const AbstractMetaClass *c) && (c->isPolymorphic() || !c->typeEntry()->polymorphicIdValue().isEmpty()); } -static void writeAddedTypeSignatures(TextStream &s, const ComplexTypeEntry *te) +static void writeAddedTypeSignatures(TextStream &s, const ComplexTypeEntryCPtr &te) { for (const auto &e : te->addedPyMethodDefEntrys()) { if (auto count = e.signatures.size()) { @@ -647,11 +647,11 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon s.setLanguage(TextStream::Language::Cpp); const AbstractMetaClass *metaClass = classContext.metaClass(); - const auto *typeEntry = metaClass->typeEntry(); + const auto typeEntry = metaClass->typeEntry(); auto innerClasses = metaClass->innerClasses(); for (auto it = innerClasses.begin(); it != innerClasses.end(); ) { - auto *innerTypeEntry = (*it)->typeEntry(); + auto innerTypeEntry = (*it)->typeEntry(); if (shouldGenerate(innerTypeEntry) && !innerTypeEntry->isSmartPointer()) ++it; else @@ -674,7 +674,7 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon const AbstractMetaClass *context = metaClass->enclosingClass(); while (context) { if (context->isNamespace() && !context->enclosingClass() - && static_cast(context->typeEntry())->generateUsing()) { + && qSharedPointerCast(context->typeEntry())->generateUsing()) { s << "\nusing namespace " << context->qualifiedCppName() << ";\n"; break; } @@ -694,7 +694,7 @@ void CppGenerator::generateClass(TextStream &s, const GeneratorContext &classCon // python conversion rules if (typeEntry->isValue()) { - auto *vte = static_cast(typeEntry); + auto vte = qSharedPointerCast(typeEntry); if (vte->hasTargetConversionRule()) { s << "// Python Conversion\n"; s << vte->targetConversionRule() << '\n'; @@ -959,7 +959,7 @@ void CppGenerator::generateSmartPointerClass(TextStream &s, const GeneratorConte { s.setLanguage(TextStream::Language::Cpp); const AbstractMetaClass *metaClass = classContext.metaClass(); - const auto *typeEntry = static_cast(metaClass->typeEntry()); + const auto typeEntry = qSharedPointerCast(metaClass->typeEntry()); const bool hasPointeeClass = classContext.pointeeClass() != nullptr; const auto smartPointerType = typeEntry->smartPointerType(); const bool isValueHandle = smartPointerType ==TypeSystem::SmartPointerType::ValueHandle; @@ -1157,7 +1157,7 @@ QString CppGenerator::getVirtualFunctionReturnTypeName(const AbstractMetaFunctio // SbkType would return null when the type is a container. auto typeEntry = func->type().typeEntry(); if (typeEntry->isContainer()) { - const auto *cte = static_cast(typeEntry); + const auto cte = qSharedPointerCast(typeEntry); switch (cte->containerKind()) { case ContainerTypeEntry::ListContainer: break; @@ -1197,7 +1197,7 @@ void CppGenerator::writeVirtualMethodCppCall(TextStream &s, const QString &funcName, const CodeSnipList &snips, const AbstractMetaArgument *lastArg, - const TypeEntry *retType, + const TypeEntryCPtr &retType, const QString &returnStatement, bool hasGil) const { if (!snips.isEmpty()) { @@ -1292,10 +1292,10 @@ QPair CppGenerator::virtualMethodNativeArg(const AbstractMetaFun return {arg.name() + CONV_RULE_OUT_VAR_SUFFIX, u'N'}; const auto &type = arg.type(); - auto *argTypeEntry = type.typeEntry(); + auto argTypeEntry = type.typeEntry(); // Check for primitive types convertible by Py_BuildValue() if (argTypeEntry->isPrimitive() && !type.isCString()) { - const auto *pte = basicReferencedTypeEntry(argTypeEntry->asPrimitive()); + const auto pte = basicReferencedTypeEntry(argTypeEntry); auto it = formatUnits().constFind(pte->name()); if (it != formatUnits().constEnd()) return {arg.name(), it.value()}; @@ -1385,7 +1385,7 @@ void CppGenerator::writeVirtualMethodNative(TextStream &s, const AbstractMetaFunctionCPtr &func, int cacheIndex) const { - const TypeEntry *retType = func->type().typeEntry(); + TypeEntryCPtr retType = func->type().typeEntry(); const QString funcName = func->isOperatorOverload() ? pythonOperatorFunctionName(func) : func->definitionNames().constFirst(); @@ -1725,7 +1725,7 @@ void CppGenerator::writeMetaCast(TextStream &s, } void CppGenerator::writeFlagsConverterFunctions(TextStream &s, - const FlagsTypeEntry *flagsType, + const FlagsTypeEntryCPtr &flagsType, const QString &enumTypeName, const QString &flagsCppTypeName, const QString &enumTypeCheck) const @@ -1781,7 +1781,7 @@ static void generateDeprecatedValueWarnings(TextStream &c, const AbstractMetaEnum &metaEnum, bool useSurrogateName) { - const EnumTypeEntry *enumType = metaEnum.typeEntry(); + EnumTypeEntryCPtr enumType = metaEnum.typeEntry(); const QString prefix = enumType->qualifiedCppName() + u"::"_s; c << "switch (value) {\n"; const auto &deprecatedValues = metaEnum.deprecatedValues(); @@ -1803,7 +1803,7 @@ void CppGenerator::writeEnumConverterFunctions(TextStream &s, const AbstractMeta { if (metaEnum.isPrivate() || metaEnum.isAnonymous()) return; - EnumTypeEntry *enumType = metaEnum.typeEntry(); + EnumTypeEntryPtr enumType = metaEnum.typeEntry(); Q_ASSERT(enumType); QString typeName = fixedCppTypeName(enumType); QString enumPythonType = cpythonTypeNameExt(enumType); @@ -1838,7 +1838,7 @@ void CppGenerator::writeEnumConverterFunctions(TextStream &s, const AbstractMeta s << '\n'; // QFlags part. - if (auto *flags = enumType->flags()) { + if (auto flags = enumType->flags(); !flags.isNull()) { const QString flagsCppTypeName = useSurrogateName ? cppTypeName : getFullTypeName(flags).trimmed(); writeFlagsConverterFunctions(s, flags, typeName, flagsCppTypeName, pyTypeCheck); @@ -1851,7 +1851,7 @@ void CppGenerator::writeConverterFunctions(TextStream &s, const AbstractMetaClas s << "// Type conversion functions.\n\n"; AbstractMetaEnumList classEnums = metaClass->enums(); - auto *typeEntry = metaClass->typeEntry(); + auto typeEntry = metaClass->typeEntry(); metaClass->getEnumsFromInvisibleNamespacesToBeGenerated(&classEnums); if (!classEnums.isEmpty()) s << "// Python to C++ enum conversion.\n"; @@ -1961,7 +1961,7 @@ return result;)"; c << '*' << outPtr << " = *" << cpythonWrapperCPtr(typeEntry, pyInVariable) << ';'; } else { - auto *ste = static_cast(typeEntry); + auto ste = qSharedPointerCast(typeEntry); const QString resetMethod = ste->resetMethod(); c << "auto *ptr = " << outPtr << ";\n"; c << "if (" << pyInVariable << " == Py_None)\n" << indent; @@ -2052,7 +2052,7 @@ return result;)"; } if (typeEntry->isValue()) { - auto *vte = static_cast(typeEntry); + auto vte = qSharedPointerCast(typeEntry); writeCustomConverterFunctions(s, vte->customConversion()); } } @@ -2065,7 +2065,7 @@ void CppGenerator::writeCustomConverterFunctions(TextStream &s, const TargetToNativeConversions &toCppConversions = customConversion->targetToNativeConversions(); if (toCppConversions.isEmpty()) return; - auto *ownerType = customConversion->ownerType(); + auto ownerType = customConversion->ownerType(); s << "// Python to C++ conversions for type '" << ownerType->qualifiedCppName() << "'.\n"; for (const auto &toNative : toCppConversions) writePythonToCppConversionFunctions(s, toNative, ownerType); @@ -2075,7 +2075,7 @@ void CppGenerator::writeCustomConverterFunctions(TextStream &s, void CppGenerator::writeConverterRegister(TextStream &s, const AbstractMetaClass *metaClass, const GeneratorContext &classContext) const { - const auto *typeEntry = metaClass->typeEntry(); + const auto typeEntry = metaClass->typeEntry(); if (typeEntry->isNamespace()) return; s << "// Register Converter\n" @@ -2185,7 +2185,7 @@ void CppGenerator::writeConverterRegister(TextStream &s, const AbstractMetaClass } if (typeEntry->isValue()) { - auto *vte = static_cast(typeEntry); + auto vte = qSharedPointerCast(typeEntry); writeCustomConverterRegister(s, vte->customConversion(), u"converter"_s); } } @@ -2220,7 +2220,7 @@ static AbstractMetaClassCList findSmartPointeeBaseClasses(const ApiExtractorResu const AbstractMetaType &smartPointerType) { AbstractMetaClassCList result; - auto *instantiationsTe = smartPointerType.instantiations().at(0).typeEntry(); + auto instantiationsTe = smartPointerType.instantiations().at(0).typeEntry(); auto targetClass = AbstractMetaClass::findClass(api.classes(), instantiationsTe); if (targetClass != nullptr) result = targetClass->allTypeSystemAncestors(); @@ -2234,14 +2234,14 @@ void CppGenerator::writeSmartPointerConverterFunctions(TextStream &s, if (baseClasses.isEmpty()) return; - auto *smartPointerTypeEntry = - static_cast(smartPointerType.typeEntry()); + auto smartPointerTypeEntry = + qSharedPointerCast(smartPointerType.typeEntry()); // TODO: Missing conversion to smart pointer pointer type: s << "// Register smartpointer conversion for all derived classes\n"; for (auto *base : baseClasses) { - auto *baseTe = base->typeEntry(); + auto baseTe = base->typeEntry(); if (smartPointerTypeEntry->matchesInstantiation(baseTe)) { if (auto opt = findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) { const auto smartTargetType = opt.value(); @@ -2889,7 +2889,7 @@ void CppGenerator::writeTypeCheck(TextStream &s, const QSharedPointer &overloadData, const QString &argumentName) { - QSet numericTypes; + QSet numericTypes; const OverloadDataList &siblings = overloadData->parent()->children(); for (const auto &sibling : siblings) { for (const auto &func : sibling->overloads()) { @@ -2997,7 +2997,7 @@ qsizetype CppGenerator::writePythonToCppTypeConversion(TextStream &s, const AbstractMetaClass *context, const QString &defaultValue) const { - const TypeEntry *typeEntry = type.typeEntry(); + TypeEntryCPtr typeEntry = type.typeEntry(); if (typeEntry->isCustom() || typeEntry->isVarargs()) return 0; @@ -3286,7 +3286,7 @@ void CppGenerator::writeOverloadedFunctionDecisorEngine(TextStream &s, if (func->isConstructor() && func->arguments().size() == 1) { const AbstractMetaClass *ownerClass = func->ownerClass(); - const ComplexTypeEntry *baseContainerType = ownerClass->typeEntry()->baseContainerType(); + ComplexTypeEntryCPtr baseContainerType = ownerClass->typeEntry()->baseContainerType(); if (baseContainerType && baseContainerType == func->arguments().constFirst().type().typeEntry() && ownerClass->isCopyable()) { tck << '!' << cpythonCheckFunction(ownerClass->typeEntry()) @@ -3472,7 +3472,7 @@ QString CppGenerator::pythonToCppFunctionName(const AbstractMetaType &sourceType return pythonToCppFunctionName(fixedCppTypeName(sourceType), fixedCppTypeName(targetType)); } QString CppGenerator::pythonToCppFunctionName(const TargetToNativeConversion &toNative, - const TypeEntry *targetType) + const TypeEntryCPtr &targetType) { return pythonToCppFunctionName(fixedCppTypeName(toNative), fixedCppTypeName(targetType)); } @@ -3487,7 +3487,7 @@ QString CppGenerator::convertibleToCppFunctionName(const AbstractMetaType &sourc return convertibleToCppFunctionName(fixedCppTypeName(sourceType), fixedCppTypeName(targetType)); } QString CppGenerator::convertibleToCppFunctionName(const TargetToNativeConversion &toNative, - const TypeEntry *targetType) + const TypeEntryCPtr &targetType) { return convertibleToCppFunctionName(fixedCppTypeName(toNative), fixedCppTypeName(targetType)); } @@ -3532,7 +3532,7 @@ void CppGenerator::writeCppToPythonFunction(TextStream &s, const CustomConversionPtr &customConversion) const { QString code = customConversion->nativeToTargetConversion(); - auto *ownerType = customConversion->ownerType(); + auto ownerType = customConversion->ownerType(); const bool constRef = !ownerType->isPrimitive(); // PyCapsule needs a non-const ref replaceCppToPythonVariables(code, getFullTypeName(ownerType), constRef); writeCppToPythonFunction(s, code, fixedCppTypeName(customConversion->ownerType())); @@ -3540,7 +3540,7 @@ void CppGenerator::writeCppToPythonFunction(TextStream &s, void CppGenerator::writeCppToPythonFunction(TextStream &s, const AbstractMetaType &containerType) const { Q_ASSERT(containerType.typeEntry()->isContainer()); - auto *cte = static_cast(containerType.typeEntry()); + auto cte = qSharedPointerCast(containerType.typeEntry()); if (!cte->hasCustomConversion()) { QString m; QTextStream(&m) << "Can't write the C++ to Python conversion function for container type '" @@ -3631,7 +3631,7 @@ void CppGenerator::writePythonToCppConversionFunctions(TextStream &s, void CppGenerator::writePythonToCppConversionFunctions(TextStream &s, const TargetToNativeConversion &toNative, - const TypeEntry *targetType) const + const TypeEntryCPtr &targetType) const { // Python to C++ conversion function. QString code = toNative.conversion(); @@ -3679,7 +3679,7 @@ void CppGenerator::writePythonToCppConversionFunctions(TextStream &s, void CppGenerator::writePythonToCppConversionFunctions(TextStream &s, const AbstractMetaType &containerType) const { Q_ASSERT(containerType.typeEntry()->isContainer()); - auto *cte = static_cast(containerType.typeEntry()); + auto cte = qSharedPointerCast(containerType.typeEntry()); if (!cte->hasCustomConversion()) { //qFatal return; @@ -3882,7 +3882,7 @@ CppGenerator::argumentClassFromIndex(const ApiExtractorResult &api, type = type.instantiations().constFirst(); } - auto *te = type.typeEntry(); + auto te = type.typeEntry(); if (type.isVoid() || !te->isComplex()) throw Exception(msgInvalidArgumentModification(func, argIndex)); auto *result = AbstractMetaClass::findClass(api.classes(), te); @@ -4411,7 +4411,7 @@ void CppGenerator::writeSpecialCastFunction(TextStream &s, const AbstractMetaCla void CppGenerator::writePrimitiveConverterInitialization(TextStream &s, const CustomConversionPtr &customConversion) { - const TypeEntry *type = customConversion->ownerType(); + TypeEntryCPtr type = customConversion->ownerType(); QString converter = converterObject(type); s << "// Register converter for type '" << type->qualifiedTargetLangName() << "'.\n" << converter << " = Shiboken::Conversions::createConverter("; @@ -4441,7 +4441,8 @@ static void registerEnumConverterScopes(TextStream &s, QString signature) } } -void CppGenerator::writeFlagsConverterInitialization(TextStream &s, const FlagsTypeEntry *flags) +void CppGenerator::writeFlagsConverterInitialization(TextStream &s, + const FlagsTypeEntryCPtr &flags) { static const char enumPythonVar[] = "FType"; @@ -4493,7 +4494,7 @@ void CppGenerator::writeEnumConverterInitialization(TextStream &s, const Abstrac { if (metaEnum.isPrivate() || metaEnum.isAnonymous()) return; - const EnumTypeEntry *enumType = metaEnum.typeEntry(); + EnumTypeEntryCPtr enumType = metaEnum.typeEntry(); Q_ASSERT(enumType); static const char enumPythonVar[] = "EType"; @@ -4516,7 +4517,7 @@ void CppGenerator::writeEnumConverterInitialization(TextStream &s, const Abstrac s << outdent << "}\n"; - if (auto *flags = enumType->flags()) + if (auto flags = enumType->flags(); !flags.isNull()) writeFlagsConverterInitialization(s, flags); } @@ -4565,13 +4566,13 @@ void CppGenerator::writeSmartPointerConverterInitialization(TextStream &s, const if (classes.isEmpty()) return; - auto *smartPointerTypeEntry = static_cast(type.typeEntry()); + auto smartPointerTypeEntry = qSharedPointerCast(type.typeEntry()); s << "// Register SmartPointer converter for type '" << cppSignature << "'." << '\n' << "///////////////////////////////////////////////////////////////////////////////////////\n\n"; for (auto *base : classes) { - auto *baseTe = base->typeEntry(); + auto baseTe = base->typeEntry(); if (auto opt = findSmartPointerInstantiation(smartPointerTypeEntry, baseTe)) { const auto smartTargetType = opt.value(); s << "// Convert to SmartPointer derived class: [" @@ -4587,7 +4588,8 @@ void CppGenerator::writeSmartPointerConverterInitialization(TextStream &s, const s << "///////////////////////////////////////////////////////////////////////////////////////" << '\n' << '\n'; } -void CppGenerator::writeExtendedConverterInitialization(TextStream &s, const TypeEntry *externalType, +void CppGenerator::writeExtendedConverterInitialization(TextStream &s, + const TypeEntryCPtr &externalType, const AbstractMetaClassCList &conversions) { s << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() @@ -4634,7 +4636,7 @@ bool CppGenerator::supportsSequenceProtocol(const AbstractMetaClass *metaClass) return true; } - const ComplexTypeEntry *baseType = metaClass->typeEntry()->baseContainerType(); + ComplexTypeEntryCPtr baseType = metaClass->typeEntry()->baseContainerType(); return baseType && baseType->isContainer(); } @@ -5392,7 +5394,7 @@ using ComparisonOperatorList = QListisSmartPointer()); - const auto *ste = static_cast(te); + const auto ste = qSharedPointerCast(te); s << "const auto *" << selfPointeeVar << " = " << CPP_SELF_VAR << '.' << ste->getter() << "();\n"; @@ -5665,7 +5667,7 @@ void CppGenerator::writeEnumInitialization(TextStream &s, const AbstractMetaEnum const AbstractMetaClass *enclosingClass = cppEnum.targetLangEnclosingClass(); bool hasUpperEnclosingClass = enclosingClass && enclosingClass->targetLangEnclosingClass() != nullptr; - const EnumTypeEntry *enumTypeEntry = cppEnum.typeEntry(); + EnumTypeEntryCPtr enumTypeEntry = cppEnum.typeEntry(); QString enclosingObjectVariable; if (enclosingClass) enclosingObjectVariable = cpythonTypeName(enclosingClass); @@ -5681,8 +5683,8 @@ void CppGenerator::writeEnumInitialization(TextStream &s, const AbstractMetaEnum QString enumVarTypeObj = cpythonTypeNameExt(enumTypeEntry); if (!cppEnum.isAnonymous()) { int packageLevel = packageName().count(u'.') + 1; - FlagsTypeEntry *flags = enumTypeEntry->flags(); - if (flags) { + FlagsTypeEntryPtr flags = enumTypeEntry->flags(); + if (!flags.isNull()) { // The following could probably be made nicer: // We need 'flags->flagsName()' with the full module/class path. QString fullPath = getClassTargetFullName(cppEnum); @@ -5805,7 +5807,7 @@ void CppGenerator::writeSignalInitialization(TextStream &s, const AbstractMetaCl void CppGenerator::writeFlagsToLong(TextStream &s, const AbstractMetaEnum &cppEnum) { - FlagsTypeEntry *flagsEntry = cppEnum.typeEntry()->flags(); + FlagsTypeEntryPtr flagsEntry = cppEnum.typeEntry()->flags(); if (!flagsEntry) return; s << "static PyObject *" << cpythonEnumName(cppEnum) << "_long(PyObject *self)\n" @@ -5819,8 +5821,8 @@ void CppGenerator::writeFlagsToLong(TextStream &s, const AbstractMetaEnum &cppEn void CppGenerator::writeFlagsNonZero(TextStream &s, const AbstractMetaEnum &cppEnum) { - FlagsTypeEntry *flagsEntry = cppEnum.typeEntry()->flags(); - if (!flagsEntry) + FlagsTypeEntryPtr flagsEntry = cppEnum.typeEntry()->flags(); + if (flagsEntry.isNull()) return; s << "static int " << cpythonEnumName(cppEnum) << "__nonzero(PyObject *self)\n"; s << "{\n" << indent << "int val;\n"; @@ -5874,8 +5876,8 @@ void CppGenerator::writeFlagsNumberMethodsDefinitions(TextStream &s, void CppGenerator::writeFlagsBinaryOperator(TextStream &s, const AbstractMetaEnum &cppEnum, const QString &pyOpName, const QString &cppOpName) { - FlagsTypeEntry *flagsEntry = cppEnum.typeEntry()->flags(); - Q_ASSERT(flagsEntry); + FlagsTypeEntryPtr flagsEntry = cppEnum.typeEntry()->flags(); + Q_ASSERT(!flagsEntry.isNull()); s << "PyObject *" << cpythonEnumName(cppEnum) << "___" << pyOpName << "__(PyObject *self, PyObject *" << PYTHON_ARG << ")\n{\n" << indent; @@ -5903,7 +5905,7 @@ void CppGenerator::writeFlagsUnaryOperator(TextStream &s, const AbstractMetaEnum const QString &pyOpName, const QString &cppOpName, bool boolResult) { - FlagsTypeEntry *flagsEntry = cppEnum.typeEntry()->flags(); + FlagsTypeEntryPtr flagsEntry = cppEnum.typeEntry()->flags(); Q_ASSERT(flagsEntry); s << "PyObject *" << cpythonEnumName(cppEnum) << "___" << pyOpName @@ -5993,7 +5995,7 @@ void CppGenerator::writeClassRegister(TextStream &s, const GeneratorContext &classContext, const QString &signatures) const { - const ComplexTypeEntry *classTypeEntry = metaClass->typeEntry(); + ComplexTypeEntryCPtr classTypeEntry = metaClass->typeEntry(); const AbstractMetaClass *enc = metaClass->targetLangEnclosingClass(); QString enclosingObjectVariable = enc ? u"enclosingClass"_s : u"module"_s; @@ -6571,7 +6573,7 @@ void CppGenerator::writeNbBoolFunction(const GeneratorContext &context, // function. void CppGenerator::writeInitFunc(TextStream &declStr, TextStream &callStr, const QString &initFunctionName, - const TypeEntry *enclosingEntry) + const TypeEntryCPtr &enclosingEntry) { const bool hasParent = enclosingEntry && enclosingEntry->type() != TypeEntry::TypeSystemType; @@ -6619,7 +6621,7 @@ bool CppGenerator::finishGeneration() AbstractMetaClassCList classesWithStaticFields; for (auto cls : api().classes()){ - auto *te = cls->typeEntry(); + auto te = cls->typeEntry(); if (shouldGenerate(te)) { writeInitFunc(s_classInitDecl, s_classPythonDefines, getSimpleClassInitFunctionName(cls), @@ -6636,7 +6638,7 @@ bool CppGenerator::finishGeneration() for (const auto &smp : api().instantiatedSmartPointers()) { GeneratorContext context = contextForSmartPointer(smp.specialized, smp.type); auto *enclosingClass = context.metaClass()->enclosingClass(); - auto *enclosingTypeEntry = enclosingClass != nullptr + auto enclosingTypeEntry = enclosingClass != nullptr ? enclosingClass->typeEntry() : targetLangEnclosingEntry(smp.type.typeEntry()); writeInitFunc(s_classInitDecl, s_classPythonDefines, @@ -6652,7 +6654,7 @@ bool CppGenerator::finishGeneration() const ExtendedConverterData extendedConverters = getExtendedConverters(); for (auto it = extendedConverters.cbegin(), end = extendedConverters.cend(); it != end; ++it) { - const TypeEntry *te = it.key(); + TypeEntryCPtr te = it.key(); includes << te->include(); for (const auto &metaClass : it.value()) includes << metaClass->typeEntry()->include(); @@ -6660,7 +6662,7 @@ bool CppGenerator::finishGeneration() const QList &typeConversions = getPrimitiveCustomConversions(); for (const auto &c : typeConversions) { - if (auto *te = c->ownerType()) + if (auto te = c->ownerType(); !te.isNull()) includes << te->include(); } @@ -6707,8 +6709,8 @@ bool CppGenerator::finishGeneration() } TypeDatabase *typeDb = TypeDatabase::instance(); - const TypeSystemTypeEntry *moduleEntry = typeDb->defaultTypeSystemType(); - Q_ASSERT(moduleEntry); + TypeSystemTypeEntryCPtr moduleEntry = typeDb->defaultTypeSystemType(); + Q_ASSERT(!moduleEntry.isNull()); s << '\n'; // Extra includes @@ -6791,7 +6793,7 @@ bool CppGenerator::finishGeneration() if (!extendedConverters.isEmpty()) { s << '\n' << "// Extended Converters.\n\n"; for (ExtendedConverterData::const_iterator it = extendedConverters.cbegin(), end = extendedConverters.cend(); it != end; ++it) { - const TypeEntry *externalType = it.key(); + TypeEntryCPtr externalType = it.key(); s << "// Extended implicit conversions for " << externalType->qualifiedTargetLangName() << '.' << '\n'; for (const AbstractMetaClass *sourceClass : it.value()) { @@ -6945,12 +6947,12 @@ bool CppGenerator::finishGeneration() s << "// Register primitive types converters.\n"; const PrimitiveTypeEntryCList &primitiveTypeList = primitiveTypes(); - for (const PrimitiveTypeEntry *pte : primitiveTypeList) { + for (const auto &pte : primitiveTypeList) { if (!pte->generateCode() || !isCppPrimitive(pte)) continue; if (!pte->referencesType()) continue; - const auto *referencedType = basicReferencedTypeEntry(pte); + TypeEntryCPtr referencedType = basicReferencedTypeEntry(pte); QString converter = converterObject(referencedType); QStringList cppSignature = pte->qualifiedCppName().split(u"::"_s, Qt::SkipEmptyParts); while (!cppSignature.isEmpty()) { @@ -7027,10 +7029,10 @@ static bool useParentHeuristics(const ApiExtractorResult &api, auto *owner = func->ownerClass(); if (owner == nullptr) return false; - auto *ownerEntry = owner->parentManagementEntry(); - if (ownerEntry == nullptr) + auto ownerEntry = owner->parentManagementEntry(); + if (ownerEntry.isNull()) return false; - auto *argTypeEntry = argType.typeEntry(); + auto argTypeEntry = argType.typeEntry(); if (!argTypeEntry->isComplex()) return false; auto *argClass = AbstractMetaClass::findClass(api.classes(), argTypeEntry); diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.h b/sources/shiboken6/generator/shiboken/cppgenerator.h index 99ad16722..b2e99b7bb 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.h +++ b/sources/shiboken6/generator/shiboken/cppgenerator.h @@ -63,7 +63,7 @@ private: const AbstractMetaClassCList &innerClasses = {}) const; static void writeInitFunc(TextStream &declStr, TextStream &callStr, const QString &initFunctionName, - const TypeEntry *enclosingEntry = nullptr); + const TypeEntryCPtr &enclosingEntry = {}); static void writeCacheResetNative(TextStream &s, const GeneratorContext &classContext); void writeConstructorNative(TextStream &s, const GeneratorContext &classContext, const AbstractMetaFunctionCPtr &func) const; @@ -85,7 +85,7 @@ private: int cacheIndex) const; void writeVirtualMethodCppCall(TextStream &s, const AbstractMetaFunctionCPtr &func, const QString &funcName, const QList &snips, - const AbstractMetaArgument *lastArg, const TypeEntry *retType, + const AbstractMetaArgument *lastArg, const TypeEntryCPtr &retType, const QString &returnStatement, bool hasGil) const; static QString virtualMethodReturn(TextStream &s, const ApiExtractorResult &api, const AbstractMetaFunctionCPtr &func, @@ -93,7 +93,7 @@ private: void writeMetaObjectMethod(TextStream &s, const GeneratorContext &classContext) const; static void writeMetaCast(TextStream &s, const GeneratorContext &classContext); - void writeFlagsConverterFunctions(TextStream &s, const FlagsTypeEntry *flagsType, + void writeFlagsConverterFunctions(TextStream &s, const FlagsTypeEntryCPtr &flagsType, const QString &enumTypeName, const QString &flagsCppTypeName, const QString &enumTypeCheck) const; @@ -292,13 +292,13 @@ private: static QString pythonToCppFunctionName(const QString &sourceTypeName, const QString &targetTypeName); static QString pythonToCppFunctionName(const AbstractMetaType &sourceType, const AbstractMetaType &targetType); static QString pythonToCppFunctionName(const TargetToNativeConversion &toNative, - const TypeEntry *targetType); + const TypeEntryCPtr &targetType); /// Returns the name of a Python to C++ convertible check function. static QString convertibleToCppFunctionName(const QString &sourceTypeName, const QString &targetTypeName); static QString convertibleToCppFunctionName(const AbstractMetaType &sourceType, const AbstractMetaType &targetType); static QString convertibleToCppFunctionName(const TargetToNativeConversion &toNative, - const TypeEntry *targetType); + const TypeEntryCPtr &targetType); /// Writes a C++ to Python conversion function. void writeCppToPythonFunction(TextStream &s, const QString &code, const QString &sourceTypeName, @@ -328,7 +328,7 @@ private: /// Writes a pair of Python to C++ conversion and check functions for implicit conversions. void writePythonToCppConversionFunctions(TextStream &s, const TargetToNativeConversion &toNative, - const TypeEntry *targetType) const; + const TypeEntryCPtr &targetType) const; /// Writes a pair of Python to C++ conversion and check functions for instantiated container types. void writePythonToCppConversionFunctions(TextStream &s, @@ -461,11 +461,12 @@ private: static void writePrimitiveConverterInitialization(TextStream &s, const CustomConversionPtr &customConversion); - static void writeFlagsConverterInitialization(TextStream &s, const FlagsTypeEntry *enumType); + static void writeFlagsConverterInitialization(TextStream &s, const FlagsTypeEntryCPtr &enumType); static void writeEnumConverterInitialization(TextStream &s, const AbstractMetaEnum &metaEnum); QString writeContainerConverterInitialization(TextStream &s, const AbstractMetaType &type) const; void writeSmartPointerConverterInitialization(TextStream &s, const AbstractMetaType &ype) const; - static void writeExtendedConverterInitialization(TextStream &s, const TypeEntry *externalType, + static void writeExtendedConverterInitialization(TextStream &s, + const TypeEntryCPtr &externalType, const AbstractMetaClassCList &conversions); void writeParentChildManagement(TextStream &s, const AbstractMetaFunctionCPtr &func, @@ -517,8 +518,8 @@ private: { return boolCast(metaClass).has_value(); } std::optional - findSmartPointerInstantiation(const SmartPointerTypeEntry *pointer, - const TypeEntry *pointee) const; + findSmartPointerInstantiation(const SmartPointerTypeEntryCPtr &pointer, + const TypeEntryCPtr &pointee) const; void clearTpFuncs(); QHash m_tpFuncs; diff --git a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp index 91c56b284..8073e0c97 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator_container.cpp @@ -85,7 +85,7 @@ CppGenerator::OpaqueContainerData { OpaqueContainerData result; const auto &valueType = containerType.instantiations().constFirst(); - const auto *containerTypeEntry = static_cast(containerType.typeEntry()); + const auto containerTypeEntry = qSharedPointerCast(containerType.typeEntry()); result.name = containerTypeEntry->opaqueContainerName(valueType.typeEntry()->name()); const auto cppSignature = containerType.cppSignature(); diff --git a/sources/shiboken6/generator/shiboken/generatorargument.cpp b/sources/shiboken6/generator/shiboken/generatorargument.cpp index 5c8f12458..e81ad0797 100644 --- a/sources/shiboken6/generator/shiboken/generatorargument.cpp +++ b/sources/shiboken6/generator/shiboken/generatorargument.cpp @@ -19,7 +19,7 @@ GeneratorArgument GeneratorArgument::fromMetaType(const AbstractMetaType &type) { GeneratorArgument result; - const TypeEntry *typeEntry = type.typeEntry(); + const auto typeEntry = type.typeEntry(); if (typeEntry->isCustom() || typeEntry->isVarargs()) return result; diff --git a/sources/shiboken6/generator/shiboken/headergenerator.cpp b/sources/shiboken6/generator/shiboken/headergenerator.cpp index d24a3b12b..9ed192097 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.cpp +++ b/sources/shiboken6/generator/shiboken/headergenerator.cpp @@ -245,12 +245,12 @@ void HeaderGenerator::writeMemberFunctionWrapper(TextStream &s, s << ", "; const AbstractMetaArgument &arg = arguments.at(i); const auto &type = arg.type(); - const TypeEntry *enumTypeEntry = nullptr; + TypeEntryCPtr enumTypeEntry; if (type.isFlags()) - enumTypeEntry = static_cast(type.typeEntry())->originator(); + enumTypeEntry = qSharedPointerCast(type.typeEntry())->originator(); else if (type.isEnum()) enumTypeEntry = type.typeEntry(); - if (enumTypeEntry) { + if (!enumTypeEntry.isNull()) { s << type.cppSignature() << '(' << arg.name() << ')'; } else if (type.passByValue() && type.isUniquePointer()) { s << stdMove(arg.name()); @@ -339,7 +339,7 @@ static const AbstractMetaClass * } void HeaderGenerator::writeTypeIndexValueLine(TextStream &s, const ApiExtractorResult &api, - const TypeEntry *typeEntry) + const TypeEntryCPtr &typeEntry) { if (!typeEntry || !typeEntry->generateCode()) return; @@ -350,7 +350,7 @@ void HeaderGenerator::writeTypeIndexValueLine(TextStream &s, const ApiExtractorR // For a typedef "using Foo=QList", write a type index // SBK_QLIST_INT besides SBK_FOO which is then matched by function // argument. Check against duplicate typedefs for the same types. - const auto *cType = static_cast(typeEntry); + const auto cType = qSharedPointerCast(typeEntry); if (cType->baseContainerType()) { auto metaClass = AbstractMetaClass::findClass(api.classes(), cType); Q_ASSERT(metaClass != nullptr); @@ -366,7 +366,7 @@ void HeaderGenerator::writeTypeIndexValueLine(TextStream &s, const ApiExtractorR } } if (typeEntry->isEnum()) { - auto ete = static_cast(typeEntry); + auto ete = qSharedPointerCast(typeEntry); if (ete->flags()) writeTypeIndexValueLine(s, api, ete->flags()); } @@ -390,7 +390,7 @@ void HeaderGenerator::writeTypeIndexValueLines(TextStream &s, const ApiExtractor // Format the typedefs for the typedef entries to be generated static void formatTypeDefEntries(TextStream &s) { - QList entries; + QList entries; const auto typeDbEntries = TypeDatabase::instance()->typedefEntries(); for (auto it = typeDbEntries.cbegin(), end = typeDbEntries.cend(); it != end; ++it) { if (it.value()->generateCode() != 0) @@ -399,7 +399,7 @@ static void formatTypeDefEntries(TextStream &s) if (entries.isEmpty()) return; s << "\n// typedef entries\n"; - for (const auto e : entries) { + for (const auto &e : entries) { const QString name = e->qualifiedCppName(); // Fixme: simplify by using nested namespaces in C++ 17. const auto components = QStringView{name}.split(u"::"); @@ -586,7 +586,7 @@ bool HeaderGenerator::finishGeneration() macrosStream << "// Converter indices\nenum : int {\n"; const auto &primitives = primitiveTypes(); int pCount = 0; - for (const PrimitiveTypeEntry *ptype : primitives) { + for (const auto &ptype : primitives) { /* Note: do not generate indices for typedef'd primitive types * as they'll use the primitive type converters instead, so we * don't need to create any other. @@ -631,7 +631,7 @@ bool HeaderGenerator::finishGeneration() StringStream protEnumsSurrogates(TextStream::Language::Cpp); for (auto metaClass : classList) { - const TypeEntry *classType = metaClass->typeEntry(); + const auto classType = metaClass->typeEntry(); if (!shouldGenerate(classType)) continue; @@ -649,8 +649,7 @@ bool HeaderGenerator::finishGeneration() for (const AbstractMetaEnum &cppEnum : metaClass->enums()) { if (cppEnum.isAnonymous() || cppEnum.isPrivate()) continue; - EnumTypeEntry *enumType = cppEnum.typeEntry(); - includeList << enumType->include(); + includeList << cppEnum.typeEntry()->include(); writeProtectedEnumSurrogate(protEnumsSurrogates, cppEnum); writeSbkTypeFunction(typeFunctionsStr, cppEnum); } @@ -660,8 +659,7 @@ bool HeaderGenerator::finishGeneration() } for (const auto &smp : api().instantiatedSmartPointers()) { - const TypeEntry *classType = smp.type.typeEntry(); - includes << classType->include(); + includes << smp.type.typeEntry()->include(); writeSbkTypeFunction(typeFunctions, smp.type); } if (usePySideExtensions()) @@ -708,7 +706,7 @@ bool HeaderGenerator::finishGeneration() if (!primitiveTypes().isEmpty()) { s << "// Conversion Includes - Primitive Types\n"; const auto &primitiveTypeList = primitiveTypes(); - for (const PrimitiveTypeEntry *ptype : primitiveTypeList) + for (const auto &ptype : primitiveTypeList) s << ptype->include(); s<< '\n'; } @@ -716,7 +714,7 @@ bool HeaderGenerator::finishGeneration() if (!containerTypes().isEmpty()) { s << "// Conversion Includes - Container Types\n"; const ContainerTypeEntryCList &containerTypeList = containerTypes(); - for (const ContainerTypeEntry *ctype : containerTypeList) + for (const auto &ctype : containerTypeList) s << ctype->include(); s<< '\n'; } @@ -802,8 +800,8 @@ void HeaderGenerator::writeSbkTypeFunction(TextStream &s, const AbstractMetaEnum s << "template<> inline PyTypeObject *SbkType< ::" << enumName << " >() "; s << "{ return " << cpythonTypeNameExt(cppEnum.typeEntry()) << "; }\n"; - FlagsTypeEntry *flag = cppEnum.typeEntry()->flags(); - if (flag) { + const auto flag = cppEnum.typeEntry()->flags(); + if (!flag.isNull()) { s << "template<> inline PyTypeObject *SbkType< ::" << flag->name() << " >() " << "{ return " << cpythonTypeNameExt(flag) << "; }\n"; } diff --git a/sources/shiboken6/generator/shiboken/headergenerator.h b/sources/shiboken6/generator/shiboken/headergenerator.h index 4f988c349..af81f0316 100644 --- a/sources/shiboken6/generator/shiboken/headergenerator.h +++ b/sources/shiboken6/generator/shiboken/headergenerator.h @@ -36,7 +36,7 @@ private: static void writeSbkTypeFunction(TextStream &s, const AbstractMetaClass *cppClass) ; static void writeSbkTypeFunction(TextStream &s, const AbstractMetaType &metaType) ; void writeTypeIndexValueLine(TextStream &s, const ApiExtractorResult &api, - const TypeEntry *typeEntry); + const TypeEntryCPtr &typeEntry); void writeTypeIndexValueLines(TextStream &s, const ApiExtractorResult &api, const AbstractMetaClass *metaClass); void writeProtectedEnumSurrogate(TextStream &s, const AbstractMetaEnum &cppEnum) const; diff --git a/sources/shiboken6/generator/shiboken/overloaddata.cpp b/sources/shiboken6/generator/shiboken/overloaddata.cpp index e42e52990..a5594791e 100644 --- a/sources/shiboken6/generator/shiboken/overloaddata.cpp +++ b/sources/shiboken6/generator/shiboken/overloaddata.cpp @@ -31,16 +31,16 @@ using namespace Qt::StringLiterals; static QString getTypeName(const AbstractMetaType &type) { - const TypeEntry *typeEntry = type.typeEntry(); + TypeEntryCPtr typeEntry = type.typeEntry(); if (typeEntry->isPrimitive()) - typeEntry = basicReferencedTypeEntry(typeEntry->asPrimitive()); + typeEntry = basicReferencedTypeEntry(typeEntry); QString typeName = typeEntry->name(); if (typeEntry->isContainer()) { QStringList types; for (const auto &cType : type.instantiations()) { - const TypeEntry *typeEntry = cType.typeEntry(); + TypeEntryCPtr typeEntry = cType.typeEntry(); if (typeEntry->isPrimitive()) - typeEntry = basicReferencedTypeEntry(typeEntry->asPrimitive()); + typeEntry = basicReferencedTypeEntry(typeEntry); types << typeEntry->name(); } typeName += u'<' + types.join(u',') + u" >"_s; @@ -241,7 +241,7 @@ void OverloadDataRootNode::sortNextOverloads(const ApiExtractorResult &api) // Process inheritance relationships if (targetType.isValue() || targetType.isObject()) { - auto *te = targetType.typeEntry(); + const auto te = targetType.typeEntry(); auto metaClass = AbstractMetaClass::findClass(api.classes(), te); if (!metaClass) throw Exception(msgArgumentClassNotFound(m_overloads.constFirst(), te)); diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index a39fe1f5e..1810235b7 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -255,11 +255,11 @@ ShibokenGenerator::FunctionGeneration return result; } -AbstractMetaFunctionCList ShibokenGenerator::implicitConversions(const TypeEntry *t) const +AbstractMetaFunctionCList ShibokenGenerator::implicitConversions(const TypeEntryCPtr &t) const { if (!generateImplicitConversions() || !t->isValue()) return {}; - auto *vte = static_cast(t); + auto vte = qSharedPointerCast(t); auto customConversion = vte->customConversion(); if (!customConversion.isNull() && customConversion->replaceOriginalTargetToNativeConversions()) return {}; @@ -417,7 +417,7 @@ static QString cpythonEnumFlagsName(const QString &moduleName, return result; } -QString ShibokenGenerator::cpythonEnumName(const EnumTypeEntry *enumEntry) +QString ShibokenGenerator::cpythonEnumName(const EnumTypeEntryCPtr &enumEntry) { QString p = enumEntry->targetLangPackage(); p.replace(u'.', u'_'); @@ -429,7 +429,7 @@ QString ShibokenGenerator::cpythonEnumName(const AbstractMetaEnum &metaEnum) return cpythonEnumName(metaEnum.typeEntry()); } -QString ShibokenGenerator::cpythonFlagsName(const FlagsTypeEntry *flagsEntry) +QString ShibokenGenerator::cpythonFlagsName(const FlagsTypeEntryCPtr &flagsEntry) { QString p = flagsEntry->targetLangPackage(); p.replace(u'.', u'_'); @@ -438,10 +438,8 @@ QString ShibokenGenerator::cpythonFlagsName(const FlagsTypeEntry *flagsEntry) QString ShibokenGenerator::cpythonFlagsName(const AbstractMetaEnum *metaEnum) { - const FlagsTypeEntry *flags = metaEnum->typeEntry()->flags(); - if (!flags) - return QString(); - return cpythonFlagsName(flags); + const auto flags = metaEnum->typeEntry()->flags(); + return flags.isNull() ? QString{} : cpythonFlagsName(flags); } QString ShibokenGenerator::cpythonSpecialCastFunctionName(const AbstractMetaClass *metaClass) @@ -465,7 +463,7 @@ QString ShibokenGenerator::cpythonWrapperCPtr(const AbstractMetaType &metaType, + u", reinterpret_cast("_s + argName + u")))"_s; } -QString ShibokenGenerator::cpythonWrapperCPtr(const TypeEntry *type, +QString ShibokenGenerator::cpythonWrapperCPtr(const TypeEntryCPtr &type, const QString &argName) { if (!type->isWrapperType()) @@ -532,21 +530,21 @@ QString ShibokenGenerator::cpythonBaseName(const AbstractMetaClass *metaClass) return cpythonBaseName(metaClass->typeEntry()); } -QString ShibokenGenerator::cpythonBaseName(const TypeEntry *type) +QString ShibokenGenerator::cpythonBaseName(const TypeEntryCPtr &type) { QString baseName; if (type->isWrapperType() || type->isNamespace()) { // && type->referenceType() == NoReference) { baseName = u"Sbk_"_s + type->name(); } else if (type->isPrimitive()) { - const auto *ptype = basicReferencedTypeEntry(type->asPrimitive()); + const auto ptype = basicReferencedTypeEntry(type); baseName = ptype->hasTargetLangApiType() ? ptype->targetLangApiName() : pythonPrimitiveTypeName(ptype->name()); } else if (type->isEnum()) { - baseName = cpythonEnumName(static_cast(type)); + baseName = cpythonEnumName(qSharedPointerCast(type)); } else if (type->isFlags()) { - baseName = cpythonFlagsName(static_cast(type)); + baseName = cpythonFlagsName(qSharedPointerCast(type)); } else if (type->isContainer()) { - const auto *ctype = static_cast(type); + const auto ctype = qSharedPointerCast(type); switch (ctype->containerKind()) { case ContainerTypeEntry::ListContainer: //baseName = "PyList"; @@ -576,12 +574,12 @@ QString ShibokenGenerator::cpythonTypeName(const AbstractMetaClass *metaClass) return cpythonTypeName(metaClass->typeEntry()); } -QString ShibokenGenerator::cpythonTypeName(const TypeEntry *type) +QString ShibokenGenerator::cpythonTypeName(const TypeEntryCPtr &type) { return cpythonBaseName(type) + u"_TypeF()"_s; } -QString ShibokenGenerator::cpythonTypeNameExt(const TypeEntry *type) +QString ShibokenGenerator::cpythonTypeNameExt(const TypeEntryCPtr &type) { return cppApiVariableName(type->targetLangPackage()) + u'[' + getTypeIndexVariableName(type) + u']'; @@ -609,7 +607,7 @@ QString ShibokenGenerator::converterObject(const AbstractMetaType &type) return converterObject(typeEntry); } -QString ShibokenGenerator::converterObject(const TypeEntry *type) +QString ShibokenGenerator::converterObject(const TypeEntryCPtr &type) { if (isExtendedCppPrimitive(type)) return QString::fromLatin1("Shiboken::Conversions::PrimitiveTypeConverter<%1>()") @@ -630,8 +628,8 @@ QString ShibokenGenerator::converterObject(const TypeEntry *type) } /* the typedef'd primitive types case */ - const auto *pte = dynamic_cast(type); - if (!pte) { + auto pte = qSharedPointerDynamicCast(type); + if (pte.isNull()) { qDebug() << "Warning: the Qt5 primitive type is unknown" << type->qualifiedCppName(); return QString(); } @@ -676,7 +674,7 @@ static QString _fixedCppTypeName(QString typeName) typeName.replace(u"&"_s, u"REF"_s); return typeName; } -QString ShibokenGenerator::fixedCppTypeName(const TypeEntry *type, QString typeName) +QString ShibokenGenerator::fixedCppTypeName(const TypeEntryCPtr &type, QString typeName) { if (typeName.isEmpty()) typeName = type->qualifiedCppName(); @@ -723,21 +721,21 @@ bool ShibokenGenerator::isNumber(const QString &cpythonApiName) } static std::optional - targetLangApiCPythonType(const PrimitiveTypeEntry *t) + targetLangApiCPythonType(const PrimitiveTypeEntryCPtr &t) { if (!t->hasTargetLangApiType()) return {}; - const auto *cte = t->targetLangApiType(); + const auto cte = t->targetLangApiType(); if (cte->type() != TypeEntry::PythonType) return {}; - return static_cast(cte)->cPythonType(); + return qSharedPointerCast(cte)->cPythonType(); } -bool ShibokenGenerator::isNumber(const TypeEntry *type) +bool ShibokenGenerator::isNumber(const TypeEntryCPtr &type) { if (!type->isPrimitive()) return false; - const auto *pte = basicReferencedTypeEntry(type->asPrimitive()); + const auto pte = basicReferencedTypeEntry(type); const auto cPythonTypeOpt = targetLangApiCPythonType(pte); // FIXME PYSIDE-1660: Return false here after making primitive types built-in? if (!cPythonTypeOpt.has_value()) { @@ -756,11 +754,11 @@ bool ShibokenGenerator::isNumber(const AbstractMetaType &type) return isNumber(type.typeEntry()); } -bool ShibokenGenerator::isPyInt(const TypeEntry *type) +bool ShibokenGenerator::isPyInt(const TypeEntryCPtr &type) { if (!type->isPrimitive()) return false; - const auto *pte = basicReferencedTypeEntry(type->asPrimitive()); + const auto pte = basicReferencedTypeEntry(type); const auto cPythonTypeOpt = targetLangApiCPythonType(pte); // FIXME PYSIDE-1660: Return false here after making primitive types built-in? if (!cPythonTypeOpt.has_value()) { @@ -784,9 +782,9 @@ bool ShibokenGenerator::isNullPtr(const QString &value) QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType) { - const auto *typeEntry = metaType.typeEntry(); + const auto typeEntry = metaType.typeEntry(); if (typeEntry->isCustom()) { - const auto *cte = static_cast(typeEntry); + const auto cte = qSharedPointerCast(typeEntry); if (cte->hasCheckFunction()) return cte->checkFunction(); throw Exception(msgUnknownCheckFunction(typeEntry)); @@ -803,7 +801,7 @@ QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType) if (typeEntry->isContainer()) { QString typeCheck = u"Shiboken::Conversions::"_s; ContainerTypeEntry::ContainerKind type = - static_cast(typeEntry)->containerKind(); + qSharedPointerCast(typeEntry)->containerKind(); if (type == ContainerTypeEntry::ListContainer || type == ContainerTypeEntry::SetContainer) { const QString containerType = type == ContainerTypeEntry::SetContainer @@ -851,10 +849,10 @@ QString ShibokenGenerator::cpythonCheckFunction(AbstractMetaType metaType) return cpythonCheckFunction(typeEntry); } -QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type) +QString ShibokenGenerator::cpythonCheckFunction(TypeEntryCPtr type) { if (type->isCustom()) { - const auto *cte = static_cast(type); + const auto cte = qSharedPointerCast(type); if (cte->hasCheckFunction()) return cte->checkFunction(); throw Exception(msgUnknownCheckFunction(type)); @@ -864,28 +862,26 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type) return u"SbkObject_TypeCheck("_s + cpythonTypeNameExt(type) + u", "_s; if (type->isPrimitive()) - type = basicReferencedTypeEntry(type->asPrimitive()); + type = basicReferencedTypeEntry(type); - if (auto *tla = type->targetLangApiType()) { + if (auto tla = type->targetLangApiType()) { if (tla->hasCheckFunction()) return tla->checkFunction(); } - if (isExtendedCppPrimitive(type)) { - const auto *pte = type->asPrimitive(); - return pythonPrimitiveTypeName(pte->name()) + u"_Check"_s; - } + if (isExtendedCppPrimitive(type)) + return pythonPrimitiveTypeName(type->name()) + u"_Check"_s; return cpythonIsConvertibleFunction(type); } -QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry *type) +QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntryCPtr &type) { if (type->isWrapperType()) { QString result = u"Shiboken::Conversions::"_s; bool isValue = false; if (type->isValue()) { - const auto *cte = static_cast(type); + const auto cte = qSharedPointerCast(type); isValue = !cte->isValueTypeWithCopyConstructorOnly(); } result += isValue ? u"isPythonToCppValueConvertible"_s @@ -899,9 +895,9 @@ QString ShibokenGenerator::cpythonIsConvertibleFunction(const TypeEntry *type) QString ShibokenGenerator::cpythonIsConvertibleFunction(AbstractMetaType metaType) { - const auto *typeEntry = metaType.typeEntry(); + const auto typeEntry = metaType.typeEntry(); if (typeEntry->isCustom()) { - const auto *cte = static_cast(typeEntry); + const auto cte = qSharedPointerCast(typeEntry); if (cte->hasCheckFunction()) return cte->checkFunction(); throw Exception(msgUnknownCheckFunction(typeEntry)); @@ -990,7 +986,7 @@ QString ShibokenGenerator::cpythonToPythonConversionFunction(const AbstractMetaC return cpythonToPythonConversionFunction(metaClass->typeEntry()); } -QString ShibokenGenerator::cpythonToPythonConversionFunction(const TypeEntry *type) +QString ShibokenGenerator::cpythonToPythonConversionFunction(const TypeEntryCPtr &type) { if (type->isWrapperType()) { const QString conversion = type->isValue() ? u"copy"_s : u"pointer"_s; @@ -1163,7 +1159,7 @@ ShibokenGenerator::ExtendedConverterData ShibokenGenerator::getExtendedConverter for (const auto &convOp : overloads) { // Get only the conversion operators that return a type from another module, // that are value-types and were not removed in the type system. - const TypeEntry *convType = convOp->type().typeEntry(); + const auto convType = convOp->type().typeEntry(); if (convType->generateCode() || !convType->isValue() || convOp->isModifiedRemoved()) continue; @@ -1177,7 +1173,7 @@ QList ShibokenGenerator::getPrimitiveCustomConversions() { QList conversions; const auto &primitiveTypeList = primitiveTypes(); - for (const PrimitiveTypeEntry *type : primitiveTypeList) { + for (const auto &type : primitiveTypeList) { if (type->shouldGenerate() && isUserPrimitive(type) && type->hasCustomConversion()) conversions << type->customConversion(); } @@ -1852,7 +1848,7 @@ QString ShibokenGenerator::getPrivateModuleHeaderFileName(const QString &moduleN IncludeGroupList ShibokenGenerator::classIncludes(const AbstractMetaClass *metaClass) const { IncludeGroupList result; - auto *typeEntry = metaClass->typeEntry(); + const auto typeEntry = metaClass->typeEntry(); //Extra includes result.append(IncludeGroup{u"Extra includes"_s, typeEntry->extraIncludes()}); @@ -2214,10 +2210,10 @@ QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaClass *met { return getTypeIndexVariableName(metaClass->typeEntry()); } -QString ShibokenGenerator::getTypeIndexVariableName(const TypeEntry *type) +QString ShibokenGenerator::getTypeIndexVariableName(TypeEntryCPtr type) { if (isCppPrimitive(type)) - type = basicReferencedTypeEntry(type->asPrimitive()); + type = basicReferencedTypeEntry(type); QString result = u"SBK_"_s; // Disambiguate namespaces per module to allow for extending them. if (type->isNamespace()) { @@ -2271,7 +2267,7 @@ QString ShibokenGenerator::minimalConstructorExpression(const ApiExtractorResult } QString ShibokenGenerator::minimalConstructorExpression(const ApiExtractorResult &api, - const TypeEntry *type) + const TypeEntryCPtr &type) { if (isExtendedCppPrimitive(type)) return {}; diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.h b/sources/shiboken6/generator/shiboken/shibokengenerator.h index 1b7168e31..d0b1158c6 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.h +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.h @@ -78,7 +78,7 @@ public: static QString minimalConstructorExpression(const ApiExtractorResult &api, const AbstractMetaType &type); static QString minimalConstructorExpression(const ApiExtractorResult &api, - const TypeEntry *type); + const TypeEntryCPtr &type); protected: bool doSetup() override; @@ -181,7 +181,7 @@ protected: FunctionGeneration functionGeneration(const AbstractMetaFunctionCPtr &func) const; // Return a list of implicit conversions if generation is enabled. - AbstractMetaFunctionCList implicitConversions(const TypeEntry *t) const; + AbstractMetaFunctionCList implicitConversions(const TypeEntryCPtr &t) const; QString wrapperName(const AbstractMetaClass *metaClass) const; @@ -198,29 +198,29 @@ protected: static QString fixedCppTypeName(const TargetToNativeConversion &toNative); static QString fixedCppTypeName(const AbstractMetaType &type); - static QString fixedCppTypeName(const TypeEntry *type, QString typeName = QString()); + static QString fixedCppTypeName(const TypeEntryCPtr &type, QString typeName = {}); static bool isNumber(const QString &cpythonApiName); - static bool isNumber(const TypeEntry *type); + static bool isNumber(const TypeEntryCPtr &type); static bool isNumber(const AbstractMetaType &type); - static bool isPyInt(const TypeEntry *type); + static bool isPyInt(const TypeEntryCPtr &type); static bool isPyInt(const AbstractMetaType &type); static bool isNullPtr(const QString &value); static QString converterObject(const AbstractMetaType &type) ; - static QString converterObject(const TypeEntry *type); + static QString converterObject(const TypeEntryCPtr &type); static QString cpythonBaseName(const AbstractMetaClass *metaClass); - static QString cpythonBaseName(const TypeEntry *type); + static QString cpythonBaseName(const TypeEntryCPtr &type); static QString cpythonBaseName(const AbstractMetaType &type); static QString cpythonTypeName(const AbstractMetaClass *metaClass); - static QString cpythonTypeName(const TypeEntry *type); - static QString cpythonTypeNameExt(const TypeEntry *type); + static QString cpythonTypeName(const TypeEntryCPtr &type); + static QString cpythonTypeNameExt(const TypeEntryCPtr &type); static QString cpythonTypeNameExt(const AbstractMetaType &type) ; - static QString cpythonCheckFunction(const TypeEntry *type); + static QString cpythonCheckFunction(TypeEntryCPtr type); static QString cpythonCheckFunction(AbstractMetaType metaType); - static QString cpythonIsConvertibleFunction(const TypeEntry *type); + static QString cpythonIsConvertibleFunction(const TypeEntryCPtr &type); static QString cpythonIsConvertibleFunction(AbstractMetaType metaType); static QString cpythonIsConvertibleFunction(const AbstractMetaArgument &metaArg); @@ -230,7 +230,7 @@ protected: static QString cpythonToPythonConversionFunction(const AbstractMetaType &type, const AbstractMetaClass *context = nullptr); static QString cpythonToPythonConversionFunction(const AbstractMetaClass *metaClass); - static QString cpythonToPythonConversionFunction(const TypeEntry *type); + static QString cpythonToPythonConversionFunction(const TypeEntryCPtr &type); static QString cpythonFunctionName(const AbstractMetaFunctionCPtr &func) ; static QString cpythonMethodDefinitionName(const AbstractMetaFunctionCPtr &func); @@ -247,12 +247,12 @@ protected: const QString &argName = QStringLiteral("self")); static QString cpythonWrapperCPtr(const AbstractMetaType &metaType, const QString &argName); - static QString cpythonWrapperCPtr(const TypeEntry *type, const QString &argName); + static QString cpythonWrapperCPtr(const TypeEntryCPtr &type, const QString &argName); - static QString cpythonEnumName(const EnumTypeEntry *enumEntry); + static QString cpythonEnumName(const EnumTypeEntryCPtr &enumEntry); static QString cpythonEnumName(const AbstractMetaEnum &metaEnum); - static QString cpythonFlagsName(const FlagsTypeEntry *flagsEntry); + static QString cpythonFlagsName(const FlagsTypeEntryCPtr &flagsEntry); static QString cpythonFlagsName(const AbstractMetaEnum *metaEnum); /// Returns the special cast function name, the function used to proper cast class with multiple inheritance. static QString cpythonSpecialCastFunctionName(const AbstractMetaClass *metaClass); @@ -287,7 +287,7 @@ protected: /// Returns the type index variable name for a given typedef for a template /// class instantiation made of the template class and the instantiation values static QString getTypeAlternateTemplateIndexVariableName(const AbstractMetaClass *metaClass); - static QString getTypeIndexVariableName(const TypeEntry *type); + static QString getTypeIndexVariableName(TypeEntryCPtr type); static QString getTypeIndexVariableName(const AbstractMetaType &type) ; /// Returns true if the user don't want verbose error messages on the generated bindings. @@ -301,7 +301,7 @@ protected: // All data about extended converters: the type entries of the target type, and a // list of AbstractMetaClasses accepted as argument for the conversion. - using ExtendedConverterData = QHash; + using ExtendedConverterData = QHash; /// Returns all extended conversions for the current module. ExtendedConverterData getExtendedConverters() const; -- cgit v1.2.3