Mercurial > projects > dil
annotate trunk/src/Statements.d @ 283:df657dd98ffa
- Fix: added member type to VariableDeclaration.
- Changed class IfStatement. parseIfStatement() parses a DeclarationStatement if the condition is not an expression.
author | aziz |
---|---|
date | Tue, 07 Aug 2007 14:56:02 +0000 |
parents | e5a6b56c7716 |
children | 104343e0f097 |
rev | line source |
---|---|
102 | 1 /++ |
2 Author: Aziz Köksal | |
249 | 3 License: GPL3 |
102 | 4 +/ |
5 module Statements; | |
240
deab661906ae
- Classes Declaration, Expression, Statement and Type inherit from Node now.
aziz
parents:
238
diff
changeset
|
6 import SyntaxTree; |
162 | 7 import Expressions; |
185 | 8 import Declarations; |
162 | 9 import Types; |
169 | 10 import Token; |
102 | 11 |
277
38a68e534a3b
- Made classes Declaration, Expression and Statement abstract.
aziz
parents:
275
diff
changeset
|
12 abstract class Statement : Node |
102 | 13 { |
240
deab661906ae
- Classes Declaration, Expression, Statement and Type inherit from Node now.
aziz
parents:
238
diff
changeset
|
14 this() |
deab661906ae
- Classes Declaration, Expression, Statement and Type inherit from Node now.
aziz
parents:
238
diff
changeset
|
15 { |
275 | 16 super(NodeCategory.Statement); |
240
deab661906ae
- Classes Declaration, Expression, Statement and Type inherit from Node now.
aziz
parents:
238
diff
changeset
|
17 } |
102 | 18 } |
161 | 19 |
20 class Statements : Statement | |
21 { | |
22 Statement[] ss; | |
23 void opCatAssign(Statement s) | |
24 { | |
278 | 25 mixin(set_kind); |
161 | 26 this.ss ~= s; |
27 } | |
28 } | |
29 | |
206 | 30 class IllegalStatement : Statement |
31 { | |
250 | 32 Token* tok; |
33 this(Token* tok) | |
206 | 34 { |
278 | 35 mixin(set_kind); |
206 | 36 this.tok = tok; |
37 } | |
38 } | |
39 | |
216 | 40 class EmptyStatement : Statement |
41 { | |
42 this() | |
43 { | |
278 | 44 mixin(set_kind); |
216 | 45 } |
46 } | |
47 | |
268 | 48 class FunctionBody : Node |
192 | 49 { |
50 Statement funcBody, inBody, outBody; | |
264 | 51 Token* outIdent; |
268 | 52 this() |
53 { | |
275 | 54 super(NodeCategory.Other); |
278 | 55 mixin(set_kind); |
268 | 56 } |
192 | 57 } |
58 | |
162 | 59 class ScopeStatement : Statement |
60 { | |
61 Statement s; | |
62 this(Statement s) | |
63 { | |
278 | 64 mixin(set_kind); |
162 | 65 this.s = s; |
66 } | |
67 } | |
68 | |
161 | 69 class LabeledStatement : Statement |
70 { | |
264 | 71 Token* label; |
161 | 72 Statement s; |
264 | 73 this(Token* label, Statement s) |
161 | 74 { |
278 | 75 mixin(set_kind); |
161 | 76 this.label = label; |
77 this.s = s; | |
78 } | |
79 } | |
80 | |
81 class ExpressionStatement : Statement | |
82 { | |
187 | 83 Expression expression; |
84 this(Expression expression) | |
85 { | |
278 | 86 mixin(set_kind); |
187 | 87 this.expression = expression; |
88 } | |
161 | 89 } |
90 | |
91 class DeclarationStatement : Statement | |
92 { | |
188 | 93 Declaration declaration; |
94 this(Declaration declaration) | |
95 { | |
278 | 96 mixin(set_kind); |
188 | 97 this.declaration = declaration; |
98 } | |
161 | 99 } |
100 | |
101 class IfStatement : Statement | |
102 { | |
283 | 103 Statement variable; // AutoDeclaration or VariableDeclaration |
162 | 104 Expression condition; |
105 Statement ifBody; | |
106 Statement elseBody; | |
283 | 107 this(Statement variable, Expression condition, Statement ifBody, Statement elseBody) |
162 | 108 { |
278 | 109 mixin(set_kind); |
283 | 110 this.variable = variable; |
162 | 111 this.condition = condition; |
112 this.ifBody = ifBody; | |
113 this.elseBody = elseBody; | |
114 } | |
161 | 115 } |
261 | 116 /+ |
161 | 117 class ConditionalStatement : Statement |
118 { | |
119 | |
120 } | |
261 | 121 +/ |
161 | 122 class WhileStatement : Statement |
123 { | |
164 | 124 Expression condition; |
125 Statement whileBody; | |
126 this(Expression condition, Statement whileBody) | |
127 { | |
278 | 128 mixin(set_kind); |
164 | 129 this.condition = condition; |
130 this.whileBody = whileBody; | |
131 } | |
161 | 132 } |
133 | |
165 | 134 class DoWhileStatement : Statement |
161 | 135 { |
165 | 136 Expression condition; |
137 Statement doBody; | |
138 this(Expression condition, Statement doBody) | |
139 { | |
278 | 140 mixin(set_kind); |
165 | 141 this.condition = condition; |
142 this.doBody = doBody; | |
143 } | |
161 | 144 } |
145 | |
146 class ForStatement : Statement | |
147 { | |
166 | 148 Statement init; |
149 Expression condition, increment; | |
150 Statement forBody; | |
169 | 151 |
166 | 152 this(Statement init, Expression condition, Expression increment, Statement forBody) |
153 { | |
278 | 154 mixin(set_kind); |
166 | 155 this.init = init; |
156 this.condition = condition; | |
157 this.increment = increment; | |
158 this.forBody = forBody; | |
159 } | |
161 | 160 } |
161 | |
162 class ForeachStatement : Statement | |
163 { | |
169 | 164 TOK tok; |
165 Parameters params; | |
166 Expression aggregate; | |
167 Statement forBody; | |
161 | 168 |
169 | 169 this(TOK tok, Parameters params, Expression aggregate, Statement forBody) |
170 { | |
278 | 171 mixin(set_kind); |
169 | 172 this.tok = tok; |
173 this.params = params; | |
174 this.aggregate = aggregate; | |
175 this.forBody = forBody; | |
176 } | |
161 | 177 } |
178 | |
269 | 179 version(D2) |
180 { | |
181 class ForeachRangeStatement : Statement | |
182 { | |
183 TOK tok; | |
184 Parameters params; | |
185 Expression lower, upper; | |
186 Statement forBody; | |
187 | |
188 this(TOK tok, Parameters params, Expression lower, Expression upper, Statement forBody) | |
189 { | |
278 | 190 mixin(set_kind); |
269 | 191 this.tok = tok; |
192 this.params = params; | |
193 this.lower = lower; | |
194 this.upper = upper; | |
195 this.forBody = forBody; | |
196 } | |
197 } | |
198 } | |
199 | |
161 | 200 class SwitchStatement : Statement |
201 { | |
170 | 202 Expression condition; |
203 Statement switchBody; | |
161 | 204 |
170 | 205 this(Expression condition, Statement switchBody) |
206 { | |
278 | 207 mixin(set_kind); |
170 | 208 this.condition = condition; |
209 this.switchBody = switchBody; | |
210 } | |
161 | 211 } |
212 | |
213 class CaseStatement : Statement | |
214 { | |
171 | 215 Expression[] values; |
216 Statement caseBody; | |
161 | 217 |
171 | 218 this(Expression[] values, Statement caseBody) |
219 { | |
278 | 220 mixin(set_kind); |
171 | 221 this.values = values; |
222 this.caseBody = caseBody; | |
223 } | |
161 | 224 } |
225 | |
226 class DefaultStatement : Statement | |
227 { | |
172 | 228 Statement defaultBody; |
229 this(Statement defaultBody) | |
230 { | |
278 | 231 mixin(set_kind); |
172 | 232 this.defaultBody = defaultBody; |
233 } | |
161 | 234 } |
235 | |
236 class ContinueStatement : Statement | |
237 { | |
264 | 238 Token* ident; |
239 this(Token* ident) | |
173 | 240 { |
278 | 241 mixin(set_kind); |
173 | 242 this.ident = ident; |
243 } | |
161 | 244 } |
245 | |
246 class BreakStatement : Statement | |
247 { | |
264 | 248 Token* ident; |
249 this(Token* ident) | |
174 | 250 { |
278 | 251 mixin(set_kind); |
174 | 252 this.ident = ident; |
253 } | |
161 | 254 } |
255 | |
256 class ReturnStatement : Statement | |
257 { | |
175 | 258 Expression expr; |
259 this(Expression expr) | |
260 { | |
278 | 261 mixin(set_kind); |
175 | 262 this.expr = expr; |
263 } | |
161 | 264 } |
265 | |
266 class GotoStatement : Statement | |
267 { | |
264 | 268 Token* ident; |
176 | 269 Expression caseExpr; |
264 | 270 this(Token* ident, Expression caseExpr) |
176 | 271 { |
278 | 272 mixin(set_kind); |
176 | 273 this.ident = ident; |
274 this.caseExpr = caseExpr; | |
275 } | |
161 | 276 } |
277 | |
278 class WithStatement : Statement | |
279 { | |
177 | 280 Expression expr; |
281 Statement withBody; | |
282 this(Expression expr, Statement withBody) | |
283 { | |
278 | 284 mixin(set_kind); |
177 | 285 this.expr = expr; |
286 this.withBody = withBody; | |
287 } | |
161 | 288 } |
289 | |
290 class SynchronizedStatement : Statement | |
291 { | |
178 | 292 Expression expr; |
293 Statement syncBody; | |
294 this(Expression expr, Statement withBody) | |
295 { | |
278 | 296 mixin(set_kind); |
178 | 297 this.expr = expr; |
298 this.syncBody = syncBody; | |
299 } | |
161 | 300 } |
301 | |
302 class TryStatement : Statement | |
303 { | |
179 | 304 Statement tryBody; |
305 CatchBody[] catchBodies; | |
306 FinallyBody finallyBody; | |
307 this(Statement tryBody, CatchBody[] catchBodies, FinallyBody finallyBody) | |
308 { | |
278 | 309 mixin(set_kind); |
179 | 310 this.tryBody = tryBody; |
311 this.catchBodies = catchBodies; | |
312 this.finallyBody = finallyBody; | |
313 } | |
314 } | |
161 | 315 |
179 | 316 class CatchBody : Statement |
317 { | |
318 Parameter param; | |
319 Statement catchBody; | |
320 this(Parameter param, Statement catchBody) | |
321 { | |
278 | 322 mixin(set_kind); |
179 | 323 this.param = param; |
324 this.catchBody = catchBody; | |
325 } | |
326 } | |
327 | |
328 class FinallyBody : Statement | |
329 { | |
330 Statement finallyBody; | |
331 this(Statement finallyBody) | |
332 { | |
278 | 333 mixin(set_kind); |
179 | 334 this.finallyBody = finallyBody; |
335 } | |
161 | 336 } |
337 | |
338 class ScopeGuardStatement : Statement | |
339 { | |
264 | 340 Token* condition; |
181 | 341 Statement scopeBody; |
264 | 342 this(Token* condition, Statement scopeBody) |
181 | 343 { |
278 | 344 mixin(set_kind); |
181 | 345 this.condition = condition; |
346 this.scopeBody = scopeBody; | |
347 } | |
161 | 348 } |
349 | |
350 class ThrowStatement : Statement | |
351 { | |
180 | 352 Expression expr; |
353 this(Expression expr) | |
354 { | |
278 | 355 mixin(set_kind); |
180 | 356 this.expr = expr; |
357 } | |
161 | 358 } |
359 | |
360 class VolatileStatement : Statement | |
361 { | |
182 | 362 Statement volatileBody; |
363 this(Statement volatileBody) | |
364 { | |
278 | 365 mixin(set_kind); |
182 | 366 this.volatileBody = volatileBody; |
367 } | |
161 | 368 } |
369 | |
370 class AsmStatement : Statement | |
371 { | |
278 | 372 this() |
373 { | |
374 mixin(set_kind); | |
375 } | |
161 | 376 } |
377 | |
378 class PragmaStatement : Statement | |
379 { | |
245 | 380 Token* ident; |
184 | 381 Expression[] args; |
382 Statement pragmaBody; | |
245 | 383 this(Token* ident, Expression[] args, Statement pragmaBody) |
184 | 384 { |
278 | 385 mixin(set_kind); |
184 | 386 this.ident = ident; |
387 this.args = args; | |
388 this.pragmaBody = pragmaBody; | |
389 } | |
161 | 390 } |
391 | |
392 class MixinStatement : Statement | |
393 { | |
256 | 394 Expression[] templateIdent; |
395 Token* mixinIdent; | |
396 this(Expression[] templateIdent, Token* mixinIdent) | |
185 | 397 { |
278 | 398 mixin(set_kind); |
256 | 399 this.templateIdent = templateIdent; |
400 this.mixinIdent = mixinIdent; | |
185 | 401 } |
161 | 402 } |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
403 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
404 class StaticIfStatement : Statement |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
405 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
406 Expression condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
407 Statement ifBody, elseBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
408 this(Expression condition, Statement ifBody, Statement elseBody) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
409 { |
278 | 410 mixin(set_kind); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
411 this.condition = condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
412 this.ifBody = ifBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
413 this.elseBody = elseBody; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
414 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
415 } |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
416 |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
417 class StaticAssertStatement : Statement |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
418 { |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
419 Expression condition, message; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
420 this(Expression condition, Expression message) |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
421 { |
278 | 422 mixin(set_kind); |
186
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
423 this.condition = condition; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
424 this.message = message; |
d4292a5a7b8b
- Implemented parseStaticIfStatement() and parseStaticAssertStatement().
aziz
parents:
185
diff
changeset
|
425 } |
187 | 426 } |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
427 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
428 class DebugStatement : Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
429 { |
264 | 430 Token* cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
431 Statement debugBody, elseBody; |
264 | 432 this(Token* cond, Statement debugBody, Statement elseBody) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
433 { |
278 | 434 mixin(set_kind); |
264 | 435 this.cond = cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
436 this.debugBody = debugBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
437 this.elseBody = elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
438 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
439 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
440 |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
441 class VersionStatement : Statement |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
442 { |
264 | 443 Token* cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
444 Statement versionBody, elseBody; |
264 | 445 this(Token* cond, Statement versionBody, Statement elseBody) |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
446 { |
278 | 447 mixin(set_kind); |
264 | 448 this.cond = cond; |
190
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
449 this.versionBody = versionBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
450 this.elseBody = elseBody; |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
451 } |
d0712601fa47
- Implemented parseDebugStatement() and parseVersionStatement().
aziz
parents:
188
diff
changeset
|
452 } |
201 | 453 |
454 class AttributeStatement : Statement | |
455 { | |
456 TOK tok; | |
457 Statement statement; | |
458 this(TOK tok, Statement statement) | |
459 { | |
278 | 460 mixin(set_kind); |
201 | 461 this.tok = tok; |
462 this.statement = statement; | |
463 } | |
464 } | |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
465 |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
466 class ExternStatement : AttributeStatement |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
467 { |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
468 Linkage linkage; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
469 this(Linkage linkage, Statement statement) |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
470 { |
278 | 471 mixin(set_kind); |
238
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
472 super(TOK.Extern, statement); |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
473 this.linkage = linkage; |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
474 } |
f3c6c15961bb
- Added method peekNext(). Replaced code that used lx.peek() with peekNext().
aziz
parents:
216
diff
changeset
|
475 } |