Mercurial > projects > ldc
comparison dmd/statement.c @ 19:788401029ecf trunk
[svn r23] * Updated to DMD 1.021
author | lindquist |
---|---|
date | Thu, 04 Oct 2007 03:42:56 +0200 |
parents | c53b6e3fe49a |
children | 4648206ca213 |
comparison
equal
deleted
inserted
replaced
18:c05ef76f1c20 | 19:788401029ecf |
---|---|
892 if (body) | 892 if (body) |
893 body = body->semanticScope(sc, this, this); | 893 body = body->semanticScope(sc, this, this); |
894 sc->noctor--; | 894 sc->noctor--; |
895 condition = condition->semantic(sc); | 895 condition = condition->semantic(sc); |
896 condition = resolveProperties(sc, condition); | 896 condition = resolveProperties(sc, condition); |
897 condition = condition->optimize(WANTvalue); | |
897 | 898 |
898 condition = condition->checkToBoolean(); | 899 condition = condition->checkToBoolean(); |
899 | 900 |
900 return this; | 901 return this; |
901 } | 902 } |
977 // Use a default value | 978 // Use a default value |
978 condition = new IntegerExp(loc, 1, Type::tboolean); | 979 condition = new IntegerExp(loc, 1, Type::tboolean); |
979 sc->noctor++; | 980 sc->noctor++; |
980 condition = condition->semantic(sc); | 981 condition = condition->semantic(sc); |
981 condition = resolveProperties(sc, condition); | 982 condition = resolveProperties(sc, condition); |
983 condition = condition->optimize(WANTvalue); | |
982 condition = condition->checkToBoolean(); | 984 condition = condition->checkToBoolean(); |
983 if (increment) | 985 if (increment) |
984 increment = increment->semantic(sc); | 986 increment = increment->semantic(sc); |
985 | 987 |
986 sc->sbreak = this; | 988 sc->sbreak = this; |
1088 | 1090 |
1089 Statement *ForeachStatement::syntaxCopy() | 1091 Statement *ForeachStatement::syntaxCopy() |
1090 { | 1092 { |
1091 Arguments *args = Argument::arraySyntaxCopy(arguments); | 1093 Arguments *args = Argument::arraySyntaxCopy(arguments); |
1092 Expression *exp = aggr->syntaxCopy(); | 1094 Expression *exp = aggr->syntaxCopy(); |
1093 ForeachStatement *s = new ForeachStatement(loc, op, args, exp, body->syntaxCopy()); | 1095 ForeachStatement *s = new ForeachStatement(loc, op, args, exp, |
1096 body ? body->syntaxCopy() : NULL); | |
1094 return s; | 1097 return s; |
1095 } | 1098 } |
1096 | 1099 |
1097 Statement *ForeachStatement::semantic(Scope *sc) | 1100 Statement *ForeachStatement::semantic(Scope *sc) |
1098 { | 1101 { |
1253 } | 1256 } |
1254 | 1257 |
1255 /* Look for special case of parsing char types out of char type | 1258 /* Look for special case of parsing char types out of char type |
1256 * array. | 1259 * array. |
1257 */ | 1260 */ |
1258 tn = tab->next->toBasetype(); | 1261 tn = tab->nextOf()->toBasetype(); |
1259 if (tn->ty == Tchar || tn->ty == Twchar || tn->ty == Tdchar) | 1262 if (tn->ty == Tchar || tn->ty == Twchar || tn->ty == Tdchar) |
1260 { Argument *arg; | 1263 { Argument *arg; |
1261 | 1264 |
1262 i = (dim == 1) ? 0 : 1; // index of value | 1265 i = (dim == 1) ? 0 : 1; // index of value |
1263 arg = (Argument *)arguments->data[i]; | 1266 arg = (Argument *)arguments->data[i]; |
1309 aggr = aggr->implicitCastTo(sc, value->type->arrayOf()); | 1312 aggr = aggr->implicitCastTo(sc, value->type->arrayOf()); |
1310 else | 1313 else |
1311 error("foreach: %s is not an array of %s", tab->toChars(), value->type->toChars()); | 1314 error("foreach: %s is not an array of %s", tab->toChars(), value->type->toChars()); |
1312 } | 1315 } |
1313 | 1316 |
1314 if (value->storage_class & STCout && value->type->toBasetype()->ty == Tbit) | |
1315 error("foreach: value cannot be out and type bit"); | |
1316 | |
1317 if (key && | 1317 if (key && |
1318 ((key->type->ty != Tint32 && key->type->ty != Tuns32) || | 1318 ((key->type->ty != Tint32 && key->type->ty != Tuns32) || |
1319 (global.params.is64bit && | 1319 (global.params.is64bit && |
1320 key->type->ty != Tint64 && key->type->ty != Tuns64) | 1320 key->type->ty != Tint64 && key->type->ty != Tuns64) |
1321 ) | 1321 ) |
1354 Type *t; | 1354 Type *t; |
1355 Expression *flde; | 1355 Expression *flde; |
1356 Identifier *id; | 1356 Identifier *id; |
1357 Type *tret; | 1357 Type *tret; |
1358 | 1358 |
1359 tret = func->type->next; | 1359 tret = func->type->nextOf(); |
1360 | 1360 |
1361 // Need a variable to hold value from any return statements in body. | 1361 // Need a variable to hold value from any return statements in body. |
1362 if (!sc->func->vresult && tret && tret != Type::tvoid) | 1362 if (!sc->func->vresult && tret && tret != Type::tvoid) |
1363 { VarDeclaration *v; | 1363 { VarDeclaration *v; |
1364 | 1364 |
1428 error("foreach: index cannot be ref"); | 1428 error("foreach: index cannot be ref"); |
1429 if (!arg->type->equals(taa->index)) | 1429 if (!arg->type->equals(taa->index)) |
1430 error("foreach: index must be type %s, not %s", taa->index->toChars(), arg->type->toChars()); | 1430 error("foreach: index must be type %s, not %s", taa->index->toChars(), arg->type->toChars()); |
1431 arg = (Argument *)arguments->data[1]; | 1431 arg = (Argument *)arguments->data[1]; |
1432 } | 1432 } |
1433 if (!arg->type->equals(taa->next)) | 1433 if (!arg->type->equals(taa->nextOf())) |
1434 error("foreach: value must be type %s, not %s", taa->next->toChars(), arg->type->toChars()); | 1434 error("foreach: value must be type %s, not %s", taa->nextOf()->toChars(), arg->type->toChars()); |
1435 | 1435 |
1436 /* Call: | 1436 /* Call: |
1437 * _aaApply(aggr, keysize, flde) | 1437 * _aaApply(aggr, keysize, flde) |
1438 */ | 1438 */ |
1439 if (dim == 2) | 1439 if (dim == 2) |
1980 if (condition->type->isString()) | 1980 if (condition->type->isString()) |
1981 { | 1981 { |
1982 // If it's not an array, cast it to one | 1982 // If it's not an array, cast it to one |
1983 if (condition->type->ty != Tarray) | 1983 if (condition->type->ty != Tarray) |
1984 { | 1984 { |
1985 condition = condition->implicitCastTo(sc, condition->type->next->arrayOf()); | 1985 condition = condition->implicitCastTo(sc, condition->type->nextOf()->arrayOf()); |
1986 } | 1986 } |
1987 } | 1987 } |
1988 else | 1988 else |
1989 { condition = condition->integralPromotions(sc); | 1989 { condition = condition->integralPromotions(sc); |
1990 condition->checkIntegral(); | 1990 condition->checkIntegral(); |
2120 } | 2120 } |
2121 | 2121 |
2122 Statement *CaseStatement::semantic(Scope *sc) | 2122 Statement *CaseStatement::semantic(Scope *sc) |
2123 { SwitchStatement *sw = sc->sw; | 2123 { SwitchStatement *sw = sc->sw; |
2124 | 2124 |
2125 //printf("CaseStatement::semantic() %s\n", toChars()); | |
2125 exp = exp->semantic(sc); | 2126 exp = exp->semantic(sc); |
2126 if (sw) | 2127 if (sw) |
2127 { int i; | 2128 { int i; |
2128 | 2129 |
2129 exp = exp->implicitCastTo(sc, sw->condition->type); | 2130 exp = exp->implicitCastTo(sc, sw->condition->type); |
2388 break; | 2389 break; |
2389 } | 2390 } |
2390 } | 2391 } |
2391 } | 2392 } |
2392 | 2393 |
2393 Type *tret = fd->type->next; | 2394 Type *tret = fd->type->nextOf(); |
2394 if (fd->tintro) | 2395 if (fd->tintro) |
2395 tret = fd->tintro->next; | 2396 tret = fd->tintro->nextOf(); |
2396 Type *tbret = NULL; | 2397 Type *tbret = NULL; |
2397 | 2398 |
2398 if (tret) | 2399 if (tret) |
2399 tbret = tret->toBasetype(); | 2400 tbret = tret->toBasetype(); |
2400 | 2401 |
2450 if (fd->returnLabel && tbret->ty != Tvoid) | 2451 if (fd->returnLabel && tbret->ty != Tvoid) |
2451 { | 2452 { |
2452 } | 2453 } |
2453 else if (fd->inferRetType) | 2454 else if (fd->inferRetType) |
2454 { | 2455 { |
2455 if (fd->type->next) | 2456 if (fd->type->nextOf()) |
2456 { | 2457 { |
2457 if (!exp->type->equals(fd->type->next)) | 2458 if (!exp->type->equals(fd->type->nextOf())) |
2458 error("mismatched function return type inference of %s and %s", | 2459 error("mismatched function return type inference of %s and %s", |
2459 exp->type->toChars(), fd->type->next->toChars()); | 2460 exp->type->toChars(), fd->type->nextOf()->toChars()); |
2460 } | 2461 } |
2461 else | 2462 else |
2462 { | 2463 { |
2463 fd->type->next = exp->type; | 2464 fd->type->next = exp->type; |
2464 fd->type = fd->type->semantic(loc, sc); | 2465 fd->type = fd->type->semantic(loc, sc); |
2465 if (!fd->tintro) | 2466 if (!fd->tintro) |
2466 { tret = fd->type->next; | 2467 { tret = fd->type->nextOf(); |
2467 tbret = tret->toBasetype(); | 2468 tbret = tret->toBasetype(); |
2468 } | 2469 } |
2469 } | 2470 } |
2470 } | 2471 } |
2471 else if (tbret->ty != Tvoid) | 2472 else if (tbret->ty != Tvoid) |
2473 exp = exp->implicitCastTo(sc, tret); | 2474 exp = exp->implicitCastTo(sc, tret); |
2474 } | 2475 } |
2475 } | 2476 } |
2476 else if (fd->inferRetType) | 2477 else if (fd->inferRetType) |
2477 { | 2478 { |
2478 if (fd->type->next) | 2479 if (fd->type->nextOf()) |
2479 { | 2480 { |
2480 if (fd->type->next->ty != Tvoid) | 2481 if (fd->type->nextOf()->ty != Tvoid) |
2481 error("mismatched function return type inference of void and %s", | 2482 error("mismatched function return type inference of void and %s", |
2482 fd->type->next->toChars()); | 2483 fd->type->nextOf()->toChars()); |
2483 } | 2484 } |
2484 else | 2485 else |
2485 { | 2486 { |
2486 fd->type->next = Type::tvoid; | 2487 fd->type->next = Type::tvoid; |
2487 fd->type = fd->type->semantic(loc, sc); | 2488 fd->type = fd->type->semantic(loc, sc); |
2508 exp->op == TOKstring) | 2509 exp->op == TOKstring) |
2509 { | 2510 { |
2510 sc->fes->cases.push(this); | 2511 sc->fes->cases.push(this); |
2511 s = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1)); | 2512 s = new ReturnStatement(0, new IntegerExp(sc->fes->cases.dim + 1)); |
2512 } | 2513 } |
2513 else if (fd->type->next->toBasetype() == Type::tvoid) | 2514 else if (fd->type->nextOf()->toBasetype() == Type::tvoid) |
2514 { | 2515 { |
2515 Statement *s1; | 2516 Statement *s1; |
2516 Statement *s2; | 2517 Statement *s2; |
2517 | 2518 |
2518 s = new ReturnStatement(0, NULL); | 2519 s = new ReturnStatement(0, NULL); |