[PATCH] libclang: New functions clang_Type_getNumTemplateArguments, clang_Type_getTemplateArgument.
Dmitri Gribenko
gribozavr at gmail.com
Wed Feb 26 04:03:06 PST 2014
================
Comment at: test/Index/print-type.cpp:8
@@ -7,1 +7,3 @@
+template <typename T, unsigned U, typename V>
+struct Baz { };
----------------
Please also add a template template parameter:
..., template<typename X> class W>
Please add another test with a variadic template.
================
Comment at: tools/libclang/CXType.cpp:878
@@ +877,3 @@
+ return -1;
+ const CXXRecordDecl* RecordDecl = T->getAsCXXRecordDecl();
+ if (!RecordDecl)
----------------
Star should go to the right (here and everywhere else):
Foo *Bar = baz();
Also, two consecutive spaces after '='.
================
Comment at: tools/libclang/CXType.cpp:881-882
@@ +880,4 @@
+ return -1;
+ const ClassTemplateSpecializationDecl* TemplateDecl =
+ dyn_cast_or_null<ClassTemplateSpecializationDecl>(RecordDecl);
+ if (!TemplateDecl)
----------------
Why do we need _or_null here? Null case is handled above.
Also, partial specialzations -- testcase?
================
Comment at: tools/libclang/CXType.cpp:874
@@ -873,1 +873,3 @@
+int clang_Type_getNumTemplateArguments(CXType X) {
+ QualType T = GetQualType(X);
----------------
'X' is not an informative parameter name. 'CT' would be better.
================
Comment at: include/clang-c/Index.h:3080-3081
@@ -3079,1 +3079,4 @@
/**
+ * \brief Returns the number of template parameters for given class template
+ * specialization, or -1 if type T is not a class template specialization.
+ *
----------------
The comment should probably say "template arguments".
Also, unnecessary indentation on the second line.
================
Comment at: include/clang-c/Index.h:3087-3088
@@ +3086,4 @@
+/**
+ * \brief Returns the template parameter of a template class specialization
+ * at given index.
+ */
----------------
Same as above.
================
Comment at: tools/c-index-test/c-index-test.c:1281
@@ +1280,3 @@
+ {
+ int numTArgs = clang_Type_getNumTemplateArguments(T);
+ if (numTArgs != -1 && numTArgs != 0) {
----------------
Variable names should start with an uppercase letter.
================
Comment at: tools/c-index-test/c-index-test.c:1288
@@ +1287,3 @@
+ if (TArg.kind != CXType_Invalid) {
+ PrintTypeAndTypeKind(TArg, " [%s] [%s]");
+ }
----------------
This format is confusing (is it two parameters instead of one?) Consider more verbose [type=%s] [typekind=%s]
================
Comment at: tools/libclang/CXType.cpp:895-896
@@ +894,4 @@
+ return MakeCXType(QualType(), GetTU(CT));
+ const ClassTemplateSpecializationDecl* TemplateDecl =
+ dyn_cast_or_null<ClassTemplateSpecializationDecl>(RecordDecl);
+ if (!TemplateDecl)
----------------
Same comment about _or_null.
================
Comment at: tools/libclang/CXType.cpp:899
@@ +898,3 @@
+ return MakeCXType(QualType(), GetTU(CT));
+ const TemplateArgumentList& TA = TemplateDecl->getTemplateArgs();
+ if (TA.size() <= i)
----------------
& should be attached to the right.
================
Comment at: test/Index/print-type.cpp:24
@@ -20,2 +23,3 @@
typedef int ArrayType[5];
+ Baz<int, 1, bool> baz;
};
----------------
Consider using a class type instead of 'bool'. The builtin type case is covered by 'int'.
http://llvm-reviews.chandlerc.com/D1688
More information about the cfe-commits
mailing list