Changeset 415
- Timestamp:
- 03/12/07 20:50:31 (1 year ago)
- Files:
-
- branches/dmdfe/constfold.c (modified) (8 diffs)
- branches/dmdfe/declaration.c (modified) (3 diffs)
- branches/dmdfe/declaration.h (modified) (2 diffs)
- branches/dmdfe/expression.c (modified) (5 diffs)
- branches/dmdfe/expression.h (modified) (3 diffs)
- branches/dmdfe/init.c (modified) (1 diff)
- branches/dmdfe/interpret.c (modified) (15 diffs)
- branches/dmdfe/mangle.c (modified) (3 diffs)
- branches/dmdfe/mars.c (modified) (1 diff)
- branches/dmdfe/mars.h (modified) (1 diff)
- branches/dmdfe/mtype.c (modified) (6 diffs)
- branches/dmdfe/optimize.c (modified) (1 diff)
- branches/dmdfe/statement.c (modified) (2 diffs)
- branches/dmdfe/staticassert.c (modified) (3 diffs)
- branches/dmdfe/tocsym.c (modified) (5 diffs)
- branches/dmdfe/todt.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmdfe/constfold.c
r414 r415 458 458 n2 = e2->toInteger(); 459 459 if (n2 == 0) 460 { e rror("divide by 0");460 { e2->error("divide by 0"); 461 461 e2 = new IntegerExp(0, 1, e2->type); 462 462 n2 = 1; … … 521 521 n2 = e2->toInteger(); 522 522 if (n2 == 0) 523 { e rror("divide by 0");523 { e2->error("divide by 0"); 524 524 e2 = new IntegerExp(0, 1, e2->type); 525 525 n2 = 1; … … 1030 1030 Loc loc = e1->loc; 1031 1031 1032 //printf("Index(e1->type = %p)\n", e1->type); 1032 //printf("Index(e1 = %s)\n", e1->toChars()); 1033 assert(e1->type); 1033 1034 if (e1->op == TOKstring && e2->op == TOKint64) 1034 1035 { StringExp *es1 = (StringExp *)e1; … … 1067 1068 1068 1069 if (i >= length) 1069 { e rror("array index %ju is out of bounds [0 .. %ju]", i, length);1070 { e2->error("array index %ju is out of bounds %s[0 .. %ju]", i, e1->toChars(), length); 1070 1071 } 1071 1072 else if (e1->op == TOKarrayliteral && !e1->checkSideEffect(2)) … … 1145 1146 { Expression *e = EXP_CANT_INTERPRET; 1146 1147 Loc loc = e1->loc; 1148 Type *t; 1147 1149 1148 1150 //printf("Cat(e1 = %s, e2 = %s)\n", e1->toChars(), e2->toChars()); … … 1185 1187 return e; 1186 1188 } 1187 1188 if (e1->op == TOKstring && e2->op == TOKstring) 1189 else if (e1->op == TOKstring && e2->op == TOKstring) 1189 1190 { 1190 1191 // Concatenate the strings … … 1320 1321 else if (e1->op == TOKnull && e2->op == TOKstring) 1321 1322 { 1323 t = e1->type; 1322 1324 e = e2; 1323 1325 goto L1; … … 1325 1327 else if (e1->op == TOKstring && e2->op == TOKnull) 1326 1328 { e = e1; 1329 t = e2->type; 1327 1330 L1: 1331 Type *tb = t->toBasetype(); 1332 if (tb->ty == Tarray && tb->next->equals(e->type)) 1333 { Expressions *expressions = new Expressions(); 1334 expressions->push(e); 1335 e = new ArrayLiteralExp(loc, expressions); 1336 e->type = t; 1337 } 1328 1338 if (!e->type->equals(type)) 1329 1339 { StringExp *se = (StringExp *)e->copy(); branches/dmdfe/declaration.c
r361 r415 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 … … 149 149 150 150 return tupletype; 151 } 152 153 int TupleDeclaration::needThis() 154 { 155 //printf("TupleDeclaration::needThis(%s)\n", toChars()); 156 for (size_t i = 0; i < objects->dim; i++) 157 { Object *o = (Object *)objects->data[i]; 158 if (o->dyncast() == DYNCAST_EXPRESSION) 159 { Expression *e = (Expression *)o; 160 if (e->op == TOKdsymbol) 161 { DsymbolExp *ve = (DsymbolExp *)e; 162 Declaration *d = ve->s->isDeclaration(); 163 if (d && d->needThis()) 164 { 165 return 1; 166 } 167 } 168 } 169 } 170 return 0; 151 171 } 152 172 … … 967 987 int VarDeclaration::needThis() 968 988 { 989 //printf("VarDeclaration::needThis(%s, x%x)\n", toChars(), storage_class); 969 990 return storage_class & STCfield; 970 991 } branches/dmdfe/declaration.h
r414 r415 131 131 char *kind(); 132 132 Type *getType(); 133 int needThis(); 133 134 134 135 TupleDeclaration *isTupleDeclaration() { return this; } … … 461 462 FuncAliasDeclaration *isFuncAliasDeclaration() { return this; } 462 463 char *kind(); 464 Symbol *toSymbol(); 463 465 }; 464 466 branches/dmdfe/expression.c
r414 r415 1155 1155 } 1156 1156 case Tchar: 1157 if (isprint(v) && v != '\\') 1157 if (v == '\'') 1158 buf->writestring("'\\''"); 1159 else if (isprint(v) && v != '\\') 1158 1160 buf->printf("'%c'", (int)v); 1159 1161 else … … 1830 1832 TupleDeclaration *tup = s->isTupleDeclaration(); 1831 1833 if (tup) 1832 { Expressions *exps = new Expressions(); 1833 1834 exps->reserve(tup->objects->dim); 1835 for (size_t i = 0; i < tup->objects->dim; i++) 1836 { Object *o = (Object *)tup->objects->data[i]; 1837 if (o->dyncast() != DYNCAST_EXPRESSION) 1838 { 1839 error("%s is not an expression", o->toChars()); 1840 } 1841 else 1842 { 1843 Expression *e = (Expression *)o; 1844 e = e->syntaxCopy(); 1845 exps->push(e); 1846 } 1847 } 1848 e = new TupleExp(loc, exps); 1834 { 1835 e = new TupleExp(loc, tup); 1849 1836 e = e->semantic(sc); 1850 1837 return e; … … 2757 2744 else 2758 2745 type = newtype->semantic(loc, sc); 2746 newtype = type; // in case type gets cast to something else 2759 2747 tb = type->toBasetype(); 2760 2748 //printf("tb: %s, deco = %s\n", tb->toChars(), tb->deco); … … 3276 3264 this->exps = exps; 3277 3265 this->type = NULL; 3266 } 3267 3268 3269 TupleExp::TupleExp(Loc loc, TupleDeclaration *tup) 3270 : Expression(loc, TOKtuple, sizeof(TupleExp)) 3271 { 3272 exps = new Expressions(); 3273 type = NULL; 3274 3275 exps->reserve(tup->objects->dim); 3276 for (size_t i = 0; i < tup->objects->dim; i++) 3277 { Object *o = (Object *)tup->objects->data[i]; 3278 if (o->dyncast() == DYNCAST_EXPRESSION) 3279 { 3280 Expression *e = (Expression *)o; 3281 e = e->syntaxCopy(); 3282 exps->push(e); 3283 } 3284 else if (o->dyncast() == DYNCAST_DSYMBOL) 3285 { 3286 Dsymbol *s = (Dsymbol *)o; 3287 Expression *e = new DsymbolExp(loc, s); 3288 exps->push(e); 3289 } 3290 else 3291 { 3292 error("%s is not an expression", o->toChars()); 3293 } 3294 } 3278 3295 } 3279 3296 … … 4721 4738 s2 = s->search(loc, id, 0); 4722 4739 if (!s2) 4723 { error("template identifier %s is not a member of %s ", id->toChars(), s->ident->toChars());4740 { error("template identifier %s is not a member of %s %s", id->toChars(), s->kind(), s->ident->toChars()); 4724 4741 goto Lerr; 4725 4742 } branches/dmdfe/expression.h
r414 r415 19 19 struct Type; 20 20 struct Scope; 21 struct TupleDeclaration; 21 22 struct VarDeclaration; 22 23 struct FuncDeclaration; … … 309 310 310 311 TupleExp(Loc loc, Expressions *exps); 312 TupleExp(Loc loc, TupleDeclaration *tup); 311 313 Expression *syntaxCopy(); 312 314 int equals(Object *o); … … 1215 1217 #define EXP_BREAK_INTERPRET ((Expression *)3) 1216 1218 #define EXP_GOTO_INTERPRET ((Expression *)4) 1219 #define EXP_VOID_INTERPRET ((Expression *)5) 1217 1220 1218 1221 Expression *expType(Type *type, Expression *e); branches/dmdfe/init.c
r361 r415 360 360 { Expressions *elements; 361 361 362 //printf("ArrayInitializer::toExpression()\n"); 363 //static int i; if (++i == 2) halt(); 362 364 elements = new Expressions(); 363 365 for (size_t i = 0; i < value.dim; i++) branches/dmdfe/interpret.c
r414 r415 76 76 TypeFunction *tf = (TypeFunction *)tb; 77 77 Type *tret = tf->next->toBasetype(); 78 if (tf->varargs || tret->ty == Tvoid)78 if (tf->varargs /*|| tret->ty == Tvoid*/) 79 79 { cantInterpret = 1; 80 80 return NULL; … … 88 88 { cantInterpret = 1; 89 89 return NULL; 90 }91 }92 }93 94 /* Save the values of the local variables used95 */96 Expressions valueSaves;97 if (istate)98 {99 valueSaves.setDim(istate->vars.dim);100 for (size_t i = 0; i < istate->vars.dim; i++)101 { VarDeclaration *v = (VarDeclaration *)istate->vars.data[i];102 if (v)103 { valueSaves.data[i] = v->value;104 v->value = NULL;105 90 } 106 91 } … … 174 159 } 175 160 161 /* Save the values of the local variables used 162 */ 163 Expressions valueSaves; 164 if (istate) 165 { 166 //printf("saving state...\n"); 167 valueSaves.setDim(istate->vars.dim); 168 for (size_t i = 0; i < istate->vars.dim; i++) 169 { VarDeclaration *v = (VarDeclaration *)istate->vars.data[i]; 170 if (v) 171 { 172 //printf("\tsaving [%d] %s = %s\n", i, v->toChars(), v->value->toChars()); 173 valueSaves.data[i] = v->value; 174 v->value = NULL; 175 } 176 } 177 } 178 176 179 Expression *e = NULL; 177 180 … … 253 256 { 254 257 #if LOG 255 printf("ExpStatement::interpret( )\n");258 printf("ExpStatement::interpret(%s)\n", exp ? exp->toChars() : ""); 256 259 #endif 257 260 START() … … 286 289 } 287 290 } 291 #if LOG 292 printf("-CompoundStatement::interpret() %p\n", e); 293 #endif 288 294 return e; 289 295 } … … 375 381 { 376 382 #if LOG 377 printf("ReturnStatement::interpret( )\n");383 printf("ReturnStatement::interpret(%s)\n", exp ? exp->toChars() : ""); 378 384 #endif 379 385 START() 380 assert(exp); 386 if (!exp) 387 return EXP_VOID_INTERPRET; 381 388 return exp->interpret(istate); 382 389 } … … 837 844 { 838 845 if (v->isConst() && v->init) 839 e = v->init->toExpression(); 846 { e = v->init->toExpression(); 847 if (!e->type) 848 e->type = v->type; 849 } 840 850 else 841 851 { e = v->value; … … 852 862 853 863 Expression *DeclarationExp::interpret(InterState *istate) 854 { Expression *e = EXP_CANT_INTERPRET; 864 { 865 #if LOG 866 printf("DeclarationExp::interpret() %s\n", toChars()); 867 #endif 868 Expression *e = EXP_CANT_INTERPRET; 855 869 VarDeclaration *v = declaration->isVarDeclaration(); 856 870 if (v) … … 865 879 e = NULL; 866 880 } 881 else if (s == v && v->isConst() && v->init) 882 { e = v->init->toExpression(); 883 if (!e) 884 e = EXP_CANT_INTERPRET; 885 else if (!e->type) 886 e->type = v->type; 887 } 867 888 } 868 889 return e; … … 870 891 871 892 Expression *TupleExp::interpret(InterState *istate) 872 { Expressions *expsx = NULL; 893 { 894 #if LOG 895 printf("VarExp::interpret() %s\n", toChars()); 896 #endif 897 Expressions *expsx = NULL; 873 898 874 899 for (size_t i = 0; i < exps->dim; i++) … … 1032 1057 Expression *e2; 1033 1058 1059 #if LOG 1060 printf("BinExp::interpretCommon2() %s\n", toChars()); 1061 #endif 1034 1062 e1 = this->e1->interpret(istate); 1035 1063 if (e1 == EXP_CANT_INTERPRET) 1036 1064 goto Lcant; 1037 if (e1->isConst() != 1 )1065 if (e1->isConst() != 1 && e1->op != TOKstring && e1->op != TOKarrayliteral) 1038 1066 goto Lcant; 1039 1067 … … 1041 1069 if (e2 == EXP_CANT_INTERPRET) 1042 1070 goto Lcant; 1043 if (e2->isConst() != 1 )1071 if (e2->isConst() != 1 && e2->op != TOKstring && e2->op != TOKarrayliteral) 1044 1072 goto Lcant; 1045 1073 … … 1104 1132 if (e2 != EXP_CANT_INTERPRET) 1105 1133 { 1106 if ( v->isAuto())1134 if (!(v->isDataseg() || v->isParameter())) 1107 1135 { 1108 1136 for (size_t i = 0; 1; i++) … … 1277 1305 if (eresult) 1278 1306 e = eresult; 1307 else if (fd->type->toBasetype()->next->ty == Tvoid) 1308 e = EXP_VOID_INTERPRET; 1279 1309 else 1280 1310 error("cannot evaluate %s at compile time", toChars()); … … 1335 1365 Expression *e2; 1336 1366 1367 #if LOG 1368 printf("IndexExp::interpret() %s\n", toChars()); 1369 #endif 1337 1370 e1 = this->e1->interpret(istate); 1338 1371 if (e1 == EXP_CANT_INTERPRET) branches/dmdfe/mangle.c
r360 r415 31 31 Dsymbol *s; 32 32 33 //printf("::mangle(%s)\n", sthis->toChars()); 33 34 s = sthis; 34 35 do 35 36 { 36 //printf(" s = %p, '%s', parent = %p\n", s, s->toChars(), s->parent);37 //printf("mangle: s = %p, '%s', parent = %p\n", s, s->toChars(), s->parent); 37 38 if (s->ident) 38 39 { … … 61 62 // buf.prependstring("_D"); 62 63 L1: 63 //printf("deco = '%s'\n", sthis->type->deco); 64 //printf("deco = '%s'\n", sthis->type->deco ? sthis->type->deco : "null"); 65 //printf("sthis->type = %s\n", sthis->type->toChars()); 64 66 FuncDeclaration *fd = sthis->isFuncDeclaration(); 65 67 if (fd && (fd->needThis() || fd->isNested())) 66 68 buf.writeByte(Type::needThisPrefix()); 67 buf.writestring(sthis->type->deco); 69 if (sthis->type->deco) 70 buf.writestring(sthis->type->deco); 71 else 72 { assert(fd->inferRetType); 73 } 68 74 69 75 id = buf.toChars(); … … 135 141 return "_Dmain"; 136 142 143 assert(this); 137 144 return Declaration::mangle(); 138 145 } branches/dmdfe/mars.c
r414 r415 56 56 copyright = "Copyright (c) 1999-2007 by Digital Mars"; 57 57 written = "written by Walter Bright"; 58 version = "v1.00 7";58 version = "v1.009"; 59 59 global.structalign = 8; 60 60 branches/dmdfe/mars.h
r361 r415 18 18 #include <stdint.h> 19 19 #include <stdarg.h> 20 21 #ifdef __DMC__ 22 #ifdef DEBUG 23 #undef assert 24 #define assert(e) (static_cast<void>((e) || (printf("assert %s(%d) %s\n", __FILE__, __LINE__, #e), halt()))) 25 #endif 26 #endif 20 27 21 28 #ifdef IN_GCC branches/dmdfe/mtype.c
r414 r415 3074 3074 sm = s->search(loc, id, 0); 3075 3075 if (!sm) 3076 { error(loc, "template identifier %s is not a member of %s", id->toChars(), s->toChars()); 3076 { 3077 #ifdef DEBUG 3078 printf("1: \n"); 3079 #endif 3080 error(loc, "template identifier %s is not a member of %s %s", 3081 id->toChars(), s->kind(), s->toChars()); 3077 3082 return; 3078 3083 } … … 3310 3315 if (s) 3311 3316 { 3312 s = s->toAlias();3313 3317 for (int i = 0; i < idents.dim; i++) 3314 3318 { Identifier *id; 3315 3319 Dsymbol *sm; 3316 3320 3321 s = s->toAlias(); 3317 3322 id = (Identifier *)idents.data[i]; 3318 3323 //printf("\tid = '%s'\n", id->toChars()); … … 3326 3331 sm = s->search(loc, id, 0); 3327 3332 if (!sm) 3328 { error(loc, "template identifier %s is not a member of %s", id->toChars(), s->toChars()); 3329 break; 3333 { 3334 Type *t = s->getType(); 3335 if (t) 3336 sm = t->toDsymbol(sc); 3337 if (!sm) 3338 { 3339 #ifdef DEBUG 3340 printf("E2: %s\n", s->getType()->toChars()); 3341 #endif 3342 error(loc, "template identifier %s is not a member of %s %s", 3343 id->toChars(), s->kind(), s->toChars()); 3344 break; 3345 } 3346 sm = sm->toAlias(); 3330 3347 } 3331 sm = sm->toAlias(); 3332 td = sm->isTemplateDeclaration(); 3333 if (!td) 3348 else 3334 3349 { 3335 error(loc, "%s is not a template", id->toChars()); 3336 break; 3350 sm = sm->toAlias(); 3351 td = sm->isTemplateDeclaration(); 3352 if (!td) 3353 { 3354 error(loc, "%s %s is not a template", sm->kind(), id->toChars()); 3355 break; 3356 } 3357 ti->tempdecl = td; 3358 if (!ti->semanticdone) 3359 ti->semantic(sc); 3360 sm = ti->toAlias(); 3337 3361 } 3338 ti->tempdecl = td;3339 if (!ti->semanticdone)3340 ti->semantic(sc);3341 sm = ti->toAlias();3342 3362 } 3343 3363 else … … 3349 3369 break; 3350 3370 } 3351 s = s->toAlias();3352 3371 } 3353 3372 } … … 4218 4237 return e; 4219 4238 } 4239 if (d->isTupleDeclaration()) 4240 { 4241 e = new TupleExp(e->loc, d->isTupleDeclaration()); 4242 e = e->semantic(sc); 4243 return e; 4244 } 4220 4245 return new VarExp(e->loc, d); 4221 4246 } … … 4549 4574 return e; 4550 4575 } 4576 else if (d->isTupleDeclaration()) 4577 { 4578 e = new TupleExp(e->loc, d->isTupleDeclaration()); 4579 e = e->semantic(sc); 4580 return e; 4581 } 4551 4582 else 4552 4583 ve = new VarExp(e->loc, d); branches/dmdfe/optimize.c
r414 r415 43 43 Expression *fromConstInitializer(Expression *e1) 44 44 { 45 //printf("fromConstInitializer(%s)\n", e1->toChars()); 45 46 if (e1->op == TOKvar) 46 47 { VarExp *ve = (VarExp *)e1; branches/dmdfe/statement.c
r414 r415 1137 1137 size_t n; 1138 1138 TupleExp *te = NULL; 1139 if (aggr->op == TOKtuple) 1139 if (aggr->op == TOKtuple) // expression tuple 1140 1140 { te = (TupleExp *)aggr; 1141 1141 n = te->exps->dim; 1142 1142 } 1143 else if (aggr->op == TOKtype) 1143 else if (aggr->op == TOKtype) // type tuple 1144 1144 { 1145 1145 n = Argument::dim(tuple->arguments); … … 1183 1183 if (te) 1184 1184 { 1185 arg->type = e->type; 1186 Initializer *ie = new ExpInitializer(0, e); 1187 var = new VarDeclaration(loc, arg->type, arg->ident, ie); 1185 if (e->type->toBasetype()->ty == Tfunction && 1186 e->op == TOKvar) 1187 { VarExp *ve = (VarExp *)e; 1188 var = new AliasDeclaration(loc, arg->ident, ve->var); 1189 } 1190 else 1191 { 1192 arg->type = e->type; 1193 Initializer *ie = new ExpInitializer(0, e); 1194 var = new VarDeclaration(loc, arg->type, arg->ident, ie); 1195 } 1188 1196 } 1189 1197 else branches/dmdfe/staticassert.c
r360 r415 1 1 2 // Copyright (c) 1999-200 6by Digital Mars2 // Copyright (c) 1999-2007 by Digital Mars 3 3 // All Rights Reserved 4 4 // written by Walter Bright … … 50 50 51 51 e = exp->semantic(sc); 52 e = e->optimize(WANTvalue );52 e = e->optimize(WANTvalue | WANTinterpret); 53 53 if (e->isBool(FALSE)) 54 54 { … … 56 56 { 57 57 msg = msg->semantic(sc); 58 msg = msg->optimize(WANTvalue );58 msg = msg->optimize(WANTvalue | WANTinterpret); 59 59 char *p = msg->toChars(); 60 60 p = strdup(p); 61 error(" (%s) is false, %s", exp->toChars(), p);61 error("%s", p); 62 62 free(p); 63 63 } 64 64 else 65 error(" (%s) is false", exp->toChars());65 error("is false"); 66 66 if (!global.gag) 67 67 fatal(); branches/dmdfe/tocsym.c
r360 r415 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 … … 175 175 176 176 if (storage_class & STCout) 177 t = type_fake(TYnptr); 177 { 178 if (global.params.symdebug && storage_class & STCparameter) 179 { 180 t = type_alloc(TYref); 181 t->Tnext = type->toCtype(); 182 t->Tnext->Tcount++; 183 } 184 else 185 t = type_fake(TYnptr); 186 } 178 187 else if (storage_class & STClazy) 179 188 t = type_fake(TYullong); // Tdelegate as C type … … 277 286 */ 278 287 288 Symbol *FuncAliasDeclaration::toSymbol() 289 { 290 return funcalias->toSymbol(); 291 } 292 293 /************************************* 294 */ 295 279 296 Symbol *FuncDeclaration::toSymbol() 280 297 { … … 289 306 id = mangle(); 290 307 #endif 291 //printf("FuncDeclaration::toSymbol(%s )\n", toChars());308 //printf("FuncDeclaration::toSymbol(%s %s)\n", kind(), toChars()); 292 309 //printf("\tid = '%s'\n", id); 293 310 //printf("\ttype = %s\n", type->toChars()); … … 301 318 f = s->Sfunc; 302 319 f->Fstartline.Slinnum = loc.linnum; 320 f->Fstartline.Sfilename = loc.filename; 303 321 if (endloc.linnum) 304 f->Fendline.Slinnum = endloc.linnum; 322 { f->Fendline.Slinnum = endloc.linnum; 323 f->Fendline.Sfilename = endloc.filename; 324 } 305 325 else 306 f->Fendline.Slinnum = loc.linnum; 326 { f->Fendline.Slinnum = loc.linnum; 327 f->Fendline.Sfilename = loc.filename; 328 } 307 329 t = type->toCtype(); 308 330 } branches/dmdfe/todt.c
r360 r415 426 426 #ifdef DEBUG 427 427 printf("Expression::toDt() %d\n", op); 428 dump(0); 428 429 #endif 429 430 error("non-constant expression %s", toChars());
