Mercurial > projects > ddmd
comparison dmd/DefaultStatement.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | a8b50ff7f201 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
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 { | |
35 assert(false); | |
36 } | |
37 | |
38 Statement semantic(Scope sc) | |
39 { | |
40 //printf("DefaultStatement.semantic()\n"); | |
41 if (sc.sw) | |
42 { | |
43 if (sc.sw.sdefault) | |
44 { | |
45 error("switch statement already has a default"); | |
46 } | |
47 sc.sw.sdefault = this; | |
48 | |
49 if (sc.sw.tf !is sc.tf) | |
50 error("switch and default are in different finally blocks"); | |
51 | |
52 if (sc.sw.isFinal) | |
53 error("default statement not allowed in final switch statement"); | |
54 } | |
55 else | |
56 error("default not in switch statement"); | |
57 statement = statement.semantic(sc); | |
58 return this; | |
59 } | |
60 | |
61 bool usesEH() | |
62 { | |
63 assert(false); | |
64 } | |
65 | |
66 BE blockExit() | |
67 { | |
68 return statement.blockExit(); | |
69 } | |
70 | |
71 bool comeFrom() | |
72 { | |
73 return true; | |
74 } | |
75 | |
76 Expression interpret(InterState* istate) | |
77 { | |
78 assert(false); | |
79 } | |
80 | |
81 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
82 { | |
83 assert(false); | |
84 } | |
85 | |
86 Statement inlineScan(InlineScanState* iss) | |
87 { | |
88 if (statement) | |
89 statement = statement.inlineScan(iss); | |
90 return this; | |
91 } | |
92 | |
93 void toIR(IRState* irs) | |
94 { | |
95 Blockx* blx = irs.blx; | |
96 block* bcase = blx.curblock; | |
97 block* bdefault = irs.getDefaultBlock(); | |
98 block_next(blx,BCgoto,bdefault); | |
99 list_append(&bcase.Bsucc,blx.curblock); | |
100 if (blx.tryblock != irs.getSwitchBlock().Btry) | |
101 error("default cannot be in different try block level from switch"); | |
102 incUsage(irs, loc); | |
103 if (statement) | |
104 statement.toIR(irs); | |
105 } | |
106 } |