Mercurial > projects > ddmd
comparison dmd/SliceExp.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 | 1765f3ef917d |
children | af1bebfd96a4 |
comparison
equal
deleted
inserted
replaced
129:010eb8f0e18d | 130:60bb0fe4563e |
---|---|
29 import dmd.Scope; | 29 import dmd.Scope; |
30 import dmd.InlineCostState; | 30 import dmd.InlineCostState; |
31 import dmd.VarDeclaration; | 31 import dmd.VarDeclaration; |
32 import dmd.ErrorExp; | 32 import dmd.ErrorExp; |
33 import dmd.TypeExp; | 33 import dmd.TypeExp; |
34 import dmd.Argument; | 34 import dmd.Parameter; |
35 import dmd.ExpInitializer; | 35 import dmd.ExpInitializer; |
36 import dmd.IRState; | 36 import dmd.IRState; |
37 import dmd.InlineDoState; | 37 import dmd.InlineDoState; |
38 import dmd.ArrayTypes; | 38 import dmd.ArrayTypes; |
39 import dmd.HdrGenState; | 39 import dmd.HdrGenState; |
198 length = te.exps.dim; | 198 length = te.exps.dim; |
199 } | 199 } |
200 else if (e1.op == TOKtype) // slicing a type tuple | 200 else if (e1.op == TOKtype) // slicing a type tuple |
201 { | 201 { |
202 tup = cast(TypeTuple)t; | 202 tup = cast(TypeTuple)t; |
203 length = Argument.dim(tup.arguments); | 203 length = Parameter.dim(tup.arguments); |
204 } | 204 } |
205 else | 205 else |
206 assert(0); | 206 assert(0); |
207 | 207 |
208 if (i1 <= i2 && i2 <= length) | 208 if (i1 <= i2 && i2 <= length) |
221 } | 221 } |
222 e = new TupleExp(loc, exps); | 222 e = new TupleExp(loc, exps); |
223 } | 223 } |
224 else | 224 else |
225 { | 225 { |
226 auto args = new Arguments; | 226 auto args = new Parameters; |
227 args.reserve(j2 - j1); | 227 args.reserve(j2 - j1); |
228 for (size_t i = j1; i < j2; i++) | 228 for (size_t i = j1; i < j2; i++) |
229 { | 229 { |
230 auto arg = Argument.getNth(tup.arguments, i); | 230 auto arg = Parameter.getNth(tup.arguments, i); |
231 args.push(arg); | 231 args.push(arg); |
232 } | 232 } |
233 e = new TypeExp(e1.loc, new TypeTuple(args)); | 233 e = new TypeExp(e1.loc, new TypeTuple(args)); |
234 } | 234 } |
235 e = e.semantic(sc); | 235 e = e.semantic(sc); |
377 assert(false); | 377 assert(false); |
378 } | 378 } |
379 | 379 |
380 override elem* toElem(IRState* irs) | 380 override elem* toElem(IRState* irs) |
381 { | 381 { |
382 elem* e; | |
383 Type t1; | |
384 | |
385 //printf("SliceExp.toElem()\n"); | 382 //printf("SliceExp.toElem()\n"); |
386 t1 = e1.type.toBasetype(); | 383 auto t1 = e1.type.toBasetype(); |
387 e = e1.toElem(irs); | 384 auto e = e1.toElem(irs); |
388 if (lwr) | 385 if (lwr) |
389 { | 386 { |
390 elem* elwr; | 387 auto einit = resolveLengthVar(lengthVar, &e, t1); |
391 elem* elwr2; | 388 |
392 elem* eupr; | 389 int sz = cast(uint)t1.nextOf().size(); |
393 elem* eptr; | 390 |
394 elem* einit; | 391 auto elwr = lwr.toElem(irs); |
395 int sz; | 392 auto eupr = upr.toElem(irs); |
396 | 393 |
397 einit = resolveLengthVar(lengthVar, &e, t1); | 394 auto elwr2 = el_same(&elwr); |
398 | |
399 sz = cast(uint)t1.nextOf().size(); | |
400 | |
401 elwr = lwr.toElem(irs); | |
402 eupr = upr.toElem(irs); | |
403 | |
404 elwr2 = el_same(&elwr); | |
405 | 395 |
406 // Create an array reference where: | 396 // Create an array reference where: |
407 // length is (upr - lwr) | 397 // length is (upr - lwr) |
408 // pointer is (ptr + lwr*sz) | 398 // pointer is (ptr + lwr*sz) |
409 // Combine as (length pair ptr) | 399 // Combine as (length pair ptr) |
410 | 400 |
411 if (global.params.useArrayBounds) | 401 if (irs.arrayBoundsCheck()) |
412 { | 402 { |
413 // Checks (unsigned compares): | 403 // Checks (unsigned compares): |
414 // upr <= array.length | 404 // upr <= array.length |
415 // lwr <= upr | 405 // lwr <= upr |
416 | 406 |
468 elwr2 = el_copytree(elwr2); | 458 elwr2 = el_copytree(elwr2); |
469 eupr = el_copytree(eupr2); | 459 eupr = el_copytree(eupr2); |
470 } | 460 } |
471 } | 461 } |
472 | 462 |
473 eptr = array_toPtr(e1.type, e); | 463 auto eptr = array_toPtr(e1.type, e); |
474 | 464 |
475 elem *elength = el_bin(OPmin, TYint, eupr, elwr2); | 465 elem *elength = el_bin(OPmin, TYint, eupr, elwr2); |
476 eptr = el_bin(OPadd, TYnptr, eptr, el_bin(OPmul, TYint, el_copytree(elwr2), el_long(TYint, sz))); | 466 eptr = el_bin(OPadd, TYnptr, eptr, el_bin(OPmul, TYint, el_copytree(elwr2), el_long(TYint, sz))); |
477 | 467 |
478 e = el_pair(TYullong, elength, eptr); | 468 e = el_pair(TYullong, elength, eptr); |
507 { | 497 { |
508 buf.writestring("Slice"); | 498 buf.writestring("Slice"); |
509 arguments.shift(this); | 499 arguments.shift(this); |
510 } | 500 } |
511 | 501 |
512 override Expression buildArrayLoop(Arguments fparams) | 502 override Expression buildArrayLoop(Parameters fparams) |
513 { | 503 { |
514 Identifier id = Identifier.generateId("p", fparams.dim); | 504 Identifier id = Identifier.generateId("p", fparams.dim); |
515 auto param = new Argument(STCconst, type, id, null); | 505 auto param = new Parameter(STCconst, type, id, null); |
516 fparams.shift(param); | 506 fparams.shift(param); |
517 Expression e = new IdentifierExp(Loc(0), id); | 507 Expression e = new IdentifierExp(Loc(0), id); |
518 Expressions arguments = new Expressions(); | 508 Expressions arguments = new Expressions(); |
519 Expression index = new IdentifierExp(Loc(0), Id.p); | 509 Expression index = new IdentifierExp(Loc(0), Id.p); |
520 arguments.push(index); | 510 arguments.push(index); |