[cfe-dev] new design of RecursiveASTVisitor

Jordy Rose jediknil at belkadan.com
Sat Jun 5 23:30:37 PDT 2010


On Sat, 5 Jun 2010 23:07:40 -0700, Zhanyong Wan (λx.x x) <wan at google.com>
wrote:
> On Sat, Jun 5, 2010 at 4:20 PM, Jordy Rose <jediknil at belkadan.com>
wrote:
>>
>> Having just written a small tree-walker myself, I want to ask what
>> returning "false" means. There's lots of ways you might want to "stop"
in
>> the middle of a traversal:
>>
>> 1. Stop traversing altogether. This is what the original proposal says,
>> if
>> I'm reading it correctly.
> 
> Yes, that's what I meant.  Think of it as throwing an exception.

<snip>

>> Do you (or does anyone) think there are enough uses of #3, #4, or #5 to
>> warrant implementing something like this? A nice way to do it could be
a
>> simple push()/pop() system -- when you say abort, it pop()s back to the
>> last saved node. Alternately, you could return a special value that
says
>> how far back to pop() (such as a particular Stmt*), with special
>> constants
>> for "Continue" and "Abort".
> 
> I suspect we are getting a bit ahead of ourselves here.  I like to
> make the design as general as possible too - as long as we don't
> introduce unnecessary complexity.  I think the use cases you described
> are rare, and I'm fine with not supporting them directly.  The user
> can always override enough methods to make the AST visitor do whatever
> he wants to do.  Or he may just create a new AST visitor class if that
> makes more sense.

Heh, I suppose so. I started out writing with the intent to make sure
"stop" was well-defined (and eventually, clearly documented), but then got
carried away with all the possible uses. Of course it's easy to modify
behavior by subclasing RecursiveASTVisitor.

Thanks,
Jordy



More information about the cfe-dev mailing list