Mercurial > projects > ddmd
comparison dmd/interpret/Util.d @ 135:af1bebfd96a4 dmd2037
dmd 2.038
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Mon, 13 Sep 2010 22:19:42 +0100 |
parents | e28b18c23469 |
children | fe2e1b93e88f |
comparison
equal
deleted
inserted
replaced
134:4251f96733f4 | 135:af1bebfd96a4 |
---|---|
138 VarDeclaration v = d.isVarDeclaration(); | 138 VarDeclaration v = d.isVarDeclaration(); |
139 SymbolDeclaration s = d.isSymbolDeclaration(); | 139 SymbolDeclaration s = d.isSymbolDeclaration(); |
140 if (v) | 140 if (v) |
141 { | 141 { |
142 ///version (DMDV2) { | 142 ///version (DMDV2) { |
143 if ((v.isConst() || v.isInvariant() || v.storage_class & STCmanifest) && v.init && !v.value) | 143 if ((v.isConst() || v.isImmutable() || v.storage_class & STCmanifest) && v.init && !v.value) |
144 ///} else { | 144 ///} else { |
145 /// if (v.isConst() && v.init) | 145 /// if (v.isConst() && v.init) |
146 ///} | 146 ///} |
147 { | 147 { |
148 e = v.init.toExpression(); | 148 e = v.init.toExpression(); |
150 e.type = v.type; | 150 e.type = v.type; |
151 } | 151 } |
152 else | 152 else |
153 { | 153 { |
154 e = v.value; | 154 e = v.value; |
155 if (v.isDataseg()) | 155 if (v.isCTFE()) |
156 { | 156 { |
157 error(loc, "static variable %s cannot be read at compile time", v.toChars()); | 157 error(loc, "static variable %s cannot be read at compile time", v.toChars()); |
158 e = EXP_CANT_INTERPRET; | 158 e = EXP_CANT_INTERPRET; |
159 } | 159 } |
160 else if (!e) | 160 else if (!e) |
228 auto ae = new ArrayLiteralExp(Loc(0), elements); | 228 auto ae = new ArrayLiteralExp(Loc(0), elements); |
229 ae.type = type; | 229 ae.type = type; |
230 return ae; | 230 return ae; |
231 } | 231 } |
232 | 232 |
233 | |
234 /******************************** | |
235 * Necessary because defaultInit() for a struct is a VarExp, not a StructLiteralExp. | |
236 */ | |
237 StructLiteralExp createDefaultInitStructLiteral(Loc loc, StructDeclaration sym) | |
238 { | |
239 Expressions structelems = new Expressions(); | |
240 structelems.setDim(sym.fields.dim); | |
241 for (size_t j = 0; j < structelems.dim; j++) | |
242 { | |
243 structelems[j] = sym.fields[j].type.defaultInit(Loc(0)); | |
244 } | |
245 StructLiteralExp structinit = new StructLiteralExp(loc, sym, structelems); | |
246 // Why doesn't the StructLiteralExp constructor do this, when | |
247 // sym.type != null ? | |
248 structinit.type = sym.type; | |
249 return structinit; | |
250 } | |
251 | 233 |
252 /******************************** | 234 /******************************** |
253 * Add v to the istate list, unless it already exists there. | 235 * Add v to the istate list, unless it already exists there. |
254 */ | 236 */ |
255 void addVarToInterstate(InterState istate, VarDeclaration v) | 237 void addVarToInterstate(InterState istate, VarDeclaration v) |