[cfe-dev] AST structrue of enums in clang

Douglas Gregor dgregor at apple.com
Fri Mar 4 07:22:26 PST 2011


On Mar 4, 2011, at 3:31 AM, Talespin Kit wrote:

> Assume the follwing code
>  
> class A
> {
>     public:
>         enum E { // E is EnumDecl
>                         ec1,  // EnumConstantDecl
>                         ec2
>                    };
>  
>        void foo()
>        {
>                E eVar = ec1; // this is a DeclStmt, but what is the type of eVar and ec1?
>        }
> };
>  
> In the above code we know that the line E eVar = ec1; is a DeclStmt. What are the subcomponents of that.
>  
> What is the type of ec1?.
>  
> _______________________________________________


The AST dump is a good way to see this information:

$ clang -cc1 -ast-dump t3.cpp 
typedef __int128_t __int128_t;
typedef __uint128_t __uint128_t;
struct __va_list_tag {
    struct __va_list_tag;
    unsigned int gp_offset;
    unsigned int fp_offset;
    void *overflow_arg_area;
    void *reg_save_area;
};
typedef struct __va_list_tag __va_list_tag;
typedef __va_list_tag __builtin_va_list[1];
class A {
    class A;
public:
    enum E {
        ec1,
        ec2
    };
    void foo() (CompoundStmt 0x101843320 <t3.cpp:10:8, line:12:8>
  (DeclStmt 0x101843300 <line:11:16, col:28>
    0x101843280 "A::E eVar =
      (DeclRefExpr 0x1018432d0 <col:25> 'enum A::E' EnumConstant='ec1' 0x1018430f0)"))


};

	- Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110304/3107be51/attachment.html>


More information about the cfe-dev mailing list