Changeset 903
- Timestamp:
- 06/29/08 19:09:51 (4 months ago)
- Files:
-
- trunk/rebuild/aggregate.h (modified) (3 diffs)
- trunk/rebuild/attrib.c (modified) (20 diffs)
- trunk/rebuild/attrib.h (modified) (1 diff)
- trunk/rebuild/cast.c (modified) (10 diffs)
- trunk/rebuild/class.c (modified) (9 diffs)
- trunk/rebuild/constfold.c (modified) (3 diffs)
- trunk/rebuild/declaration.c (modified) (12 diffs)
- trunk/rebuild/declaration.h (modified) (10 diffs)
- trunk/rebuild/doc.c (modified) (3 diffs)
- trunk/rebuild/dsymbol.c (modified) (1 diff)
- trunk/rebuild/dsymbol.h (modified) (2 diffs)
- trunk/rebuild/expression.c (modified) (35 diffs)
- trunk/rebuild/expression.h (modified) (17 diffs)
- trunk/rebuild/func.c (modified) (22 diffs)
- trunk/rebuild/idgen.c (modified) (1 diff)
- trunk/rebuild/init.c (modified) (1 diff)
- trunk/rebuild/interpret.c (modified) (5 diffs)
- trunk/rebuild/lexer.c (modified) (3 diffs)
- trunk/rebuild/lexer.h (modified) (1 diff)
- trunk/rebuild/lib.h (copied) (copied from branches/dmdfe-2.0/lib.h)
- trunk/rebuild/libelf.c (copied) (copied from branches/dmdfe-2.0/libelf.c)
- trunk/rebuild/link.c (modified) (1 diff)
- trunk/rebuild/man.c (copied) (copied from branches/dmdfe-2.0/man.c)
- trunk/rebuild/mars.c (modified) (16 diffs)
- trunk/rebuild/mars.h (modified) (5 diffs)
- trunk/rebuild/module.c (modified) (4 diffs)
- trunk/rebuild/module.h (modified) (3 diffs)
- trunk/rebuild/mtype.c (modified) (41 diffs)
- trunk/rebuild/mtype.h (modified) (3 diffs)
- trunk/rebuild/opover.c (modified) (7 diffs)
- trunk/rebuild/optimize.c (modified) (7 diffs)
- trunk/rebuild/parse.c (modified) (66 diffs)
- trunk/rebuild/parse.h (modified) (3 diffs)
- trunk/rebuild/root.c (modified) (3 diffs)
- trunk/rebuild/root.h (modified) (1 diff)
- trunk/rebuild/statement.c (modified) (21 diffs)
- trunk/rebuild/statement.h (modified) (2 diffs)
- trunk/rebuild/stringtable.c (modified) (1 diff)
- trunk/rebuild/stringtable.h (modified) (1 diff)
- trunk/rebuild/struct.c (modified) (1 diff)
- trunk/rebuild/template.c (modified) (70 diffs)
- trunk/rebuild/template.h (modified) (13 diffs)
- trunk/rebuild/total.h (modified) (1 diff)
- trunk/rebuild/traits.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/rebuild/aggregate.h
r884 r903 107 107 { 108 108 int zeroInit; // !=0 if initialize with 0 fill 109 #if V2 109 110 int hasIdentityAssign; // !=0 if has identity opAssign 110 111 FuncDeclaration *cpctor; // generated copy-constructor, if any … … 112 113 FuncDeclarations postblits; // Array of postblit functions 113 114 FuncDeclaration *postblit; // aggregate postblit 115 #endif 114 116 115 117 StructDeclaration(Loc loc, Identifier *id); … … 200 202 VarDeclaration *vthis; // 'this' parameter if this class is nested 201 203 204 int inuse; // to prevent recursive attempts 205 202 206 ClassDeclaration(Loc loc, Identifier *id, BaseClasses *baseclasses); 203 207 Dsymbol *syntaxCopy(Dsymbol *s); trunk/rebuild/attrib.c
r884 r903 53 53 int AttribDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 54 54 { 55 unsigned i;56 55 int m = 0; 57 56 Array *d = include(sc, sd); … … 59 58 if (d) 60 59 { 61 for (i = 0; i < d->dim; i++) 62 { Dsymbol *s; 63 64 s = (Dsymbol *)d->data[i]; 60 for (unsigned i = 0; i < d->dim; i++) 61 { Dsymbol *s = (Dsymbol *)d->data[i]; 65 62 m |= s->addMember(sc, sd, m | memnum); 66 63 } … … 73 70 Array *d = include(sc, NULL); 74 71 75 //printf("\tAttribDeclaration::semantic '%s' \n",toChars());72 //printf("\tAttribDeclaration::semantic '%s', d = %p\n",toChars(), d); 76 73 if (d) 77 74 { … … 87 84 void AttribDeclaration::semantic2(Scope *sc) 88 85 { 89 unsigned i;90 86 Array *d = include(sc, NULL); 91 87 92 88 if (d) 93 89 { 94 for (i = 0; i < d->dim; i++) 95 { Dsymbol *s; 96 97 s = (Dsymbol *)d->data[i]; 90 for (unsigned i = 0; i < d->dim; i++) 91 { Dsymbol *s = (Dsymbol *)d->data[i]; 98 92 s->semantic2(sc); 99 93 } … … 103 97 void AttribDeclaration::semantic3(Scope *sc) 104 98 { 105 unsigned i;106 99 Array *d = include(sc, NULL); 107 100 108 101 if (d) 109 102 { 110 for (i = 0; i < d->dim; i++) 111 { Dsymbol *s; 112 113 s = (Dsymbol *)d->data[i]; 103 for (unsigned i = 0; i < d->dim; i++) 104 { Dsymbol *s = (Dsymbol *)d->data[i]; 114 105 s->semantic3(sc); 115 106 } … … 119 110 void AttribDeclaration::inlineScan() 120 111 { 121 unsigned i;122 112 Array *d = include(NULL, NULL); 123 113 124 114 if (d) 125 115 { 126 for (i = 0; i < d->dim; i++) 127 { Dsymbol *s; 128 129 s = (Dsymbol *)d->data[i]; 116 for (unsigned i = 0; i < d->dim; i++) 117 { Dsymbol *s = (Dsymbol *)d->data[i]; 130 118 //printf("AttribDeclaration::inlineScan %s\n", s->toChars()); 131 119 s->inlineScan(); … … 138 126 if (comment) 139 127 { 140 unsigned i;141 128 Array *d = include(NULL, NULL); 142 129 143 130 if (d) 144 131 { 145 for (i = 0; i < d->dim; i++) 146 { Dsymbol *s; 147 148 s = (Dsymbol *)d->data[i]; 132 for (unsigned i = 0; i < d->dim; i++) 133 { Dsymbol *s = (Dsymbol *)d->data[i]; 149 134 //printf("AttribDeclaration::addComment %s\n", s->toChars()); 150 135 s->addComment(comment); … … 164 149 // return; 165 150 166 unsigned i;167 151 Array *d = include(NULL, NULL); 168 152 169 153 if (d) 170 154 { 171 for (i = 0; i < d->dim; i++) 172 { Dsymbol *s; 173 174 s = (Dsymbol *)d->data[i]; 155 for (unsigned i = 0; i < d->dim; i++) 156 { Dsymbol *s = (Dsymbol *)d->data[i]; 175 157 //printf("AttribDeclaration::emitComment %s\n", s->toChars()); 176 158 s->emitComment(sc); … … 209 191 void AttribDeclaration::checkCtorConstInit() 210 192 { 211 unsigned i;212 193 Array *d = include(NULL, NULL); 213 194 214 195 if (d) 215 196 { 216 for (i = 0; i < d->dim; i++) 217 { Dsymbol *s; 218 219 s = (Dsymbol *)d->data[i]; 197 for (unsigned i = 0; i < d->dim; i++) 198 { Dsymbol *s = (Dsymbol *)d->data[i]; 220 199 s->checkCtorConstInit(); 221 200 } … … 227 206 228 207 void AttribDeclaration::addLocalClass(ClassDeclarations *aclasses) 229 { unsigned i;208 { 230 209 Array *d = include(NULL, NULL); 231 210 232 211 if (d) 233 212 { 234 for (i = 0; i < d->dim; i++) 235 { Dsymbol *s; 236 237 s = (Dsymbol *)d->data[i]; 213 for (unsigned i = 0; i < d->dim; i++) 214 { Dsymbol *s = (Dsymbol *)d->data[i]; 238 215 s->addLocalClass(aclasses); 239 216 } … … 314 291 if (stc & (STCauto | STCscope | STCstatic | STCextern | STCmanifest)) 315 292 sc->stc &= ~(STCauto | STCscope | STCstatic | STCextern | STCmanifest); 293 if (stc & (STCauto | STCscope | STCstatic | STCtls | STCmanifest)) 294 sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls | STCmanifest); 316 295 if (stc & (STCconst | STCinvariant | STCmanifest)) 317 296 sc->stc &= ~(STCconst | STCinvariant | STCmanifest); … … 350 329 { STCdeprecated, TOKdeprecated }, 351 330 { STCoverride, TOKoverride }, 331 { STCnothrow, TOKnothrow }, 332 { STCpure, TOKpure }, 333 { STCtls, TOKtls }, 352 334 }; 353 335 … … 614 596 sc = sc->push(); 615 597 sc->anonAgg = &aad; 616 sc->stc &= ~(STCauto | STCscope | STCstatic );598 sc->stc &= ~(STCauto | STCscope | STCstatic | STCtls); 617 599 sc->inunion = isunion; 618 600 sc->offset = 0; … … 841 823 if (!sa || !sa->isFuncDeclaration()) 842 824 error("function name expected for start address, not '%s'", e->toChars()); 825 } 826 goto Lnodecl; 827 } 828 else if (global.params.ignoreUnsupportedPragmas) 829 { 830 if (global.params.verbose) 831 { 832 / * Print unrecognized pragmas 833 * / 834 printf("pragma %s", ident->toChars()); 835 if (args) 836 { 837 for (size_t i = 0; i < args->dim; i++) 838 { 839 Expression *e = (Expression *)args->data[i]; 840 e = e->semantic(sc); 841 e = e->optimize(WANTvalue | WANTinterpret); 842 if (i == 0) 843 printf(" ("); 844 else 845 printf(","); 846 printf("%s", e->toChars()); 847 } 848 if (args->dim) 849 printf(")"); 850 } 851 printf("\n"); 843 852 } 844 853 goto Lnodecl; … … 930 939 void PragmaDeclaration::toCBuffer(OutBuffer *buf, HdrGenState *hgs) 931 940 { 932 buf->printf("pragma(%s", ident->toChars()); 933 if (args) 934 { 935 for (size_t i = 0; i < args->dim; i++) 936 { 937 Expression *e = (Expression *)args->data[i]; 938 939 buf->writestring(", "); 940 e->toCBuffer(buf, hgs); 941 } 942 } 943 buf->writestring(")"); 941 buf->printf("pragma (%s", ident->toChars()); 942 if (args && args->dim) 943 { 944 buf->writestring(", "); 945 argsToCBuffer(buf, args, hgs); 946 } 947 buf->writeByte(')'); 944 948 AttribDeclaration::toCBuffer(buf, hgs); 945 949 } … … 1139 1143 int StaticIfDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 1140 1144 { 1145 //printf("StaticIfDeclaration::addMember() '%s'\n",toChars()); 1141 1146 /* This is deferred until semantic(), so that 1142 1147 * expressions in the condition can refer to declarations … … 1165 1170 Array *d = include(sc, sd); 1166 1171 1167 //printf("\tStaticIfDeclaration::semantic '%s' \n",toChars());1172 //printf("\tStaticIfDeclaration::semantic '%s', d = %p\n",toChars(), d); 1168 1173 if (d) 1169 1174 { … … 1195 1200 this->exp = exp; 1196 1201 this->sd = NULL; 1202 this->compiled = 0; 1197 1203 } 1198 1204 … … 1206 1212 int CompileDeclaration::addMember(Scope *sc, ScopeDsymbol *sd, int memnum) 1207 1213 { 1214 //printf("CompileDeclaration::addMember(sc = %p)\n", sc); 1208 1215 this->sd = sd; 1216 if (memnum == 0) 1217 { /* No members yet, so parse the mixin now 1218 */ 1219 compileIt(sc); 1220 memnum |= AttribDeclaration::addMember(sc, sd, memnum); 1221 compiled = 1; 1222 } 1209 1223 return memnum; 1210 1224 } 1211 1225 1212 void CompileDeclaration:: semantic(Scope *sc)1213 { 1214 //printf("CompileDeclaration:: semantic()\n");1226 void CompileDeclaration::compileIt(Scope *sc) 1227 { 1228 //printf("CompileDeclaration::compileIt()\n"); 1215 1229 exp = exp->semantic(sc); 1216 1230 exp = resolveProperties(sc, exp); … … 1218 1232 if (exp->op != TOKstring) 1219 1233 { //error("argument to mixin must be a string, not (%s)", exp->toChars()); 1220 return; 1221 } 1222 StringExp *se = (StringExp *)exp; 1223 se = se->toUTF8(sc); 1224 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 1225 p.loc = loc; 1226 p.nextToken(); 1227 decl = p.parseDeclDefs(0); 1228 if (p.token.value != TOKeof) 1229 { 1230 //error("incomplete mixin declaration (%s)", se->toChars()); 1231 } 1232 1233 AttribDeclaration::addMember(sc, sd, 0); 1234 } 1235 else 1236 { 1237 StringExp *se = (StringExp *)exp; 1238 se = se->toUTF8(sc); 1239 Parser p(sc->module, (unsigned char *)se->string, se->len, 0); 1240 p.loc = loc; 1241 p.nextToken(); 1242 decl = p.parseDeclDefs(0); 1243 /*if (p.token.value != TOKeof) 1244 error("incomplete mixin declaration (%s)", se->toChars());*/ 1245 } 1246 } 1247 1248 void CompileDeclaration::semantic(Scope *sc) 1249 { 1250 //printf("CompileDeclaration::semantic()\n"); 1251 1252 if (!compiled) 1253 { 1254 compileIt(sc); 1255 AttribDeclaration::addMember(sc, sd, 0); 1256 compiled = 1; 1257 } 1234 1258 AttribDeclaration::semantic(sc); 1235 1259 } trunk/rebuild/attrib.h
r459 r903 158 158 159 159 ScopeDsymbol *sd; 160 int compiled; 160 161 161 162 CompileDeclaration(Loc loc, Expression *exp); 162 163 Dsymbol *syntaxCopy(Dsymbol *s); 163 164 int addMember(Scope *sc, ScopeDsymbol *sd, int memnum); 165 void compileIt(Scope *sc); 164 166 void semantic(Scope *sc); 165 167 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); trunk/rebuild/cast.c
r884 r903 1 1 2 // Copyright (c) 1999-200 7by Digital Mars2 // Copyright (c) 1999-2008 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("Expression::implicitCastTo(%s) => %s\n", type->toChars(), t->toChars()); 35 //printf("%s\n", toChars()); 34 //printf("Expression::implicitCastTo(%s of type %s) => %s\n", toChars(), type->toChars(), t->toChars()); 36 35 37 36 MATCH match = implicitConvTo(t); … … 104 103 toChars(), type->toChars(), t->toChars()); 105 104 #endif 106 //static int nest; if (++nest == 50) halt();105 //static int nest; if (++nest == 10) halt(); 107 106 if (!type) 108 107 { //error("%s is not an expression", toChars()); … … 1087 1086 { 1088 1087 #if 0 1089 printf("ArrayLiteralExp::castTo(this=%s, type=%s, t=%s)\n",1088 printf("ArrayLiteralExp::castTo(this=%s, type=%s, => %s)\n", 1090 1089 toChars(), type->toChars(), t->toChars()); 1091 1090 #endif … … 1097 1096 if ((tb->ty == Tarray || tb->ty == Tsarray) && 1098 1097 (typeb->ty == Tarray || typeb->ty == Tsarray) && 1099 tb->nextOf()->toBasetype()->ty != Tvoid) 1098 // Not trying to convert non-void[] to void[] 1099 !(tb->nextOf()->toBasetype()->ty == Tvoid && typeb->nextOf()->toBasetype()->ty != Tvoid)) 1100 1100 { 1101 1101 if (tb->ty == Tsarray) … … 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 { int i1; 1518 int i2; 1519 1520 i1 = e2->implicitConvTo(t1); 1521 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 1541 goto Lincompatible; 1542 } 1543 else if (t1->ty == Tstruct && t2->ty == Tstruct) 1544 { 1545 if (((TypeStruct *)t1)->sym != ((TypeStruct *)t2)->sym) 1546 goto Lincompatible; 1547 } 1548 else if ((e1->op == TOKstring || e1->op == TOKnull) && e1->implicitConvTo(t2)) 1549 { 1550 goto Lt2; 1551 } 1552 else if ((e2->op == TOKstring || e2->op == TOKnull) && e2->implicitConvTo(t1)) 1553 { 1554 goto Lt1; 1555 } 1556 else if (t1->ty == Tsarray && t2->ty == Tsarray && 1557 e2->implicitConvTo(t1->nextOf()->arrayOf())) 1558 { 1559 Lx1: 1560 t = t1->nextOf()->arrayOf(); 1561 e1 = e1->castTo(sc, t); 1562 e2 = e2->castTo(sc, t); 1563 } 1564 else if (t1->ty == Tsarray && t2->ty == Tsarray && 1565 e1->implicitConvTo(t2->nextOf()->arrayOf())) 1566 { 1567 Lx2: 1568 t = t2->nextOf()->arrayOf(); 1569 e1 = e1->castTo(sc, t); 1570 e2 = e2->castTo(sc, t); 1571 } 1572 else if (t1->isintegral() && t2->isintegral()) 1573 { 1574 assert(0); 1575 } 1576 else 1577 { 1578 Lincompatible: 1579 incompatibleTypes(); 1580 } 1581 Lret: 1582 if (!type) 1583 type = t; 1584 #if 0 1585 printf("-BinExp::typeCombine() %s\n", toChars()); 1586 if (e1->type) printf("\tt1 = %s\n", e1->type->toChars()); 1587 if (e2->type) printf("\tt2 = %s\n", e2->type->toChars()); 1588 printf("\ttype = %s\n", type->toChars()); 1589 #endif 1590 //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; 1591 1630 return this; 1592 1631 1593 1594 Lt1: 1595 e2 = e2->castTo(sc, t1); 1596 t = t1; 1597 goto Lret; 1598 1599 Lt2: 1600 e1 = e1->castTo(sc, t2); 1601 t = t2; 1602 goto Lret; 1632 Lerror: 1633 incompatibleTypes(); 1634 type = Type::terror; 1635 return this; 1603 1636 } 1604 1637 trunk/rebuild/class.c
r884 r903 187 187 isnested = 0; 188 188 vthis = NULL; 189 inuse = 0; 189 190 } 190 191 … … 530 531 sc = sc->push(this); 531 532 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 532 STCabstract | STCdeprecated | STCconst | STCinvariant );533 STCabstract | STCdeprecated | STCconst | STCinvariant | STCtls); 533 534 sc->stc |= storage_class & (STCconst | STCinvariant); 534 535 sc->parent = this; … … 575 576 scope->module->addDeferredSemantic(this); 576 577 577 //printf("\tsemantic('%s') failed \n", toChars());578 //printf("\tsemantic('%s') failed due to forward references\n", toChars()); 578 579 return; 579 580 } … … 815 816 int ClassDeclaration::isFuncHidden(FuncDeclaration *fd) 816 817 { 817 //printf("ClassDeclaration::isFuncHidden( %s)\n", fd->toChars());818 //printf("ClassDeclaration::isFuncHidden(class = %s, fd = %s)\n", toChars(), fd->toChars()); 818 819 Dsymbol *s = search(0, fd->ident, 4|2); 819 820 if (!s) … … 1014 1015 1015 1016 //printf("InterfaceDeclaration::semantic(%s), type = %p\n", toChars(), type); 1017 if (inuse) 1018 return; 1016 1019 if (!scope) 1017 1020 { type = type->semantic(loc, sc); … … 1101 1104 continue; 1102 1105 } 1103 if (!b->base->symtab || b->base->scope )1106 if (!b->base->symtab || b->base->scope || b->base->inuse) 1104 1107 { 1105 1108 //error("forward reference of base class %s", baseClass->toChars()); … … 1168 1171 sc = sc->push(this); 1169 1172 sc->stc &= ~(STCfinal | STCauto | STCscope | STCstatic | 1170 STCabstract | STCdeprecated | STCconst | STCinvariant );1173 STCabstract | STCdeprecated | STCconst | STCinvariant | STCtls); 1171 1174 sc->stc |= storage_class & (STCconst | STCinvariant); 1172 1175 sc->parent = this; … … 1178 1181 structalign = sc->structalign; 1179 1182 sc->offset = 8; 1183 inuse++; 1180 1184 for (i = 0; i < members->dim; i++) 1181 1185 { … … 1183 1187 s->semantic(sc); 1184 1188 } 1189 inuse--; 1185 1190 //members->print(); 1186 1191 sc->pop(); trunk/rebuild/constfold.c
r884 r903 1100 1100 return expType(to, e1); 1101 1101 1102 Type *tb = to->toBasetype(); 1103 Type *typeb = type->toBasetype(); 1104 1105 if (e1->op == TOKstring) 1106 { 1107 if (tb->ty == Tarray && typeb->ty == Tarray && 1108 tb->nextOf()->size() == typeb->nextOf()->size()) 1109 { 1110 return expType(to, e1); 1111 } 1112 } 1113 1102 1114 if (e1->isConst() != 1) 1103 1115 return EXP_CANT_INTERPRET; 1104 1116 1105 Type *tb = to->toBasetype();1106 1117 if (tb->ty == Tbool) 1107 1118 e = new IntegerExp(loc, e1->toInteger() != 0, type); … … 1112 1123 real_t r = e1->toReal(); 1113 1124 1114 switch (type ->toBasetype()->ty)1125 switch (typeb->ty) 1115 1126 { 1116 1127 case Tin
