Smarter node recognition for the visitor
LPeter1997 opened this issue · comments
Right now we assume, that anything that eventually inherits from a type that has a [SyntaxTree]
annotation belongs to the same hierarchy. And I believe this is wrong. [SyntaxTree]
and [SyntaxTreeVisitor]
should be separate concepts. It's not unreasonable that I want my visitor only to visit my statements for example. But since my statements contain expressions, they will leak into the visitor.
Ideally, this code:
[SyntaxTreeVisitor(typeof(Statement))]
public abstract partial class StatementVisitor {}
[SyntaxTreeVisitor(typeof(Expression))]
public abstract partial class ExpressionVisitor {}
Would generate two very different visitors. The "scope" of what they visit would be based on the inheritance tree, and the top should be the top-level defined node in the annotation.
This would also mean, that [SyntaxTree]
would be very much independent from the visitor generation. We could even separate the two generators in code, and rename the annotation to just [Visitor]
, to note this differentiation.