Mercurial > projects > ddmd
annotate dmd/GotoDefaultStatement.d @ 68:ee3a9f34dc48
final bits of codegen implementation to compile Phobos
author | korDen |
---|---|
date | Tue, 24 Aug 2010 16:44:34 +0400 |
parents | 4290d870944a |
children | 2e2a5c3f943a |
rev | line source |
---|---|
0 | 1 module dmd.GotoDefaultStatement; |
2 | |
3 import dmd.Statement; | |
4 import dmd.SwitchStatement; | |
5 import dmd.Loc; | |
6 import dmd.Scope; | |
7 import dmd.Expression; | |
8 import dmd.InterState; | |
9 import dmd.OutBuffer; | |
10 import dmd.HdrGenState; | |
11 import dmd.IRState; | |
12 import dmd.BE; | |
13 | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
14 import dmd.backend.block; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
15 import dmd.backend.Blockx; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
16 import dmd.backend.Util; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
17 import dmd.backend.BC; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
18 |
0 | 19 class GotoDefaultStatement : Statement |
20 { | |
21 SwitchStatement sw; | |
22 | |
23 this(Loc loc) | |
24 { | |
25 super(loc); | |
51 | 26 sw = null; |
0 | 27 } |
28 | |
29 Statement syntaxCopy() | |
30 { | |
64 | 31 GotoDefaultStatement s = new GotoDefaultStatement(loc); |
32 return s; | |
0 | 33 } |
34 | |
35 Statement semantic(Scope sc) | |
36 { | |
64 | 37 sw = sc.sw; |
38 if (!sw) | |
39 error("goto default not in switch statement"); | |
40 return this; | |
0 | 41 } |
42 | |
63 | 43 Expression interpret(InterState istate) |
0 | 44 { |
45 assert(false); | |
46 } | |
47 | |
48 BE blockExit() | |
49 { | |
64 | 50 return BEgoto; |
0 | 51 } |
52 | |
53 void toCBuffer(OutBuffer buf, HdrGenState* hgs) | |
54 { | |
64 | 55 buf.writestring("goto default;\n"); |
0 | 56 } |
57 | |
58 void toIR(IRState *irs) | |
59 { | |
68
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
60 block *b; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
61 Blockx *blx = irs.blx; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
62 block *bdest = irs.getDefaultBlock(); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
63 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
64 b = blx.curblock; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
65 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
66 // The rest is equivalent to GotoStatement |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
67 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
68 // Adjust exception handler scope index if in different try blocks |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
69 if (b.Btry != bdest.Btry) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
70 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
71 // Check that bdest is in an enclosing try block |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
72 for (block* bt = b.Btry; bt != bdest.Btry; bt = bt.Btry) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
73 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
74 if (!bt) |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
75 { |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
76 //printf("b.Btry = %p, bdest.Btry = %p\n", b.Btry, bdest.Btry); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
77 error("cannot goto into try block"); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
78 break; |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
79 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
80 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
81 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
82 //setScopeIndex(blx, b, bdest.Btry ? bdest.Btry.Bscope_index : -1); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
83 } |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
84 |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
85 list_append(&b.Bsucc,bdest); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
86 incUsage(irs, loc); |
ee3a9f34dc48
final bits of codegen implementation to compile Phobos
korDen
parents:
64
diff
changeset
|
87 block_next(blx,BCgoto,null); |
0 | 88 } |
89 } |