[neon/qt/pyside2/Neon/release] debian: Backport 9 upstream patches for LLVM 16 support.
Dmitry Shachnev
null at kde.org
Thu Jul 25 03:06:04 BST 2024
Git commit cfb414d9eee7019425569c9e7c0ab579884665b3 by Dmitry Shachnev.
Committed on 04/02/2024 at 13:55.
Pushed by carlosdem into branch 'Neon/release'.
Backport 9 upstream patches for LLVM 16 support.
M +6 -0 debian/changelog
M +9 -0 debian/patches/series
A +26 -0 debian/patches/shiboken2-Fail-template-test-instead-of-crashing.patch
A +29 -0 debian/patches/shiboken2-Fix-build-with-clang-16.patch
A +88 -0 debian/patches/shiboken2-clang-Fix-and-simplify-resolveType-helper.patch
A +108 -0 debian/patches/shiboken2-clang-Fix-build-with-clang-16.patch
A +92 -0 debian/patches/shiboken2-clang-Fix-clashes-between-type-name-and-enumera.patch
A +178 -0 debian/patches/shiboken2-clang-Record-scope-resolution-of-arguments-func.patch
A +101 -0 debian/patches/shiboken2-clang-Remove-typedef-expansion.patch
A +96 -0 debian/patches/shiboken2-clang-Suppress-class-scope-look-up-for-paramete.patch
A +62 -0 debian/patches/shiboken2-clang-Write-scope-resolution-for-all-parameters.patch
https://invent.kde.org/neon/qt/pyside2/-/commit/cfb414d9eee7019425569c9e7c0ab579884665b3
diff --git a/debian/changelog b/debian/changelog
index 5fb6d612..0bd0fa16 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+pyside2 (5.15.12-5) UNRELEASED; urgency=medium
+
+ * Backport 9 upstream patches for LLVM 16 support.
+
+ -- Dmitry Shachnev <mitya57 at debian.org> Sat, 03 Feb 2024 20:39:50 +0300
+
pyside2 (5.15.12-4) unstable; urgency=medium
* Team upload.
diff --git a/debian/patches/series b/debian/patches/series
index 8e07fce3..77b6838a 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -10,3 +10,12 @@ Support-running-PySide-on-Python-3.12.patch
Final-details-to-enable-3.12-wheel-compatibility.patch
Stop-using-imp-module.patch
Do-not-change-RPATH.patch
+shiboken2-Fix-build-with-clang-16.patch
+shiboken2-Fail-template-test-instead-of-crashing.patch
+shiboken2-clang-Fix-clashes-between-type-name-and-enumera.patch
+shiboken2-clang-Fix-and-simplify-resolveType-helper.patch
+shiboken2-clang-Remove-typedef-expansion.patch
+shiboken2-clang-Fix-build-with-clang-16.patch
+shiboken2-clang-Record-scope-resolution-of-arguments-func.patch
+shiboken2-clang-Suppress-class-scope-look-up-for-paramete.patch
+shiboken2-clang-Write-scope-resolution-for-all-parameters.patch
diff --git a/debian/patches/shiboken2-Fail-template-test-instead-of-crashing.patch b/debian/patches/shiboken2-Fail-template-test-instead-of-crashing.patch
new file mode 100644
index 00000000..f7887f0f
--- /dev/null
+++ b/debian/patches/shiboken2-Fail-template-test-instead-of-crashing.patch
@@ -0,0 +1,26 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Tue, 11 Apr 2023 14:57:49 +0200
+Subject: shiboken2: Fail template test instead of crashing
+
+The class is not found by Clang 16.
+
+Pick-to: 6.5 6.2 5.15
+Task-number: PYSIDE-2288
+Change-Id: If7c7a29417d083645ddf2e9fd206a09e47401833
+Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes at qt.io>
+---
+ sources/shiboken2/ApiExtractor/tests/testtemplates.cpp | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp b/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
+index f6c70a6..9f929c4 100644
+--- a/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
++++ b/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
+@@ -641,6 +641,7 @@ public:
+ auto derived = AbstractMetaClass::findClass(classes, QLatin1String("Derived"));
+ QVERIFY(derived);
+ auto base = derived->templateBaseClass();
++ QVERIFY(base);
+ QCOMPARE(base->name(), QLatin1String("Container1"));
+ }
+
diff --git a/debian/patches/shiboken2-Fix-build-with-clang-16.patch b/debian/patches/shiboken2-Fix-build-with-clang-16.patch
new file mode 100644
index 00000000..3c09a3ac
--- /dev/null
+++ b/debian/patches/shiboken2-Fix-build-with-clang-16.patch
@@ -0,0 +1,29 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Tue, 11 Apr 2023 14:38:01 +0200
+Subject: shiboken2: Fix build with clang 16
+
+getCursorSpelling() reports a name for unnamed enums.
+
+Pick-to: 6.5 6.2 5.15
+Task-number: PYSIDE-2288
+Change-Id: Iaeb6409c8825dc0fb2720b450fb14e64bbf5d303
+Reviewed-by: Adrian Herrmann <adrian.herrmann at qt.io>
+Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh at qt.io>
+(cherry picked from commit e20e1ea0f5f9f9a0fe1c309a60cb5297f1276efc)
+---
+ sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+index ebe3b99..e8e5bcf 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+@@ -895,6 +895,8 @@ static NamespaceType namespaceType(const CXCursor &cursor)
+ static QString enumType(const CXCursor &cursor)
+ {
+ QString name = getCursorSpelling(cursor); // "enum Foo { v1, v2 };"
++ if (name.contains(u"unnamed enum")) // Clang 16.0
++ return {};
+ if (name.isEmpty()) {
+ // PYSIDE-1228: For "typedef enum { v1, v2 } Foo;", type will return
+ // "Foo" as expected. Care must be taken to exclude real anonymous enums.
diff --git a/debian/patches/shiboken2-clang-Fix-and-simplify-resolveType-helper.patch b/debian/patches/shiboken2-clang-Fix-and-simplify-resolveType-helper.patch
new file mode 100644
index 00000000..304cff91
--- /dev/null
+++ b/debian/patches/shiboken2-clang-Fix-and-simplify-resolveType-helper.patch
@@ -0,0 +1,88 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Tue, 25 Apr 2023 10:00:39 +0200
+Subject: shiboken2/clang: Fix and simplify resolveType() helper
+
+The function had a bug which only manifested with clang 16:
+"type" should have been assigned the type of the cursor
+obtained from clang_getTypeDeclaration(). With this, the complicated
+lookup code in getBaseClass() can be removed.
+
+Task-number: PYSIDE-2288
+Pick-to: 6.5
+Change-Id: I861e30451b3f4af2ec0c2e4ffa4179a429854533
+Reviewed-by: Christian Tismer <tismer at stackless.com>
+Reviewed-by: Qt CI Bot <qt_ci_bot at qt-project.org>
+---
+ .../ApiExtractor/clangparser/clangbuilder.cpp | 39 ++++++++++------------
+ 1 file changed, 18 insertions(+), 21 deletions(-)
+
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+index e8e5bcf..1b4c81c 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+@@ -627,6 +627,9 @@ long clang_EnumDecl_isScoped4(BaseVisitor *bv, const CXCursor &cursor)
+ #endif // CLANG_NO_ENUMDECL_ISSCOPED
+
+ // Resolve declaration and type of a base class
++// Note: TypeAliasTemplateDecl ("using QVector<T>=QList<T>") is automatically
++// resolved by clang_getTypeDeclaration(), but it stops at
++// TypeAliasDecl / TypedefDecl.
+
+ struct TypeDeclaration
+ {
+@@ -634,19 +637,23 @@ struct TypeDeclaration
+ CXCursor declaration;
+ };
+
++static inline bool isTypeAliasDecl(const CXCursor &cursor)
++{
++ const auto kind = clang_getCursorKind(cursor);
++ return kind == CXCursor_TypeAliasDecl || kind == CXCursor_TypedefDecl;
++}
++
+ static TypeDeclaration resolveBaseSpecifier(const CXCursor &cursor)
+ {
+ Q_ASSERT(clang_getCursorKind(cursor) == CXCursor_CXXBaseSpecifier);
+ CXType inheritedType = clang_getCursorType(cursor);
+ CXCursor decl = clang_getTypeDeclaration(inheritedType);
+- if (inheritedType.kind != CXType_Unexposed) {
+- while (true) {
+- auto kind = clang_getCursorKind(decl);
+- if (kind != CXCursor_TypeAliasDecl && kind != CXCursor_TypedefDecl)
+- break;
+- inheritedType = clang_getTypedefDeclUnderlyingType(decl);
+- decl = clang_getTypeDeclaration(inheritedType);
+- }
++ auto resolvedType = clang_getCursorType(decl);
++ if (resolvedType.kind != CXType_Invalid && resolvedType.kind != inheritedType.kind)
++ inheritedType = resolvedType;
++ while (isTypeAliasDecl(decl)) {
++ inheritedType = clang_getTypedefDeclUnderlyingType(decl);
++ decl = clang_getTypeDeclaration(inheritedType);
+ }
+ return {inheritedType, decl};
+ }
+@@ -656,20 +663,10 @@ void BuilderPrivate::addBaseClass(const CXCursor &cursor)
+ {
+ Q_ASSERT(clang_getCursorKind(cursor) == CXCursor_CXXBaseSpecifier);
+ // Note: spelling has "struct baseClass", use type
+- QString baseClassName;
+ const auto decl = resolveBaseSpecifier(cursor);
+- if (decl.type.kind == CXType_Unexposed) {
+- // The type is unexposed when the base class is a template type alias:
+- // "class QItemSelection : public QList<X>" where QList is aliased to QVector.
+- // Try to resolve via code model.
+- TypeInfo info = createTypeInfo(decl.type);
+- auto parentScope = m_scopeStack.at(m_scopeStack.size() - 2); // Current is class.
+- auto resolved = TypeInfo::resolveType(info, parentScope);
+- if (resolved != info)
+- baseClassName = resolved.toString();
+- }
+- if (baseClassName.isEmpty())
+- baseClassName = getTypeName(decl.type);
++ QString baseClassName = getTypeName(decl.type);
++ if (baseClassName.startsWith(u"std::")) // Simplify "std::" types
++ baseClassName = createTypeInfo(decl.type).toString();
+
+ auto it = m_cursorClassHash.constFind(decl.declaration);
+ const CodeModel::AccessPolicy access = accessPolicy(clang_getCXXAccessSpecifier(cursor));
diff --git a/debian/patches/shiboken2-clang-Fix-build-with-clang-16.patch b/debian/patches/shiboken2-clang-Fix-build-with-clang-16.patch
new file mode 100644
index 00000000..b07cc335
--- /dev/null
+++ b/debian/patches/shiboken2-clang-Fix-build-with-clang-16.patch
@@ -0,0 +1,108 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Tue, 25 Apr 2023 14:01:45 +0200
+Subject: shiboken2/clang: Fix build with clang 16
+
+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 at stackless.com>
+(cherry picked from commit 44ef1859214c66861a251d4a0faf5c38dc050850)
+---
+ .../ApiExtractor/clangparser/clangbuilder.cpp | 2 +-
+ .../ApiExtractor/clangparser/clangutils.cpp | 23 ++++++++++++++++++++++
+ .../ApiExtractor/clangparser/clangutils.h | 1 +
+ .../shiboken2/ApiExtractor/tests/testtemplates.cpp | 3 +--
+ 4 files changed, 26 insertions(+), 3 deletions(-)
+
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+index 332f1da..ed1e15d 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+@@ -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)) {
+ }
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
+index 57271ef..295ede3 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
+@@ -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)
+ {
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
+index f7c230a..aacaf63 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
+@@ -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)
+diff --git a/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp b/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
+index 9f929c4..fbc5c4c 100644
+--- a/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
++++ b/sources/shiboken2/ApiExtractor/tests/testtemplates.cpp
+@@ -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();
diff --git a/debian/patches/shiboken2-clang-Fix-clashes-between-type-name-and-enumera.patch b/debian/patches/shiboken2-clang-Fix-clashes-between-type-name-and-enumera.patch
new file mode 100644
index 00000000..62de5a15
--- /dev/null
+++ b/debian/patches/shiboken2-clang-Fix-clashes-between-type-name-and-enumera.patch
@@ -0,0 +1,92 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Tue, 25 Apr 2023 15:30:30 +0200
+Subject: shiboken2/clang: Fix clashes between type name and enumeration
+ values
+
+Remove all constant and enum value type entries found in the type lookup
+unless it is looking for template arguments; where it may be a
+non-type template argument.
+
+Task-number: PYSIDE-2288
+Pick-to: 6.5 5.15
+Change-Id: If0609ce0d0223f551ed6dee1d1e0ea3ef49d6917
+Reviewed-by: Christian Tismer <tismer at stackless.com>
+(cherry picked from commit e22f717153a5e9855531f45c0bf82ff2461a3f7e)
+---
+ .../shiboken2/ApiExtractor/abstractmetabuilder.cpp | 21 +++++++++++++++++++--
+ .../shiboken2/ApiExtractor/abstractmetabuilder.h | 3 ++-
+ .../shiboken2/ApiExtractor/typesystem_typedefs.h | 1 +
+ 3 files changed, 22 insertions(+), 3 deletions(-)
+
+diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+index 5a413ec..2f34e16 100644
+--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
++++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+@@ -2144,6 +2144,13 @@ static bool isNumber(const QString &s)
+ [](QChar c) { return c.isDigit(); });
+ }
+
++// A type entry relevant only for non type template "X<5>"
++static bool isNonTypeTemplateArgument(const TypeEntryCPtr &te)
++{
++ const auto type = te->type();
++ return type == TypeEntry::EnumValue || type == TypeEntry::ConstantValueType;
++}
++
+ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo &_typei,
+ AbstractMetaClass *currentClass,
+ AbstractMetaBuilderPrivate *d,
+@@ -2271,7 +2278,15 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
+ typeInfo.clearInstantiations();
+ }
+
+- const TypeEntries types = findTypeEntries(qualifiedName, name, currentClass, d);
++ TypeEntries types = findTypeEntries(qualifiedName, name, currentClass, d);
++ if (!flags.testFlag(AbstractMetaBuilder::TemplateArgument)) {
++ // Avoid clashes between QByteArray and enum value QMetaType::QByteArray
++ // unless we are looking for template arguments.
++ auto end = std::remove_if(types.begin(), types.end(),
++ isNonTypeTemplateArgument);
++ types.erase(end, types.end());
++ }
++
+ if (types.isEmpty()) {
+ if (errorMessageIn) {
+ *errorMessageIn =
+@@ -2293,7 +2308,9 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
+ const auto &templateArguments = typeInfo.instantiations();
+ for (int t = 0, size = templateArguments.size(); t < size; ++t) {
+ const TypeInfo &ti = templateArguments.at(t);
+- AbstractMetaType *targType = translateTypeStatic(ti, currentClass, d, flags, &errorMessage);
++ AbstractMetaType *targType = translateTypeStatic(ti, currentClass, d,
++ flags | AbstractMetaBuilder::TemplateArgument,
++ &errorMessage);
+ // For non-type template parameters, create a dummy type entry on the fly
+ // as is done for classes.
+ if (!targType) {
+diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
+index d2dc080..8916eaf 100644
+--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
++++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
+@@ -93,7 +93,8 @@ public:
+ void setSkipDeprecated(bool value);
+
+ enum TranslateTypeFlag {
+- DontResolveType = 0x1
++ DontResolveType = 0x1,
++ TemplateArgument = 0x2
+ };
+ Q_DECLARE_FLAGS(TranslateTypeFlags, TranslateTypeFlag);
+
+diff --git a/sources/shiboken2/ApiExtractor/typesystem_typedefs.h b/sources/shiboken2/ApiExtractor/typesystem_typedefs.h
+index 73f92b2..5dcc65c 100644
+--- a/sources/shiboken2/ApiExtractor/typesystem_typedefs.h
++++ b/sources/shiboken2/ApiExtractor/typesystem_typedefs.h
+@@ -48,6 +48,7 @@ using CodeSnipList = QVector<CodeSnip>;
+ using DocModificationList = QVector<DocModification>;
+ using FieldModificationList = QVector<FieldModification>;
+ using FunctionModificationList = QVector<FunctionModification>;
++using TypeEntryCPtr = const TypeEntry *;
+ using TypeEntries = QVector<const TypeEntry *>;
+
+ #endif // TYPESYSTEM_TYPEDEFS_H
diff --git a/debian/patches/shiboken2-clang-Record-scope-resolution-of-arguments-func.patch b/debian/patches/shiboken2-clang-Record-scope-resolution-of-arguments-func.patch
new file mode 100644
index 00000000..fc65d2b4
--- /dev/null
+++ b/debian/patches/shiboken2-clang-Record-scope-resolution-of-arguments-func.patch
@@ -0,0 +1,178 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Thu, 27 Apr 2023 12:44:10 +0200
+Subject: shiboken2/clang: Record scope resolution of arguments/function
+ return
+
+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 at stackless.com>
+(cherry picked from commit 075d8ad4660f05e6d2583ff1c05e9987ad624bfe)
+---
+ .../ApiExtractor/clangparser/clangbuilder.cpp | 8 ++++++--
+ .../ApiExtractor/clangparser/clangutils.cpp | 11 ++++++++++
+ .../ApiExtractor/clangparser/clangutils.h | 1 +
+ .../shiboken2/ApiExtractor/parser/codemodel.cpp | 24 ++++++++++++++++++++++
+ sources/shiboken2/ApiExtractor/parser/codemodel.h | 8 ++++++++
+ 5 files changed, 50 insertions(+), 2 deletions(-)
+
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+index ed1e15d..1b5cc5c 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+@@ -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()) {
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
+index 295ede3..ec6d228 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.cpp
+@@ -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)
+ {
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
+index aacaf63..33f362c 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangutils.h
+@@ -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)); }
+diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
+index 9995fc7..34c1b79 100644
+--- a/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
++++ b/sources/shiboken2/ApiExtractor/parser/codemodel.cpp
+@@ -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 << ",...";
+diff --git a/sources/shiboken2/ApiExtractor/parser/codemodel.h b/sources/shiboken2/ApiExtractor/parser/codemodel.h
+index 13bc7cf..d9cd99d 100644
+--- a/sources/shiboken2/ApiExtractor/parser/codemodel.h
++++ b/sources/shiboken2/ApiExtractor/parser/codemodel.h
+@@ -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;
+ };
diff --git a/debian/patches/shiboken2-clang-Remove-typedef-expansion.patch b/debian/patches/shiboken2-clang-Remove-typedef-expansion.patch
new file mode 100644
index 00000000..14264117
--- /dev/null
+++ b/debian/patches/shiboken2-clang-Remove-typedef-expansion.patch
@@ -0,0 +1,101 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Thu, 20 Apr 2023 11:16:15 +0200
+Subject: shiboken2/clang: Remove typedef expansion
+
+The functionality will be re-added by a subsequent change
+expanding elaborated types.
+
+Task-number: PYSIDE-2288
+Pick-to: 6.5 5.15
+Change-Id: I3245c6dccba7de0ed1ce0e7820e1edb4567ca3c2
+Reviewed-by: Christian Tismer <tismer at stackless.com>
+(cherry picked from commit 24742dca014109bd3c2a9775fc15ca306ab22c9c)
+---
+ .../ApiExtractor/clangparser/clangbuilder.cpp | 39 ----------------------
+ 1 file changed, 39 deletions(-)
+
+diff --git a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+index 1b4c81c..332f1da 100644
+--- a/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
++++ b/sources/shiboken2/ApiExtractor/clangparser/clangbuilder.cpp
+@@ -140,7 +140,6 @@ static bool isSigned(CXTypeKind kind)
+ class BuilderPrivate {
+ public:
+ using CursorClassHash = QHash<CXCursor, ClassModelItem>;
+- using CursorTypedefHash = QHash<CXCursor, TypeDefModelItem>;
+ using TypeInfoHash = QHash<CXType, TypeInfo>;
+
+ explicit BuilderPrivate(BaseVisitor *bv) : m_baseVisitor(bv), m_model(new CodeModel)
+@@ -197,9 +196,6 @@ public:
+ QString cursorValueExpression(BaseVisitor *bv, const CXCursor &cursor) const;
+ void addBaseClass(const CXCursor &cursor);
+
+- template <class Item>
+- void qualifyTypeDef(const CXCursor &typeRefCursor, const QSharedPointer<Item> &item) const;
+-
+ bool visitHeader(const char *cFileName) const;
+
+ void setFileName(const CXCursor &cursor, _CodeModelItem *item);
+@@ -213,7 +209,6 @@ public:
+ // classes can be correctly parented in case of forward-declared inner classes
+ // (QMetaObject::Connection)
+ CursorClassHash m_cursorClassHash;
+- CursorTypedefHash m_cursorTypedefHash;
+
+ mutable TypeInfoHash m_typeInfoHash; // Cache type information
+ mutable QHash<QString, TemplateTypeAliasModelItem> m_templateTypeAliases;
+@@ -561,7 +556,6 @@ void BuilderPrivate::addTypeDef(const CXCursor &cursor, const CXType &cxType)
+ item->setType(createTypeInfo(cxType));
+ item->setScope(m_scope);
+ m_scopeStack.back()->addTypeDef(item);
+- m_cursorTypedefHash.insert(cursor, item);
+ }
+
+ void BuilderPrivate::startTemplateTypeAlias(const CXCursor &cursor)
+@@ -703,31 +697,6 @@ static inline CXCursor definitionFromTypeRef(const CXCursor &typeRefCursor)
+ return clang_getTypeDeclaration(clang_getCursorType(typeRefCursor));
+ }
+
+-// Qualify function arguments or fields that are typedef'ed from another scope:
+-// enum ConversionFlag {};
+-// typedef QFlags<ConversionFlag> ConversionFlags;
+-// class QTextCodec {
+-// enum ConversionFlag {};
+-// typedef QFlags<ConversionFlag> ConversionFlags;
+-// struct ConverterState {
+-// explicit ConverterState(ConversionFlags);
+-// ^^ qualify to QTextCodec::ConversionFlags
+-// ConversionFlags m_flags;
+-// ^^ ditto
+-
+-template <class Item> // ArgumentModelItem, VariableModelItem
+-void BuilderPrivate::qualifyTypeDef(const CXCursor &typeRefCursor, const QSharedPointer<Item> &item) const
+-{
+- TypeInfo type = item->type();
+- if (type.qualifiedName().size() == 1) { // item's type is unqualified.
+- const auto it = m_cursorTypedefHash.constFind(definitionFromTypeRef(typeRefCursor));
+- if (it != m_cursorTypedefHash.constEnd() && !it.value()->scope().isEmpty()) {
+- type.setQualifiedName(it.value()->scope() + type.qualifiedName());
+- item->setType(type);
+- }
+- }
+-}
+-
+ void BuilderPrivate::setFileName(const CXCursor &cursor, _CodeModelItem *item)
+ {
+ const SourceRange range = getCursorRange(cursor);
+@@ -1120,14 +1089,6 @@ BaseVisitor::StartTokenResult Builder::startToken(const CXCursor &cursor)
+ }
+ break;
+ case CXCursor_TypeRef:
+- if (!d->m_currentFunction.isNull()) {
+- if (d->m_currentArgument.isNull())
+- d->qualifyTypeDef(cursor, d->m_currentFunction); // return type
+- else
+- d->qualifyTypeDef(cursor, d->m_currentArgument);
+- } else if (!d->m_currentField.isNull()) {
+- d->qualifyTypeDef(cursor, d->m_currentField);
+- }
+ break;
+ case CXCursor_CXXFinalAttr:
+ if (!d->m_currentFunction.isNull())
diff --git a/debian/patches/shiboken2-clang-Suppress-class-scope-look-up-for-paramete.patch b/debian/patches/shiboken2-clang-Suppress-class-scope-look-up-for-paramete.patch
new file mode 100644
index 00000000..db9791a9
--- /dev/null
+++ b/debian/patches/shiboken2-clang-Suppress-class-scope-look-up-for-paramete.patch
@@ -0,0 +1,96 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Thu, 27 Apr 2023 13:00:37 +0200
+Subject: shiboken2/clang: Suppress class scope look up for parameters with
+ scope resolution
+
+Add a flag to AbstractMetaBuilderPrivate::findTypeEntriesHelper()
+to suppress the class scope look in case scope resolution.
+
+Task-number: PYSIDE-2288
+Pick-to: 6.5 5.15
+Change-Id: I04a4810d03845fb48393c5efed3641220bd12d87
+Reviewed-by: Christian Tismer <tismer at stackless.com>
+---
+ sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp | 16 ++++++++++++----
+ sources/shiboken2/ApiExtractor/abstractmetabuilder.h | 3 ++-
+ sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h | 1 +
+ 3 files changed, 15 insertions(+), 5 deletions(-)
+
+diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+index 2f34e16..4bf4ab4 100644
+--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
++++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.cpp
+@@ -1845,7 +1845,10 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio
+ return nullptr;
+ }
+
+- AbstractMetaType *type = translateType(returnType, currentClass, {}, &errorMessage);
++ TranslateTypeFlags flags;
++ if (functionItem->scopeResolution())
++ flags.setFlag(AbstractMetaBuilder::NoClassScopeLookup);
++ AbstractMetaType *type = translateType(returnType, currentClass, flags, &errorMessage);
+ if (!type) {
+ const QString reason = msgUnmatchedReturnType(functionItem, errorMessage);
+ qCWarning(lcShiboken, "%s",
+@@ -1880,7 +1883,10 @@ AbstractMetaFunction *AbstractMetaBuilderPrivate::traverseFunction(const Functio
+ return nullptr;
+ }
+
+- AbstractMetaType *metaType = translateType(arg->type(), currentClass, {}, &errorMessage);
++ TranslateTypeFlags flags;
++ if (arg->scopeResolution())
++ flags.setFlag(AbstractMetaBuilder::NoClassScopeLookup);
++ AbstractMetaType *metaType = translateType(arg->type(), currentClass, flags, &errorMessage);
+ if (!metaType) {
+ // If an invalid argument has a default value, simply remove it
+ // unless the function is virtual (since the override in the
+@@ -2073,11 +2079,13 @@ static const TypeEntry* findTypeEntryUsingContext(const AbstractMetaClass* metaC
+ // Helper for translateTypeStatic()
+ TypeEntries AbstractMetaBuilderPrivate::findTypeEntries(const QString &qualifiedName,
+ const QString &name,
++ TranslateTypeFlags flags,
+ AbstractMetaClass *currentClass,
+ AbstractMetaBuilderPrivate *d)
+ {
+ // 5.1 - Try first using the current scope
+- if (currentClass) {
++ if (currentClass != nullptr
++ && !flags.testFlag(AbstractMetaBuilder::NoClassScopeLookup)) {
+ if (auto type = findTypeEntryUsingContext(currentClass, qualifiedName))
+ return {type};
+
+@@ -2278,7 +2286,7 @@ AbstractMetaType *AbstractMetaBuilderPrivate::translateTypeStatic(const TypeInfo
+ typeInfo.clearInstantiations();
+ }
+
+- TypeEntries types = findTypeEntries(qualifiedName, name, currentClass, d);
++ TypeEntries types = findTypeEntries(qualifiedName, name, flags, currentClass, d);
+ if (!flags.testFlag(AbstractMetaBuilder::TemplateArgument)) {
+ // Avoid clashes between QByteArray and enum value QMetaType::QByteArray
+ // unless we are looking for template arguments.
+diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
+index 8916eaf..f333ad5 100644
+--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
++++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder.h
+@@ -94,7 +94,8 @@ public:
+
+ enum TranslateTypeFlag {
+ DontResolveType = 0x1,
+- TemplateArgument = 0x2
++ TemplateArgument = 0x2,
++ NoClassScopeLookup = 0x4
+ };
+ Q_DECLARE_FLAGS(TranslateTypeFlags, TranslateTypeFlag);
+
+diff --git a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h
+index 8468950..8ddd369 100644
+--- a/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h
++++ b/sources/shiboken2/ApiExtractor/abstractmetabuilder_p.h
+@@ -154,6 +154,7 @@ public:
+ TranslateTypeFlags flags = {},
+ QString *errorMessageIn = nullptr);
+ static TypeEntries findTypeEntries(const QString &qualifiedName, const QString &name,
++ TranslateTypeFlags flags = {},
+ AbstractMetaClass *currentClass = nullptr,
+ AbstractMetaBuilderPrivate *d = nullptr);
+
diff --git a/debian/patches/shiboken2-clang-Write-scope-resolution-for-all-parameters.patch b/debian/patches/shiboken2-clang-Write-scope-resolution-for-all-parameters.patch
new file mode 100644
index 00000000..b0be6fa2
--- /dev/null
+++ b/debian/patches/shiboken2-clang-Write-scope-resolution-for-all-parameters.patch
@@ -0,0 +1,62 @@
+From: Friedemann Kleint <Friedemann.Kleint at qt.io>
+Date: Thu, 27 Apr 2023 12:18:39 +0200
+Subject: shiboken2/clang: Write scope resolution for all parameters of native
+ wrappers
+
+Make sure types are correct for cases like:
+
+- QtDBusHelper::QDBusReply::QDBusReply(::QDBusReply<void>)
+- Qt3DInput*Event constructors taking the equivalent QtGui classes
+ (Qt3DInput::QMouseEvent(::QMouseEvent *);
+
+[ChangeLog][shiboken6] Support for parameters/function return
+types with scope resolution has been improved.
+
+Fixes: PYSIDE-2288
+Pick-to: 6.5 5.15
+Change-Id: Id29758fceb88188f4cd834fbd5a7cc0ab511fb1a
+Reviewed-by: Christian Tismer <tismer at stackless.com>
+(cherry picked from commit dd863857436bbeeba4c0a1077f5ad16653296277)
+---
+ sources/shiboken2/generator/generator.cpp | 24 +++++++++++++-----------
+ 1 file changed, 13 insertions(+), 11 deletions(-)
+
+diff --git a/sources/shiboken2/generator/generator.cpp b/sources/shiboken2/generator/generator.cpp
+index 6028282..6147b8a 100644
+--- a/sources/shiboken2/generator/generator.cpp
++++ b/sources/shiboken2/generator/generator.cpp
+@@ -899,21 +899,23 @@ QString Generator::translateType(const AbstractMetaType *cType,
+ if (index >= (s.size() - (constLen + 1))) // (VarType const) or (VarType const[*|&])
+ s = s.remove(index, constLen);
+ }
+- } else if (options & Generator::ExcludeConst || options & Generator::ExcludeReference) {
++ } else {
+ AbstractMetaType *copyType = cType->copy();
++ if (options & Generator::ExcludeConst || options & Generator::ExcludeReference) {
++ if (options & Generator::ExcludeConst)
++ copyType->setConstant(false);
+
+- if (options & Generator::ExcludeConst)
+- copyType->setConstant(false);
+-
+- if (options & Generator::ExcludeReference)
+- copyType->setReferenceType(NoReference);
+-
++ if (options & Generator::ExcludeReference)
++ copyType->setReferenceType(NoReference);
++ }
+ s = copyType->cppSignature();
+- if (!copyType->typeEntry()->isVoid() && !copyType->typeEntry()->isCppPrimitive())
+- s.prepend(QLatin1String("::"));
++ const auto te = copyType->typeEntry();
++ if (!te->isVoid() && !te->isCppPrimitive()) { // Add scope resolution
++ const auto pos = s.indexOf(te->qualifiedCppName()); // Skip const/volatile
++ Q_ASSERT(pos >= 0);
++ s.insert(pos, QLatin1String("::"));
++ }
+ delete copyType;
+- } else {
+- s = cType->cppSignature();
+ }
+ }
+
More information about the Neon-commits
mailing list