0
|
1 module dmd.DoStatement;
|
|
2
|
|
3 import dmd.Statement;
|
|
4 import dmd.Expression;
|
|
5 import dmd.Loc;
|
|
6 import dmd.Scope;
|
|
7 import dmd.InterState;
|
|
8 import dmd.HdrGenState;
|
|
9 import dmd.OutBuffer;
|
|
10 import dmd.InlineScanState;
|
|
11 import dmd.IRState;
|
|
12 import dmd.BE;
|
|
13 import dmd.WANT;
|
|
14
|
|
15 import dmd.backend.block;
|
|
16 import dmd.backend.Blockx;
|
|
17 import dmd.backend.Util;
|
|
18 import dmd.backend.BC;
|
|
19
|
|
20 class DoStatement : Statement
|
|
21 {
|
|
22 Statement body_;
|
|
23 Expression condition;
|
|
24
|
|
25 this(Loc loc, Statement b, Expression c)
|
|
26 {
|
|
27 super(loc);
|
|
28 body_ = b;
|
|
29 condition = c;
|
|
30 }
|
|
31
|
72
|
32 override Statement syntaxCopy()
|
0
|
33 {
|
|
34 DoStatement s = new DoStatement(loc, body_ ? body_.syntaxCopy() : null, condition.syntaxCopy());
|
|
35 return s;
|
|
36 }
|
|
37
|
72
|
38 override Statement semantic(Scope sc)
|
0
|
39 {
|
|
40 sc.noctor++;
|
|
41 if (body_)
|
|
42 body_ = body_.semanticScope(sc, this, this);
|
|
43 sc.noctor--;
|
|
44 condition = condition.semantic(sc);
|
|
45 condition = resolveProperties(sc, condition);
|
|
46 condition = condition.optimize(WANTvalue);
|
|
47
|
|
48 condition = condition.checkToBoolean();
|
|
49
|
|
50 return this;
|
|
51 }
|
|
52
|
72
|
53 override bool hasBreak()
|
0
|
54 {
|
|
55 return true;
|
|
56 }
|
|
57
|
72
|
58 override bool hasContinue()
|
0
|
59 {
|
|
60 return true;
|
|
61 }
|
|
62
|
72
|
63 override bool usesEH()
|
0
|
64 {
|
|
65 return body_ ? body_.usesEH() : false;
|
|
66 }
|
|
67
|
72
|
68 override BE blockExit()
|
0
|
69 {
|
|
70 BE result;
|
|
71
|
|
72 if (body_)
|
|
73 {
|
|
74 result = body_.blockExit();
|
|
75 if (result == BE.BEbreak)
|
|
76 return BE.BEfallthru;
|
|
77 if (result & BE.BEcontinue)
|
|
78 result |= BE.BEfallthru;
|
|
79 }
|
|
80 else
|
|
81 result = BE.BEfallthru;
|
|
82
|
|
83 if (result & BE.BEfallthru)
|
|
84 {
|
|
85 if (condition.canThrow())
|
|
86 result |= BE.BEthrow;
|
|
87 if (!(result & BE.BEbreak) && condition.isBool(true))
|
|
88 result &= ~BE.BEfallthru;
|
|
89 }
|
|
90 result &= ~(BE.BEbreak | BE.BEcontinue);
|
|
91
|
|
92 return result;
|
|
93 }
|
|
94
|
72
|
95 override bool comeFrom()
|
0
|
96 {
|
|
97 assert(false);
|
|
98 }
|
|
99
|
72
|
100 override Expression interpret(InterState istate)
|
0
|
101 {
|
|
102 assert(false);
|
|
103 }
|
|
104
|
72
|
105 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
106 {
|
|
107 assert(false);
|
|
108 }
|
|
109
|
72
|
110 override Statement inlineScan(InlineScanState* iss)
|
0
|
111 {
|
|
112 body_ = body_ ? body_.inlineScan(iss) : null;
|
|
113 condition = condition.inlineScan(iss);
|
|
114 return this;
|
|
115 }
|
|
116
|
72
|
117 override void toIR(IRState* irs)
|
0
|
118 {
|
|
119 Blockx *blx = irs.blx;
|
|
120
|
|
121 IRState mystate = IRState(irs,this);
|
|
122 mystate.breakBlock = block_calloc(blx);
|
|
123 mystate.contBlock = block_calloc(blx);
|
|
124
|
|
125 block* bpre = blx.curblock;
|
|
126 block_next(blx, BCgoto, null);
|
|
127 list_append(&bpre.Bsucc, blx.curblock);
|
|
128
|
|
129 list_append(&mystate.contBlock.Bsucc, blx.curblock);
|
|
130 list_append(&mystate.contBlock.Bsucc, mystate.breakBlock);
|
|
131
|
|
132 if (body_)
|
|
133 body_.toIR(&mystate);
|
|
134 list_append(&blx.curblock.Bsucc, mystate.contBlock);
|
|
135
|
|
136 block_next(blx, BCgoto, mystate.contBlock);
|
|
137 incUsage(irs, condition.loc);
|
|
138 block_appendexp(mystate.contBlock, condition.toElem(&mystate));
|
|
139 block_next(blx, BCiftrue, mystate.breakBlock);
|
|
140 }
|
72
|
141 }
|