aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-12-18 19:16:59 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-12-21 17:55:54 +0100
commit44fc52f4f02e0f1c9fdbfa16d2bc1f6f073bfed0 (patch)
tree7fadf08d8d07e6686c0916712c82fc3aa6c1f159 /sources/shiboken6
parentdacd0e5f2c087478029b68d0b65ead7ba8a49e81 (diff)
shiboken6: Refactor base class retrieval
AbstractMetaClass has a list of base class names and a list of AbstractMetaClass* base instances. AbstractMetaBuilder populates the instance list from the names in setupInheritance() and sets a flag. In a few places in AbstractMetaBuilder, the base class instances are needed before this has been completed. For this purpose, the helper AbstractMetaBuilder::getBaseClasses() is needed. Replace the set of classes m_setupInheritanceDone by a flag on AbstractMetaClass. This allows for adding an assert to AbstractMetaClass::baseClasses() ensuring setupInheritance() has been called and taking a shortcut in AbstractMetaBuilder::getBaseClasses(). In addition, classesTopologicalSorted() can use AbstractMetaClass::baseClasses() instead of searching with AbstractMetaBuilder::getBaseClasses() and can thus be made static. Change-Id: Iaf8209b6f6534ad91a96970a56c1e86cce054922 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit e99ac18b134469854dff05fd3bb61158f9d9ccf9) Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp18
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder.h4
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h6
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetalang.cpp27
-rw-r--r--sources/shiboken6/ApiExtractor/abstractmetalang.h8
-rw-r--r--sources/shiboken6/ApiExtractor/apiextractor.cpp3
6 files changed, 49 insertions, 17 deletions
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
index ad354d901..9f2196d84 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.cpp
@@ -456,7 +456,7 @@ void AbstractMetaBuilderPrivate::traverseDom(const FileModelItem &dom)
ReportHandler::startProgress("Fixing class inheritance...");
for (AbstractMetaClass *cls : qAsConst(m_metaClasses)) {
- if (!cls->isNamespace()) {
+ if (cls->needsInheritanceSetup()) {
setupInheritance(cls);
if (cls->templateBaseClass())
inheritTemplateFunctions(cls);
@@ -1419,10 +1419,10 @@ void AbstractMetaBuilderPrivate::applyFunctionModifications(AbstractMetaFunction
bool AbstractMetaBuilderPrivate::setupInheritance(AbstractMetaClass *metaClass)
{
- if (m_setupInheritanceDone.contains(metaClass))
+ if (metaClass->inheritanceDone())
return true;
- m_setupInheritanceDone.insert(metaClass);
+ metaClass->setInheritanceDone(true);
QStringList baseClasses = metaClass->baseClassNames();
@@ -2590,6 +2590,9 @@ AbstractMetaClass* AbstractMetaBuilderPrivate::findTemplateClass(const QString &
AbstractMetaClassList AbstractMetaBuilderPrivate::getBaseClasses(const AbstractMetaClass *metaClass) const
{
+ // Shortcut if inheritance has already been set up
+ if (metaClass->inheritanceDone() || !metaClass->needsInheritanceSetup())
+ return metaClass->baseClasses();
AbstractMetaClassList baseClasses;
const QStringList &baseClassNames = metaClass->baseClassNames();
for (const QString& parent : baseClassNames) {
@@ -3015,7 +3018,7 @@ static bool addClassDependency(const AbstractMetaClassList &classList,
}
AbstractMetaClassList AbstractMetaBuilderPrivate::classesTopologicalSorted(const AbstractMetaClassList &classList,
- const Dependencies &additionalDependencies) const
+ const Dependencies &additionalDependencies)
{
ClassGraph graph(classList.cbegin(), classList.cend());
@@ -3033,8 +3036,7 @@ AbstractMetaClassList AbstractMetaBuilderPrivate::classesTopologicalSorted(const
graph.addEdge(enclosing, clazz);
}
- const AbstractMetaClassList &bases = getBaseClasses(clazz);
- for (AbstractMetaClass *baseClass : bases)
+ for (auto baseClass : clazz->baseClasses())
graph.addEdge(baseClass, clazz);
for (const auto &func : clazz->functions()) {
@@ -3101,9 +3103,9 @@ void AbstractMetaBuilderPrivate::pushScope(const NamespaceModelItem &item)
}
AbstractMetaClassList AbstractMetaBuilder::classesTopologicalSorted(const AbstractMetaClassList &classList,
- const Dependencies &additionalDependencies) const
+ const Dependencies &additionalDependencies)
{
- return d->classesTopologicalSorted(classList, additionalDependencies);
+ return AbstractMetaBuilderPrivate::classesTopologicalSorted(classList, additionalDependencies);
}
AbstractMetaArgumentList AbstractMetaBuilderPrivate::reverseList(const AbstractMetaArgumentList &list)
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h
index 5b0414cd0..2ad9db304 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder.h
@@ -77,8 +77,8 @@ public:
* Sorts a list of classes topologically.
* \return a list of classes sorted topologically
*/
- AbstractMetaClassList classesTopologicalSorted(const AbstractMetaClassList &classList,
- const Dependencies &additionalDependencies = Dependencies()) const;
+ static AbstractMetaClassList classesTopologicalSorted(const AbstractMetaClassList &classList,
+ const Dependencies &additionalDependencies = {});
bool build(const QByteArrayList &arguments,
LanguageLevel level = LanguageLevel::Default,
diff --git a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
index 4fd13adc9..80c7f76d3 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetabuilder_p.h
@@ -67,8 +67,8 @@ public:
void traverseDom(const FileModelItem &dom);
void dumpLog() const;
- AbstractMetaClassList classesTopologicalSorted(const AbstractMetaClassList &classList,
- const Dependencies &additionalDependencies = Dependencies()) const;
+ static AbstractMetaClassList classesTopologicalSorted(const AbstractMetaClassList &classList,
+ const Dependencies &additionalDependencies = {});
NamespaceModelItem popScope() { return m_scopes.takeLast(); }
void pushScope(const NamespaceModelItem &item);
@@ -206,8 +206,6 @@ public:
QList<NamespaceModelItem> m_scopes;
- QSet<AbstractMetaClass *> m_setupInheritanceDone;
-
QString m_logDirectory;
QFileInfoList m_globalHeaders;
QStringList m_headerPaths;
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
index 72d36bae7..114433163 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
+++ b/sources/shiboken6/ApiExtractor/abstractmetalang.cpp
@@ -57,6 +57,7 @@ public:
m_hasNonPrivateConstructor(false),
m_hasPrivateConstructor(false),
m_functionsFixed(false),
+ m_inheritanceDone(false),
m_hasPrivateDestructor(false),
m_hasProtectedDestructor(false),
m_hasVirtualDestructor(false),
@@ -74,6 +75,7 @@ public:
uint m_hasNonPrivateConstructor : 1;
uint m_hasPrivateConstructor : 1;
uint m_functionsFixed : 1;
+ uint m_inheritanceDone : 1; // m_baseClasses has been populated from m_baseClassNames
uint m_hasPrivateDestructor : 1;
uint m_hasProtectedDestructor : 1;
uint m_hasVirtualDestructor : 1;
@@ -425,6 +427,7 @@ AbstractMetaClass *AbstractMetaClass::baseClass() const
const AbstractMetaClassList &AbstractMetaClass::baseClasses() const
{
+ Q_ASSERT(inheritanceDone() || !needsInheritanceSetup());
return d->m_baseClasses;
}
@@ -1295,6 +1298,30 @@ void AbstractMetaClass::fixFunctions()
setFunctions(funcs);
}
+bool AbstractMetaClass::needsInheritanceSetup() const
+{
+ if (d->m_typeEntry != nullptr) {
+ switch (d->m_typeEntry->type()) {
+ case TypeEntry::NamespaceType:
+ case TypeEntry::SmartPointerType:
+ return false;
+ default:
+ break;
+ }
+ }
+ return true;
+}
+
+void AbstractMetaClass::setInheritanceDone(bool b)
+{
+ d->m_inheritanceDone = b;
+}
+
+bool AbstractMetaClass::inheritanceDone() const
+{
+ return d->m_inheritanceDone;
+}
+
/*******************************************************************************
* Other stuff...
*/
diff --git a/sources/shiboken6/ApiExtractor/abstractmetalang.h b/sources/shiboken6/ApiExtractor/abstractmetalang.h
index 2100f0eaa..61b5a092c 100644
--- a/sources/shiboken6/ApiExtractor/abstractmetalang.h
+++ b/sources/shiboken6/ApiExtractor/abstractmetalang.h
@@ -58,8 +58,6 @@ public:
AbstractMetaClass();
~AbstractMetaClass();
- void fixFunctions();
-
const AbstractMetaFunctionCList &functions() const;
void setFunctions(const AbstractMetaFunctionCList &functions);
void addFunction(const AbstractMetaFunctionCPtr &function);
@@ -305,6 +303,12 @@ public:
SourceLocation sourceLocation() const;
void setSourceLocation(const SourceLocation &sourceLocation);
+ // For AbstractMetaBuilder
+ void fixFunctions();
+ bool needsInheritanceSetup() const;
+ void setInheritanceDone(bool b);
+ bool inheritanceDone() const;
+
template <class Function>
void invisibleNamespaceRecursion(Function f) const;
diff --git a/sources/shiboken6/ApiExtractor/apiextractor.cpp b/sources/shiboken6/ApiExtractor/apiextractor.cpp
index bfae4cbc0..02f376bdb 100644
--- a/sources/shiboken6/ApiExtractor/apiextractor.cpp
+++ b/sources/shiboken6/ApiExtractor/apiextractor.cpp
@@ -149,7 +149,8 @@ const AbstractMetaClassList &ApiExtractor::smartPointers() const
AbstractMetaClassList ApiExtractor::classesTopologicalSorted(const Dependencies &additionalDependencies) const
{
Q_ASSERT(m_builder);
- return m_builder->classesTopologicalSorted(m_builder->classes(), additionalDependencies);
+ return AbstractMetaBuilder::classesTopologicalSorted(m_builder->classes(),
+ additionalDependencies);
}
PrimitiveTypeEntryList ApiExtractor::primitiveTypes() const