annotate dmd/TryFinallyStatement.d @ 161:584dc990e12f

type fixed
author korDen
date Mon, 20 Sep 2010 01:19:36 +0400
parents e28b18c23469
children af724d3510d7
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 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 this.body_ = body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 this.finalbody = finalbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
33 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 assert(false);
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 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
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 Statement semantic(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 //printf("TryFinallyStatement::semantic()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 body_ = body_.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 sc.tf = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 sc.sbreak = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 sc.scontinue = null; // no break or continue out of finally block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 finalbody = finalbody.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 sc.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 if (!body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 return finalbody;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 if (!finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 return body_;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 if (body_.blockExit() == BE.BEfallthru)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 Statement s = new CompoundStatement(loc, body_, finalbody);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
65 override bool hasBreak()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
70 override bool hasContinue()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 assert(false);
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 usesEH()
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 BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 return body_.blockExit();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 return BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
87 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 body_ = body_.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 if (finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 finalbody = finalbody.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 * A try-finally statement.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 * Builds the following:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 * _try
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 * block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 * _finally
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 * finalbody
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 * _ret
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 */
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
105 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 //printf("TryFinallyStatement.toIR()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 version (SEH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 nteh_declarvars(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 block* tryblock = block_goto(blx, BCgoto, null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 int previndex = blx.scope_index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 tryblock.Blast_index = previndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 tryblock.Bscope_index = blx.next_index++;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 blx.scope_index = tryblock.Bscope_index;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 // Current scope index
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 setScopeIndex(blx,tryblock,tryblock.Bscope_index);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 blx.tryblock = tryblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 block_goto(blx,BC_try,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 IRState bodyirs = IRState(irs, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 block* breakblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 block* contblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 if (body_)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 body_.toIR(&bodyirs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 blx.tryblock = tryblock.Btry; // back to previous tryblock
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 setScopeIndex(blx,blx.curblock,previndex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 blx.scope_index = previndex;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 block_goto(blx,BCgoto, breakblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 block* finallyblock = block_goto(blx,BCgoto,contblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 list_append(&tryblock.Bsucc,finallyblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 block_goto(blx,BC_finally,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 IRState finallyState = IRState(irs, this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 breakblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 contblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 setScopeIndex(blx, blx.curblock, previndex);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 if (finalbody)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 finalbody.toIR(&finallyState);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 block_goto(blx, BCgoto, contblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 block_goto(blx, BCgoto, breakblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 block* retblock = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 block_next(blx,BC_ret,null);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 list_append(&finallyblock.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 list_append(&retblock.Bsucc, blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
161 }