Mercurial > projects > ldc
comparison dmd/arrayop.c @ 1587:def7a1d494fd
Merge DMD 1.051
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Fri, 06 Nov 2009 23:58:01 +0100 |
parents | afecdb8ee962 |
children | 207a8a438dea |
comparison
equal
deleted
inserted
replaced
1586:7f728c52e63c | 1587:def7a1d494fd |
---|---|
1 | 1 |
2 // Copyright (c) 1999-2008 by Digital Mars | 2 // Copyright (c) 1999-2009 by Digital Mars |
3 // All Rights Reserved | 3 // All Rights Reserved |
4 // written by Walter Bright | 4 // written by Walter Bright |
5 // http://www.digitalmars.com | 5 // http://www.digitalmars.com |
6 // License for redistribution is by either the Artistic License | 6 // License for redistribution is by either the Artistic License |
7 // in artistic.txt, or the GNU General Public License in gnu.txt. | 7 // in artistic.txt, or the GNU General Public License in gnu.txt. |
29 * Construct the array operation expression. | 29 * Construct the array operation expression. |
30 */ | 30 */ |
31 | 31 |
32 Expression *BinExp::arrayOp(Scope *sc) | 32 Expression *BinExp::arrayOp(Scope *sc) |
33 { | 33 { |
34 //printf("BinExp::arrayOp() %s\n", toChars()); | |
35 | |
36 if (type->toBasetype()->nextOf()->toBasetype()->ty == Tvoid) | |
37 { | |
38 error("Cannot perform array operations on void[] arrays"); | |
39 return new ErrorExp(); | |
40 } | |
41 | |
34 Expressions *arguments = new Expressions(); | 42 Expressions *arguments = new Expressions(); |
35 | 43 |
36 /* The expression to generate an array operation for is mangled | 44 /* The expression to generate an array operation for is mangled |
37 * into a name to use as the array operation function name. | 45 * into a name to use as the array operation function name. |
38 * Mangle in the operands and operators in RPN order, and type. | 46 * Mangle in the operands and operators in RPN order, and type. |
286 sc = sc->push(); | 294 sc = sc->push(); |
287 sc->parent = sc->module->importedFrom; | 295 sc->parent = sc->module->importedFrom; |
288 sc->stc = 0; | 296 sc->stc = 0; |
289 sc->linkage = LINKd; | 297 sc->linkage = LINKd; |
290 fd->semantic(sc); | 298 fd->semantic(sc); |
299 fd->semantic2(sc); | |
300 fd->semantic3(sc); | |
291 sc->pop(); | 301 sc->pop(); |
292 // } | 302 // } |
293 // else | 303 // else |
294 // { /* In library, refer to it. | 304 // { /* In library, refer to it. |
295 // */ | 305 // */ |
316 { | 326 { |
317 buf->writestring("Exp"); | 327 buf->writestring("Exp"); |
318 arguments->shift(this); | 328 arguments->shift(this); |
319 } | 329 } |
320 | 330 |
331 void CastExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments) | |
332 { | |
333 Type *tb = type->toBasetype(); | |
334 if (tb->ty == Tarray || tb->ty == Tsarray) | |
335 { | |
336 e1->buildArrayIdent(buf, arguments); | |
337 } | |
338 else | |
339 Expression::buildArrayIdent(buf, arguments); | |
340 } | |
341 | |
321 void SliceExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments) | 342 void SliceExp::buildArrayIdent(OutBuffer *buf, Expressions *arguments) |
322 { | 343 { |
323 buf->writestring("Slice"); | 344 buf->writestring("Slice"); |
324 arguments->shift(this); | 345 arguments->shift(this); |
325 } | 346 } |
400 fparams->shift(param); | 421 fparams->shift(param); |
401 Expression *e = new IdentifierExp(0, id); | 422 Expression *e = new IdentifierExp(0, id); |
402 return e; | 423 return e; |
403 } | 424 } |
404 | 425 |
426 Expression *CastExp::buildArrayLoop(Arguments *fparams) | |
427 { | |
428 Type *tb = type->toBasetype(); | |
429 if (tb->ty == Tarray || tb->ty == Tsarray) | |
430 { | |
431 return e1->buildArrayLoop(fparams); | |
432 } | |
433 else | |
434 return Expression::buildArrayLoop(fparams); | |
435 } | |
436 | |
405 Expression *SliceExp::buildArrayLoop(Arguments *fparams) | 437 Expression *SliceExp::buildArrayLoop(Arguments *fparams) |
406 { | 438 { |
407 Identifier *id = Identifier::generateId("p", fparams->dim); | 439 Identifier *id = Identifier::generateId("p", fparams->dim); |
408 Argument *param = new Argument(STCconst, type, id, NULL); | 440 Argument *param = new Argument(STCconst, type, id, NULL); |
409 fparams->shift(param); | 441 fparams->shift(param); |
418 Expression *AssignExp::buildArrayLoop(Arguments *fparams) | 450 Expression *AssignExp::buildArrayLoop(Arguments *fparams) |
419 { | 451 { |
420 /* Evaluate assign expressions right to left | 452 /* Evaluate assign expressions right to left |
421 */ | 453 */ |
422 Expression *ex2 = e2->buildArrayLoop(fparams); | 454 Expression *ex2 = e2->buildArrayLoop(fparams); |
455 #if DMDV2 | |
456 /* Need the cast because: | |
457 * b = c + p[i]; | |
458 * where b is a byte fails because (c + p[i]) is an int | |
459 * which cannot be implicitly cast to byte. | |
460 */ | |
461 ex2 = new CastExp(0, ex2, e1->type->nextOf()); | |
462 #endif | |
423 Expression *ex1 = e1->buildArrayLoop(fparams); | 463 Expression *ex1 = e1->buildArrayLoop(fparams); |
424 Argument *param = (Argument *)fparams->data[0]; | 464 Argument *param = (Argument *)fparams->data[0]; |
425 param->storageClass = 0; | 465 param->storageClass = 0; |
426 Expression *e = new AssignExp(0, ex1, ex2); | 466 Expression *e = new AssignExp(0, ex1, ex2); |
427 return e; | 467 return e; |
486 X(Or) | 526 X(Or) |
487 | 527 |
488 #undef X | 528 #undef X |
489 | 529 |
490 | 530 |
531 /*********************************************** | |
532 * Test if operand is a valid array op operand. | |
533 */ | |
534 | |
535 int Expression::isArrayOperand() | |
536 { | |
537 //printf("Expression::isArrayOperand() %s\n", toChars()); | |
538 if (op == TOKslice) | |
539 return 1; | |
540 if (type->toBasetype()->ty == Tarray) | |
541 { | |
542 switch (op) | |
543 { | |
544 case TOKadd: | |
545 case TOKmin: | |
546 case TOKmul: | |
547 case TOKdiv: | |
548 case TOKmod: | |
549 case TOKxor: | |
550 case TOKand: | |
551 case TOKor: | |
552 case TOKneg: | |
553 case TOKtilde: | |
554 return 1; | |
555 | |
556 default: | |
557 break; | |
558 } | |
559 } | |
560 return 0; | |
561 } |