diff options
Diffstat (limited to 'sources/shiboken6/ApiExtractor')
11 files changed, 79 insertions, 73 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 |