================
@@ -916,6 +916,135 @@ def test_get_template_argument_unsigned_value(self):
self.assertEqual(foos[1].get_template_argument_unsigned_value(0),
2**32 - 7)
self.assertEqual(foos[1].get_template_argument_unsigned_value(2), True)
+ def test_get_template_argument_integral_type(self):
+ tu = get_tu(TEMPLATE_ARG_TEST, lang="cpp")
+ foos = get_cursors(tu, "foo")
+
+ self.assertEqual(
+ foos[1].get_template_argument_integral_type(0).kind, TypeKind.INT
+ )
+ self.assertEqual(
+ foos[1].get_template_argument_integral_type(1).kind,
+ TypeKind.INVALID,
+ )
+ self.assertEqual(
+ foos[1].get_template_argument_integral_type(2).kind, TypeKind.BOOL
+ )
+
+ def test_get_template_argument_integral_type_pack(self):
+ source = """
+ template<int... Ns> struct Foo {};
+ template class Foo<1, 2, 3>;
+ """
+ tu = get_tu(source, lang="cpp")
+ foo = get_cursor(tu, "Foo")
+ # Find the specialization.
+ spec = None
+ for c in tu.cursor.walk_preorder():
+ if c.kind == CursorKind.STRUCT_DECL and c.spelling == "Foo":
+ if c.get_num_template_arguments() >= 0:
+ spec = c
+ break
+ self.assertIsNotNone(spec)
+ self.assertEqual(spec.get_num_template_arguments(), 3)
+ self.assertEqual(spec.get_template_argument_integral_type(0).kind,
TypeKind.INT)
+ self.assertEqual(spec.get_template_argument_integral_type(1).kind,
TypeKind.INT)
+ self.assertEqual(spec.get_template_argument_integral_type(2).kind,
TypeKind.INT)
+
+ def test_get_num_template_parameters(self):
+ source = "template<typename T, int N> void foo(); template<typename...
Ts> void bar(); void baz();"
+ tu = get_tu(source, lang="cpp")
+ foo = get_cursor(tu, "foo")
+ bar = get_cursor(tu, "bar")
+ baz = get_cursor(tu, "baz")
+ self.assertIsNotNone(foo)
+ self.assertIsNotNone(bar)
+ self.assertIsNotNone(baz)
+
+ self.assertEqual(foo.get_num_template_parameters(), 2)
+ self.assertEqual(bar.get_num_template_parameters(), 1)
+ self.assertEqual(baz.get_num_template_parameters(), -1)
+
+ def test_get_template_parameter(self):
+ source = "template<typename T, int N> void foo();"
+ tu = get_tu(source, lang="cpp")
+ foo = get_cursor(tu, "foo")
+ self.assertIsNotNone(foo)
+
+ t_param = foo.get_template_parameter(0)
+ n_param = foo.get_template_parameter(1)
+ self.assertEqual(t_param.kind, CursorKind.TEMPLATE_TYPE_PARAMETER)
+ self.assertEqual(t_param.spelling, "T")
+ self.assertEqual(n_param.kind, CursorKind.TEMPLATE_NON_TYPE_PARAMETER)
+ self.assertEqual(n_param.spelling, "N")
+ oob = conf.lib.clang_Cursor_getTemplateParameter(foo, 5)
----------------
fscheidl wrote:
Done
https://github.com/llvm/llvm-project/pull/183504
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits