0
|
1 module dmd.GotoCaseStatement;
|
|
2
|
|
3 import dmd.Statement;
|
|
4 import dmd.Expression;
|
|
5 import dmd.CaseStatement;
|
|
6 import dmd.IRState;
|
|
7 import dmd.Scope;
|
|
8 import dmd.Loc;
|
|
9 import dmd.InterState;
|
|
10 import dmd.OutBuffer;
|
|
11 import dmd.HdrGenState;
|
|
12 import dmd.BE;
|
64
|
13 import dmd.WANT;
|
0
|
14
|
|
15 class GotoCaseStatement : Statement
|
|
16 {
|
|
17 Expression exp; // NULL, or which case to goto
|
|
18 CaseStatement cs; // case statement it resolves to
|
|
19
|
|
20 this(Loc loc, Expression exp)
|
|
21 {
|
|
22 super(loc);
|
64
|
23 cs = null;
|
|
24 this.exp = exp;
|
0
|
25 }
|
|
26
|
72
|
27 override Statement syntaxCopy()
|
0
|
28 {
|
64
|
29 Expression e = exp ? exp.syntaxCopy() : null;
|
|
30 GotoCaseStatement s = new GotoCaseStatement(loc, e);
|
|
31 return s;
|
0
|
32 }
|
|
33
|
72
|
34 override Statement semantic(Scope sc)
|
0
|
35 {
|
64
|
36 if (exp)
|
|
37 exp = exp.semantic(sc);
|
|
38
|
|
39 if (!sc.sw)
|
|
40 error("goto case not in switch statement");
|
|
41 else
|
|
42 {
|
|
43 sc.sw.gotoCases.push(cast(void*)this);
|
|
44 if (exp)
|
|
45 {
|
|
46 exp = exp.implicitCastTo(sc, sc.sw.condition.type);
|
|
47 exp = exp.optimize(WANTvalue);
|
|
48 }
|
|
49 }
|
|
50 return this;
|
0
|
51 }
|
|
52
|
72
|
53 override Expression interpret(InterState istate)
|
0
|
54 {
|
|
55 assert(false);
|
|
56 }
|
|
57
|
72
|
58 override BE blockExit()
|
0
|
59 {
|
64
|
60 return BEgoto;
|
0
|
61 }
|
|
62
|
72
|
63 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
0
|
64 {
|
64
|
65 buf.writestring("goto case");
|
|
66 if (exp)
|
|
67 {
|
|
68 buf.writebyte(' ');
|
|
69 exp.toCBuffer(buf, hgs);
|
|
70 }
|
|
71 buf.writebyte(';');
|
|
72 buf.writenl();
|
0
|
73 }
|
|
74
|
72
|
75 override void toIR(IRState* irs)
|
0
|
76 {
|
|
77 assert(false);
|
|
78 }
|
72
|
79 }
|