annotate dmd/Statement.d @ 182:b64060ab22df

Now compileable with dmd2.050
author korDen
date Sat, 30 Oct 2010 05:05:32 +0400
parents e3afd1303184
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.Statement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 63
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.TryCatchStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.GotoStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.AsmStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.ScopeStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.DeclarationStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.CompoundStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.ReturnStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.IfStatement;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.OutBuffer;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.HdrGenState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.InterState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19 import dmd.InlineCostState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 import dmd.InlineDoState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 import dmd.InlineScanState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 import dmd.IRState;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 import dmd.BE;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 import dmd.Global;
155
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
25 import dmd.GlobalExpressions;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 import dmd.Util;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
28 import std.stdio;
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
29
155
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
30 //! startup code used in *Statement.interpret() functions
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
31 enum START = `
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
32 if (istate.start)
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
33 {
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
34 if (istate.start !is this)
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
35 return null;
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
36 istate.start = null;
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
37 }
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
38 `;
63
cab4c37afb89 A bunch of implementations
korDen
parents: 58
diff changeset
39
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
40 import dmd.TObject;
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
41
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
42 class Statement : TObject
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 Loc loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 this(Loc loc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
48 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 this.loc = loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 Statement syntaxCopy()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 void print()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
61
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 string toChars()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 {
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
64 /*scope*/ OutBuffer buf = new OutBuffer();
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
65 HdrGenState hgs;
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
66
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
67 toCBuffer(buf, &hgs);
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
68 return buf.toChars();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 void error(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 {
58
ecf732dfe11e Statement.error
korDen
parents: 0
diff changeset
73 .error(loc, format, t);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
75
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 void warning(T...)(string format, T t)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 if (global.params.warnings && !global.gag)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 writef("warning - ");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 .error(loc, format, t);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 void toCBuffer(OutBuffer buf, HdrGenState* hgs)
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 TryCatchStatement isTryCatchStatement() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 GotoStatement isGotoStatement() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 AsmStatement isAsmStatement() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
95
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 version (_DH) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 int incontract;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 ScopeStatement isScopeStatement() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 Statement semantic(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
105
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 Statement semanticScope(Scope sc, Statement sbreak, Statement scontinue)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 Scope scd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 Statement s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 scd = sc.push();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 if (sbreak)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 scd.sbreak = sbreak;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 if (scontinue)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 scd.scontinue = scontinue;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 s = semantic(scd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 scd.pop();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 return s;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
120
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 bool hasBreak()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
125
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 bool hasContinue()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
130
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
131 // TRUE if statement uses exception handling
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
132
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 bool usesEH()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 {
123
9e39c7de8438 Make dmd test suite compile
korDen
parents: 114
diff changeset
135 return false;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
136 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
137
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
138 BE blockExit()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
139 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
140 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
141 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
142
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
143 // true if statement 'comes from' somewhere else, like a goto
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
144 bool comeFrom()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
145 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
146 //printf("Statement::comeFrom()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
147 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
148 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
149
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
150 // Return TRUE if statement has no code in it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
151 bool isEmpty()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
152 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
153 //printf("Statement::isEmpty()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
154 return false;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
155 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
156
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
157 /****************************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
158 * If this statement has code that needs to run in a finally clause
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
159 * at the end of the current scope, return that code in the form of
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
160 * a Statement.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
161 * Output:
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
162 * *sentry code executed upon entry to the scope
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
163 * *sexception code executed upon exit from the scope via exception
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
164 * *sfinally code executed in finally block
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
165 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
166 void scopeCode(Scope sc, Statement* sentry, Statement* sexception, Statement* sfinally)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
167 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
168 //printf("Statement::scopeCode()\n");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
169 //print();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
170 *sentry = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
171 *sexception = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
172 *sfinally = null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
173 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
174
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
175 /*********************************
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
176 * Flatten out the scope by presenting the statement
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
177 * as an array of statements.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
178 * Returns NULL if no flattening necessary.
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
179 */
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
180 Statements flatten(Scope sc)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
181 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
182 return null;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
183 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
184
155
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
185 /***********************************
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
186 * Interpret the statement.
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
187 * Returns:
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
188 * null continue to next statement
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
189 * EXP_CANT_INTERPRET cannot interpret statement at compile time
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
190 * !null expression from return statement
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
191 */
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
192 Expression interpret(InterState istate)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
193 {
155
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
194 version(LOG)
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
195 writef("Statement::interpret()\n");
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
196
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
197 mixin(START);
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
198 error("Statement %s cannot be interpreted at compile time", this.toChars());
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
199 return EXP_CANT_INTERPRET;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
200 }
155
a43c65469219 + Statement.interpret()
trass3r
parents: 123
diff changeset
201
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
202 int inlineCost(InlineCostState* ics)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
203 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
204 return COST_MAX; // default is we can't inline it
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
205 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
206
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
207 Expression doInline(InlineDoState ids)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
208 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
209 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
210 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
211
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
212 Statement inlineScan(InlineScanState* iss)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
213 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
214 return this;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
215 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
216
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
217 // Back end
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
218 void toIR(IRState* irs)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
219 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
220 assert(false);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
221 }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
222
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
223 // Avoid dynamic_cast
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
224 DeclarationStatement isDeclarationStatement() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
225 CompoundStatement isCompoundStatement() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
226 ReturnStatement isReturnStatement() { return null; }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
227 IfStatement isIfStatement() { return null; }
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 155
diff changeset
228 }