[cfe-dev] Getting multiple AST matches as a list

Vane, Edwin edwin.vane at intel.com
Fri Aug 30 07:17:45 PDT 2013


Wouldn't binding the result of the initListExpr() give you access to the InitListExpr that you could get the items from? Or did you want something that was a little nicer?

Another option would be to bind to every child of the initListExpr() but then you don't get the matches all at once to your match callback. Rather the callback gets called once per child.

If you wanted every child at once, you'd need to bind a different name to each child. There's no way to do that currently. Or we'd need some mechanism to collect a bunch of matches under a single name.

> -----Original Message-----
> From: cfe-dev-bounces at cs.uiuc.edu [mailto:cfe-dev-bounces at cs.uiuc.edu] On
> Behalf Of Jesper Eskilson
> Sent: Friday, August 30, 2013 7:23 AM
> To: cfe-dev at cs.uiuc.edu
> Subject: [cfe-dev] Getting multiple AST matches as a list
> 
> 
> Hello,
> 
> I'm learning about how to use AST matchers, but one usecase is giving me
> headaches. I have a declaration like this:
> 
> const char *list = { "a", "b" };
> 
> and I would like to retrieve the array initializer as a list of strings in my matcher
> callback.  I've managed to get a pointer to the InitListExpr which looks like this:
> 
> > InitListExpr 0x46be670 'const char *[2]'
> > |-ImplicitCastExpr 0x46be6c0 'const char *' <ArrayToPointerDecay>
> > |`-StringLiteral 0x46be5b8 'const char [12]' lvalue "semihosting"
> > `-ImplicitCastExpr 0x46be6d8 'const char *' <ArrayToPointerDecay>
> >   `-StringLiteral 0x46be5f0 'const char [4]' lvalue "swo"
> 
> I've looked through the traversal matchers, but it seems like I can only get
> matchers which will generate a match for each element in the list.
> Is there any way to generate a single match with all elements wrapped up in a
> list?
> 
> /Jesper
> --
> *Jesper Eskilson* /Development Engineer/ IAR Systems AB Box 23051,
> Strandbodgatan 1
> SE-750 23 Uppsala, SWEDEN
> E-mail: jesper.eskilson at iar.com <mailto:jesper.eskilson at iar.com>
> Website: www.iar.com
> <http://www.iar.com> Twitter: www.twitter.com/iarsystems
> <http://www.twitter.com/iarsystems>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list