[PATCH] libclang: New functions clang_Type_getNumTemplateArguments, clang_Type_getTemplateArgument.

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Sep 24 17:12:56 PDT 2013


Hi,

Could you also add some tests for this ?
I suggest modifying the PrintType() function in c-index-test.c to print info about template arguments and then adding test cases in "test/Index/print-type.cpp".

-Argyrios

On Sep 16, 2013, at 7:57 AM, Matthieu Nottale <mnottale at aldebaran-robotics.com> wrote:

> http://llvm-reviews.chandlerc.com/D1688
> 
> Files:
>  include/clang-c/Index.h
>  tools/libclang/CXType.cpp
>  tools/libclang/libclang.exports
> 
> Index: include/clang-c/Index.h
> ===================================================================
> --- include/clang-c/Index.h
> +++ include/clang-c/Index.h
> @@ -2994,6 +2994,20 @@
> CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
> 
> /**
> + * \brief Returns the number of template parameters for given class template
> + *   specialization, or -1 if type T is not a class template specialization.
> + *
> + */
> +CINDEX_LINKAGE int clang_Type_getNumTemplateArguments(CXType T);
> +
> +/**
> +* \brief Returns the template parameter of a template class specialization
> +*    at given index.
> +*/
> +CINDEX_LINKAGE CXType clang_Type_getTemplateArgument(CXType T, unsigned i);
> +
> +
> +/**
>  * \brief Returns non-zero if the cursor specifies a Record member that is a
>  *   bitfield.
>  */
> Index: tools/libclang/CXType.cpp
> ===================================================================
> --- tools/libclang/CXType.cpp
> +++ tools/libclang/CXType.cpp
> @@ -832,4 +832,34 @@
>   return cxstring::createDup(encoding);
> }
> 
> +int clang_Type_getNumTemplateArguments(CXType X)
> +{
> +  QualType T = GetQualType(X);
> +  const CXXRecordDecl* RecordDecl =  T->getAsCXXRecordDecl();
> +  if (!RecordDecl)
> +    return -1;
> +  const ClassTemplateSpecializationDecl* TemplateDecl = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RecordDecl);
> +  if (!TemplateDecl)
> +    return -1;
> +  return TemplateDecl->getTemplateArgs().size();
> +}
> +
> +CXType clang_Type_getTemplateArgument(CXType CT, unsigned i)
> +{
> +  QualType T = GetQualType(CT);
> +  const CXXRecordDecl* RecordDecl = T->getAsCXXRecordDecl();
> +  if (!RecordDecl)
> +    return MakeCXType(QualType(), GetTU(CT));
> +  const ClassTemplateSpecializationDecl* TemplateDecl = dyn_cast_or_null<ClassTemplateSpecializationDecl>(RecordDecl);
> +  if (!TemplateDecl)
> +    return MakeCXType(QualType(), GetTU(CT));
> +  const TemplateArgumentList& TA =  TemplateDecl->getTemplateArgs();
> +  if (TA.size() <= i)
> +    return MakeCXType(QualType(), GetTU(CT));
> +  const TemplateArgument& A = TA.get(i);
> +  if (A.getKind() != TemplateArgument::Type)
> +    return MakeCXType(QualType(), GetTU(CT));
> +  return MakeCXType(A.getAsType(), GetTU(CT));
> +}
> +
> } // end: extern "C"
> Index: tools/libclang/libclang.exports
> ===================================================================
> --- tools/libclang/libclang.exports
> +++ tools/libclang/libclang.exports
> @@ -63,6 +63,8 @@
> clang_Type_getAlignOf
> clang_Type_getSizeOf
> clang_Type_getOffsetOf
> +clang_Type_getNumTemplateArguments
> +clang_Type_getTemplateArgument
> clang_VerbatimBlockLineComment_getText
> clang_VerbatimLineComment_getText
> clang_HTMLTagComment_getAsString
> <D1688.1.patch>_______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list