at master 7.5 kB view raw
1From: Friedemann Kleint <Friedemann.Kleint@qt.io> 2Date: Thu, 27 Apr 2023 12:44:10 +0200 3Subject: shiboken2/clang: Record scope resolution of arguments/function 4 return 5 6Add a flag indicating whether a type was specified with a leading "::" 7(scope resolution). Such parameters previously caused the function to 8rejected due to the "::TypeName" not being found. The type resolution 9added for clang 16 strips these qualifiers though, so, the information 10needs to be stored. 11 12Task-number: PYSIDE-2288 13Pick-to: 6.5 5.15 14Change-Id: I27d27c94ec43bcc4cb3b79e6e9ce6706c749a1e9 15Reviewed-by: Christian Tismer <tismer@stackless.com> 16(cherry picked from commit 075d8ad4660f05e6d2583ff1c05e9987ad624bfe) 17--- 18 .../ApiExtractor/clangparser/clangbuilder.cpp | 8 ++++++-- 19 .../ApiExtractor/clangparser/clangutils.cpp | 11 ++++++++++ 20 .../ApiExtractor/clangparser/clangutils.h | 1 + 21 .../shiboken2/ApiExtractor/parser/codemodel.cpp | 24 ++++++++++++++++++++++ 22 sources/shiboken2/ApiExtractor/parser/codemodel.h | 8 ++++++++ 23 5 files changed, 50 insertions(+), 2 deletions(-) 24 25diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp 26index ed1e15d..1b5cc5c 100644 27--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp 28+++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp 29@@ -294,7 +294,9 @@ FunctionModelItem BuilderPrivate::createFunction(const CXCursor &cursor, 30 name = fixTypeName(name); 31 FunctionModelItem result(new _FunctionModelItem(m_model, name)); 32 setFileName(cursor, result.data()); 33- result->setType(createTypeInfoHelper(clang_getCursorResultType(cursor))); 34+ const auto type = clang_getCursorResultType(cursor); 35+ result->setType(createTypeInfoHelper(type)); 36+ result->setScopeResolution(hasScopeResolution(type)); 37 result->setFunctionType(t); 38 result->setScope(m_scope); 39 result->setStatic(clang_Cursor_getStorageClass(cursor) == CX_SC_Static); 40@@ -1031,7 +1033,9 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor) 41 if (d->m_currentArgument.isNull() && !d->m_currentFunction.isNull()) { 42 const QString name = getCursorSpelling(cursor); 43 d->m_currentArgument.reset(new _ArgumentModelItem(d->m_model, name)); 44- d->m_currentArgument->setType(d->createTypeInfo(cursor)); 45+ const auto type = clang_getCursorType(cursor); 46+ d->m_currentArgument->setScopeResolution(hasScopeResolution(type)); 47+ d->m_currentArgument->setType(d->createTypeInfo(type)); 48 d->m_currentFunction->addArgument(d->m_currentArgument); 49 QString defaultValueExpression = d->cursorValueExpression(this, cursor); 50 if (!defaultValueExpression.isEmpty()) { 51diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp 52index 295ede3..ec6d228 100644 53--- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp 54+++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp 55@@ -155,6 +155,17 @@ QString getTypeName(const CXType &type) 56 return result; 57 } 58 59+// Quick check for "::Type" 60+bool hasScopeResolution(const CXType &type) 61+{ 62+ CXString typeSpelling = clang_getTypeSpelling(type); 63+ const QString spelling = QString::fromUtf8(clang_getCString(typeSpelling)); 64+ const bool result = spelling.startsWith(QLatin1String("::")) 65+ || spelling.contains(QLatin1String(" ::")); 66+ clang_disposeString(typeSpelling); 67+ return result; 68+} 69+ 70 // Resolve elaborated types occurring with clang 16 71 QString getResolvedTypeName(const CXType &type) 72 { 73diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h 74index aacaf63..33f362c 100644 75--- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h 76+++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h 77@@ -52,6 +52,7 @@ QString getCursorKindName(CXCursorKind cursorKind); 78 QString getCursorSpelling(const CXCursor &cursor); 79 QString getCursorDisplayName(const CXCursor &cursor); 80 QString getTypeName(const CXType &type); 81+bool hasScopeResolution(const CXType &type); 82 QString getResolvedTypeName(const CXType &type); 83 inline QString getCursorTypeName(const CXCursor &cursor) 84 { return getTypeName(clang_getCursorType(cursor)); } 85diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp 86index dea0812..ba07a01 100644 87--- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp 88+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp 89@@ -1121,11 +1121,23 @@ void _ArgumentModelItem::setDefaultValue(bool defaultValue) 90 m_defaultValue = defaultValue; 91 } 92 93+bool _ArgumentModelItem::scopeResolution() const 94+{ 95+ return m_scopeResolution; 96+} 97+ 98+void _ArgumentModelItem::setScopeResolution(bool v) 99+{ 100+ m_scopeResolution = v; 101+} 102+ 103 #ifndef QT_NO_DEBUG_STREAM 104 void _ArgumentModelItem::formatDebug(QDebug &d) const 105 { 106 _CodeModelItem::formatDebug(d); 107 d << ", type=" << m_type; 108+ if (m_scopeResolution) 109+ d << ", [m_scope resolution]"; 110 if (m_defaultValue) 111 d << ", defaultValue=\"" << m_defaultValueExpression << '"'; 112 } 113@@ -1200,6 +1212,16 @@ void _FunctionModelItem::setVariadics(bool isVariadics) 114 m_isVariadics = isVariadics; 115 } 116 117+bool _FunctionModelItem::scopeResolution() const 118+{ 119+ return m_scopeResolution; 120+} 121+ 122+void _FunctionModelItem::setScopeResolution(bool v) 123+{ 124+ m_scopeResolution = v; 125+} 126+ 127 bool _FunctionModelItem::isNoExcept() const 128 { 129 return m_exceptionSpecification == ExceptionSpecification::NoExcept; 130@@ -1343,6 +1365,8 @@ void _FunctionModelItem::formatDebug(QDebug &d) const 131 d << " [explicit]"; 132 if (m_isInvokable) 133 d << " [invokable]"; 134+ if (m_scopeResolution) 135+ d << " [scope resolution]"; 136 formatModelItemList(d, ", arguments=", m_arguments); 137 if (m_isVariadics) 138 d << ",..."; 139diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h 140index b990ad9..85f298c 100644 141--- a/sources/shiboken2/ApiExtractor/parser/codemodel.h 142+++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h 143@@ -499,6 +499,10 @@ public: 144 QString defaultValueExpression() const { return m_defaultValueExpression; } 145 void setDefaultValueExpression(const QString &expr) { m_defaultValueExpression = expr; } 146 147+ // Argument type has scope resolution "::ArgumentType" 148+ bool scopeResolution() const; 149+ void setScopeResolution(bool v); 150+ 151 #ifndef QT_NO_DEBUG_STREAM 152 void formatDebug(QDebug &d) const override; 153 #endif 154@@ -507,6 +511,7 @@ private: 155 TypeInfo m_type; 156 QString m_defaultValueExpression; 157 bool m_defaultValue = false; 158+ bool m_scopeResolution = false; 159 }; 160 161 class _MemberModelItem: public _CodeModelItem 162@@ -623,6 +628,8 @@ public: 163 bool isVariadics() const; 164 void setVariadics(bool isVariadics); 165 166+ bool scopeResolution() const; // Return type has scope resolution "::ReturnType" 167+ void setScopeResolution(bool v); 168 169 bool isSimilar(const FunctionModelItem &other) const; 170 171@@ -652,6 +659,7 @@ private: 172 uint m_isExplicit: 1; 173 uint m_isVariadics: 1; 174 uint m_isInvokable : 1; // Qt 175+ uint m_scopeResolution: 1; 176 }; 177 uint m_flags; 178 };