annotate dmd/Statement.d @ 63:cab4c37afb89

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