Introducing BoundTreeVisitor and BoundTreeWalker #104
Merged
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.
Summary
This PR introduces
BoundTreeVisitor
andBoundTreeWalker
patterns to all the bound nodes.This PR also converted
ControlGraphAnalyzer
to inherit fromBoundTreeWalker
.Detail
Similar to roslyn, we use the Visitor Pattern to traverse the
BoundTree
and the nodes. This requires thatBoundNode
types needs to implementAccept(T)
method. (This could even be generated in the future)Visit*
method present in theBoundTreeVisitor
base class.The benefit to this approach is that we don't need a centralized
Visit
method withswitch
statements for every singleBoundNode
types.BoundTreeVisitor
BoundTreeVisitor
class is the base class which has all theVisit*
methods returnnull
. It provides boilerplate code for children classes to extend. Analyzers and rewriters should not directly inherit from this class and instead useBoundTreeWalker
orBoundTreeRewriter
(not implemented yet).BoundTreeWalker
BoundTreeWalker
class inherits fromBoundTreeVisitor
and provides basic depth-first traversal functionality. All nodes are examined and are not modified. Analyzers that don't modify the nodes should inherit from this class.BoundTreeRewriter (not in this PR)
BoundTreeRewriter
class also inherits fromBoundTreeVisitor
. It is similar toBoundTreeWalker
but nodes can be updated (note,BoundNode
s are immutable by design so here "updates" to the node actually creates a new node and replace the old one). The detailed implementation will be provided in future PRs.