diff options
| author | Jonathan Coe <jbcoe@me.com> | 2018-09-11 12:44:52 +0000 |
|---|---|---|
| committer | Jonathan Coe <jbcoe@me.com> | 2018-09-11 12:44:52 +0000 |
| commit | 5f5d3fa098eac9505cfb37898a7ac31177e04917 (patch) | |
| tree | d3b9290b1f77216cba4bef7865e395450cd5f47a /clang/bindings/python | |
| parent | 8f776db7ff8898959312b234d5d6671f3e2ec61c (diff) | |
| download | bcm5719-llvm-5f5d3fa098eac9505cfb37898a7ac31177e04917.tar.gz bcm5719-llvm-5f5d3fa098eac9505cfb37898a7ac31177e04917.zip | |
[python bindings] Expose getNumTemplateArguments
Expose the C bindings for clang_Type_getNumTemplateArguments() and
clang_Type_getTemplateArgumentAsType() in the python API.
Patch by kjteske (Kyle Teske).
Reviewed By: jbcoe
Subscribers: cfe-commits
Differential Revision: https://reviews.llvm.org/D51299
llvm-svn: 341930
Diffstat (limited to 'clang/bindings/python')
| -rw-r--r-- | clang/bindings/python/clang/cindex.py | 15 | ||||
| -rw-r--r-- | clang/bindings/python/tests/cindex/test_type.py | 25 |
2 files changed, 40 insertions, 0 deletions
diff --git a/clang/bindings/python/clang/cindex.py b/clang/bindings/python/clang/cindex.py index 56fcc78763e..c9f4a5e91a0 100644 --- a/clang/bindings/python/clang/cindex.py +++ b/clang/bindings/python/clang/cindex.py @@ -2254,6 +2254,12 @@ class Type(Structure): return res + def get_num_template_arguments(self): + return conf.lib.clang_Type_getNumTemplateArguments(self) + + def get_template_argument_type(self, num): + return conf.lib.clang_Type_getTemplateArgumentAsType(self, num) + def get_canonical(self): """ Return the canonical type for a Type. @@ -3999,6 +4005,15 @@ functionList = [ Type, Type.from_result), + ("clang_Type_getNumTemplateArguments", + [Type], + c_int), + + ("clang_Type_getTemplateArgumentAsType", + [Type, c_uint], + Type, + Type.from_result), + ("clang_Type_getOffsetOf", [Type, c_interop_string], c_longlong), diff --git a/clang/bindings/python/tests/cindex/test_type.py b/clang/bindings/python/tests/cindex/test_type.py index 4dec0583c7b..12db9964078 100644 --- a/clang/bindings/python/tests/cindex/test_type.py +++ b/clang/bindings/python/tests/cindex/test_type.py @@ -436,3 +436,28 @@ class TestType(unittest.TestCase): self.assertIsNotNone(testInteger, "Could not find testInteger.") self.assertEqual(testInteger.type.get_address_space(), 2) + + def test_template_arguments(self): + source = """ + class Foo { + }; + template <typename T> + class Template { + }; + Template<Foo> instance; + int bar; + """ + tu = get_tu(source, lang='cpp') + + # Varible with a template argument. + cursor = get_cursor(tu, 'instance') + cursor_type = cursor.type + self.assertEqual(cursor.kind, CursorKind.VAR_DECL) + self.assertEqual(cursor_type.spelling, 'Template<Foo>') + self.assertEqual(cursor_type.get_num_template_arguments(), 1) + template_type = cursor_type.get_template_argument_type(0) + self.assertEqual(template_type.spelling, 'Foo') + + # Variable without a template argument. + cursor = get_cursor(tu, 'bar') + self.assertEqual(cursor.get_num_template_arguments(), -1) |

