shiboken2/clang: Fix build with clang 16
authorFriedemann Kleint <Friedemann.Kleint@qt.io>
Tue, 25 Apr 2023 12:01:45 +0000 (14:01 +0200)
committerGraham Inggs <ginggs@debian.org>
Sat, 25 Jan 2025 16:33:38 +0000 (16:33 +0000)
clang 16 returns more elaborated types instead of fully qualified type
names. Qualify elaborated types when retrieving the type name.

[ChangeLog][shiboken6] Support for libclang version 16 has been added.

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

Gbp-Pq: Name shiboken2-clang-Fix-build-with-clang-16.patch

sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
sources/shiboken2/ApiExtractor/clangparser/clangutils.h
sources/shiboken2/ApiExtractor/tests/testtemplates.cpp

index 332f1dac9af75e861637af38dca7adc120b8c462..ed1e15d4e778637abec94840537e04a0a5200a5b 100644 (file)
@@ -524,7 +524,7 @@ TypeInfo BuilderPrivate::createTypeInfoHelper(const CXType &type) const
     typeInfo.setConstant(clang_isConstQualifiedType(nestedType) != 0);
     typeInfo.setVolatile(clang_isVolatileQualifiedType(nestedType) != 0);
 
-    QString typeName = getTypeName(nestedType);
+    QString typeName = getResolvedTypeName(nestedType);
     while (TypeInfo::stripLeadingConst(&typeName)
            || TypeInfo::stripLeadingVolatile(&typeName)) {
     }
index 57271ef71f19cf7a4445134dbc29136c3ce98a5a..295ede39b25dab237755ac0f450aadc7c460075f 100644 (file)
@@ -130,6 +130,23 @@ QString getCursorDisplayName(const CXCursor &cursor)
     return result;
 }
 
+static inline bool isBuiltinType(CXTypeKind kind)
+{
+    return kind >= CXType_FirstBuiltin && kind <= CXType_LastBuiltin;
+}
+
+// Resolve elaborated types occurring with clang 16
+static CXType resolveType(const CXType &type)
+{
+    if (!isBuiltinType(type.kind)) {
+        CXCursor decl = clang_getTypeDeclaration(type);
+        auto resolvedType = clang_getCursorType(decl);
+        if (resolvedType.kind != CXType_Invalid && resolvedType.kind != type.kind)
+            return resolvedType;
+    }
+    return type;
+}
+
 QString getTypeName(const CXType &type)
 {
     CXString typeSpelling = clang_getTypeSpelling(type);
@@ -138,6 +155,12 @@ QString getTypeName(const CXType &type)
     return result;
 }
 
+// Resolve elaborated types occurring with clang 16
+QString getResolvedTypeName(const CXType &type)
+{
+    return getTypeName(resolveType(type));
+}
+
 Diagnostic::Diagnostic(const QString &m, const CXCursor &c, CXDiagnosticSeverity s)
     : message(m), source(Other), severity(s)
 {
index f7c230a6666b1c0c63c0d4968c99f1505d4f27e4..aacaf63ff2f943c72df0c72a0c9f6f140eb945e7 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);
+QString getResolvedTypeName(const CXType &type);
 inline QString getCursorTypeName(const CXCursor &cursor)
     { return getTypeName(clang_getCursorType(cursor)); }
 inline QString getCursorResultTypeName(const CXCursor &cursor)
index 9f929c432ad93b78a5305899bc69af2a163cbdf3..fbc5c4c9022833eb3723051c0104b31a2320cca6 100644 (file)
@@ -236,7 +236,6 @@ struct List {
     const AbstractMetaFunction *erase = list->findFunction(QStringLiteral("erase"));
     QVERIFY(erase);
     QCOMPARE(erase->arguments().size(), 1);
-    QEXPECT_FAIL("", "Clang: Some other code changes the parameter type", Abort);
     QCOMPARE(erase->arguments().at(0)->type()->cppSignature(), QLatin1String("List::Iterator"));
 }
 
@@ -389,7 +388,7 @@ typedef BaseTemplateClass<TypeOne> TypeOneClass;
     const ComplexTypeEntry* oneType = one->typeEntry();
     const ComplexTypeEntry* baseType = base->typeEntry();
     QCOMPARE(oneType->baseContainerType(), baseType);
-    QCOMPARE(one->baseClassNames(), QStringList(QLatin1String("BaseTemplateClass<TypeOne>")));
+    QCOMPARE(one->baseClassNames(), QStringList(QLatin1String("NSpace::BaseTemplateClass<NSpace::TypeOne>")));
 
     QVERIFY(one->hasTemplateBaseClassInstantiations());
     AbstractMetaTypeList instantiations = one->templateBaseClassInstantiations();