aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-03-26 13:29:35 +0100
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2019-03-26 20:29:54 +0000
commit066dfadf24b64628fabe25097a86a41f62e73526 (patch)
tree2b59f2caecddc29532489ca845bdafb5e9a93127 /sources/shiboken2
parente6b746dc70203689960b8f57d9d6ef0463482415 (diff)
shiboken/Typedatabase: Store type system entries separately
This makes it easier to access the default type system entry, which will always be the first one in the list. Change-Id: Ie0844cef5fa4f0cd8bc50c28898e54a42845c830 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken2')
-rw-r--r--sources/shiboken2/ApiExtractor/tests/testextrainclude.cpp3
-rw-r--r--sources/shiboken2/ApiExtractor/tests/testinserttemplate.cpp4
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.cpp23
-rw-r--r--sources/shiboken2/ApiExtractor/typedatabase.h4
-rw-r--r--sources/shiboken2/ApiExtractor/typesystem.cpp7
-rw-r--r--sources/shiboken2/generator/generator.cpp18
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();