Changeset 740
- Timestamp:
- 08/07/07 23:33:56 (1 year ago)
- Files:
-
- branches/dmdfe/Makefile (modified) (1 diff)
- branches/dmdfe/attrib.c (modified) (1 diff)
- branches/dmdfe/cast.c (modified) (16 diffs)
- branches/dmdfe/constfold.c (modified) (3 diffs)
- branches/dmdfe/declaration.h (modified) (1 diff)
- branches/dmdfe/expression.c (modified) (1 diff)
- branches/dmdfe/expression.h (modified) (11 diffs)
- branches/dmdfe/func.c (modified) (21 diffs)
- branches/dmdfe/inline.c (modified) (2 diffs)
- branches/dmdfe/interpret.c (modified) (11 diffs)
- branches/dmdfe/mars.c (modified) (1 diff)
- branches/dmdfe/mars.h (modified) (1 diff)
- branches/dmdfe/mtype.c (modified) (12 diffs)
- branches/dmdfe/mtype.h (modified) (9 diffs)
- branches/dmdfe/opover.c (modified) (5 diffs)
- branches/dmdfe/template.c (modified) (14 diffs)
- branches/dmdfe/template.h (modified) (3 diffs)
- branches/dmdfe/tocsym.c (modified) (2 diffs)
- branches/dmdfe/toir.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe/Makefile
r362 r740 2 2 CXX=$(CROSS)g++ 3 3 NATIVECXX=g++ 4 CXXFLAGS=- O2 -g4 CXXFLAGS=-g 5 5 6 6 EXEEXT= branches/dmdfe/attrib.c
r659 r740 255 255 } 256 256 else 257 buf->writeByte(' :');257 buf->writeByte(';'); 258 258 buf->writenl(); 259 259 } branches/dmdfe/cast.c
r657 r740 88 88 */ 89 89 90 intExpression::implicitConvTo(Type *t)90 MATCH Expression::implicitConvTo(Type *t) 91 91 { 92 92 #if 0 … … 105 105 return e->implicitConvTo(t); 106 106 } 107 intmatch = type->implicitConvTo(t);107 MATCH match = type->implicitConvTo(t); 108 108 if (match) 109 109 return match; … … 130 130 131 131 132 intIntegerExp::implicitConvTo(Type *t)132 MATCH IntegerExp::implicitConvTo(Type *t) 133 133 { 134 134 #if 0 … … 143 143 144 144 if (type->implicitConvTo(t) == MATCHnomatch && t->ty == Tenum) 145 { 145 146 return MATCHnomatch; 147 } 146 148 147 149 switch (ty) … … 303 305 304 306 Lyes: 307 //printf("MATCHconvert\n"); 305 308 return MATCHconvert; 306 309 307 310 Lno: 311 //printf("MATCHnomatch\n"); 308 312 return MATCHnomatch; 309 313 } 310 314 311 intNullExp::implicitConvTo(Type *t)315 MATCH NullExp::implicitConvTo(Type *t) 312 316 { 313 317 #if 0 … … 330 334 } 331 335 332 intStringExp::implicitConvTo(Type *t)336 MATCH StringExp::implicitConvTo(Type *t) 333 337 { MATCH m; 334 338 … … 382 386 } 383 387 384 intArrayLiteralExp::implicitConvTo(Type *t)388 MATCH ArrayLiteralExp::implicitConvTo(Type *t) 385 389 { MATCH result = MATCHexact; 386 390 … … 410 414 } 411 415 412 intAssocArrayLiteralExp::implicitConvTo(Type *t)416 MATCH AssocArrayLiteralExp::implicitConvTo(Type *t) 413 417 { MATCH result = MATCHexact; 414 418 … … 437 441 } 438 442 439 intAddrExp::implicitConvTo(Type *t)443 MATCH AddrExp::implicitConvTo(Type *t) 440 444 { 441 445 #if 0 … … 443 447 toChars(), type->toChars(), t->toChars()); 444 448 #endif 445 intresult;449 MATCH result; 446 450 447 451 result = type->implicitConvTo(t); … … 469 473 } 470 474 471 intSymOffExp::implicitConvTo(Type *t)475 MATCH SymOffExp::implicitConvTo(Type *t) 472 476 { 473 477 #if 0 … … 475 479 toChars(), type->toChars(), t->toChars()); 476 480 #endif 477 intresult;481 MATCH result; 478 482 479 483 result = type->implicitConvTo(t); … … 498 502 } 499 503 500 intDelegateExp::implicitConvTo(Type *t)504 MATCH DelegateExp::implicitConvTo(Type *t) 501 505 { 502 506 #if 0 … … 504 508 toChars(), type->toChars(), t->toChars()); 505 509 #endif 506 intresult;510 MATCH result; 507 511 508 512 result = type->implicitConvTo(t); … … 518 522 { 519 523 if (func && func->overloadExactMatch(t->next)) 520 result = 2;524 result = MATCHexact; 521 525 } 522 526 } … … 524 528 } 525 529 526 intCondExp::implicitConvTo(Type *t)527 { 528 intm1;529 intm2;530 MATCH CondExp::implicitConvTo(Type *t) 531 { 532 MATCH m1; 533 MATCH m2; 530 534 531 535 m1 = e1->implicitConvTo(t); branches/dmdfe/constfold.c
r656 r740 23 23 #include "mtype.h" 24 24 #include "expression.h" 25 #include "aggregate.h" 26 #include "declaration.h" 25 27 26 28 #ifdef IN_GCC … … 1027 1029 else if (tb->isscalar()) 1028 1030 e = new IntegerExp(loc, e1->toInteger(), type); 1031 else if (tb->ty == Tvoid) 1032 e = EXP_CANT_INTERPRET; 1033 else if (tb->ty == Tstruct && e1->op == TOKint64) 1034 { // Struct = 0; 1035 StructDeclaration *sd = tb->toDsymbol(NULL)->isStructDeclaration(); 1036 assert(sd); 1037 Expressions *elements = new Expressions; 1038 for (size_t i = 0; i < sd->fields.dim; i++) 1039 { Dsymbol *s = (Dsymbol *)sd->fields.data[i]; 1040 VarDeclaration *v = s->isVarDeclaration(); 1041 assert(v); 1042 1043 Expression *exp = new IntegerExp(0); 1044 exp = Cast(v->type, v->type, exp); 1045 if (exp == EXP_CANT_INTERPRET) 1046 return exp; 1047 elements->push(exp); 1048 } 1049 e = new StructLiteralExp(loc, sd, elements); 1050 e->type = type; 1051 } 1029 1052 else 1030 1053 { 1031 if (tb->ty == Tvoid) 1032 e = EXP_CANT_INTERPRET; 1033 else 1034 { error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); 1035 e = new IntegerExp(loc, 0, type); 1036 } 1054 error("cannot cast %s to %s", e1->type->toChars(), type->toChars()); 1055 e = new IntegerExp(loc, 0, type); 1037 1056 } 1038 1057 return e; … … 1080 1099 1081 1100 if (i >= es1->len) 1082 e1->error("string index %ju is out of bounds [0 .. % ju]", i, es1->len);1101 e1->error("string index %ju is out of bounds [0 .. %zu]", i, es1->len); 1083 1102 else 1084 1103 { integer_t value; branches/dmdfe/declaration.h
r458 r740 75 75 76 76 void overloadResolveX(Match *m, FuncDeclaration *f, Expressions *arguments); 77 int overloadApply(FuncDeclaration *fstart, 78 int (*fp)(void *, FuncDeclaration *), 79 void *param); 77 80 78 81 /**************************************************************/ branches/dmdfe/expression.c
r659 r740 3132 3132 if (cd->isInterfaceDeclaration()) 3133 3133 error("cannot create instance of interface %s", cd->toChars()); 3134 if (cd->isAbstract())3134 else if (cd->isAbstract()) 3135 3135 error("cannot create instance of abstract class %s", cd->toChars()); 3136 3136 checkDeprecated(sc, cd); branches/dmdfe/expression.h
r659 r740 100 100 virtual Expression *modifiableLvalue(Scope *sc, Expression *e); 101 101 Expression *implicitCastTo(Scope *sc, Type *t); 102 virtual intimplicitConvTo(Type *t);102 virtual MATCH implicitConvTo(Type *t); 103 103 virtual Expression *castTo(Scope *sc, Type *t); 104 104 virtual void checkEscape(); … … 156 156 int isConst(); 157 157 int isBool(int result); 158 intimplicitConvTo(Type *t);158 MATCH implicitConvTo(Type *t); 159 159 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 160 160 void toMangleBuffer(OutBuffer *buf); … … 275 275 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 276 276 void toMangleBuffer(OutBuffer *buf); 277 intimplicitConvTo(Type *t);277 MATCH implicitConvTo(Type *t); 278 278 Expression *castTo(Scope *sc, Type *t); 279 279 Expression *interpret(InterState *istate); … … 297 297 Expression *interpret(InterState *istate); 298 298 StringExp *toUTF8(Scope *sc); 299 intimplicitConvTo(Type *t);299 MATCH implicitConvTo(Type *t); 300 300 Expression *castTo(Scope *sc, Type *t); 301 301 int compare(Object *obj); … … 345 345 Expression *optimize(int result); 346 346 Expression *interpret(InterState *istate); 347 intimplicitConvTo(Type *t);347 MATCH implicitConvTo(Type *t); 348 348 Expression *castTo(Scope *sc, Type *t); 349 349 dt_t **toDt(dt_t **pdt); … … 371 371 Expression *optimize(int result); 372 372 Expression *interpret(InterState *istate); 373 intimplicitConvTo(Type *t);373 MATCH implicitConvTo(Type *t); 374 374 Expression *castTo(Scope *sc, Type *t); 375 375 … … 504 504 int isBool(int result); 505 505 Expression *doInline(InlineDoState *ids); 506 intimplicitConvTo(Type *t);506 MATCH implicitConvTo(Type *t); 507 507 Expression *castTo(Scope *sc, Type *t); 508 508 void scanForNestedRef(Scope *sc); … … 649 649 Expression *interpretCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *)); 650 650 Expression *interpretCommon2(InterState *istate, Expression *(*fp)(TOK, Type *, Expression *, Expression *)); 651 Expression *interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *) );651 Expression *interpretAssignCommon(InterState *istate, Expression *(*fp)(Type *, Expression *, Expression *), int post = 0); 652 652 653 653 int inlineCost(InlineCostState *ics); … … 745 745 DelegateExp(Loc loc, Expression *e, FuncDeclaration *func); 746 746 Expression *semantic(Scope *sc); 747 intimplicitConvTo(Type *t);747 MATCH implicitConvTo(Type *t); 748 748 Expression *castTo(Scope *sc, Type *t); 749 749 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 790 790 AddrExp(Loc loc, Expression *e); 791 791 Expression *semantic(Scope *sc); 792 int implicitConvTo(Type *t); 792 elem *toElem(IRState *irs); 793 MATCH implicitConvTo(Type *t); 793 794 Expression *castTo(Scope *sc, Type *t); 794 795 Expression *optimize(int result); … … 1262 1263 int checkSideEffect(int flag); 1263 1264 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); 1264 intimplicitConvTo(Type *t);1265 MATCH implicitConvTo(Type *t); 1265 1266 Expression *castTo(Scope *sc, Type *t); 1266 1267 void scanForNestedRef(Scope *sc); branches/dmdfe/func.c
r659 r740 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 … … 68 68 introducing = 0; 69 69 tintro = NULL; 70 inferRetType = (type && type->next == NULL);70 inferRetType = (type && type->nextOf() == NULL); 71 71 scope = NULL; 72 72 hasReturnExp = 0; … … 110 110 #endif 111 111 112 if (type->next )112 if (type->nextOf()) 113 113 type = type->semantic(loc, sc); 114 114 //type->print(); … … 145 145 if (isStaticConstructor() || isStaticDestructor()) 146 146 { 147 if (!isStatic() || type->next ->ty != Tvoid)147 if (!isStatic() || type->nextOf()->ty != Tvoid) 148 148 error("static constructors / destructors must be static void"); 149 149 if (f->arguments && f->arguments->dim) … … 317 317 */ 318 318 int offset; 319 if (fdv->type->next ->isBaseOf(type->next, &offset))319 if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset)) 320 320 { 321 321 tintro = fdv->type; … … 398 398 */ 399 399 int offset; 400 if (fdv->type->next ->isBaseOf(type->next, &offset))400 if (fdv->type->nextOf()->isBaseOf(type->nextOf(), &offset)) 401 401 { 402 402 ti = fdv->type; … … 490 490 } 491 491 492 if (f->next ->ty != Tint32 && f->next->ty != Tvoid)493 error("must return int or void, not %s", f->next ->toChars());492 if (f->nextOf()->ty != Tint32 && f->nextOf()->ty != Tvoid) 493 error("must return int or void, not %s", f->nextOf()->toChars()); 494 494 if (f->varargs) 495 495 { … … 513 513 Type *tb = sd ? sd->type : cd->type; 514 514 if (arg0->type->implicitConvTo(tb) || 515 (sd && t0->ty == Tpointer && t0->next ->implicitConvTo(tb))515 (sd && t0->ty == Tpointer && t0->nextOf()->implicitConvTo(tb)) 516 516 ) 517 517 { … … 794 794 sc2 = sc2->push(sym); 795 795 796 assert(type->next );797 if (type->next ->ty == Tvoid)796 assert(type->nextOf()); 797 if (type->nextOf()->ty == Tvoid) 798 798 { 799 799 if (outId) … … 814 814 loc = fensure->loc; 815 815 816 v = new VarDeclaration(loc, type->next , outId, NULL);816 v = new VarDeclaration(loc, type->nextOf(), outId, NULL); 817 817 v->noauto = 1; 818 818 sc2->incontract--; … … 910 910 if (inferRetType) 911 911 { // If no return type inferred yet, then infer a void 912 if (!type->next )912 if (!type->nextOf()) 913 913 { 914 914 type->next = Type::tvoid; … … 976 976 assert(!returnLabel); 977 977 } 978 else if (!hasReturnExp && type->next ->ty != Tvoid)979 error("expected to return a value of type %s", type->next ->toChars());978 else if (!hasReturnExp && type->nextOf()->ty != Tvoid) 979 error("expected to return a value of type %s", type->nextOf()->toChars()); 980 980 else if (!inlineAsm) 981 981 { 982 if (type->next ->ty == Tvoid)982 if (type->nextOf()->ty == Tvoid) 983 983 { 984 984 if (offend && isMain()) … … 1006 1006 endloc, 1007 1007 new IntegerExp(0), 1008 new StringExp( 0, "missing return expression")1008 new StringExp(loc, "missing return expression") 1009 1009 ); 1010 1010 } 1011 1011 else 1012 1012 e = new HaltExp(endloc); 1013 e = new CommaExp(0, e, type->next ->defaultInit());1013 e = new CommaExp(0, e, type->nextOf()->defaultInit()); 1014 1014 e = e->semantic(sc2); 1015 1015 Statement *s = new ExpStatement(0, e); … … 1138 1138 a->push(returnLabel->statement); 1139 1139 1140 if (type->next ->ty != Tvoid)1140 if (type->nextOf()->ty != Tvoid) 1141 1141 { 1142 1142 // Create: return vresult; … … 1144 1144 Expression *e = new VarExp(0, vresult); 1145 1145 if (tintro) 1146 { e = e->implicitCastTo(sc, tintro->next );1146 { e = e->implicitCastTo(sc, tintro->nextOf()); 1147 1147 e = e->semantic(sc); 1148 1148 } … … 1283 1283 */ 1284 1284 1285 /*************************************************** 1286 * Visit each overloaded function in turn, and call 1287 * (*fp)(param, f) on it. 1288 * Exit when no more, or (*fp)(param, f) returns 1. 1289 * Returns: 1290 * 0 continue 1291 * 1 done 1292 */ 1293 1294 int overloadApply(FuncDeclaration *fstart, 1295 int (*fp)(void *, FuncDeclaration *), 1296 void *param) 1297 { 1298 FuncDeclaration *f; 1299 Declaration *d; 1300 Declaration *next; 1301 1302 for (d = fstart; d; d = next) 1303 { FuncAliasDeclaration *fa = d->isFuncAliasDeclaration(); 1304 1305 if (fa) 1306 { 1307 if (overloadApply(fa->funcalias, fp, param)) 1308 return 1; 1309 next = fa->overnext; 1310 } 1311 else 1312 { 1313 AliasDeclaration *a = d->isAliasDeclaration(); 1314 1315 if (a) 1316 { 1317 Dsymbol *s = a->toAlias(); 1318 next = s->isDeclaration(); 1319 if (next == a) 1320 break; 1321 if (next == fstart) 1322 break; 1323 } 1324 else 1325 { 1326 f = d->isFuncDeclaration(); 1327 if (!f) 1328 { d->error("is aliased to a function"); 1329 break; // BUG: should print error message? 1330 } 1331 if ((*fp)(param, f)) 1332 return 1; 1333 1334 next = f->overnext; 1335 } 1336 } 1337 } 1338 return 0; 1339 } 1340 1341 /******************************************** 1342 * Find function in overload list that exactly matches t. 1343 */ 1344 1345 struct Param1 1346 { 1347 Type *t; // type to match 1348 FuncDeclaration *f; // return value 1349 }; 1350 1351 int fp1(void *param, FuncDeclaration *f) 1352 { Param1 *p = (Param1 *)param; 1353 Type *t = p->t; 1354 1355 if (t->equals(f->type)) 1356 { p->f = f; 1357 return 1; 1358 } 1359 1360 #if V2 1361 /* Allow covariant matches, if it's just a const conversion 1362 * of the return type 1363 */ 1364 if (t->ty == Tfunction) 1365 { TypeFunction *tf = (TypeFunction *)f->type; 1366 if (tf->covariant(t) == 1 && 1367 tf->nextOf()->implicitConvTo(t->nextOf()) >= MATCHconst) 1368 { 1369 p->f = f; 1370 return 1; 1371 } 1372 } 1373 #endif 1374 return 0; 1375 } 1376 1377 FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) 1378 { 1379 Param1 p; 1380 p.t = t; 1381 p.f = NULL; 1382 overloadApply(this, &fp1, &p); 1383 return p.f; 1384 } 1385 1386 #if 0 1285 1387 FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) 1286 1388 { … … 1323 1425 return NULL; 1324 1426 } 1427 #endif 1325 1428 1326 1429 /******************************************** … … 1328 1431 */ 1329 1432 1433 struct Param2 1434 { 1435 Match *m; 1436 Expressions *arguments; 1437 }; 1438 1439 int fp2(void *param, FuncDeclaration *f) 1440 { Param2 *p = (Param2 *)param; 1441 Match *m = p->m; 1442 Expressions *arguments = p->arguments; 1443 MATCH match; 1444 1445 if (f != m->lastf) // skip duplicates 1446 { 1447 TypeFunction *tf; 1448 1449 m->anyf = f; 1450 tf = (TypeFunction *)f->type; 1451 match = (MATCH) tf->callMatch(arguments); 1452 //printf("match = %d\n", match); 1453 if (match != MATCHnomatch) 1454 { 1455 if (match > m->last) 1456 goto LfIsBetter; 1457 1458 if (match < m->last) 1459 goto LlastIsBetter; 1460 1461 /* See if one of the matches overrides the other. 1462 */ 1463 if (m->lastf->overrides(f)) 1464 goto LlastIsBetter; 1465 else if (f->overrides(m->lastf)) 1466 goto LfIsBetter; 1467 1468 Lambiguous: 1469 m->nextf = f; 1470 m->count++; 1471 return 0; 1472 1473 LfIsBetter: 1474 m->last = match; 1475 m->lastf = f; 1476 m->count = 1; 1477 return 0; 1478 1479 LlastIsBetter: 1480 return 0; 1481 } 1482 } 1483 return 0; 1484 } 1485 1486 1487 void overloadResolveX(Match *m, FuncDeclaration *fstart, Expressions *arguments) 1488 { 1489 Param2 p; 1490 p.m = m; 1491 p.arguments = arguments; 1492 overloadApply(fstart, &fp2, &p); 1493 } 1494 1495 #if 0 1330 1496 // Recursive helper function 1331 1497 … … 1407 1573 } 1408 1574 } 1575 #endif 1409 1576 1410 1577 FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments) … … 1732 1899 fd = s->isFuncDeclaration(); 1733 1900 assert(fd); 1734 assert(fd->type->next ->equals(treturn));1901 assert(fd->type->nextOf()->equals(treturn)); 1735 1902 } 1736 1903 else … … 2077 2244 { 2078 2245 if (hgs->hdrgen) 2246 { buf->writestring("static this(){}\n"); 2079 2247 return; 2248 } 2080 2249 buf->writestring("static this()"); 2081 2250 bodyToCBuffer(buf, hgs); branches/dmdfe/inline.c
r659 r740 503 503 //if (!ids->vthis) 504 504 //error("no 'this' when inlining %s", ids->parent->toChars()); 505 assert(ids->vthis); 505 if (!ids->vthis) 506 { 507 return this; 508 } 506 509 507 510 VarExp *ve = new VarExp(loc, ids->vthis); … … 855 858 return this; 856 859 } 860 861 862 #if V2 863 Statement *ForeachRangeStatement::inlineScan(InlineScanState *iss) 864 { 865 lwr = lwr->inlineScan(iss); 866 upr = upr->inlineScan(iss); 867 body = body->inlineScan(iss); 868 return this; 869 } 870 #endif 857 871 858 872 branches/dmdfe/interpret.c
r659 r740 636 636 return EXP_CANT_INTERPRET; 637 637 638 Expression *keysave = key ? key->value : NULL; 639 Expression *valuesave = value->value; 640 638 641 uinteger_t d = dim->toUInteger(); 639 642 uinteger_t index; … … 646 649 if (key) 647 650 key->value = ekey; 648 value->value = Index(value->type, eaggr, ekey); 649 if (value->value == EXP_CANT_INTERPRET) 650 return EXP_CANT_INTERPRET; 651 e = Index(value->type, eaggr, ekey); 652 if (e == EXP_CANT_INTERPRET) 653 break; 654 value->value = e; 651 655 652 656 e = body ? body->interpret(istate) : NULL; … … 670 674 if (key) 671 675 key->value = ekey; 672 value->value = Index(value->type, eaggr, ekey); 673 if (value->value == EXP_CANT_INTERPRET) 674 return EXP_CANT_INTERPRET; 676 e = Index(value->type, eaggr, ekey); 677 if (e == EXP_CANT_INTERPRET) 678 break; 679 value->value = e; 675 680 676 681 e = body ? body->interpret(istate) : NULL; … … 687 692 } 688 693 } 689 return e; 690 } 694 value->value = valuesave; 695 if (key) 696 key->value = keysave; 697 return e; 698 } 699 700 #if V2 701 Expression *ForeachRangeStatement::interpret(InterState *istate) 702 { 703 #if LOG 704 printf("ForeachRangeStatement::interpret()\n"); 705 #endif 706 if (istate->start == this) 707 istate->start = NULL; 708 if (istate->start) 709 return NULL; 710 711 Expression *e = NULL; 712 Expression *elwr = lwr->interpret(istate); 713 if (elwr == EXP_CANT_INTERPRET) 714 return EXP_CANT_INTERPRET; 715 716 Expression *eupr = upr->interpret(istate); 717 if (eupr == EXP_CANT_INTERPRET) 718 return EXP_CANT_INTERPRET; 719 720 Expression *keysave = key->value; 721 722 if (op == TOKforeach) 723 { 724 key->value = elwr; 725 726 while (1) 727 { 728 e = Cmp(TOKlt, key->value->type, key->value, upr); 729 if (e == EXP_CANT_INTERPRET) 730 break; 731 if (e->isBool(TRUE) == FALSE) 732 { e = NULL; 733 break; 734 } 735 736 e = body ? body->interpret(istate) : NULL; 737 if (e == EXP_CANT_INTERPRET) 738 break; 739 if (e == EXP_BREAK_INTERPRET) 740 { e = NULL; 741 break; 742 } 743 e = Add(key->value->type, key->value, new IntegerExp(loc, 1, key->value->type)); 744 if (e == EXP_CANT_INTERPRET) 745 break; 746 key->value = e; 747 } 748 } 749 else // TOKforeach_reverse 750 { 751 key->value = eupr; 752 753 while (1) 754 { 755 e = Cmp(TOKgt, key->value->type, key->value, lwr); 756 if (e == EXP_CANT_INTERPRET) 757 break; 758 if (e->isBool(TRUE) == FALSE) 759 { e = NULL; 760 break; 761 } 762 763 e = Min(key->value->type, key->value, new IntegerExp(loc, 1, key->value->type)); 764 if (e == EXP_CANT_INTERPRET) 765 break; 766 key->value = e; 767 768 e = body ? body->interpret(istate) : NULL; 769 if (e == EXP_CANT_INTERPRET) 770 break; 771 if (e == EXP_BREAK_INTERPRET) 772 { e = NULL; 773 break; 774 } 775 } 776 } 777 key->value = keysave; 778 return e; 779 } 780 #endif 691 781 692 782 Expression *SwitchStatement::interpret(InterState *istate) … … 1284 1374 BIN_INTERPRET2(Cmp) 1285 1375 1286 Expression *BinExp::interpretAssignCommon(InterState *istate, fp_t fp )1376 Expression *BinExp::interpretAssignCommon(InterState *istate, fp_t fp, int post) 1287 1377 { 1288 1378 #if LOG … … 1323 1413 } 1324 1414 1325 if (fp && !v->value) 1415 Expression *ev = v->value; 1416 if (fp && !ev) 1326 1417 { error("variable %s is used before initialization", v->toChars()); 1327 1418 return e; 1328 1419 } 1329 1420 if (fp) 1330 e2 = (*fp)(v->type, v->value, e2);1421 e2 = (*fp)(v->type, ev, e2); 1331 1422 else 1332 1423 e2 = Cast(v->type, v->type, e2); … … 1346 1437 } 1347 1438 v->value = e2; 1348 e = Cast(type, type, e2);1439 e = Cast(type, type, post ? ev : e2); 1349 1440 } 1350 1441 } … … 1402 1493 } 1403 1494 v->value = new StructLiteralExp(se->loc, se->sd, expsx); 1404 1405 e = Cast(type, type, e2); 1495 v->value->type = se->type; 1496 1497 e = Cast(type, type, post ? ev : e2); 1406 1498 } 1407 1499 /* Assignment to array element of the form: … … 1563 1655 assert(0); 1564 1656 1565 e = Cast(type, type, e2);1657 e = Cast(type, type, post ? ev : e2); 1566 1658 } 1567 1659 else … … 1603 1695 printf("PostExp::interpret() %s\n", toChars()); 1604 1696 #endif 1605 Expression *e = EXP_CANT_INTERPRET; 1606 1607 if (e1->op == TOKvar) 1608 { 1609 VarExp *ve = (VarExp *)e1; 1610 VarDeclaration *v = ve->var->isVarDeclaration(); 1611 if (v && !v->isDataseg()) 1612 { 1613 /* Chase down rebinding of out and ref 1614 */ 1615 if (v->value && v->value->op == TOKvar) 1616 { 1617 ve = (VarExp *)v->value; 1618 v = ve->var->isVarDeclaration(); 1619 assert(v); 1620 } 1621 1622 if (!v->value) 1623 { error("variable %s is used before initialization", v->toChars()); 1624 return e; 1625 } 1626 Expression *e2 = this->e2->interpret(istate); 1627 if (e2 != EXP_CANT_INTERPRET) 1628 { 1629 e = ((op == TOKplusplus) ? &Add : &Min)(v->type, v->value, e2); 1630 if (e != EXP_CANT_INTERPRET) 1631 { 1632 if (v->isAuto()) 1633 { 1634 for (size_t i = 0; 1; i++) 1635 { 1636 if (i == istate->vars.dim) 1637 { istate->vars.push(v); 1638 break; 1639 } 1640 if (v == (VarDeclaration *)istate->vars.data[i]) 1641 break; 1642 } 1643 } 1644 Expression *eold = v->value; 1645 v->value = e; 1646 e = Cast(type, type, eold); 1647 } 1648 } 1649 } 1650 } 1697 Expression *e; 1698 if (op == TOKplusplus) 1699 e = interpretAssignCommon(istate, &Add, 1); 1700 else 1701 e = interpretAssignCommon(istate, &Min, 1); 1702 #if LOG 1703 if (e == EXP_CANT_INTERPRET) 1704 printf("PostExp::interpret() CANT\n"); 1705 #endif 1651 1706 return e; 1652 1707 } … … 1961 2016 // Constant fold *(&structliteral + offset) 1962 2017 if (e1->op == TOKadd) 1963 { 2018 { AddExp *ae = (AddExp *)e1; 2019 if (ae->e1->op == TOKaddress && ae->e2->op == TOKint64) 2020 { AddrExp *ade = (AddrExp *)ae->e1; 2021 Expression *ex = ade->e1; 2022 ex = ex->interpret(istate); 2023 if (ex != EXP_CANT_INTERPRET) 2024 { 2025 if (ex->op == TOKstructliteral) 2026 { StructLiteralExp *se = (StructLiteralExp *)ex; 2027 unsigned offset = ae->e2->toInteger(); 2028 e = se->getField(type, offset); 2029 if (!e) 2030 e = EXP_CANT_INTERPRET; 2031 return e; 2032 } 2033 } 2034 } 1964 2035 e = Ptr(type, e1); 1965 2036 } branches/dmdfe/mars.c
r659 r740 56 56 copyright = "Copyright (c) 1999-2007 by Digital Mars"; 57 57 written = "written by Walter Bright"; 58 version = "v1.01 8";58 version = "v1.019"; 59 59 global.structalign = 8; 60 60 branches/dmdfe/mars.h
r659 r740 252 252 }; 253 253 254 enum MATCH 255 { 256 MATCHnomatch, // no match 257 MATCHconvert, // match with conversions 258 #if V2 259 MATCHconst, // match with conversion to const 260 #endif 261 MATCHexact // exact match 262 }; 263 254 264 void error(Loc loc, const char *format, ...); 255 265 void verror(Loc loc, const char *format, va_list); branches/dmdfe/mtype.c
r659 r740 496 496 */ 497 497 498 intType::implicitConvTo(Type *to)498 MATCH Type::implicitConvTo(Type *to) 499 499 { 500 500 //printf("Type::implicitConvTo(this=%p, to=%p)\n", this, to); … … 504 504 // if (to->ty == Tvoid) 505 505 // return 1; 506 return 0;506 return MATCHnomatch; 507 507 } 508 508 … … 1396 1396 } 1397 1397 1398 intTypeBasic::implicitConvTo(Type *to)1398 MATCH TypeBasic::implicitConvTo(Type *to) 1399 1399 { 1400 1400 //printf("TypeBasic::implicitConvTo(%s) from %s\n", to->toChars(), toChars()); … … 1912 1912 } 1913 1913 1914 intTypeSArray::implicitConvTo(Type *to)1914 MATCH TypeSArray::implicitConvTo(Type *to) 1915 1915 { 1916 1916 //printf("TypeSArray::implicitConvTo()\n"); … … 1921 1921 /*|| to->next->isBaseOf(next)*/)) 1922 1922 { 1923 return 1;1923 return MATCHconvert; 1924 1924 } 1925 1925 if (to->ty == Tarray) … … 1938 1938 if (next->equals(tsa->next) && dim->equals(tsa->dim)) 1939 1939 { 1940 return 1;1940 return MATCHconvert; 1941 1941 } 1942 1942 } … … 2081 2081 } 2082 2082 2083 intTypeDArray::implicitConvTo(Type *to)2083 MATCH TypeDArray::implicitConvTo(Type *to) 2084 2084 { 2085 2085 //printf("TypeDArray::implicitConvTo()\n"); … … 2390 2390 } 2391 2391 2392 intTypePointer::implicitConvTo(Type *to)2392 MATCH TypePointer::implicitConvTo(Type *to) 2393 2393 { 2394 2394 //printf("TypePointer::implicitConvTo()\n"); … … 3802 3802 } 3803 3803 3804 intTypeEnum::implicitConvTo
