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