1 /**
2 This module defines the interfaces that work with statement and expression nodes. Compiler
3 implements these interfaces. 
4 
5 ────────────────────────────────────────────────────────────────────────────────
6 
7 Copyright (C) 2021 pillager86.rf.gd
8 
9 This program is free software: you can redistribute it and/or modify it under 
10 the terms of the GNU General Public License as published by the Free Software 
11 Foundation, either version 3 of the License, or (at your option) any later 
12 version.
13 
14 This program is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License along with 
19 this program.  If not, see <https://www.gnu.org/licenses/>.
20  */
21 module mildew.visitors;
22 
23 import std.variant;
24 
25 import mildew.nodes;
26 
27 package:
28 
29 /// Defines an interface that can visit ExpressionNodes
30 interface IExpressionVisitor
31 {
32     Variant visitLiteralNode(LiteralNode lnode);
33     Variant visitFunctionLiteralNode(FunctionLiteralNode flnode);
34     Variant visitLambdaNode(LambdaNode lnode);
35     Variant visitTemplateStringNode(TemplateStringNode tsnode);
36     Variant visitArrayLiteralNode(ArrayLiteralNode alnode);
37     Variant visitObjectLiteralNode(ObjectLiteralNode olnode);
38     Variant visitClassLiteralNode(ClassLiteralNode clnode);
39     Variant visitBinaryOpNode(BinaryOpNode bonode);
40     Variant visitUnaryOpNode(UnaryOpNode uonode);
41     Variant visitPostfixOpNode(PostfixOpNode ponode);
42     Variant visitTerniaryOpNode(TerniaryOpNode tonode);
43     Variant visitVarAccessNode(VarAccessNode vanode);
44     Variant visitFunctionCallNode(FunctionCallNode fcnode);
45     Variant visitArrayIndexNode(ArrayIndexNode ainode);
46     Variant visitMemberAccessNode(MemberAccessNode manode);
47     Variant visitNewExpressionNode(NewExpressionNode nenode);
48     Variant visitSuperNode(SuperNode snode);
49     Variant visitYieldNode(YieldNode ynode);
50 }
51 
52 /// Defines an interface that can visit StatementNodes
53 interface IStatementVisitor 
54 {
55     Variant visitVarDeclarationStatementNode(VarDeclarationStatementNode vdsnode);
56     Variant visitBlockStatementNode(BlockStatementNode bsnode);
57     Variant visitIfStatementNode(IfStatementNode isnode);
58     Variant visitSwitchStatementNode(SwitchStatementNode ssnode);
59     Variant visitWhileStatementNode(WhileStatementNode wsnode);
60     Variant visitDoWhileStatementNode(DoWhileStatementNode dwsnode);
61     Variant visitForStatementNode(ForStatementNode fsnode);
62     Variant visitForOfStatementNode(ForOfStatementNode fosnode);
63     Variant visitBreakStatementNode(BreakStatementNode bsnode);
64     Variant visitContinueStatementNode(ContinueStatementNode csnode);
65     Variant visitReturnStatementNode(ReturnStatementNode rsnode);
66     Variant visitFunctionDeclarationStatementNode(FunctionDeclarationStatementNode fdsnode);
67     Variant visitThrowStatementNode(ThrowStatementNode tsnode);
68     Variant visitTryCatchBlockStatementNode(TryCatchBlockStatementNode tcbsnode);
69     Variant visitDeleteStatementNode(DeleteStatementNode dsnode);
70     Variant visitClassDeclarationStatementNode(ClassDeclarationStatementNode cdsnode);
71     Variant visitExpressionStatementNode(ExpressionStatementNode esnode);
72 }
73 
74 /// Defines an interface that can visit both ExpressionNodes and StatementNodes
75 interface INodeVisitor : IExpressionVisitor, IStatementVisitor {}