Mercurial > projects > ddmd
annotate dmd/GotoCaseStatement.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 |
rev | line source |
---|---|
0 | 1 module dmd.GotoCaseStatement; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Statement; |
5 import dmd.Expression; | |
6 import dmd.CaseStatement; | |
7 import dmd.IRState; | |
8 import dmd.Scope; | |
9 import dmd.Loc; | |
10 import dmd.InterState; | |
11 import dmd.OutBuffer; | |
12 import dmd.HdrGenState; | |
13 import dmd.BE; | |
64 | 14 import dmd.WANT; |
0 | 15 |
123 | 16 import dmd.backend.Util; |
17 import dmd.backend.block; | |
18 import dmd.backend.BC; | |
19 import dmd.backend.Blockx; | |
20 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
21 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
|
22 |
0 | 23 class GotoCaseStatement : Statement |
24 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
25 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
|
26 |
0 | 27 Expression exp; // NULL, or which case to goto |
28 CaseStatement cs; // case statement it resolves to | |
29 | |
30 this(Loc loc, Expression exp) | |
31 { | |
178 | 32 register(); |
0 | 33 super(loc); |
64 | 34 cs = null; |
35 this.exp = exp; | |
0 | 36 } |
37 | |
72 | 38 override Statement syntaxCopy() |
0 | 39 { |
64 | 40 Expression e = exp ? exp.syntaxCopy() : null; |
41 GotoCaseStatement s = new GotoCaseStatement(loc, e); | |
42 return s; | |
0 | 43 } |
44 | |
72 | 45 override Statement semantic(Scope sc) |
0 | 46 { |
64 | 47 if (exp) |
48 exp = exp.semantic(sc); | |
49 | |
50 if (!sc.sw) | |
51 error("goto case not in switch statement"); | |
52 else | |
53 { | |
54 sc.sw.gotoCases.push(cast(void*)this); | |
55 if (exp) | |
56 { | |
57 exp = exp.implicitCastTo(sc, sc.sw.condition.type); | |
58 exp = exp.optimize(WANTvalue); | |
59 } | |
60 } | |
61 return this; | |
0 | 62 } |
63 | |
72 | 64 override Expression interpret(InterState istate) |
0 | 65 { |
66 assert(false); | |
67 } | |
68 | |
72 | 69 override BE blockExit() |
0 | 70 { |
64 | 71 return BEgoto; |
0 | 72 } |
73 | |
72 | 74 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 75 { |
64 | 76 buf.writestring("goto case"); |
77 if (exp) | |
78 { | |
79 buf.writebyte(' '); | |
80 exp.toCBuffer(buf, hgs); | |
81 } | |
82 buf.writebyte(';'); | |
83 buf.writenl(); | |
0 | 84 } |
85 | |
72 | 86 override void toIR(IRState* irs) |
0 | 87 { |
123 | 88 block* b; |
89 Blockx* blx = irs.blx; | |
90 block* bdest = cs.cblock; | |
91 | |
92 if (!bdest) | |
93 { | |
94 bdest = block_calloc(blx); | |
95 cs.cblock = bdest; | |
96 } | |
97 | |
98 b = blx.curblock; | |
99 | |
100 // The rest is equivalent to GotoStatement | |
101 | |
102 // Adjust exception handler scope index if in different try blocks | |
103 if (b.Btry != bdest.Btry) | |
104 { | |
105 // Check that bdest is in an enclosing try block | |
106 for (block* bt = b.Btry; bt != bdest.Btry; bt = bt.Btry) | |
107 { | |
108 if (!bt) | |
109 { | |
110 //printf("b.Btry = %p, bdest.Btry = %p\n", b.Btry, bdest.Btry); | |
111 error("cannot goto into try block"); | |
112 break; | |
113 } | |
114 } | |
115 | |
116 //setScopeIndex(blx, b, bdest.Btry ? bdest.Btry.Bscope_index : -1); | |
117 } | |
118 | |
119 list_append(&b.Bsucc,bdest); | |
120 incUsage(irs, loc); | |
121 block_next(blx, BC.BCgoto, null); | |
0 | 122 } |
72 | 123 } |