annotate dmd/ContinueStatement.d @ 187:b0d41ff5e0df

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