annotate dmd/GotoDefaultStatement.d @ 178:e3afd1303184

Many small bugs fixed Made all classes derive from TObject to detect memory leaks (functionality is disabled for now) Began work on overriding backend memory allocations (to avoid memory leaks)
author korDen
date Sun, 17 Oct 2010 07:42:00 +0400
parents e28b18c23469
children b0d41ff5e0df
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
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 class GotoDefaultStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 SwitchStatement sw;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 this(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 114
diff changeset
26 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 super(loc);
51
b7d29f613539 StaticAssertStatement.syntaxCopy
korDen
parents: 0
diff changeset
28 sw = null;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
31 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
33 GotoDefaultStatement s = new GotoDefaultStatement(loc);
4290d870944a More fixes
korDen
parents: 63
diff changeset
34 return s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
37 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
39 sw = sc.sw;
4290d870944a More fixes
korDen
parents: 63
diff changeset
40 if (!sw)
4290d870944a More fixes
korDen
parents: 63
diff changeset
41 error("goto default not in switch statement");
4290d870944a More fixes
korDen
parents: 63
diff changeset
42 return this;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
45 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
50 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
52 return BEgoto;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
55 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 {
64
4290d870944a More fixes
korDen
parents: 63
diff changeset
57 buf.writestring("goto default;\n");
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
60 override void toIR(IRState *irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 {
68
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
62 block *b;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
63 Blockx *blx = irs.blx;
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
64 block *bdest = irs.getDefaultBlock();
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 b = blx.curblock;
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 // The rest is equivalent to GotoStatement
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 // Adjust exception handler scope index if in different try blocks
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
71 if (b.Btry != bdest.Btry)
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
72 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
73 // Check that bdest is in an enclosing try block
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
74 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
75 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
76 if (!bt)
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
77 {
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
78 //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
79 error("cannot goto into try block");
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
80 break;
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 }
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 //setScopeIndex(blx, b, bdest.Btry ? bdest.Btry.Bscope_index : -1);
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 list_append(&b.Bsucc,bdest);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
88 incUsage(irs, loc);
ee3a9f34dc48 final bits of codegen implementation to compile Phobos
korDen
parents: 64
diff changeset
89 block_next(blx,BCgoto,null);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 68
diff changeset
91 }