Changeset 840
- Timestamp:
- 11/17/07 18:52:40 (10 months ago)
- Files:
-
- trunk/docs/ChangeLog (modified) (1 diff)
- trunk/rebuild/aggregate.h (modified) (6 diffs)
- trunk/rebuild/cast.c (modified) (31 diffs)
- trunk/rebuild/class.c (modified) (18 diffs)
- trunk/rebuild/constfold.c (modified) (6 diffs)
- trunk/rebuild/declaration.c (modified) (15 diffs)
- trunk/rebuild/declaration.h (modified) (11 diffs)
- trunk/rebuild/dsymbol.c (modified) (18 diffs)
- trunk/rebuild/dsymbol.h (modified) (6 diffs)
- trunk/rebuild/enum.c (modified) (1 diff)
- trunk/rebuild/expression.c (modified) (49 diffs)
- trunk/rebuild/expression.h (modified) (18 diffs)
- trunk/rebuild/func.c (modified) (17 diffs)
- trunk/rebuild/identifier.c (modified) (2 diffs)
- trunk/rebuild/idgen.c (modified) (6 diffs)
- trunk/rebuild/inifile.c (modified) (2 diffs)
- trunk/rebuild/init.c (modified) (2 diffs)
- trunk/rebuild/init.h (modified) (4 diffs)
- trunk/rebuild/inline.c (modified) (5 diffs)
- trunk/rebuild/interpret.c (modified) (13 diffs)
- trunk/rebuild/lexer.c (modified) (7 diffs)
- trunk/rebuild/lexer.h (modified) (2 diffs)
- trunk/rebuild/mangle.c (modified) (4 diffs)
- trunk/rebuild/mars.c (modified) (4 diffs)
- trunk/rebuild/mars.h (modified) (1 diff)
- trunk/rebuild/mtype.c (modified) (45 diffs)
- trunk/rebuild/mtype.h (modified) (19 diffs)
- trunk/rebuild/opover.c (modified) (2 diffs)
- trunk/rebuild/optimize.c (modified) (13 diffs)
- trunk/rebuild/parse.c (modified) (8 diffs)
- trunk/rebuild/parse.h (modified) (1 diff)
- trunk/rebuild/statement.c (modified) (13 diffs)
- trunk/rebuild/statement.h (modified) (2 diffs)
- trunk/rebuild/staticassert.c (modified) (1 diff)
- trunk/rebuild/template.c (modified) (33 diffs)
- trunk/rebuild/template.h (modified) (3 diffs)
- trunk/rebuild/traits.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/docs/ChangeLog
r831 r840 5 5 - DSSS no longer builds libraries or performs incremental compilation 6 6 with DMD, as neither of these build strategies is supportable. 7 - Rebuild: Merged DMD 2.007. 7 8 8 9 0.73 from 0.72: trunk/rebuild/aggregate.h
r660 r840 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 … … 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 … … 176 176 177 177 ClassInfoDeclaration *vclassinfo; // the ClassInfo object for this ClassDeclaration 178 int com; // !=0 if this is a COM class 178 int com; // !=0 if this is a COM class (meaning 179 // it derives from IUnknown) 179 180 int isauto; // !=0 if this is an auto class 180 181 int isabstract; // !=0 if abstract class … … 193 194 194 195 Dsymbol *search(Loc, Identifier *ident, int flags); 196 int isFuncHidden(FuncDeclaration *fd); 195 197 FuncDeclaration *findFunc(Identifier *ident, TypeFunction *tf); 196 198 void interfaceSemantic(Scope *sc); 197 199 int isNested(); 198 200 int isCOMclass(); 201 virtual int isCOMinterface(); 202 virtual int isCPPinterface(); 199 203 int isAbstract(); 200 204 virtual int vtblOffset(); … … 220 224 struct InterfaceDeclaration : ClassDeclaration 221 225 { 226 int cpp; // !=0 if this is a C++ interface 227 222 228 InterfaceDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); 223 229 Dsymbol *syntaxCopy(Dsymbol *s); … … 227 233 char *kind(); 228 234 int vtblOffset(); 235 int isCPPinterface(); 236 virtual int isCOMinterface(); 229 237 230 238 InterfaceDeclaration *isInterfaceDeclaration() { return this; } trunk/rebuild/cast.c
r785 r840 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 } … … 481 484 { 482 485 // Look for pointers to functions where the functions are overloaded. 483 VarExp *ve;484 FuncDeclaration *f;485 486 486 487 t = t->toBasetype(); 488 489 if (e1->op == TOKoverloadset && 490 (t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction) 491 { OverExp *eo = (OverExp *)e1; 492 FuncDeclaration *f = NULL; 493 for (int i = 0; i < eo->vars->a.dim; i++) 494 { Dsymbol *s = (Dsymbol *)eo->vars->a.data[i]; 495 FuncDeclaration *f2 = s->isFuncDeclaration(); 496 assert(f2); 497 if (f2->overloadExactMatch(t->nextOf())) 498 { if (f) 499 /* Error if match in more than one overload set, 500 * even if one is a 'better' match than the other. 501 */ 502 ScopeDsymbol::multiplyDefined(loc, f, f2); 503 else 504 f = f2; 505 result = MATCHexact; 506 } 507 } 508 } 509 487 510 if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 488 511 t->ty == Tpointer && t->nextOf()->ty == Tfunction && … … 494 517 */ 495 518 assert(0); 496 ve = (VarExp *)e1;497 f = ve->var->isFuncDeclaration();519 VarExp *ve = (VarExp *)e1; 520 FuncDeclaration *f = ve->var->isFuncDeclaration(); 498 521 if (f && f->overloadExactMatch(t->nextOf())) 499 522 result = MATCHexact; … … 593 616 toChars(), type->toChars(), t->toChars()); 594 617 #endif 618 if (type == t) 619 return this; 595 620 e = this; 596 621 tb = t->toBasetype(); … … 693 718 Expression *StringExp::castTo(Scope *sc, Type *t) 694 719 { 720 /* This follows copy-on-write; any changes to 'this' 721 * will result in a copy. 722 * The this->string member is considered immutable. 723 */ 695 724 StringExp *se; 696 725 Type *tb; 697 int unique;726 int copied = 0; 698 727 699 728 //printf("StringExp::castTo(t = %s), '%s' committed = %d\n", t->toChars(), toChars(), committed); … … 703 732 error("cannot convert string literal to void*"); 704 733 } */ 734 735 se = this; 736 if (!committed) 737 { se = (StringExp *)copy(); 738 se->committed = 1; 739 copied = 1; 740 } 741 742 if (type == t) 743 { 744 return se; 745 } 705 746 706 747 tb = t->toBasetype(); … … 709 750 return Expression::castTo(sc, t); 710 751 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; 752 Type *typeb = type->toBasetype(); 753 if (typeb == tb) 754 { 755 if (!copied) 756 { se = (StringExp *)copy(); 757 copied = 1; 758 } 759 se->type = t; 730 760 return se; 731 761 } 732 762 733 763 if (tb->ty != Tsarray && tb->ty != Tarray && tb->ty != Tpointer) 734 { se->committed = 1; 764 { if (!copied) 765 { se = (StringExp *)copy(); 766 copied = 1; 767 } 735 768 goto Lcast; 736 769 } 737 if (se->type->ty != Tsarray && se->type->ty != Tarray && se->type->ty != Tpointer) 738 { se->committed = 1; 770 if (typeb->ty != Tsarray && typeb->ty != Tarray && typeb->ty != Tpointer) 771 { if (!copied) 772 { se = (StringExp *)copy(); 773 copied = 1; 774 } 739 775 goto Lcast; 740 776 } 741 777 742 if (se->committed == 1) 743 { 744 if (se->type->nextOf()->size() == tb->nextOf()->size()) 745 { se->type = t; 746 return se; 747 } 778 if (typeb->nextOf()->size() == tb->nextOf()->size()) 779 { 780 if (!copied) 781 { se = (StringExp *)copy(); 782 copied = 1; 783 } 784 if (tb->ty == Tsarray) 785 goto L2; // handle possible change in static array dimension 786 se->type = t; 787 return se; 788 } 789 790 if (committed) 748 791 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 792 760 793 #define X(tf,tt) ((tf) * 256 + (tt)) 761 794 { 762 795 OutBuffer buffer; 763 newlen = 0;764 tfty = se->type->nextOf()->toBasetype()->ty;765 ttty = tb->nextOf()->toBasetype()->ty;796 size_t newlen = 0; 797 int tfty = typeb->nextOf()->toBasetype()->ty; 798 int ttty = tb->nextOf()->toBasetype()->ty; 766 799 switch (X(tfty, ttty)) 767 800 { … … 772 805 773 806 case X(Tchar, Twchar): 774 for ( u = 0; u < len;)775 { 776 p = utf_decodeChar((unsigned char *)se->string, len, &u, &c);807 for (size_t u = 0; u < len;) 808 { unsigned c; 809 char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 777 810 if (p) 778 811 error("%s", p); … … 785 818 786 819 case X(Tchar, Tdchar): 787 for ( u = 0; u < len;)788 { 789 p = utf_decodeChar((unsigned char *)se->string, len, &u, &c);820 for (size_t u = 0; u < len;) 821 { unsigned c; 822 char *p = utf_decodeChar((unsigned char *)se->string, len, &u, &c); 790 823 if (p) 791 824 error("%s", p); … … 797 830 798 831 case X(Twchar,Tchar): 799 for ( u = 0; u < len;)800 { 801 p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);832 for (size_t u = 0; u < len;) 833 { unsigned c; 834 char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 802 835 if (p) 803 836 error("%s", p); … … 810 843 811 844 case X(Twchar,Tdchar): 812 for ( u = 0; u < len;)813 { 814 p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c);845 for (size_t u = 0; u < len;) 846 { unsigned c; 847 char *p = utf_decodeWchar((unsigned short *)se->string, len, &u, &c); 815 848 if (p) 816 849 error("%s", p); … … 822 855 823 856 case X(Tdchar,Tchar): 824 for ( u = 0; u < len; u++)825 { 826 c = ((unsigned *)se->string)[u];857 for (size_t u = 0; u < len; u++) 858 { 859 unsigned c = ((unsigned *)se->string)[u]; 827 860 if (!utf_isValidDchar(c)) 828 861 error("invalid UCS-32 char \\U%08x", c); … … 836 869 837 870 case X(Tdchar,Twchar): 838 for ( u = 0; u < len; u++)839 { 840 c = ((unsigned *)se->string)[u];871 for (size_t u = 0; u < len; u++) 872 { 873 unsigned c = ((unsigned *)se->string)[u]; 841 874 if (!utf_isValidDchar(c)) 842 875 error("invalid UCS-32 char \\U%08x", c); … … 850 883 851 884 L1: 852 if (!unique) 853 se = new StringExp(loc, NULL, 0); 885 if (!copied) 886 { se = (StringExp *)copy(); 887 copied = 1; 888 } 854 889 se->string = buffer.extractData(); 855 890 se->len = newlen; … … 858 893 859 894 default: 860 if (se->type->nextOf()->size() == tb->nextOf()->size()) 861 { se->type = t; 862 return se; 863 } 895 assert(typeb->nextOf()->size() != tb->nextOf()->size()); 864 896 goto Lcast; 865 897 } 866 898 } 867 899 #undef X 900 L2: 901 assert(copied); 868 902 869 903 // See if need to truncate or extend the literal … … 877 911 if (dim2 != se->len) 878 912 { 913 // Copy when changing the string literal 879 914 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 } 915 void *s; 916 int d; 917 918 d = (dim2 < se->len) ? dim2 : se->len; 919 s = (unsigned char *)mem.malloc((dim2 + 1) * newsz); 920 memcpy(s, se->string, d * newsz); 921 // Extend with 0, add terminating 0 922 memset((char *)s + d * newsz, 0, (dim2 + 1 - d) * newsz); 923 se->string = s; 924 se->len = dim2; 901 925 } 902 926 } … … 906 930 Lcast: 907 931 Expression *e = new CastExp(loc, se, t); 908 e->type = t; 932 e->type = t; // so semantic() won't be run on e 909 933 return e; 910 934 } … … 925 949 { 926 950 // Look for pointers to functions where the functions are overloaded. 927 VarExp *ve; 928 FuncDeclaration *f; 951 952 if (e1->op == TOKoverloadset && 953 (t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction) 954 { OverExp *eo = (OverExp *)e1; 955 FuncDeclaration *f = NULL; 956 for (int i = 0; i < eo->vars->a.dim; i++) 957 { Dsymbol *s = (Dsymbol *)eo->vars->a.data[i]; 958 FuncDeclaration *f2 = s->isFuncDeclaration(); 959 assert(f2); 960 if (f2->overloadExactMatch(t->nextOf())) 961 { if (f) 962 /* Error if match in more than one overload set, 963 * even if one is a 'better' match than the other. 964 */ 965 ScopeDsymbol::multiplyDefined(loc, f, f2); 966 else 967 f = f2; 968 } 969 } 970 if (f) 971 { f->tookAddressOf = 1; 972 SymOffExp *se = new SymOffExp(loc, f, 0, 0); 973 se->semantic(sc); 974 // Let SymOffExp::castTo() do the heavy lifting 975 return se->castTo(sc, t); 976 } 977 } 978 929 979 930 980 if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && … … 932 982 e1->op == TOKvar) 933 983 { 934 ve = (VarExp *)e1;935 f = ve->var->isFuncDeclaration();984 VarExp *ve = (VarExp *)e1; 985 FuncDeclaration *f = ve->var->isFuncDeclaration(); 936 986 if (f) 937 987 { 988 assert(0); // should be SymOffExp instead 938 989 f = f->overloadExactMatch(tb->nextOf()); 939 990 if (f) … … 967 1018 Expression *ArrayLiteralExp::castTo(Scope *sc, Type *t) 968 1019 { 1020 #if 0 1021 printf("ArrayLiteralExp::castTo(this=%s, type=%s, t=%s)\n", 1022 toChars(), type->toChars(), t->toChars()); 1023 #endif 1024 if (type == t) 1025 return this; 969 1026 Type *typeb = type->toBasetype(); 970 1027 Type *tb = t->toBasetype(); … … 1061 1118 e->type = t; 1062 1119 } 1120 f->tookAddressOf = 1; 1063 1121 return e; 1064 1122 } … … 1102 1160 if (f->tintro && f->tintro->nextOf()->isBaseOf(f->type->nextOf(), &offset) && offset) 1103 1161 error("%s", msg); 1162 f->tookAddressOf = 1; 1104 1163 e = new DelegateExp(loc, e1, f); 1105 1164 e->type = t; … … 1115 1174 { int offset; 1116 1175 1176 func->tookAddressOf = 1; 1117 1177 if (func->tintro && func->tintro->nextOf()->isBaseOf(func->type->nextOf(), &offset) && offset) 1118 1178 error("%s", msg); … … 1154 1214 Type *t = Type::tptrdiff_t; 1155 1215 1156 stride = t1b->nextOf()->size( );1216 stride = t1b->nextOf()->size(loc); 1157 1217 if (!t->equals(t2b)) 1158 1218 e2 = e2->castTo(sc, t); … … 1167 1227 Expression *e; 1168 1228 1169 stride = t2b->nextOf()->size( );1229 stride = t2b->nextOf()->size(loc); 1170 1230 if (!t->equals(t1b)) 1171 1231 e = e1->castTo(sc, t); … … 1192 1252 TY ty; 1193 1253 1194 //printf("BinExp::typeCombine() \n");1254 //printf("BinExp::typeCombine() %s\n", toChars()); 1195 1255 //dump(0); 1196 1256 … … 1262 1322 if ((t1->ty == Tsarray || t1->ty == Tarray) && 1263 1323 (t2->ty == Tsarray || t2->ty == Tarray) && 1264 (t1->nextOf()->mod || t2->nextOf()->mod)) 1265 { 1266 t1 = t1->constOf(); 1267 t2 = t2->constOf(); 1324 (t1->nextOf()->mod || t2->nextOf()->mod) && 1325 (t1->nextOf()->mod != t2->nextOf()->mod) 1326 ) 1327 { 1328 t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 1329 t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 1330 //t1 = t1->constOf(); 1331 //t2 = t2->constOf(); 1332 e1 = e1->castTo(sc, t1); 1333 e2 = e2->castTo(sc, t2); 1334 goto Lagain; 1268 1335 } 1269 1336 } … … 1291 1358 else if (t1n->mod != t2n->mod) 1292 1359 { 1293 t1 = t1 ->constOf();1294 t2 = t2 ->constOf();1360 t1 = t1n->mutableOf()->constOf()->pointerTo(); 1361 t2 = t2n->mutableOf()->constOf()->pointerTo(); 1295 1362 goto Lagain; 1296 1363 } … … 1347 1414 ) 1348 1415 { 1349 t1 = t1->constOf(); 1350 t2 = t2->constOf(); 1416 if (t1->ty == Tpointer) 1417 t1 = t1->nextOf()->mutableOf()->constOf()->pointerTo(); 1418 else 1419 t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 1420 1421 if (t2->ty == Tpointer) 1422 t2 = t2->nextOf()->mutableOf()->constOf()->pointerTo(); 1423 else 1424 t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 1351 1425 goto Lagain; 1352 1426 } … … 1420 1494 if (!type) 1421 1495 type = t; 1496 #if 0 1497 printf("-BinExp::typeCombine() %s\n", toChars()); 1498 if (e1->type) printf("\tt1 = %s\n", e1->type->toChars()); 1499 if (e2->type) printf("\tt2 = %s\n", e2->type->toChars()); 1500 printf("\ttype = %s\n", type->toChars()); 1501 #endif 1422 1502 //dump(0); 1423 1503 return this; trunk/rebuild/class.c
r785 r840 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 … … 148 148 } 149 149 150 #if V2 150 151 if (id == Id::TypeInfo_Const) 151 152 { if (Type::typeinfoconst) … … 159 160 Type::typeinfoinvariant = this; 160 161 } 162 #endif 161 163 } 162 164 … … 181 183 182 184 com = 0; 183 #if 0184 if (id == Id::IUnknown) // IUnknown is the root of all COM objects185 com = 1;186 #endif187 185 isauto = 0; 188 186 isabstract = 0; … … 261 259 methods.setDim(0); 262 260 #endif 261 262 if (sc->stc & STCdeprecated) 263 { 264 isdeprecated = 1; 265 } 266 267 if (sc->linkage == LINKcpp) 268 error("cannot create C++ classes"); 263 269 264 270 // Expand any tuples in baseclasses[] … … 299 305 { 300 306 tc = (TypeClass *)(tb); 307 308 if (tc->sym->isDeprecated()) 309 { 310 if (!isDeprecated()) 311 { 312 // Deriving from deprecated class makes this one deprecated too 313 isdeprecated = 1; 314 315 tc->checkDeprecated(loc, sc); 316 } 317 } 318 301 319 if (tc->sym->isInterfaceDeclaration()) 302 320 ; … … 353 371 else 354 372 { 373 if (tc->sym->isDeprecated()) 374 { 375 if (!isDeprecated()) 376 { 377 // Deriving from deprecated class makes this one deprecated too 378 isdeprecated = 1; 379 380 tc->checkDeprecated(loc, sc); 381 } 382 } 383 355 384 // Check for duplicate interfaces 356 385 for (size_t j = (baseClass ? 1 : 0); j < i; j++) … … 493 522 if (storage_class & STCabstract) 494 523 isabstract = 1; 495 if (storage_class & STCdeprecated)496 isdeprecated = 1;497 524 498 525 sc = sc->push(this); … … 767 794 } 768 795 796 /********************************************************** 797 * fd is in the vtbl[] for this class. 798 * Return 1 if function is hidden (not findable through search). 799 */ 800 801 #if V2 802 int isf(void *param, FuncDeclaration *fd) 803 { 804 //printf("param = %p, fd = %p %s\n", param, fd, fd->toChars()); 805 return param == fd; 806 } 807 808 int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) 809 { 810 //printf("ClassDeclaration::isFuncHidden(%s)\n", fd->toChars()); 811 Dsymbol *s = search(0, fd->ident, 4|2); 812 if (!s) 813 { //printf("not found\n"); 814 /* Because, due to a hack, if there are multiple definitions 815 * of fd->ident, NULL is returned. 816 */ 817 return 0; 818 } 819 s = s->toAlias(); 820 OverloadSet *os = s->isOverloadSet(); 821 if (os) 822 { 823 for (int i = 0; i < os->a.dim; i++) 824 { Dsymbol *s = (Dsymbol *)os->a.data[i]; 825 FuncDeclaration *f2 = s->isFuncDeclaration(); 826 if (f2 && overloadApply(f2, &isf, fd)) 827 return 0; 828 } 829 return 1; 830 } 831 else 832 { 833 FuncDeclaration *fdstart = s->isFuncDeclaration(); 834 //printf("%s fdstart = %p\n", s->kind(), fdstart); 835 return !overloadApply(fdstart, &isf, fd); 836 } 837 } 838 #endif 839 769 840 /**************** 770 841 * Find virtual function matching identifier and type. … … 804 875 805 876 void ClassDeclaration::interfaceSemantic(Scope *sc) 806 { int i; 877 { 878 InterfaceDeclaration *id = isInterfaceDeclaration(); 807 879 808 880 vtblInterfaces = new BaseClasses(); 809 881 vtblInterfaces->reserve(interfaces_dim); 810 882 811 for ( i = 0; i < interfaces_dim; i++)883 for (size_t i = 0; i < interfaces_dim; i++) 812 884 { 813 885 BaseClass *b = interfaces[i]; … … 815 887 // If this is an interface, and it derives from a COM interface, 816 888 // then this is a COM interface too. 817 if (b->base->isCOM class())889 if (b->base->isCOMinterface()) 818 890 com = 1; 891 892 if (b->base->isCPPinterface() && id) 893 id->cpp = 1; 819 894 820 895 vtblInterfaces->push(b); … … 829 904 { 830 905 return com; 906 } 907 908 int ClassDeclaration::isCOMinterface() 909 { 910 return 0; 911 } 912 913 int ClassDeclaration::isCPPinterface() 914 { 915 return 0; 831 916 } 832 917 … … 897 982 { 898 983 com = 0; 899 if (id == Id::IUnknown) // IUnknown is the root of all COM objects 900 com = 1; 984 cpp = 0; 985 if (id == Id::IUnknown) // IUnknown is the root of all COM interfaces 986 { com = 1; 987 cpp = 1; // IUnknown is also a C++ interface 988 } 901 989 } 902 990 … … 938 1026 scx = scope; // save so we don't make redundant copies 939 1027 scope = NULL; 1028 } 1029 1030 if (sc->stc & STCdeprecated) 1031 { 1032 isdeprecated = 1; 940 1033 } 941 1034 … … 961 1054 } 962 1055 1056 if (!baseclasses.dim && sc->linkage == LINKcpp) 1057 cpp = 1; 1058 963 1059 // Check for errors, handle forward references 964 1060 for (i = 0; i < baseclasses.dim; ) … … 1057 1153 sc = sc->push(this); 1058 1154 sc->parent = this; 1059 if (isCOM class())1155 if (isCOMinterface()) 1060 1156 sc->linkage = LINKwindows; 1157 else if (isCPPinterface()) 1158 sc->linkage = LINKcpp; 1061 1159 sc->structalign = 8; 1062 1160 structalign = sc->structalign; … … 1147 1245 /**************************************** 1148 1246 * Determine if slot 0 of the vtbl[] is reserved for something else. 1149 * For class objects, yes, this is where the classinfo ptr goes.1247 * For class objects, yes, this is where the ClassInfo ptr goes. 1150 1248 * For COM interfaces, no. 1151 1249 * For non-COM interfaces, yes, this is where the Interface ptr goes. … … 1154 1252 int InterfaceDeclaration::vtblOffset() 1155 1253 { 1156 if (isCOM class())1254 if (isCOMinterface() || isCPPinterface()) 1157 1255 return 0; 1158 1256 return 1; 1257 } 1258 1259 int InterfaceDeclaration::isCOMinterface() 1260 { 1261 return com; 1262 } 1263 1264 int InterfaceDeclaration::isCPPinterface() 1265 { 1266 return cpp; 1159 1267 } 1160 1268 trunk/rebuild/constfold.c
r785 r840 690 690 assert(op == TOKequal || op == TOKnotequal); 691 691 692 if (e1->op == TOKstring && e2->op == TOKstring) 692 if (e1->op == TOKnull) 693 { 694 if (e2->op == TOKnull) 695 cmp = 1; 696 else if (e2->op == TOKstring) 697 { StringExp *es2 = (StringExp *)e2; 698 cmp = (0 == es2->len); 699 } 700 else if (e2->op == TOKarrayliteral) 701 { ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; 702 cmp = !es2->elements || (0 == es2->elements->dim); 703 } 704 else 705 return EXP_CANT_INTERPRET; 706 } 707 else if (e2->op == TOKnull) 708 { 709 if (e1->op == TOKstring) 710 { StringExp *es1 = (StringExp *)e1; 711 cmp = (0 == es1->len); 712 } 713 else if (e1->op == TOKarrayliteral) 714 { ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; 715 cmp = !es1->elements || (0 == es1->elements->dim); 716 } 717 else 718 return EXP_CANT_INTERPRET; 719 } 720 else if (e1->op == TOKstring && e2->op == TOKstring) 693 721 { StringExp *es1 = (StringExp *)e1; 694 722 StringExp *es2 = (StringExp *)e2; … … 722 750 return EXP_CANT_INTERPRET; 723 751 cmp = v->toInteger(); 752 if (cmp == 0) 753 break; 754 } 755 } 756 } 757 else if (e1->op == TOKarrayliteral && e2->op == TOKstring) 758 { // Swap operands and use common code 759 Expression *e = e1; 760 e1 = e2; 761 e2 = e; 762 goto Lsa; 763 } 764 else if (e1->op == TOKstring && e2->op == TOKarrayliteral) 765 { 766 Lsa: 767 StringExp *es1 = (StringExp *)e1; 768 ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; 769 size_t dim1 = es1->len; 770 size_t dim2 = es2->elements ? es2->elements->dim : 0; 771 if (dim1 != dim2) 772 cmp = 0; 773 else 774 { 775 for (size_t i = 0; i < dim1; i++) 776 { 777 uinteger_t c = es1->charAt(i); 778 Expression *ee2 = (Expression *)es2->elements->data[i]; 779 if (ee2->isConst() != 1) 780 return EXP_CANT_INTERPRET; 781 cmp = (c == ee2->toInteger()); 724 782 if (cmp == 0) 725 783 break; … … 814 872 int cmp; 815 873 816 if (e1->op == TOKsymoff && e2->op == TOKsymoff) 874 if (e1->op == TOKnull && e2->op == TOKnull) 875 { 876 cmp = 1; 877 } 878 else if (e1->op == TOKsymoff && e2->op == TOKsymoff) 817 879 { 818 880 SymOffExp *es1 = (SymOffExp *)e1; … … 1076 1138 else 1077 1139 { 1078 // error( "cannot cast %s to %s", e1->type->toChars(), type->toChars());1140 // error(loc, "cannot cast %s to %s", e1->type->toChars(), type->toChars()); 1079 1141 e = new IntegerExp(loc, 0, type); 1080 1142 } … … 1123 1185 1124 1186 if (i >= es1->len) {} 1125 // e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len); 1126 else 1127 { integer_t value; 1128 1129 switch (es1->sz) 1130 { 1131 case 1: 1132 value = ((unsigned char *)es1->string)[i]; 1133 break; 1134 1135 case 2: 1136 value = ((unsigned short *)es1->string)[i]; 1137 break; 1138 1139 case 4: 1140 value = ((unsigned int *)es1->string)[i]; 1141 break; 1142 1143 default: 1144 assert(0); 1145 break; 1146 } 1187 // e1->error("string index %ju is out of bounds [0 .. " ZU "]", i, es1->len); 1188 else 1189 { unsigned value = es1->charAt(i); 1147 1190 e = new IntegerExp(loc, value, type); 1148 1191 } … … 1273 1316 //printf("\tt1 = %s, t2 = %s\n", t1->toChars(), t2->toChars()); 1274 1317 1275 if (e1->op == TOKnull && e2->op == TOKint64)1318 if (e1->op == TOKnull && (e2->op == TOKint64 || e2->op == TOKstructliteral)) 1276 1319 { e = e2; 1277 1320 goto L2; 1278 1321 } 1279 else if ( e1->op == TOKint64&& e2->op == TOKnull)1322 else if ((e1->op == TOKint64 || e1->op == TOKstructliteral) && e2->op == TOKnull) 1280 1323 { e = e1; 1281 1324 L2: trunk/rebuild/declaration.c
r785 r840 446 446 { 447 447 // Try to convert Expression to Dsymbol 448 if (e->op == TOKvar) 449 { s = ((VarExp *)e)->var;448 s = getDsymbol(e); 449 if (s) 450 450 goto L2; 451 } 452 else if (e->op == TOKfunction) 453 { s = ((FuncExp *)e)->fd; 454 goto L2; 455 } 456 else 457 { //error("cannot alias an expression %s", e->toChars()); 458 t = e->type; 459 } 451 // error("cannot alias an expression %s", e->toChars()); 452 t = e->type; 460 453 } 461 454 else if (t) … … 595 588 offset = 0; 596 589 noauto = 0; 597 nestedref = 0;598 590 inuse = 0; 599 591 ctorinit = 0; … … 602 594 canassign = 0; 603 595 value = NULL; 596 scope = NULL; 604 597 } 605 598 … … 649 642 { 650 643 //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 651 //printf("type = %s\n", type->toChars()); 644 //printf(" type = %s\n", type->toChars()); 645 //printf("stc = x%x\n", sc->stc); 652 646 //printf("linkage = %d\n", sc->linkage); 653 647 //if (strcmp(toChars(), "mul") == 0) halt(); … … 747 741 } 748 742 743 Lagain: 749 744 if (isConst()) 750 745 { 746 /* Rewrite things like: 747
