Mercurial > projects > dang
comparison src/parser/Action.d @ 207:e0551773a005
Added the correct version.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 12 Aug 2008 18:19:34 +0200 |
parents | d3c148ca429b |
children | 42e663451371 |
comparison
equal
deleted
inserted
replaced
206:d3c148ca429b | 207:e0551773a005 |
---|---|
1 module parser.Action; | 1 module parser.Action; |
2 | 2 |
3 import lexer.Token; | 3 import lexer.Token; |
4 | |
5 import basic.Attribute; | |
4 | 6 |
5 /** | 7 /** |
6 Used to indicate what type of operator is used in a given binary expression | 8 Used to indicate what type of operator is used in a given binary expression |
7 (and unary expressions?) | 9 (and unary expressions?) |
8 */ | 10 */ |
9 public enum Operator | 11 public enum Operator |
10 { | 12 { |
11 Assign, | 13 Assign, |
14 AddAssign, | |
15 SubAssign, | |
16 MulAssign, | |
17 DivAssign, | |
18 ModAssign, | |
12 | 19 |
13 Eq, Ne, | 20 Eq, Ne, |
14 | 21 |
15 Lt, Le, | 22 Lt, Le, |
16 Gt, Ge, | 23 Gt, Ge, |
17 | 24 |
18 Add, Sub, | 25 Add, Sub, |
19 Mul, Div, Mod, | 26 Mul, Div, Mod, |
27 | |
28 LeftShift, RightShift, UnsignedRightShift, | |
20 } | 29 } |
21 | 30 |
22 | 31 |
23 class Id | 32 class Id |
24 { | 33 { |
29 return id; | 38 return id; |
30 } | 39 } |
31 Token tok; | 40 Token tok; |
32 } | 41 } |
33 | 42 |
34 class PointerId : Id | 43 class PointerTypeId : Id |
35 { | 44 { |
36 public static PointerId opCall(Id id) | 45 public static PointerTypeId opCall(Id id) |
37 { | 46 { |
38 auto p = new PointerId(); | 47 auto p = new PointerTypeId(); |
39 p.id = id; | 48 p.id = id; |
40 return p; | 49 return p; |
41 } | 50 } |
42 | 51 |
43 Id id; | 52 Id id; |
44 } | 53 } |
45 | 54 |
46 class ArrayId : Id | 55 class StaticArrayTypeId : Id |
47 { | 56 { |
48 public static ArrayId opCall(Id id, Object number) | 57 public static StaticArrayTypeId opCall(Id id, Object number) |
49 { | 58 { |
50 auto a = new ArrayId(); | 59 auto a = new StaticArrayTypeId(); |
51 a.id = id; | 60 a.id = id; |
52 a.number = number; | 61 a.number = number; |
53 return a; | 62 return a; |
54 } | 63 } |
55 | 64 |
56 Id id; | 65 Id id; |
57 Object number; | 66 Object number; |
67 } | |
68 | |
69 class FunctionTypeId : Id | |
70 { | |
71 public static FunctionTypeId opCall(Id id, DeclT[] decls) | |
72 { | |
73 auto f = new FunctionTypeId(); | |
74 f.id = id; | |
75 f.decls = decls; | |
76 return f; | |
77 } | |
78 | |
79 Id id; | |
80 DeclT[] decls; | |
58 } | 81 } |
59 | 82 |
60 /** | 83 /** |
61 Represents a fully qualified name, with some packages and a final identifier. | 84 Represents a fully qualified name, with some packages and a final identifier. |
62 The identifier should always be set, but packages may have length 0. | 85 The identifier should always be set, but packages may have length 0. |
74 r = r + identifier.tok.asRange(); | 97 r = r + identifier.tok.asRange(); |
75 return r; | 98 return r; |
76 } | 99 } |
77 } | 100 } |
78 | 101 |
102 /** | |
103 A few aliases to indicate what methods should be dealing with the same | |
104 types. | |
105 Not typesafe, and not using typedef because users would need a lot of | |
106 casts (and base type would be void*, so no possibility to synchronize, | |
107 print etc.) | |
108 */ | |
109 alias Object ExprT; | |
110 alias Object StmtT; /// ditto | |
111 alias Object DeclT; /// ditto | |
112 alias Object ModuleT; /// ditto | |
113 | |
79 /** | 114 /** |
80 All methods are optional. | 115 All methods are optional. |
81 | 116 |
82 Warning: Interface is not stable yet. Use the `override` keyword in all classes | 117 Warning: Interface is not stable yet. Use the `override` keyword in all classes |
83 inheriting from this to get warning if the interface changes. | 118 inheriting from this to get warning if the interface changes. |
84 */ | 119 */ |
85 abstract class Action | 120 abstract class Action |
86 { | 121 { |
87 /** | 122 |
88 A few aliases to indicate what methods should be dealing with the same | |
89 types. | |
90 | |
91 Not typesafe, and not using typedef because users would need a lot of | |
92 casts (and base type would be void*, so no possibility to synchronize, | |
93 print etc.) | |
94 */ | |
95 alias Object ExprT; | |
96 alias Object StmtT; /// ditto | |
97 alias Object DeclT; /// ditto | |
98 alias Object ModuleT; /// ditto | |
99 | 123 |
100 // -- Modules -- | 124 // -- Modules -- |
101 | 125 |
102 ModuleT actOnModule(ref Token _module, char[] name) | 126 ModuleT actOnModule(ref Token _module, char[] name) |
103 { | 127 { |
144 As an example, this method could handle the params in `int f(int, int)` | 168 As an example, this method could handle the params in `int f(int, int)` |
145 as well as handling `int x` at both top-level, in classes and in methods. | 169 as well as handling `int x` at both top-level, in classes and in methods. |
146 | 170 |
147 The other solution is an addParamToFunc or similar. | 171 The other solution is an addParamToFunc or similar. |
148 */ | 172 */ |
149 DeclT actOnDeclarator(ref Id type, ref Id name, ExprT init) | 173 DeclT actOnDeclarator(ref Id type, ref Id name, ExprT init, Attribute att) |
174 { | |
175 return null; | |
176 } | |
177 | |
178 DeclT actOnAliasDecl(DeclT decl, Attribute att) | |
150 { | 179 { |
151 return null; | 180 return null; |
152 } | 181 } |
153 | 182 |
154 /** | 183 /** |
155 Add a struct member to a struct. | 184 Add a struct member to a struct. |
156 */ | 185 */ |
157 void actOnStructMember(DeclT st_decl, DeclT m_decl) //ref Id type, ref Id name, ExprT init) | 186 void actOnStructMember(DeclT st_decl, DeclT m_decl) |
187 { | |
188 return null; | |
189 } | |
190 | |
191 /** | |
192 Add a class member to a struct. | |
193 */ | |
194 void actOnClassMember(DeclT cl_decl, DeclT m_decl) | |
195 { | |
196 return null; | |
197 } | |
198 | |
199 /** | |
200 Add a class member to a struct. | |
201 */ | |
202 void actOnClassBaseClass(DeclT cl_decl, ref Id name) | |
203 { | |
204 return null; | |
205 } | |
206 | |
207 /** | |
208 Add a class member to a struct. | |
209 */ | |
210 void actOnInterfaceMember(DeclT if_decl, DeclT m_decl) | |
211 { | |
212 return null; | |
213 } | |
214 | |
215 /** | |
216 Add a class member to a struct. | |
217 */ | |
218 void actOnInterfaceBaseClass(DeclT if_decl, ref Id name) | |
158 { | 219 { |
159 return null; | 220 return null; |
160 } | 221 } |
161 | 222 |
162 /** | 223 /** |
171 | 232 |
172 /** | 233 /** |
173 Called at the start of a function, doesn't get a lot of info - that is | 234 Called at the start of a function, doesn't get a lot of info - that is |
174 added later on, through addFuncArg and actOnEndOfFunction. | 235 added later on, through addFuncArg and actOnEndOfFunction. |
175 */ | 236 */ |
176 DeclT actOnStartOfFunctionDef(ref Id type, ref Id name) | 237 DeclT actOnStartOfFunctionDef(ref Id type, ref Id name, Attribute att) |
177 { | 238 { |
178 return null; | 239 return null; |
179 } | 240 } |
180 | 241 |
181 /** | 242 /** |
245 return null; | 306 return null; |
246 } | 307 } |
247 | 308 |
248 /** | 309 /** |
249 */ | 310 */ |
311 StmtT actOnForStmt(ref Token forTok, StmtT init, ExprT cond, ExprT incre, StmtT forBody) | |
312 { | |
313 return null; | |
314 } | |
315 | |
316 /** | |
317 */ | |
250 StmtT actOnDeclStmt(DeclT decl) | 318 StmtT actOnDeclStmt(DeclT decl) |
251 { | 319 { |
252 return null; | 320 return null; |
253 } | 321 } |
254 | 322 |
255 StmtT actOnStartOfSwitchStmt() | 323 StmtT actOnStartOfSwitchStmt(Token _switch, ExprT exp) |
256 { | 324 { |
257 return null; | 325 return null; |
258 } | 326 } |
259 | 327 |
260 void actOnCaseStmt() | 328 void actOnCaseStmt(StmtT stmt, Token _case, ExprT[] exps, StmtT[] stmts) |
261 { | 329 { |
262 } | 330 } |
263 | 331 |
264 void actOnDefaultStmt() | 332 void actOnDefaultStmt(StmtT stmt, Token _default, StmtT[] stmts) |
265 { | 333 { |
266 } | 334 } |
267 | 335 |
268 StmtT actOnFinishSwitchStmt(StmtT sw) | 336 StmtT actOnFinishSwitchStmt(StmtT sw) |
269 { | 337 { |
283 | 351 |
284 /** | 352 /** |
285 This is called when identifiers are used in expressions. | 353 This is called when identifiers are used in expressions. |
286 */ | 354 */ |
287 ExprT actOnIdentifierExp(Id id) | 355 ExprT actOnIdentifierExp(Id id) |
356 { | |
357 return null; | |
358 } | |
359 | |
360 /** | |
361 This is called when strings are used in expression | |
362 */ | |
363 ExprT actOnStringExp(Token t) | |
288 { | 364 { |
289 return null; | 365 return null; |
290 } | 366 } |
291 | 367 |
292 /** | 368 /** |
336 } | 412 } |
337 | 413 |
338 /** | 414 /** |
339 Called when function calls are encountered. | 415 Called when function calls are encountered. |
340 */ | 416 */ |
341 ExprT actOnIndexEpr(ExprT array, ref Token left_bracket, ExprT index, | 417 ExprT actOnIndexExpr(ExprT array, ref Token left_bracket, ExprT index, |
342 ref Token right_bracket) | 418 ref Token right_bracket) |
343 { | 419 { |
344 return null; | 420 return null; |
345 } | 421 } |
346 | 422 |
347 /** | 423 /** |
348 Cast expression. | 424 Cast expression. |
349 */ | 425 */ |
350 ExprT actOnCastExpr(ref Token _cast, Id type, ExprT exp) | 426 ExprT actOnCastExpr(ref Token _cast, Id type, ExprT exp) |
427 { | |
428 return null; | |
429 } | |
430 | |
431 /** | |
432 New expression. | |
433 */ | |
434 ExprT actOnNewExpr(ref Id type, ExprT[] a_args, ExprT[] c_args) | |
435 { | |
436 return null; | |
437 } | |
438 | |
439 /** | |
440 Array Literal expression. | |
441 */ | |
442 ExprT actOnArrayLiteralExpr(ExprT[] exps, SLoc start, SLoc end) | |
443 { | |
444 return null; | |
445 } | |
446 | |
447 /** | |
448 Null expression. | |
449 */ | |
450 ExprT actOnNullExpr(SLoc pos) | |
351 { | 451 { |
352 return null; | 452 return null; |
353 } | 453 } |
354 } | 454 } |
355 | 455 |