diff options
-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: |