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.
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),
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)