1 From: Friedemann Kleint <Friedemann.Kleint@qt.io>
2 Date: Thu, 27 Apr 2023 12:44:10 +0200
3 Subject: shiboken2/clang: Record scope resolution of arguments/function
6 Add a flag indicating whether a type was specified with a leading "::"
7 (scope resolution). Such parameters previously caused the function to
8 rejected due to the "::TypeName" not being found. The type resolution
9 added for clang 16 strips these qualifiers though, so, the information
12 Task-number: PYSIDE-2288
14 Change-Id: I27d27c94ec43bcc4cb3b79e6e9ce6706c749a1e9
15 Reviewed-by: Christian Tismer <tismer@stackless.com>
16 (cherry picked from commit 075d8ad4660f05e6d2583ff1c05e9987ad624bfe)
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(-)
25 diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
26 index 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()) {
51 diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
52 index 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)
59 +// Quick check for "::Type"
60 +bool hasScopeResolution(const CXType &type)
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);
70 // Resolve elaborated types occurring with clang 16
71 QString getResolvedTypeName(const CXType &type)
73 diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
74 index 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)); }
85 diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
86 index 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;
93 +bool _ArgumentModelItem::scopeResolution() const
95 + return m_scopeResolution;
98 +void _ArgumentModelItem::setScopeResolution(bool v)
100 + m_scopeResolution = v;
103 #ifndef QT_NO_DEBUG_STREAM
104 void _ArgumentModelItem::formatDebug(QDebug &d) const
106 _CodeModelItem::formatDebug(d);
107 d << ", type=" << m_type;
108 + if (m_scopeResolution)
109 + d << ", [m_scope resolution]";
111 d << ", defaultValue=\"" << m_defaultValueExpression << '"';
113 @@ -1200,6 +1212,16 @@ void _FunctionModelItem::setVariadics(bool isVariadics)
114 m_isVariadics = isVariadics;
117 +bool _FunctionModelItem::scopeResolution() const
119 + return m_scopeResolution;
122 +void _FunctionModelItem::setScopeResolution(bool v)
124 + m_scopeResolution = v;
127 bool _FunctionModelItem::isNoExcept() const
129 return m_exceptionSpecification == ExceptionSpecification::NoExcept;
130 @@ -1343,6 +1365,8 @@ void _FunctionModelItem::formatDebug(QDebug &d) const
134 + if (m_scopeResolution)
135 + d << " [scope resolution]";
136 formatModelItemList(d, ", arguments=", m_arguments);
139 diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h
140 index 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; }
147 + // Argument type has scope resolution "::ArgumentType"
148 + bool scopeResolution() const;
149 + void setScopeResolution(bool v);
151 #ifndef QT_NO_DEBUG_STREAM
152 void formatDebug(QDebug &d) const override;
154 @@ -507,6 +511,7 @@ private:
156 QString m_defaultValueExpression;
157 bool m_defaultValue = false;
158 + bool m_scopeResolution = false;
161 class _MemberModelItem: public _CodeModelItem
162 @@ -623,6 +628,8 @@ public:
163 bool isVariadics() const;
164 void setVariadics(bool isVariadics);
166 + bool scopeResolution() const; // Return type has scope resolution "::ReturnType"
167 + void setScopeResolution(bool v);
169 bool isSimilar(const FunctionModelItem &other) const;
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;