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