Mercurial > projects > dang
annotate sema/Visitor.d @ 99:857f0d530789 new_gen
Imports and improved module statement
Allow "module a.b.c"
Supports most forms of D's import.
import A, B;
import A, B = C;
import A, B : a = b, c;
author | Anders Halager <halager@gmail.com> |
---|---|
date | Tue, 06 May 2008 21:59:22 +0200 |
parents | 48bb2287c035 |
children | fea8d61a2451 |
rev | line source |
---|---|
1 | 1 module sema.Visitor; |
2 | |
3 import tango.io.Stdout; | |
4 | |
5 public | |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
6 import ast.Module, |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
7 ast.Decl, |
1 | 8 ast.Stmt, |
9 ast.Exp; | |
10 | |
11 import lexer.Token; | |
12 | |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
13 class Visitor(FinalT = int, ModuleT = FinalT, DeclT = ModuleT, StmtT = DeclT, ExpT = StmtT) |
1 | 14 { |
15 public: | |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
16 FinalT visit(Module m) |
1 | 17 { |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
18 visitModule(m); |
1 | 19 static if (is(FinalT == void)) |
20 return; | |
21 else | |
22 return FinalT.init; | |
23 } | |
24 | |
94
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
25 ModuleT visitModule(Module m) |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
26 { |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
27 foreach (decl; m.decls) |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
28 visitDecl(decl); |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
29 static if (is(ModuleT == void)) |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
30 return; |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
31 else |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
32 return ModuleT.init; |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
33 } |
48bb2287c035
Added Modules. Right now it's very simple - will grow with time and need.
Anders Johnsen <skabet@gmail.com>
parents:
83
diff
changeset
|
34 |
1 | 35 DeclT visitDecl(Decl decl) |
36 { | |
37 switch(decl.declType) | |
38 { | |
39 case DeclType.FuncDecl: | |
40 return visitFuncDecl(cast(FuncDecl)decl); | |
41 case DeclType.VarDecl: | |
42 return visitVarDecl(cast(VarDecl)decl); | |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
43 case DeclType.ImportDecl: |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
44 return visitImportDecl(cast(ImportDecl)decl); |
22 | 45 case DeclType.StructDecl: |
46 return visitStructDecl(cast(StructDecl)decl); | |
1 | 47 default: |
48 throw new Exception("Unknown declaration type"); | |
49 } | |
50 } | |
51 | |
52 StmtT visitStmt(Stmt stmt) | |
53 { | |
54 switch(stmt.stmtType) | |
55 { | |
56 case StmtType.Return: | |
57 return visitReturnStmt(cast(ReturnStmt)stmt); | |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
58 case StmtType.Compound: |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
59 return visitCompoundStmt(cast(CompoundStatement)stmt); |
1 | 60 case StmtType.Decl: |
61 return visitDeclStmt(cast(DeclStmt)stmt); | |
62 case StmtType.Exp: | |
63 return visitExpStmt(cast(ExpStmt)stmt); | |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
64 case StmtType.If: |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
65 return visitIfStmt(cast(IfStmt)stmt); |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
66 case StmtType.While: |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
67 return visitWhileStmt(cast(WhileStmt)stmt); |
36
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
68 case StmtType.Switch: |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
69 return visitSwitchStmt(cast(SwitchStmt)stmt); |
1 | 70 default: |
71 throw new Exception("Unknown statement type"); | |
72 } | |
73 } | |
74 | |
75 ExpT visitExp(Exp exp) | |
76 { | |
77 switch(exp.expType) | |
78 { | |
79 case ExpType.Binary: | |
80 return visitBinaryExp(cast(BinaryExp)exp); | |
81 case ExpType.IntegerLit: | |
82 return visitIntegerLit(cast(IntegerLit)exp); | |
83 case ExpType.Negate: | |
84 return visitNegateExp(cast(NegateExp)exp); | |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
85 case ExpType.Deref: |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
86 return visitDerefExp(cast(DerefExp)exp); |
1 | 87 case ExpType.AssignExp: |
88 return visitAssignExp(cast(AssignExp)exp); | |
89 case ExpType.CallExp: | |
90 return visitCallExp(cast(CallExp)exp); | |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
91 case ExpType.CastExp: |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
92 return visitCastExp(cast(CastExp)exp); |
1 | 93 case ExpType.Identifier: |
94 return visitIdentifier(cast(Identifier)exp); | |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
95 case ExpType.PointerIdentifier: |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
96 return visitPointerIdentifier(cast(PointerIdentifier)exp); |
81 | 97 case ExpType.ArrayIdentifier: |
98 return visitArrayIdentifier(cast(ArrayIdentifier)exp); | |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
99 case ExpType.Index: |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
100 return visitIndexExp(cast(IndexExp)exp); |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
46
diff
changeset
|
101 case ExpType.MemberReference: |
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
46
diff
changeset
|
102 return visitMemberReference(cast(MemberReference)exp); |
1 | 103 default: |
104 throw new Exception("Unknown expression type"); | |
105 } | |
106 } | |
107 | |
108 // Declarations: | |
109 DeclT visitVarDecl(VarDecl d) | |
110 { | |
63
9f8131676242
Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents:
55
diff
changeset
|
111 visitExp(d.varType); |
82
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
81
diff
changeset
|
112 if(d.identifier) |
06dda301ea61
Can declare outside functions and call c-functions
Anders Johnsen <skabet@gmail.com>
parents:
81
diff
changeset
|
113 visitExp(d.identifier); |
1 | 114 if (d.init) |
115 visitExp(d.init); | |
116 | |
117 static if (is(DeclT == void)) | |
118 return; | |
119 else | |
120 return DeclT.init; | |
121 } | |
122 | |
99
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
123 DeclT visitImportDecl(ImportDecl d) |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
124 { |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
125 visitIdentifier(d.name); |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
126 visitIdentifier(d.aliasedName); |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
127 foreach (id; d.packages) |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
128 visitIdentifier(id); |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
129 foreach (ids; d.explicitSymbols) |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
130 { |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
131 visitIdentifier(ids[0]); |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
132 visitIdentifier(ids[1]); |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
133 } |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
134 |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
135 static if (is(DeclT == void)) |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
136 return; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
137 else |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
138 return DeclT.init; |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
139 } |
857f0d530789
Imports and improved module statement
Anders Halager <halager@gmail.com>
parents:
94
diff
changeset
|
140 |
1 | 141 DeclT visitFuncDecl(FuncDecl f) |
142 { | |
63
9f8131676242
Now Decl's have a DType type(), and should use varType and returnType to get the old type id
Anders Halager <halager@gmail.com>
parents:
55
diff
changeset
|
143 visitExp(f.returnType); |
1 | 144 visitExp(f.identifier); |
145 foreach (arg; f.funcArgs) | |
146 visitDecl(arg); | |
147 foreach (stmt; f.statements) | |
148 visitStmt(stmt); | |
149 | |
150 static if (is(DeclT == void)) | |
151 return; | |
152 else | |
153 return DeclT.init; | |
154 } | |
155 | |
22 | 156 DeclT visitStructDecl(StructDecl s) |
157 { | |
158 visitExp(s.identifier); | |
159 | |
160 foreach (arg; s.vars) | |
161 visitDecl(arg); | |
162 | |
163 static if (is(DeclT == void)) | |
164 return; | |
165 else | |
166 return DeclT.init; | |
167 } | |
168 | |
1 | 169 // Statements: |
170 StmtT visitReturnStmt(ReturnStmt s) | |
171 { | |
37 | 172 if (s.exp) |
173 visitExp(s.exp); | |
1 | 174 static if (is(StmtT == void)) |
175 return; | |
176 else | |
177 return StmtT.init; | |
178 } | |
179 | |
180 StmtT visitDeclStmt(DeclStmt d) | |
181 { | |
182 visitDecl(d.decl); | |
183 static if (is(StmtT == void)) | |
184 return; | |
185 else | |
186 return StmtT.init; | |
187 } | |
188 | |
44
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
189 StmtT visitCompoundStmt(CompoundStatement c) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
190 { |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
191 foreach (stmt; c.statements) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
192 visitStmt(stmt); |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
193 static if (is(StmtT == void)) |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
194 return; |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
195 else |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
196 return StmtT.init; |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
197 } |
495188f9078e
Big update - Moving towards a better, more seperated parser
Anders Halager <halager@gmail.com>
parents:
37
diff
changeset
|
198 |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
199 StmtT visitIfStmt(IfStmt s) |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
200 { |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
201 visitExp(s.cond); |
45 | 202 visitStmt(s.then_body); |
203 if (s.else_body !is null) | |
204 visitStmt(s.else_body); | |
11
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
205 static if (is(StmtT == void)) |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
206 return; |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
207 else |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
208 return StmtT.init; |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
209 } |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
210 |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
211 StmtT visitWhileStmt(WhileStmt s) |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
212 { |
642c6a998fd9
Support for while statements and fixed scope for if
Anders Halager <halager@gmail.com>
parents:
5
diff
changeset
|
213 visitExp(s.cond); |
46 | 214 visitStmt(s.whileBody); |
5
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
215 static if (is(StmtT == void)) |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
216 return; |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
217 else |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
218 return StmtT.init; |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
219 } |
2c5a8f4c254a
Added very simple if support.
Anders Halager <halager@gmail.com>
parents:
1
diff
changeset
|
220 |
36
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
221 StmtT visitSwitchStmt(SwitchStmt s) |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
222 { |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
223 visitExp(s.cond); |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
224 foreach(stmt; s.defaultBlock) |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
225 visitStmt(stmt); |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
226 foreach (c; s.cases) |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
227 { |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
228 foreach(lit; c.values) |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
229 visitIntegerLit(lit); |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
230 foreach(stmt; c.stmts) |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
231 visitStmt(stmt); |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
232 } |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
233 static if (is(StmtT == void)) |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
234 return; |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
235 else |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
236 return StmtT.init; |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
237 } |
ce17bea8e9bd
Switch statements support
Anders Halager <halager@gmail.com>
parents:
28
diff
changeset
|
238 |
1 | 239 StmtT visitExpStmt(ExpStmt s) |
240 { | |
241 visitExp(s.exp); | |
242 static if (is(StmtT == void)) | |
243 return; | |
244 else | |
245 return StmtT.init; | |
246 } | |
247 | |
248 // Expressions: | |
249 ExpT visitAssignExp(AssignExp exp) | |
250 { | |
251 visitExp(exp.identifier); | |
252 visitExp(exp.exp); | |
253 static if (is(ExpT == void)) | |
254 return; | |
255 else | |
256 return ExpT.init; | |
257 } | |
258 | |
259 ExpT visitBinaryExp(BinaryExp exp) | |
260 { | |
261 visitExp(exp.left); | |
262 visitExp(exp.right); | |
263 static if (is(ExpT == void)) | |
264 return; | |
265 else | |
266 return ExpT.init; | |
267 } | |
268 | |
269 ExpT visitCallExp(CallExp exp) | |
270 { | |
271 visitExp(exp.exp); | |
272 foreach (arg; exp.args) | |
273 visitExp(arg); | |
274 static if (is(ExpT == void)) | |
275 return; | |
276 else | |
277 return ExpT.init; | |
278 } | |
279 | |
68
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
280 ExpT visitCastExp(CastExp exp) |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
281 { |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
282 visitExp(exp.castType); |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
283 visitExp(exp.exp); |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
284 static if (is(ExpT == void)) |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
285 return; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
286 else |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
287 return ExpT.init; |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
288 } |
381975d76baf
A LOT of bug fixing - also implemented implicit casts. If you do a --ast-dump-code on a target with some algebra of differant types, you should now see the type casts being made. Also, Tests are again back with only switches failing...
Anders Johnsen <skabet@gmail.com>
parents:
63
diff
changeset
|
289 |
1 | 290 ExpT visitNegateExp(NegateExp exp) |
291 { | |
292 visitExp(exp.exp); | |
293 static if (is(ExpT == void)) | |
294 return; | |
295 else | |
296 return ExpT.init; | |
297 } | |
298 | |
78
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
299 ExpT visitDerefExp(DerefExp exp) |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
300 { |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
301 visitExp(exp.exp); |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
302 static if (is(ExpT == void)) |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
303 return; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
304 else |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
305 return ExpT.init; |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
306 } |
ad956143dcdc
Parse and gen for dereferences
Anders Halager <halager@gmail.com>
parents:
68
diff
changeset
|
307 |
1 | 308 ExpT visitIntegerLit(IntegerLit exp) |
309 { | |
310 static if (is(ExpT == void)) | |
311 return; | |
312 else | |
313 return ExpT.init; | |
314 } | |
315 | |
316 ExpT visitIdentifier(Identifier exp) | |
317 { | |
318 static if (is(ExpT == void)) | |
319 return; | |
320 else | |
321 return ExpT.init; | |
322 } | |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
323 |
77
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
324 ExpT visitPointerIdentifier(PointerIdentifier exp) |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
325 { |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
326 visitExp(exp.pointerOf); |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
327 |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
328 static if (is(ExpT == void)) |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
329 return; |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
330 else |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
331 return ExpT.init; |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
332 } |
13eea2c4e60d
Now able of --ast-dump-code with Pointer types and also codeGen int* x;
Anders Johnsen <skabet@gmail.com>
parents:
68
diff
changeset
|
333 |
81 | 334 ExpT visitArrayIdentifier(ArrayIdentifier exp) |
335 { | |
336 visitExp(exp.arrayOf); | |
337 | |
338 static if (is(ExpT == void)) | |
339 return; | |
340 else | |
341 return ExpT.init; | |
342 } | |
343 | |
83
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
344 ExpT visitIndexExp(IndexExp exp) |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
345 { |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
346 visitExp(exp.target); |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
347 visitExp(exp.index); |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
348 |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
349 static if (is(ExpT == void)) |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
350 return; |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
351 else |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
352 return ExpT.init; |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
353 } |
9e90694f5da0
Parse array indexing, and allow reading from arrays
Anders Halager <halager@gmail.com>
parents:
82
diff
changeset
|
354 |
55
79cb0afafabe
Now structs are somewhat useable to use.
Anders Johnsen <skabet@gmail.com>
parents:
46
diff
changeset
|
355 ExpT visitMemberReference(MemberReference mem) |
28
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
356 { |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
357 visitExp(mem.target); |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
358 visitExp(mem.child); |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
359 |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
360 static if (is(ExpT == void)) |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
361 return; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
362 else |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
363 return ExpT.init; |
69464d465284
Now supporting structs - both read and write. Still a few errors though, so watch out.
Anders Johnsen <skabet@gmail.com>
parents:
22
diff
changeset
|
364 } |
1 | 365 } |
366 |