Changeset 838
- Timestamp:
- 11/17/07 17:28:07 (1 year ago)
- Files:
-
- branches/dmdfe-2.0/cast.c (modified) (9 diffs)
- branches/dmdfe-2.0/declaration.c (modified) (6 diffs)
- branches/dmdfe-2.0/declaration.h (modified) (8 diffs)
- branches/dmdfe-2.0/expression.c (modified) (10 diffs)
- branches/dmdfe-2.0/expression.h (modified) (11 diffs)
- branches/dmdfe-2.0/func.c (modified) (6 diffs)
- branches/dmdfe-2.0/idgen.c (modified) (1 diff)
- branches/dmdfe-2.0/inline.c (modified) (5 diffs)
- branches/dmdfe-2.0/lexer.c (modified) (1 diff)
- branches/dmdfe-2.0/mars.c (modified) (2 diffs)
- branches/dmdfe-2.0/mtype.c (modified) (27 diffs)
- branches/dmdfe-2.0/mtype.h (modified) (12 diffs)
- branches/dmdfe-2.0/opover.c (modified) (1 diff)
- branches/dmdfe-2.0/optimize.c (modified) (2 diffs)
- branches/dmdfe-2.0/parse.c (modified) (2 diffs)
- branches/dmdfe-2.0/statement.c (modified) (8 diffs)
- branches/dmdfe-2.0/statement.h (modified) (2 diffs)
- branches/dmdfe-2.0/template.c (modified) (17 diffs)
- branches/dmdfe-2.0/tocsym.c (modified) (1 diff)
- branches/dmdfe-2.0/toir.c (modified) (7 diffs)
- branches/dmdfe-2.0/toobj.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe-2.0/cast.c
r837 r838 969 969 } 970 970 if (f) 971 { SymOffExp *se = new SymOffExp(loc, f, 0, 0); 971 { f->tookAddressOf = 1; 972 SymOffExp *se = new SymOffExp(loc, f, 0, 0); 972 973 se->semantic(sc); 973 974 // Let SymOffExp::castTo() do the heavy lifting … … 1117 1118 e->type = t; 1118 1119 } 1120 f->tookAddressOf = 1; 1119 1121 return e; 1120 1122 } … … 1158 1160 if (f->tintro && f->tintro->nextOf()->isBaseOf(f->type->nextOf(), &offset) && offset) 1159 1161 error("%s", msg); 1162 f->tookAddressOf = 1; 1160 1163 e = new DelegateExp(loc, e1, f); 1161 1164 e->type = t; … … 1171 1174 { int offset; 1172 1175 1176 func->tookAddressOf = 1; 1173 1177 if (func->tintro && func->tintro->nextOf()->isBaseOf(func->type->nextOf(), &offset) && offset) 1174 1178 error("%s", msg); … … 1248 1252 TY ty; 1249 1253 1250 //printf("BinExp::typeCombine() \n");1254 //printf("BinExp::typeCombine() %s\n", toChars()); 1251 1255 //dump(0); 1252 1256 … … 1322 1326 ) 1323 1327 { 1324 t1 = t1->constOf(); 1325 t2 = t2->constOf(); 1328 t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 1329 t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 1330 //t1 = t1->constOf(); 1331 //t2 = t2->constOf(); 1332 e1 = e1->castTo(sc, t1); 1333 e2 = e2->castTo(sc, t2); 1334 goto Lagain; 1326 1335 } 1327 1336 } … … 1349 1358 else if (t1n->mod != t2n->mod) 1350 1359 { 1351 t1 = t1 ->constOf();1352 t2 = t2 ->constOf();1360 t1 = t1n->mutableOf()->constOf()->pointerTo(); 1361 t2 = t2n->mutableOf()->constOf()->pointerTo(); 1353 1362 goto Lagain; 1354 1363 } … … 1405 1414 ) 1406 1415 { 1407 t1 = t1->constOf(); 1408 t2 = t2->constOf(); 1416 if (t1->ty == Tpointer) 1417 t1 = t1->nextOf()->mutableOf()->constOf()->pointerTo(); 1418 else 1419 t1 = t1->nextOf()->mutableOf()->constOf()->arrayOf(); 1420 1421 if (t2->ty == Tpointer) 1422 t2 = t2->nextOf()->mutableOf()->constOf()->pointerTo(); 1423 else 1424 t2 = t2->nextOf()->mutableOf()->constOf()->arrayOf(); 1409 1425 goto Lagain; 1410 1426 } … … 1478 1494 if (!type) 1479 1495 type = t; 1496 #if 0 1497 printf("-BinExp::typeCombine() %s\n", toChars()); 1498 if (e1->type) printf("\tt1 = %s\n", e1->type->toChars()); 1499 if (e2->type) printf("\tt2 = %s\n", e2->type->toChars()); 1500 printf("\ttype = %s\n", type->toChars()); 1501 #endif 1480 1502 //dump(0); 1481 1503 return this; branches/dmdfe-2.0/declaration.c
r837 r838 589 589 offset = 0; 590 590 noauto = 0; 591 nestedref = 0;592 591 inuse = 0; 593 592 ctorinit = 0; … … 842 841 843 842 if (!init && !sc->inunion && !isStatic() && !isConst() && fd && 844 !(storage_class & (STCfield | STCin | STCforeach))) 843 !(storage_class & (STCfield | STCin | STCforeach)) && 844 type->size() != 0) 845 845 { 846 846 // Provide a default initializer … … 936 936 if (t->ty == Tsarray) 937 937 { 938 dim = ((TypeSArray *)t)->dim->toInteger(); 939 // If multidimensional static array, treat as one large array 940 while (1) 938 ei->exp = ei->exp->semantic(sc); 939 if (!ei->exp->implicitConvTo(type)) 941 940 { 942 t = t->nextOf()->toBasetype(); 943 if (t->ty != Tsarray) 944 break; 945 dim *= ((TypeSArray *)t)->dim->toInteger(); 946 e1->type = new TypeSArray(t->nextOf(), new IntegerExp(0, dim, Type::tindex)); 941 dim = ((TypeSArray *)t)->dim->toInteger(); 942 // If multidimensional static array, treat as one large array 943 while (1) 944 { 945 t = t->nextOf()->toBasetype(); 946 if (t->ty != Tsarray) 947 break; 948 dim *= ((TypeSArray *)t)->dim->toInteger(); 949 e1->type = new TypeSArray(t->nextOf(), new IntegerExp(0, dim, Type::tindex)); 950 } 947 951 } 948 952 e1 = new SliceExp(loc, e1, NULL, NULL); … … 1117 1121 1118 1122 /************************************ 1119 * Check to see if variable is a reference toan enclosing function1120 * or not.1123 * Check to see if this variable is actually in an enclosing function 1124 * rather than the current one. 1121 1125 */ 1122 1126 1123 1127 void VarDeclaration::checkNestedReference(Scope *sc, Loc loc) 1124 1128 { 1125 if (!isDataseg() && parent != sc->parent && parent) 1126 { 1129 if (parent && !isDataseg() && parent != sc->parent) 1130 { 1131 // The function that this variable is in 1127 1132 FuncDeclaration *fdv = toParent()->isFuncDeclaration(); 1133 // The current function 1128 1134 FuncDeclaration *fdthis = sc->parent->isFuncDeclaration(); 1129 1135 1130 if (fdv && fdthis )1136 if (fdv && fdthis && fdv != fdthis) 1131 1137 { 1132 1138 if (loc.filename) 1133 1139 fdthis->getLevel(loc, fdv); 1134 nestedref = 1; 1135 fdv->nestedFrameRef = 1; 1140 1141 for (int i = 0; i < nestedrefs.dim; i++) 1142 { FuncDeclaration *f = (FuncDeclaration *)nestedrefs.data[i]; 1143 if (f == fdthis) 1144 goto L1; 1145 } 1146 nestedrefs.push(fdthis); 1147 L1: ; 1148 1149 1150 for (int i = 0; i < fdv->closureVars.dim; i++) 1151 { Dsymbol *s = (Dsymbol *)fdv->closureVars.data[i]; 1152 if (s == this) 1153 goto L2; 1154 } 1155 fdv->closureVars.push(this); 1156 L2: ; 1157 1136 1158 //printf("var %s in function %s is nested ref\n", toChars(), fdv->toChars()); 1137 1159 } 1138 1160 } 1139 1161 } 1162 1140 1163 1141 1164 /******************************* … … 1153 1176 if (!parent && !(storage_class & (STCstatic | STCconst))) 1154 1177 { error("forward referenced"); 1178 halt(); 1155 1179 type = Type::terror; 1156 1180 return 0; … … 1262 1286 /***************************** TypeInfoConstDeclaration **********************/ 1263 1287 1288 #if V2 1264 1289 TypeInfoConstDeclaration::TypeInfoConstDeclaration(Type *tinfo) 1265 1290 : TypeInfoDeclaration(tinfo, 0) 1266 1291 { 1267 1292 } 1293 #endif 1268 1294 1269 1295 /***************************** TypeInfoInvariantDeclaration **********************/ 1270 1296 1297 #if V2 1271 1298 TypeInfoInvariantDeclaration::TypeInfoInvariantDeclaration(Type *tinfo) 1272 1299 : TypeInfoDeclaration(tinfo, 0) 1273 1300 { 1274 1301 } 1302 #endif 1275 1303 1276 1304 /***************************** TypeInfoStructDeclaration **********************/ branches/dmdfe-2.0/declaration.h
r837 r838 32 32 struct TupleType; 33 33 struct InterState; 34 struct IRState; 34 35 35 36 enum PROT; … … 211 212 unsigned offset; 212 213 int noauto; // no auto semantics 213 int nestedref; // referenced by a lexically nested function214 FuncDeclarations nestedrefs; // referenced by these lexically nested functions 214 215 int inuse; 215 216 int ctorinit; // it has been initialized in a ctor … … 386 387 387 388 /**************************************************************/ 389 #if V2 388 390 389 391 enum BUILTIN … … 397 399 BUILTINfabs, // std.math.fabs 398 400 }; 401 402 #endif 399 403 400 404 struct FuncDeclaration : Declaration … … 427 431 int cantInterpret; // !=0 if cannot interpret function 428 432 int semanticRun; // !=0 if semantic3() had been run 429 int nestedFrameRef; // !=0 if nested variables referencedframe ptr433 // this function's frame ptr 430 434 ForeachStatement *fes; // if foreach body, this is the foreach 431 435 int introducing; // !=0 if 'introducing' function … … 447 451 Symbol *shidden; // hidden pointer passed to function 448 452 453 #if V2 449 454 enum BUILTIN builtin; // set if this is a known, builtin 450 455 // function we can evaluate at compile 451 456 // time 457 458 int tookAddressOf; // set if someone took the address of 459 // this function 460 Dsymbols closureVars; // local variables in this function 461 // which are referenced by nested 462 // functions 463 #else 464 int nestedFrameRef; // !=0 if nested variables referenced 465 #endif 452 466 453 467 FuncDeclaration(Loc loc, Loc endloc, Identifier *id, enum STC storage_class, Type *type); … … 490 504 void toDocBuffer(OutBuffer *buf); 491 505 FuncDeclaration *isUnique(); 506 int needsClosure(); 492 507 493 508 static FuncDeclaration *genCfunc(Type *treturn, char *name); … … 495 510 496 511 Symbol *toThunkSymbol(int offset); // thunk version 512 void buildClosure(IRState *irs); 497 513 498 514 FuncDeclaration *isFuncDeclaration() { return this; } branches/dmdfe-2.0/expression.c
r837 r838 872 872 } 873 873 874 voidExpression::checkArithmetic()874 Expression *Expression::checkArithmetic() 875 875 { 876 876 if (!type->isintegral() && !type->isfloating()) 877 error("'%s' is not an arithmetic type", toChars()); 877 { error("'%s' is not of arithmetic type, it is a %s", toChars(), type->toChars()); 878 return new IntegerExp(0); 879 } 880 return this; 878 881 } 879 882 … … 1972 1975 type = var->type; 1973 1976 var->isVarDeclaration()->checkNestedReference(sc, loc); 1974 #if 01975 if (fd != fdthis) // if nested1976 {1977 fdthis->getLevel(loc, fd);1978 fd->vthis->nestedref = 1;1979 fd->nestedFrameRef = 1;1980 }1981 #endif1982 1977 sc->callSuper |= CSXthis; 1983 1978 return this; … … 2080 2075 2081 2076 var->isVarDeclaration()->checkNestedReference(sc, loc); 2082 #if 02083 if (fd != fdthis)2084 {2085 fdthis->getLevel(loc, fd);2086 fd->vthis->nestedref = 1;2087 fd->nestedFrameRef = 1;2088 }2089 #endif2090 2077 2091 2078 sc->callSuper |= CSXsuper; … … 3440 3427 } 3441 3428 3442 /********************** Sym OffExp **************************************/3443 3444 Sym OffExp::SymOffExp(Loc loc, Declaration *var, unsigned offset, int hasOverloads)3445 : Expression(loc, TOKsymoff, sizeof(SymOffExp))3429 /********************** SymbolExp **************************************/ 3430 3431 SymbolExp::SymbolExp(Loc loc, enum TOK op, int size, Declaration *var, int hasOverloads) 3432 : Expression(loc, op, size) 3446 3433 { 3447 3434 assert(var); 3448 3435 this->var = var; 3436 this->hasOverloads = hasOverloads; 3437 } 3438 3439 /********************** SymOffExp **************************************/ 3440 3441 SymOffExp::SymOffExp(Loc loc, Declaration *var, unsigned offset, int hasOverloads) 3442 : SymbolExp(loc, TOKsymoff, sizeof(SymOffExp), var, hasOverloads) 3443 { 3449 3444 this->offset = offset; 3450 this->hasOverloads = hasOverloads;3451 3445 3452 3446 VarDeclaration *v = var->isVarDeclaration(); … … 3495 3489 3496 3490 VarExp::VarExp(Loc loc, Declaration *var, int hasOverloads) 3497 : Expression(loc, TOKvar, sizeof(VarExp))3498 { 3499 //printf("VarExp(this = %p, '%s' )\n", this, var->toChars());3491 : SymbolExp(loc, TOKvar, sizeof(VarExp), var, hasOverloads) 3492 { 3493 //printf("VarExp(this = %p, '%s', loc = %s)\n", this, var->toChars(), loc.toChars()); 3500 3494 //if (strcmp(var->ident->toChars(), "func") == 0) halt(); 3501 this->var = var;3502 3495 this->type = var->type; 3503 this->hasOverloads = hasOverloads;3504 3496 } 3505 3497 … … 3807 3799 type = fd->type->pointerTo(); 3808 3800 } 3801 fd->tookAddressOf++; 3809 3802 } 3810 3803 return this; … … 6005 5998 if (f) 6006 5999 { 6000 if (!dve->hasOverloads) 6001 f->tookAddressOf = 1; 6007 6002 Expression *e = new DelegateExp(loc, dve->e1, f, dve->hasOverloads); 6008 6003 e = e->semantic(sc); … … 6020 6015 if (f) 6021 6016 { 6017 if (!ve->hasOverloads) 6018 f->tookAddressOf = 1; 6022 6019 if (f->isNested()) 6023 6020 { … … 6054 6051 printf("PtrExp::semantic('%s')\n", toChars()); 6055 6052 #endif 6056 UnaExp::semantic(sc); 6057 e1 = resolveProperties(sc, e1); 6058 if (type) 6059 return this; 6060 if (!e1->type) 6061 printf("PtrExp::semantic('%s')\n", toChars()); 6062 tb = e1->type->toBasetype(); 6063 switch (tb->ty) 6064 { 6065 case Tpointer: 6066 type = ((TypePointer *)tb)->next; 6067 break; 6068 6069 case Tsarray: 6070 case Tarray: 6071 type = ((TypeArray *)tb)->next; 6072 e1 = e1->castTo(sc, type->pointerTo()); 6073 break; 6074 6075 default: 6076 error("can only * a pointer, not a '%s'", e1->type->toChars()); 6077 type = Type::tint32; 6078 break; 6079 } 6080 rvalue(); 6053 if (!type) 6054 { 6055 UnaExp::semantic(sc); 6056 e1 = resolveProperties(sc, e1); 6057 if (!e1->type) 6058 printf("PtrExp::semantic('%s')\n", toChars()); 6059 Expression *e = op_overload(sc); 6060 if (e) 6061 return e; 6062 tb = e1->type->toBasetype(); 6063 switch (tb->ty) 6064 { 6065 case Tpointer: 6066 type = ((TypePointer *)tb)->next; 6067 break; 6068 6069 case Tsarray: 6070 case Tarray: 6071 type = ((TypeArray *)tb)->next; 6072 e1 = e1->castTo(sc, type->pointerTo()); 6073 break; 6074 6075 default: 6076 error("can only * a pointer, not a '%s'", e1->type->toChars()); 6077 type = Type::tint32; 6078 break; 6079 } 6080 rvalue(); 6081 } 6081 6082 return this; 6082 6083 } … … 7410 7411 else 7411 7412 { 7413 e1 = e1->checkArithmetic(); 7414 e2 = e2->checkArithmetic(); 7412 7415 type = e1->type; 7413 7416 typeCombine(sc); 7414 e1->checkArithmetic();7415 e2->checkArithmetic();7416 7417 if (type->isreal() || type->isimaginary()) 7417 7418 { branches/dmdfe-2.0/expression.h
r837 r838 109 109 void checkNoBool(); 110 110 Expression *checkIntegral(); 111 voidcheckArithmetic();111 Expression *checkArithmetic(); 112 112 void checkDeprecated(Scope *sc, Dsymbol *s); 113 113 virtual Expression *checkToBoolean(); … … 328 328 Expression *interpret(InterState *istate); 329 329 Expression *castTo(Scope *sc, Type *t); 330 elem *toElem(IRState *irs);331 330 332 331 int inlineCost(InlineCostState *ics); … … 353 352 MATCH implicitConvTo(Type *t); 354 353 Expression *castTo(Scope *sc, Type *t); 355 dt_t **toDt(dt_t **pdt);356 354 357 355 int inlineCost(InlineCostState *ics); … … 370 368 Expression *semantic(Scope *sc); 371 369 int isBool(int result); 372 elem *toElem(IRState *irs);373 370 int checkSideEffect(int flag); 374 371 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 401 398 Expression *getField(Type *type, unsigned offset); 402 399 int getFieldIndex(Type *type, unsigned offset); 403 elem *toElem(IRState *irs);404 400 int checkSideEffect(int flag); 405 401 void toCBuffer(OutBuffer *buf, HdrGenState *hgs); … … 408 404 Expression *optimize(int result); 409 405 Expression *interpret(InterState *istate); 410 dt_t **toDt(dt_t **pdt);411 406 Expression *toLvalue(Scope *sc, Expression *e); 412 407 … … 496 491 }; 497 492 493 struct SymbolExp : Expression 494 { 495 Declaration *var; 496 int hasOverloads; 497 498 SymbolExp(Loc loc, enum TOK op, int size, Declaration *var, int hasOverloads); 499 }; 500 498 501 // Offset from symbol 499 502 500 struct SymOffExp : Expression 501 { 502 Declaration *var; 503 struct SymOffExp : SymbolExp 504 { 503 505 unsigned offset; 504 int hasOverloads;505 506 506 507 SymOffExp(Loc loc, Declaration *var, unsigned offset, int hasOverloads = 0); … … 518 519 // Variable 519 520 520 struct VarExp : Expression 521 { 522 Declaration *var; 523 int hasOverloads; 524 521 struct VarExp : SymbolExp 522 { 525 523 VarExp(Loc loc, Declaration *var, int hasOverloads = 0); 526 524 int equals(Object *o); … … 688 686 689 687 Expression *op_overload(Scope *sc); 690 691 elem *toElemBin(IRState *irs, int op);692 688 }; 693 689 … … 824 820 AddrExp(Loc loc, Expression *e); 825 821 Expression *semantic(Scope *sc); 826 elem *toElem(IRState *irs);827 822 MATCH implicitConvTo(Type *t); 828 823 Expression *castTo(Scope *sc, Type *t); … … 840 835 Expression *optimize(int result); 841 836 Expression *interpret(InterState *istate); 837 838 // For operator overloading 839 Identifier *opId(); 842 840 }; 843 841 branches/dmdfe-2.0/func.c
r837 r838 64 64 cantInterpret = 0; 65 65 semanticRun = 0; 66 nestedFrameRef = 0;67 66 fes = NULL; 68 67 introducing = 0; … … 75 74 shidden = NULL; 76 75 builtin = BUILTINunknown; 76 tookAddressOf = 0; 77 77 } 78 78 … … 556 556 if (!parent) 557 557 { 558 if (global.errors) 559 return; 558 560 printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc); 559 561 assert(0); 560 562 } 561 //printf("FuncDeclaration::semantic3('%s.%s', sc = %p )\n", parent->toChars(), toChars(), sc);563 //printf("FuncDeclaration::semantic3('%s.%s', sc = %p, loc = %s)\n", parent->toChars(), toChars(), sc, loc.toChars()); 562 564 //fflush(stdout); 563 565 //{ static int x; if (++x == 2) *(char*)0=0; } … … 747 749 arg->ident = id; 748 750 } 749 VarDeclaration *v = new VarDeclaration( 0, arg->type, id, NULL);751 VarDeclaration *v = new VarDeclaration(loc, arg->type, id, NULL); 750 752 //printf("declaring parameter %s of type %s\n", v->toChars(), v->type->toChars()); 751 753 v->storage_class |= STCparameter; … … 784 786 VarDeclaration *v = sc2->search(0, narg->ident, NULL)->isVarDeclaration(); 785 787 assert(v); 786 Expression *e = new VarExp( 0, v);788 Expression *e = new VarExp(v->loc, v); 787 789 exps->data[j] = (void *)e; 788 790 } 789 791 assert(arg->ident); 790 TupleDeclaration *v = new TupleDeclaration( 0, arg->ident, exps);792 TupleDeclaration *v = new TupleDeclaration(loc, arg->ident, exps); 791 793 //printf("declaring tuple %s\n", v->toChars()); 792 794 v->isexp = 1; … … 1871 1873 } 1872 1874 1875 /******************************* 1876 * Look at all the variables in this function that are referenced 1877 * by nested functions, and determine if a closure needs to be 1878 * created for them. 1879 */ 1880 1881 #if V2 1882 int FuncDeclaration::needsClosure() 1883 { 1884 /* Need a closure for all the closureVars[] if any of the 1885 * closureVars[] are accessed by a 1886 * function that escapes the scope of this function. 1887 * We take the conservative approach and decide that any function that: 1888 * 1) is a virtual function 1889 * 2) has its address taken 1890 * 3) has a parent that escapes 1891 * escapes. 1892 */ 1893 1894 //printf("FuncDeclaration::needsClosure() %s\n", toChars()); 1895 for (int i = 0; i < closureVars.dim; i++) 1896 { VarDeclaration *v = (VarDeclaration *)closureVars.data[i]; 1897 assert(v->isVarDeclaration()); 1898 //printf("\tv = %s\n", v->toChars()); 1899 1900 for (int j = 0; j < v->nestedrefs.dim; j++) 1901 { FuncDeclaration *f = (FuncDeclaration *)v->nestedrefs.data[j]; 1902 assert(f != this); 1903 1904 //printf("\t\tf = %s, %d, %d\n", f->toChars(), f->isVirtual(), f->tookAddressOf); 1905 if (f->isVirtual() || f->tookAddressOf) 1906 goto Lyes; // assume f escapes this function's scope 1907 1908 // Look to see if any parents of f that are below this escape 1909 for (Dsymbol *s = f->parent; s != this; s = s->parent) 1910 { 1911 f = s->isFuncDeclaration(); 1912 if (f && (f->isVirtual() || f->tookAddressOf)) 1913 goto Lyes; 1914 } 1915 } 1916 } 1917 return 0; 1918 1919 Lyes: 1920 //printf("\tneeds closure\n"); 1921 return 1; 1922 } 1923 #endif 1924 1873 1925 /****************************** FuncAliasDeclaration ************************/ 1874 1926 branches/dmdfe-2.0/idgen.c
r836 r838 191 191 { "opIn" }, 192 192 { "opIn_r" }, 193 { "opStar" }, 193 194 194 195 { "classNew", "new" }, branches/dmdfe-2.0/inline.c
r740 r838 547 547 else 548 548 { 549 ExpInitializer *ie;550 ExpInitializer *ieto;551 549 VarDeclaration *vto; 552 550 … … 560 558 ids->to.push(vto); 561 559 562 if (vd->init ->isVoidInitializer())560 if (vd->init) 563 561 { 564 vto->init = new VoidInitializer(vd->init->loc); 565 } 566 else 567 { 568 ie = vd->init->isExpInitializer(); 569 assert(ie); 570 ieto = new ExpInitializer(ie->loc, ie->exp->doInline(ids)); 571 vto->init = ieto; 562 if (vd->init->isVoidInitializer()) 563 { 564 vto->init = new VoidInitializer(vd->init->loc); 565 } 566 else 567 { 568 ExpInitializer *ie = vd->init->isExpInitializer(); 569 assert(ie); 570 vto->init = new ExpInitializer(ie->loc, ie->exp->doInline(ids)); 571 } 572 572 } 573 573 de->declaration = (Dsymbol *) (void *)vto; … … 855 855 { 856 856 aggr = aggr->inlineScan(iss); 857 body = body->inlineScan(iss); 857 if (body) 858 body = body->inlineScan(iss); 858 859 return this; 859 860 } … … 865 866 lwr = lwr->inlineScan(iss); 866 867 upr = upr->inlineScan(iss); 867 body = body->inlineScan(iss); 868 if (body) 869 body = body->inlineScan(iss); 868 870 return this; 869 871 } … … 1289 1291 isSynchronized() || 1290 1292 isImportedSymbol() || 1293 #if V2 1294 closureVars.dim || // no nested references to this frame 1295 #else 1291 1296 nestedFrameRef || // no nested references to this frame 1297 #endif 1292 1298 (isVirtual() && !isFinal()) 1293 1299 )) branches/dmdfe-2.0/lexer.c
r837 r838 3023 3023 Token::tochars[TOKdeclaration] = "declaration"; 3024 3024 Token::tochars[TOKdottd] = "dottd"; 3025 } 3025 Token::tochars[TOKon_scope_exit] = "scope(exit)"; 3026 } branches/dmdfe-2.0/mars.c
r837 r838 56 56 copyright = "Copyright (c) 1999-2007 by Digital Mars"; 57 57 written = "written by Walter Bright"; 58 version = "v2.00 6";58 version = "v2.007"; 59 59 global.structalign = 8; 60 60 … … 110 110 fprintf(stdmsg, "\n"); 111 111 fflush(stdmsg); 112 halt();112 //halt(); 113 113 } 114 114 global.errors++; branches/dmdfe-2.0/mtype.c
r837 r838 670 670 671 671 672 Expression *Type::defaultInit( )672 Expression *Type::defaultInit(Loc loc) 673 673 { 674 674 #if LOGDEFAULTINIT … … 734 734 if (ty == Tvoid) 735 735 error(loc, "void does not have an initializer"); 736 e = defaultInit(); 737 e->loc = loc; 736 e = defaultInit(loc); 738 737 } 739 738 else if (ident == Id::mangleof) … … 812 811 v->type->toBasetype()->ty == Tstruct) 813 812 { 814 e = v->type->defaultInit( );813 e = v->type->defaultInit(e->loc); 815 814 } 816 815 } … … 822 821 } 823 822 #endif 824 Expression *ex = defaultInit(); 825 ex->loc = e->loc; 823 Expression *ex = defaultInit(e->loc); 826 824 return ex; 827 825 } … … 978 976 return cto; 979 977 TypeNext *t = (TypeNext *)Type::makeConst(); 980 if (ty != Tfunction && ty != Tdelegate && next->deco) 978 if (ty != Tfunction && ty != Tdelegate && next->deco && 979 !next->isInvariant()) 981 980 t->next = next->constOf(); 982 981 return t; … … 1547 1546 } 1548 1547 1549 Expression *TypeBasic::defaultInit( )1548 Expression *TypeBasic::defaultInit(Loc loc) 1550 1549 { integer_t value = 0; 1551 1550 … … 1573 1572 case Tcomplex64: 1574 1573 case Tcomplex80: 1575 return getProperty(0, Id::nan); 1576 } 1577 return new IntegerExp(0, value, this); 1574 return getProperty(loc, Id::nan); 1575 1576 case Tvoid: 1577 error(loc, "void does not have a default initializer"); 1578 } 1579 return new IntegerExp(loc, value, this); 1578 1580 } 1579 1581 … … 1990 1992 1991 1993 dim = dim->optimize(WANTvalue | WANTinterpret); 1994 if (sc->parameterSpecialization && dim->op == TOKvar && 1995 ((VarExp *)dim)->var->storage_class & STCtemplateparameter) 1996 { 1997 /* It could be a template parameter N which has no value yet: 1998 * template Foo(T : T[N], size_t N); 1999 */ 2000 return this; 2001 } 1992 2002 integer_t d1 = dim->toInteger(); 1993 2003 dim = dim->castTo(sc, tsize_t); … … 2171 2181 } 2172 2182 2173 Expression *TypeSArray::defaultInit( )2183 Expression *TypeSArray::defaultInit(Loc loc) 2174 2184 { 2175 2185 #if LOGDEFAULTINIT 2176 2186 printf("TypeSArray::defaultInit() '%s'\n", toChars()); 2177 2187 #endif 2178 return next->defaultInit( );2188 return next->defaultInit(loc); 2179 2189 } 2180 2190 … … 2359 2369 } 2360 2370 2361 Expression *TypeDArray::defaultInit( )2371 Expression *TypeDArray::defaultInit(Loc loc) 2362 2372 { 2363 2373 #if LOGDEFAULTINIT … … 2365 2375 #endif 2366 2376 Expression *e; 2367 e = new NullExp( 0);2377 e = new NullExp(loc); 2368 2378 e->type = this; 2369 2379 return e; … … 2564 2574 } 2565 2575 2566 Expression *TypeAArray::defaultInit( )2576 Expression *TypeAArray::defaultInit(Loc loc) 2567 2577 { 2568 2578 #if LOGDEFAULTINIT … … 2570 2580 #endif 2571 2581 Expression *e; 2572 e = new NullExp( 0);2582 e = new NullExp(loc); 2573 2583 e->type = this; 2574 2584 return e; … … 2680 2690 } 2681 2691 2682 Expression *TypePointer::defaultInit( )2692 Expression *TypePointer::defaultInit(Loc loc) 2683 2693 { 2684 2694 #if LOGDEFAULTINIT … … 2686 2696 #endif 2687 2697 Expression *e; 2688 e = new NullExp( 0);2698 e = new NullExp(loc); 2689 2699 e->type = this; 2690 2700 return e; … … 2762 2772 } 2763 2773 2764 Expression *TypeReference::defaultInit( )2774 Expression *TypeReference::defaultInit(Loc loc) 2765 2775 { 2766 2776 #if LOGDEFAULTINIT … … 2768 2778 #endif 2769 2779 Expression *e; 2770 e = new NullExp( 0);2780 e = new NullExp(loc); 2771 2781 e->type = this; 2772 2782 return e; … … 3295 3305 } 3296 3306 3297 Expression *TypeDelegate::defaultInit( )3307 Expression *TypeDelegate::defaultInit(Loc loc) 3298 3308 { 3299 3309 #if LOGDEFAULTINIT … … 3301 3311 #endif 3302 3312 Expression *e; 3303 e = new NullExp( 0);3313 e = new NullExp(loc); 3304 3314 e->type = this; 3305 3315 return e; … … 4097 4107 if (!sym->symtab) 4098 4108 goto Lfwd; 4099 e = defaultInit( );4109 e = defaultInit(loc); 4100 4110 } 4101 4111 else … … 4157 4167 4158 4168 4159 Expression *TypeEnum::defaultInit( )4169 Expression *TypeEnum::defaultInit(Loc loc) 4160 4170 { 4161 4171 #if LOGDEFAULTINIT … … 4164 4174 // Initialize to first member of enum 4165 4175 Expression *e; 4166 e = new IntegerExp( 0, sym->defaultval, this);4176 e = new IntegerExp(loc, sym->defaultval, this); 4167 4177 return e; 4168 4178 } … … 4351 4361 4352 4362 4353 Expression *TypeTypedef::defaultInit( )4363 Expression *TypeTypedef::defaultInit(Loc loc) 4354 4364 { Expression *e; 4355 4365 Type *bt; … … 4364 4374 } 4365 4375 bt = sym->basetype; 4366 e = bt->defaultInit( );4376 e = bt->defaultInit(loc); 4367 4377 e->type = this; 4368 4378 while (bt->ty == Tsarray) … … 4644 4654 } 4645 4655 4646 Expression *TypeStruct::defaultInit( )4656 Expression *TypeStruct::defaultInit(Loc loc) 4647 4657 { Symbol *s; 4648 4658 Declaration *d; … … 5074 5084 } 5075 5085 5076 Expression *TypeClass::defaultInit( )5086 Expression *TypeClass::defaultInit(Loc loc) 5077 5087 { 5078 5088 #if LOGDEFAULTINIT … … 5080 5090 #endif 5081 5091 Expression *e; 5082 e = new NullExp( 0);5092 e = new NullExp(loc); 5083 5093 e->type = this; 5084 5094 return e; branches/dmdfe-2.0/mtype.h
r836 r838 243 243 virtual Expression *dotExp(Scope *sc, Expression *e, Identifier *ident); 244 244 virtual unsigned memalign(unsigned salign); 245 virtual Expression *defaultInit( );245 virtual Expression *defaultInit(Loc loc = 0); 246 246 virtual int isZeroInit(); // if initializer is 0 247 247 Identifier *getTypeInfoIdent(int internal); … … 300 300 int isunsigned(); 301 301 MATCH implicitConvTo(Type *to); 302 Expression *defaultInit( );302 Expression *defaultInit(Loc loc); 303 303 int isZeroInit(); 304 304 … … 332 332 MATCH constConv(Type *to)
