0
|
1 module dmd.DoStatement;
|
|
2
|
114
|
3 import dmd.common;
|
0
|
4 import dmd.Statement;
|
|
5 import dmd.Expression;
|
|
6 import dmd.Loc;
|
|
7 import dmd.Scope;
|
|
8 import dmd.InterState;
|
155
|
9 import dmd.GlobalExpressions;
|
0
|
10 import dmd.HdrGenState;
|
|
11 import dmd.OutBuffer;
|
|
12 import dmd.InlineScanState;
|
|
13 import dmd.IRState;
|
|
14 import dmd.BE;
|
|
15 import dmd.WANT;
|
|
16
|
|
17 import dmd.backend.block;
|
|
18 import dmd.backend.Blockx;
|
|
19 import dmd.backend.Util;
|
|
20 import dmd.backend.BC;
|
|
21
|
|
22 class DoStatement : Statement
|
|
23 {
|
|
24 Statement body_;
|
|
25 Expression condition;
|
|
26
|
|
27 this(Loc loc, Statement b, Expression c)
|
|
28 {
|
|
29 super(loc);
|
|
30 body_ = b;
|
|
31 condition = c;
|
|
32 }
|
|
33
|
72
|
34 override Statement syntaxCopy()
|
0
|
35 {
|
|
36 DoStatement s = new DoStatement(loc, body_ ? body_.syntaxCopy() : null, condition.syntaxCopy());
|
|
37 return s;
|
|
38 }
|
|
39
|
72
|
40 override Statement semantic(Scope sc)
|
0
|
41 {
|
|
42 sc.noctor++;
|
|
43 if (body_)
|
|
44 body_ = body_.semanticScope(sc, this, this);
|
|
45 sc.noctor--;
|
|
46 condition = condition.semantic(sc);
|
|
47 condition = resolveProperties(sc, condition);
|
|
48 condition = condition.optimize(WANTvalue);
|
|
49
|
|
50 condition = condition.checkToBoolean();
|
|
51
|
|
52 return this;
|
|
53 }
|
|
54
|
72
|
55 override bool hasBreak()
|
0
|
56 {
|
|
57 return true;
|
|
58 }
|
|
59
|
72
|
60 override bool hasContinue()
|
0
|
61 {
|
|
62 return true;
|
|
63 }
|
|
64
|
72
|
65 override bool usesEH()
|
0
|
66 {
|
|
67 return body_ ? body_.usesEH() : false;
|
|
68 }
|
|
69
|
72
|
70 override BE blockExit()
|
0
|
71 {
|
|
72 BE result;
|
|
73
|
|
74 if (body_)
|
|
75 {
|
|
76 result = body_.blockExit();
|
|
77 if (result == BE.BEbreak)
|
|
78 return BE.BEfallthru;
|
|
79 if (result & BE.BEcontinue)
|
|
80 result |= BE.BEfallthru;
|
|
81 }
|
|
82 else
|
|
83 result = BE.BEfallthru;
|
|
84
|
|
85 if (result & BE.BEfallthru)
|
|
86 {
|
|
87 if (condition.canThrow())
|
|
88 result |= BE.BEthrow;
|
|
89 if (!(result & BE.BEbreak) && condition.isBool(true))
|
|
90 result &= ~BE.BEfallthru;
|
|
91 }
|
|
92 result &= ~(BE.BEbreak | BE.BEcontinue);
|
|
93
|
|
94 return result;
|
|
95 }
|
|
96
|
72
|
97 override bool comeFrom()
|
0
|
98 {
|
|
99 assert(false);
|
|
100 }
|
|
101
|
72
|
102 override Expression interpret(InterState istate)
|
0
|
103 {
|
155
|
104 version(LOG)
|
|
105 writef("DoStatement::interpret()\n");
|
|
106
|
|
107 if (istate.start == this)
|
|
108 istate.start = null;
|
|
109 Expression e;
|
|
110
|
|
111 if (istate.start)
|
|
112 {
|
|
113 e = body_ ? body_.interpret(istate) : null;
|
|
114 if (istate.start)
|
|
115 return null;
|
|
116 if (e is EXP_CANT_INTERPRET)
|
|
117 return e;
|
|
118 if (e is EXP_BREAK_INTERPRET)
|
|
119 return null;
|
|
120 if (e is EXP_CONTINUE_INTERPRET)
|
|
121 goto Lcontinue;
|
|
122 if (e)
|
|
123 return e;
|
|
124 }
|
|
125
|
|
126 while (1)
|
|
127 {
|
|
128 e = body_ ? body_.interpret(istate) : null;
|
|
129 if (e is EXP_CANT_INTERPRET)
|
|
130 break;
|
|
131 if (e is EXP_BREAK_INTERPRET)
|
|
132 {
|
|
133 e = null;
|
|
134 break;
|
|
135 }
|
|
136 if (e && e !is EXP_CONTINUE_INTERPRET)
|
|
137 break;
|
|
138
|
|
139 Lcontinue:
|
|
140 e = condition.interpret(istate);
|
|
141 if (e is EXP_CANT_INTERPRET)
|
|
142 break;
|
|
143 if (!e.isConst())
|
|
144 {
|
|
145 e = EXP_CANT_INTERPRET;
|
|
146 break;
|
|
147 }
|
|
148 if (e.isBool(true))
|
|
149 {
|
|
150 }
|
|
151 else if (e.isBool(false))
|
|
152 {
|
|
153 e = null;
|
|
154 break;
|
|
155 }
|
|
156 else
|
|
157 assert(0);
|
|
158 }
|
|
159 return e;
|
0
|
160 }
|
|
161
|
72
|
162 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
163 {
|
|
164 assert(false);
|
|
165 }
|
|
166
|
72
|
167 override Statement inlineScan(InlineScanState* iss)
|
0
|
168 {
|
|
169 body_ = body_ ? body_.inlineScan(iss) : null;
|
|
170 condition = condition.inlineScan(iss);
|
|
171 return this;
|
|
172 }
|
|
173
|
72
|
174 override void toIR(IRState* irs)
|
0
|
175 {
|
|
176 Blockx *blx = irs.blx;
|
|
177
|
|
178 IRState mystate = IRState(irs,this);
|
|
179 mystate.breakBlock = block_calloc(blx);
|
|
180 mystate.contBlock = block_calloc(blx);
|
|
181
|
|
182 block* bpre = blx.curblock;
|
|
183 block_next(blx, BCgoto, null);
|
|
184 list_append(&bpre.Bsucc, blx.curblock);
|
|
185
|
|
186 list_append(&mystate.contBlock.Bsucc, blx.curblock);
|
|
187 list_append(&mystate.contBlock.Bsucc, mystate.breakBlock);
|
|
188
|
|
189 if (body_)
|
|
190 body_.toIR(&mystate);
|
|
191 list_append(&blx.curblock.Bsucc, mystate.contBlock);
|
|
192
|
|
193 block_next(blx, BCgoto, mystate.contBlock);
|
|
194 incUsage(irs, condition.loc);
|
|
195 block_appendexp(mystate.contBlock, condition.toElem(&mystate));
|
|
196 block_next(blx, BCiftrue, mystate.breakBlock);
|
|
197 }
|
72
|
198 }
|