[cfe-dev] Recursive ASTMatcher expressions
klimek at google.com
Tue Aug 26 05:16:40 PDT 2014
On Tue Aug 26 2014 at 12:44:50 PM Luke Titley <luke.titley at gmail.com> wrote:
> Hi my name is Luke Titley,
> I'm a c++ developer based in London and I'm experimenting with clang
> It's really a lot of fun and already I can see the power of using AST
> matchers for automatic re-factoring.
> clang, really does provide a top notch set of tools.
> There's one thing I'm not 100 % clear on.
> Is is possible to create recursive/(self referential) ASTMatcher
> For example, if I wanted a matcher to match this scenario.
> int var = 1;
> int * foo = &var;
> int * bar = foo;
> int * baz = bar;
> ... Add infinitum ...
> I'd like my matcher to match
> and baz
> I want to track every pointer that is initialized with a reference to a
> variable that is initialized with a value of 1.
> I imagine this would be done with some sort of self referential
> definition. Is that correct ?
Well, we have self-referential matchers (equalsBoundNode), but this would
also require looping over the initialization sequences, which we don't
Currently the easiest way is to get a callback for each pointer, and then
do the traversal yourself in the callback.
I'd also be curious whether we can implement matchers that would lead to
this, but I think they'd need to be somehow integrated into the matching
process (you'd want to memoize based on the matches, otherwise you have an
extra O(N) you don't really need).
> Thanks in advance,
> and thanks for all the hard work!
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev