diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-11-14 10:50:57 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-11-17 18:14:28 +0100 |
commit | cf4f1a7488ba3202b44081eade36debf1d665e8f (patch) | |
tree | 15c65874973b87de4e96ec08f80c3ab0a264ae8b | |
parent | e9a406d871a74242555f4b75715fe36950e6788c (diff) |
shiboken6: Make some TypeEntry query functions free functions
Some query functions like TypeEntry::typeSystemTypeEntry() search in
the hierarchy, starting with "this". This cannot be ported to smart
pointers, so the functions are changed to be free functions where the
first element has to be passed in.
Change-Id: I3122b648ad499a2236577f6a101e8637a2f87d55
Reviewed-by: Christian Tismer <tismer@stackless.com>
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
15 files changed, 104 insertions, 98 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp index 5d3321f50..499f79874 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp @@ -959,7 +959,7 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseTypeDef(const FileModelIt // It is a (nested?) global typedef to a primitive type // (like size_t = unsigned)? Add it to the type DB. - if (pTarget && pTarget->basicReferencedNonBuiltinTypeEntry()->isCppPrimitive() + if (pTarget && isCppPrimitive(basicReferencedNonBuiltinTypeEntry(pTarget)) && currentClass == nullptr) { auto *pte = new PrimitiveTypeEntry(className, {}, nullptr); pte->setReferencedTypeEntry(pTarget); @@ -1092,7 +1092,7 @@ AbstractMetaClass *AbstractMetaBuilderPrivate::traverseClass(const FileModelItem TemplateParameterList template_parameters = classItem->templateParameters(); TypeEntryCList template_args; template_args.clear(); - auto argumentParent = metaClass->typeEntry()->typeSystemTypeEntry(); + auto argumentParent = typeSystemTypeEntry(metaClass->typeEntry()); for (qsizetype i = 0; i < template_parameters.size(); ++i) { const TemplateParameterModelItem ¶m = template_parameters.at(i); auto param_type = new TemplateArgumentEntry(param->name(), type->version(), @@ -2260,7 +2260,7 @@ TypeEntryCList AbstractMetaBuilderPrivate::findTypeEntries(const QString &qualif for (qsizetype i = 0, size = types.size(); i < size; ++i) { const auto *e = types.at(i); if (e->isPrimitive()) - types[i] = e->asPrimitive()->basicReferencedNonBuiltinTypeEntry(); + types[i] = basicReferencedNonBuiltinTypeEntry(e->asPrimitive()); } if (types.size() == 1) @@ -2451,7 +2451,7 @@ static AbstractMetaClass *createSmartPointerClass(const SmartPointerTypeEntry *s auto *result = new AbstractMetaClass(); result->setTypeEntry(const_cast<SmartPointerTypeEntry *>(ste)); auto *templateArg = new TemplateArgumentEntry(u"T"_s, ste->version(), - ste->typeSystemTypeEntry()); + typeSystemTypeEntry(ste)); result->setTemplateArguments({templateArg}); fixSmartPointerClass(result, ste); auto *enclosingTe = ste->parent(); @@ -2652,7 +2652,8 @@ std::optional<AbstractMetaType> if (!targType.has_value()) { const QString value = ti.qualifiedName().join(colonColon()); if (isNumber(value)) { - TypeDatabase::instance()->addConstantValueTypeEntry(value, type->typeSystemTypeEntry()); + auto *module = typeSystemTypeEntry(type); + TypeDatabase::instance()->addConstantValueTypeEntry(value, module); targType = translateTypeStatic(ti, currentClass, d, flags, &errorMessage); } } @@ -3061,7 +3062,7 @@ bool AbstractMetaBuilderPrivate::inheritTemplate(AbstractMetaClass *subclass, if (isNumber(typeName)) { t = typeDb->findType(typeName); if (!t) { - auto parent = subclass->typeEntry()->typeSystemTypeEntry(); + auto parent = typeSystemTypeEntry(subclass->typeEntry()); t = TypeDatabase::instance()->addConstantValueTypeEntry(typeName, parent); } } else { diff --git a/sources/shiboken6/ApiExtractor/abstractmetafield.cpp b/sources/shiboken6/ApiExtractor/abstractmetafield.cpp index e0c8a2678..06bdbee1e 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafield.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafield.cpp @@ -202,7 +202,7 @@ TypeSystem::SnakeCase AbstractMetaField::snakeCase() const auto typeEntry = enclosingClass()->typeEntry(); const auto snakeCase = typeEntry->snakeCase(); return snakeCase != TypeSystem::SnakeCase::Unspecified - ? snakeCase : typeEntry->typeSystemTypeEntry()->snakeCase(); + ? snakeCase : typeSystemTypeEntry(typeEntry)->snakeCase(); } FieldModificationList AbstractMetaField::modifications() const diff --git a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp index 4d115e8b7..0dae7a4c4 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetafunction.cpp @@ -225,7 +225,7 @@ bool AbstractMetaFunction::returnsBool() const if (d->m_type.typeUsagePattern() != AbstractMetaType::PrimitivePattern) return false; const auto *pte = d->m_type.typeEntry()->asPrimitive(); - return pte->basicReferencedTypeEntry()->name() == u"bool"; + return basicReferencedTypeEntry(pte)->name() == u"bool"; } bool AbstractMetaFunction::isOperatorBool() const @@ -1472,14 +1472,14 @@ TypeSystem::SnakeCase AbstractMetaFunction::snakeCase() const if (d->m_typeEntry) { // Global function const auto snakeCase = d->m_typeEntry->snakeCase(); return snakeCase != TypeSystem::SnakeCase::Unspecified - ? snakeCase : d->m_typeEntry->typeSystemTypeEntry()->snakeCase(); + ? snakeCase : typeSystemTypeEntry(d->m_typeEntry)->snakeCase(); } if (d->m_class) { auto typeEntry = d->m_class->typeEntry(); const auto snakeCase = typeEntry->snakeCase(); return snakeCase != TypeSystem::SnakeCase::Unspecified - ? snakeCase : typeEntry->typeSystemTypeEntry()->snakeCase(); + ? snakeCase : typeSystemTypeEntry(typeEntry)->snakeCase(); } return TypeSystem::SnakeCase::Disabled; } diff --git a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp index e260429ff..c3f6a71ec 100644 --- a/sources/shiboken6/ApiExtractor/abstractmetatype.cpp +++ b/sources/shiboken6/ApiExtractor/abstractmetatype.cpp @@ -656,7 +656,7 @@ QString AbstractMetaType::formatPythonSignature() const bool AbstractMetaType::isCppPrimitive() const { - return d->m_pattern == PrimitivePattern && d->m_typeEntry->isCppPrimitive(); + return d->m_pattern == PrimitivePattern && ::isCppPrimitive(d->m_typeEntry); } bool AbstractMetaType::isConstant() const @@ -827,7 +827,7 @@ bool AbstractMetaType::isVoidPointer() const bool AbstractMetaType::isUserPrimitive() const { - return d->m_indirections.isEmpty() && d->m_typeEntry->isUserPrimitive(); + return d->m_indirections.isEmpty() && ::isUserPrimitive(d->m_typeEntry); } bool AbstractMetaType::isObjectTypeUsedAsValueType() const @@ -854,7 +854,7 @@ bool AbstractMetaType::isWrapperPassedByReference() const bool AbstractMetaType::isCppIntegralPrimitive() const { - return d->m_typeEntry->isCppIntegralPrimitive(); + return ::isCppIntegralPrimitive(d->m_typeEntry); } bool AbstractMetaType::isExtendedCppPrimitive() const @@ -863,7 +863,7 @@ bool AbstractMetaType::isExtendedCppPrimitive() const return true; if (!d->m_indirections.isEmpty()) return false; - return d->m_typeEntry->isExtendedCppPrimitive(); + return ::isExtendedCppPrimitive(d->m_typeEntry); } bool AbstractMetaType::isValueTypeWithCopyConstructorOnly() const diff --git a/sources/shiboken6/ApiExtractor/apiextractor.cpp b/sources/shiboken6/ApiExtractor/apiextractor.cpp index 8c0286f7d..62b12362e 100644 --- a/sources/shiboken6/ApiExtractor/apiextractor.cpp +++ b/sources/shiboken6/ApiExtractor/apiextractor.cpp @@ -602,9 +602,9 @@ static bool generateOpaqueContainer(const AbstractMetaType &type, const TypeSystemTypeEntry *moduleEntry) { auto *te = type.instantiations().constFirst().typeEntry(); - auto *typeModuleEntry = te->typeSystemTypeEntry(); + auto *typeModuleEntry = typeSystemTypeEntry(te); return typeModuleEntry == moduleEntry - || (te->isPrimitive() && type.typeEntry()->typeSystemTypeEntry() == moduleEntry); + || (te->isPrimitive() && typeSystemTypeEntry(type.typeEntry()) == moduleEntry); } void ApiExtractorPrivate::collectInstantiatedOpqaqueContainers(InstantiationCollectContext &context) diff --git a/sources/shiboken6/ApiExtractor/primitivetypeentry.h b/sources/shiboken6/ApiExtractor/primitivetypeentry.h index f9864eb66..1ed60a855 100644 --- a/sources/shiboken6/ApiExtractor/primitivetypeentry.h +++ b/sources/shiboken6/ApiExtractor/primitivetypeentry.h @@ -36,18 +36,6 @@ public: */ void setReferencedTypeEntry(PrimitiveTypeEntry *referencedTypeEntry); - /// Finds the most basic primitive type that the typedef represents, - /// 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; - - /// 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; - /// Returns whether this entry references another entry. bool referencesType() const; @@ -68,4 +56,16 @@ protected: explicit PrimitiveTypeEntry(PrimitiveTypeEntryPrivate *d); }; +/// Finds the most basic primitive type that the typedef represents, +/// 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); + +/// 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); + #endif // PRIMITIVETYPEENTRY_H diff --git a/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.cpp b/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.cpp index b7df94a62..8dc9b641b 100644 --- a/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.cpp +++ b/sources/shiboken6/ApiExtractor/tests/testnumericaltypedef.cpp @@ -40,12 +40,12 @@ void TestNumericalTypedef::testNumericalTypedef() const AbstractMetaType doubleType = funcDouble->arguments().constFirst().type(); QCOMPARE(doubleType.cppSignature(), u"double"); QVERIFY(doubleType.isPrimitive()); - QVERIFY(doubleType.typeEntry()->isCppPrimitive()); + QVERIFY(isCppPrimitive(doubleType.typeEntry())); const AbstractMetaType realType = funcReal->arguments().constFirst().type(); QCOMPARE(realType.cppSignature(), u"real"); QVERIFY(realType.isPrimitive()); - QVERIFY(realType.typeEntry()->isCppPrimitive()); + QVERIFY(isCppPrimitive(realType.typeEntry())); } void TestNumericalTypedef::testUnsignedNumericalTypedef() @@ -78,12 +78,12 @@ void TestNumericalTypedef::testUnsignedNumericalTypedef() const AbstractMetaType unsignedShortType = funcUnsignedShort->arguments().constFirst().type(); QCOMPARE(unsignedShortType.cppSignature(), u"unsigned short"); QVERIFY(unsignedShortType.isPrimitive()); - QVERIFY(unsignedShortType.typeEntry()->isCppPrimitive()); + QVERIFY(isCppPrimitive(unsignedShortType.typeEntry())); const AbstractMetaType ushortType = funcUShort->arguments().constFirst().type(); QCOMPARE(ushortType.cppSignature(), u"custom_ushort"); QVERIFY(ushortType.isPrimitive()); - QVERIFY(ushortType.typeEntry()->isCppPrimitive()); + QVERIFY(isCppPrimitive(ushortType.typeEntry())); } QTEST_APPLESS_MAIN(TestNumericalTypedef) diff --git a/sources/shiboken6/ApiExtractor/typedatabase.cpp b/sources/shiboken6/ApiExtractor/typedatabase.cpp index a53af364a..c37d4fc53 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken6/ApiExtractor/typedatabase.cpp @@ -1328,9 +1328,9 @@ QDebug operator<<(QDebug debug, const formatPrimitiveEntry &fe) debug << " (\"" << targetLangName << "\")"; if (fe.m_pe->isBuiltIn()) debug << " [builtin]"; - if (fe.m_pe->isExtendedCppPrimitive()) { + if (isExtendedCppPrimitive(fe.m_pe)) { debug << " ["; - if (!fe.m_pe->isCppPrimitive()) + if (!isCppPrimitive(fe.m_pe)) debug << "extended "; debug << "C++]"; } @@ -1371,7 +1371,7 @@ void TypeDatabase::formatBuiltinTypes(QDebug debug) const for (auto *e : std::as_const(d->m_entries)) { if (e->isPrimitive()) { auto *pe = static_cast<const PrimitiveTypeEntry *>(e); - auto *basic = pe->basicReferencedTypeEntry(); + auto *basic = basicReferencedTypeEntry(pe); if (basic != pe) { const auto idx = indexOf(primitiveEntries, basic); if (idx != -1) diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index e3dfd741e..95c817897 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -140,16 +140,16 @@ QVersionNumber TypeEntry::version() const return m_d->m_version; } -bool TypeEntry::isCppPrimitive() const +bool isCppPrimitive(const TypeEntry *e) { - if (!isPrimitive()) + if (!e->isPrimitive()) return false; - if (m_d->m_type == VoidType) + if (e->type() == TypeEntry::VoidType) return true; const PrimitiveTypeEntry *referencedType = - static_cast<const PrimitiveTypeEntry *>(this)->basicReferencedTypeEntry(); + basicReferencedTypeEntry(e->asPrimitive()); const QString &typeName = referencedType->name(); return AbstractMetaType::cppPrimitiveTypes().contains(typeName); } @@ -178,18 +178,18 @@ bool TypeEntry::isChildOf(const TypeEntry *p) const return false; } -const TypeSystemTypeEntry *TypeEntry::typeSystemTypeEntry() const +const TypeSystemTypeEntry *typeSystemTypeEntry(const TypeEntry *e) { - for (auto e = this; e; e = e->parent()) { + for (; e; e = e->parent()) { if (e->type() == TypeEntry::TypeSystemType) return static_cast<const TypeSystemTypeEntry *>(e); } return nullptr; } -const TypeEntry *TypeEntry::targetLangEnclosingEntry() const +const TypeEntry *targetLangEnclosingEntry(const TypeEntry *e) { - auto result = m_d->m_parent; + auto result = e->parent(); while (result && result->type() != TypeEntry::TypeSystemType && !NamespaceTypeEntry::isVisibleScope(result)) { result = result->parent(); @@ -465,12 +465,12 @@ const PrimitiveTypeEntry *TypeEntry::asPrimitive() const return static_cast<const PrimitiveTypeEntry *>(this); } -bool TypeEntry::isUserPrimitive() const +bool isUserPrimitive(const TypeEntry *e) { - if (!isPrimitive()) + if (!e->isPrimitive()) return false; - const auto *type = asPrimitive()->basicReferencedTypeEntry(); - return !type->isCppPrimitive() + const auto *type = basicReferencedTypeEntry(e->asPrimitive()); + return !isCppPrimitive(type) && type->qualifiedCppName() != u"std::string"; } @@ -479,21 +479,21 @@ bool TypeEntry::isWrapperType() const return isObject() || isValue() || isSmartPointer(); } -bool TypeEntry::isCppIntegralPrimitive() const +bool isCppIntegralPrimitive(const TypeEntry *e) { - if (!isCppPrimitive()) + if (!isCppPrimitive(e)) return false; - const auto *type = asPrimitive()->basicReferencedTypeEntry(); + const auto *type = basicReferencedTypeEntry(e->asPrimitive()); return AbstractMetaType::cppIntegralTypes().contains(type->qualifiedCppName()); } -bool TypeEntry::isExtendedCppPrimitive() const +bool isExtendedCppPrimitive(const TypeEntry *e) { - if (isCppPrimitive()) + if (isCppPrimitive(e)) return true; - if (!isPrimitive()) + if (!e->isPrimitive()) return false; - const auto *type = asPrimitive()->basicReferencedTypeEntry(); + const auto *type = basicReferencedTypeEntry(e->asPrimitive()); const QString &name = type->qualifiedCppName(); return name == u"std::string" || name == u"std::wstring"; } @@ -563,7 +563,7 @@ TypeEntry *TypeEntry::clone() const void TypeEntry::useAsTypedef(const TypeEntry *source) { // XML Typedefs are in the global namespace for now. - m_d->m_parent = source->typeSystemTypeEntry(); + m_d->m_parent = typeSystemTypeEntry(source); m_d->m_entryName = source->m_d->m_entryName; m_d->m_name = source->m_d->m_name; m_d->m_targetLangPackage = source->m_d->m_targetLangPackage; @@ -888,17 +888,17 @@ void PrimitiveTypeEntry::setReferencedTypeEntry(PrimitiveTypeEntry *referencedTy d->m_referencedTypeEntry = referencedTypeEntry; } -const PrimitiveTypeEntry *PrimitiveTypeEntry::basicReferencedTypeEntry() const +const PrimitiveTypeEntry *basicReferencedTypeEntry(const PrimitiveTypeEntry *e) { - auto *result = this; + auto *result = e; while (auto *referenced = result->referencedTypeEntry()) result = referenced; return result; } -const PrimitiveTypeEntry *PrimitiveTypeEntry::basicReferencedNonBuiltinTypeEntry() const +const PrimitiveTypeEntry *basicReferencedNonBuiltinTypeEntry(const PrimitiveTypeEntry *e) { - auto *result = this; + auto *result = e; for (; result->referencedTypeEntry() ; result = result->referencedTypeEntry()) { if (!result->isBuiltIn()) break; diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h index c3304d630..e207fe9ea 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.h +++ b/sources/shiboken6/ApiExtractor/typesystem.h @@ -69,9 +69,6 @@ public: const TypeEntry *parent() const; void setParent(const TypeEntry *p); bool isChildOf(const TypeEntry *p) const; - const TypeSystemTypeEntry *typeSystemTypeEntry() const; - // cf AbstractMetaClass::targetLangEnclosingClass() - const TypeEntry *targetLangEnclosingEntry() const; bool isPrimitive() const; bool isEnum() const; @@ -160,8 +157,6 @@ public: QVersionNumber version() const; - bool isCppPrimitive() const; - // View on: Type to use for function argument conversion, fex // std::string_view -> std::string for foo(std::string_view). // cf AbstractMetaType::viewOn() @@ -178,17 +173,9 @@ public: const PrimitiveTypeEntry *asPrimitive() const; // Query functions for generators - /// Returns true if the type is a primitive but not a C++ primitive. - bool isUserPrimitive() const; /// Returns true if the type passed has a Python wrapper for it. /// Although namespace has a Python wrapper, it's not considered a type. bool isWrapperType() const; - /// Returns true if the type is a C++ integral primitive, - /// i.e. bool, char, int, long, and their unsigned counterparts. - bool isCppIntegralPrimitive() const; - /// Returns true if the type is an extended C++ primitive, a void*, - /// a const char*, or a std::string (cf isCppPrimitive()). - bool isExtendedCppPrimitive() const; #ifndef QT_NO_DEBUG_STREAM virtual void formatDebug(QDebug &d) const; @@ -208,4 +195,22 @@ private: QScopedPointer<TypeEntryPrivate> m_d; }; +const TypeSystemTypeEntry *typeSystemTypeEntry(const TypeEntry *e); + +// cf AbstractMetaClass::targetLangEnclosingClass() +const TypeEntry *targetLangEnclosingEntry(const TypeEntry *e); + +bool isCppPrimitive(const TypeEntry *e); + +/// Returns true if the type is a primitive but not a C++ primitive. +bool isUserPrimitive(const TypeEntry *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); + +/// 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); + #endif // TYPESYSTEM_H diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp index 769cfe27d..cf73a9bb0 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp @@ -1321,7 +1321,7 @@ FlagsTypeEntry * return nullptr; auto ftype = new FlagsTypeEntry(u"QFlags<"_s + enumEntry->name() + u'>', since, - currentParentTypeEntry()->typeSystemTypeEntry()); + typeSystemTypeEntry(currentParentTypeEntry())); ftype->setOriginator(enumEntry); ftype->setTargetLangPackage(enumEntry->targetLangPackage()); // Try toenumEntry get the guess the qualified flag name diff --git a/sources/shiboken6/generator/generator.cpp b/sources/shiboken6/generator/generator.cpp index 14fa50014..5975e54e6 100644 --- a/sources/shiboken6/generator/generator.cpp +++ b/sources/shiboken6/generator/generator.cpp @@ -281,7 +281,7 @@ QString Generator::getFullTypeName(const TypeEntry *type) QString result = type->qualifiedCppName(); if (type->isArray()) type = static_cast<const ArrayTypeEntry *>(type)->nestedTypeEntry(); - if (!type->isCppPrimitive()) + if (!isCppPrimitive(type)) result.prepend(u"::"_s); return result; } @@ -396,7 +396,7 @@ std::optional<DefaultValue> if (!type) return {}; - if (type->isCppPrimitive()) { + if (isCppPrimitive(type)) { const QString &name = type->qualifiedCppName(); return name == u"bool" ? DefaultValue(DefaultValue::Boolean) @@ -491,7 +491,7 @@ std::optional<DefaultValue> const AbstractMetaArgument &arg = arguments.at(i); const TypeEntry *aType = arg.type().typeEntry(); suitable &= aType != cType; - simple &= aType->isCppPrimitive() || aType->isEnum() || arg.type().isPointer(); + simple &= isCppPrimitive(aType) || aType->isEnum() || arg.type().isPointer(); } if (suitable) candidates.insert(arguments.size() + (simple ? 0 : 100), ctor); @@ -547,7 +547,7 @@ QString Generator::translateType(AbstractMetaType cType, copyType.setReferenceType(NoReference); s = copyType.cppSignature(); - if (!copyType.typeEntry()->isVoid() && !copyType.typeEntry()->isCppPrimitive()) + if (!copyType.typeEntry()->isVoid() && !isCppPrimitive(copyType.typeEntry())) s.prepend(u"::"_s); } else { s = cType.cppSignature(); diff --git a/sources/shiboken6/generator/shiboken/cppgenerator.cpp b/sources/shiboken6/generator/shiboken/cppgenerator.cpp index ce4f8a74c..fbe7f183e 100644 --- a/sources/shiboken6/generator/shiboken/cppgenerator.cpp +++ b/sources/shiboken6/generator/shiboken/cppgenerator.cpp @@ -1295,7 +1295,7 @@ QPair<QString, QChar> CppGenerator::virtualMethodNativeArg(const AbstractMetaFun auto *argTypeEntry = type.typeEntry(); // Check for primitive types convertible by Py_BuildValue() if (argTypeEntry->isPrimitive() && !type.isCString()) { - const auto *pte = argTypeEntry->asPrimitive()->basicReferencedTypeEntry(); + const auto *pte = basicReferencedTypeEntry(argTypeEntry->asPrimitive()); auto it = formatUnits().constFind(pte->name()); if (it != formatUnits().constEnd()) return {arg.name(), it.value()}; @@ -2828,7 +2828,7 @@ void CppGenerator::writeTypeCheck(TextStream &s, const AbstractMetaType &argType if (!argType.typeEntry()->isCustom()) { typeCheck = u'(' + pythonToCppConverterForArgumentName(argumentName) + u" = "_s + typeCheck + u"))"_s; - if (!isNumber && argType.typeEntry()->isCppPrimitive()) { + if (!isNumber && isCppPrimitive(argType.typeEntry())) { typeCheck.prepend(cpythonCheckFunction(argType) + u'(' + argumentName + u") && "_s); } @@ -5393,7 +5393,7 @@ static ComparisonOperatorList smartPointeeComparisons(const GeneratorContext &co { Q_ASSERT(context.forSmartPointer()); auto *te = context.preciseType().instantiations().constFirst().typeEntry(); - if (te->isExtendedCppPrimitive()) { // Primitive pointee types have all + if (isExtendedCppPrimitive(te)) { // Primitive pointee types have all return {AbstractMetaFunction::OperatorEqual, AbstractMetaFunction::OperatorNotEqual, AbstractMetaFunction::OperatorLess, @@ -6623,7 +6623,7 @@ bool CppGenerator::finishGeneration() if (shouldGenerate(te)) { writeInitFunc(s_classInitDecl, s_classPythonDefines, getSimpleClassInitFunctionName(cls), - te->targetLangEnclosingEntry()); + targetLangEnclosingEntry(te)); if (cls->hasStaticFields()) { s_classInitDecl << "void " << getSimpleClassStaticFieldsInitFunctionName(cls) << "();\n"; @@ -6638,7 +6638,7 @@ bool CppGenerator::finishGeneration() auto *enclosingClass = context.metaClass()->enclosingClass(); auto *enclosingTypeEntry = enclosingClass != nullptr ? enclosingClass->typeEntry() - : smp.type.typeEntry()->targetLangEnclosingEntry(); + : targetLangEnclosingEntry(smp.type.typeEntry()); writeInitFunc(s_classInitDecl, s_classPythonDefines, getInitFunctionName(context), enclosingTypeEntry); @@ -6946,11 +6946,11 @@ bool CppGenerator::finishGeneration() s << "// Register primitive types converters.\n"; const PrimitiveTypeEntryCList &primitiveTypeList = primitiveTypes(); for (const PrimitiveTypeEntry *pte : primitiveTypeList) { - if (!pte->generateCode() || !pte->isCppPrimitive()) + if (!pte->generateCode() || !isCppPrimitive(pte)) continue; if (!pte->referencesType()) continue; - const TypeEntry *referencedType = pte->basicReferencedTypeEntry(); + const auto *referencedType = basicReferencedTypeEntry(pte); QString converter = converterObject(referencedType); QStringList cppSignature = pte->qualifiedCppName().split(u"::"_s, Qt::SkipEmptyParts); while (!cppSignature.isEmpty()) { diff --git a/sources/shiboken6/generator/shiboken/overloaddata.cpp b/sources/shiboken6/generator/shiboken/overloaddata.cpp index 6bcadd83a..e42e52990 100644 --- a/sources/shiboken6/generator/shiboken/overloaddata.cpp +++ b/sources/shiboken6/generator/shiboken/overloaddata.cpp @@ -33,14 +33,14 @@ static QString getTypeName(const AbstractMetaType &type) { const TypeEntry *typeEntry = type.typeEntry(); if (typeEntry->isPrimitive()) - typeEntry = typeEntry->asPrimitive()->basicReferencedTypeEntry(); + typeEntry = basicReferencedTypeEntry(typeEntry->asPrimitive()); QString typeName = typeEntry->name(); if (typeEntry->isContainer()) { QStringList types; for (const auto &cType : type.instantiations()) { const TypeEntry *typeEntry = cType.typeEntry(); if (typeEntry->isPrimitive()) - typeEntry = typeEntry->asPrimitive()->basicReferencedTypeEntry(); + typeEntry = basicReferencedTypeEntry(typeEntry->asPrimitive()); types << typeEntry->name(); } typeName += u'<' + types.join(u',') + u" >"_s; diff --git a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp index e549ef982..a39fe1f5e 100644 --- a/sources/shiboken6/generator/shiboken/shibokengenerator.cpp +++ b/sources/shiboken6/generator/shiboken/shibokengenerator.cpp @@ -538,7 +538,7 @@ QString ShibokenGenerator::cpythonBaseName(const TypeEntry *type) if (type->isWrapperType() || type->isNamespace()) { // && type->referenceType() == NoReference) { baseName = u"Sbk_"_s + type->name(); } else if (type->isPrimitive()) { - const auto *ptype = type->asPrimitive()->basicReferencedTypeEntry(); + const auto *ptype = basicReferencedTypeEntry(type->asPrimitive()); baseName = ptype->hasTargetLangApiType() ? ptype->targetLangApiName() : pythonPrimitiveTypeName(ptype->name()); } else if (type->isEnum()) { @@ -611,7 +611,7 @@ QString ShibokenGenerator::converterObject(const AbstractMetaType &type) QString ShibokenGenerator::converterObject(const TypeEntry *type) { - if (type->isExtendedCppPrimitive()) + if (isExtendedCppPrimitive(type)) return QString::fromLatin1("Shiboken::Conversions::PrimitiveTypeConverter<%1>()") .arg(type->qualifiedCppName()); if (type->isWrapperType()) @@ -635,8 +635,8 @@ QString ShibokenGenerator::converterObject(const TypeEntry *type) qDebug() << "Warning: the Qt5 primitive type is unknown" << type->qualifiedCppName(); return QString(); } - pte = pte->basicReferencedTypeEntry(); - if (pte->isPrimitive() && !pte->isCppPrimitive() && !pte->customConversion()) { + pte = basicReferencedTypeEntry(pte); + if (pte->isPrimitive() && !isCppPrimitive(pte) && !pte->customConversion()) { return u"Shiboken::Conversions::PrimitiveTypeConverter<"_s + pte->qualifiedCppName() + u">()"_s; } @@ -737,7 +737,7 @@ bool ShibokenGenerator::isNumber(const TypeEntry *type) { if (!type->isPrimitive()) return false; - const auto *pte = type->asPrimitive()->basicReferencedTypeEntry(); + const auto *pte = basicReferencedTypeEntry(type->asPrimitive()); const auto cPythonTypeOpt = targetLangApiCPythonType(pte); // FIXME PYSIDE-1660: Return false here after making primitive types built-in? if (!cPythonTypeOpt.has_value()) { @@ -760,7 +760,7 @@ bool ShibokenGenerator::isPyInt(const TypeEntry *type) { if (!type->isPrimitive()) return false; - const auto *pte = type->asPrimitive()->basicReferencedTypeEntry(); + const auto *pte = basicReferencedTypeEntry(type->asPrimitive()); const auto cPythonTypeOpt = targetLangApiCPythonType(pte); // FIXME PYSIDE-1660: Return false here after making primitive types built-in? if (!cPythonTypeOpt.has_value()) { @@ -864,14 +864,14 @@ QString ShibokenGenerator::cpythonCheckFunction(const TypeEntry *type) return u"SbkObject_TypeCheck("_s + cpythonTypeNameExt(type) + u", "_s; if (type->isPrimitive()) - type = type->asPrimitive()->basicReferencedTypeEntry(); + type = basicReferencedTypeEntry(type->asPrimitive()); if (auto *tla = type->targetLangApiType()) { if (tla->hasCheckFunction()) return tla->checkFunction(); } - if (type->isExtendedCppPrimitive()) { + if (isExtendedCppPrimitive(type)) { const auto *pte = type->asPrimitive(); return pythonPrimitiveTypeName(pte->name()) + u"_Check"_s; } @@ -1178,7 +1178,7 @@ QList<CustomConversionPtr> ShibokenGenerator::getPrimitiveCustomConversions() QList<CustomConversionPtr> conversions; const auto &primitiveTypeList = primitiveTypes(); for (const PrimitiveTypeEntry *type : primitiveTypeList) { - if (type->shouldGenerate() && type->isUserPrimitive() && type->hasCustomConversion()) + if (type->shouldGenerate() && isUserPrimitive(type) && type->hasCustomConversion()) conversions << type->customConversion(); } return conversions; @@ -2216,8 +2216,8 @@ QString ShibokenGenerator::getTypeIndexVariableName(const AbstractMetaClass *met } QString ShibokenGenerator::getTypeIndexVariableName(const TypeEntry *type) { - if (type->isCppPrimitive()) - type = type->asPrimitive()->basicReferencedTypeEntry(); + if (isCppPrimitive(type)) + type = basicReferencedTypeEntry(type->asPrimitive()); QString result = u"SBK_"_s; // Disambiguate namespaces per module to allow for extending them. if (type->isNamespace()) { @@ -2273,7 +2273,7 @@ QString ShibokenGenerator::minimalConstructorExpression(const ApiExtractorResult QString ShibokenGenerator::minimalConstructorExpression(const ApiExtractorResult &api, const TypeEntry *type) { - if (type->isExtendedCppPrimitive()) + if (isExtendedCppPrimitive(type)) return {}; const auto ctor = minimalConstructor(api, type); if (ctor.has_value()) |