annotate dmd/GotoDefaultStatement.d @ 187:b0d41ff5e0df

Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author Abscissa
date Tue, 07 Jun 2011 23:37:34 -0400
parents e3afd1303184
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.GotoDefaultStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 72
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.SwitchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
15 import dmd.backend.block;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
16 import dmd.backend.Blockx;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
17 import dmd.backend.Util;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
18 import dmd.backend.BC;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
19
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
20 import dmd.DDMDExtensions;
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
21
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 class GotoDefaultStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
24 mixin insertMemberExtension!(typeof(this));
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
25
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 SwitchStatement sw;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 this(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
30 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 super(loc);
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
32 sw = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
35 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
37 GotoDefaultStatement s = new GotoDefaultStatement(loc);
4290d870944a More fixes
korDen
parents: 63
diff changeset
38 return s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
41 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
43 sw = sc.sw;
4290d870944a More fixes
korDen
parents: 63
diff changeset
44 if (!sw)
4290d870944a More fixes
korDen
parents: 63
diff changeset
45 error("goto default not in switch statement");
4290d870944a More fixes
korDen
parents: 63
diff changeset
46 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
49 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
54 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
56 return BEgoto;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
59 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
61 buf.writestring("goto default;\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
64 override void toIR(IRState *irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
66 block *b;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
67 Blockx *blx = irs.blx;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
68 block *bdest = irs.getDefaultBlock();
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
69
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
70 b = blx.curblock;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
71
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
72 // The rest is equivalent to GotoStatement
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 // Adjust exception handler scope index if in different try blocks
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
75 if (b.Btry != bdest.Btry)
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
76 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
77 // Check that bdest is in an enclosing try block
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
78 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
79 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
80 if (!bt)
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 //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
83 error("cannot goto into try block");
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
84 break;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
85 }
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
86 }
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
87
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
88 //setScopeIndex(blx, b, bdest.Btry ? bdest.Btry.Bscope_index : -1);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
89 }
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
90
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
91 list_append(&b.Bsucc,bdest);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
92 incUsage(irs, loc);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
93 block_next(blx,BCgoto,null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
95 }