[cfe-dev] Expr walk up? Looking for Enum name not value?

Lukas Vogel lukedirtwalkerdev at gmail.com
Sun Apr 21 02:15:18 PDT 2013


If you use VisitEnumDecl(ed) you can use an iterator to loop over all
EnumConstantDecl and from those you can get the name with getNameAsString()
I implemented this myself just few days ago (if you want to take a look:


2013/4/20 Gábor Kozár <kozargabor at gmail.com>

> Hi,
> If I understand your problem correctly, what you need is to look for
> typecasts (e.g. ImplicitCast) where the source type is an enum. I actually
> do not know how enum values appear in the AST, i.e. whether they are
> expanded to their values, but I'm assuming that they are not: in this case
> the typecast AST node probably has an EnumConstantDecl as a child
> (somewhere below an Expr), which you should be able to find without too
> much of an issue, and it will give you the information you need. Try
> dumping some example code (using enums) AST to figure out what is it you
> exactly need to do.
> Also consult the documentation for EnumDecl and EnumConstantDecl types:
> http://clang.llvm.org/doxygen/classclang_1_1EnumDecl.html
> http://clang.llvm.org/doxygen/classclang_1_1EnumConstantDecl.html
> Hope this helps!
> Gabor
> 2013/4/18 steveneliuk <s.eliuk at sisa.samsung.com>
>> Hi there,
>> There are various implemented visit*() statements in
>> myRecursiveASTVisitor()
>> and I am looking for a way to obtain the actual enum name before it is
>> converted to a value. The value works fine for Source-to-Source
>> translation
>> but some have complained because it is not as easy to read. I guess it is
>> a
>> MacroID and therefore is not contained in the original source. I can think
>> of many laborious ways to obtain this but I know there has to be a built
>> in
>> function to obtain the name,
>> ie)
>> cl_device_type CL_DEVICE_TYPE_ALL has a value of 4294967295U, but I need
>> CL_DEVICE_TYPE_ALL to keep the translation easy to read.
>> Any advice would be appreciated!!!
>> --
>> View this message in context:
>> http://clang-developers.42468.n3.nabble.com/Expr-walk-up-Looking-for-Enum-name-not-value-tp4031582.html
>> Sent from the Clang Developers mailing list archive at Nabble.com.
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130421/192e67c2/attachment.html>

More information about the cfe-dev mailing list