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