[cfe-dev] Recursive ASTMatcher expressions

Manuel Klimek 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
> libtooling.
> 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
> expressions?
> 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
> foo
> bar
> 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
support yet.

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!
> Luke
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140826/d8e34a75/attachment.html>

More information about the cfe-dev mailing list