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