0
|
1 module dmd.ContinueStatement;
|
|
2
|
114
|
3 import dmd.common;
|
155
|
4 import dmd.interpret.Util;
|
0
|
5 import dmd.Statement;
|
|
6 import dmd.FuncDeclaration;
|
155
|
7 import dmd.GlobalExpressions;
|
0
|
8 import dmd.IntegerExp;
|
|
9 import dmd.ReturnStatement;
|
|
10 import dmd.LabelStatement;
|
|
11 import dmd.Identifier;
|
|
12 import dmd.Loc;
|
|
13 import dmd.Scope;
|
|
14 import dmd.Expression;
|
|
15 import dmd.InterState;
|
|
16 import dmd.HdrGenState;
|
|
17 import dmd.OutBuffer;
|
|
18 import dmd.IRState;
|
|
19 import dmd.BE;
|
|
20
|
|
21 import dmd.backend.Util;
|
|
22 import dmd.backend.BC;
|
|
23 import dmd.backend.block;
|
|
24 import dmd.backend.Blockx;
|
|
25
|
|
26 class ContinueStatement : Statement
|
|
27 {
|
|
28 Identifier ident;
|
|
29
|
|
30 this(Loc loc, Identifier ident)
|
|
31 {
|
|
32 super(loc);
|
|
33 this.ident = ident;
|
|
34 }
|
|
35
|
72
|
36 override Statement syntaxCopy()
|
0
|
37 {
|
|
38 ContinueStatement s = new ContinueStatement(loc, ident);
|
|
39 return s;
|
|
40 }
|
|
41
|
72
|
42 override Statement semantic(Scope sc)
|
0
|
43 {
|
|
44 //printf("ContinueStatement.semantic() %p\n", this);
|
|
45 if (ident)
|
|
46 {
|
|
47 Scope scx;
|
|
48 FuncDeclaration thisfunc = sc.func;
|
|
49
|
|
50 for (scx = sc; scx; scx = scx.enclosing)
|
|
51 {
|
|
52 LabelStatement ls;
|
|
53
|
|
54 if (scx.func != thisfunc) // if in enclosing function
|
|
55 {
|
|
56 if (sc.fes) // if this is the body of a foreach
|
|
57 {
|
|
58 for (; scx; scx = scx.enclosing)
|
|
59 {
|
|
60 ls = scx.slabel;
|
|
61 if (ls && ls.ident == ident && ls.statement == sc.fes)
|
|
62 {
|
|
63 // Replace continue ident; with return 0;
|
|
64 return new ReturnStatement(Loc(0), new IntegerExp(0));
|
|
65 }
|
|
66 }
|
|
67
|
|
68 /* Post this statement to the fes, and replace
|
|
69 * it with a return value that caller will put into
|
|
70 * a switch. Caller will figure out where the break
|
|
71 * label actually is.
|
|
72 * Case numbers start with 2, not 0, as 0 is continue
|
|
73 * and 1 is break.
|
|
74 */
|
|
75 Statement s;
|
|
76 sc.fes.cases.push(cast(void*)this);
|
|
77 s = new ReturnStatement(Loc(0), new IntegerExp(sc.fes.cases.dim + 1));
|
|
78 return s;
|
|
79 }
|
|
80 break; // can't continue to it
|
|
81 }
|
|
82
|
|
83 ls = scx.slabel;
|
|
84 if (ls && ls.ident == ident)
|
|
85 {
|
|
86 Statement s = ls.statement;
|
|
87
|
|
88 if (!s.hasContinue())
|
|
89 error("label '%s' has no continue", ident.toChars());
|
|
90 if (ls.tf != sc.tf)
|
|
91 error("cannot continue out of finally block");
|
|
92 return this;
|
|
93 }
|
|
94 }
|
|
95 error("enclosing label '%s' for continue not found", ident.toChars());
|
|
96 }
|
|
97 else if (!sc.scontinue)
|
|
98 {
|
|
99 if (sc.fes)
|
|
100 {
|
|
101 Statement s;
|
|
102
|
|
103 // Replace continue; with return 0;
|
|
104 s = new ReturnStatement(Loc(0), new IntegerExp(0));
|
|
105 return s;
|
|
106 }
|
|
107 error("continue is not inside a loop");
|
|
108 }
|
|
109 return this;
|
|
110 }
|
|
111
|
72
|
112 override Expression interpret(InterState istate)
|
0
|
113 {
|
155
|
114 version(LOG)
|
|
115 writef("ContinueStatement::interpret()\n");
|
|
116
|
|
117 mixin(START);
|
|
118 if (ident)
|
|
119 return EXP_CANT_INTERPRET;
|
|
120 else
|
|
121 return EXP_CONTINUE_INTERPRET;
|
0
|
122 }
|
|
123
|
72
|
124 override BE blockExit()
|
0
|
125 {
|
|
126 return ident ? BE.BEgoto : BE.BEcontinue;
|
|
127 }
|
|
128
|
72
|
129 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
130 {
|
|
131 buf.writestring("continue");
|
|
132 if (ident)
|
|
133 {
|
|
134 buf.writebyte(' ');
|
|
135 buf.writestring(ident.toChars());
|
|
136 }
|
|
137 buf.writebyte(';');
|
|
138 buf.writenl();
|
|
139 }
|
|
140
|
72
|
141 override void toIR(IRState* irs)
|
0
|
142 {
|
|
143 block* bcont;
|
|
144 block* b;
|
|
145 Blockx* blx = irs.blx;
|
|
146
|
|
147 //printf("ContinueStatement.toIR() %p\n", this);
|
|
148 bcont = irs.getContBlock(ident);
|
|
149 assert(bcont);
|
|
150 b = blx.curblock;
|
|
151 incUsage(irs, loc);
|
|
152
|
|
153 // Adjust exception handler scope index if in different try blocks
|
|
154 if (b.Btry != bcont.Btry)
|
|
155 {
|
|
156 //setScopeIndex(blx, b, bcont.Btry ? bcont.Btry.Bscope_index : -1);
|
|
157 }
|
|
158
|
|
159 /* Nothing more than a 'goto' to the current continue destination
|
|
160 */
|
|
161 list_append(&b.Bsucc, bcont);
|
|
162 block_next(blx, BCgoto, null);
|
|
163 }
|
72
|
164 }
|