1
|
1 module ast.Decl;
|
|
2
|
|
3 import ast.Exp,
|
|
4 ast.Stmt;
|
|
5
|
|
6 import lexer.Token;
|
|
7
|
|
8 import sema.SymbolTable;
|
|
9
|
|
10 enum DeclType
|
|
11 {
|
|
12 VarDecl,
|
|
13 FuncDecl,
|
|
14 }
|
|
15
|
|
16 class Decl
|
|
17 {
|
|
18 this(DeclType declType)
|
|
19 {
|
|
20 this.declType = declType;
|
|
21 }
|
|
22
|
|
23 DeclType declType;
|
|
24 Scope env;
|
|
25 }
|
|
26
|
|
27 class VarDecl : Decl
|
|
28 {
|
|
29 this(Identifier type, Identifier identifier,
|
|
30 Exp e = null)
|
|
31 {
|
|
32 super(DeclType.VarDecl);
|
|
33 this.type = type;
|
|
34 this.identifier = identifier;
|
|
35 this.init = e;
|
|
36 }
|
|
37
|
|
38 Identifier type, identifier;
|
|
39 Exp init;
|
|
40 }
|
|
41
|
|
42 class FuncDecl : Decl
|
|
43 {
|
|
44 this(Identifier type, Identifier identifier,
|
|
45 VarDecl[] funcArgs, Stmt[] statements)
|
|
46 {
|
|
47 super(DeclType.FuncDecl);
|
|
48 this.type = type;
|
|
49 this.identifier = identifier;
|
|
50 this.funcArgs = funcArgs;
|
|
51 this.statements = statements;
|
|
52 }
|
|
53
|
|
54 Identifier type, identifier;
|
|
55 VarDecl[] funcArgs;
|
|
56 Stmt[] statements;
|
|
57 }
|
|
58
|