diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-29 09:36:12 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2020-09-30 13:08:58 +0200 |
commit | faf7c506a451cef1dc8229a3779eb62796c93e5f (patch) | |
tree | a7064dd88244a74bca9c467f6f4c1e6bda599bcb /sources/shiboken2/ApiExtractor | |
parent | 433fbf103e96ba62eedcd563d5a8c71f4e5cd5a0 (diff) |
shiboken2: Refactor handling of invisible top level namespaces
To avoid having to add a
ShibokenGenerator::lookForFunctionsInClassesNotToBeGenerated()
to fix the function issue,
replace ShibokenGenerator::lookForEnumsInClassesNotToBeGenerated()
by several helper functions:
- Add a list of top level invisible namespace to the generators
- Add functions to retrieve enumerations of nested invisible namespaces
to AbstractMetaClass with recursion helpers.
Task-number: PYSIDE-1075
Change-Id: I421113770e622611caeb221498b872d0a6ba1aeb
Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken2/ApiExtractor')
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.cpp | 24 | ||||
-rw-r--r-- | sources/shiboken2/ApiExtractor/abstractmetalang.h | 17 |
2 files changed, 41 insertions, 0 deletions
diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp index 2c693c70e..29c2f153d 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.cpp +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.cpp @@ -1637,6 +1637,14 @@ bool AbstractMetaClass::isNamespace() const return m_typeEntry->isNamespace(); } +// Is an invisible namespaces whose functions/enums +// should be mapped to the global space. +bool AbstractMetaClass::isInvisibleNamespace() const +{ + return m_typeEntry->isNamespace() && m_typeEntry->generateCode() + && !NamespaceTypeEntry::isVisibleScope(m_typeEntry); +} + static bool qObjectPredicate(const AbstractMetaClass *c) { return c->qualifiedCppName() == QLatin1String("QObject"); @@ -2128,6 +2136,22 @@ AbstractMetaEnumValue *AbstractMetaClass::findEnumValue(const QString &enumValue return nullptr; } +void AbstractMetaClass::getEnumsToBeGenerated(AbstractMetaEnumList *enumList) const +{ + for (AbstractMetaEnum *metaEnum : m_enums) { + if (!metaEnum->isPrivate() && metaEnum->typeEntry()->generateCode()) + enumList->append(metaEnum); + } +} + +void AbstractMetaClass::getEnumsFromInvisibleNamespacesToBeGenerated(AbstractMetaEnumList *enumList) const +{ + if (isNamespace()) { + invisibleNamespaceRecursion([enumList](AbstractMetaClass *c) { + c->getEnumsToBeGenerated(enumList); + }); + } +} static void addExtraIncludeForType(AbstractMetaClass *metaClass, const AbstractMetaType *type) { diff --git a/sources/shiboken2/ApiExtractor/abstractmetalang.h b/sources/shiboken2/ApiExtractor/abstractmetalang.h index 648c792b3..693ecc4d4 100644 --- a/sources/shiboken2/ApiExtractor/abstractmetalang.h +++ b/sources/shiboken2/ApiExtractor/abstractmetalang.h @@ -1426,6 +1426,8 @@ public: AbstractMetaEnum *findEnum(const QString &enumName); AbstractMetaEnumValue *findEnumValue(const QString &enumName); + void getEnumsToBeGenerated(AbstractMetaEnumList *enumList) const; + void getEnumsFromInvisibleNamespacesToBeGenerated(AbstractMetaEnumList *enumList) const; QString fullName() const { @@ -1476,6 +1478,7 @@ public: QString package() const; bool isNamespace() const; + bool isInvisibleNamespace() const; bool isQObject() const; @@ -1672,6 +1675,9 @@ public: SourceLocation sourceLocation() const; void setSourceLocation(const SourceLocation &sourceLocation); + template <class Function> + void invisibleNamespaceRecursion(Function f) const; + private: #ifndef QT_NO_DEBUG_STREAM void format(QDebug &d) const; @@ -1719,4 +1725,15 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaClass::FunctionQueryOptions) Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractMetaClass::OperatorQueryOptions) +template <class Function> +void AbstractMetaClass::invisibleNamespaceRecursion(Function f) const +{ + for (auto ic : m_innerClasses) { + if (ic->isInvisibleNamespace()) { + f(ic); + ic->invisibleNamespaceRecursion(f); + } + } +} + #endif // ABSTRACTMETALANG_H |