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