From 6392ea613c1cf93a3fd793cd61050aa348ae1c7c Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 17 Sep 2021 11:24:39 +0200 Subject: shiboken6: Add support for built-in types Add a built-in flag to TypeEntry and fix the duplicate type entry checking logic to handle built-in types with a different warning. Task-number: PYSIDE-1660 Change-Id: I22b0fc92b0f19b4163a4311441638176ff6a4bfb Reviewed-by: Christian Tismer --- sources/shiboken6/ApiExtractor/messages.cpp | 11 ++++++++ sources/shiboken6/ApiExtractor/messages.h | 3 +++ sources/shiboken6/ApiExtractor/typedatabase.cpp | 10 ++++++-- sources/shiboken6/ApiExtractor/typedatabase.h | 1 + sources/shiboken6/ApiExtractor/typesystem.cpp | 11 ++++++++ sources/shiboken6/ApiExtractor/typesystem.h | 3 +++ .../shiboken6/ApiExtractor/typesystemparser.cpp | 29 +++++++++++++++++++++- sources/shiboken6/ApiExtractor/typesystemparser.h | 2 ++ 8 files changed, 67 insertions(+), 3 deletions(-) diff --git a/sources/shiboken6/ApiExtractor/messages.cpp b/sources/shiboken6/ApiExtractor/messages.cpp index 1f79000e2..796d18c4b 100644 --- a/sources/shiboken6/ApiExtractor/messages.cpp +++ b/sources/shiboken6/ApiExtractor/messages.cpp @@ -811,3 +811,14 @@ QString msgUnknownTypeInArgumentTypeReplacement(const QString &typeReplaced, << "', the generated code may be broken."; return result; } + +QString msgDuplicateBuiltInTypeEntry(const QString &name) +{ + return u"A type entry duplicating the built-in type \""_qs + + name + u"\" was found. It is ignored."_qs; +} + +QString msgDuplicateTypeEntry(const QString &name) +{ + return u"Duplicate type entry: '"_qs + name + u"'."_qs; +} diff --git a/sources/shiboken6/ApiExtractor/messages.h b/sources/shiboken6/ApiExtractor/messages.h index 434d33ff5..cc8c00d02 100644 --- a/sources/shiboken6/ApiExtractor/messages.h +++ b/sources/shiboken6/ApiExtractor/messages.h @@ -234,4 +234,7 @@ QString msgPureVirtualFunctionRemoved(const AbstractMetaFunction *f); QString msgUnknownTypeInArgumentTypeReplacement(const QString &typeReplaced, const AbstractMetaFunction *f); +QString msgDuplicateBuiltInTypeEntry(const QString &name); +QString msgDuplicateTypeEntry(const QString &name); + #endif // MESSAGES_H diff --git a/sources/shiboken6/ApiExtractor/typedatabase.cpp b/sources/shiboken6/ApiExtractor/typedatabase.cpp index 596af53ca..6b63d2052 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken6/ApiExtractor/typedatabase.cpp @@ -59,8 +59,8 @@ Q_GLOBAL_STATIC(ApiVersions, apiVersions) TypeDatabase::TypeDatabase() { - addType(new VoidTypeEntry()); - addType(new VarargsTypeEntry()); + addBuiltInType(new VoidTypeEntry()); + addBuiltInType(new VarargsTypeEntry()); } TypeDatabase::~TypeDatabase() = default; @@ -939,6 +939,12 @@ void TypeDatabase::formatDebug(QDebug &d) const d << ')'; } +void TypeDatabase::addBuiltInType(TypeEntry *e) +{ + e->setBuiltIn(true); + addType(e); +} + QDebug operator<<(QDebug d, const TypeDatabase &db) { QDebugStateSaver saver(d); diff --git a/sources/shiboken6/ApiExtractor/typedatabase.h b/sources/shiboken6/ApiExtractor/typedatabase.h index f8878f896..347401968 100644 --- a/sources/shiboken6/ApiExtractor/typedatabase.h +++ b/sources/shiboken6/ApiExtractor/typedatabase.h @@ -212,6 +212,7 @@ public: void formatDebug(QDebug &d) const; #endif private: + void addBuiltInType(TypeEntry *e); TypeEntryMultiMapConstIteratorRange findTypeRange(const QString &name) const; template TypeEntries findTypesHelper(const QString &name, Predicate pred) const; diff --git a/sources/shiboken6/ApiExtractor/typesystem.cpp b/sources/shiboken6/ApiExtractor/typesystem.cpp index 91d40cfbf..678acefc3 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.cpp +++ b/sources/shiboken6/ApiExtractor/typesystem.cpp @@ -94,6 +94,7 @@ public: TypeEntry::Type m_type; bool m_stream = false; bool m_private = false; + bool m_builtin = false; }; TypeEntryPrivate::TypeEntryPrivate(const QString &entryName, TypeEntry::Type t, const QVersionNumber &vr, @@ -345,6 +346,16 @@ void TypeEntry::setStream(bool b) m_d->m_stream = b; } +bool TypeEntry::isBuiltIn() const +{ + return m_d->m_builtin; +} + +void TypeEntry::setBuiltIn(bool b) +{ + m_d->m_builtin = b; +} + bool TypeEntry::isPrivate() const { return m_d->m_private; diff --git a/sources/shiboken6/ApiExtractor/typesystem.h b/sources/shiboken6/ApiExtractor/typesystem.h index 04e81361c..f6a00cab5 100644 --- a/sources/shiboken6/ApiExtractor/typesystem.h +++ b/sources/shiboken6/ApiExtractor/typesystem.h @@ -147,6 +147,9 @@ public: bool stream() const; void setStream(bool b); + bool isBuiltIn() const; + void setBuiltIn(bool b); + bool isPrivate() const; void setPrivate(bool b); diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.cpp b/sources/shiboken6/ApiExtractor/typesystemparser.cpp index 8ad885089..7ba7860f4 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken6/ApiExtractor/typesystemparser.cpp @@ -2809,6 +2809,31 @@ bool TypeSystemParser::parseReplace(const ConditionalStreamReader &, return true; } +// Check for a duplicated type entry and return whether to add the new one. +// We need to be able to have duplicate primitive type entries, +// or it's not possible to cover all primitive target language +// types (which we need to do in order to support fake meta objects) +bool TypeSystemParser::checkDuplicatedTypeEntry(const ConditionalStreamReader &reader, + StackElement::ElementType t, + const QString &name) const +{ + if (t == StackElement::PrimitiveTypeEntry || t == StackElement::FunctionTypeEntry) + return true; + const auto *duplicated = m_database->findType(name); + if (!duplicated || duplicated->isNamespace()) + return true; + if (duplicated->isBuiltIn()) { + qCWarning(lcShiboken, "%s", + qPrintable(msgReaderMessage(reader, "Warning", + msgDuplicateBuiltInTypeEntry(name)))); + return false; + } + qCWarning(lcShiboken, "%s", + qPrintable(msgReaderMessage(reader, "Warning", + msgDuplicateTypeEntry(name)))); + return true; +} + static bool parseVersion(const QString &versionSpec, const QString &package, QVersionNumber *result, QString *errorMessage) { @@ -3038,8 +3063,10 @@ bool TypeSystemParser::startElement(const ConditionalStreamReader &reader) } if (element->entry) { - if (!m_database->addType(element->entry, &m_error)) + if (checkDuplicatedTypeEntry(reader, element->type, element->entry->name()) + && !m_database->addType(element->entry, &m_error)) { return false; + } } else { qCWarning(lcShiboken).noquote().nospace() << u"Type: "_qs + name + u" was rejected by typesystem"_qs; diff --git a/sources/shiboken6/ApiExtractor/typesystemparser.h b/sources/shiboken6/ApiExtractor/typesystemparser.h index f1e11d661..903e84421 100644 --- a/sources/shiboken6/ApiExtractor/typesystemparser.h +++ b/sources/shiboken6/ApiExtractor/typesystemparser.h @@ -259,6 +259,8 @@ private: QXmlStreamAttributes *); bool parseReplace(const ConditionalStreamReader &, const StackElement &topElement, StackElement *element, QXmlStreamAttributes *); + bool checkDuplicatedTypeEntry(const ConditionalStreamReader &reader, + StackElement::ElementType t, const QString &name) const; TypeDatabase* m_database; StackElement* m_current = nullptr; -- cgit v1.2.3