[cfe-dev] traversing structure initializers in c99 style

Vladimir Kirillov proger at uaoug.org.ua
Sat Nov 27 14:25:22 PST 2010


On 17:25 Sat 27 Nov, Peter Collingbourne wrote:
> 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.

Right! That's it, I've missed the InitListExpr part entirely. Thank you.



More information about the cfe-dev mailing list