Changeset 902
- Timestamp:
- 06/29/08 18:49:05 (3 months ago)
- Files:
-
- branches/dmdfe-2.0/attrib.c (modified) (15 diffs)
- branches/dmdfe-2.0/attrib.h (modified) (1 diff)
- branches/dmdfe-2.0/cast.c (modified) (5 diffs)
- branches/dmdfe-2.0/class.c (modified) (1 diff)
- branches/dmdfe-2.0/constfold.c (modified) (3 diffs)
- branches/dmdfe-2.0/declaration.c (modified) (4 diffs)
- branches/dmdfe-2.0/declaration.h (modified) (5 diffs)
- branches/dmdfe-2.0/doc.c (modified) (3 diffs)
- branches/dmdfe-2.0/dsymbol.c (modified) (1 diff)
- branches/dmdfe-2.0/dsymbol.h (modified) (2 diffs)
- branches/dmdfe-2.0/expression.c (modified) (32 diffs)
- branches/dmdfe-2.0/expression.h (modified) (15 diffs)
- branches/dmdfe-2.0/func.c (modified) (11 diffs)
- branches/dmdfe-2.0/interpret.c (modified) (1 diff)
- branches/dmdfe-2.0/lexer.c (modified) (1 diff)
- branches/dmdfe-2.0/mars.c (modified) (3 diffs)
- branches/dmdfe-2.0/mtype.c (modified) (10 diffs)
- branches/dmdfe-2.0/mtype.h (modified) (1 diff)
- branches/dmdfe-2.0/opover.c (modified) (6 diffs)
- branches/dmdfe-2.0/parse.c (modified) (61 diffs)
- branches/dmdfe-2.0/parse.h (modified) (3 diffs)
- branches/dmdfe-2.0/statement.c (modified) (16 diffs)
- branches/dmdfe-2.0/statement.h (modified) (1 diff)
- branches/dmdfe-2.0/template.c (modified) (47 diffs)
- branches/dmdfe-2.0/template.h (modified) (5 diffs)
- branches/dmdfe-2.0/toir.c (modified) (5 diffs)
- branches/dmdfe-2.0/toobj.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe-2.0/attrib.c
r900 r902 51 51 int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 52 52 { 53 unsigned i;54 53 int m = 0; 55 54 Array *d = include(sc, sd); … … 57 56 if (d) 58 57 { 59 for (i = 0; i < d->dim; i++) 60 { Dsymbol *s; 61 62 s = (Dsymbol *)d->data[i]; 58 for (unsigned i = 0; i < d->dim; i++) 59 { Dsymbol *s = (Dsymbol *)d->data[i]; 63 60 m |= s->addMember(sc, sd, m | memnum); 64 61 } … … 71 68 Array *d = include(sc, NULL); 72 69 73 //printf("\tAttribDeclaration::semantic '%s' \n",toChars());70 //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d); 74 71 if (d) 75 72 { … … 85 82 void AttribDeclaration::semantic2(Scope *sc) 86 83 { 87 unsigned i;88 84 Array *d = include(sc, NULL); 89 85 90 86 if (d) 91 87 { 92 for (i = 0; i < d->dim; i++) 93 { Dsymbol *s; 94 95 s = (Dsymbol *)d->data[i]; 88 for (unsigned i = 0; i < d->dim; i++) 89 { Dsymbol *s = (Dsymbol *)d->data[i]; 96 90 s->semantic2(sc); 97 91 } … … 101 95 void AttribDeclaration::semantic3(Scope *sc) 102 96 { 103 unsigned i;104 97 Array *d = include(sc, NULL); 105 98 106 99 if (d) 107 100 { 108 for (i = 0; i < d->dim; i++) 109 { Dsymbol *s; 110 111 s = (Dsymbol *)d->data[i]; 101 for (unsigned i = 0; i < d->dim; i++) 102 { Dsymbol *s = (Dsymbol *)d->data[i]; 112 103 s->semantic3(sc); 113 104 } … … 117 108 void AttribDeclaration::inlineScan() 118 109 { 119 unsigned i;120 110 Array *d = include(NULL, NULL); 121 111 122 112 if (d) 123 113 { 124 for (i = 0; i < d->dim; i++) 125 { Dsymbol *s; 126 127 s = (Dsymbol *)d->data[i]; 114 for (unsigned i = 0; i < d->dim; i++) 115 { Dsymbol *s = (Dsymbol *)d->data[i]; 128 116 //printf("AttribDeclaration::inlineScan %s\n", s->toChars()); 129 117 s->inlineScan(); … … 136 124 if (comment) 137 125 { 138 unsigned i;139 126 Array *d = include(NULL, NULL); 140 127 141 128 if (d) 142 129 { 143 for (i = 0; i < d->dim; i++) 144 { Dsymbol *s; 145 146 s = (Dsymbol *)d->data[i]; 130 for (unsigned i = 0; i < d->dim; i++) 131 { Dsymbol *s = (Dsymbol *)d->data[i]; 147 132 //printf("AttribDeclaration::addComment %s\n", s->toChars()); 148 133 s->addComment(comment); … … 162 147 // return; 163 148 164 unsigned i;165 149 Array *d = include(NULL, NULL); 166 150 167 151 if (d) 168 152 { 169 for (i = 0; i < d->dim; i++) 170 { Dsymbol *s; 171 172 s = (Dsymbol *)d->data[i]; 153 for (unsigned i = 0; i < d->dim; i++) 154 { Dsymbol *s = (Dsymbol *)d->data[i]; 173 155 //printf("AttribDeclaration::emitComment %s\n", s->toChars()); 174 156 s->emitComment(sc); … … 207 189 void AttribDeclaration::checkCtorConstInit() 208 190 { 209 unsigned i;210 191 Array *d = include(NULL, NULL); 211 192 212 193 if (d) 213 194 { 214 for (i = 0; i < d->dim; i++) 215 { Dsymbol *s; 216 217 s = (Dsymbol *)d->data[i]; 195 for (unsigned i = 0; i < d->dim; i++) 196 { Dsymbol *s = (Dsymbol *)d->data[i]; 218 197 s->checkCtorConstInit(); 219 198 } … … 225 204 226 205 void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses) 227 { unsigned i;206 { 228 207 Array *d = include(NULL, NULL); 229 208 230 209 if (d) 231 210 { 232 for (i = 0; i < d->dim; i++) 233 { Dsymbol *s; 234 235 s = (Dsymbol *)d->data[i]; 211 for (unsigned i = 0; i < d->dim; i++) 212 { Dsymbol *s = (Dsymbol *)d->data[i]; 236 213 s->addLocalClass(aclasses); 237 214 } … … 1042 1019 int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 1043 1020 { 1021 //printf("StaticIfDeclaration::addMember() '%s'\n",toChars()); 1044 1022 /* This is deferred until semantic(), so that 1045 1023 * expressions in the condition can refer to declarations … … 1068 1046 Array *d = include(sc, sd); 1069 1047 1070 //printf("\tStaticIfDeclaration::semantic '%s' \n",toChars());1048 //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); 1071 1049 if (d) 1072 1050 { … … 1098 1076 this->exp = exp; 1099 1077 this->sd = NULL; 1078 this->compiled = 0; 1100 1079 } 1101 1080 … … 1109 1088 int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 1110 1089 { 1090 //printf("CompileDeclaration::addMember(sc = %p)\n", sc); 1111 1091 this->sd = sd; 1092 if (memnum == 0) 1093 { /* No members yet, so parse the mixin now 1094 */ 1095 compileIt(sc); 1096 memnum |= AttribDeclaration::addMember(sc, sd, memnum); 1097 compiled = 1; 1098 } 1112 1099 return memnum; 1113 1100 } 1114 1101 1115 void CompileDeclaration:: semantic(Scope *sc)1116 { 1117 //printf("CompileDeclaration:: semantic()\n");1102 void CompileDeclaration::compileIt(Scope *sc) 1103 { 1104 //printf("CompileDeclaration::compileIt()\n"); 1118 1105 exp = exp->semantic(sc); 1119 1106 exp = resolveProperties(sc, exp); … … 1121 1108 if (exp->op != TOKstring) 1122 1109 { error("argument to mixin must be a string, not (%s)", exp->toChars()); 1123 return; 1124 } 1125 StringExp *se = (StringExp *)exp; 1126 se = se->toUTF8(sc); 1127 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 1128 p.loc = loc; 1129 p.nextToken(); 1130 decl = p.parseDeclDefs(0); 1131 if (p.token.value != TOKeof) 1132 { 1133 error("incomplete mixin declaration (%s)", se->toChars()); 1134 } 1135 1136 AttribDeclaration::addMember(sc, sd, 0); 1110 } 1111 else 1112 { 1113 StringExp *se = (StringExp *)exp; 1114 se = se->toUTF8(sc); 1115 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 1116 p.loc = loc; 1117 p.nextToken(); 1118 decl = p.parseDeclDefs(0); 1119 if (p.token.value != TOKeof) 1120 error("incomplete mixin declaration (%s)", se->toChars()); 1121 } 1122 } 1123 1124 void CompileDeclaration::semantic(Scope *sc) 1125 { 1126 //printf("CompileDeclaration::semantic()\n"); 1127 1128 if (!compiled) 1129 { 1130 compileIt(sc); 1131 AttribDeclaration::addMember(sc, sd, 0); 1132 compiled = 1; 1133 } 1137 1134 AttribDeclaration::semantic(sc); 1138 1135 } branches/dmdfe-2.0/attrib.h
r458 r902 152 152 153 153 ScopeDsymbol *sd; 154 int compiled; 154 155 155 156 CompileDeclaration(Loc loc, Expression *exp); 156 157 Dsymbol *syntaxCopy(Dsymbol *s); 157 158 int addMember(Scope *sc, ScopeDsymbol *sd, int memnum); 159 void compileIt(Scope *sc); 158 160 void semantic(Scope *sc); 159 161 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); branches/dmdfe-2.0/cast.c
r901 r902 1318 1318 } 1319 1319 1320 /************************************ 1321 * Bring leaves to common type. 1320 /************************************** 1321 * Combine types. 1322 * Output: 1323 * *pt merged type, if *pt is not NULL 1324 * *pe1 rewritten e1 1325 * *pe2 rewritten e2 1326 * Returns: 1327 * !=0 success 1328 * 0 failed 1322 1329 */ 1323 1330 1324 Expression *BinExp::typeCombine(Scope *sc) 1325 { 1326 Type *t1; 1327 Type *t2; 1328 Type *t; 1329 TY ty; 1330 1331 //printf("BinExp::typeCombine() %s\n", toChars()); 1331 int typeMerge(Scope *sc, Type **pt, Expression **pe1, Expression **pe2) 1332 { 1333 //printf("typeMerge() %s\n", toChars()); 1332 1334 //dump(0); 1333 1335 1334 e1 = e1->integralPromotions(sc); 1335 e2 = e2->integralPromotions(sc); 1336 1337 // BUG: do toBasetype() 1338 t1 = e1->type; 1339 t2 = e2->type; 1336 Expression *e1 = (*pe1)->integralPromotions(sc); 1337 Expression *e2 = (*pe2)->integralPromotions(sc); 1338 1339 Type *t1 = e1->type; 1340 Type *t2 = e2->type; 1340 1341 assert(t1); 1341 t = t1;1342 Type *t = t1; 1342 1343 1343 1344 //if (t1) printf("\tt1 = %s\n", t1->toChars()); … … 1351 1352 Type *t2b = t2->toBasetype(); 1352 1353 1353 ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty];1354 TY ty = (TY)Type::impcnvResult[t1b->ty][t2b->ty]; 1354 1355 if (ty != Terror) 1355 1356 { TY ty1; … … 1363 1364 if (t1 == t2) 1364 1365 { 1365 if (!type) 1366 type = t1; 1367 return this; 1366 t = t1; 1367 goto Lret; 1368 1368 } 1369 1369 1370 1370 if (t1b == t2b) 1371 1371 { 1372 if (!type) 1373 type = t1b; 1374 return this; 1375 } 1376 } 1377 1378 if (!type) 1379 type = Type::basic[ty]; 1372 t = t1b; 1373 goto Lret; 1374 } 1375 } 1376 1377 t = Type::basic[ty]; 1380 1378 1381 1379 t1 = Type::basic[ty1]; … … 1383 1381 e1 = e1->castTo(sc, t1); 1384 1382 e2 = e2->castTo(sc, t2); 1385 #if 01386 if (type != Type::basic[ty])1387 { t = type;1388 type = Type::basic[ty];1389 return castTo(sc, t);1390 }1391 #endif1392 1383 //printf("after typeCombine():\n"); 1393 1384 //dump(0); 1394 1385 //printf("ty = %d, ty1 = %d, ty2 = %d\n", ty, ty1, ty2); 1395 return this;1386 goto Lret; 1396 1387 } 1397 1388 1398 1389 t1 = t1b; 1399 1390 t2 = t2b; 1391 1392 Lagain: 1393 if (t1 == t2) 1394 { 1395 } 1396 else if (t1->ty == Tpointer && t2->ty == Tpointer) 1397 { 1398 // Bring pointers to compatible type 1399 Type *t1n = t1->nextOf(); 1400 Type *t2n = t2->nextOf(); 1401 1402 if (t1n == t2n) 1403 ; 1404 else if (t1n->ty == Tvoid) // pointers to void are always compatible 1405 t = t2; 1406 else if (t2n->ty == Tvoid) 1407 ; 1408 else if (t1n->mod != t2n->mod) 1409 { 1410 t1 = t1n->mutableOf()->constOf()->pointerTo(); 1411 t2 = t2n->mutableOf()->constOf()->pointerTo(); 1412 t = t1; 1413 goto Lagain; 1414 } 1415 else if (t1n->ty == Tclass && t2n->ty == Tclass) 1416 { ClassDeclaration *cd1 = t1n->isClassHandle(); 1417 ClassDeclaration *cd2 = t2n->isClassHandle(); 1418 int offset; 1419 1420 if (cd1->isBaseOf(cd2, &offset)) 1421 { 1422 if (offset) 1423 e2 = e2->castTo(sc, t); 1424 } 1425 else if (cd2->isBaseOf(cd1, &offset)) 1426 { 1427 t = t2; 1428 if (offset) 1429 e1 = e1->castTo(sc, t); 1430 } 1431 else 1432 goto Lincompatible; 1433 } 1434 else 1435 goto Lincompatible; 1436 } 1437 else if ((t1->ty == Tsarray || t1->ty == Tarray) && 1438 e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty == Tvoid) 1439 { /* (T[n] op void*) 1440 * (T[] op void*) 1441 */ 1442 goto Lx1; 1443 } 1444 else if ((t2->ty == Tsarray || t2->ty == Tarray) && 1445 e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty == Tvoid) 1446 { /* (void* op T[n]) 1447 * (void* op T[]) 1448 */ 1449 goto Lx2; 1450 } 1451 else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2)) 1452 { 1453 goto Lt2; 1454 } 1455 else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1)) 1456 { 1457 goto Lt1; 1458 } 1459 /* If one is mutable and the other invariant, then retry 1460 * with both of them as const 1461 */ 1462 else if ((t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Tpointer) && 1463 (t2->ty == Tsarray || t2->ty == Tarray || t2->ty == Tpointer) && 1464 t1->nextOf()->mod != t2->nextOf()->mod 1465 ) 1466 { 1467 if (t1->ty == Tpointer) 1468 t1 = t1->nextOf()->mutableOf()->constOf()->pointerTo(); 1469 else 1470 t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 1471 1472 if (t2->ty == Tpointer) 1473 t2 = t2->nextOf()->mutableOf()->constOf()->pointerTo(); 1474 else 1475 t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 1476 t = t1; 1477 goto Lagain; 1478 } 1479 else if (t1->ty == Tclass || t2->ty == Tclass) 1480 { 1481 while (1) 1482 { 1483 int i1 = e2->implicitConvTo(t1); 1484 int i2 = e1->implicitConvTo(t2); 1485 1486 if (i1 && i2) 1487 { 1488 // We have the case of class vs. void*, so pick class 1489 if (t1->ty == Tpointer) 1490 i1 = 0; 1491 else if (t2->ty == Tpointer) 1492 i2 = 0; 1493 } 1494 1495 if (i2) 1496 { 1497 goto Lt2; 1498 } 1499 else if (i1) 1500 { 1501 goto Lt1; 1502 } 1503 else if (t1->ty == Tclass && t2->ty == Tclass) 1504 { TypeClass *tc1 = (TypeClass *)t1; 1505 TypeClass *tc2 = (TypeClass *)t2; 1506 1507 /* Pick 'tightest' type 1508 */ 1509 ClassDeclaration *cd1 = tc1->sym->baseClass; 1510 ClassDeclaration *cd2 = tc2->sym->baseClass; 1511 1512 if (cd1 && cd2) 1513 { t1 = cd1->type; 1514 t2 = cd2->type; 1515 } 1516 else if (cd1) 1517 t1 = cd1->type; 1518 else if (cd2) 1519 t2 = cd2->type; 1520 else 1521 goto Lincompatible; 1522 } 1523 else 1524 goto Lincompatible; 1525 } 1526 } 1527 else if (t1->ty == Tstruct && t2->ty == Tstruct) 1528 { 1529 if (((TypeStruct *)t1)->sym != ((TypeStruct *)t2)->sym) 1530 goto Lincompatible; 1531 } 1532 else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) 1533 { 1534 goto Lt2; 1535 } 1536 else if ((e2->op == TOKstring || e2->op == TOKnull) && e2->implicitConvTo(t1)) 1537 { 1538 goto Lt1; 1539 } 1540 else if (t1->ty == Tsarray && t2->ty == Tsarray && 1541 e2->implicitConvTo(t1->nextOf()->arrayOf())) 1542 { 1543 Lx1: 1544 t = t1->nextOf()->arrayOf(); 1545 e1 = e1->castTo(sc, t); 1546 e2 = e2->castTo(sc, t); 1547 } 1548 else if (t1->ty == Tsarray && t2->ty == Tsarray && 1549 e1->implicitConvTo(t2->nextOf()->arrayOf())) 1550 { 1551 Lx2: 1552 t = t2->nextOf()->arrayOf(); 1553 e1 = e1->castTo(sc, t); 1554 e2 = e2->castTo(sc, t); 1555 } 1556 else if (t1->isintegral() && t2->isintegral()) 1557 { 1558 assert(0); 1559 } 1560 else 1561 { 1562 Lincompatible: 1563 return 0; 1564 } 1565 Lret: 1566 if (!*pt) 1567 *pt = t; 1568 *pe1 = e1; 1569 *pe2 = e2; 1570 #if 0 1571 printf("-typeMerge() %s\n", toChars()); 1572 if (e1->type) printf("\tt1 = %s\n", e1->type->toChars()); 1573 if (e2->type) printf("\tt2 = %s\n", e2->type->toChars()); 1574 printf("\ttype = %s\n", type->toChars()); 1575 #endif 1576 //dump(0); 1577 return 1; 1578 1579 1580 Lt1: 1581 e2 = e2->castTo(sc, t1); 1582 t = t1; 1583 goto Lret; 1584 1585 Lt2: 1586 e1 = e1->castTo(sc, t2); 1587 t = t2; 1588 goto Lret; 1589 } 1590 1591 /************************************ 1592 * Bring leaves to common type. 1593 */ 1594 1595 Expression *BinExp::typeCombine(Scope *sc) 1596 { 1597 Type *t1 = e1->type->toBasetype(); 1598 Type *t2 = e2->type->toBasetype(); 1400 1599 1401 1600 if (op == TOKcat) … … 1419 1618 else 1420 1619 e2 = e2->castTo(sc, t2); 1421 t = t1; 1422 goto Lagain; 1423 } 1424 } 1425 1426 Lagain: 1427 if (t1 == t2) 1428 { 1429 if ((t1->ty == Tstruct || t1->ty == Tclass) && 1430 (op == TOKmin || op == TOKadd)) 1431 goto Lincompatible; 1432 } 1433 else if (t1->ty == Tpointer && t2->ty == Tpointer) 1434 { 1435 // Bring pointers to compatible type 1436 Type *t1n = t1->nextOf(); 1437 Type *t2n = t2->nextOf(); 1438 1439 if (t1n == t2n) 1440 ; 1441 else if (t1n->ty == Tvoid) // pointers to void are always compatible 1442 t = t2; 1443 else if (t2n->ty == Tvoid) 1444 ; 1445 else if (t1n->mod != t2n->mod) 1446 { 1447 t1 = t1n->mutableOf()->constOf()->pointerTo(); 1448 t2 = t2n->mutableOf()->constOf()->pointerTo(); 1449 t = t1; 1450 goto Lagain; 1451 } 1452 else if (t1n->ty == Tclass && t2n->ty == Tclass) 1453 { ClassDeclaration *cd1 = t1n->isClassHandle(); 1454 ClassDeclaration *cd2 = t2n->isClassHandle(); 1455 int offset; 1456 1457 if (cd1->isBaseOf(cd2, &offset)) 1458 { 1459 if (offset) 1460 e2 = e2->castTo(sc, t); 1461 } 1462 else if (cd2->isBaseOf(cd1, &offset)) 1463 { 1464 t = t2; 1465 if (offset) 1466 e1 = e1->castTo(sc, t); 1467 } 1468 else 1469 goto Lincompatible; 1470 } 1471 else 1472 goto Lincompatible; 1473 } 1474 else if ((t1->ty == Tsarray || t1->ty == Tarray) && 1475 e2->op == TOKnull && t2->ty == Tpointer && t2->nextOf()->ty == Tvoid) 1476 { /* (T[n] op void*) 1477 * (T[] op void*) 1478 */ 1479 goto Lx1; 1480 } 1481 else if ((t2->ty == Tsarray || t2->ty == Tarray) && 1482 e1->op == TOKnull && t1->ty == Tpointer && t1->nextOf()->ty == Tvoid) 1483 { /* (void* op T[n]) 1484 * (void* op T[]) 1485 */ 1486 goto Lx2; 1487 } 1488 else if ((t1->ty == Tsarray || t1->ty == Tarray) && t1->implicitConvTo(t2)) 1489 { 1490 goto Lt2; 1491 } 1492 else if ((t2->ty == Tsarray || t2->ty == Tarray) && t2->implicitConvTo(t1)) 1493 { 1494 goto Lt1; 1495 } 1496 /* If one is mutable and the other invariant, then retry 1497 * with both of them as const 1498 */ 1499 else if ((t1->ty == Tsarray || t1->ty == Tarray || t1->ty == Tpointer) && 1500 (t2->ty == Tsarray || t2->ty == Tarray || t2->ty == Tpointer) && 1501 t1->nextOf()->mod != t2->nextOf()->mod 1502 ) 1503 { 1504 if (t1->ty == Tpointer) 1505 t1 = t1->nextOf()->mutableOf()->constOf()->pointerTo(); 1506 else 1507 t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 1508 1509 if (t2->ty == Tpointer) 1510 t2 = t2->nextOf()->mutableOf()->constOf()->pointerTo(); 1511 else 1512 t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 1513 t = t1; 1514 goto Lagain; 1515 } 1516 else if (t1->ty == Tclass || t2->ty == Tclass) 1517 { 1518 while (1) 1519 { 1520 int i1 = e2->implicitConvTo(t1); 1521 int i2 = e1->implicitConvTo(t2); 1522 1523 if (i1 && i2) 1524 { 1525 // We have the case of class vs. void*, so pick class 1526 if (t1->ty == Tpointer) 1527 i1 = 0; 1528 else if (t2->ty == Tpointer) 1529 i2 = 0; 1530 } 1531 1532 if (i2) 1533 { 1534 goto Lt2; 1535 } 1536 else if (i1) 1537 { 1538 goto Lt1; 1539 } 1540 else if (t1->ty == Tclass && t2->ty == Tclass) 1541 { TypeClass *tc1 = (TypeClass *)t1; 1542 TypeClass *tc2 = (TypeClass *)t2; 1543 1544 /* Pick 'tightest' type 1545 */ 1546 ClassDeclaration *cd1 = tc1->sym->baseClass; 1547 ClassDeclaration *cd2 = tc1->sym->baseClass; 1548 1549 if (cd1 && cd2) 1550 { t1 = cd1->type; 1551 t2 = cd2->type; 1552 } 1553 else if (cd1) 1554 t1 = cd1->type; 1555 else if (cd2) 1556 t2 = cd2->type; 1557 else 1558 goto Lincompatible; 1559 } 1560 else 1561 goto Lincompatible; 1562 } 1563 } 1564 else if (t1->ty == Tstruct && t2->ty == Tstruct) 1565 { 1566 if (((TypeStruct *)t1)->sym != ((TypeStruct *)t2)->sym) 1567 goto Lincompatible; 1568 } 1569 else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) 1570 { 1571 goto Lt2; 1572 } 1573 else if ((e2->op == TOKstring || e2->op == TOKnull) && e2->implicitConvTo(t1)) 1574 { 1575 goto Lt1; 1576 } 1577 else if (t1->ty == Tsarray && t2->ty == Tsarray && 1578 e2->implicitConvTo(t1->nextOf()->arrayOf())) 1579 { 1580 Lx1: 1581 t = t1->nextOf()->arrayOf(); 1582 e1 = e1->castTo(sc, t); 1583 e2 = e2->castTo(sc, t); 1584 } 1585 else if (t1->ty == Tsarray && t2->ty == Tsarray && 1586 e1->implicitConvTo(t2->nextOf()->arrayOf())) 1587 { 1588 Lx2: 1589 t = t2->nextOf()->arrayOf(); 1590 e1 = e1->castTo(sc, t); 1591 e2 = e2->castTo(sc, t); 1592 } 1593 else if (t1->isintegral() && t2->isintegral()) 1594 { 1595 assert(0); 1596 } 1597 else 1598 { 1599 Lincompatible: 1600 incompatibleTypes(); 1601 } 1602 Lret: 1603 if (!type) 1604 type = t; 1605 #if 0 1606 printf("-BinExp::typeCombine() %s\n", toChars()); 1607 if (e1->type) printf("\tt1 = %s\n", e1->type->toChars()); 1608 if (e2->type) printf("\tt2 = %s\n", e2->type->toChars()); 1609 printf("\ttype = %s\n", type->toChars()); 1610 #endif 1611 //dump(0); 1620 } 1621 } 1622 else if (op == TOKmin || op == TOKadd) 1623 { 1624 if (t1 == t2 && (t1->ty == Tstruct || t1->ty == Tclass)) 1625 goto Lerror; 1626 } 1627 1628 if (!typeMerge(sc, &type, &e1, &e2)) 1629 goto Lerror; 1612 1630 return this; 1613 1631 1614 1615 Lt1: 1616 e2 = e2->castTo(sc, t1); 1617 t = t1; 1618 goto Lret; 1619 1620 Lt2: 1621 e1 = e1->castTo(sc, t2); 1622 t = t2; 1623 goto Lret; 1632 Lerror: 1633 incompatibleTypes(); 1634 type = Type::terror; 1635 return this; 1624 1636 } 1625 1637 branches/dmdfe-2.0/class.c
r900 r902 816 816 int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) 817 817 { 818 //printf("ClassDeclaration::isFuncHidden( %s)\n", fd->toChars());818 //printf("ClassDeclaration::isFuncHidden(class = %s, fd = %s)\n", toChars(), fd->toChars()); 819 819 Dsymbol *s = search(0, fd->ident, 4|2); 820 820 if (!s) branches/dmdfe-2.0/constfold.c
r880 r902 1079 1079 return expType(to, e1); 1080 1080 1081 Type *tb = to->toBasetype(); 1082 Type *typeb = type->toBasetype(); 1083 1084 if (e1->op == TOKstring) 1085 { 1086 if (tb->ty == Tarray && typeb->ty == Tarray && 1087 tb->nextOf()->size() == typeb->nextOf()->size()) 1088 { 1089 return expType(to, e1); 1090 } 1091 } 1092 1081 1093 if (e1->isConst() != 1) 1082 1094 return EXP_CANT_INTERPRET; 1083 1095 1084 Type *tb = to->toBasetype();1085 1096 if (tb->ty == Tbool) 1086 1097 e = new IntegerExp(loc, e1->toInteger() != 0, type); … … 1091 1102 real_t r = e1->toReal(); 1092 1103 1093 switch (type ->toBasetype()->ty)1104 switch (typeb->ty) 1094 1105 { 1095 1106 case Tint8: result = (d_int8)r; break; … … 1468 1479 e->type = type; 1469 1480 } 1470 else if ( e1->op == TOKarrayliteral&&1481 else if ((e1->op == TOKarrayliteral || e1->op == TOKnull) && 1471 1482 e1->type->toBasetype()->nextOf()->equals(e2->type)) 1472 1483 { 1473 ArrayLiteralExp *es1 = (ArrayLiteralExp *)e1; 1474 1475 es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy()); 1476 es1->elements->push(e2); 1484 ArrayLiteralExp *es1; 1485 if (e1->op == TOKarrayliteral) 1486 { es1 = (ArrayLiteralExp *)e1; 1487 es1 = new ArrayLiteralExp(es1->loc, (Expressions *)es1->elements->copy()); 1488 es1->elements->push(e2); 1489 } 1490 else 1491 { 1492 es1 = new ArrayLiteralExp(e1->loc, e2); 1493 } 1477 1494 e = es1; 1478 1495 branches/dmdfe-2.0/declaration.c
r901 r902 87 87 */ 88 88 89 #if V2 89 90 void Declaration::checkModify(Loc loc, Scope *sc, Type *t) 90 91 { … … 148 149 } 149 150 } 151 #endif 150 152 151 153 … … 660 662 void VarDeclaration::semantic(Scope *sc) 661 663 { 662 //printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 663 //printf(" type = %s\n", type ? type->toChars() : "null"); 664 //printf(" stc = x%x\n", sc->stc); 665 //printf(" storage_class = x%x\n", storage_class); 666 //printf("linkage = %d\n", sc->linkage); 664 #if 0 665 printf("VarDeclaration::semantic('%s', parent = '%s')\n", toChars(), sc->parent->toChars()); 666 printf(" type = %s\n", type ? type->toChars() : "null"); 667 printf(" stc = x%x\n", sc->stc); 668 printf(" storage_class = x%x\n", storage_class); 669 printf("linkage = %d\n", sc->linkage); 667 670 //if (strcmp(toChars(), "mul") == 0) halt(); 671 #endif 668 672 669 673 storage_class |= sc->stc; … … 1109 1113 void VarDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 1110 1114 { 1115 if (storage_class & STCconst) 1116 buf->writestring("const "); 1117 if (storage_class & STCstatic) 1118 buf->writestring("static "); 1119 if (storage_class & STCauto) 1120 buf->writestring("auto "); 1121 #if V2 1111 1122 if (storage_class & STCmanifest) 1112 1123 buf->writestring("manifest "); 1113 if (storage_class & STCstatic)1114 buf->writestring("static ");1115 if (storage_class & STCtls)1116 buf->writestring("__tls ");1117 if (storage_class & STCconst)1118 buf->writestring("const ");1119 1124 if (storage_class & STCinvariant) 1120 1125 buf->writestring("invariant "); 1126 if (storage_class & STCtls) 1127 buf->writestring("__thread "); 1128 #endif 1121 1129 1122 1130 if (type) branches/dmdfe-2.0/declaration.h
r901 r902 70 70 STCpure = 0x4000000, // pure function 71 71 STCtls = 0x8000000, // thread local 72 STCalias = 0x10000000, // alias parameter 72 73 }; 73 74 … … 257 258 VarDeclaration *isVarDeclaration() { return (VarDeclaration *)this; } 258 259 }; 259 260 260 261 261 /**************************************************************/ … … 567 567 }; 568 568 569 #if V2 569 570 struct PostBlitDeclaration : FuncDeclaration 570 571 { … … 582 583 PostBlitDeclaration *isPostBlitDeclaration() { return this; } 583 584 }; 585 #endif 584 586 585 587 struct DtorDeclaration : FuncDeclaration … … 616 618 617 619 struct StaticDtorDeclaration : FuncDeclaration 618 { 620 { VarDeclaration *vgate; // 'gate' variable 621 619 622 StaticDtorDeclaration(Loc loc, Loc endloc); 620 623 Dsymbol *syntaxCopy(Dsymbol *); branches/dmdfe-2.0/doc.c
r882 r902 401 401 void ScopeDsymbol::emitMemberComments(Scope *sc) 402 402 { 403 //printf("ScopeDsymbol::emitMemberComments() \n");403 //printf("ScopeDsymbol::emitMemberComments() %s\n", toChars()); 404 404 OutBuffer *buf = sc->docbuf; 405 405 … … 744 744 (td = parent->isTemplateDeclaration()) != NULL && 745 745 td->onemember == this) 746 { HdrGenState hgs; 746 { /* It's a function template 747 */ 748 HdrGenState hgs; 747 749 unsigned o = buf->offset; 748 750 TypeFunction *tf = (TypeFunction *)type; … … 1582 1584 if (f && f->type) 1583 1585 { 1584 TypeFunction *tf = (TypeFunction *)f->type; 1586 TypeFunction *tf; 1587 if (f->originalType) 1588 { 1589 tf = (TypeFunction *)f->originalType; 1590 } 1591 else 1592 tf = (TypeFunction *)f->type; 1585 1593 1586 1594 if (tf->parameters) branches/dmdfe-2.0/dsymbol.c
r883 r902 236 236 } 237 237 238 TemplateInstance *Dsymbol::inTemplateInstance() 239 { 240 for (Dsymbol *parent = this->parent; parent; parent = parent->parent) 241 { 242 TemplateInstance *ti = parent->isTemplateInstance(); 243 if (ti) 244 return ti; 245 } 246 return NULL; 247 } 238 248 239 249 int Dsymbol::isAnonymous() branches/dmdfe-2.0/dsymbol.h
r883 r902 56 56 struct WithStatement; 57 57 struct LabelDsymbol; 58 struct ScopeDsymbol;59 58 struct TemplateDeclaration; 60 59 struct TemplateInstance; … … 116 115 Dsymbol *toParent(); 117 116 Dsymbol *toParent2(); 117 TemplateInstance *inTemplateInstance(); 118 118 119 119 int dyncast() { return DYNCAST_DSYMBOL; } // kludge for template.isSymbol() branches/dmdfe-2.0/expression.c
r901 r902 112 112 precedence[TOKfunction] = PREC_primary; 113 113 precedence[TOKvar] = PREC_primary; 114 #if V2 114 115 precedence[TOKdefault] = PREC_primary; 116 #endif 115 117 116 118 // post … … 241 243 242 244 e1 = new DotVarExp(loc, e1, tcd->vthis); 243 e1 = e1->semantic(sc); 245 e1->type = tcd->vthis->type; 246 // Do not call checkNestedRef() 247 //e1 = e1->semantic(sc); 244 248 245 249 // Skip up over nested functions, and get the enclosing 246 250 // class type. 251 int n = 0; 247 252 Dsymbol *s; 248 253 for (s = tcd->toParent(); … … 251 256 { FuncDeclaration *f = s->isFuncDeclaration(); 252 257 if (f->vthis) 253 { 258 &
