2 // Compiler implementation of the D programming language
3 // Copyright (c) 1999-2008 by Digital Mars
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.
11 #ifndef DMD_STATEMENT_H
12 #define DMD_STATEMENT_H
20 #include "arraytypes.h"
29 struct DeclarationStatement
;
30 struct DefaultStatement
;
31 struct VarDeclaration
;
35 struct InlineCostState
;
37 struct InlineScanState
;
38 struct ReturnStatement
;
39 struct CompoundStatement
;
44 struct ScopeStatement
;
45 struct TryCatchStatement
;
46 struct TryFinallyStatement
;
56 union tree_node
; typedef union tree_node block
;
57 union tree_node
; typedef union tree_node elem
;
64 /* How a statement exits
76 BEany
= (BEfallthru
| BEthrow
| BEreturn
| BEgoto
| BEhalt
),
79 struct Statement
: Object
84 virtual Statement
*syntaxCopy();
89 void error(const char *format
, ...);
90 virtual void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
91 virtual TryCatchStatement
*isTryCatchStatement() { return NULL
; }
92 virtual GotoStatement
*isGotoStatement() { return NULL
; }
93 virtual AsmStatement
*isAsmStatement() { return NULL
; }
97 virtual ScopeStatement
*isScopeStatement() { return NULL
; }
98 virtual Statement
*semantic(Scope
*sc
);
99 Statement
*semanticScope(Scope
*sc
, Statement
*sbreak
, Statement
*scontinue
);
100 virtual int hasBreak();
101 virtual int hasContinue();
102 virtual int usesEH();
103 virtual int fallOffEnd();
104 virtual int blockExit();
105 virtual int comeFrom();
106 virtual void scopeCode(Scope
*sc
, Statement
**sentry
, Statement
**sexit
, Statement
**sfinally
);
107 virtual Statements
*flatten(Scope
*sc
);
108 virtual Expression
*interpret(InterState
*istate
);
110 virtual int inlineCost(InlineCostState
*ics
);
111 virtual Expression
*doInline(InlineDoState
*ids
);
112 virtual Statement
*inlineScan(InlineScanState
*iss
);
115 virtual void toIR(IRState
*irs
);
117 // Avoid dynamic_cast
118 virtual DeclarationStatement
*isDeclarationStatement() { return NULL
; }
119 virtual CompoundStatement
*isCompoundStatement() { return NULL
; }
120 virtual ReturnStatement
*isReturnStatement() { return NULL
; }
121 virtual IfStatement
*isIfStatement() { return NULL
; }
124 struct ExpStatement
: Statement
128 ExpStatement(Loc loc
, Expression
*exp
);
129 Statement
*syntaxCopy();
130 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
131 Statement
*semantic(Scope
*sc
);
132 Expression
*interpret(InterState
*istate
);
136 int inlineCost(InlineCostState
*ics
);
137 Expression
*doInline(InlineDoState
*ids
);
138 Statement
*inlineScan(InlineScanState
*iss
);
140 void toIR(IRState
*irs
);
143 struct CompileStatement
: Statement
147 CompileStatement(Loc loc
, Expression
*exp
);
148 Statement
*syntaxCopy();
149 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
150 Statement
*semantic(Scope
*sc
);
153 struct DeclarationStatement
: ExpStatement
155 // Doing declarations as an expression, rather than a statement,
156 // makes inlining functions much easier.
158 DeclarationStatement(Loc loc
, Dsymbol
*s
);
159 DeclarationStatement(Loc loc
, Expression
*exp
);
160 Statement
*syntaxCopy();
161 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
162 void scopeCode(Scope
*sc
, Statement
**sentry
, Statement
**sexit
, Statement
**sfinally
);
164 DeclarationStatement
*isDeclarationStatement() { return this; }
167 struct InjectorMainBody
: Statement
{
168 ClassDeclaration
*mainClass
;
170 InjectorMainBody(Loc loc
, ClassDeclaration
*mainClass
);
171 Statement
*semantic(Scope
*sc
);
174 struct CompoundStatement
: Statement
176 Statements
*statements
;
178 CompoundStatement(Loc loc
, Statements
*s
);
179 CompoundStatement(Loc loc
, Statement
*s1
, Statement
*s2
);
180 Statement
*syntaxCopy();
181 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
182 Statement
*semantic(Scope
*sc
);
187 Statements
*flatten(Scope
*sc
);
188 ReturnStatement
*isReturnStatement();
189 Expression
*interpret(InterState
*istate
);
191 int inlineCost(InlineCostState
*ics
);
192 Expression
*doInline(InlineDoState
*ids
);
193 Statement
*inlineScan(InlineScanState
*iss
);
195 void toIR(IRState
*irs
);
197 CompoundStatement
*isCompoundStatement() { return this; }
200 /* The purpose of this is so that continue will go to the next
201 * of the statements, and break will go to the end of the statements.
203 struct UnrolledLoopStatement
: Statement
205 Statements
*statements
;
207 UnrolledLoopStatement(Loc loc
, Statements
*statements
);
208 Statement
*syntaxCopy();
209 Statement
*semantic(Scope
*sc
);
216 Expression
*interpret(InterState
*istate
);
217 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
219 int inlineCost(InlineCostState
*ics
);
220 Expression
*doInline(InlineDoState
*ids
);
221 Statement
*inlineScan(InlineScanState
*iss
);
223 void toIR(IRState
*irs
);
226 struct ScopeStatement
: Statement
228 Statement
*statement
;
230 ScopeStatement(Loc loc
, Statement
*s
);
231 Statement
*syntaxCopy();
232 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
233 ScopeStatement
*isScopeStatement() { return this; }
234 Statement
*semantic(Scope
*sc
);
241 Expression
*interpret(InterState
*istate
);
243 Statement
*inlineScan(InlineScanState
*iss
);
245 void toIR(IRState
*irs
);
248 struct WhileStatement
: Statement
250 Expression
*condition
;
253 WhileStatement(Loc loc
, Expression
*c
, Statement
*b
);
254 Statement
*syntaxCopy();
255 Statement
*semantic(Scope
*sc
);
262 Expression
*interpret(InterState
*istate
);
263 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
265 Statement
*inlineScan(InlineScanState
*iss
);
267 void toIR(IRState
*irs
);
270 struct DoStatement
: Statement
273 Expression
*condition
;
275 DoStatement(Loc loc
, Statement
*b
, Expression
*c
);
276 Statement
*syntaxCopy();
277 Statement
*semantic(Scope
*sc
);
284 Expression
*interpret(InterState
*istate
);
285 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
287 Statement
*inlineScan(InlineScanState
*iss
);
289 void toIR(IRState
*irs
);
292 struct ForStatement
: Statement
295 Expression
*condition
;
296 Expression
*increment
;
299 ForStatement(Loc loc
, Statement
*init
, Expression
*condition
, Expression
*increment
, Statement
*body
);
300 Statement
*syntaxCopy();
301 Statement
*semantic(Scope
*sc
);
302 void scopeCode(Scope
*sc
, Statement
**sentry
, Statement
**sexit
, Statement
**sfinally
);
309 Expression
*interpret(InterState
*istate
);
310 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
312 Statement
*inlineScan(InlineScanState
*iss
);
314 void toIR(IRState
*irs
);
317 struct ForeachStatement
: Statement
319 enum TOK op
; // TOKforeach or TOKforeach_reverse
320 Arguments
*arguments
; // array of Argument*'s
325 VarDeclaration
*value
;
327 FuncDeclaration
*func
; // function we're lexically in
329 Array cases
; // put breaks, continues, gotos and returns here
330 Array gotos
; // forward referenced goto's go here
332 ForeachStatement(Loc loc
, enum TOK op
, Arguments
*arguments
, Expression
*aggr
, Statement
*body
);
333 Statement
*syntaxCopy();
334 Statement
*semantic(Scope
*sc
);
341 Expression
*interpret(InterState
*istate
);
342 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
344 Statement
*inlineScan(InlineScanState
*iss
);
346 void toIR(IRState
*irs
);
349 struct ForeachRangeStatement
: Statement
351 enum TOK op
; // TOKforeach or TOKforeach_reverse
352 Argument
*arg
; // loop index variable
359 ForeachRangeStatement(Loc loc
, enum TOK op
, Argument
*arg
,
360 Expression
*lwr
, Expression
*upr
, Statement
*body
);
361 Statement
*syntaxCopy();
362 Statement
*semantic(Scope
*sc
);
369 Expression
*interpret(InterState
*istate
);
370 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
372 Statement
*inlineScan(InlineScanState
*iss
);
374 void toIR(IRState
*irs
);
377 struct IfStatement
: Statement
380 Expression
*condition
;
384 VarDeclaration
*match
; // for MatchExpression results
386 IfStatement(Loc loc
, Argument
*arg
, Expression
*condition
, Statement
*ifbody
, Statement
*elsebody
);
387 Statement
*syntaxCopy();
388 Statement
*semantic(Scope
*sc
);
389 Expression
*interpret(InterState
*istate
);
390 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
394 IfStatement
*isIfStatement() { return this; }
396 int inlineCost(InlineCostState
*ics
);
397 Expression
*doInline(InlineDoState
*ids
);
398 Statement
*inlineScan(InlineScanState
*iss
);
400 void toIR(IRState
*irs
);
403 struct ConditionalStatement
: Statement
405 Condition
*condition
;
409 ConditionalStatement(Loc loc
, Condition
*condition
, Statement
*ifbody
, Statement
*elsebody
);
410 Statement
*syntaxCopy();
411 Statement
*semantic(Scope
*sc
);
412 Statements
*flatten(Scope
*sc
);
415 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
418 struct PragmaStatement
: Statement
421 Expressions
*args
; // array of Expression's
424 PragmaStatement(Loc loc
, Identifier
*ident
, Expressions
*args
, Statement
*body
);
425 Statement
*syntaxCopy();
426 Statement
*semantic(Scope
*sc
);
431 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
433 void toIR(IRState
*irs
);
436 struct LogStatement
: Statement
450 LogStatement(Loc loc
, int level
, Expressions
*args
);
451 Statement
*syntaxCopy();
452 Statement
*semantic(Scope
*sc
);
454 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
457 struct StaticAssertStatement
: Statement
461 StaticAssertStatement(StaticAssert
*sa
);
462 Statement
*syntaxCopy();
463 Statement
*semantic(Scope
*sc
);
465 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
468 struct SwitchStatement
: Statement
470 Expression
*condition
;
473 DefaultStatement
*sdefault
;
474 TryFinallyStatement
*tf
;
475 Array gotoCases
; // array of unresolved GotoCaseStatement's
476 Array
*cases
; // array of CaseStatement's
477 int hasNoDefault
; // !=0 if no default statement
478 int hasVars
; // !=0 if has variable case values
480 SwitchStatement(Loc loc
, Expression
*c
, Statement
*b
);
481 Statement
*syntaxCopy();
482 Statement
*semantic(Scope
*sc
);
487 Expression
*interpret(InterState
*istate
);
488 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
490 Statement
*inlineScan(InlineScanState
*iss
);
492 void toIR(IRState
*irs
);
495 struct CaseStatement
: Statement
498 Statement
*statement
;
499 int index
; // which case it is (since we sort this)
500 block
*cblock
; // back end: label for the block
502 CaseStatement(Loc loc
, Expression
*exp
, Statement
*s
);
503 Statement
*syntaxCopy();
504 Statement
*semantic(Scope
*sc
);
505 int compare(Object
*obj
);
510 Expression
*interpret(InterState
*istate
);
511 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
513 Statement
*inlineScan(InlineScanState
*iss
);
515 void toIR(IRState
*irs
);
518 struct DefaultStatement
: Statement
520 Statement
*statement
;
522 block
*cblock
; // back end: label for the block
525 DefaultStatement(Loc loc
, Statement
*s
);
526 Statement
*syntaxCopy();
527 Statement
*semantic(Scope
*sc
);
532 Expression
*interpret(InterState
*istate
);
533 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
535 Statement
*inlineScan(InlineScanState
*iss
);
537 void toIR(IRState
*irs
);
540 struct GotoDefaultStatement
: Statement
544 GotoDefaultStatement(Loc loc
);
545 Statement
*syntaxCopy();
546 Statement
*semantic(Scope
*sc
);
547 Expression
*interpret(InterState
*istate
);
550 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
552 void toIR(IRState
*irs
);
555 struct GotoCaseStatement
: Statement
557 Expression
*exp
; // NULL, or which case to goto
558 CaseStatement
*cs
; // case statement it resolves to
560 GotoCaseStatement(Loc loc
, Expression
*exp
);
561 Statement
*syntaxCopy();
562 Statement
*semantic(Scope
*sc
);
563 Expression
*interpret(InterState
*istate
);
566 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
568 void toIR(IRState
*irs
);
571 struct SwitchErrorStatement
: Statement
573 SwitchErrorStatement(Loc loc
);
576 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
578 void toIR(IRState
*irs
);
581 struct ReturnStatement
: Statement
585 ReturnStatement(Loc loc
, Expression
*exp
);
586 Statement
*syntaxCopy();
587 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
588 Statement
*semantic(Scope
*sc
);
591 Expression
*interpret(InterState
*istate
);
593 int inlineCost(InlineCostState
*ics
);
594 Expression
*doInline(InlineDoState
*ids
);
595 Statement
*inlineScan(InlineScanState
*iss
);
597 void toIR(IRState
*irs
);
599 ReturnStatement
*isReturnStatement() { return this; }
602 struct BreakStatement
: Statement
606 BreakStatement(Loc loc
, Identifier
*ident
);
607 Statement
*syntaxCopy();
608 Statement
*semantic(Scope
*sc
);
609 Expression
*interpret(InterState
*istate
);
612 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
614 void toIR(IRState
*irs
);
617 struct ContinueStatement
: Statement
621 ContinueStatement(Loc loc
, Identifier
*ident
);
622 Statement
*syntaxCopy();
623 Statement
*semantic(Scope
*sc
);
624 Expression
*interpret(InterState
*istate
);
627 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
629 void toIR(IRState
*irs
);
632 struct SynchronizedStatement
: Statement
637 SynchronizedStatement(Loc loc
, Expression
*exp
, Statement
*body
);
638 Statement
*syntaxCopy();
639 Statement
*semantic(Scope
*sc
);
645 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
647 Statement
*inlineScan(InlineScanState
*iss
);
651 SynchronizedStatement(Loc loc
, elem
*esync
, Statement
*body
);
652 void toIR(IRState
*irs
);
655 struct WithStatement
: Statement
659 VarDeclaration
*wthis
;
661 WithStatement(Loc loc
, Expression
*exp
, Statement
*body
);
662 Statement
*syntaxCopy();
663 Statement
*semantic(Scope
*sc
);
664 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
669 Statement
*inlineScan(InlineScanState
*iss
);
671 void toIR(IRState
*irs
);
674 struct TryCatchStatement
: Statement
679 TryCatchStatement(Loc loc
, Statement
*body
, Array
*catches
);
680 Statement
*syntaxCopy();
681 Statement
*semantic(Scope
*sc
);
687 Statement
*inlineScan(InlineScanState
*iss
);
689 void toIR(IRState
*irs
);
690 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
691 TryCatchStatement
*isTryCatchStatement() { return this; }
694 struct Catch
: Object
702 Catch(Loc loc
, Type
*t
, Identifier
*id
, Statement
*handler
);
704 void semantic(Scope
*sc
);
706 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
709 struct TryFinallyStatement
: Statement
712 Statement
*finalbody
;
714 TryFinallyStatement(Loc loc
, Statement
*body
, Statement
*finalbody
);
715 Statement
*syntaxCopy();
716 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
717 Statement
*semantic(Scope
*sc
);
724 Statement
*inlineScan(InlineScanState
*iss
);
726 void toIR(IRState
*irs
);
729 struct OnScopeStatement
: Statement
732 Statement
*statement
;
734 OnScopeStatement(Loc loc
, TOK tok
, Statement
*statement
);
735 Statement
*syntaxCopy();
737 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
738 Statement
*semantic(Scope
*sc
);
740 void scopeCode(Scope
*sc
, Statement
**sentry
, Statement
**sexit
, Statement
**sfinally
);
742 void toIR(IRState
*irs
);
745 struct ThrowStatement
: Statement
749 ThrowStatement(Loc loc
, Expression
*exp
);
750 Statement
*syntaxCopy();
751 Statement
*semantic(Scope
*sc
);
752 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
756 Statement
*inlineScan(InlineScanState
*iss
);
758 void toIR(IRState
*irs
);
761 struct VolatileStatement
: Statement
763 Statement
*statement
;
765 VolatileStatement(Loc loc
, Statement
*statement
);
766 Statement
*syntaxCopy();
767 Statement
*semantic(Scope
*sc
);
768 Statements
*flatten(Scope
*sc
);
771 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
773 Statement
*inlineScan(InlineScanState
*iss
);
775 void toIR(IRState
*irs
);
778 struct GotoStatement
: Statement
782 TryFinallyStatement
*tf
;
784 GotoStatement(Loc loc
, Identifier
*ident
);
785 Statement
*syntaxCopy();
786 Statement
*semantic(Scope
*sc
);
789 Expression
*interpret(InterState
*istate
);
791 void toIR(IRState
*irs
);
792 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
793 GotoStatement
*isGotoStatement() { return this; }
796 struct LabelStatement
: Statement
799 Statement
*statement
;
800 TryFinallyStatement
*tf
;
801 block
*lblock
; // back end
804 LabelStatement(Loc loc
, Identifier
*ident
, Statement
*statement
);
805 Statement
*syntaxCopy();
806 Statement
*semantic(Scope
*sc
);
807 Statements
*flatten(Scope
*sc
);
812 Expression
*interpret(InterState
*istate
);
813 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
815 Statement
*inlineScan(InlineScanState
*iss
);
817 void toIR(IRState
*irs
);
820 struct LabelDsymbol
: Dsymbol
822 LabelStatement
*statement
;
824 unsigned asmLabelNum
; // GCC-specific
827 LabelDsymbol(Identifier
*ident
);
828 LabelDsymbol
*isLabel();
831 struct AsmStatement
: Statement
835 unsigned asmalign
; // alignment of this statement
836 unsigned refparam
; // !=0 if function parameter is referenced
837 unsigned naked
; // !=0 if function is to be naked
838 unsigned regs
; // mask of registers modified
840 AsmStatement(Loc loc
, Token
*tokens
);
841 Statement
*syntaxCopy();
842 Statement
*semantic(Scope
*sc
);
846 void toCBuffer(OutBuffer
*buf
, HdrGenState
*hgs
);
847 virtual AsmStatement
*isAsmStatement() { return this; }
849 void toIR(IRState
*irs
);
854 // Assembler instructions with D expression operands
855 struct ExtAsmStatement
: Statement
857 Expression
*insnTemplate
;
859 Array
*argNames
; // of NULL or Identifier*
860 Expressions
*argConstraints
; // of StringExp*
861 unsigned nOutputArgs
;
862 Expressions
*clobbers
; // of StringExp*
864 ExtAsmStatement(Loc loc
, Expression
*insnTemplate
, Expressions
*args
, Array
*argNames
,
865 Expressions
*argConstraints
, int nOutputArgs
, Expressions
*clobbers
);
866 Statement
*syntaxCopy();
867 Statement
*semantic(Scope
*sc
);
869 void toIR(IRState
*irs
);
874 #endif /* DMD_STATEMENT_H */