aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-17 11:24:39 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-09-17 12:12:45 +0200
commit6392ea613c1cf93a3fd793cd61050aa348ae1c7c (patch)
treeeb71393adb8b66f23b6429e5356bab3de6f02a61
parent0055c90694cbf8a82a4c3ee75d47b6d2538f6247 (diff)
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 <tismer@stackless.com>
-rw-r--r--sources/shiboken6/ApiExtractor/messages.cpp11
-rw-r--r--sources/shiboken6/ApiExtractor/messages.h3
-rw-r--r--sources/shiboken6/ApiExtractor/typedatabase.cpp10
-rw-r--r--sources/shiboken6/ApiExtractor/typedatabase.h1
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.cpp11
-rw-r--r--sources/shiboken6/ApiExtractor/typesystem.h3
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.cpp29
-rw-r--r--sources/shiboken6/ApiExtractor/typesystemparser.h2
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 <class Predicate>
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;