Mercurial > projects > dang
annotate ast/Decl.d @ 44:495188f9078e new_gen
Big update - Moving towards a better, more seperated parser
The parser no loner creates the AST directly, but through
callbacks(actions). This means the parser can be run with a different set
of actions that do something else.
The parser is not back to full strength yet, the main thing missing is the
various statements and structs.
Also added a SmallArray that uses the stack only until a given size is
exceeded, after which the array is copied unto the heap.
author | Anders Halager <halager@gmail.com> |
---|---|
date | Wed, 23 Apr 2008 00:57:45 +0200 |
parents | e331e4e816e4 |
children | da551f90e03f |
rev | line source |
---|---|
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 { | |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
45 this(Identifier type, Identifier identifier) |
1 | 46 { |
47 super(DeclType.FuncDecl); | |
48 this.type = type; | |
49 this.identifier = identifier; | |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
50 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
51 |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
52 void addParam(Identifier type, Identifier name) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
53 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
54 funcArgs ~= new VarDecl(type, name, null); |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
55 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
56 |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
57 void setBody(CompoundStatement stmts) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
58 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
22
diff
changeset
|
59 statements = stmts.statements; |
1 | 60 } |
61 | |
62 Identifier type, identifier; | |
63 VarDecl[] funcArgs; | |
64 Stmt[] statements; | |
65 } | |
66 | |
22 | 67 class StructDecl : Decl |
68 { | |
69 this(Identifier identifier, | |
70 VarDecl[] vars) | |
71 { | |
72 super(DeclType.StructDecl); | |
73 this.identifier = identifier; | |
74 this.vars = vars; | |
75 } | |
76 | |
77 Identifier identifier; | |
78 VarDecl[] vars; | |
79 } | |
80 |