On 2014/10/14 11:10:00, marja wrote:
Acutally, I think it's silly that all visitors need to implement the
recursive
AST walking themselves.
That's the silliness of the visitor pattern. :-)
Can't we have it implemented in one place (in the
superclass) and if the actual visitors want to do something else than
just
visit children, they'd need to override the corresponding func?
Things get a bit tricky, because in general you would need hooks for the
various
points in the recursion for every node type. If you look e.g. at the pretty
printer:
---------------------------------------------------------------------
void PrettyPrinter::VisitIfStatement(IfStatement* node) {
Print("if (");
Visit(node->condition());
Print(") ");
Visit(node->then_statement());
if (node->HasElseStatement()) {
Print(" else ");
Visit(node->else_statement());
}
}
---------------------------------------------------------------------
Note that the recursion (the various calls to Visit) is deeply nested into
the
logic of what to do at an IfStatement (the 3 Print calls, actually a 4th one
could be there for an empty else clause). This means that you would need 4
calls
to (virtual) hooks for the IfStatement alone. The pretty printer would
override
3, while the renumbering pass would only override 1. Not sure if this is a
big
win. The visitor pattern is verbose, but there's no easy way around this in
C++.
https://codereview.chromium.org/636403003/
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.