dmd.apply: Implement walkPreorder helper function #14883
+304
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Looking at putting #14830 into the front-end where it feels like it belongs (@kinke). I'll have to see whether what I'm using this for actually makes sense, this change only breaks out the boilerplate part into its own standalone PR.
Current expression/statement apply helper implements a post-order DFS traversal of the AST. This is fine when you want to descend and mark all children first before each connecting parent, but doesn't help when you want to traverse the AST in a more forwards direction as you'd expect the flow of user code to be executed in.
i.e: Given a stoppable visitor with
override void visit(LabelStatement) { stop = true; }
and marking every other statement/expression visited, for the following:Traversing post-order will give you
Traversing pre-order will instead give you
Wait, if you want forward walking, shouldn't you be instead using a
ParseTimeTransitiveVisitor
?Yes, maybe, well, not sure anymore the more I think about it. At the very least, one negative aspect of
ParseTimeTransitiveVisitor
is that it by default visits all connecting nodes, including types, constraints, and base class declarations. This would waste extra time walking the trees just to get to the nodes you actually want to visit.Couldn't
PostorderStatementVisitor
andPreorderStatementVisitor
just be folded into the same visitor, make it a template instead of 300 lines of almost (but not quite) identical code?Yes, but would it be readable having both paths mixed together, ehh... maybe. We'll see how this goes first.