comparison dmd/ForeachStatement.d @ 126:1765f3ef917d

ClassDeclarations, Arguments -> Vector
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Fri, 03 Sep 2010 23:25:55 +0100
parents c77e9f4f1793
children 60bb0fe4563e
comparison
equal deleted inserted replaced
125:767a01c2a272 126:1765f3ef917d
178 if (te) 178 if (te)
179 e = te.exps[k]; 179 e = te.exps[k];
180 else 180 else
181 t = Argument.getNth(tuple.arguments, k).type; 181 t = Argument.getNth(tuple.arguments, k).type;
182 182
183 Argument arg = cast(Argument)arguments.data[0]; 183 auto arg = arguments[0];
184 Statements st = new Statements(); 184 auto st = new Statements();
185 185
186 if (dim == 2) 186 if (dim == 2)
187 { 187 {
188 // Declare key 188 // Declare key
189 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) 189 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy))
202 Initializer ie = new ExpInitializer(Loc(0), new IntegerExp(k)); 202 Initializer ie = new ExpInitializer(Loc(0), new IntegerExp(k));
203 VarDeclaration var = new VarDeclaration(loc, arg.type, arg.ident, ie); 203 VarDeclaration var = new VarDeclaration(loc, arg.type, arg.ident, ie);
204 var.storage_class |= STC.STCmanifest; 204 var.storage_class |= STC.STCmanifest;
205 DeclarationExp de = new DeclarationExp(loc, var); 205 DeclarationExp de = new DeclarationExp(loc, var);
206 st.push(new ExpStatement(loc, de)); 206 st.push(new ExpStatement(loc, de));
207 arg = cast(Argument)arguments.data[1]; // value 207 arg = arguments[1]; // value
208 } 208 }
209 // Declare value 209 // Declare value
210 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) 210 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy))
211 error("no storage class for value %s", arg.ident.toChars()); 211 error("no storage class for value %s", arg.ident.toChars());
212 Dsymbol var; 212 Dsymbol var;
213 if (te) 213 if (te)
214 { 214 {
215 Type tb = e.type.toBasetype(); 215 Type tb = e.type.toBasetype();
216 if ((tb.ty == TY.Tfunction || tb.ty == TY.Tsarray) && e.op == TOK.TOKvar) 216 if ((tb.ty == TY.Tfunction || tb.ty == TY.Tsarray) && e.op == TOK.TOKvar)
217 { 217 {
218 VarExp ve = cast(VarExp)e; 218 auto ve = cast(VarExp)e;
219 var = new AliasDeclaration(loc, arg.ident, ve.var); 219 var = new AliasDeclaration(loc, arg.ident, ve.var);
220 } 220 }
221 else 221 else
222 { 222 {
223 arg.type = e.type; 223 arg.type = e.type;
275 if (tn.ty == TY.Tchar || tn.ty == TY.Twchar || tn.ty == TY.Tdchar) 275 if (tn.ty == TY.Tchar || tn.ty == TY.Twchar || tn.ty == TY.Tdchar)
276 { 276 {
277 Argument arg; 277 Argument arg;
278 278
279 int i = (dim == 1) ? 0 : 1; // index of value 279 int i = (dim == 1) ? 0 : 1; // index of value
280 arg = cast(Argument)arguments.data[i]; 280 arg = arguments[i];
281 arg.type = arg.type.semantic(loc, sc); 281 arg.type = arg.type.semantic(loc, sc);
282 tnv = arg.type.toBasetype(); 282 tnv = arg.type.toBasetype();
283 if (tnv.ty != tn.ty && (tnv.ty == TY.Tchar || tnv.ty == TY.Twchar || tnv.ty == TY.Tdchar)) 283 if (tnv.ty != tn.ty && (tnv.ty == TY.Tchar || tnv.ty == TY.Twchar || tnv.ty == TY.Tdchar))
284 { 284 {
285 if (arg.storageClass & STC.STCref) 285 if (arg.storageClass & STC.STCref)
286 error("foreach: value of UTF conversion cannot be ref"); 286 error("foreach: value of UTF conversion cannot be ref");
287 if (dim == 2) 287 if (dim == 2)
288 { 288 {
289 arg = cast(Argument)arguments.data[0]; 289 arg = arguments[0];
290 if (arg.storageClass & STC.STCref) 290 if (arg.storageClass & STC.STCref)
291 error("foreach: key cannot be ref"); 291 error("foreach: key cannot be ref");
292 } 292 }
293 goto Lapply; 293 goto Lapply;
294 } 294 }
295 } 295 }
296 296
297 for (size_t i = 0; i < dim; i++) 297 for (size_t i = 0; i < dim; i++)
298 { 298 {
299 // Declare args 299 // Declare args
300 Argument arg = cast(Argument)arguments.data[i]; 300 auto arg = arguments[i];
301 Type argtype = arg.type.semantic(loc, sc); 301 Type argtype = arg.type.semantic(loc, sc);
302 VarDeclaration var = new VarDeclaration(loc, argtype, arg.ident, null); 302 auto var = new VarDeclaration(loc, argtype, arg.ident, null);
303 var.storage_class |= STC.STCforeach; 303 var.storage_class |= STC.STCforeach;
304 var.storage_class |= arg.storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STC_TYPECTOR); 304 var.storage_class |= arg.storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STC_TYPECTOR);
305 if (var.storage_class & (STC.STCref | STC.STCout)) 305 if (var.storage_class & (STC.STCref | STC.STCout))
306 var.storage_class |= STC.STCnodtor; 306 var.storage_class |= STC.STCnodtor;
307 307
506 * auto e = __r.idhead; 506 * auto e = __r.idhead;
507 */ 507 */
508 e = new VarExp(loc, r); 508 e = new VarExp(loc, r);
509 Expression einit = new DotIdExp(loc, e, idhead); 509 Expression einit = new DotIdExp(loc, e, idhead);
510 // einit = einit.semantic(sc); 510 // einit = einit.semantic(sc);
511 Argument arg = cast(Argument)arguments.data[0]; 511 auto arg = arguments[0];
512 VarDeclaration ve = new VarDeclaration(loc, arg.type, arg.ident, new ExpInitializer(loc, einit)); 512 auto ve = new VarDeclaration(loc, arg.type, arg.ident, new ExpInitializer(loc, einit));
513 ve.storage_class |= STC.STCforeach; 513 ve.storage_class |= STC.STCforeach;
514 ve.storage_class |= arg.storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STC_TYPECTOR); 514 ve.storage_class |= arg.storageClass & (STC.STCin | STC.STCout | STC.STCref | STC.STC_TYPECTOR);
515 515
516 DeclarationExp de = new DeclarationExp(loc, ve); 516 auto de = new DeclarationExp(loc, ve);
517 517
518 Statement body2 = new CompoundStatement(loc, new DeclarationStatement(loc, de), this.body_); 518 Statement body2 = new CompoundStatement(loc, new DeclarationStatement(loc, de), this.body_);
519 s = new ForStatement(loc, init, condition, increment, body2); 519 s = new ForStatement(loc, init, condition, increment, body2);
520 520
521 static if (false) { 521 static if (false) {
567 * int delegate(ref T arg) { body } 567 * int delegate(ref T arg) { body }
568 */ 568 */
569 args = new Arguments(); 569 args = new Arguments();
570 for (size_t i = 0; i < dim; i++) 570 for (size_t i = 0; i < dim; i++)
571 { 571 {
572 Argument arg = cast(Argument)arguments.data[i]; 572 auto arg = arguments[i];
573 573
574 arg.type = arg.type.semantic(loc, sc); 574 arg.type = arg.type.semantic(loc, sc);
575 if (arg.storageClass & STC.STCref) 575 if (arg.storageClass & STC.STCref)
576 id = arg.ident; 576 id = arg.ident;
577 else 577 else
586 v = new VarDeclaration(Loc(0), arg.type, arg.ident, ie); 586 v = new VarDeclaration(Loc(0), arg.type, arg.ident, ie);
587 s = new DeclarationStatement(Loc(0), v); 587 s = new DeclarationStatement(Loc(0), v);
588 body_ = new CompoundStatement(loc, s, body_); 588 body_ = new CompoundStatement(loc, s, body_);
589 } 589 }
590 a = new Argument(STC.STCref, arg.type, id, null); 590 a = new Argument(STC.STCref, arg.type, id, null);
591 args.push(cast(void*)a); 591 args.push(a);
592 } 592 }
593 t = new TypeFunction(args, Type.tint32, 0, LINK.LINKd); 593 t = new TypeFunction(args, Type.tint32, 0, LINK.LINKd);
594 fld = new FuncLiteralDeclaration(loc, Loc(0), t, TOK.TOKdelegate, this); 594 fld = new FuncLiteralDeclaration(loc, Loc(0), t, TOK.TOKdelegate, this);
595 fld.fbody = body_; 595 fld.fbody = body_;
596 flde = new FuncExp(loc, fld); 596 flde = new FuncExp(loc, fld);
613 } 613 }
614 614
615 if (tab.ty == TY.Taarray) 615 if (tab.ty == TY.Taarray)
616 { 616 {
617 // Check types 617 // Check types
618 Argument arg = cast(Argument)arguments.data[0]; 618 auto arg = arguments[0];
619 if (dim == 2) 619 if (dim == 2)
620 { 620 {
621 if (arg.storageClass & STC.STCref) 621 if (arg.storageClass & STC.STCref)
622 error("foreach: index cannot be ref"); 622 error("foreach: index cannot be ref");
623 if (!arg.type.equals(taa.index)) 623 if (!arg.type.equals(taa.index))
624 error("foreach: index must be type %s, not %s", taa.index.toChars(), arg.type.toChars()); 624 error("foreach: index must be type %s, not %s", taa.index.toChars(), arg.type.toChars());
625 625
626 arg = cast(Argument)arguments.data[1]; 626 arg = arguments[1];
627 } 627 }
628 if (!arg.type.equals(taa.nextOf())) 628 if (!arg.type.equals(taa.nextOf()))
629 error("foreach: value must be type %s, not %s", taa.nextOf().toChars(), arg.type.toChars()); 629 error("foreach: value must be type %s, not %s", taa.nextOf().toChars(), arg.type.toChars());
630 630
631 /* Call: 631 /* Call:
779 779
780 bool checkForArgTypes() 780 bool checkForArgTypes()
781 { 781 {
782 bool result = true; 782 bool result = true;
783 783
784 for (size_t i = 0; i < arguments.dim; i++) 784 foreach (arg; arguments)
785 { 785 {
786 Argument arg = cast(Argument)arguments.data[i];
787 if (!arg.type) 786 if (!arg.type)
788 { 787 {
789 error("cannot infer type for %s", arg.ident.toChars()); 788 error("cannot infer type for %s", arg.ident.toChars());
790 arg.type = Type.terror; 789 arg.type = Type.terror;
791 result = false; 790 result = false;
840 { 839 {
841 buf.writestring(Token.toChars(op)); 840 buf.writestring(Token.toChars(op));
842 buf.writestring(" ("); 841 buf.writestring(" (");
843 for (int i = 0; i < arguments.dim; i++) 842 for (int i = 0; i < arguments.dim; i++)
844 { 843 {
845 Argument a = cast(Argument)arguments.data[i]; 844 auto a = arguments[i];
846 if (i) 845 if (i)
847 buf.writestring(", "); 846 buf.writestring(", ");
848 if (a.storageClass & STCref) 847 if (a.storageClass & STCref)
849 buf.writestring((global.params.Dversion == 1) ? "inout " : "ref "); 848 buf.writestring((global.params.Dversion == 1) ? "inout " : "ref ");
850 if (a.type) 849 if (a.type)