Mercurial > projects > ddmd
comparison dmd/VarDeclaration.d @ 130:60bb0fe4563e
dmdfe 2.037 first main iteration
author | Eldar Insafutdinov <e.insafutdinov@gmail.com> |
---|---|
date | Thu, 09 Sep 2010 22:51:44 +0100 |
parents | e28b18c23469 |
children | af1bebfd96a4 |
comparison
equal
deleted
inserted
replaced
129:010eb8f0e18d | 130:60bb0fe4563e |
---|---|
31 import dmd.TemplateInstance; | 31 import dmd.TemplateInstance; |
32 import dmd.Id; | 32 import dmd.Id; |
33 import dmd.Initializer; | 33 import dmd.Initializer; |
34 import dmd.TypeStruct; | 34 import dmd.TypeStruct; |
35 import dmd.TypeTuple; | 35 import dmd.TypeTuple; |
36 import dmd.Argument; | 36 import dmd.Parameter; |
37 import dmd.ExpInitializer; | 37 import dmd.ExpInitializer; |
38 import dmd.ArrayTypes; | 38 import dmd.ArrayTypes; |
39 import dmd.Dsymbol; | 39 import dmd.Dsymbol; |
40 import dmd.Expression; | 40 import dmd.Expression; |
41 import dmd.Loc; | 41 import dmd.Loc; |
196 */ | 196 */ |
197 int inferred = 0; | 197 int inferred = 0; |
198 if (!type) | 198 if (!type) |
199 { | 199 { |
200 inuse++; | 200 inuse++; |
201 type = init.inferType(sc); | 201 |
202 ArrayInitializer ai = init.isArrayInitializer(); | |
203 if (ai) | |
204 { | |
205 Expression e; | |
206 if (ai.isAssociativeArray()) | |
207 e = ai.toAssocArrayLiteral(); | |
208 else | |
209 e = init.toExpression(); | |
210 init = new ExpInitializer(e.loc, e); | |
211 type = init.inferType(sc); | |
212 if (type.ty == TY.Tsarray) | |
213 type = type.nextOf().arrayOf(); | |
214 } | |
215 else | |
216 type = init.inferType(sc); | |
217 | |
202 inuse--; | 218 inuse--; |
203 inferred = 1; | 219 inferred = 1; |
204 | 220 |
221 if (init.isArrayInitializer() && type.toBasetype().ty == TY.Tsarray) | |
222 { // Prefer array literals to give a T[] type rather than a T[dim] | |
223 type = type.toBasetype().nextOf().arrayOf(); | |
224 } | |
225 | |
205 /* This is a kludge to support the existing syntax for RAII | 226 /* This is a kludge to support the existing syntax for RAII |
206 * declarations. | 227 * declarations. |
207 */ | 228 */ |
208 storage_class &= ~STC.STCauto; | 229 storage_class &= ~STC.STCauto; |
209 originalType = type; | 230 originalType = type; |
224 protection = sc.protection; | 245 protection = sc.protection; |
225 //printf("sc.stc = %x\n", sc.stc); | 246 //printf("sc.stc = %x\n", sc.stc); |
226 //printf("storage_class = x%x\n", storage_class); | 247 //printf("storage_class = x%x\n", storage_class); |
227 | 248 |
228 version (DMDV2) { | 249 version (DMDV2) { |
250 static if (true) { | |
251 if (storage_class & STC.STCgshared && sc.func && sc.func.isSafe()) | |
252 { | |
253 error("__gshared not allowed in safe functions; use shared"); | |
254 } | |
255 } else { | |
229 if (storage_class & STC.STCgshared && global.params.safe && !sc.module_.safe) | 256 if (storage_class & STC.STCgshared && global.params.safe && !sc.module_.safe) |
230 { | 257 { |
231 error("__gshared not allowed in safe mode; use shared"); | 258 error("__gshared not allowed in safe mode; use shared"); |
232 } | 259 } |
260 } | |
233 } | 261 } |
234 | 262 |
235 Dsymbol parent = toParent(); | 263 Dsymbol parent = toParent(); |
236 FuncDeclaration fd = parent.isFuncDeclaration(); | 264 FuncDeclaration fd = parent.isFuncDeclaration(); |
237 | 265 |
258 if (tb.ty == TY.Ttuple) | 286 if (tb.ty == TY.Ttuple) |
259 { /* Instead, declare variables for each of the tuple elements | 287 { /* Instead, declare variables for each of the tuple elements |
260 * and add those. | 288 * and add those. |
261 */ | 289 */ |
262 TypeTuple tt = cast(TypeTuple)tb; | 290 TypeTuple tt = cast(TypeTuple)tb; |
263 size_t nelems = Argument.dim(tt.arguments); | 291 size_t nelems = Parameter.dim(tt.arguments); |
264 Objects exps = new Objects(); | 292 Objects exps = new Objects(); |
265 exps.setDim(nelems); | 293 exps.setDim(nelems); |
266 Expression ie = init ? init.toExpression() : null; | 294 Expression ie = init ? init.toExpression() : null; |
267 | 295 |
268 for (size_t i = 0; i < nelems; i++) | 296 for (size_t i = 0; i < nelems; i++) |
269 { Argument arg = Argument.getNth(tt.arguments, i); | 297 { auto arg = Parameter.getNth(tt.arguments, i); |
270 | 298 |
271 OutBuffer buf = new OutBuffer(); | 299 auto buf = new OutBuffer(); |
272 ///buf.printf("_%s_field_%zu", ident.toChars(), i); | 300 ///buf.printf("_%s_field_%zu", ident.toChars(), i); |
273 buf.printf("_%s_field_%s", ident.toChars(), i); | 301 buf.printf("_%s_field_%s", ident.toChars(), i); |
274 buf.writeByte(0); | 302 buf.writeByte(0); |
275 string name = buf.extractString(); | 303 string name = buf.extractString(); |
276 Identifier id = new Identifier(name, TOK.TOKidentifier); | 304 Identifier id = new Identifier(name, TOK.TOKidentifier); |
471 sc.stc &= ~(STC.STC_TYPECTOR | STC.STCpure | STC.STCnothrow | STC.STCref); | 499 sc.stc &= ~(STC.STC_TYPECTOR | STC.STCpure | STC.STCnothrow | STC.STCref); |
472 | 500 |
473 ArrayInitializer ai = init.isArrayInitializer(); | 501 ArrayInitializer ai = init.isArrayInitializer(); |
474 if (ai && tb.ty == TY.Taarray) | 502 if (ai && tb.ty == TY.Taarray) |
475 { | 503 { |
476 init = ai.toAssocArrayInitializer(); | 504 Expression e = ai.toAssocArrayLiteral(); |
505 init = new ExpInitializer(e.loc, e); | |
477 } | 506 } |
478 | 507 |
479 StructInitializer si = init.isStructInitializer(); | 508 StructInitializer si = init.isStructInitializer(); |
480 ExpInitializer ei = init.isExpInitializer(); | 509 ExpInitializer ei = init.isExpInitializer(); |
481 | 510 |