1 module vayne.ast.visitor;
2 
3 
4 import vayne.ast.node;
5 
6 
7 interface IVisitorNode {
8 	void accept(IVisitor);
9 }
10 
11 
12 mixin template NodeInterface(T) {
13 	void visit(T);
14 }
15 
16 
17 interface IVisitor {
18 	mixin NodeInterface!Expression;
19 	mixin NodeInterface!Constant;
20 	mixin NodeInterface!Identifier;
21 	mixin NodeInterface!UnaryOp;
22 	mixin NodeInterface!BinaryOp;
23 	mixin NodeInterface!ConditionalExpression;
24 	mixin NodeInterface!IndexOp;
25 	mixin NodeInterface!PrefixOp;
26 	mixin NodeInterface!SuffixOp;
27 	mixin NodeInterface!SliceOp;
28 	mixin NodeInterface!DispatchOp;
29 	mixin NodeInterface!FunctionCall;
30 	mixin NodeInterface!WithExpression;
31 	mixin NodeInterface!WithStatement;
32 	mixin NodeInterface!IfStatement;
33 	mixin NodeInterface!LoopStatement;
34 	mixin NodeInterface!Output;
35 	mixin NodeInterface!StatementBlock;
36 	mixin NodeInterface!Module;
37 }
38 
39 
40 mixin template VisitNode(T) {
41 	override void visit(T node) {
42 		foreach (child; node.children) {
43 			if (child)
44 				child.accept(this);
45 		}
46 	}
47 }
48 
49 
50 class Visitor : IVisitor {
51 	mixin VisitNode!Expression;
52 	mixin VisitNode!Constant;
53 	mixin VisitNode!Identifier;
54 	mixin VisitNode!UnaryOp;
55 	mixin VisitNode!BinaryOp;
56 	mixin VisitNode!ConditionalExpression;
57 	mixin VisitNode!IndexOp;
58 	mixin VisitNode!PrefixOp;
59 	mixin VisitNode!SuffixOp;
60 	mixin VisitNode!SliceOp;
61 	mixin VisitNode!DispatchOp;
62 	mixin VisitNode!FunctionCall;
63 	mixin VisitNode!WithExpression;
64 	mixin VisitNode!WithStatement;
65 	mixin VisitNode!IfStatement;
66 	mixin VisitNode!LoopStatement;
67 	mixin VisitNode!Output;
68 	mixin VisitNode!StatementBlock;
69 	mixin VisitNode!Module;
70 }