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