annotate dmd/SwitchStatement.d @ 192:eb38fdcb3e62 default tip

updated to compile with dmd2.062
author korDen
date Sat, 02 Mar 2013 01:25:52 -0800
parents b0d41ff5e0df
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.SwitchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 77
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.Expression;
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
6 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.DefaultStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.Array;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.WANT;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.GotoCaseStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.CaseStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.SwitchErrorStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 import dmd.HaltExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 import dmd.BreakStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 import dmd.EnumDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 import dmd.TypeEnum;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 import dmd.Dsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 import dmd.EnumMember;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 import dmd.TypeTypedef;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 import dmd.TOK;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 import dmd.StringExp;
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
37 import dmd.expression.Equal;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 import dmd.backend.elem;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 import dmd.backend.OPER;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 import dmd.backend.TYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 import dmd.backend.dt_t;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 import dmd.backend.Symbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 import dmd.backend.SC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 import dmd.backend.FL;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 import dmd.backend.RTLSYM;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 import dmd.backend.targ_types;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52
183
190ba98276b3 Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents: 180
diff changeset
53 version (MACHOBJ)
190ba98276b3 Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents: 180
diff changeset
54 import dmd.Module;
190ba98276b3 Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents: 180
diff changeset
55
4
d706d958e4e8 Step 2 of restoring GC functionality.
korDen
parents: 2
diff changeset
56 import core.memory;
2
7427ded8caf7 Removed unreferenced modules
korDen
parents: 0
diff changeset
57
5
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
58 import core.stdc.stdlib;
63623152e82a Fixed memory corruption bug which was introduced when attempting to restore GC functionality
dkoroskin <>
parents: 4
diff changeset
59
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 183
diff changeset
60 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 183
diff changeset
61
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 class SwitchStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 183
diff changeset
64 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 183
diff changeset
65
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 Expression condition;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 bool isFinal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 DefaultStatement sdefault = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 TryFinallyStatement tf = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 Array gotoCases; // array of unresolved GotoCaseStatement's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 Array cases; // array of CaseStatement's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 int hasNoDefault = 0; // !=0 if no default statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 int hasVars = 0; // !=0 if has variable case values
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 this(Loc loc, Expression c, Statement b, bool isFinal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
79 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 this.condition = c;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 this.body_ = b;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 this.isFinal = isFinal;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 gotoCases = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
89 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 {
53
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 5
diff changeset
91 SwitchStatement s = new SwitchStatement(loc,
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 5
diff changeset
92 condition.syntaxCopy(), body_.syntaxCopy(), isFinal);
a8b50ff7f201 ForeachStatement.syntaxCopy
korDen
parents: 5
diff changeset
93 return s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
96 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 //printf("SwitchStatement.semantic(%p)\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 tf = sc.tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 assert(!cases); // ensure semantic() is only run once
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 condition = condition.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 condition = resolveProperties(sc, condition);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 if (condition.type.isString())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 // If it's not an array, cast it to one
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 if (condition.type.ty != Tarray)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 condition = condition.implicitCastTo(sc, condition.type.nextOf().arrayOf());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 condition.type = condition.type.constOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 condition = condition.integralPromotions(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 condition.checkIntegral();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 condition = condition.optimize(WANTvalue);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 sc.sbreak = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 sc.sw = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 cases = new Array();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 sc.noctor++; // BUG: should use Scope.mergeCallSuper() for each case instead
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 body_ = body_.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 sc.noctor--;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 // Resolve any goto case's with exp
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 for (int i = 0; i < gotoCases.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 GotoCaseStatement gcs = cast(GotoCaseStatement)gotoCases.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 if (!gcs.exp)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 gcs.error("no case statement following goto case;");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 for (Scope scx = sc; scx; scx = scx.enclosing)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 if (!scx.sw)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 continue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 for (int j = 0; j < scx.sw.cases.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 CaseStatement cs = cast(CaseStatement)scx.sw.cases.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 if (cs.exp.equals(gcs.exp))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 gcs.cs = cs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 goto Lfoundcase;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 gcs.error("case %s not found", gcs.exp.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 Lfoundcase:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 if (!sc.sw.sdefault && !isFinal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 hasNoDefault = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 warning("switch statement has no default");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 // Generate runtime error if the default is hit
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 Statements a = new Statements();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 CompoundStatement cs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 if (global.params.useSwitchError)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 s = new SwitchErrorStatement(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
174 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 Expression e = new HaltExp(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 s = new ExpStatement(loc, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 a.reserve(4);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
180 a.push(body_);
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
181 a.push(new BreakStatement(loc, null));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 sc.sw.sdefault = new DefaultStatement(loc, s);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
183 a.push(sc.sw.sdefault);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
184 cs = new CompoundStatement(loc, a);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
185 body_ = cs;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
186 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
187
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
188 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
189 if (isFinal)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
190 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
191 Type t = condition.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
192 while (t.ty == Ttypedef)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
194 // Don't use toBasetype() because that will skip past enums
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
195 t = (cast(TypeTypedef)t).sym.basetype;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
196 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
197 if (condition.type.ty == Tenum)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
198 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
199 TypeEnum te = cast(TypeEnum)condition.type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 EnumDeclaration ed = te.toDsymbol(sc).isEnumDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
201 assert(ed);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 size_t dim = ed.members.dim;
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
203 foreach (Dsymbol s; ed.members)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 {
77
ad4792a1cfd6 more D-ification container accessing
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
205 if (auto em = s.isEnumMember())
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
206 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 for (size_t j = 0; j < cases.dim; j++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 CaseStatement cs = cast(CaseStatement)cases.data[j];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 if (cs.exp.equals(em.value))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
211 goto L1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 error("enum member %s not represented in final switch", em.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 L1:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
216 ;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
222 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
226 override bool hasBreak()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
228 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
229 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
230
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
231 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
232 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
233 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
234 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
235
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
236 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
237 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
238 BE result = BE.BEnone;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
239 if (condition.canThrow())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
240 result |= BE.BEthrow;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
241
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
242 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
243 { result |= body_.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
244 if (result & BE.BEbreak)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
245 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
246 result |= BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
247 result &= ~BE.BEbreak;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
248 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
249 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
250 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
251 result |= BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
252
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
253 return result;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
254 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
255
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
256 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
257 {
162
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
258 version (LOG) {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
259 printf("SwitchStatement.interpret()\n");
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
260 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
261 if (istate.start == this)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
262 istate.start = null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
263 Expression e = null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
264
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
265 if (istate.start)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
266 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
267 e = body_ ? body_.interpret(istate) : null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
268 if (istate.start)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
269 return null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
270 if (e is EXP_CANT_INTERPRET)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
271 return e;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
272 if (e is EXP_BREAK_INTERPRET)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
273 return null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
274 return e;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
275 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
276
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
277
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
278 Expression econdition = condition.interpret(istate);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
279 if (econdition is EXP_CANT_INTERPRET)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
280 return EXP_CANT_INTERPRET;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
281
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
282 Statement s = null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
283 if (cases)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
284 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
285 for (size_t i = 0; i < cases.dim; i++)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
286 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
287 CaseStatement cs = cast(CaseStatement)cases.data[i];
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
288 e = Equal(TOKequal, Type.tint32, econdition, cs.exp);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
289 if (e is EXP_CANT_INTERPRET)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
290 return EXP_CANT_INTERPRET;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
291 if (e.isBool(true))
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
292 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
293 s = cs;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
294 break;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
295 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
296 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
297 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
298 if (!s)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
299 {
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
300 if (hasNoDefault)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
301 error("no default or case for %s in switch statement", econdition.toChars());
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
302 s = sdefault;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
303 }
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
304
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
305 assert(s);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
306 istate.start = s;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
307 e = body_ ? body_.interpret(istate) : null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
308 assert(!istate.start);
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
309 if (e is EXP_BREAK_INTERPRET)
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
310 return null;
438eaa11eed4 updated build script to use dmd2.039
korDen
parents: 135
diff changeset
311 return e;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
312 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
313
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
314 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
315 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
316 buf.writestring("switch (");
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
317 condition.toCBuffer(buf, hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
318 buf.writebyte(')');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
319 buf.writenl();
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
320 if (body_)
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
321 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
322 if (!body_.isScopeStatement())
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
323 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
324 buf.writebyte('{');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
325 buf.writenl();
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
326 body_.toCBuffer(buf, hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
327 buf.writebyte('}');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
328 buf.writenl();
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
329 }
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
330 else
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
331 {
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
332 body_.toCBuffer(buf, hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
333 }
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 162
diff changeset
334 }
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
335 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
336
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
337 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
338 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
339 //printf("SwitchStatement.inlineScan()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
340 condition = condition.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
341 body_ = body_ ? body_.inlineScan(iss) : null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
342 if (sdefault)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
343 sdefault = cast(DefaultStatement)sdefault.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
344 if (cases)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
345 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
346 for (int i = 0; i < cases.dim; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
347 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
348 Statement s = cast(Statement)cases.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
349 cases.data[i] = cast(void*)s.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
350 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
351 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
352 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
353 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
354
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
355 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
356 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
357 int string;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
358 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
359
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
360 //printf("SwitchStatement.toIR()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
361 IRState mystate = IRState(irs,this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
362
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
363 mystate.switchBlock = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
364
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
365 /* Block for where "break" goes to
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
366 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
367 mystate.breakBlock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
368
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
369 /* Block for where "default" goes to.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
370 * If there is a default statement, then that is where default goes.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
371 * If not, then do:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
372 * default: break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
373 * by making the default block the same as the break block.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
374 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
375 mystate.defaultBlock = sdefault ? block_calloc(blx) : mystate.breakBlock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
376
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
377 int numcases = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
378 if (cases)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
379 numcases = cases.dim;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
380
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
381 incUsage(irs, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
382 elem* econd = condition.toElem(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
383
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
384 version (DMDV2) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
385 if (hasVars)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
386 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
387 /* Generate a sequence of if-then-else blocks for the cases.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
388 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
389 if (econd.Eoper != OPvar)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
390 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
391 elem* e = exp2_copytotemp(econd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
392 block_appendexp(mystate.switchBlock, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
393 econd = e.E2;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
394 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
395
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
396 for (int i = 0; i < numcases; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
397 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
398 CaseStatement cs = cast(CaseStatement)cases.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
399
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
400 elem* ecase = cs.exp.toElem(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
401 elem* e = el_bin(OPeqeq, TYbool, el_copytree(econd), ecase);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
402 block* b = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
403 block_appendexp(b, e);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
404 block* bcase = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
405 cs.cblock = bcase;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
406 block_next(blx, BCiftrue, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
407 list_append(&b.Bsucc, bcase);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
408 list_append(&b.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
409 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
410
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
411 /* The final 'else' clause goes to the default
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
412 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
413 block* b = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
414 block_next(blx, BCgoto, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
415 list_append(&b.Bsucc, mystate.defaultBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
416
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
417 body_.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
418
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
419 /* Have the end of the switch body fall through to the block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
420 * following the switch statement.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
421 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
422 block_goto(blx, BCgoto, mystate.breakBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
423 return;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
424 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
425 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
426
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
427 if (condition.type.isString())
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
428 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
429 // Number the cases so we can unscramble things after the sort()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
430 for (int i = 0; i < numcases; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
431 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
432 CaseStatement cs = cast(CaseStatement)cases.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
433 cs.index = i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
434 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
435
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
436 cases.sort();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
437
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
438 /* Create a sorted array of the case strings, and si
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
439 * will be the symbol for it.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
440 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
441 dt_t* dt = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
442 Symbol* si = symbol_generate(SCstatic,type_fake(TYullong));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
443 version (MACHOBJ) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
444 si.Sseg = Segment.DATA;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
445 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
446 dtdword(&dt, numcases);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
447 dtxoff(&dt, si, 8, TYnptr);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
448
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
449 for (int i = 0; i < numcases; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
450 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
451 CaseStatement cs = cast(CaseStatement)cases.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
452
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
453 if (cs.exp.op != TOKstring)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
454 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
455 error("case '%s' is not a string", cs.exp.toChars()); // BUG: this should be an assert
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
456 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
457 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
458 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
459 StringExp se = cast(StringExp)(cs.exp);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
460 uint len = se.len;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
461 dtdword(&dt, len);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
462 dtabytes(&dt, TYnptr, 0, se.len * se.sz, cast(char*)se.string_);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
463 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
464 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
465
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
466 si.Sdt = dt;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
467 si.Sfl = FLdata;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
468 outdata(si);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
469
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
470 /* Call:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
471 * _d_switch_string(string[] si, string econd)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
472 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
473 elem* eparam = el_param(econd, el_var(si));
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
474 switch (condition.type.nextOf().ty)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
475 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
476 case Tchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
477 econd = el_bin(OPcall, TYint, el_var(rtlsym[RTLSYM_SWITCH_STRING]), eparam);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
478 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
479 case Twchar:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
480 econd = el_bin(OPcall, TYint, el_var(rtlsym[RTLSYM_SWITCH_USTRING]), eparam);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
481 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
482 case Tdchar: // BUG: implement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
483 econd = el_bin(OPcall, TYint, el_var(rtlsym[RTLSYM_SWITCH_DSTRING]), eparam);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
484 break;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
485 default:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
486 assert(0);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
487 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
488 elem_setLoc(econd, loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
489 string = 1;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
490 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
491 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
492 string = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
493 block_appendexp(mystate.switchBlock, econd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
494 block_next(blx,BCswitch,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
495
135
af1bebfd96a4 dmd 2.038
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 122
diff changeset
496 // Corresponding free is in block_free
180
0622fff7810a Fixed a few memory allocation related issues
korDen
parents: 178
diff changeset
497 targ_llong* pu = cast(targ_llong*) malloc(targ_llong.sizeof * (numcases + 1));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
498 mystate.switchBlock.Bswitch = pu;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
499 /* First pair is the number of cases, and the default block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
500 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
501 *pu++ = numcases;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
502 list_append(&mystate.switchBlock.Bsucc, mystate.defaultBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
503
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
504 /* Fill in the first entry in each pair, which is the case value.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
505 * CaseStatement.toIR() will fill in
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
506 * the second entry for each pair with the block.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
507 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
508 for (int i = 0; i < numcases; i++)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
509 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
510 CaseStatement cs = cast(CaseStatement)cases.data[i];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
511 if (string)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
512 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
513 pu[cs.index] = i;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
514 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
515 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
516 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
517 pu[i] = cs.exp.toInteger();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
518 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
519 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
520
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
521 body_.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
522
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
523 /* Have the end of the switch body fall through to the block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
524 * following the switch statement.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
525 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
526 block_goto(blx, BCgoto, mystate.breakBlock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
527 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
528 }