[cfe-dev] [libClang] Get name of method parameter or variable type
Alexander Droste via cfe-dev
cfe-dev at lists.llvm.org
Mon Jun 12 02:37:37 PDT 2017
Good point. I missed that you're using the C interface but it seems like
similar functionality is available there:
clang_getPointeeType
https://github.com/llvm-mirror/clang/blob/master/include/clang-c/Index.h#L3437
clang_getElementType
https://github.com/llvm-mirror/clang/blob/master/include/clang-c/Index.h#L3513
Though, I couldn't find functionality to remove the qualifiers.
-Alex
2017-06-12 9:20 GMT+02:00 Sam Vanheer <duo929 at hotmail.com>:
> I was under the impression that any headers not in the clang-c directory
> are not part of the libClang API and cannot be used. Should i just
> include the headers from the clang C++ API as well then?
>
>
> Op 12/06/2017 om 0:41 schreef Alexander Droste:
> > 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
> >>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170612/fafeb44a/attachment.html>
More information about the cfe-dev
mailing list