336
|
1
|
|
2 // Compiler implementation of the D programming language
|
|
3 // Copyright (c) 1999-2008 by Digital Mars
|
|
4 // All Rights Reserved
|
|
5 // written by Walter Bright
|
|
6 // http://www.digitalmars.com
|
|
7 // License for redistribution is by either the Artistic License
|
|
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
|
|
9 // See the included readme.txt for details.
|
|
10
|
|
11 #ifndef DMD_STATEMENT_H
|
|
12 #define DMD_STATEMENT_H
|
|
13
|
|
14 #ifdef __DMC__
|
|
15 #pragma once
|
|
16 #endif /* __DMC__ */
|
|
17
|
|
18 #include "root.h"
|
|
19
|
|
20 #include "arraytypes.h"
|
|
21 #include "dsymbol.h"
|
|
22 #include "lexer.h"
|
|
23
|
|
24 struct OutBuffer;
|
|
25 struct Scope;
|
|
26 struct Expression;
|
|
27 struct LabelDsymbol;
|
|
28 struct Identifier;
|
|
29 struct IfStatement;
|
|
30 struct DeclarationStatement;
|
|
31 struct DefaultStatement;
|
|
32 struct VarDeclaration;
|
|
33 struct Condition;
|
|
34 struct Module;
|
|
35 struct Token;
|
|
36 struct InlineCostState;
|
|
37 struct InlineDoState;
|
|
38 struct InlineScanState;
|
|
39 struct ReturnStatement;
|
|
40 struct CompoundStatement;
|
|
41 struct Argument;
|
|
42 struct StaticAssert;
|
|
43 struct AsmStatement;
|
|
44 struct AsmBlockStatement;
|
|
45 struct GotoStatement;
|
|
46 struct ScopeStatement;
|
|
47 struct TryCatchStatement;
|
|
48 struct TryFinallyStatement;
|
|
49 struct HdrGenState;
|
|
50 struct InterState;
|
|
51 struct CaseStatement;
|
|
52 struct LabelStatement;
|
|
53 struct VolatileStatement;
|
|
54 struct SynchronizedStatement;
|
|
55
|
|
56 enum TOK;
|
|
57
|
|
58 namespace llvm
|
|
59 {
|
|
60 class Value;
|
|
61 class BasicBlock;
|
|
62 class ConstantInt;
|
|
63 }
|
|
64
|
|
65 // Back end
|
|
66 struct IRState;
|
|
67 struct Blockx;
|
|
68 #if IN_LLVM
|
|
69 struct DValue;
|
|
70 typedef DValue elem;
|
|
71 #endif
|
|
72
|
|
73 #if IN_GCC
|
|
74 union tree_node; typedef union tree_node block;
|
|
75 //union tree_node; typedef union tree_node elem;
|
|
76 #else
|
|
77 struct block;
|
|
78 //struct elem;
|
|
79 #endif
|
|
80 struct code;
|
|
81
|
|
82 /* How a statement exits
|
|
83 */
|
|
84 enum BE
|
|
85 {
|
|
86 BEnone = 0,
|
|
87 BEfallthru = 1,
|
|
88 BEthrow = 2,
|
|
89 BEreturn = 4,
|
|
90 BEgoto = 8,
|
|
91 BEhalt = 0x10,
|
|
92 BEbreak = 0x20,
|
|
93 BEcontinue = 0x40,
|
|
94 BEany = (BEfallthru | BEthrow | BEreturn | BEgoto | BEhalt),
|
|
95 };
|
|
96
|
|
97 // LLVMDC this is used for tracking try-finally, synchronized and volatile scopes
|
|
98 // definitions in gen/llvmhelpers.cpp
|
|
99 struct EnclosingHandler : Object
|
|
100 {
|
|
101 virtual void emitCode(IRState* p) = 0;
|
|
102 virtual EnclosingHandler* getEnclosing() = 0;
|
|
103 };
|
|
104 struct EnclosingTryFinally : EnclosingHandler
|
|
105 {
|
|
106 TryFinallyStatement* tf;
|
|
107 void emitCode(IRState* p);
|
|
108 EnclosingHandler* getEnclosing();
|
|
109 EnclosingTryFinally(TryFinallyStatement* _tf) : tf(_tf) {}
|
|
110 };
|
|
111 struct EnclosingVolatile : EnclosingHandler
|
|
112 {
|
|
113 VolatileStatement* v;
|
|
114 void emitCode(IRState* p);
|
|
115 EnclosingHandler* getEnclosing();
|
|
116 EnclosingVolatile(VolatileStatement* _tf) : v(_tf) {}
|
|
117 };
|
|
118 struct EnclosingSynchro : EnclosingHandler
|
|
119 {
|
|
120 SynchronizedStatement* s;
|
|
121 void emitCode(IRState* p);
|
|
122 EnclosingHandler* getEnclosing();
|
|
123 EnclosingSynchro(SynchronizedStatement* _tf) : s(_tf) {}
|
|
124 };
|
|
125
|
|
126 struct Statement : Object
|
|
127 {
|
|
128 Loc loc;
|
|
129
|
|
130 Statement(Loc loc);
|
|
131 virtual Statement *syntaxCopy();
|
|
132
|
|
133 void print();
|
|
134 char *toChars();
|
|
135
|
|
136 void error(const char *format, ...);
|
|
137 virtual void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
138 virtual TryCatchStatement *isTryCatchStatement() { return NULL; }
|
|
139 virtual GotoStatement *isGotoStatement() { return NULL; }
|
|
140 virtual AsmStatement *isAsmStatement() { return NULL; }
|
|
141 virtual AsmBlockStatement *isAsmBlockStatement() { return NULL; }
|
|
142 #ifdef _DH
|
|
143 int incontract;
|
|
144 #endif
|
|
145 virtual ScopeStatement *isScopeStatement() { return NULL; }
|
|
146 virtual Statement *semantic(Scope *sc);
|
|
147 Statement *semanticScope(Scope *sc, Statement *sbreak, Statement *scontinue);
|
|
148 virtual int hasBreak();
|
|
149 virtual int hasContinue();
|
|
150 virtual int usesEH();
|
|
151 virtual int fallOffEnd();
|
|
152 virtual int blockExit();
|
|
153 virtual int comeFrom();
|
|
154 virtual void scopeCode(Statement **sentry, Statement **sexit, Statement **sfinally);
|
|
155 virtual Statements *flatten(Scope *sc);
|
|
156 virtual Expression *interpret(InterState *istate);
|
|
157
|
|
158 virtual int inlineCost(InlineCostState *ics);
|
|
159 virtual Expression *doInline(InlineDoState *ids);
|
|
160 virtual Statement *inlineScan(InlineScanState *iss);
|
|
161
|
|
162 // Back end
|
|
163 virtual void toIR(IRState *irs);
|
|
164
|
|
165 // Avoid dynamic_cast
|
|
166 virtual DeclarationStatement *isDeclarationStatement() { return NULL; }
|
|
167 virtual CompoundStatement *isCompoundStatement() { return NULL; }
|
|
168 virtual ReturnStatement *isReturnStatement() { return NULL; }
|
|
169 virtual IfStatement *isIfStatement() { return NULL; }
|
|
170 virtual CaseStatement* isCaseStatement() { return NULL; }
|
|
171 };
|
|
172
|
|
173 struct ExpStatement : Statement
|
|
174 {
|
|
175 Expression *exp;
|
|
176
|
|
177 ExpStatement(Loc loc, Expression *exp);
|
|
178 Statement *syntaxCopy();
|
|
179 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
180 Statement *semantic(Scope *sc);
|
|
181 Expression *interpret(InterState *istate);
|
|
182 int fallOffEnd();
|
|
183 int blockExit();
|
|
184
|
|
185 int inlineCost(InlineCostState *ics);
|
|
186 Expression *doInline(InlineDoState *ids);
|
|
187 Statement *inlineScan(InlineScanState *iss);
|
|
188
|
|
189 void toIR(IRState *irs);
|
|
190 };
|
|
191
|
|
192 struct CompileStatement : Statement
|
|
193 {
|
|
194 Expression *exp;
|
|
195
|
|
196 CompileStatement(Loc loc, Expression *exp);
|
|
197 Statement *syntaxCopy();
|
|
198 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
199 Statements *flatten(Scope *sc);
|
|
200 Statement *semantic(Scope *sc);
|
|
201 };
|
|
202
|
|
203 struct DeclarationStatement : ExpStatement
|
|
204 {
|
|
205 // Doing declarations as an expression, rather than a statement,
|
|
206 // makes inlining functions much easier.
|
|
207
|
|
208 DeclarationStatement(Loc loc, Dsymbol *s);
|
|
209 DeclarationStatement(Loc loc, Expression *exp);
|
|
210 Statement *syntaxCopy();
|
|
211 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
212 void scopeCode(Statement **sentry, Statement **sexit, Statement **sfinally);
|
|
213
|
|
214 DeclarationStatement *isDeclarationStatement() { return this; }
|
|
215 };
|
|
216
|
|
217 struct CompoundStatement : Statement
|
|
218 {
|
|
219 Statements *statements;
|
|
220
|
|
221 CompoundStatement(Loc loc, Statements *s);
|
|
222 CompoundStatement(Loc loc, Statement *s1, Statement *s2);
|
|
223 virtual Statement *syntaxCopy();
|
|
224 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
225 virtual Statement *semantic(Scope *sc);
|
|
226 int usesEH();
|
|
227 int blockExit();
|
|
228 int fallOffEnd();
|
|
229 int comeFrom();
|
|
230 virtual Statements *flatten(Scope *sc);
|
|
231 ReturnStatement *isReturnStatement();
|
|
232 Expression *interpret(InterState *istate);
|
|
233
|
|
234 int inlineCost(InlineCostState *ics);
|
|
235 Expression *doInline(InlineDoState *ids);
|
|
236 Statement *inlineScan(InlineScanState *iss);
|
|
237
|
|
238 virtual void toIR(IRState *irs);
|
|
239
|
|
240 virtual CompoundStatement *isCompoundStatement() { return this; }
|
|
241 };
|
|
242
|
|
243 /* The purpose of this is so that continue will go to the next
|
|
244 * of the statements, and break will go to the end of the statements.
|
|
245 */
|
|
246 struct UnrolledLoopStatement : Statement
|
|
247 {
|
|
248 Statements *statements;
|
|
249 EnclosingHandler* enclosinghandler;
|
|
250
|
|
251 UnrolledLoopStatement(Loc loc, Statements *statements);
|
|
252 Statement *syntaxCopy();
|
|
253 Statement *semantic(Scope *sc);
|
|
254 int hasBreak();
|
|
255 int hasContinue();
|
|
256 int usesEH();
|
|
257 int blockExit();
|
|
258 int fallOffEnd();
|
|
259 int comeFrom();
|
|
260 Expression *interpret(InterState *istate);
|
|
261 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
262
|
|
263 int inlineCost(InlineCostState *ics);
|
|
264 Expression *doInline(InlineDoState *ids);
|
|
265 Statement *inlineScan(InlineScanState *iss);
|
|
266
|
|
267 void toIR(IRState *irs);
|
|
268 };
|
|
269
|
|
270 struct ScopeStatement : Statement
|
|
271 {
|
|
272 Statement *statement;
|
|
273
|
|
274 ScopeStatement(Loc loc, Statement *s);
|
|
275 Statement *syntaxCopy();
|
|
276 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
277 ScopeStatement *isScopeStatement() { return this; }
|
|
278 Statement *semantic(Scope *sc);
|
|
279 int hasBreak();
|
|
280 int hasContinue();
|
|
281 int usesEH();
|
|
282 int blockExit();
|
|
283 int fallOffEnd();
|
|
284 int comeFrom();
|
|
285 Expression *interpret(InterState *istate);
|
|
286
|
|
287 Statement *inlineScan(InlineScanState *iss);
|
|
288
|
|
289 void toIR(IRState *irs);
|
|
290 };
|
|
291
|
|
292 struct WhileStatement : Statement
|
|
293 {
|
|
294 Expression *condition;
|
|
295 Statement *body;
|
|
296 EnclosingHandler* enclosinghandler;
|
|
297
|
|
298 WhileStatement(Loc loc, Expression *c, Statement *b);
|
|
299 Statement *syntaxCopy();
|
|
300 Statement *semantic(Scope *sc);
|
|
301 int hasBreak();
|
|
302 int hasContinue();
|
|
303 int usesEH();
|
|
304 int blockExit();
|
|
305 int fallOffEnd();
|
|
306 int comeFrom();
|
|
307 Expression *interpret(InterState *istate);
|
|
308 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
309
|
|
310 Statement *inlineScan(InlineScanState *iss);
|
|
311
|
|
312 void toIR(IRState *irs);
|
|
313 };
|
|
314
|
|
315 struct DoStatement : Statement
|
|
316 {
|
|
317 Statement *body;
|
|
318 Expression *condition;
|
|
319 EnclosingHandler* enclosinghandler;
|
|
320
|
|
321 DoStatement(Loc loc, Statement *b, Expression *c);
|
|
322 Statement *syntaxCopy();
|
|
323 Statement *semantic(Scope *sc);
|
|
324 int hasBreak();
|
|
325 int hasContinue();
|
|
326 int usesEH();
|
|
327 int blockExit();
|
|
328 int fallOffEnd();
|
|
329 int comeFrom();
|
|
330 Expression *interpret(InterState *istate);
|
|
331 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
332
|
|
333 Statement *inlineScan(InlineScanState *iss);
|
|
334
|
|
335 void toIR(IRState *irs);
|
|
336 };
|
|
337
|
|
338 struct ForStatement : Statement
|
|
339 {
|
|
340 Statement *init;
|
|
341 Expression *condition;
|
|
342 Expression *increment;
|
|
343 Statement *body;
|
|
344 EnclosingHandler* enclosinghandler;
|
|
345
|
|
346 ForStatement(Loc loc, Statement *init, Expression *condition, Expression *increment, Statement *body);
|
|
347 Statement *syntaxCopy();
|
|
348 Statement *semantic(Scope *sc);
|
|
349 void scopeCode(Statement **sentry, Statement **sexit, Statement **sfinally);
|
|
350 int hasBreak();
|
|
351 int hasContinue();
|
|
352 int usesEH();
|
|
353 int blockExit();
|
|
354 int fallOffEnd();
|
|
355 int comeFrom();
|
|
356 Expression *interpret(InterState *istate);
|
|
357 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
358
|
|
359 Statement *inlineScan(InlineScanState *iss);
|
|
360
|
|
361 void toIR(IRState *irs);
|
|
362 };
|
|
363
|
|
364 struct ForeachStatement : Statement
|
|
365 {
|
|
366 enum TOK op; // TOKforeach or TOKforeach_reverse
|
|
367 Arguments *arguments; // array of Argument*'s
|
|
368 Expression *aggr;
|
|
369 Statement *body;
|
|
370 EnclosingHandler* enclosinghandler;
|
|
371
|
|
372 VarDeclaration *key;
|
|
373 VarDeclaration *value;
|
|
374
|
|
375 FuncDeclaration *func; // function we're lexically in
|
|
376
|
|
377 Array cases; // put breaks, continues, gotos and returns here
|
|
378 Array gotos; // forward referenced goto's go here
|
|
379
|
|
380 ForeachStatement(Loc loc, enum TOK op, Arguments *arguments, Expression *aggr, Statement *body);
|
|
381 Statement *syntaxCopy();
|
|
382 Statement *semantic(Scope *sc);
|
|
383 int hasBreak();
|
|
384 int hasContinue();
|
|
385 int usesEH();
|
|
386 int blockExit();
|
|
387 int fallOffEnd();
|
|
388 int comeFrom();
|
|
389 Expression *interpret(InterState *istate);
|
|
390 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
391
|
|
392 Statement *inlineScan(InlineScanState *iss);
|
|
393
|
|
394 void toIR(IRState *irs);
|
|
395 };
|
|
396
|
|
397 #if DMDV2
|
|
398 struct ForeachRangeStatement : Statement
|
|
399 {
|
|
400 enum TOK op; // TOKforeach or TOKforeach_reverse
|
|
401 Argument *arg; // loop index variable
|
|
402 Expression *lwr;
|
|
403 Expression *upr;
|
|
404 Statement *body;
|
|
405
|
|
406 VarDeclaration *key;
|
|
407
|
|
408 ForeachRangeStatement(Loc loc, enum TOK op, Argument *arg,
|
|
409 Expression *lwr, Expression *upr, Statement *body);
|
|
410 Statement *syntaxCopy();
|
|
411 Statement *semantic(Scope *sc);
|
|
412 int hasBreak();
|
|
413 int hasContinue();
|
|
414 int usesEH();
|
|
415 int blockExit();
|
|
416 int fallOffEnd();
|
|
417 int comeFrom();
|
|
418 Expression *interpret(InterState *istate);
|
|
419 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
420
|
|
421 Statement *inlineScan(InlineScanState *iss);
|
|
422
|
|
423 void toIR(IRState *irs);
|
|
424 };
|
|
425 #endif
|
|
426
|
|
427 struct IfStatement : Statement
|
|
428 {
|
|
429 Argument *arg;
|
|
430 Expression *condition;
|
|
431 Statement *ifbody;
|
|
432 Statement *elsebody;
|
|
433
|
|
434 VarDeclaration *match; // for MatchExpression results
|
|
435
|
|
436 IfStatement(Loc loc, Argument *arg, Expression *condition, Statement *ifbody, Statement *elsebody);
|
|
437 Statement *syntaxCopy();
|
|
438 Statement *semantic(Scope *sc);
|
|
439 Expression *interpret(InterState *istate);
|
|
440 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
441 int usesEH();
|
|
442 int blockExit();
|
|
443 int fallOffEnd();
|
|
444 IfStatement *isIfStatement() { return this; }
|
|
445
|
|
446 int inlineCost(InlineCostState *ics);
|
|
447 Expression *doInline(InlineDoState *ids);
|
|
448 Statement *inlineScan(InlineScanState *iss);
|
|
449
|
|
450 void toIR(IRState *irs);
|
|
451 };
|
|
452
|
|
453 struct ConditionalStatement : Statement
|
|
454 {
|
|
455 Condition *condition;
|
|
456 Statement *ifbody;
|
|
457 Statement *elsebody;
|
|
458
|
|
459 ConditionalStatement(Loc loc, Condition *condition, Statement *ifbody, Statement *elsebody);
|
|
460 Statement *syntaxCopy();
|
|
461 Statement *semantic(Scope *sc);
|
|
462 Statements *flatten(Scope *sc);
|
|
463 int usesEH();
|
|
464
|
|
465 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
466 };
|
|
467
|
|
468 struct PragmaStatement : Statement
|
|
469 {
|
|
470 Identifier *ident;
|
|
471 Expressions *args; // array of Expression's
|
|
472 Statement *body;
|
|
473
|
|
474 PragmaStatement(Loc loc, Identifier *ident, Expressions *args, Statement *body);
|
|
475 Statement *syntaxCopy();
|
|
476 Statement *semantic(Scope *sc);
|
|
477 int usesEH();
|
|
478 int blockExit();
|
|
479 int fallOffEnd();
|
|
480
|
|
481 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
482 };
|
|
483
|
|
484 struct StaticAssertStatement : Statement
|
|
485 {
|
|
486 StaticAssert *sa;
|
|
487
|
|
488 StaticAssertStatement(StaticAssert *sa);
|
|
489 Statement *syntaxCopy();
|
|
490 Statement *semantic(Scope *sc);
|
|
491
|
|
492 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
493 };
|
|
494
|
|
495 struct SwitchStatement : Statement
|
|
496 {
|
|
497 Expression *condition;
|
|
498 Statement *body;
|
|
499
|
|
500 DefaultStatement *sdefault;
|
|
501 EnclosingHandler* enclosinghandler;
|
|
502
|
|
503 Array gotoCases; // array of unresolved GotoCaseStatement's
|
|
504 Array *cases; // array of CaseStatement's
|
|
505 int hasNoDefault; // !=0 if no default statement
|
|
506
|
|
507 SwitchStatement(Loc loc, Expression *c, Statement *b);
|
|
508 Statement *syntaxCopy();
|
|
509 Statement *semantic(Scope *sc);
|
|
510 int hasBreak();
|
|
511 int usesEH();
|
|
512 int blockExit();
|
|
513 int fallOffEnd();
|
|
514 Expression *interpret(InterState *istate);
|
|
515 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
516
|
|
517 Statement *inlineScan(InlineScanState *iss);
|
|
518
|
|
519 void toIR(IRState *irs);
|
|
520 };
|
|
521
|
|
522 struct CaseStatement : Statement
|
|
523 {
|
|
524 Expression *exp;
|
|
525 Statement *statement;
|
|
526 int index; // which case it is (since we sort this)
|
|
527 block *cblock; // back end: label for the block
|
|
528
|
|
529 CaseStatement(Loc loc, Expression *exp, Statement *s);
|
|
530 Statement *syntaxCopy();
|
|
531 Statement *semantic(Scope *sc);
|
|
532 int compare(Object *obj);
|
|
533 int usesEH();
|
|
534 int blockExit();
|
|
535 int fallOffEnd();
|
|
536 int comeFrom();
|
|
537 Expression *interpret(InterState *istate);
|
|
538 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
539
|
|
540 Statement *inlineScan(InlineScanState *iss);
|
|
541
|
|
542 void toIR(IRState *irs);
|
|
543
|
|
544 CaseStatement* isCaseStatement() { return this; }
|
|
545
|
|
546 // LLVMDC
|
|
547 llvm::BasicBlock* bodyBB;
|
|
548 llvm::ConstantInt* llvmIdx;
|
|
549 };
|
|
550
|
|
551 struct DefaultStatement : Statement
|
|
552 {
|
|
553 Statement *statement;
|
|
554 #if IN_GCC
|
|
555 block *cblock; // back end: label for the block
|
|
556 #endif
|
|
557
|
|
558 DefaultStatement(Loc loc, Statement *s);
|
|
559 Statement *syntaxCopy();
|
|
560 Statement *semantic(Scope *sc);
|
|
561 int usesEH();
|
|
562 int blockExit();
|
|
563 int fallOffEnd();
|
|
564 int comeFrom();
|
|
565 Expression *interpret(InterState *istate);
|
|
566 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
567
|
|
568 Statement *inlineScan(InlineScanState *iss);
|
|
569
|
|
570 void toIR(IRState *irs);
|
|
571
|
|
572 // LLVMDC
|
|
573 llvm::BasicBlock* bodyBB;
|
|
574 };
|
|
575
|
|
576 struct GotoDefaultStatement : Statement
|
|
577 {
|
|
578 SwitchStatement *sw;
|
|
579 EnclosingHandler* enclosinghandler;
|
|
580
|
|
581 GotoDefaultStatement(Loc loc);
|
|
582 Statement *syntaxCopy();
|
|
583 Statement *semantic(Scope *sc);
|
|
584 Expression *interpret(InterState *istate);
|
|
585 int blockExit();
|
|
586 int fallOffEnd();
|
|
587 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
588
|
|
589 void toIR(IRState *irs);
|
|
590 };
|
|
591
|
|
592 struct GotoCaseStatement : Statement
|
|
593 {
|
|
594 Expression *exp; // NULL, or which case to goto
|
|
595 CaseStatement *cs; // case statement it resolves to
|
|
596 EnclosingHandler* enclosinghandler;
|
|
597 SwitchStatement *sw;
|
|
598
|
|
599 GotoCaseStatement(Loc loc, Expression *exp);
|
|
600 Statement *syntaxCopy();
|
|
601 Statement *semantic(Scope *sc);
|
|
602 Expression *interpret(InterState *istate);
|
|
603 int blockExit();
|
|
604 int fallOffEnd();
|
|
605 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
606
|
|
607 void toIR(IRState *irs);
|
|
608 };
|
|
609
|
|
610 struct SwitchErrorStatement : Statement
|
|
611 {
|
|
612 SwitchErrorStatement(Loc loc);
|
|
613 int blockExit();
|
|
614 int fallOffEnd();
|
|
615 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
616
|
|
617 void toIR(IRState *irs);
|
|
618 };
|
|
619
|
|
620 struct ReturnStatement : Statement
|
|
621 {
|
|
622 Expression *exp;
|
|
623 EnclosingHandler* enclosinghandler;
|
|
624
|
|
625 ReturnStatement(Loc loc, Expression *exp);
|
|
626 Statement *syntaxCopy();
|
|
627 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
628 Statement *semantic(Scope *sc);
|
|
629 int blockExit();
|
|
630 int fallOffEnd();
|
|
631 Expression *interpret(InterState *istate);
|
|
632
|
|
633 int inlineCost(InlineCostState *ics);
|
|
634 Expression *doInline(InlineDoState *ids);
|
|
635 Statement *inlineScan(InlineScanState *iss);
|
|
636
|
|
637 void toIR(IRState *irs);
|
|
638
|
|
639 ReturnStatement *isReturnStatement() { return this; }
|
|
640 };
|
|
641
|
|
642 struct BreakStatement : Statement
|
|
643 {
|
|
644 Identifier *ident;
|
|
645 EnclosingHandler* enclosinghandler;
|
|
646
|
|
647 BreakStatement(Loc loc, Identifier *ident);
|
|
648 Statement *syntaxCopy();
|
|
649 Statement *semantic(Scope *sc);
|
|
650 Expression *interpret(InterState *istate);
|
|
651 int blockExit();
|
|
652 int fallOffEnd();
|
|
653 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
654
|
|
655 void toIR(IRState *irs);
|
|
656
|
|
657 // LLVMDC: only set if ident is set: label statement to jump to
|
|
658 LabelStatement *target;
|
|
659 };
|
|
660
|
|
661 struct ContinueStatement : Statement
|
|
662 {
|
|
663 Identifier *ident;
|
|
664 EnclosingHandler* enclosinghandler;
|
|
665
|
|
666 ContinueStatement(Loc loc, Identifier *ident);
|
|
667 Statement *syntaxCopy();
|
|
668 Statement *semantic(Scope *sc);
|
|
669 Expression *interpret(InterState *istate);
|
|
670 int blockExit();
|
|
671 int fallOffEnd();
|
|
672 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
673
|
|
674 void toIR(IRState *irs);
|
|
675
|
|
676 // LLVMDC: only set if ident is set: label statement to jump to
|
|
677 LabelStatement *target;
|
|
678 };
|
|
679
|
|
680 struct SynchronizedStatement : Statement
|
|
681 {
|
|
682 Expression *exp;
|
|
683 Statement *body;
|
|
684 EnclosingHandler* enclosinghandler;
|
|
685
|
|
686 SynchronizedStatement(Loc loc, Expression *exp, Statement *body);
|
|
687 Statement *syntaxCopy();
|
|
688 Statement *semantic(Scope *sc);
|
|
689 int hasBreak();
|
|
690 int hasContinue();
|
|
691 int usesEH();
|
|
692 int blockExit();
|
|
693 int fallOffEnd();
|
|
694 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
695
|
|
696 Statement *inlineScan(InlineScanState *iss);
|
|
697
|
|
698 // Back end
|
|
699 elem *esync;
|
|
700 SynchronizedStatement(Loc loc, elem *esync, Statement *body);
|
|
701 void toIR(IRState *irs);
|
|
702 llvm::Value* llsync;
|
|
703 };
|
|
704
|
|
705 struct WithStatement : Statement
|
|
706 {
|
|
707 Expression *exp;
|
|
708 Statement *body;
|
|
709 VarDeclaration *wthis;
|
|
710
|
|
711 WithStatement(Loc loc, Expression *exp, Statement *body);
|
|
712 Statement *syntaxCopy();
|
|
713 Statement *semantic(Scope *sc);
|
|
714 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
715 int usesEH();
|
|
716 int blockExit();
|
|
717 int fallOffEnd();
|
|
718
|
|
719 Statement *inlineScan(InlineScanState *iss);
|
|
720
|
|
721 void toIR(IRState *irs);
|
|
722 };
|
|
723
|
|
724 struct TryCatchStatement : Statement
|
|
725 {
|
|
726 Statement *body;
|
|
727 Array *catches;
|
|
728
|
|
729 TryCatchStatement(Loc loc, Statement *body, Array *catches);
|
|
730 Statement *syntaxCopy();
|
|
731 Statement *semantic(Scope *sc);
|
|
732 int hasBreak();
|
|
733 int usesEH();
|
|
734 int blockExit();
|
|
735 int fallOffEnd();
|
|
736
|
|
737 Statement *inlineScan(InlineScanState *iss);
|
|
738
|
|
739 void toIR(IRState *irs);
|
|
740 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
741 TryCatchStatement *isTryCatchStatement() { return this; }
|
|
742 };
|
|
743
|
|
744 struct Catch : Object
|
|
745 {
|
|
746 Loc loc;
|
|
747 Type *type;
|
|
748 Identifier *ident;
|
|
749 VarDeclaration *var;
|
|
750 Statement *handler;
|
|
751
|
|
752 Catch(Loc loc, Type *t, Identifier *id, Statement *handler);
|
|
753 Catch *syntaxCopy();
|
|
754 void semantic(Scope *sc);
|
|
755 int blockExit();
|
|
756 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
757 };
|
|
758
|
|
759 struct TryFinallyStatement : Statement
|
|
760 {
|
|
761 Statement *body;
|
|
762 Statement *finalbody;
|
|
763 EnclosingHandler* enclosinghandler;
|
|
764
|
|
765 TryFinallyStatement(Loc loc, Statement *body, Statement *finalbody);
|
|
766 Statement *syntaxCopy();
|
|
767 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
768 Statement *semantic(Scope *sc);
|
|
769 int hasBreak();
|
|
770 int hasContinue();
|
|
771 int usesEH();
|
|
772 int blockExit();
|
|
773 int fallOffEnd();
|
|
774
|
|
775 Statement *inlineScan(InlineScanState *iss);
|
|
776
|
|
777 void toIR(IRState *irs);
|
|
778 };
|
|
779
|
|
780 struct OnScopeStatement : Statement
|
|
781 {
|
|
782 TOK tok;
|
|
783 Statement *statement;
|
|
784
|
|
785 OnScopeStatement(Loc loc, TOK tok, Statement *statement);
|
|
786 Statement *syntaxCopy();
|
|
787 int blockExit();
|
|
788 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
789 Statement *semantic(Scope *sc);
|
|
790 int usesEH();
|
|
791 void scopeCode(Statement **sentry, Statement **sexit, Statement **sfinally);
|
|
792
|
|
793 void toIR(IRState *irs);
|
|
794 };
|
|
795
|
|
796 struct ThrowStatement : Statement
|
|
797 {
|
|
798 Expression *exp;
|
|
799
|
|
800 ThrowStatement(Loc loc, Expression *exp);
|
|
801 Statement *syntaxCopy();
|
|
802 Statement *semantic(Scope *sc);
|
|
803 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
804 int blockExit();
|
|
805 int fallOffEnd();
|
|
806
|
|
807 Statement *inlineScan(InlineScanState *iss);
|
|
808
|
|
809 void toIR(IRState *irs);
|
|
810 };
|
|
811
|
|
812 struct VolatileStatement : Statement
|
|
813 {
|
|
814 Statement *statement;
|
|
815 EnclosingHandler* enclosinghandler;
|
|
816
|
|
817 VolatileStatement(Loc loc, Statement *statement);
|
|
818 Statement *syntaxCopy();
|
|
819 Statement *semantic(Scope *sc);
|
|
820 Statements *flatten(Scope *sc);
|
|
821 int blockExit();
|
|
822 int fallOffEnd();
|
|
823 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
824
|
|
825 Statement *inlineScan(InlineScanState *iss);
|
|
826
|
|
827 void toIR(IRState *irs);
|
|
828 };
|
|
829
|
|
830 struct GotoStatement : Statement
|
|
831 {
|
|
832 Identifier *ident;
|
|
833 LabelDsymbol *label;
|
|
834 TryFinallyStatement *tf;
|
|
835 EnclosingHandler* enclosinghandler;
|
|
836
|
|
837 GotoStatement(Loc loc, Identifier *ident);
|
|
838 Statement *syntaxCopy();
|
|
839 Statement *semantic(Scope *sc);
|
|
840 int blockExit();
|
|
841 int fallOffEnd();
|
|
842 Expression *interpret(InterState *istate);
|
|
843
|
|
844 void toIR(IRState *irs);
|
|
845 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
846 GotoStatement *isGotoStatement() { return this; }
|
|
847 };
|
|
848
|
|
849 struct LabelStatement : Statement
|
|
850 {
|
|
851 Identifier *ident;
|
|
852 Statement *statement;
|
|
853 TryFinallyStatement *tf;
|
|
854 EnclosingHandler* enclosinghandler;
|
|
855 block *lblock; // back end
|
|
856 int isReturnLabel;
|
|
857
|
|
858 LabelStatement(Loc loc, Identifier *ident, Statement *statement);
|
|
859 Statement *syntaxCopy();
|
|
860 Statement *semantic(Scope *sc);
|
|
861 Statements *flatten(Scope *sc);
|
|
862 int usesEH();
|
|
863 int blockExit();
|
|
864 int fallOffEnd();
|
|
865 int comeFrom();
|
|
866 Expression *interpret(InterState *istate);
|
|
867 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
868
|
|
869 Statement *inlineScan(InlineScanState *iss);
|
|
870
|
|
871 void toIR(IRState *irs);
|
|
872
|
|
873 // LLVMDC
|
|
874 llvm::BasicBlock* llvmBB;
|
|
875 bool asmLabel; // for labels inside inline assembler
|
|
876 };
|
|
877
|
|
878 struct LabelDsymbol : Dsymbol
|
|
879 {
|
|
880 LabelStatement *statement;
|
|
881
|
|
882 LabelDsymbol(Identifier *ident);
|
|
883 LabelDsymbol *isLabel();
|
|
884 };
|
|
885
|
|
886 struct AsmStatement : Statement
|
|
887 {
|
|
888 Token *tokens;
|
|
889 code *asmcode;
|
|
890 unsigned asmalign; // alignment of this statement
|
|
891 unsigned refparam; // !=0 if function parameter is referenced
|
|
892 unsigned naked; // !=0 if function is to be naked
|
|
893 unsigned regs; // mask of registers modified
|
|
894
|
|
895 AsmStatement(Loc loc, Token *tokens);
|
|
896 Statement *syntaxCopy();
|
|
897 Statement *semantic(Scope *sc);
|
|
898 int blockExit();
|
|
899 int comeFrom();
|
|
900
|
|
901 void toCBuffer(OutBuffer *buf, HdrGenState *hgs);
|
|
902 virtual AsmStatement *isAsmStatement() { return this; }
|
|
903
|
|
904 void toIR(IRState *irs);
|
|
905
|
|
906 // LLVMDC
|
|
907 // non-zero if this is a branch, contains the target labels identifier
|
|
908 Identifier* isBranchToLabel;
|
|
909 };
|
|
910
|
|
911 struct AsmBlockStatement : CompoundStatement
|
|
912 {
|
|
913 EnclosingHandler* enclosinghandler;
|
|
914
|
|
915 AsmBlockStatement(Loc loc, Statements *s);
|
|
916 Statements *flatten(Scope *sc);
|
|
917 Statement *syntaxCopy();
|
|
918 Statement *semantic(Scope *sc);
|
|
919
|
|
920 CompoundStatement *isCompoundStatement() { return NULL; }
|
|
921 AsmBlockStatement *isAsmBlockStatement() { return this; }
|
|
922
|
|
923 void toIR(IRState *irs);
|
|
924 };
|
|
925
|
|
926 #endif /* DMD_STATEMENT_H */
|