comparison dmd/NewExp.d @ 90:39648eb578f6

more Expressions work
author Eldar Insafutdinov <e.insafutdinov@gmail.com>
date Mon, 30 Aug 2010 20:27:56 +0100
parents be2ab491772e
children e28b18c23469
comparison
equal deleted inserted replaced
88:23280d154c5b 90:39648eb578f6
345 error("too many arguments for array"); 345 error("too many arguments for array");
346 arguments.dim = i; 346 arguments.dim = i;
347 break; 347 break;
348 } 348 }
349 349
350 Expression arg = cast(Expression)arguments.data[j]; 350 auto arg = arguments[j];
351 arg = resolveProperties(sc, arg); 351 arg = resolveProperties(sc, arg);
352 arg = arg.implicitCastTo(sc, Type.tsize_t); 352 arg = arg.implicitCastTo(sc, Type.tsize_t);
353 arg = arg.optimize(WANTvalue); 353 arg = arg.optimize(WANTvalue);
354 if (arg.op == TOKint64 && cast(long)arg.toInteger() < 0) 354 if (arg.op == TOKint64 && cast(long)arg.toInteger() < 0)
355 error("negative array index %s", arg.toChars()); 355 error("negative array index %s", arg.toChars());
382 thisexp = thisexp.optimize(WANTvalue); 382 thisexp = thisexp.optimize(WANTvalue);
383 383
384 // Optimize parameters 384 // Optimize parameters
385 if (newargs) 385 if (newargs)
386 { 386 {
387 for (size_t i = 0; i < newargs.dim; i++) 387 foreach (ref Expression e; newargs)
388 { 388 {
389 Expression e = cast(Expression)newargs.data[i];
390
391 e = e.optimize(WANTvalue); 389 e = e.optimize(WANTvalue);
392 newargs[i] = e;
393 } 390 }
394 } 391 }
395 392
396 if (arguments) 393 if (arguments)
397 { 394 {
398 for (size_t i = 0; i < arguments.dim; i++) 395 foreach (ref Expression e; arguments)
399 { 396 {
400 Expression e = cast(Expression)arguments.data[i];
401
402 e = e.optimize(WANTvalue); 397 e = e.optimize(WANTvalue);
403 arguments[i] = e;
404 } 398 }
405 } 399 }
406 return this; 400 return this;
407 } 401 }
408 402
666 660
667 assert(arguments && arguments.dim >= 1); 661 assert(arguments && arguments.dim >= 1);
668 if (arguments.dim == 1) 662 if (arguments.dim == 1)
669 { 663 {
670 // Single dimension array allocations 664 // Single dimension array allocations
671 Expression arg = cast(Expression)arguments.data[0]; // gives array length 665 auto arg = arguments[0]; // gives array length
672 e = arg.toElem(irs); 666 e = arg.toElem(irs);
673 ulong elemsize = tda.next.size(); 667 ulong elemsize = tda.next.size();
674 668
675 // call _d_newT(ti, arg) 669 // call _d_newT(ti, arg)
676 e = el_param(e, type.getTypeInfo(null).toElem(irs)); 670 e = el_param(e, type.getTypeInfo(null).toElem(irs));
679 } 673 }
680 else 674 else
681 { 675 {
682 // Multidimensional array allocations 676 // Multidimensional array allocations
683 e = el_long(TYint, arguments.dim); 677 e = el_long(TYint, arguments.dim);
684 for (size_t i = 0; i < arguments.dim; i++) 678 foreach (Expression arg; arguments)
685 { 679 {
686 Expression arg = cast(Expression)arguments.data[i]; // gives array length
687 e = el_param(arg.toElem(irs), e); 680 e = el_param(arg.toElem(irs), e);
688 assert(t.ty == Tarray); 681 assert(t.ty == Tarray);
689 t = t.nextOf(); 682 t = t.nextOf();
690 assert(t); 683 assert(t);
691 } 684 }