annotate dmd/LabelStatement.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.LabelStatement;
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.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.TryFinallyStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.ExpStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.LabelDsymbol;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.CSX;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.backend.block;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.backend.Blockx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.backend.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 import dmd.backend.BC;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
27 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
28
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 class LabelStatement : Statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
30 {
187
b0d41ff5e0df Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents: 178
diff changeset
31 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
32
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 Identifier ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
34 Statement statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 TryFinallyStatement tf = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 block* lblock = null; // back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37 int isReturnLabel = 0;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 this(Loc loc, Identifier ident, Statement statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 122
diff changeset
41 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 super(loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 this.ident = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 this.statement = statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
47 override Statement syntaxCopy()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 LabelStatement s = new LabelStatement(loc, ident, statement.syntaxCopy());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 return s;
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: 63
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 LabelDsymbol ls;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 FuncDeclaration fd = sc.parent.isFuncDeclaration();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 //printf("LabelStatement.semantic()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 ls = fd.searchLabel(ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 if (ls.statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 error("Label '%s' already defined", ls.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 ls.statement = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 tf = sc.tf;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 sc = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 sc.scopesym = sc.enclosing.scopesym;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 sc.callSuper |= CSXlabel;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 sc.slabel = this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 statement = statement.semantic(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 sc.pop();
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: 63
diff changeset
75 override Statements flatten(Scope sc)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 Statements a = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 a = statement.flatten(sc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 if (a)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 if (!a.dim)
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
85 a.push(new ExpStatement(loc, null));
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
87 Statement s = a[0];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 s = new LabelStatement(loc, ident, s);
122
c77e9f4f1793 Statements -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 114
diff changeset
90 a[0] = s;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 return a;
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: 63
diff changeset
97 override bool usesEH()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 return statement ? statement.usesEH() : false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
102 override BE blockExit()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 //printf("LabelStatement.blockExit(%p)\n", this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 return statement ? statement.blockExit() : BE.BEfallthru;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
108 override bool comeFrom()
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 //printf("LabelStatement.comeFrom()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 return true;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
114 override Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
119 override void toCBuffer(OutBuffer buf, HdrGenState* hgs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 buf.writestring(ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 buf.writebyte(':');
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 buf.writenl();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 statement.toCBuffer(buf, hgs);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
128 override Statement inlineScan(InlineScanState* iss)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 statement = statement.inlineScan(iss);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
132 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
135 override void toIR(IRState* irs)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
137 //printf("LabelStatement.toIR() %p, statement = %p\n", this, statement);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 Blockx* blx = irs.blx;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 block* bc = blx.curblock;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 IRState mystate = IRState(irs,this);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 mystate.ident = ident;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
142
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 if (lblock)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 // We had made a guess about which tryblock the label is in.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 // Error if we guessed wrong.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 // BUG: should fix this
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 if (lblock.Btry != blx.tryblock)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
149 error("cannot goto forward into different try block level");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 lblock = block_calloc(blx);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 block_next(blx,BCgoto,lblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 list_append(&bc.Bsucc,blx.curblock);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
156 if (statement)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 statement.toIR(&mystate);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 }
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 63
diff changeset
159 }