shiboken2/clang: Record scope resolution of arguments/function return
authorFriedemann Kleint <Friedemann.Kleint@qt.io>
Thu, 27 Apr 2023 10:44:10 +0000 (12:44 +0200)
committerDmitry Shachnev <mitya57@debian.org>
Sun, 14 Apr 2024 20:48:11 +0000 (23:48 +0300)
Add a flag indicating whether a type was specified with a leading "::"
(scope resolution). Such parameters previously caused the function to
rejected due to the "::TypeName" not being found. The type resolution
added for clang 16 strips these qualifiers though, so, the information
needs to be stored.

Task-number: PYSIDE-2288
Pick-to: 6.5 5.15
Change-Id: I27d27c94ec43bcc4cb3b79e6e9ce6706c749a1e9
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit 075d8ad4660f05e6d2583ff1c05e9987ad624bfe)

Gbp-Pq: Name shiboken2-clang-Record-scope-resolution-of-arguments-func.patch

sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
sources/shiboken2/ApiExtractor/clangparser/clangutils.h
sources/shiboken2/ApiExtractor/parser/codemodel.cpp
sources/shiboken2/ApiExtractor/parser/codemodel.h

index ed1e15d4e778637abec94840537e04a0a5200a5b..1b5cc5c8f588c4c046a2cfdcccfc99ab8243bc72 100644 (file)
@@ -294,7 +294,9 @@ FunctionModelItem BuilderPrivate::createFunction(const CXCursor &cursor,
         name = fixTypeName(name);
     FunctionModelItem result(new _FunctionModelItem(m_model, name));
     setFileName(cursor, result.data());
-    result->setType(createTypeInfoHelper(clang_getCursorResultType(cursor)));
+    const auto type = clang_getCursorResultType(cursor);
+    result->setType(createTypeInfoHelper(type));
+    result->setScopeResolution(hasScopeResolution(type));
     result->setFunctionType(t);
     result->setScope(m_scope);
     result->setStatic(clang_Cursor_getStorageClass(cursor) == CX_SC_Static);
@@ -1031,7 +1033,9 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor)
         if (d->m_currentArgument.isNull() && !d->m_currentFunction.isNull()) {
             const QString name = getCursorSpelling(cursor);
             d->m_currentArgument.reset(new _ArgumentModelItem(d->m_model, name));
-            d->m_currentArgument->setType(d->createTypeInfo(cursor));
+            const auto type = clang_getCursorType(cursor);
+            d->m_currentArgument->setScopeResolution(hasScopeResolution(type));
+            d->m_currentArgument->setType(d->createTypeInfo(type));
             d->m_currentFunction->addArgument(d->m_currentArgument);
             QString defaultValueExpression = d->cursorValueExpression(this, cursor);
             if (!defaultValueExpression.isEmpty()) {
index 295ede39b25dab237755ac0f450aadc7c460075f..ec6d228384eeabf4a03e871908fca2c4d23ff80d 100644 (file)
@@ -155,6 +155,17 @@ QString getTypeName(const CXType &type)
     return result;
 }
 
+// Quick check for "::Type"
+bool hasScopeResolution(const CXType &type)
+{
+    CXString typeSpelling = clang_getTypeSpelling(type);
+    const QString spelling = QString::fromUtf8(clang_getCString(typeSpelling));
+    const bool result = spelling.startsWith(QLatin1String("::"))
+        || spelling.contains(QLatin1String(" ::"));
+    clang_disposeString(typeSpelling);
+    return result;
+}
+
 // Resolve elaborated types occurring with clang 16
 QString getResolvedTypeName(const CXType &type)
 {
index aacaf63ff2f943c72df0c72a0c9f6f140eb945e7..33f362cbcca36a9bb27dbc099c14e0a4508fc1e0 100644 (file)
@@ -52,6 +52,7 @@ QString getCursorKindName(CXCursorKind cursorKind);
 QString getCursorSpelling(const CXCursor &cursor);
 QString getCursorDisplayName(const CXCursor &cursor);
 QString getTypeName(const CXType &type);
+bool hasScopeResolution(const CXType &type);
 QString getResolvedTypeName(const CXType &type);
 inline QString getCursorTypeName(const CXCursor &cursor)
     { return getTypeName(clang_getCursorType(cursor)); }
index 9995fc71a6121af8e76444836600c01183b411a7..34c1b798715347f7678c036832222e24117c2e93 100644 (file)
@@ -1083,11 +1083,23 @@ void _ArgumentModelItem::setDefaultValue(bool defaultValue)
     m_defaultValue = defaultValue;
 }
 
+bool _ArgumentModelItem::scopeResolution() const
+{
+    return m_scopeResolution;
+}
+
+void _ArgumentModelItem::setScopeResolution(bool v)
+{
+    m_scopeResolution = v;
+}
+
 #ifndef QT_NO_DEBUG_STREAM
 void _ArgumentModelItem::formatDebug(QDebug &d) const
 {
     _CodeModelItem::formatDebug(d);
     d << ", type=" << m_type;
+    if (m_scopeResolution)
+        d << ", [m_scope resolution]";
     if (m_defaultValue)
         d << ", defaultValue=\"" << m_defaultValueExpression << '"';
 }
@@ -1152,6 +1164,16 @@ void _FunctionModelItem::setVariadics(bool isVariadics)
     m_isVariadics = isVariadics;
 }
 
+bool _FunctionModelItem::scopeResolution() const
+{
+    return m_scopeResolution;
+}
+
+void _FunctionModelItem::setScopeResolution(bool v)
+{
+    m_scopeResolution = v;
+}
+
 bool _FunctionModelItem::isNoExcept() const
 {
     return m_exceptionSpecification == ExceptionSpecification::NoExcept;
@@ -1295,6 +1317,8 @@ void _FunctionModelItem::formatDebug(QDebug &d) const
         d << " [explicit]";
     if (m_isInvokable)
         d << " [invokable]";
+    if (m_scopeResolution)
+        d << " [scope resolution]";
     formatModelItemList(d, ", arguments=", m_arguments);
     if (m_isVariadics)
         d << ",...";
index 13bc7cf36b38ba919688932cfd2f0d518e72b535..d9cd99dcdea453bd1b918174e537e2be22190b3f 100644 (file)
@@ -505,6 +505,10 @@ public:
     QString defaultValueExpression() const { return m_defaultValueExpression; }
     void setDefaultValueExpression(const QString &expr) { m_defaultValueExpression = expr; }
 
+    // Argument type has scope resolution "::ArgumentType"
+    bool scopeResolution() const;
+    void setScopeResolution(bool v);
+
 #ifndef QT_NO_DEBUG_STREAM
     void formatDebug(QDebug &d) const override;
 #endif
@@ -513,6 +517,7 @@ private:
     TypeInfo m_type;
     QString m_defaultValueExpression;
     bool m_defaultValue;
+    bool m_scopeResolution = false;
 };
 
 class _MemberModelItem: public _CodeModelItem
@@ -631,6 +636,8 @@ public:
     bool isVariadics() const;
     void setVariadics(bool isVariadics);
 
+    bool scopeResolution() const; // Return type has scope resolution "::ReturnType"
+    void setScopeResolution(bool v);
 
     bool isSimilar(const FunctionModelItem &other) const;
 
@@ -660,6 +667,7 @@ private:
             uint m_isExplicit: 1;
             uint m_isVariadics: 1;
             uint m_isInvokable : 1; // Qt
+            uint m_scopeResolution: 1;
         };
         uint m_flags;
     };