[cfe-dev] [libClang] Get name of method parameter or variable type

Alexander Droste via cfe-dev cfe-dev at lists.llvm.org
Sun Jun 11 15:41:18 PDT 2017


Hi Sam,

here's one way which might work.
First, convert the CXType to a QualType with 'GetQualType'.

Combining 'getTypePtr'
https://github.com/llvm-mirror/clang/blob/master/include/clang/AST/Type.h#L653

and 'getPointeeOrArrayElementType'
https://github.com/llvm-mirror/clang/blob/master/include/clang/AST/Type.h#L1946
should provide the unqualified pointee type.

Probably, you also want to ignore implicit casts
https://github.com/llvm-mirror/clang/blob/master/include/clang/AST/Expr.h#L727 .

The QualType can be converted back to a CXType with 'MakeCXType'
https://github.com/trolldbois/libclang/blob/master/CXType.cpp#L98 .

-Alex

On 11.06.17 22:13, Sam Vanheer via cfe-dev wrote:
> I'm trying to get the name of method parameter and variable types, but
> the name returned by clang_getTypeSpelling contains part of the type as
> used, like "const", "&", etc.
> 
> Is there any way to use libClang's API to get just the name of the type,
> without any of these additions? I'm currently removing these from the
> name manually, but it seems superfluous when Clang already has it.
> 
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> 



More information about the cfe-dev mailing list