diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-10-28 17:47:41 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-11-04 22:49:07 +0000 |
commit | f41b9d4c87af3a7bc7d30dee39797af12c30a3fa (patch) | |
tree | 284884e895cf08acc47876f4e2ae0aad326e804c /sources | |
parent | d1df2d00b3d82e72b7b4bd32adf4ffaf2d49ad68 (diff) |
shiboken6: Store a pointer to base classes in the code model
Extend the struct _ClassModelItem::BaseClass by an optional
ClassModelItem pointing to the class directly and populate it by the
builder. This is needed for implementing enum resolution in the code
model directly.
Task-number: PYSIDE-1691
Change-Id: I1abce6cbb777384ccbb187e79c09b5cb9da1563b
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit d4b4b15965139f282797a053dc84903f431eb1fa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'sources')
-rw-r--r-- | sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp | 14 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/parser/codemodel.cpp | 8 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/parser/codemodel.h | 3 |
3 files changed, 9 insertions, 16 deletions
diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp index 31adbb898..5ce33f433 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp +++ b/sources/shiboken6/ApiExtractor/clangparser/clangbuilder.cpp @@ -200,7 +200,7 @@ public: void addField(const CXCursor &cursor); static QString cursorValueExpression(BaseVisitor *bv, const CXCursor &cursor); - QString getBaseClassName(CXType type) const; + std::pair<QString, ClassModelItem> getBaseClass(CXType type) const; void addBaseClass(const CXCursor &cursor); template <class Item> @@ -702,7 +702,7 @@ static TypeDeclaration resolveType(CXType type) // Note: Return the baseclass for cursors like CXCursor_CXXBaseSpecifier, // where the cursor spelling has "struct baseClass". -QString BuilderPrivate::getBaseClassName(CXType type) const +std::pair<QString, ClassModelItem> BuilderPrivate::getBaseClass(CXType type) const { const auto decl = resolveType(type); // Note: spelling has "struct baseClass", use type @@ -725,7 +725,7 @@ QString BuilderPrivate::getBaseClassName(CXType type) const // "class X : public std::list<...>", "template<class T> class Foo : public T" // and standard types like true_type, false_type. if (it == m_cursorClassHash.constEnd()) - return baseClassName; + return {baseClassName, {}}; // Completely qualify the class name by looking it up and taking its scope // plus the actual baseClass stripped off any scopes. Consider: @@ -745,7 +745,7 @@ QString BuilderPrivate::getBaseClassName(CXType type) const baseClassName.prepend(colonColon()); baseClassName.prepend(baseScope.join(colonColon())); } - return baseClassName; + return {baseClassName, it.value()}; } // Add a base class to the current class from CXCursor_CXXBaseSpecifier @@ -753,8 +753,8 @@ void BuilderPrivate::addBaseClass(const CXCursor &cursor) { Q_ASSERT(clang_getCursorKind(cursor) == CXCursor_CXXBaseSpecifier); const auto access = accessPolicy(clang_getCXXAccessSpecifier(cursor)); - QString baseClassName = getBaseClassName(clang_getCursorType(cursor)); - m_currentClass->addBaseClass(baseClassName, access); + const auto baseClass = getBaseClass(clang_getCursorType(cursor)); + m_currentClass->addBaseClass({baseClass.first, baseClass.second, access}); } static inline CXCursor definitionFromTypeRef(const CXCursor &typeRefCursor) @@ -1173,7 +1173,7 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor) } else if (!d->m_currentField.isNull()) { d->qualifyTypeDef(cursor, d->m_currentField); } else if (d->m_withinUsingDeclaration && d->m_usingTypeRef.isEmpty()) { - d->m_usingTypeRef = d->getBaseClassName(clang_getCursorType(cursor)); + d->m_usingTypeRef = d->getBaseClass(clang_getCursorType(cursor)).first; } break; case CXCursor_CXXFinalAttr: diff --git a/sources/shiboken6/ApiExtractor/parser/codemodel.cpp b/sources/shiboken6/ApiExtractor/parser/codemodel.cpp index 1ea9f45f6..7d3b9aa83 100644 --- a/sources/shiboken6/ApiExtractor/parser/codemodel.cpp +++ b/sources/shiboken6/ApiExtractor/parser/codemodel.cpp @@ -377,14 +377,6 @@ void _ClassModelItem::setTemplateParameters(const TemplateParameterList &templat m_templateParameters = templateParameters; } -void _ClassModelItem::addBaseClass(const QString &name, Access accessPolicy) -{ - _ClassModelItem::BaseClass baseClass; - baseClass.name = name; - baseClass.accessPolicy = accessPolicy; - m_baseClasses.append(baseClass); -} - bool _ClassModelItem::extendsClass(const QString &name) const { for (const BaseClass &bc : m_baseClasses) { diff --git a/sources/shiboken6/ApiExtractor/parser/codemodel.h b/sources/shiboken6/ApiExtractor/parser/codemodel.h index 76abd47cf..6527ab7bb 100644 --- a/sources/shiboken6/ApiExtractor/parser/codemodel.h +++ b/sources/shiboken6/ApiExtractor/parser/codemodel.h @@ -266,6 +266,7 @@ public: struct BaseClass { QString name; + ClassModelItem klass; // Might be null in case of templates Access accessPolicy = Access::Public; }; @@ -288,7 +289,7 @@ public: void addUsingMember(const QString &className, const QString &memberName, Access accessPolicy); - void addBaseClass(const QString &name, Access accessPolicy); + void addBaseClass(const BaseClass &b) { m_baseClasses.append(b); } TemplateParameterList templateParameters() const; void setTemplateParameters(const TemplateParameterList &templateParameters); |