0
|
1 module dmd.DefaultStatement;
|
|
2
|
|
3 import dmd.Statement;
|
|
4 import dmd.Loc;
|
|
5 import dmd.Scope;
|
|
6 import dmd.Expression;
|
|
7 import dmd.InterState;
|
|
8 import dmd.OutBuffer;
|
|
9 import dmd.HdrGenState;
|
|
10 import dmd.InlineScanState;
|
|
11 import dmd.IRState;
|
|
12 import dmd.BE;
|
|
13
|
|
14 import dmd.backend.Util;
|
|
15 import dmd.backend.OPER;
|
|
16 import dmd.backend.Blockx;
|
|
17 import dmd.backend.block;
|
|
18 import dmd.backend.BC;
|
|
19
|
|
20 class DefaultStatement : Statement
|
|
21 {
|
|
22 Statement statement;
|
|
23 version (IN_GCC) {
|
|
24 block* cblock = null; // back end: label for the block
|
|
25 }
|
|
26
|
|
27 this(Loc loc, Statement s)
|
|
28 {
|
|
29 super(loc);
|
|
30 this.statement = s;
|
|
31 }
|
|
32
|
|
33 Statement syntaxCopy()
|
|
34 {
|
53
|
35 DefaultStatement s = new DefaultStatement(loc, statement.syntaxCopy());
|
|
36 return s;
|
0
|
37 }
|
|
38
|
|
39 Statement semantic(Scope sc)
|
|
40 {
|
|
41 //printf("DefaultStatement.semantic()\n");
|
|
42 if (sc.sw)
|
|
43 {
|
|
44 if (sc.sw.sdefault)
|
|
45 {
|
|
46 error("switch statement already has a default");
|
|
47 }
|
|
48 sc.sw.sdefault = this;
|
|
49
|
|
50 if (sc.sw.tf !is sc.tf)
|
|
51 error("switch and default are in different finally blocks");
|
|
52
|
|
53 if (sc.sw.isFinal)
|
|
54 error("default statement not allowed in final switch statement");
|
|
55 }
|
|
56 else
|
|
57 error("default not in switch statement");
|
|
58 statement = statement.semantic(sc);
|
|
59 return this;
|
|
60 }
|
|
61
|
|
62 bool usesEH()
|
|
63 {
|
|
64 assert(false);
|
|
65 }
|
|
66
|
|
67 BE blockExit()
|
|
68 {
|
|
69 return statement.blockExit();
|
|
70 }
|
|
71
|
|
72 bool comeFrom()
|
|
73 {
|
|
74 return true;
|
|
75 }
|
|
76
|
|
77 Expression interpret(InterState* istate)
|
|
78 {
|
|
79 assert(false);
|
|
80 }
|
|
81
|
|
82 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
|
|
83 {
|
|
84 assert(false);
|
|
85 }
|
|
86
|
|
87 Statement inlineScan(InlineScanState* iss)
|
|
88 {
|
|
89 if (statement)
|
|
90 statement = statement.inlineScan(iss);
|
|
91 return this;
|
|
92 }
|
|
93
|
|
94 void toIR(IRState* irs)
|
|
95 {
|
|
96 Blockx* blx = irs.blx;
|
|
97 block* bcase = blx.curblock;
|
|
98 block* bdefault = irs.getDefaultBlock();
|
|
99 block_next(blx,BCgoto,bdefault);
|
|
100 list_append(&bcase.Bsucc,blx.curblock);
|
|
101 if (blx.tryblock != irs.getSwitchBlock().Btry)
|
|
102 error("default cannot be in different try block level from switch");
|
|
103 incUsage(irs, loc);
|
|
104 if (statement)
|
|
105 statement.toIR(irs);
|
|
106 }
|
|
107 } |