diff options
6 files changed, 38 insertions, 21 deletions
diff --git a/sources/shiboken2/ApiExtractor/tests/testextrainclude.cpp b/sources/shiboken2/ApiExtractor/tests/testextrainclude.cpp index 216101215..7e5664842 100644 --- a/sources/shiboken2/ApiExtractor/tests/testextrainclude.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testextrainclude.cpp @@ -73,8 +73,9 @@ void TestExtraInclude::testGlobalExtraIncludes() QVERIFY(AbstractMetaClass::findClass(classes, QLatin1String("A"))); TypeDatabase* td = TypeDatabase::instance(); - TypeEntry* module = td->findType(QLatin1String("Foo")); + const TypeSystemTypeEntry *module = td->defaultTypeSystemType(); QVERIFY(module); + QCOMPARE(module->name(), QLatin1String("Foo")); QVector<Include> includes = module->extraIncludes(); QCOMPARE(includes.count(), 2); diff --git a/sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp b/sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp index 8962f83ff..2d1692ee9 100644 --- a/sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp +++ b/sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp @@ -74,7 +74,9 @@ void TestInsertTemplate::testInsertTemplateOnModuleInjectCode() AbstractMetaClassList classes = builder->classes(); QVERIFY(classes.isEmpty()); - TypeEntry* module = TypeDatabase::instance()->findType(QLatin1String("Foo")); + const TypeSystemTypeEntry *module = TypeDatabase::instance()->defaultTypeSystemType(); + QVERIFY(module); + QCOMPARE(module->name(), QLatin1String("Foo")); QVERIFY(module); QCOMPARE(module->codeSnips().count(), 1); QString code = module->codeSnips().first().code().trimmed(); diff --git a/sources/shiboken2/ApiExtractor/typedatabase.cpp b/sources/shiboken2/ApiExtractor/typedatabase.cpp index c0999e7ab..4ce2790f5 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.cpp +++ b/sources/shiboken2/ApiExtractor/typedatabase.cpp @@ -182,16 +182,31 @@ FunctionTypeEntry* TypeDatabase::findFunctionType(const QString& name) const return 0; } +void TypeDatabase::addTypeSystemType(const TypeSystemTypeEntry *e) +{ + m_typeSystemEntries.append(e); +} + const TypeSystemTypeEntry *TypeDatabase::findTypeSystemType(const QString &name) const { - const auto entries = findTypes(name); - for (const TypeEntry *entry : entries) { - if (entry->type() == TypeEntry::TypeSystemType) - return static_cast<const TypeSystemTypeEntry *>(entry); + for (auto entry : m_typeSystemEntries) { + if (entry->name() == name) + return entry; } return nullptr; } +const TypeSystemTypeEntry *TypeDatabase::defaultTypeSystemType() const +{ + return m_typeSystemEntries.value(0, nullptr); +} + +QString TypeDatabase::defaultPackageName() const +{ + Q_ASSERT(!m_typeSystemEntries.isEmpty()); + return m_typeSystemEntries.constFirst()->name(); +} + TypeEntry* TypeDatabase::findType(const QString& name) const { const auto entries = findTypes(name); diff --git a/sources/shiboken2/ApiExtractor/typedatabase.h b/sources/shiboken2/ApiExtractor/typedatabase.h index 247d74362..0040364bf 100644 --- a/sources/shiboken2/ApiExtractor/typedatabase.h +++ b/sources/shiboken2/ApiExtractor/typedatabase.h @@ -91,6 +91,8 @@ public: ContainerTypeEntry* findContainerType(const QString& name) const; FunctionTypeEntry* findFunctionType(const QString& name) const; const TypeSystemTypeEntry *findTypeSystemType(const QString &name) const; + const TypeSystemTypeEntry *defaultTypeSystemType() const; + QString defaultPackageName() const; TypeEntry* findType(const QString& name) const; @@ -115,6 +117,7 @@ public: QString *reason = nullptr) const; bool addType(TypeEntry* e, QString *errorMessage = nullptr); + void addTypeSystemType(const TypeSystemTypeEntry *e); FlagsTypeEntry* findFlagsType(const QString& name) const; void addFlagsType(FlagsTypeEntry* fte); @@ -172,6 +175,7 @@ private: TypedefEntryMap m_typedefEntries; TemplateEntryMap m_templates; QVector<QRegularExpression> m_suppressedWarnings; + QVector<const TypeSystemTypeEntry *> m_typeSystemEntries; // maintain order, default is first. AddedFunctionList m_globalUserFunctions; FunctionModificationList m_functionMods; diff --git a/sources/shiboken2/ApiExtractor/typesystem.cpp b/sources/shiboken2/ApiExtractor/typesystem.cpp index 204253777..ad97e40ee 100644 --- a/sources/shiboken2/ApiExtractor/typesystem.cpp +++ b/sources/shiboken2/ApiExtractor/typesystem.cpp @@ -1509,7 +1509,8 @@ TypeSystemTypeEntry *Handler::parseRootElement(const QXmlStreamReader &, TypeSystemTypeEntry *moduleEntry = const_cast<TypeSystemTypeEntry *>(m_database->findTypeSystemType(m_defaultPackage)); - if (!moduleEntry) + const bool add = moduleEntry == nullptr; + if (add) moduleEntry = new TypeSystemTypeEntry(m_defaultPackage, since); moduleEntry->setCodeGeneration(m_generate); @@ -1517,8 +1518,8 @@ TypeSystemTypeEntry *Handler::parseRootElement(const QXmlStreamReader &, m_generate == TypeEntry::GenerateNothing) && !m_defaultPackage.isEmpty()) TypeDatabase::instance()->addRequiredTargetImport(m_defaultPackage); - if (!moduleEntry->qualifiedCppName().isEmpty()) - m_database->addType(moduleEntry); + if (add) + m_database->addTypeSystemType(moduleEntry); return moduleEntry; } diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp index ec227bd83..154a16ed3 100644 --- a/sources/shiboken2/generator/generator.cpp +++ b/sources/shiboken2/generator/generator.cpp @@ -176,19 +176,13 @@ Generator::~Generator() bool Generator::setup(const ApiExtractor& extractor) { m_d->apiextractor = &extractor; - const auto &allEntries = TypeDatabase::instance()->entries(); - TypeEntry* entryFound = 0; - for (auto it = allEntries.cbegin(), end = allEntries.cend(); it != end; ++it) { - TypeEntry *entry = it.value(); - if (entry->type() == TypeEntry::TypeSystemType && entry->generateCode()) { - entryFound = entry; - break; - } - } - if (entryFound) - m_d->packageName = entryFound->name(); - else + const auto moduleEntry = TypeDatabase::instance()->defaultTypeSystemType(); + if (!moduleEntry || !moduleEntry->generateCode()) { qCWarning(lcShiboken) << "Couldn't find the package name!!"; + return false; + } + + m_d->packageName = moduleEntry->name(); collectInstantiatedContainersAndSmartPointers(); |