Mercurial > projects > ddmd
comparison dmd/TypeFunction.d @ 96:acd69f84627e
further work
author | Trass3r |
---|---|
date | Tue, 31 Aug 2010 02:12:15 +0200 |
parents | ae5b11064a9a |
children | 3482c73a991b |
comparison
equal
deleted
inserted
replaced
95:ae5b11064a9a | 96:acd69f84627e |
---|---|
140 | 140 |
141 tf.linkage = sc.linkage; | 141 tf.linkage = sc.linkage; |
142 if (tf.next) | 142 if (tf.next) |
143 { | 143 { |
144 tf.next = tf.next.semantic(loc,sc); | 144 tf.next = tf.next.semantic(loc,sc); |
145 version(SARRAYVALUE) {} else | |
146 { | |
145 if (tf.next.toBasetype().ty == TY.Tsarray) | 147 if (tf.next.toBasetype().ty == TY.Tsarray) |
146 { error(loc, "functions cannot return static array %s", tf.next.toChars()); | 148 { error(loc, "functions cannot return static array %s", tf.next.toChars()); |
147 tf.next = Type.terror; | 149 tf.next = Type.terror; |
148 } | 150 } |
151 } | |
149 if (tf.next.toBasetype().ty == TY.Tfunction) | 152 if (tf.next.toBasetype().ty == TY.Tfunction) |
150 { error(loc, "functions cannot return a function"); | 153 { error(loc, "functions cannot return a function"); |
151 tf.next = Type.terror; | 154 tf.next = Type.terror; |
152 } | 155 } |
153 if (tf.next.toBasetype().ty == TY.Ttuple) | 156 if (tf.next.toBasetype().ty == TY.Ttuple) |
185 | 188 |
186 Type t = arg.type.toBasetype(); | 189 Type t = arg.type.toBasetype(); |
187 | 190 |
188 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) | 191 if (arg.storageClass & (STC.STCout | STC.STCref | STC.STClazy)) |
189 { | 192 { |
190 if (t.ty == TY.Tsarray) | 193 //if (t.ty == TY.Tsarray) |
191 error(loc, "cannot have out or ref parameter of type %s", t.toChars()); | 194 //error(loc, "cannot have out or ref parameter of type %s", t.toChars()); |
192 if (arg.storageClass & STC.STCout && arg.type.mod) | 195 if (arg.storageClass & STC.STCout && arg.type.mod & (STCconst | STCimmutable)) |
193 error(loc, "cannot have const/invariant out parameter of type %s", t.toChars()); | 196 error(loc, "cannot have const or immutabl out parameter of type %s", t.toChars()); |
194 } | 197 } |
195 if (!(arg.storageClass & STC.STClazy) && t.ty == TY.Tvoid) | 198 if (!(arg.storageClass & STC.STClazy) && t.ty == TY.Tvoid) |
196 error(loc, "cannot have parameter of type %s", arg.type.toChars()); | 199 error(loc, "cannot have parameter of type %s", arg.type.toChars()); |
197 | 200 |
198 if (arg.defaultArg) | 201 if (arg.defaultArg) |
509 goto Nomatch; // not enough arguments | 512 goto Nomatch; // not enough arguments |
510 } | 513 } |
511 | 514 |
512 arg = cast(Expression)args.data[u]; | 515 arg = cast(Expression)args.data[u]; |
513 assert(arg); | 516 assert(arg); |
517 // writef("arg: %s, type: %s\n", arg.toChars(), arg.type.toChars()); | |
518 | |
514 | 519 |
515 // Non-lvalues do not match ref or out parameters | 520 // Non-lvalues do not match ref or out parameters |
516 if (p.storageClass & (STC.STCref | STC.STCout) && !arg.isLvalue()) | 521 if (p.storageClass & (STC.STCref | STC.STCout)) |
517 goto Nomatch; | 522 { |
523 if (!arg.isLvalue()) | |
524 goto Nomatch; | |
525 } | |
526 | |
527 if (p.storageClass & STCref) | |
528 { | |
529 /* Don't allow static arrays to be passed to mutable refereces | |
530 * to static arrays if the argument cannot be modified. | |
531 */ | |
532 Type targb = arg.type.toBasetype(); | |
533 Type tparb = p.type.toBasetype(); | |
534 //writef("%s\n", targb.toChars()); | |
535 //writef("%s\n", tparb.toChars()); | |
536 if (targb.nextOf() && tparb.ty == Tsarray && | |
537 targb.nextOf().mod != tparb.nextOf().mod && | |
538 !tparb.nextOf().isConst()) | |
539 goto Nomatch; | |
540 } | |
518 | 541 |
519 if (p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid && arg.type.ty != TY.Tvoid) | 542 if (p.storageClass & STC.STClazy && p.type.ty == TY.Tvoid && arg.type.ty != TY.Tvoid) |
520 m = MATCH.MATCHconvert; | 543 m = MATCH.MATCHconvert; |
521 else | 544 else |
522 m = arg.implicitConvTo(p.type); | 545 m = arg.implicitConvTo(p.type); |
603 Nomatch: | 626 Nomatch: |
604 //printf("no match\n"); | 627 //printf("no match\n"); |
605 return MATCH.MATCHnomatch; | 628 return MATCH.MATCHnomatch; |
606 } | 629 } |
607 | 630 |
608 override type* toCtype() | 631 override type* toCtype() |
609 { | 632 { |
610 if (ctype) { | 633 if (ctype) { |
611 return ctype; | 634 return ctype; |
612 } | 635 } |
613 | 636 |
648 | 671 |
649 /*************************** | 672 /*************************** |
650 * Determine return style of function - whether in registers or | 673 * Determine return style of function - whether in registers or |
651 * through a hidden pointer to the caller's stack. | 674 * through a hidden pointer to the caller's stack. |
652 */ | 675 */ |
653 RET retStyle() | 676 RET retStyle() |
654 { | 677 { |
655 //printf("TypeFunction.retStyle() %s\n", toChars()); | 678 //printf("TypeFunction.retStyle() %s\n", toChars()); |
656 version (DMDV2) | 679 version (DMDV2) |
657 { | 680 { |
658 if (isref) | 681 if (isref) |
680 switch (sz) | 703 switch (sz) |
681 { case 1: | 704 { case 1: |
682 case 2: | 705 case 2: |
683 case 4: | 706 case 4: |
684 case 8: | 707 case 8: |
685 return RETregs; // return small structs in regs | 708 return RET.RETregs; // return small structs in regs |
686 // (not 3 byte structs!) | 709 // (not 3 byte structs!) |
687 default: | 710 default: |
688 break; | 711 break; |
689 } | 712 } |
690 } | 713 } |
691 return RETstack; | 714 return RET.RETstack; |
692 } | 715 } |
693 } | 716 } |
694 } | 717 } |
695 if (tns.ty == TY.Tstruct) | 718 if (tns.ty == TY.Tstruct) |
696 { | 719 { |