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