[clang] [libclang/python] Add non ref and unqualified getters for types (PR #175534)
Martin Rodriguez Reboredo via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 12 05:11:03 PST 2026
https://github.com/YakoYakoYokuYoku created https://github.com/llvm/llvm-project/pull/175534
These methods are notoriously absent in the Python API. I really need these for a project of mine. If testing is needed, it can be added on demand.
>From 90d2d37b09684829de254418dbe271200cb0e0d1 Mon Sep 17 00:00:00 2001
From: Martin Rodriguez Reboredo <yakoyoku at gmail.com>
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 <yakoyoku at gmail.com>
---
clang/bindings/python/clang/cindex.py | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py
index 2b6ab00c88219..98c15a04ff627 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 or restrict. 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:
@@ -4246,6 +4265,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),
@@ -4275,6 +4295,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),
More information about the cfe-commits
mailing list