diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-06-29 13:01:19 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-06-30 06:27:41 +0200 |
commit | 3eea22494846e31589555d1f9d38ba2600327e85 (patch) | |
tree | 52386a25eb1fcf38906a2b6d78875805d45900b2 /sources | |
parent | 492b58dbf7b597fec2bcb59f84ced2b3491c2494 (diff) |
shiboken2: Accept unqualified names for drop-type-entries
The option expected fully qualified type names
(PySide2.QtNetwork.QSslKey), but the PySide2 CMakeLists only
create unqualified names (QSslKey). Match this, too.
Change-Id: I6c86a4ef9bb1a6bdb6a0672454ac2f2806477408
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources')
-rw-r--r-- | sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp | 10 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/typesystemparser.cpp | 38 | ||||
-rw-r--r-- | sources/shiboken2/doc/shibokengenerator.rst | 4 |
3 files changed, 29 insertions, 23 deletions
diff --git a/sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp b/sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp index 6abebb922..7b3da182f 100644 --- a/sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testdroptypeentries.cpp @@ -66,10 +66,12 @@ static const char* xmlCode = "\ void TestDropTypeEntries::testDropEntries() { - QStringList droppedEntries(QLatin1String("Foo.ValueB")); - droppedEntries << QLatin1String("Foo.ObjectB") << QLatin1String("Foo.NamespaceA.InnerClassA"); - droppedEntries << QLatin1String("Foo.NamespaceB") << QLatin1String("Foo.EnumB") << QLatin1String("Foo.funcB()"); - droppedEntries << QLatin1String("Foo.NamespaceA.InnerNamespaceA"); + const QStringList droppedEntries{QLatin1String("Foo.ValueB"), + QLatin1String("ObjectB"), // Check whether module can be omitted + QLatin1String("Foo.NamespaceA.InnerClassA"), + QLatin1String("Foo.NamespaceB"), QLatin1String("Foo.EnumB"), + QLatin1String("Foo.funcB()"), + QLatin1String("Foo.NamespaceA.InnerNamespaceA")}; QScopedPointer<AbstractMetaBuilder> builder(TestUtil::parse(cppCode, xmlCode, false, QString(), droppedEntries)); QVERIFY(!builder.isNull()); diff --git a/sources/shiboken2/ApiExtractor/typesystemparser.cpp b/sources/shiboken2/ApiExtractor/typesystemparser.cpp index ff8f1d59d..207c99c7a 100644 --- a/sources/shiboken2/ApiExtractor/typesystemparser.cpp +++ b/sources/shiboken2/ApiExtractor/typesystemparser.cpp @@ -1070,19 +1070,23 @@ static bool convertRemovalAttribute(QStringView remove, Modification& mod, QStri return false; } -static void getNamePrefixRecursive(StackElement* element, QStringList& names) -{ - if (!element->parent || !element->parent->entry) - return; - getNamePrefixRecursive(element->parent, names); - names << element->parent->entry->name(); -} - -static QString getNamePrefix(StackElement* element) -{ - QStringList names; - getNamePrefixRecursive(element, names); - return names.join(QLatin1Char('.')); +// Check whether an entry should be dropped, allowing for dropping the module +// name (match 'Class' and 'Module.Class'). +static bool shouldDropTypeEntry(const TypeDatabase *db, + const StackElement *element, + QString name) +{ + for (auto e = element->parent; e ; e = e->parent) { + if (e->entry) { + if (e->entry->type() == TypeEntry::TypeSystemType) { + if (db->shouldDropTypeEntry(name)) // Unqualified + return true; + } + name.prepend(QLatin1Char('.')); + name.prepend(e->entry->name()); + } + } + return db->shouldDropTypeEntry(name); } // Returns empty string if there's no error. @@ -2728,11 +2732,9 @@ bool TypeSystemParser::startElement(const QXmlStreamReader &reader) } if (m_database->hasDroppedTypeEntries()) { - QString identifier = getNamePrefix(element) + QLatin1Char('.'); - identifier += element->type == StackElement::FunctionTypeEntry - ? attributes.value(signatureAttribute()).toString() - : name; - if (m_database->shouldDropTypeEntry(identifier)) { + const QString identifier = element->type == StackElement::FunctionTypeEntry + ? attributes.value(signatureAttribute()).toString() : name; + if (shouldDropTypeEntry(m_database, element, identifier)) { m_currentDroppedEntry = element; m_currentDroppedEntryDepth = 1; if (ReportHandler::isDebug(ReportHandler::SparseDebug)) { diff --git a/sources/shiboken2/doc/shibokengenerator.rst b/sources/shiboken2/doc/shibokengenerator.rst index b15ad5ada..c3000ac09 100644 --- a/sources/shiboken2/doc/shibokengenerator.rst +++ b/sources/shiboken2/doc/shibokengenerator.rst @@ -123,7 +123,9 @@ Options ``--drop-type-entries="<TypeEntry0>[;TypeEntry1;...]"`` Semicolon separated list of type system entries (classes, namespaces, - global functions and enums) to be dropped from generation. + global functions and enums) to be dropped from generation. Values are + fully qualified Python type names ('Module.Class'), but the module can + be omitted ('Class'). .. _generation-set: |