annotate dmd/TryFinallyStatement.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 af724d3510d7
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.TryFinallyStatement;
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.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.codegen.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 class TryFinallyStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 Statement body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 Statement finalbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 this(Loc loc, Statement body_, Statement finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
28 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 this.body_ = body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 this.finalbody = finalbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
34 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
39 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
41 buf.printf("try\n{\n");
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
42 body_.toCBuffer(buf, hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
43 buf.printf("}\nfinally\n{\n");
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
44 finalbody.toCBuffer(buf, hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
45 buf.writeByte('}');
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 114
diff changeset
46 buf.writenl();
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: 0
diff changeset
49 override Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 //printf("TryFinallyStatement::semantic()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 body_ = body_.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 sc.tf = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 sc.sbreak = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 sc.scontinue = null; // no break or continue out of finally block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 finalbody = finalbody.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 if (!body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 return finalbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 if (!finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 return body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 if (body_.blockExit() == BE.BEfallthru)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 Statement s = new CompoundStatement(loc, body_, finalbody);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
71 override bool hasBreak()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
76 override bool hasContinue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
81 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
86 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 return body_.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 return BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
93 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 body_ = body_.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 finalbody = finalbody.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 * A try-finally statement.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 * Builds the following:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 * _try
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 * block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 * _finally
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 * finalbody
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 * _ret
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 */
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
111 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 //printf("TryFinallyStatement.toIR()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 version (SEH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 nteh_declarvars(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 block* tryblock = block_goto(blx, BCgoto, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 int previndex = blx.scope_index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 tryblock.Blast_index = previndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 tryblock.Bscope_index = blx.next_index++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 blx.scope_index = tryblock.Bscope_index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 // Current scope index
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 setScopeIndex(blx,tryblock,tryblock.Bscope_index);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 blx.tryblock = tryblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 block_goto(blx,BC_try,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 IRState bodyirs = IRState(irs, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 block* breakblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 block* contblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 body_.toIR(&bodyirs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 blx.tryblock = tryblock.Btry; // back to previous tryblock
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 setScopeIndex(blx,blx.curblock,previndex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142 blx.scope_index = previndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 block_goto(blx,BCgoto, breakblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 block* finallyblock = block_goto(blx,BCgoto,contblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 list_append(&tryblock.Bsucc,finallyblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 block_goto(blx,BC_finally,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 IRState finallyState = IRState(irs, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 breakblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 contblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 setScopeIndex(blx, blx.curblock, previndex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 if (finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 finalbody.toIR(&finallyState);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 block_goto(blx, BCgoto, contblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 block_goto(blx, BCgoto, breakblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 block* retblock = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 block_next(blx,BC_ret,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 list_append(&finallyblock.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 list_append(&retblock.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
167 }