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