[PATCH] Add [some] template argument-extraction calls to libclang & cindex

Rob Springer rspringer at google.com
Mon Oct 6 11:23:29 PDT 2014


Updated patch coming shortly.

================
Comment at: bindings/python/tests/cindex/test_cursor.py:260
@@ +259,3 @@
+
+    found = False
+    for foo in foos:
----------------
eliben wrote:
> Since you're really only looking for one cursor for 'foo' here, maybe this loop can be simplified away? I.g. no need for 'found' etc. The test and its kin can be made shorter
That makes sense - it took me a few tries to get my test case code written correctly, so "found" was verifying, for me, that a template was present. 
However, since the FUNCTION_DECL is returned after the FUNCTION_TEMPLATE, I can eliminate the loops.

================
Comment at: bindings/python/tests/cindex/test_cursor.py:264
@@ +263,3 @@
+        found = True
+        num_template_args = foo.get_num_template_arguments()
+        assert num_template_args == 3
----------------
eliben wrote:
> Just:
> 
>   assert foo.get_num_template_arguments() == 3
> 
> ?
Yep. Done.

================
Comment at: bindings/python/tests/cindex/test_cursor.py:287
@@ +286,3 @@
+        found = True
+        assert ctypes.c_int(foo.get_template_argument_value(0)).value == -7
+        assert ctypes.c_bool(foo.get_template_argument_value(2)).value == True
----------------
eliben wrote:
> Why the ctypes casts here?
get_template_argument_value and get_template_argument_unsigned_value return the values as 64-bit signed and unsigned integers, respectively, but the values as declared in the template are ints and bools, respectively, so I want to cast them to 32-bit values to make sure they're extracted correctly as those values.

It's really not necessary for the bools (obviously), but I suppose I'm a fan of symmetry. I'm happy to change that, though, if you think they're just clutter.

================
Comment at: include/clang-c/Index.h:2947
@@ +2946,3 @@
+ */
+CINDEX_LINKAGE int clang_Cursor_getNumTemplateArguments(CXCursor C);
+
----------------
eliben wrote:
> Since this is all only for function decls that are specializations, IMHO the comment should mention this. A small code sample could help too
Comment updated and examples added. It may be a touch verbose now, but I'll let you be the judge.

================
Comment at: tools/libclang/CXCursor.cpp:1091
@@ +1090,3 @@
+    assert(0 && "NULL FunctionTemplateSpecializationInfo retrieved");
+    return 0;
+  }
----------------
eliben wrote:
> Why 0 and not -1 here?
Oversight. Fixed & thanks!

http://reviews.llvm.org/D5621






More information about the cfe-commits mailing list