Changeset 835
- Timestamp:
- 11/17/07 17:11:23 (9 months ago)
- Files:
-
- branches/dmdfe-2.0/aggregate.h (modified) (2 diffs)
- branches/dmdfe-2.0/cast.c (modified) (19 diffs)
- branches/dmdfe-2.0/class.c (modified) (2 diffs)
- branches/dmdfe-2.0/constfold.c (modified) (4 diffs)
- branches/dmdfe-2.0/declaration.c (modified) (6 diffs)
- branches/dmdfe-2.0/declaration.h (modified) (1 diff)
- branches/dmdfe-2.0/dsymbol.c (modified) (4 diffs)
- branches/dmdfe-2.0/dsymbol.h (modified) (1 diff)
- branches/dmdfe-2.0/enum.c (modified) (1 diff)
- branches/dmdfe-2.0/expression.c (modified) (18 diffs)
- branches/dmdfe-2.0/expression.h (modified) (4 diffs)
- branches/dmdfe-2.0/func.c (modified) (6 diffs)
- branches/dmdfe-2.0/identifier.c (modified) (2 diffs)
- branches/dmdfe-2.0/idgen.c (modified) (4 diffs)
- branches/dmdfe-2.0/init.c (modified) (2 diffs)
- branches/dmdfe-2.0/init.h (modified) (4 diffs)
- branches/dmdfe-2.0/interpret.c (modified) (12 diffs)
- branches/dmdfe-2.0/lexer.c (modified) (6 diffs)
- branches/dmdfe-2.0/lexer.h (modified) (2 diffs)
- branches/dmdfe-2.0/link.c (modified) (1 diff)
- branches/dmdfe-2.0/mars.c (modified) (5 diffs)
- branches/dmdfe-2.0/mars.h (modified) (1 diff)
- branches/dmdfe-2.0/mtype.c (modified) (6 diffs)
- branches/dmdfe-2.0/mtype.h (modified) (1 diff)
- branches/dmdfe-2.0/opover.c (modified) (1 diff)
- branches/dmdfe-2.0/optimize.c (modified) (10 diffs)
- branches/dmdfe-2.0/parse.c (modified) (5 diffs)
- branches/dmdfe-2.0/parse.h (modified) (1 diff)
- branches/dmdfe-2.0/statement.c (modified) (5 diffs)
- branches/dmdfe-2.0/staticassert.c (modified) (1 diff)
- branches/dmdfe-2.0/template.c (modified) (2 diffs)
- branches/dmdfe-2.0/toobj.c (modified) (9 diffs)
- branches/dmdfe-2.0/traits.c (modified) (3 diffs)
- branches/dmdfe-2.0/typinf.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe-2.0/aggregate.h
r656 r835 149 149 }; 150 150 151 #define CLASSINFO_SIZE (0x3C+1 2) // value of ClassInfo.size151 #define CLASSINFO_SIZE (0x3C+16) // value of ClassInfo.size 152 152 153 153 struct ClassDeclaration : AggregateDeclaration … … 193 193 194 194 Dsymbol *search(Loc, Identifier *ident, int flags); 195 int isFuncHidden(FuncDeclaration *fd); 195 196 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); 196 197 void interfaceSemantic(Scope *sc); branches/dmdfe-2.0/cast.c
r783 r835 96 96 toChars(), type->toChars(), t->toChars()); 97 97 #endif 98 //static int nest; if (++nest == 10) halt(); 98 99 if (!type) 99 100 { error("%s is not an expression", toChars()); … … 101 102 } 102 103 Expression *e = optimize(WANTvalue | WANTflags); 104 if (e->type == t) 105 return MATCHexact; 103 106 if (e != this) 104 { //printf("optim zed to %s\n", e->toChars());107 { //printf("optimized to %s\n", e->toChars()); 105 108 return e->implicitConvTo(t); 106 109 } … … 593 596 toChars(), type->toChars(), t->toChars()); 594 597 #endif 598 if (type == t) 599 return this; 595 600 e = this; 596 601 tb = t->toBasetype(); … … 693 698 Expression *StringExp::castTo(Scope *sc, Type *t) 694 699 { 700 /* This follows copy-on-write; any changes to 'this' 701 * will result in a copy. 702 * The this->string member is considered immutable. 703 */ 695 704 StringExp *se; 696 705 Type *tb; 697 int unique;706 int copied = 0; 698 707 699 708 //printf("StringExp::castTo(t = %s), '%s' committed = %d\n", t->toChars(), toChars(), committed); … … 702 711 { 703 712 error("cannot convert string literal to void*"); 713 } 714 715 se = this; 716 if (!committed) 717 { se = (StringExp *)copy(); 718 se->committed = 1; 719 copied = 1; 720 } 721 722 if (type == t) 723 { 724 return se; 704 725 } 705 726 … … 709 730 return Expression::castTo(sc, t); 710 731 711 se = this; 712 unique = 0; 713 if (!committed) 714 { 715 // Copy when committing the type 716 void *s; 717 718 s = (unsigned char *)mem.malloc((len + 1) * sz); 719 memcpy(s, string, (len + 1) * sz); 720 se = new StringExp(loc, s, len); 721 se->type = type; 722 se->sz = sz; 723 se->committed = 0; 724 unique = 1; // this is the only instance 725 } 726 se->type = type->toBasetype(); 727 if (tb == se->type) 728 { se->type = t; 729 se->committed = 1; 732 Type *typeb = type->toBasetype(); 733 if (typeb == tb) 734 { 735 if (!copied) 736 { se = (StringExp *)copy(); 737 copied = 1; 738 } 739 se->type = t; 730 740 return se; 731 741 } 732 742 733 743 if (tb->ty != Tsarray && tb->ty != Tarray && tb->ty != Tpointer) 734 { se->committed = 1; 744 { if (!copied) 745 { se = (StringExp *)copy(); 746 copied = 1; 747 } 735 748 goto Lcast; 736 749 } 737 if (se->type->ty != Tsarray && se->type->ty != Tarray && se->type->ty != Tpointer) 738 { se->committed = 1; 750 if (typeb->ty != Tsarray && typeb->ty != Tarray && typeb->ty != Tpointer) 751 { if (!copied) 752 { se = (StringExp *)copy(); 753 copied = 1; 754 } 739 755 goto Lcast; 740 756 } 741 757 742 if (se->committed == 1) 743 { 744 if (se->type->nextOf()->size() == tb->nextOf()->size()) 745 { se->type = t; 746 return se; 747 } 758 if (typeb->nextOf()->size() == tb->nextOf()->size()) 759 { 760 if (!copied) 761 { se = (StringExp *)copy(); 762 copied = 1; 763 } 764 if (tb->ty == Tsarray) 765 goto L2; // handle possible change in static array dimension 766 se->type = t; 767 return se; 768 } 769 770 if (committed) 748 771 goto Lcast; 749 }750 751 se->committed = 1;752 753 int tfty;754 int ttty;755 char *p;756 size_t u;757 unsigned c;758 size_t newlen;759 772 760 773 #define X(tf,tt) ((tf) * 256 + (tt)) 761 774 { 762 775 OutBuffer buffer; 763 newlen = 0;764 tfty = se->type->nextOf()->toBasetype()->ty;765 ttty = tb->nextOf()->toBasetype()->ty;776 size_t newlen = 0; 777 int tfty = typeb->nextOf()->toBasetype()->ty; 778 int ttty = tb->nextOf()->toBasetype()->ty; 766 779 switch (X(tfty, ttty)) 767 780 { … … 772 785 773 786 case X(Tchar, Twchar): 774 for ( u = 0; u < len;)775 { 776 p = utf_decodeChar((unsigned char *)se->string, len, &u, &c);787 for (size_t u = 0; u < len;) 788 { unsigned c; 789 char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 777 790 if (p) 778 791 error("%s", p); … … 785 798 786 799 case X(Tchar, Tdchar): 787 for ( u = 0; u < len;)788 { 789 p = utf_decodeChar((unsigned char *)se->string, len, &u, &c);800 for (size_t u = 0; u < len;) 801 { unsigned c; 802 char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 790 803 if (p) 791 804 error("%s", p); … … 797 810 798 811 case X(Twchar,Tchar): 799 for ( u = 0; u < len;)800 { 801 p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);812 for (size_t u = 0; u < len;) 813 { unsigned c; 814 char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 802 815 if (p) 803 816 error("%s", p); … … 810 823 811 824 case X(Twchar,Tdchar): 812 for ( u = 0; u < len;)813 { 814 p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);825 for (size_t u = 0; u < len;) 826 { unsigned c; 827 char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 815 828 if (p) 816 829 error("%s", p); … … 822 835 823 836 case X(Tdchar,Tchar): 824 for ( u = 0; u < len; u++)825 { 826 c = ((unsigned *)se->string)[u];837 for (size_t u = 0; u < len; u++) 838 { 839 unsigned c = ((unsigned *)se->string)[u]; 827 840 if (!utf_isValidDchar(c)) 828 841 error("invalid UCS-32 char \\U%08x", c); … … 836 849 837 850 case X(Tdchar,Twchar): 838 for ( u = 0; u < len; u++)839 { 840 c = ((unsigned *)se->string)[u];851 for (size_t u = 0; u < len; u++) 852 { 853 unsigned c = ((unsigned *)se->string)[u]; 841 854 if (!utf_isValidDchar(c)) 842 855 error("invalid UCS-32 char \\U%08x", c); … … 850 863 851 864 L1: 852 if (!unique) 853 se = new StringExp(loc, NULL, 0); 865 if (!copied) 866 { se = (StringExp *)copy(); 867 copied = 1; 868 } 854 869 se->string = buffer.extractData(); 855 870 se->len = newlen; … … 858 873 859 874 default: 860 if (se->type->nextOf()->size() == tb->nextOf()->size()) 861 { se->type = t; 862 return se; 863 } 875 assert(typeb->nextOf()->size() != tb->nextOf()->size()); 864 876 goto Lcast; 865 877 } 866 878 } 867 879 #undef X 880 L2: 881 assert(copied); 868 882 869 883 // See if need to truncate or extend the literal … … 877 891 if (dim2 != se->len) 878 892 { 893 // Copy when changing the string literal 879 894 unsigned newsz = se->sz; 880 881 if (unique && dim2 < se->len) 882 { se->len = dim2; 883 // Add terminating 0 884 memset((unsigned char *)se->string + dim2 * newsz, 0, newsz); 885 } 886 else 887 { 888 // Copy when changing the string literal 889 void *s; 890 int d; 891 892 d = (dim2 < se->len) ? dim2 : se->len; 893 s = (unsigned char *)mem.malloc((dim2 + 1) * newsz); 894 memcpy(s, se->string, d * newsz); 895 // Extend with 0, add terminating 0 896 memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz); 897 se = new StringExp(loc, s, dim2); 898 se->committed = 1; // it now has a firm type 899 se->sz = newsz; 900 } 895 void *s; 896 int d; 897 898 d = (dim2 < se->len) ? dim2 : se->len; 899 s = (unsigned char *)mem.malloc((dim2 + 1) * newsz); 900 memcpy(s, se->string, d * newsz); 901 // Extend with 0, add terminating 0 902 memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz); 903 se->string = s; 904 se->len = dim2; 901 905 } 902 906 } … … 906 910 Lcast: 907 911 Expression *e = new CastExp(loc, se, t); 908 e->type = t; 912 e->type = t; // so semantic() won't be run on e 909 913 return e; 910 914 } … … 967 971 Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t) 968 972 { 973 #if 0 974 printf("ArrayLiteralExp::castTo(this=%s, type=%s, t=%s)\n", 975 toChars(), type->toChars(), t->toChars()); 976 #endif 977 if (type == t) 978 return this; 969 979 Type *typeb = type->toBasetype(); 970 980 Type *tb = t->toBasetype(); … … 1154 1164 Type *t = Type::tptrdiff_t; 1155 1165 1156 stride = t1b->nextOf()->size( );1166 stride = t1b->nextOf()->size(loc); 1157 1167 if (!t->equals(t2b)) 1158 1168 e2 = e2->castTo(sc, t); … … 1167 1177 Expression *e; 1168 1178 1169 stride = t2b->nextOf()->size( );1179 stride = t2b->nextOf()->size(loc); 1170 1180 if (!t->equals(t1b)) 1171 1181 e = e1->castTo(sc, t); branches/dmdfe-2.0/class.c
r783 r835 1 1 2 2 // Compiler implementation of the D programming language 3 // Copyright (c) 1999-200 6by Digital Mars3 // Copyright (c) 1999-2007 by Digital Mars 4 4 // All Rights Reserved 5 5 // written by Walter Bright … … 767 767 } 768 768 769 /********************************************************** 770 * fd is in the vtbl[] for this class. 771 * Return 1 if function is hidden (not findable through search). 772 */ 773 774 int isf(void *param, FuncDeclaration *fd) 775 { 776 //printf("param = %p, fd = %p %s\n", param, fd, fd->toChars()); 777 return param == fd; 778 } 779 780 int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) 781 { 782 //printf("ClassDeclaration::isFuncHidden(%s)\n", fd->toChars()); 783 Dsymbol *s = search(0, fd->ident, 4|2); 784 if (!s) 785 { //printf("not found\n"); 786 /* Because, due to a hack, if there are multiple definitions 787 * of fd->ident, NULL is returned. 788 */ 789 return 0; 790 } 791 FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration(); 792 //printf("%s fdstart = %p\n", s->kind(), fdstart); 793 return !overloadApply(fdstart, &isf, fd); 794 } 795 769 796 /**************** 770 797 * Find virtual function matching identifier and type. branches/dmdfe-2.0/constfold.c
r783 r835 669 669 assert(op == TOKequal || op == TOKnotequal); 670 670 671 if (e1->op == TOKstring && e2->op == TOKstring) 671 if (e1->op == TOKnull) 672 { 673 if (e2->op == TOKnull) 674 cmp = 1; 675 else if (e2->op == TOKstring) 676 { StringExp *es2 = (StringExp *)e2; 677 cmp = (0 == es2->len); 678 } 679 else if (e2->op == TOKarrayliteral) 680 { ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; 681 cmp = !es2->elements || (0 == es2->elements->dim); 682 } 683 else 684 return EXP_CANT_INTERPRET; 685 } 686 else if (e2->op == TOKnull) 687 { 688 if (e1->op == TOKstring) 689 { StringExp *es1 = (StringExp *)e1; 690 cmp = (0 == es1->len); 691 } 692 else if (e1->op == TOKarrayliteral) 693 { ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; 694 cmp = !es1->elements || (0 == es1->elements->dim); 695 } 696 else 697 return EXP_CANT_INTERPRET; 698 } 699 else if (e1->op == TOKstring && e2->op == TOKstring) 672 700 { StringExp *es1 = (StringExp *)e1; 673 701 StringExp *es2 = (StringExp *)e2; … … 793 821 int cmp; 794 822 795 if (e1->op == TOKsymoff && e2->op == TOKsymoff) 823 if (e1->op == TOKnull && e2->op == TOKnull) 824 { 825 cmp = 1; 826 } 827 else if (e1->op == TOKsymoff && e2->op == TOKsymoff) 796 828 { 797 829 SymOffExp *es1 = (SymOffExp *)e1; … … 1055 1087 else 1056 1088 { 1057 error( "cannot cast %s to %s", e1->type->toChars(), type->toChars());1089 error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars()); 1058 1090 e = new IntegerExp(loc, 0, type); 1059 1091 } … … 1252 1284 //printf("\tt1 = %s, t2 = %s\n", t1->toChars(), t2->toChars()); 1253 1285 1254 if (e1->op == TOKnull && e2->op == TOKint64)1286 if (e1->op == TOKnull && (e2->op == TOKint64 || e2->op == TOKstructliteral)) 1255 1287 { e = e2; 1256 1288 goto L2; 1257 1289 } 1258 else if ( e1->op == TOKint64&& e2->op == TOKnull)1290 else if ((e1->op == TOKint64 || e1->op == TOKstructliteral) && e2->op == TOKnull) 1259 1291 { e = e1; 1260 1292 L2: branches/dmdfe-2.0/declaration.c
r783 r835 649 649 { 650 650 //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 651 //printf(" type = %s\n", type->toChars());651 //printf(" type = %s\n", type->toChars()); 652 652 //printf("linkage = %d\n", sc->linkage); 653 653 //if (strcmp(toChars(), "mul") == 0) halt(); … … 841 841 if (type->ty == Tstruct && 842 842 ((TypeStruct *)type)->sym->zeroInit == 1) 843 { 843 { /* If a struct is all zeros, as a special case 844 * set it's initializer to the integer 0. 845 * In AssignExp::toElem(), we check for this and issue 846 * a memset() to initialize the struct. 847 * Must do same check in interpreter. 848 */ 844 849 Expression *e = new IntegerExp(loc, 0, Type::tint32); 845 850 Expression *e1; 846 851 e1 = new VarExp(loc, this); 847 852 e = new AssignExp(loc, e1, e); 848 e->type = e1->type; 849 init = new ExpInitializer(loc, e /*->type->defaultInit()*/);853 e->type = e1->type; // don't type check this, it would fail 854 init = new ExpInitializer(loc, e); 850 855 return; 851 856 } … … 871 876 { 872 877 ArrayInitializer *ai = init->isArrayInitializer(); 873 if (ai && t ype->toBasetype()->ty == Taarray)878 if (ai && tb->ty == Taarray) 874 879 { 875 880 init = ai->toAssocArrayInitializer(); 876 881 } 877 882 883 StructInitializer *si = init->isStructInitializer(); 878 884 ExpInitializer *ei = init->isExpInitializer(); 879 885 … … 965 971 */ 966 972 967 if ( ei &&!global.errors && !inferred)973 if (!global.errors && !inferred) 968 974 { 969 975 unsigned errors = global.errors; 970 976 global.gag++; 971 977 //printf("+gag\n"); 972 Expression *e = ei->exp->syntaxCopy(); 978 Expression *e; 979 Initializer *i2 = init; 973 980 inuse++; 974 e = e->semantic(sc); 981 if (ei) 982 { 983 e = ei->exp->syntaxCopy(); 984 e = e->semantic(sc); 985 e = e->implicitCastTo(sc, type); 986 } 987 else if (si || ai) 988 { i2 = init->syntaxCopy(); 989 i2 = i2->semantic(sc, type); 990 } 975 991 inuse--; 976 e = e->implicitCastTo(sc, type);977 992 global.gag--; 978 993 //printf("-gag\n"); … … 982 997 global.errors = errors; // act as if nothing happened 983 998 } 984 else 999 else if (ei) 985 1000 { 986 1001 e = e->optimize(WANTvalue | WANTinterpret); … … 990 1005 } 991 1006 } 1007 else 1008 init = i2; // no errors, keep result 992 1009 } 993 1010 } branches/dmdfe-2.0/declaration.h
r783 r835 422 422 // this one is overriding 423 423 int inferRetType; // !=0 if return type is to be inferred 424 Scope *scope; // !=NULL means context to use424 Scope *scope; // !=NULL means context to use 425 425 426 426 // Things that should really go into Scope branches/dmdfe-2.0/dsymbol.c
r783 r835 266 266 * flags: 1 don't find private members 267 267 * 2 don't give error messages 268 * 4 return NULL if ambiguous 268 269 * Returns: 269 270 * NULL if not found … … 664 665 ) 665 666 { 667 if (flags & 4) 668 return NULL; 666 669 if (!(flags & 2)) 667 670 ss->multiplyDefined(loc, s, s2); … … 776 779 777 780 781 /******************************************* 782 * Look for member of the form: 783 * const(MemberInfo)[] getMembers(string); 784 * Returns NULL if not found 785 */ 786 787 #if V2 788 FuncDeclaration *ScopeDsymbol::findGetMembers() 789 { 790 Dsymbol *s = search_function(this, Id::getmembers); 791 FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; 792 793 #if 0 // Finish 794 static TypeFunction *tfgetmembers; 795 796 if (!tfgetmembers) 797 { 798 Scope sc; 799 Arguments *arguments = new Arguments; 800 Arguments *arg = new Argument(STCin, Type::tchar->constOf()->arrayOf(), NULL, NULL); 801 arguments->push(arg); 802 803 Type *tret = NULL; 804 tfgetmembers = new TypeFunction(arguments, tret, 0, LINKd); 805 tfgetmembers = (TypeFunction *)tfgetmembers->semantic(0, &sc); 806 } 807 if (fdx) 808 fdx = fdx->overloadExactMatch(tfgetmembers); 809 #endif 810 if (fdx && fdx->isVirtual()) 811 fdx = NULL; 812 813 return fdx; 814 } 815 #endif 816 817 778 818 /****************************** WithScopeSymbol ******************************/ 779 819 … … 873 913 { 874 914 VarDeclaration *v = new VarDeclaration(loc, Type::tsize_t, Id::dollar, NULL); 915 916 if (ce->op == TOKvar) 917 { // if ce is const, get its initializer 918 ce = fromConstInitializer(WANTvalue | WANTinterpret, ce); 919 } 875 920 876 921 if (ce->op == TOKstring) branches/dmdfe-2.0/dsymbol.h
r458 r835 227 227 Dsymbol *nameCollision(Dsymbol *s); 228 228 char *kind(); 229 FuncDeclaration *findGetMembers(); 229 230 230 231 void emitMemberComments(Scope *sc); branches/dmdfe-2.0/enum.c
r656 r835 104 104 assert(e->dyncast() == DYNCAST_EXPRESSION); 105 105 e = e->semantic(sce); 106 e = e->optimize(WANTvalue );106 e = e->optimize(WANTvalue | WANTinterpret); 107 107 // Need to copy it because we're going to change the type 108 108 e = e->copy(); 109 109 e = e->implicitCastTo(sc, memtype); 110 e = e->optimize(WANTvalue );110 e = e->optimize(WANTvalue | WANTinterpret); 111 111 number = e->toInteger(); 112 112 e->type = t; branches/dmdfe-2.0/expression.c
r783 r835 635 635 { Expression *arg = (Expression *)arguments->data[i]; 636 636 637 if (i)638 buf->writeByte(',');639 637 if (arg) 638 { if (i) 639 buf->writeByte(','); 640 640 expToCBuffer(buf, hgs, arg, PREC_assign); 641 } 641 642 } 642 643 } … … 1100 1101 1101 1102 default: 1102 print();1103 1103 type->print(); 1104 1104 assert(0); … … 1683 1683 else 1684 1684 { 1685 //printf("test1 %s\n", s->toChars());1686 1685 e = new DsymbolExp(loc, s); 1687 1686 } … … 1800 1799 } 1801 1800 } 1801 #if 0 1802 1802 if ((v->isConst() || v->isInvariant()) && type->toBasetype()->ty != Tsarray) 1803 1803 { // Replace v with its initializer … … 1828 1828 } 1829 1829 } 1830 #endif 1830 1831 e = new VarExp(loc, v); 1831 1832 e->type = type; … … 3556 3557 if (v) 3557 3558 { 3559 #if 0 3558 3560 if ((v->isConst() || v->isInvariant()) && 3559 3561 type->toBasetype()->ty != Tsarray && v->init) … … 3566 3568 } 3567 3569 } 3570 #endif 3568 3571 v->checkNestedReference(sc, loc); 3569 3572 } … … 4028 4031 /************************************************************/ 4029 4032 4030 I ftypeExp::IftypeExp(Loc loc, Type *targ, Identifier *id, enum TOK tok,4031 Type *tspec, enum TOK tok2 )4032 : Expression(loc, TOKis, sizeof(I ftypeExp))4033 IsExp::IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, 4034 Type *tspec, enum TOK tok2, TemplateParameters *parameters) 4035 : Expression(loc, TOKis, sizeof(IsExp)) 4033 4036 { 4034 4037 this->targ = targ; … … 4037 4040 this->tspec = tspec; 4038 4041 this->tok2 = tok2; 4039 } 4040 4041 Expression *IftypeExp::syntaxCopy() 4042 { 4043 return new IftypeExp(loc, 4042 this->parameters = parameters; 4043 } 4044 4045 Expression *IsExp::syntaxCopy() 4046 { 4047 // This section is identical to that in TemplateDeclaration::syntaxCopy() 4048 TemplateParameters *p = NULL; 4049 if (parameters) 4050 { 4051 p = new TemplateParameters(); 4052 p->setDim(parameters->dim); 4053 for (int i = 0; i < p->dim; i++) 4054 { TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; 4055 p->data[i] = (void *)tp->syntaxCopy(); 4056 } 4057 } 4058 4059 return new IsExp(loc, 4044 4060 targ->syntaxCopy(), 4045 4061 id, 4046 4062 tok, 4047 4063 tspec ? tspec->syntaxCopy() : NULL, 4048 tok2); 4049 } 4050 4051 Expression *IftypeExp::semantic(Scope *sc) 4064 tok2, 4065 p); 4066 } 4067 4068 Expression *IsExp::semantic(Scope *sc) 4052 4069 { Type *tded; 4053 4070 4054 //printf("IftypeExp::semantic()\n"); 4071 /* is(targ id tok tspec) 4072 * is(targ id == tok2) 4073 */ 4074 4075 //printf("IsExp::semantic(%s)\n", toChars()); 4055 4076 if (id && !(sc->flags & SCOPEstaticif)) 4056 4077 error("can only declare type aliases within static if conditionals"); … … 4139 4160 4140 4161 case TOKfunction: 4141 { if (targ->ty != Tfunction) 4162 { 4163 if (targ->ty != Tfunction) 4142 4164 goto Lno; 4143 4165 tded = targ; … … 4189 4211 4190 4212 MATCH m; 4191 TemplateTypeParameter tp(loc, id, NULL, NULL); 4192 4193 TemplateParameters parameters; 4194 parameters.setDim(1); 4195 parameters.data[0] = (void *)&tp; 4213 assert(parameters && parameters->dim); 4196 4214 4197 4215 Objects dedtypes; 4198 dedtypes.setDim( 1);4199 dedtypes. data[0] = NULL;4200 4201 m = targ->deduceType(NULL, tspec, ¶meters, &dedtypes);4216 dedtypes.setDim(parameters->dim); 4217 dedtypes.zero(); 4218 4219 m = targ->deduceType(NULL, tspec, parameters, &dedtypes); 4202 4220 if (m == MATCHnomatch || 4203 4221 (m != MATCHexact && tok == TOKequal)) … … 4205 4223 else 4206 4224 { 4207 assert(dedtypes.dim == 1);4208 4225 tded = (Type *)dedtypes.data[0]; 4209 4226 if (!tded) 4210 4227 tded = targ; 4228 4229 Objects tiargs; 4230 tiargs.setDim(1); 4231 tiargs.data[0] = (void *)targ; 4232 4233 for (int i = 1; i < parameters->dim; i++) 4234 { TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; 4235 Declaration *s; 4236 4237 m = tp->matchArg(sc, &tiargs, i, parameters, &dedtypes, &s); 4238 if (m == MATCHnomatch) 4239 goto Lno; 4240 s->semantic(sc); 4241 if (!sc->insert(s)) 4242 error("declaration %s is already defined", s->toChars()); 4243 #if 0 4244 Object *o = (Object *)dedtypes.data[i]; 4245 Dsymbol *s = TemplateDeclaration::declareParameter(loc, sc, tp, o); 4246 #endif 4247 if (sc->sd) 4248 s->addMember(sc, sc->sd, 1); 4249 } 4250 4211 4251 goto Lyes; 4212 4252 } … … 4245 4285 Dsymbol *s = new AliasDeclaration(loc, id, tded); 4246 4286 s->semantic(sc); 4247 sc->insert(s); 4287 if (!sc->insert(s)) 4288 error("declaration %s is already defined", s->toChars()); 4248 4289 if (sc->sd) 4249 4290 s->addMember(sc, sc->sd, 1); 4250 4291 } 4251 return new IntegerExp( 1);4292 return new IntegerExp(loc, 1, Type::tbool); 4252 4293 4253 4294 Lno: 4254 return new IntegerExp( 0);4255 } 4256 4257 void I ftypeExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs)4295 return new IntegerExp(loc, 0, Type::tbool); 4296 } 4297 4298 void IsExp::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 4258 4299 { 4259 4300 buf->writestring("is("); 4260 4301 targ->toCBuffer(buf, id, hgs); 4261 if (tspec) 4302 if (tok2 != TOKreserved) 4303 { 4304 buf->printf(" %s %s", Token::toChars(tok), Token::toChars(tok2)); 4305 } 4306 else if (tspec) 4262 4307 { 4263 4308 if (tok == TOKcolon) … … 4266 4311 buf->writestring(" == "); 4267 4312 tspec->toCBuffer(buf, NULL, hgs); 4313 } 4314 if (parameters) 4315 { // First parameter is already output, so start with second 4316 for (int i = 1; i < parameters->dim; i++) 4317 { 4318 buf->writeByte(','); 4319 TemplateParameter *tp = (TemplateParameter *)parameters->data[i]; 4320 tp->toCBuffer(buf, hgs); 4321 } 4268 4322 } 4269 4323 buf->writeByte(')'); … … 4757 4811 } 4758 4812 type = v->type; 4813 #if 0 4759 4814 if (v->isConst() || v->isInvariant()) 4760 4815 { … … 4781 4836 } 4782 4837 } 4838 #endif 4783 4839 if (v->needThis()) 4784 4840 { … … 5521 5577 if (search_function(ad, Id::call)) 5522 5578 goto L1; // overload of opCall, therefore it's a call 5579 5580 if (e1->op != TOKtype) 5581 error("%s %s does not overload ()", ad->kind(), ad->toChars()); 5523 5582 /* It's a struct literal 5524 5583 */ … … 6881 6940 { 6882 6941 e2 = e2->implicitCastTo(sc, Type::tsize_t); 6883 e2 = e2->optimize(WANTvalue );6942 e2 = e2->optimize(WANTvalue | WANTinterpret); 6884 6943 uinteger_t index = e2->toUInteger(); 6885 6944 size_t length; branches/dmdfe-2.0/expression.h
r783 r835 61 61 Expression *resolveProperties(Scope *sc, Expression *e); 62 62 void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d); 63 Dsymbol *search_function( AggregateDeclaration*ad, Identifier *funcid);63 Dsymbol *search_function(ScopeDsymbol *ad, Identifier *funcid); 64 64 void inferApplyArgTypes(enum TOK op, Arguments *arguments, Expression *aggr); 65 65 void argExpTypesToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs); … … 67 67 void expandTuples(Expressions *exps); 68 68 FuncDeclaration *hasThis(Scope *sc); 69 Expression *fromConstInitializer(int result, Expression *e); 69 70 70 71 struct Expression : Object … … 602 603 }; 603 604 604 struct I ftypeExp : Expression605 struct IsExp : Expression 605 606 { 606 607 /* is(targ id tok tspec) … … 612 613 Type *tspec; // can be NULL 613 614 enum TOK tok2; // 'struct', 'union', 'typedef', etc. 614 615 IftypeExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec, enum TOK tok2); 615 TemplateParameters *parameters; 616 617 IsExp(Loc loc, Type *targ, Identifier *id, enum TOK tok, Type *tspec, 618 enum TOK tok2, TemplateParameters *parameters); 616 619 Expression *syntaxCopy(); 617 620 Expression *semantic(Scope *sc); branches/dmdfe-2.0/func.c
r783 r835 254 254 { 255 255 //printf("\tnot virtual\n"); 256 return;256 goto Ldone; 257 257 } 258 258 … … 284 284 if (fdv->isFinal()) 285 285 error("cannot override final function %s", fdv->toPrettyChars()); 286 287 if (!isOverride() && global.params.warnings) 288 error("overrides base class function %s, but is not marked with 'override'", fdv->toPrettyChars()); 289 286 290 if (fdv->toParent() == parent) 287 291 { … … 433 437 if (introducing && isOverride()) 434 438 { 435 error(" function %s does not override any", toChars());439 error("does not override any function"); 436 440 } 437 441 … … 525 529 } 526 530 531 Ldone: 527 532 /* Save scope for possible later use (if we need the 528 533 * function internals) … … 2114 2119 2115 2120 StaticCtorDeclaration::StaticCtorDeclaration(Loc loc, Loc endloc) 2116 : FuncDeclaration(loc, endloc, Id::staticCtor, STCstatic, NULL) 2121 : FuncDeclaration(loc, endloc, 2122 Identifier::generateId("_staticCtor"), STCstatic, NULL) 2117 <
