[cfe-dev] AST structrue of enums in clang
Talespin Kit
talespin_kit at yahoo.com
Wed Mar 9 03:25:47 PST 2011
Thanks,
Calling VarDecl::getInit() to retrieve the DeclRefExpr is what i want to know. By the way, "coverage" wheather the enum has been used in the statment(as in code coverage).
--- On Mon, 3/7/11, Douglas Gregor <dgregor at apple.com> wrote:
From: Douglas Gregor <dgregor at apple.com>
Subject: Re: [cfe-dev] AST structrue of enums in clang
To: "Talespin Kit" <talespin_kit at yahoo.com>
Cc: cfe-dev at cs.uiuc.edu
Date: Monday, March 7, 2011, 3:03 PM
I don't know what you mean by "covers", but if you look at the AST dump
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)"))
You can see that that the DeclStmt has the declaration eVar as one of its child nodes, and the initializer of eVar is a DeclRefExpr that points back at the EnumConstantDecl ec1.
- Doug
On Mar 6, 2011, at 10:44 PM, Talespin Kit wrote:
Thanks for reply,
Given an EnumConstantDecl(E::e1) and DeclStmt( E eVar1 = ec1;), how to find that the DeclStmt covers the EnumConstantDecl.
--- On Fri, 3/4/11, Douglas Gregor <dgregor at apple.com> wrote:
From: Douglas Gregor <dgregor at apple.com>
Subject: Re: [cfe-dev] AST structrue of enums in clang
To: "Talespin Kit" <talespin_kit at yahoo.com>
Cc: cfe-dev at cs.uiuc.edu
Date: Friday, March 4, 2011, 3:22 PM
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/20110309/1537d4d1/attachment.html>
More information about the cfe-dev
mailing list