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