[cfe-dev] traversing structure initializers in c99 style
Peter Collingbourne
peter at pcc.me.uk
Sat Nov 27 09:25:25 PST 2010
On Sat, Nov 27, 2010 at 06:42:49PM +0200, Vladimir Kirillov wrote:
> Hello, cfe-dev!
>
> Suppose i have such statement:
>
> struct data {
> int a;
> int b;
> } instance = {
> .b = 10,
> .a = 5,
> };
>
> When calling getAnyInitializer() for VarDecl of instance, and
> traversing it's children Stmts, it sequentially iterates over the
> values, without any mentions of the C99 style used.
>
> Is it possible to detect it and be aware of the order of fields
> during initialization?
Hi Vladimir,
The InitListExpr you get from getAnyInitializer() is in
semantic form, which among other things means that designated
initialisers have been eliminated. To get the syntactic form of
the InitListExpr, which includes designated initialisers, you can
call InitListExpr::getSyntacticForm(). See also the comments for
InitListExpr for more information.
Thanks,
--
Peter
More information about the cfe-dev
mailing list