From f41b9d4c87af3a7bc7d30dee39797af12c30a3fa Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 28 Oct 2021 17:47:41 +0200 Subject: 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 (cherry picked from commit d4b4b15965139f282797a053dc84903f431eb1fa) Reviewed-by: Qt Cherry-pick Bot --- .../shiboken6/ApiExtractor/clangparser/clangbuilder.cpp | 14 +++++++------- sources/shiboken6/ApiExtractor/parser/codemodel.cpp | 8 -------- sources/shiboken6/ApiExtractor/parser/codemodel.h | 3 ++- 3 files changed, 9 insertions(+), 16 deletions(-) (limited to 'sources') 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 getBaseClass(CXType type) const; void addBaseClass(const CXCursor &cursor); template @@ -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 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 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); -- cgit v1.2.3