[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax created https://github.com/llvm/llvm-project/pull/135420 None >From 6fe4155fad0cdbc6ca04e37df143f22f537d5514 Mon Sep 17 00:00:00 2001 From: Brian Cody Date: Fri, 11 Apr 2025 14:27:22 -0400 Subject: [PATCH] [cindex] Add support for calling getFullyQualifiedName to the Python binding. --- clang/bindings/python/clang/cindex.py | 12 ++ .../bindings/python/tests/cindex/test_type.py | 22 +++ clang/docs/ReleaseNotes.rst | 4 clang/include/clang-c/Index.h | 12 ++ clang/tools/libclang/CXType.cpp | 17 ++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 68 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2319534a6f121..5830dc2149348 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2593,6 +2593,17 @@ def get_canonical(self): """ return Type.from_result(conf.lib.clang_getCanonicalType(self), (self,)) +def get_fully_qualified_name(self, policy, with_global_ns_prefix = False): +""" +Get the fully qualified name for a type. + +This includes full qualification of all template parameters. + +policy - This PrintingPolicy can further refine the type formatting +with_global_ns_prefix - If true, function will prepend a '::' to qualified names +""" +return _CXString.from_result(conf.lib.clang_getFullyQualifiedName(self, policy, with_global_ns_prefix)) + def is_const_qualified(self): """Determine whether a Type has the "const" qualifier set. @@ -4022,6 +4033,7 @@ def set_property(self, property, value): ("clang_getTypeSpelling", [Type], _CXString), ("clang_hashCursor", [Cursor], c_uint), ("clang_isAttribute", [CursorKind], bool), +("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString), ("clang_isConstQualifiedType", [Type], bool), ("clang_isCursorDefinition", [Cursor], bool), ("clang_isDeclaration", [CursorKind], bool), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index a9473e1dc2458..b2a82a00b4f40 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] +self.assertEqual(arg.type.get_fully_qualified_name(pp), "home::Bar *") +self.assertEqual(arg.type.get_fully_qualified_name(pp, True), "::home::Bar *") + def test_base_classes(self): source = """ class A { int a; }; diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c45965dc4d82..f228a32acd51d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,8 @@ libclang - Added ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``clang_getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. - Fixed a buffer overflow in ``CXString`` implementation. The fix may result in increased memory allocation. @@ -643,6 +645,8 @@ Python Binding Changes the cursor is a specialization of. - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``Type.getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 38e2417dcd181..25700a48c928c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4223,6 +4223,18 @@ CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. + * + * Policy - Further refine the type formatting + * WithGlobalNsPrefix - If non-zero, function will pre
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax edited https://github.com/llvm/llvm-project/pull/135420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax updated https://github.com/llvm/llvm-project/pull/135420 >From 6fe4155fad0cdbc6ca04e37df143f22f537d5514 Mon Sep 17 00:00:00 2001 From: Brian Cody Date: Fri, 11 Apr 2025 14:27:22 -0400 Subject: [PATCH 1/2] [cindex] Add support for calling getFullyQualifiedName to the Python binding. --- clang/bindings/python/clang/cindex.py | 12 ++ .../bindings/python/tests/cindex/test_type.py | 22 +++ clang/docs/ReleaseNotes.rst | 4 clang/include/clang-c/Index.h | 12 ++ clang/tools/libclang/CXType.cpp | 17 ++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 68 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2319534a6f121..5830dc2149348 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2593,6 +2593,17 @@ def get_canonical(self): """ return Type.from_result(conf.lib.clang_getCanonicalType(self), (self,)) +def get_fully_qualified_name(self, policy, with_global_ns_prefix = False): +""" +Get the fully qualified name for a type. + +This includes full qualification of all template parameters. + +policy - This PrintingPolicy can further refine the type formatting +with_global_ns_prefix - If true, function will prepend a '::' to qualified names +""" +return _CXString.from_result(conf.lib.clang_getFullyQualifiedName(self, policy, with_global_ns_prefix)) + def is_const_qualified(self): """Determine whether a Type has the "const" qualifier set. @@ -4022,6 +4033,7 @@ def set_property(self, property, value): ("clang_getTypeSpelling", [Type], _CXString), ("clang_hashCursor", [Cursor], c_uint), ("clang_isAttribute", [CursorKind], bool), +("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString), ("clang_isConstQualifiedType", [Type], bool), ("clang_isCursorDefinition", [Cursor], bool), ("clang_isDeclaration", [CursorKind], bool), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index a9473e1dc2458..b2a82a00b4f40 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] +self.assertEqual(arg.type.get_fully_qualified_name(pp), "home::Bar *") +self.assertEqual(arg.type.get_fully_qualified_name(pp, True), "::home::Bar *") + def test_base_classes(self): source = """ class A { int a; }; diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c45965dc4d82..f228a32acd51d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,8 @@ libclang - Added ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``clang_getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. - Fixed a buffer overflow in ``CXString`` implementation. The fix may result in increased memory allocation. @@ -643,6 +645,8 @@ Python Binding Changes the cursor is a specialization of. - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``Type.getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 38e2417dcd181..25700a48c928c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4223,6 +4223,18 @@ CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. + * + * Policy - Further refine the type formatting + * WithGlobalNsPrefix - If non-zero, function will prepe
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax updated https://github.com/llvm/llvm-project/pull/135420 >From 6fe4155fad0cdbc6ca04e37df143f22f537d5514 Mon Sep 17 00:00:00 2001 From: Brian Cody Date: Fri, 11 Apr 2025 14:27:22 -0400 Subject: [PATCH 1/3] [cindex] Add support for calling getFullyQualifiedName to the Python binding. --- clang/bindings/python/clang/cindex.py | 12 ++ .../bindings/python/tests/cindex/test_type.py | 22 +++ clang/docs/ReleaseNotes.rst | 4 clang/include/clang-c/Index.h | 12 ++ clang/tools/libclang/CXType.cpp | 17 ++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 68 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2319534a6f121..5830dc2149348 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2593,6 +2593,17 @@ def get_canonical(self): """ return Type.from_result(conf.lib.clang_getCanonicalType(self), (self,)) +def get_fully_qualified_name(self, policy, with_global_ns_prefix = False): +""" +Get the fully qualified name for a type. + +This includes full qualification of all template parameters. + +policy - This PrintingPolicy can further refine the type formatting +with_global_ns_prefix - If true, function will prepend a '::' to qualified names +""" +return _CXString.from_result(conf.lib.clang_getFullyQualifiedName(self, policy, with_global_ns_prefix)) + def is_const_qualified(self): """Determine whether a Type has the "const" qualifier set. @@ -4022,6 +4033,7 @@ def set_property(self, property, value): ("clang_getTypeSpelling", [Type], _CXString), ("clang_hashCursor", [Cursor], c_uint), ("clang_isAttribute", [CursorKind], bool), +("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString), ("clang_isConstQualifiedType", [Type], bool), ("clang_isCursorDefinition", [Cursor], bool), ("clang_isDeclaration", [CursorKind], bool), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index a9473e1dc2458..b2a82a00b4f40 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] +self.assertEqual(arg.type.get_fully_qualified_name(pp), "home::Bar *") +self.assertEqual(arg.type.get_fully_qualified_name(pp, True), "::home::Bar *") + def test_base_classes(self): source = """ class A { int a; }; diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c45965dc4d82..f228a32acd51d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,8 @@ libclang - Added ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``clang_getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. - Fixed a buffer overflow in ``CXString`` implementation. The fix may result in increased memory allocation. @@ -643,6 +645,8 @@ Python Binding Changes the cursor is a specialization of. - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``Type.getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 38e2417dcd181..25700a48c928c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4223,6 +4223,18 @@ CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. + * + * Policy - Further refine the type formatting + * WithGlobalNsPrefix - If non-zero, function will prepe
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax updated https://github.com/llvm/llvm-project/pull/135420 >From 6fe4155fad0cdbc6ca04e37df143f22f537d5514 Mon Sep 17 00:00:00 2001 From: Brian Cody Date: Fri, 11 Apr 2025 14:27:22 -0400 Subject: [PATCH 1/7] [cindex] Add support for calling getFullyQualifiedName to the Python binding. --- clang/bindings/python/clang/cindex.py | 12 ++ .../bindings/python/tests/cindex/test_type.py | 22 +++ clang/docs/ReleaseNotes.rst | 4 clang/include/clang-c/Index.h | 12 ++ clang/tools/libclang/CXType.cpp | 17 ++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 68 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2319534a6f121..5830dc2149348 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2593,6 +2593,17 @@ def get_canonical(self): """ return Type.from_result(conf.lib.clang_getCanonicalType(self), (self,)) +def get_fully_qualified_name(self, policy, with_global_ns_prefix = False): +""" +Get the fully qualified name for a type. + +This includes full qualification of all template parameters. + +policy - This PrintingPolicy can further refine the type formatting +with_global_ns_prefix - If true, function will prepend a '::' to qualified names +""" +return _CXString.from_result(conf.lib.clang_getFullyQualifiedName(self, policy, with_global_ns_prefix)) + def is_const_qualified(self): """Determine whether a Type has the "const" qualifier set. @@ -4022,6 +4033,7 @@ def set_property(self, property, value): ("clang_getTypeSpelling", [Type], _CXString), ("clang_hashCursor", [Cursor], c_uint), ("clang_isAttribute", [CursorKind], bool), +("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString), ("clang_isConstQualifiedType", [Type], bool), ("clang_isCursorDefinition", [Cursor], bool), ("clang_isDeclaration", [CursorKind], bool), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index a9473e1dc2458..b2a82a00b4f40 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] +self.assertEqual(arg.type.get_fully_qualified_name(pp), "home::Bar *") +self.assertEqual(arg.type.get_fully_qualified_name(pp, True), "::home::Bar *") + def test_base_classes(self): source = """ class A { int a; }; diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c45965dc4d82..f228a32acd51d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,8 @@ libclang - Added ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``clang_getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. - Fixed a buffer overflow in ``CXString`` implementation. The fix may result in increased memory allocation. @@ -643,6 +645,8 @@ Python Binding Changes the cursor is a specialization of. - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``Type.getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 38e2417dcd181..25700a48c928c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4223,6 +4223,18 @@ CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. + * + * Policy - Further refine the type formatting + * WithGlobalNsPrefix - If non-zero, function will prepe
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
@@ -431,6 +431,7 @@ LLVM_19 { LLVM_20 { global: +clang_getFullyQualifiedName; epistax wrote: Thanks, I made a new section. https://github.com/llvm/llvm-project/pull/135420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax updated https://github.com/llvm/llvm-project/pull/135420 >From 6fe4155fad0cdbc6ca04e37df143f22f537d5514 Mon Sep 17 00:00:00 2001 From: Brian Cody Date: Fri, 11 Apr 2025 14:27:22 -0400 Subject: [PATCH 1/7] [cindex] Add support for calling getFullyQualifiedName to the Python binding. --- clang/bindings/python/clang/cindex.py | 12 ++ .../bindings/python/tests/cindex/test_type.py | 22 +++ clang/docs/ReleaseNotes.rst | 4 clang/include/clang-c/Index.h | 12 ++ clang/tools/libclang/CXType.cpp | 17 ++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 68 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2319534a6f121..5830dc2149348 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2593,6 +2593,17 @@ def get_canonical(self): """ return Type.from_result(conf.lib.clang_getCanonicalType(self), (self,)) +def get_fully_qualified_name(self, policy, with_global_ns_prefix = False): +""" +Get the fully qualified name for a type. + +This includes full qualification of all template parameters. + +policy - This PrintingPolicy can further refine the type formatting +with_global_ns_prefix - If true, function will prepend a '::' to qualified names +""" +return _CXString.from_result(conf.lib.clang_getFullyQualifiedName(self, policy, with_global_ns_prefix)) + def is_const_qualified(self): """Determine whether a Type has the "const" qualifier set. @@ -4022,6 +4033,7 @@ def set_property(self, property, value): ("clang_getTypeSpelling", [Type], _CXString), ("clang_hashCursor", [Cursor], c_uint), ("clang_isAttribute", [CursorKind], bool), +("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString), ("clang_isConstQualifiedType", [Type], bool), ("clang_isCursorDefinition", [Cursor], bool), ("clang_isDeclaration", [CursorKind], bool), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index a9473e1dc2458..b2a82a00b4f40 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] +self.assertEqual(arg.type.get_fully_qualified_name(pp), "home::Bar *") +self.assertEqual(arg.type.get_fully_qualified_name(pp, True), "::home::Bar *") + def test_base_classes(self): source = """ class A { int a; }; diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c45965dc4d82..f228a32acd51d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,8 @@ libclang - Added ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``clang_getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. - Fixed a buffer overflow in ``CXString`` implementation. The fix may result in increased memory allocation. @@ -643,6 +645,8 @@ Python Binding Changes the cursor is a specialization of. - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``Type.getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 38e2417dcd181..25700a48c928c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4223,6 +4223,18 @@ CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. + * + * Policy - Further refine the type formatting + * WithGlobalNsPrefix - If non-zero, function will prepe
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax updated https://github.com/llvm/llvm-project/pull/135420 >From 6fe4155fad0cdbc6ca04e37df143f22f537d5514 Mon Sep 17 00:00:00 2001 From: Brian Cody Date: Fri, 11 Apr 2025 14:27:22 -0400 Subject: [PATCH 1/6] [cindex] Add support for calling getFullyQualifiedName to the Python binding. --- clang/bindings/python/clang/cindex.py | 12 ++ .../bindings/python/tests/cindex/test_type.py | 22 +++ clang/docs/ReleaseNotes.rst | 4 clang/include/clang-c/Index.h | 12 ++ clang/tools/libclang/CXType.cpp | 17 ++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 68 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2319534a6f121..5830dc2149348 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2593,6 +2593,17 @@ def get_canonical(self): """ return Type.from_result(conf.lib.clang_getCanonicalType(self), (self,)) +def get_fully_qualified_name(self, policy, with_global_ns_prefix = False): +""" +Get the fully qualified name for a type. + +This includes full qualification of all template parameters. + +policy - This PrintingPolicy can further refine the type formatting +with_global_ns_prefix - If true, function will prepend a '::' to qualified names +""" +return _CXString.from_result(conf.lib.clang_getFullyQualifiedName(self, policy, with_global_ns_prefix)) + def is_const_qualified(self): """Determine whether a Type has the "const" qualifier set. @@ -4022,6 +4033,7 @@ def set_property(self, property, value): ("clang_getTypeSpelling", [Type], _CXString), ("clang_hashCursor", [Cursor], c_uint), ("clang_isAttribute", [CursorKind], bool), +("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString), ("clang_isConstQualifiedType", [Type], bool), ("clang_isCursorDefinition", [Cursor], bool), ("clang_isDeclaration", [CursorKind], bool), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index a9473e1dc2458..b2a82a00b4f40 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] +self.assertEqual(arg.type.get_fully_qualified_name(pp), "home::Bar *") +self.assertEqual(arg.type.get_fully_qualified_name(pp, True), "::home::Bar *") + def test_base_classes(self): source = """ class A { int a; }; diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c45965dc4d82..f228a32acd51d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,8 @@ libclang - Added ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``clang_getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. - Fixed a buffer overflow in ``CXString`` implementation. The fix may result in increased memory allocation. @@ -643,6 +645,8 @@ Python Binding Changes the cursor is a specialization of. - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``Type.getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 38e2417dcd181..25700a48c928c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4223,6 +4223,18 @@ CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. + * + * Policy - Further refine the type formatting + * WithGlobalNsPrefix - If non-zero, function will prepe
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax updated https://github.com/llvm/llvm-project/pull/135420 >From 6fe4155fad0cdbc6ca04e37df143f22f537d5514 Mon Sep 17 00:00:00 2001 From: Brian Cody Date: Fri, 11 Apr 2025 14:27:22 -0400 Subject: [PATCH 1/4] [cindex] Add support for calling getFullyQualifiedName to the Python binding. --- clang/bindings/python/clang/cindex.py | 12 ++ .../bindings/python/tests/cindex/test_type.py | 22 +++ clang/docs/ReleaseNotes.rst | 4 clang/include/clang-c/Index.h | 12 ++ clang/tools/libclang/CXType.cpp | 17 ++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 68 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2319534a6f121..5830dc2149348 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2593,6 +2593,17 @@ def get_canonical(self): """ return Type.from_result(conf.lib.clang_getCanonicalType(self), (self,)) +def get_fully_qualified_name(self, policy, with_global_ns_prefix = False): +""" +Get the fully qualified name for a type. + +This includes full qualification of all template parameters. + +policy - This PrintingPolicy can further refine the type formatting +with_global_ns_prefix - If true, function will prepend a '::' to qualified names +""" +return _CXString.from_result(conf.lib.clang_getFullyQualifiedName(self, policy, with_global_ns_prefix)) + def is_const_qualified(self): """Determine whether a Type has the "const" qualifier set. @@ -4022,6 +4033,7 @@ def set_property(self, property, value): ("clang_getTypeSpelling", [Type], _CXString), ("clang_hashCursor", [Cursor], c_uint), ("clang_isAttribute", [CursorKind], bool), +("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString), ("clang_isConstQualifiedType", [Type], bool), ("clang_isCursorDefinition", [Cursor], bool), ("clang_isDeclaration", [CursorKind], bool), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index a9473e1dc2458..b2a82a00b4f40 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] +self.assertEqual(arg.type.get_fully_qualified_name(pp), "home::Bar *") +self.assertEqual(arg.type.get_fully_qualified_name(pp, True), "::home::Bar *") + def test_base_classes(self): source = """ class A { int a; }; diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c45965dc4d82..f228a32acd51d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,8 @@ libclang - Added ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``clang_getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. - Fixed a buffer overflow in ``CXString`` implementation. The fix may result in increased memory allocation. @@ -643,6 +645,8 @@ Python Binding Changes the cursor is a specialization of. - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``Type.getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 38e2417dcd181..25700a48c928c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4223,6 +4223,18 @@ CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. + * + * Policy - Further refine the type formatting + * WithGlobalNsPrefix - If non-zero, function will prepe
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
https://github.com/epistax updated https://github.com/llvm/llvm-project/pull/135420 >From 6fe4155fad0cdbc6ca04e37df143f22f537d5514 Mon Sep 17 00:00:00 2001 From: Brian Cody Date: Fri, 11 Apr 2025 14:27:22 -0400 Subject: [PATCH 1/5] [cindex] Add support for calling getFullyQualifiedName to the Python binding. --- clang/bindings/python/clang/cindex.py | 12 ++ .../bindings/python/tests/cindex/test_type.py | 22 +++ clang/docs/ReleaseNotes.rst | 4 clang/include/clang-c/Index.h | 12 ++ clang/tools/libclang/CXType.cpp | 17 ++ clang/tools/libclang/libclang.map | 1 + 6 files changed, 68 insertions(+) diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 2319534a6f121..5830dc2149348 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2593,6 +2593,17 @@ def get_canonical(self): """ return Type.from_result(conf.lib.clang_getCanonicalType(self), (self,)) +def get_fully_qualified_name(self, policy, with_global_ns_prefix = False): +""" +Get the fully qualified name for a type. + +This includes full qualification of all template parameters. + +policy - This PrintingPolicy can further refine the type formatting +with_global_ns_prefix - If true, function will prepend a '::' to qualified names +""" +return _CXString.from_result(conf.lib.clang_getFullyQualifiedName(self, policy, with_global_ns_prefix)) + def is_const_qualified(self): """Determine whether a Type has the "const" qualifier set. @@ -4022,6 +4033,7 @@ def set_property(self, property, value): ("clang_getTypeSpelling", [Type], _CXString), ("clang_hashCursor", [Cursor], c_uint), ("clang_isAttribute", [CursorKind], bool), +("clang_getFullyQualifiedName", [Type, PrintingPolicy, c_uint], _CXString), ("clang_isConstQualifiedType", [Type], bool), ("clang_isCursorDefinition", [Cursor], bool), ("clang_isDeclaration", [CursorKind], bool), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index a9473e1dc2458..b2a82a00b4f40 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] +self.assertEqual(arg.type.get_fully_qualified_name(pp), "home::Bar *") +self.assertEqual(arg.type.get_fully_qualified_name(pp, True), "::home::Bar *") + def test_base_classes(self): source = """ class A { int a; }; diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 9c45965dc4d82..f228a32acd51d 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -589,6 +589,8 @@ libclang - Added ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``clang_getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. - Fixed a buffer overflow in ``CXString`` implementation. The fix may result in increased memory allocation. @@ -643,6 +645,8 @@ Python Binding Changes the cursor is a specialization of. - Added ``Type.get_methods``, a binding for ``clang_visitCXXMethods``, which allows visiting the methods of a class. +- Added ``Type.getFullyQualifiedName``, which provides fully qualified type names as + instructed by a PrintingPolicy. OpenMP Support -- diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h index 38e2417dcd181..25700a48c928c 100644 --- a/clang/include/clang-c/Index.h +++ b/clang/include/clang-c/Index.h @@ -4223,6 +4223,18 @@ CINDEX_LINKAGE CXString clang_getCursorPrettyPrinted(CXCursor Cursor, CINDEX_LINKAGE CXString clang_getTypePrettyPrinted(CXType CT, CXPrintingPolicy cxPolicy); +/** + * Get the fully qualified name for a type. + * + * This includes full qualification of all template parameters. + * + * Policy - Further refine the type formatting + * WithGlobalNsPrefix - If non-zero, function will prepe
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
@@ -535,6 +535,28 @@ def test_pretty(self): pp.set_property(PrintingPolicyProperty.SuppressTagKeyword, False) self.assertEqual(f.type.get_canonical().pretty_printed(pp), "struct X") +def test_fully_qualified_name(self): +source = """ +namespace home { + class Bar { + }; + class Foo { +public: + void setIt(Bar*); + }; +} +class A : public home::Foo { +}; +""" +tu = get_tu(source, lang="cpp") +c = get_cursor(tu, "A") +pp = PrintingPolicy.create(c) +base = list(c.get_children())[0].type.get_declaration() +set_it = list(base.get_children())[1] +arg = list(set_it.get_arguments())[0] epistax wrote: Thanks, didn't occur to me that there would be a more direct route. https://github.com/llvm/llvm-project/pull/135420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [cindex] Add support for calling getFullyQualifiedName to the Python binding. (PR #135420)
epistax wrote: > @epistax I just realized you don't have perms to merge, right? If this is > ready from your side, shall I merge? That's right. Yep this is ready from my side. I'd appreciate it if you merged! Thanks https://github.com/llvm/llvm-project/pull/135420 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits