Changeset 783
- Timestamp:
- 08/26/07 19:13:24 (1 year ago)
- Files:
-
- branches/dmdfe-2.0/Makefile (modified) (1 diff)
- branches/dmdfe-2.0/cast.c (modified) (46 diffs)
- branches/dmdfe-2.0/class.c (modified) (2 diffs)
- branches/dmdfe-2.0/constfold.c (modified) (7 diffs)
- branches/dmdfe-2.0/declaration.c (modified) (10 diffs)
- branches/dmdfe-2.0/declaration.h (modified) (5 diffs)
- branches/dmdfe-2.0/doc.c (modified) (2 diffs)
- branches/dmdfe-2.0/dsymbol.c (modified) (3 diffs)
- branches/dmdfe-2.0/expression.c (modified) (84 diffs)
- branches/dmdfe-2.0/expression.h (modified) (8 diffs)
- branches/dmdfe-2.0/func.c (modified) (15 diffs)
- branches/dmdfe-2.0/idgen.c (modified) (1 diff)
- branches/dmdfe-2.0/impcnvgen.c (modified) (6 diffs)
- branches/dmdfe-2.0/init.c (modified) (5 diffs)
- branches/dmdfe-2.0/lexer.c (modified) (1 diff)
- branches/dmdfe-2.0/lexer.h (modified) (1 diff)
- branches/dmdfe-2.0/link.c (modified) (1 diff)
- branches/dmdfe-2.0/mars.c (modified) (6 diffs)
- branches/dmdfe-2.0/mars.h (modified) (1 diff)
- branches/dmdfe-2.0/mtype.c (modified) (119 diffs)
- branches/dmdfe-2.0/mtype.h (modified) (35 diffs)
- branches/dmdfe-2.0/optimize.c (modified) (7 diffs)
- branches/dmdfe-2.0/parse.c (modified) (54 diffs)
- branches/dmdfe-2.0/parse.h (modified) (2 diffs)
- branches/dmdfe-2.0/statement.c (modified) (18 diffs)
- branches/dmdfe-2.0/statement.h (modified) (2 diffs)
- branches/dmdfe-2.0/template.c (modified) (9 diffs)
- branches/dmdfe-2.0/todt.c (modified) (8 diffs)
- branches/dmdfe-2.0/toobj.c (modified) (2 diffs)
- branches/dmdfe-2.0/typinf.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe-2.0/Makefile
r740 r783 56 56 struct.o \ 57 57 template.o \ 58 traits.o \ 58 59 unialpha.o \ 59 60 utf.o \ branches/dmdfe-2.0/cast.c
r740 r783 1 1 2 // Copyright (c) 1999-200 6by Digital Mars2 // Copyright (c) 1999-2007 by Digital Mars 3 3 // All Rights Reserved 4 4 // written by Walter Bright … … 32 32 Expression *Expression::implicitCastTo(Scope *sc, Type *t) 33 33 { 34 //printf("implicitCastTo(%s) => %s\n", type->toChars(), t->toChars()); 34 //printf("Expression::implicitCastTo(%s) => %s\n", type->toChars(), t->toChars()); 35 //printf("%s\n", toChars()); 36 35 37 if (implicitConvTo(t)) 36 38 { … … 61 63 t->print(); 62 64 printf("%p %p type: %s to: %s\n", type->deco, t->deco, type->deco, t->deco); 63 //printf("%p %p %p\n", type->next ->arrayOf(), type, t);65 //printf("%p %p %p\n", type->nextOf()->arrayOf(), type, t); 64 66 fflush(stdout); 65 67 #endif … … 98 100 type = Type::terror; 99 101 } 100 if (t->ty == Tbit && isBit())101 return MATCHconvert;102 102 Expression *e = optimize(WANTvalue | WANTflags); 103 103 if (e != this) … … 106 106 } 107 107 MATCH match = type->implicitConvTo(t); 108 if (match )108 if (match != MATCHnomatch) 109 109 return match; 110 110 #if 0 … … 112 112 if (tb->ty == Tdelegate) 113 113 { TypeDelegate *td = (TypeDelegate *)tb; 114 TypeFunction *tf = (TypeFunction *)td->next ;114 TypeFunction *tf = (TypeFunction *)td->nextOf(); 115 115 116 116 if (!tf->varargs && … … 118 118 ) 119 119 { 120 match = type->implicitConvTo(tf->next );120 match = type->implicitConvTo(tf->nextOf()); 121 121 if (match) 122 122 return match; 123 if (tf->next ->toBasetype()->ty == Tvoid)123 if (tf->nextOf()->toBasetype()->ty == Tvoid) 124 124 return MATCHconvert; 125 125 } … … 139 139 return MATCHexact; 140 140 141 enumTY ty = type->toBasetype()->ty;142 enumTY toty = t->toBasetype()->ty;141 TY ty = type->toBasetype()->ty; 142 TY toty = t->toBasetype()->ty; 143 143 144 144 if (type->implicitConvTo(t) == MATCHnomatch && t->ty == Tenum) 145 { 146 return MATCHnomatch; 147 } 145 goto Lno; 148 146 149 147 switch (ty) … … 301 299 goto Lyes; 302 300 } 301 302 case Tpointer: 303 //printf("type = %s\n", type->toBasetype()->toChars()); 304 //printf("t = %s\n", t->toBasetype()->toChars()); 305 if (ty == Tpointer && 306 type->toBasetype()->nextOf()->ty == t->toBasetype()->nextOf()->ty) 307 { /* Allow things like: 308 * const char* P = cast(char *)3; 309 * char* q = P; 310 */ 311 goto Lyes; 312 } 313 break; 303 314 } 304 315 return Expression::implicitConvTo(t); 305 316 306 317 Lyes: 307 //printf("MATCHconvert\n");308 318 return MATCHconvert; 309 319 310 320 Lno: 311 //printf("MATCHnomatch\n");312 321 return MATCHnomatch; 313 322 } … … 322 331 return MATCHexact; 323 332 // NULL implicitly converts to any pointer type or dynamic array 324 if (type->ty == Tpointer && type->next ->ty == Tvoid)333 if (type->ty == Tpointer && type->nextOf()->ty == Tvoid) 325 334 { 326 335 if (t->ty == Ttypedef) … … 343 352 if (!committed) 344 353 { 345 if (!committed && t->ty == Tpointer && t->next ->ty == Tvoid)354 if (!committed && t->ty == Tpointer && t->nextOf()->ty == Tvoid) 346 355 { 347 356 return MATCHnomatch; … … 349 358 if (type->ty == Tsarray || type->ty == Tarray || type->ty == Tpointer) 350 359 { 351 if (type->next->ty == Tchar) 352 { 360 TY tyn = type->nextOf()->ty; 361 if (tyn == Tchar || tyn == Twchar || tyn == Tdchar) 362 { Type *tn; 363 MATCH m; 364 353 365 switch (t->ty) 354 366 { 355 367 case Tsarray: 356 if (type->ty == Tsarray && 357 ((TypeSArray *)type)->dim->toInteger() != 358 ((TypeSArray *)t)->dim->toInteger()) 359 return MATCHnomatch; 360 goto L1; 368 if (type->ty == Tsarray) 369 { 370 if (((TypeSArray *)type)->dim->toInteger() != 371 ((TypeSArray *)t)->dim->toInteger()) 372 return MATCHnomatch; 373 TY tynto = t->nextOf()->ty; 374 if (tynto == Tchar || tynto == Twchar || tynto == Tdchar) 375 return MATCHexact; 376 } 361 377 case Tarray: 362 goto L1;363 378 case Tpointer: 364 L1: 365 if (t->next->ty == Tchar) 366 return MATCHexact; 367 else if (t->next->ty == Twchar) 368 return MATCHexact; 369 else if (t->next->ty == Tdchar) 370 return MATCHexact; 379 tn = t->nextOf(); 380 m = MATCHexact; 381 if (type->nextOf()->mod != tn->mod) 382 { if (!tn->isConst()) 383 return MATCHnomatch; 384 m = MATCHconst; 385 } 386 switch (tn->ty) 387 { 388 case Tchar: 389 case Twchar: 390 case Tdchar: 391 return m; 392 } 371 393 break; 372 394 } … … 389 411 { MATCH result = MATCHexact; 390 412 413 #if 0 414 printf("ArrayLiteralExp::implicitConvTo(this=%s, type=%s, t=%s)\n", 415 toChars(), type->toChars(), t->toChars()); 416 #endif 391 417 Type *typeb = type->toBasetype(); 392 418 Type *tb = t->toBasetype(); … … 402 428 for (int i = 0; i < elements->dim; i++) 403 429 { Expression *e = (Expression *)elements->data[i]; 404 MATCH m = (MATCH)e->implicitConvTo(tb->next );430 MATCH m = (MATCH)e->implicitConvTo(tb->nextOf()); 405 431 if (m < result) 406 432 result = m; // remember worst match … … 423 449 for (size_t i = 0; i < keys->dim; i++) 424 450 { Expression *e = (Expression *)keys->data[i]; 425 MATCH m = (MATCH)e->implicitConvTo(((TypeAArray *)tb)-> key);451 MATCH m = (MATCH)e->implicitConvTo(((TypeAArray *)tb)->index); 426 452 if (m < result) 427 453 result = m; // remember worst match … … 429 455 break; // no need to check for worse 430 456 e = (Expression *)values->data[i]; 431 m = (MATCH)e->implicitConvTo(tb->next );457 m = (MATCH)e->implicitConvTo(tb->nextOf()); 432 458 if (m < result) 433 459 result = m; // remember worst match … … 459 485 460 486 t = t->toBasetype(); 461 if (type->ty == Tpointer && type->next ->ty == Tfunction &&462 t->ty == Tpointer && t->next ->ty == Tfunction &&487 if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 488 t->ty == Tpointer && t->nextOf()->ty == Tfunction && 463 489 e1->op == TOKvar) 464 490 { 491 /* I don't think this can ever happen - 492 * it should have been 493 * converted to a SymOffExp. 494 */ 495 assert(0); 465 496 ve = (VarExp *)e1; 466 497 f = ve->var->isFuncDeclaration(); 467 if (f && f->overloadExactMatch(t->next ))498 if (f && f->overloadExactMatch(t->nextOf())) 468 499 result = MATCHexact; 469 500 } … … 490 521 491 522 t = t->toBasetype(); 492 if (type->ty == Tpointer && type->next ->ty == Tfunction &&493 t->ty == Tpointer && t->next->ty == Tfunction)523 if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 524 (t->ty == Tpointer || t->ty == Tdelegate) && t->nextOf()->ty == Tfunction) 494 525 { 495 526 f = var->isFuncDeclaration(); 496 if (f && f->overloadExactMatch(t->next)) 497 result = MATCHexact; 527 if (f) 528 { f = f->overloadExactMatch(t->nextOf()); 529 if (f) 530 { if ((t->ty == Tdelegate && (f->needThis() || f->isNested())) || 531 (t->ty == Tpointer && !(f->needThis() || f->isNested()))) 532 result = MATCHexact; 533 } 534 } 498 535 } 499 536 } … … 512 549 result = type->implicitConvTo(t); 513 550 514 if (result == 0)551 if (result == MATCHnomatch) 515 552 { 516 553 // Look for pointers to functions where the functions are overloaded. … … 518 555 519 556 t = t->toBasetype(); 520 if (type->ty == Tdelegate && type->next ->ty == Tfunction &&521 t->ty == Tdelegate && t->next ->ty == Tfunction)522 { 523 if (func && func->overloadExactMatch(t->next ))557 if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction && 558 t->ty == Tdelegate && t->nextOf()->ty == Tfunction) 559 { 560 if (func && func->overloadExactMatch(t->nextOf())) 524 561 result = MATCHexact; 525 562 } … … 561 598 if (tb != type) 562 599 { 563 if (tb->ty == Tbit && isBit())564 ;565 566 600 // Do (type *) cast of (type [dim]) 567 elseif (tb->ty == Tpointer &&601 if (tb->ty == Tpointer && 568 602 type->ty == Tsarray 569 603 ) … … 580 614 { 581 615 TypeDelegate *td = (TypeDelegate *)tb; 582 TypeFunction *tf = (TypeFunction *)td->next ;583 return toDelegate(sc, tf->next );616 TypeFunction *tf = (TypeFunction *)td->nextOf(); 617 return toDelegate(sc, tf->nextOf()); 584 618 } 585 619 #endif … … 629 663 { 630 664 // NULL implicitly converts to any pointer type or dynamic array 631 if (type->ty == Tpointer && type->next ->ty == Tvoid &&665 if (type->ty == Tpointer && type->nextOf()->ty == Tvoid && 632 666 (tb->ty == Tpointer || tb->ty == Tarray || tb->ty == Taarray || 633 667 tb->ty == Tdelegate)) … … 636 670 if (tb->ty == Tdelegate) 637 671 { TypeDelegate *td = (TypeDelegate *)tb; 638 TypeFunction *tf = (TypeFunction *)td->next ;672 TypeFunction *tf = (TypeFunction *)td->nextOf(); 639 673 640 674 if (!tf->varargs && … … 665 699 //printf("StringExp::castTo(t = %s), '%s' committed = %d\n", t->toChars(), toChars(), committed); 666 700 667 if (!committed && t->ty == Tpointer && t->next ->ty == Tvoid)701 if (!committed && t->ty == Tpointer && t->nextOf()->ty == Tvoid) 668 702 { 669 703 error("cannot convert string literal to void*"); … … 708 742 if (se->committed == 1) 709 743 { 710 if (se->type->next ->size() == tb->next->size())744 if (se->type->nextOf()->size() == tb->nextOf()->size()) 711 745 { se->type = t; 712 746 return se; … … 728 762 OutBuffer buffer; 729 763 newlen = 0; 730 tfty = se->type->next ->toBasetype()->ty;731 ttty = tb->next ->toBasetype()->ty;764 tfty = se->type->nextOf()->toBasetype()->ty; 765 ttty = tb->nextOf()->toBasetype()->ty; 732 766 switch (X(tfty, ttty)) 733 767 { … … 820 854 se->string = buffer.extractData(); 821 855 se->len = newlen; 822 se->sz = tb->next ->size();856 se->sz = tb->nextOf()->size(); 823 857 break; 824 858 825 859 default: 826 if (se->type->next ->size() == tb->next->size())860 if (se->type->nextOf()->size() == tb->nextOf()->size()) 827 861 { se->type = t; 828 862 return se; … … 894 928 FuncDeclaration *f; 895 929 896 if (type->ty == Tpointer && type->next ->ty == Tfunction &&897 tb->ty == Tpointer && tb->next ->ty == Tfunction &&930 if (type->ty == Tpointer && type->nextOf()->ty == Tfunction && 931 tb->ty == Tpointer && tb->nextOf()->ty == Tfunction && 898 932 e1->op == TOKvar) 899 933 { … … 902 936 if (f) 903 937 { 904 f = f->overloadExactMatch(tb->next );938 f = f->overloadExactMatch(tb->nextOf()); 905 939 if (f) 906 940 { … … 937 971 if ((tb->ty == Tarray || tb->ty == Tsarray) && 938 972 (typeb->ty == Tarray || typeb->ty == Tsarray) && 939 tb->next ->toBasetype()->ty != Tvoid)973 tb->nextOf()->toBasetype()->ty != Tvoid) 940 974 { 941 975 if (tb->ty == Tsarray) … … 947 981 for (int i = 0; i < elements->dim; i++) 948 982 { Expression *e = (Expression *)elements->data[i]; 949 e = e->castTo(sc, tb->next );983 e = e->castTo(sc, tb->nextOf()); 950 984 elements->data[i] = (void *)e; 951 985 } … … 955 989 if (tb->ty == Tpointer && typeb->ty == Tsarray) 956 990 { 957 type = typeb->next ->pointerTo();991 type = typeb->nextOf()->pointerTo(); 958 992 } 959 993 L1: … … 966 1000 Type *tb = t->toBasetype(); 967 1001 if (tb->ty == Taarray && typeb->ty == Taarray && 968 tb->next ->toBasetype()->ty != Tvoid)1002 tb->nextOf()->toBasetype()->ty != Tvoid) 969 1003 { 970 1004 assert(keys->dim == values->dim); 971 1005 for (size_t i = 0; i < keys->dim; i++) 972 1006 { Expression *e = (Expression *)values->data[i]; 973 e = e->castTo(sc, tb->next );1007 e = e->castTo(sc, tb->nextOf()); 974 1008 values->data[i] = (void *)e; 975 1009 976 1010 e = (Expression *)keys->data[i]; 977 e = e->castTo(sc, ((TypeAArray *)tb)-> key);1011 e = e->castTo(sc, ((TypeAArray *)tb)->index); 978 1012 keys->data[i] = (void *)e; 979 1013 } … … 1002 1036 FuncDeclaration *f; 1003 1037 1004 if (type->ty == Tpointer && type->next->ty == Tfunction && 1005 tb->ty == Tpointer && tb->next->ty == Tfunction) 1038 if (hasOverloads && 1039 type->ty == Tpointer && type->nextOf()->ty == Tfunction && 1040 (tb->ty == Tpointer || tb->ty == Tdelegate) && tb->nextOf()->ty == Tfunction) 1006 1041 { 1007 1042 f = var->isFuncDeclaration(); 1008 1043 if (f) 1009 1044 { 1010 f = f->overloadExactMatch(tb->next );1045 f = f->overloadExactMatch(tb->nextOf()); 1011 1046 if (f) 1012 1047 { 1013 e = new SymOffExp(loc, f, 0); 1014 e->type = t; 1048 if (tb->ty == Tdelegate && f->needThis() && hasThis(sc)) 1049 { 1050 e = new DelegateExp(loc, new ThisExp(loc), f); 1051 e = e->semantic(sc); 1052 } 1053 else if (tb->ty == Tdelegate && f->isNested()) 1054 { 1055 e = new DelegateExp(loc, new IntegerExp(0), f); 1056 e = e->semantic(sc); 1057 } 1058 else 1059 { 1060 e = new SymOffExp(loc, f, 0); 1061 e->type = t; 1062 } 1015 1063 return e; 1016 1064 } … … 1018 1066 } 1019 1067 e = Expression::castTo(sc, t); 1068 } 1069 if (e == this && hasOverloads) 1070 { e = syntaxCopy(); 1071 ((SymOffExp *)e)->hasOverloads = 0; 1020 1072 } 1021 1073 e->type = t; … … 1040 1092 FuncDeclaration *f; 1041 1093 1042 if (type->ty == Tdelegate && type->next ->ty == Tfunction &&1043 tb->ty == Tdelegate && tb->next ->ty == Tfunction)1094 if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction && 1095 tb->ty == Tdelegate && tb->nextOf()->ty == Tfunction) 1044 1096 { 1045 1097 if (func) 1046 1098 { 1047 f = func->overloadExactMatch(tb->next );1099 f = func->overloadExactMatch(tb->nextOf()); 1048 1100 if (f) 1049 1101 { int offset; 1050 if (f->tintro && f->tintro->next ->isBaseOf(f->type->next, &offset) && offset)1102 if (f->tintro && f->tintro->nextOf()->isBaseOf(f->type->nextOf(), &offset) && offset) 1051 1103 error("%s", msg); 1052 1104 e = new DelegateExp(loc, e1, f); … … 1063 1115 { int offset; 1064 1116 1065 if (func->tintro && func->tintro->next ->isBaseOf(func->type->next, &offset) && offset)1117 if (func->tintro && func->tintro->nextOf()->isBaseOf(func->type->nextOf(), &offset) && offset) 1066 1118 error("%s", msg); 1067 1119 } … … 1102 1154 Type *t = Type::tptrdiff_t; 1103 1155 1104 stride = t1b->next ->size();1156 stride = t1b->nextOf()->size(); 1105 1157 if (!t->equals(t2b)) 1106 1158 e2 = e2->castTo(sc, t); 1107 if (t1b->next->isbit()) 1108 // BUG: should add runtime check for misaligned offsets 1109 // This perhaps should be done by rewriting as &p[i] 1110 // and letting back end do it. 1111 e2 = new UshrExp(loc, e2, new IntegerExp(0, 3, t)); 1112 else 1113 e2 = new MulExp(loc, e2, new IntegerExp(0, stride, t)); 1159 e2 = new MulExp(loc, e2, new IntegerExp(0, stride, t)); 1114 1160 e2->type = t; 1115 1161 type = e1->type; … … 1121 1167 Expression *e; 1122 1168 1123 stride = t2b->next ->size();1169 stride = t2b->nextOf()->size(); 1124 1170 if (!t->equals(t1b)) 1125 1171 e = e1->castTo(sc, t); 1126 1172 else 1127 1173 e = e1; 1128 if (t2b->next->isbit()) 1129 // BUG: should add runtime check for misaligned offsets 1130 e = new UshrExp(loc, e, new IntegerExp(0, 3, t)); 1131 else 1132 e = new MulExp(loc, e, new IntegerExp(0, stride, t)); 1174 e = new MulExp(loc, e, new IntegerExp(0, stride, t)); 1133 1175 e->type = t; 1134 1176 type = e2->type; … … 1216 1258 } 1217 1259 1260 if (op == TOKcat) 1261 { 1262 if ((t1->ty == Tsarray || t1->ty == Tarray) && 1263 (t2->ty == Tsarray || t2->ty == Tarray) && 1264 (t1->nextOf()->mod || t2->nextOf()->mod)) 1265 { 1266 t1 = t1->constOf(); 1267 t2 = t2->constOf(); 1268 } 1269 } 1270 1271 Lagain: 1218 1272 t = t1; 1219 1273 if (t1 == t2) … … 1223 1277 goto Lincompatible; 1224 1278 } 1225 else if (t1->isintegral() && t2->isintegral())1226 {1227 printf("t1 = %s, t2 = %s\n", t1->toChars(), t2->toChars());1228 int sz1 = t1->size();1229 int sz2 = t2->size();1230 int sign1 = t1->isunsigned() == 0;1231 int sign2 = t2->isunsigned() == 0;1232 1233 if (sign1 == sign2)1234 {1235 if (sz1 < sz2)1236 goto Lt2;1237 else1238 goto Lt1;1239 }1240 if (!sign1)1241 {1242 if (sz1 >= sz2)1243 goto Lt1;1244 else1245 goto Lt2;1246 }1247 else1248 {1249 if (sz2 >= sz1)1250 goto Lt2;1251 else1252 goto Lt1;1253 }1254 }1255 1279 else if (t1->ty == Tpointer && t2->ty == Tpointer) 1256 1280 { 1257 1281 // Bring pointers to compatible type 1258 Type *t1n = t1->next; 1259 Type *t2n = t2->next; 1260 1261 //t1->print(); 1262 //t2->print(); 1263 //if (t1n == t2n) *(char *)0 = 0; 1264 assert(t1n != t2n); 1265 if (t1n->ty == Tvoid) // pointers to void are always compatible 1282 Type *t1n = t1->nextOf(); 1283 Type *t2n = t2->nextOf(); 1284 1285 if (t1n == t2n) 1286 ; 1287 else if (t1n->ty == Tvoid) // pointers to void are always compatible 1266 1288 t = t2; 1267 1289 else if (t2n->ty == Tvoid) 1268 1290 ; 1291 else if (t1n->mod != t2n->mod) 1292 { 1293 t1 = t1->constOf(); 1294 t2 = t2->constOf(); 1295 goto Lagain; 1296 } 1269 1297 else if (t1n->ty == Tclass && t2n->ty == Tclass) 1270 1298 { ClassDeclaration *cd1 = t1n->isClassHandle(); … … 1290 1318 } 1291 1319 else if ((t1->ty == Tsarray || t1->ty == Tarray) && 1292 e2->op == TOKnull && t2->ty == Tpointer && t2->next->ty == Tvoid) 1293 { 1320 e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty == Tvoid) 1321 { /* (T[n] op void*) 1322 * (T[] op void*) 1323 */ 1294 1324 goto Lx1; 1295 1325 } 1296 1326 else if ((t2->ty == Tsarray || t2->ty == Tarray) && 1297 e1->op == TOKnull && t1->ty == Tpointer && t1->next->ty == Tvoid) 1298 { 1327 e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty == Tvoid) 1328 { /* (void* op T[n]) 1329 * (void* op T[]) 1330 */ 1299 1331 goto Lx2; 1300 1332 } … … 1306 1338 { 1307 1339 goto Lt1; 1340 } 1341 /* If one is mutable and the other invariant, then retry 1342 * with both of them as const 1343 */ 1344 else if ((t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Tpointer) && 1345 (t2->ty == Tsarray || t2->ty == Tarray || t2->ty == Tpointer) && 1346 t1->nextOf()->mod != t2->nextOf()->mod 1347 ) 1348 { 1349 t1 = t1->constOf(); 1350 t2 = t2->constOf(); 1351 goto Lagain; 1308 1352 } 1309 1353 else if (t1->ty == Tclass || t2->ty == Tclass) … … 1334 1378 goto Lincompatible; 1335 1379 } 1380 else if (t1->ty == Tstruct && t2->ty == Tstruct) 1381 { 1382 if (((TypeStruct *)t1)->sym != ((TypeStruct *)t2)->sym) 1383 goto Lincompatible; 1384 } 1336 1385 else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) 1337 1386 { … … 1344 1393 } 1345 1394 else if (t1->ty == Tsarray && t2->ty == Tsarray && 1346 e2->implicitConvTo(t1->next ->arrayOf()))1395 e2->implicitConvTo(t1->nextOf()->arrayOf())) 1347 1396 { 1348 1397 Lx1: 1349 t = t1->next ->arrayOf();1398 t = t1->nextOf()->arrayOf(); 1350 1399 e1 = e1->castTo(sc, t); 1351 1400 e2 = e2->castTo(sc, t); 1352 1401 } 1353 1402 else if (t1->ty == Tsarray && t2->ty == Tsarray && 1354 e1->implicitConvTo(t2->next ->arrayOf()))1403 e1->implicitConvTo(t2->nextOf()->arrayOf())) 1355 1404 { 1356 1405 Lx2: 1357 t = t2->next ->arrayOf();1406 t = t2->nextOf()->arrayOf(); 1358 1407 e1 = e1->castTo(sc, t); 1359 1408 e2 = e2->castTo(sc, t); 1409 } 1410 else if (t1->isintegral() && t2->isintegral()) 1411 { 1412 assert(0); 1360 1413 } 1361 1414 else branches/dmdfe-2.0/class.c
r659 r783 146 146 Type::typeinfotypelist->error("%s", msg); 147 147 Type::typeinfotypelist = this; 148 } 149 150 if (id == Id::TypeInfo_Const) 151 { if (Type::typeinfoconst) 152 Type::typeinfoconst->error("%s", msg); 153 Type::typeinfoconst = this; 154 } 155 156 if (id == Id::TypeInfo_Invariant) 157 { if (Type::typeinfoinvariant) 158 Type::typeinfoinvariant->error("%s", msg); 159 Type::typeinfoinvariant = this; 148 160 } 149 161 } … … 568 580 members->push(ctor); 569 581 ctor->addMember(sc, this, 1); 570 *sc = scsave; 582 *sc = scsave; // why? What about sc->nofree? 571 583 sc->offset = structsize; 572 584 ctor->semantic(sc); branches/dmdfe-2.0/constfold.c
r740 r783 972 972 973 973 //printf("Cast(type = %s, to = %s, e1 = %s)\n", type->toChars(), to->toChars(), e1->toChars()); 974 //printf(" e1->type = %s\n", e1->type->toChars());975 if ( type->equals(e1->type) && to->equals(type))974 //printf("\te1->type = %s\n", e1->type->toChars()); 975 if (e1->type->equals(type) && type->equals(to)) 976 976 return e1; 977 if (e1->type->implicitConvTo(to) >= MATCHconst || 978 to->implicitConvTo(e1->type) >= MATCHconst) 979 return expType(to, e1); 977 980 978 981 if (e1->isConst() != 1) … … 1243 1246 Loc loc = e1->loc; 1244 1247 Type *t; 1248 Type *t1 = e1->type->toBasetype(); 1249 Type *t2 = e2->type->toBasetype(); 1245 1250 1246 1251 //printf("Cat(e1 = %s, e2 = %s)\n", e1->toChars(), e2->toChars()); 1252 //printf("\tt1 = %s, t2 = %s\n", t1->toChars(), t2->toChars()); 1247 1253 1248 1254 if (e1->op == TOKnull && e2->op == TOKint64) … … 1363 1369 } 1364 1370 else if (e1->op == TOKarrayliteral && e2->op == TOKarrayliteral && 1365 e1->type->equals(e2->type))1371 t1->nextOf()->equals(t2->nextOf())) 1366 1372 { 1367 1373 // Concatenate the arrays … … 1375 1381 if (type->toBasetype()->ty == Tsarray) 1376 1382 { 1377 e->type = new TypeSArray( e1->type->toBasetype()->next, new IntegerExp(0, es1->elements->dim, Type::tindex));1383 e->type = new TypeSArray(t1->nextOf(), new IntegerExp(0, es1->elements->dim, Type::tindex)); 1378 1384 e->type = e->type->semantic(loc, NULL); 1379 1385 } … … 1382 1388 } 1383 1389 else if (e1->op == TOKarrayliteral && 1384 e1->type->toBasetype()->next ->equals(e2->type))1390 e1->type->toBasetype()->nextOf()->equals(e2->type)) 1385 1391 { 1386 1392 ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; … … 1399 1405 } 1400 1406 else if (e2->op == TOKarrayliteral && 1401 e2->type->toBasetype()->next ->equals(e1->type))1407 e2->type->toBasetype()->nextOf()->equals(e1->type)) 1402 1408 { 1403 1409 ArrayLiteralExp *es2 = (ArrayLiteralExp *)e2; … … 1426 1432 L1: 1427 1433 Type *tb = t->toBasetype(); 1428 if (tb->ty == Tarray && tb->next ->equals(e->type))1434 if (tb->ty == Tarray && tb->nextOf()->equals(e->type)) 1429 1435 { Expressions *expressions = new Expressions(); 1430 1436 expressions->push(e); branches/dmdfe-2.0/declaration.c
r657 r783 81 81 } 82 82 83 /************************************* 84 * Check to see if declaration can be modified in this context (sc). 85 * Issue error if not. 86 */ 87 88 void Declaration::checkModify(Loc loc, Scope *sc) 89 { 90 if (sc->incontract && isParameter()) 91 error(loc, "cannot modify parameter '%s' in contract", toChars()); 92 93 VarDeclaration *v = isVarDeclaration(); 94 if (v && v->canassign == 0 && 95 (isConst() || isInvariant() || (isFinal() && !isCtorinit()))) 96 error(loc, "cannot modify final/const/invariant variable '%s'", toChars()); 97 98 if (isCtorinit()) 99 { // It's only modifiable if inside the right constructor 100 Dsymbol *s = sc->func; 101 while (1) 102 { 103 FuncDeclaration *fd = NULL; 104 if (s) 105 fd = s->isFuncDeclaration(); 106 if (fd && 107 ((fd->isCtorDeclaration() && storage_class & STCfield) || 108 (fd->isStaticCtorDeclaration() && !(storage_class & STCfield))) && 109 fd->toParent() == toParent() 110 ) 111 { 112 assert(v); 113 v->ctorinit = 1; 114 //printf("setting ctorinit\n"); 115 } 116 else 117 { 118 if (s) 119 { s = s->toParent2(); 120 continue; 121 } 122 else 123 { 124 const char *p = isStatic() ? "static " : ""; 125 error(loc, "can only initialize %sconst %s inside %sconstructor", 126 p, toChars(), p); 127 } 128 } 129 break; 130 } 131 } 132 } 133 134 83 135 /********************************* TupleDeclaration ****************************/ 84 136 … … 140 192 Argument *arg = new Argument(STCin, t, id, NULL); 141 193 #else 142 Argument *arg = new Argument( STCin, t, NULL, NULL);194 Argument *arg = new Argument(0, t, NULL, NULL); 143 195 #endif 144 196 args->data[i] = (void *)arg; … … 628 680 protection = sc->protection; 629 681 //printf("sc->stc = %x\n", sc->stc); 630 //printf("storage_class = %x\n", storage_class);682 //printf("storage_class = x%x\n", storage_class); 631 683 632 684 Dsymbol *parent = toParent(); … … 690 742 } 691 743 692 if (storage_class & STCconst && !init && !fd) 693 // Initialize by constructor only 694 storage_class = (storage_class & ~STCconst) | STCctorinit; 744 if (storage_class & STCfinal && !init && !fd) 745 { // Initialize by constructor only 746 storage_class |= STCctorinit; 747 } 695 748 696 749 if (isConst()) 697 750 { 698 } 699 else if (isStatic()) 751 type = type->constOf(); 752 if (isParameter()) 753 { storage_class |= STCfinal; 754 storage_class &= ~STCconst; 755 } 756 } 757 else if (storage_class & STCinvariant) 758 { 759 type = type->invariantOf(); 760 if (isParameter()) 761 { storage_class |= STCfinal; 762 storage_class &= ~STCinvariant; 763 } 764 } 765 type = type->toCanonConst(); 766 767 if (storage_class & (STCconst | STCinvariant | STCstatic)) 700 768 { 701 769 } … … 721 789 aad = parent->isAggregateDeclaration(); 722 790 if (aad) 723 { 791 { assert(!(storage_class & (STCconst | STCinvariant | STCstatic))); 724 792 aad->addField(sc, this); 725 793 } … … 826 894 // If local variable, use AssignExp to handle all the various 827 895 // possibilities. 828 if (fd && !isStatic() && !isConst() && !init->isVoidInitializer()) 896 if (fd && !isStatic() && !isConst() && !isInvariant() && 897 !init->isVoidInitializer()) 829 898 { 830 899 Expression *e1; … … 858 927 while (1) 859 928 { 860 t = t->next ->toBasetype();929 t = t->nextOf()->toBasetype(); 861 930 if (t->ty != Tsarray) 862 931 break; 863 if (t->next->toBasetype()->ty == Tbit) 864 // t->size() gives size in bytes, convert to bits 865 dim *= t->size() * 8; 866 else 867 dim *= ((TypeSArray *)t)->dim->toInteger(); 868 e1->type = new TypeSArray(t->next, new IntegerExp(0, dim, Type::tindex)); 932 dim *= ((TypeSArray *)t)->dim->toInteger(); 933 e1->type = new TypeSArray(t->nextOf(), new IntegerExp(0, dim, Type::tindex)); 869 934 } 870 935 e1 = new SliceExp(loc, e1, NULL, NULL); … … 886 951 { 887 952 init = init->semantic(sc, type); 888 if (fd && isConst() && !isStatic())953 if (fd && (isConst() || isInvariant()) && !isStatic()) 889 954 { // Make it static 890 955 storage_class |= STCstatic; … … 892 957 } 893 958 } 894 else if (isConst() || is Final())959 else if (isConst() || isInvariant() || isFinal()) 895 960 { 896 961 /* Because we may need the results of a const declaration in a … … 1159 1224 } 1160 1225 1226 /***************************** TypeInfoConstDeclaration **********************/ 1227 1228 TypeInfoConstDeclaration::TypeInfoConstDeclaration(Type *tinfo) 1229 : TypeInfoDeclaration(tinfo, 0) 1230 { 1231 } 1232 1233 /***************************** TypeInfoInvariantDeclaration **********************/ 1234 1235 TypeInfoInvariantDeclaration::TypeInfoInvariantDeclaration(Type *tinfo) 1236 : TypeInfoDeclaration(tinfo, 0) 1237 { 1238 } 1239 1161 1240 /***************************** TypeInfoStructDeclaration **********************/ 1162 1241
