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,
|
22
|
14 StructDecl,
|
1
|
15 }
|
|
16
|
|
17 class Decl
|
|
18 {
|
|
19 this(DeclType declType)
|
|
20 {
|
|
21 this.declType = declType;
|
|
22 }
|
|
23
|
|
24 DeclType declType;
|
|
25 Scope env;
|
|
26 }
|
|
27
|
|
28 class VarDecl : Decl
|
|
29 {
|
|
30 this(Identifier type, Identifier identifier,
|
|
31 Exp e = null)
|
|
32 {
|
|
33 super(DeclType.VarDecl);
|
|
34 this.type = type;
|
|
35 this.identifier = identifier;
|
|
36 this.init = e;
|
|
37 }
|
|
38
|
|
39 Identifier type, identifier;
|
|
40 Exp init;
|
|
41 }
|
|
42
|
|
43 class FuncDecl : Decl
|
|
44 {
|
|
45 this(Identifier type, Identifier identifier,
|
|
46 VarDecl[] funcArgs, Stmt[] statements)
|
|
47 {
|
|
48 super(DeclType.FuncDecl);
|
|
49 this.type = type;
|
|
50 this.identifier = identifier;
|
|
51 this.funcArgs = funcArgs;
|
|
52 this.statements = statements;
|
|
53 }
|
|
54
|
|
55 Identifier type, identifier;
|
|
56 VarDecl[] funcArgs;
|
|
57 Stmt[] statements;
|
|
58 }
|
|
59
|
22
|
60 class StructDecl : Decl
|
|
61 {
|
|
62 this(Identifier identifier,
|
|
63 VarDecl[] vars)
|
|
64 {
|
|
65 super(DeclType.StructDecl);
|
|
66 this.identifier = identifier;
|
|
67 this.vars = vars;
|
|
68 }
|
|
69
|
|
70 Identifier identifier;
|
|
71 VarDecl[] vars;
|
|
72 }
|
|
73
|