https://github.com/YakoYakoYokuYoku updated 
https://github.com/llvm/llvm-project/pull/175534

>From bd5781806dd0c677a99d72cbe2095f05260ea585 Mon Sep 17 00:00:00 2001
From: Martin Rodriguez Reboredo <[email protected]>
Date: Mon, 12 Jan 2026 01:04:05 -0300
Subject: [PATCH] [libclang/python] Add non ref and unqualified getters for
 types

These methods were missing in the bindings API.

Signed-off-by: Martin Rodriguez Reboredo <[email protected]>
---
 clang/bindings/python/clang/cindex.py         | 21 ++++++++++++
 .../bindings/python/tests/cindex/test_type.py | 34 +++++++++++++++++++
 clang/docs/ReleaseNotes.rst                   |  2 ++
 3 files changed, 57 insertions(+)

diff --git a/clang/bindings/python/clang/cindex.py 
b/clang/bindings/python/clang/cindex.py
index 1896a0a9c1c34..4d9d4ee78aa0d 100644
--- a/clang/bindings/python/clang/cindex.py
+++ b/clang/bindings/python/clang/cindex.py
@@ -2803,6 +2803,25 @@ def get_canonical(self) -> Type:
         """
         return Type.from_result(conf.lib.clang_getCanonicalType(self), self)
 
+    def get_non_reference(self) -> Type:
+        """
+        Return the type stripped of references from a Type.
+
+        If a type is either an l-value or an r-value reference then those
+        are going to be removed. It returns the type unchanged otherwise.
+        """
+        return Type.from_result(conf.lib.clang_getNonReferenceType(self), self)
+
+    def get_unqualified(self) -> Type:
+        """
+        Return the type without any qualifiers from a Type.
+
+        A type can be qualified with const, volatile, restrict or a
+        combination of these. This method removes the qualifier of a type. In
+        the absence of any of these, the type is returned unchanged.
+        """
+        return Type.from_result(conf.lib.clang_getUnqualifiedType(self), self)
+
     def get_fully_qualified_name(
         self, policy: PrintingPolicy, with_global_ns_prefix: bool = False
     ) -> str:
@@ -4357,6 +4376,7 @@ def set_property(self, property, value):
     ),
     ("clang_getLocation", [TranslationUnit, File, c_uint, c_uint], 
SourceLocation),
     ("clang_getLocationForOffset", [TranslationUnit, File, c_uint], 
SourceLocation),
+    ("clang_getNonReferenceType", [Type], Type),
     ("clang_getNullCursor", None, Cursor),
     ("clang_getNumArgTypes", [Type], c_uint),
     ("clang_getNumCompletionChunks", [c_void_p], c_int),
@@ -4386,6 +4406,7 @@ def set_property(self, property, value):
     ("clang_getTypeKindSpelling", [c_uint], _CXString),
     ("clang_getTypePrettyPrinted", [Type, PrintingPolicy], _CXString),
     ("clang_getTypeSpelling", [Type], _CXString),
+    ("clang_getUnqualifiedType", [Type], Type),
     ("clang_hashCursor", [Cursor], c_uint),
     ("clang_isAttribute", [CursorKind], c_uint),
     ("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString),
diff --git a/clang/bindings/python/tests/cindex/test_type.py 
b/clang/bindings/python/tests/cindex/test_type.py
index 562ac74e98b6e..853ef14b90c2f 100644
--- a/clang/bindings/python/tests/cindex/test_type.py
+++ b/clang/bindings/python/tests/cindex/test_type.py
@@ -530,6 +530,40 @@ def test_pretty(self):
         pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False)
         self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X")
 
+    def test_non_reference(self):
+        source = """
+        int &reference;
+        """
+        tu = get_tu(source, lang="cpp")
+        reference = get_cursor(tu, "reference")
+        
self.assertEqual(reference.type.get_non_reference().get_ref_qualifier(), 
RefQualifierKind.NONE)
+
+    def test_unqualified(self):
+        source = """
+        bool b;
+        const long c;
+        volatile long v;
+        const volatile int cv;
+        void f(int *__restrict l, const int *__restrict r, long s);
+        const bool &ref;
+        """
+        tu = get_tu(source, lang="cpp")
+        b = get_cursor(tu, "b")
+        c = get_cursor(tu, "c")
+        v = get_cursor(tu, "v")
+        cv = get_cursor(tu, "cv")
+        l = get_cursor(tu, "l")
+        r = get_cursor(tu, "r")
+        ref = get_cursor(tu, "ref")
+        self.assertEqual(b.type.get_unqualified().spelling, "bool")
+        self.assertEqual(c.type.get_unqualified().spelling, "long")
+        self.assertEqual(v.type.get_unqualified().spelling, "long")
+        self.assertEqual(cv.type.get_unqualified().spelling, "int")
+        self.assertEqual(l.type.get_unqualified().spelling, "int *")
+        self.assertEqual(r.type.get_unqualified().spelling, "const int *")
+        self.assertEqual(ref.type.get_unqualified().spelling, "const bool &")
+        
self.assertEqual(ref.type.get_non_reference().get_unqualified().spelling, 
"bool")
+
     def test_fully_qualified_name(self):
         source = """
         namespace home {
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 7ed56ce6ae6a6..88024649471e6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -532,6 +532,8 @@ Python Binding Changes
   ``CodeCompletionResults.results`` should be changed to directly use
   ``CodeCompletionResults``: it nows supports ``__len__`` and ``__getitem__``,
   so it can be used the same as ``CodeCompletionResults.results``.
+- Exposed ``clang_getNonReferenceType`` and ``clang_getUnqualifiedType`` via
+  ``Type.get_non_reference()`` and ``Type.get_unqualified()``.
 
 OpenMP Support
 --------------

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to