Changeset 640
- Timestamp:
- 08/28/10 19:24:44 (14 years ago)
- Files:
-
- branches/dmd-1.x/src/e2ir.c (modified) (1 diff)
- branches/dmd-1.x/src/expression.c (modified) (2 diffs)
- branches/dmd-1.x/src/inline.c (modified) (1 diff)
- trunk/src/e2ir.c (modified) (1 diff)
- trunk/src/expression.c (modified) (3 diffs)
- trunk/src/inline.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/e2ir.c
r621 r640 3051 3051 elem *ec; 3052 3052 int directcall; 3053 3053 FuncDeclaration *fd; 3054 3054 Type *t1 = e1->type->toBasetype(); 3055 3055 Type *ectype = t1; 3056 3056 3057 3057 elem *ehidden = irs->ehidden; 3058 3058 irs->ehidden = NULL; 3059 3059 3060 3060 directcall = 0; 3061 3061 fd = NULL; 3062 3062 if (e1->op == TOKdotvar && t1->ty != Tdelegate) 3063 3063 { DotVarExp *dve = (DotVarExp *)e1; 3064 3064 3065 3065 fd = dve->var->isFuncDeclaration(); 3066 3066 Expression *ex = dve->e1; 3067 3067 while (1) 3068 3068 { 3069 3069 switch (ex->op) 3070 3070 { 3071 case TOKsuper: // super .member() calls directly3071 case TOKsuper: // super(args) ctor calls 3072 3072 case TOKdottype: // type.member() calls directly 3073 3073 directcall = 1; 3074 3074 break; 3075 3075 3076 3076 case TOKcast: 3077 3077 ex = ((CastExp *)ex)->e1; 3078 3078 continue; 3079 3079 3080 3080 default: 3081 3081 //ex->dump(0); 3082 3082 break; 3083 3083 } 3084 3084 break; 3085 3085 } 3086 3086 ec = dve->e1->toElem(irs); 3087 3087 ectype = dve->e1->type->toBasetype(); 3088 3088 } 3089 3089 else if (e1->op == TOKvar) 3090 3090 { 3091 3091 fd = ((VarExp *)e1)->var->isFuncDeclaration(); branches/dmd-1.x/src/expression.c
r639 r640 6167 6167 return this; // semantic() already run 6168 6168 #if 0 6169 6169 if (arguments && arguments->dim) 6170 6170 { 6171 6171 Expression *earg = (Expression *)arguments->data[0]; 6172 6172 earg->print(); 6173 6173 if (earg->type) earg->type->print(); 6174 6174 } 6175 6175 #endif 6176 6176 6177 6177 if (e1->op == TOKdelegate) 6178 6178 { DelegateExp *de = (DelegateExp *)e1; 6179 6179 6180 6180 e1 = new DotVarExp(de->loc, de->e1, de->func); 6181 6181 return semantic(sc); 6182 6182 } 6183 6183 6184 6184 /* Transform: 6185 6185 * array.id(args) into id(array,args) 6186 6186 * aa.remove(arg) into delete aa[arg] 6187 * super.id(args) into parent.id(args) 6187 6188 */ 6188 6189 if (e1->op == TOKdot) 6189 6190 { 6190 6191 // BUG: we should handle array.a.b.c.e(args) too 6191 6192 6192 6193 DotIdExp *dotid = (DotIdExp *)(e1); 6193 6194 dotid->e1 = dotid->e1->semantic(sc); 6194 6195 assert(dotid->e1); 6195 6196 if (dotid->e1->type) 6196 6197 { 6197 6198 TY e1ty = dotid->e1->type->toBasetype()->ty; 6198 6199 if (e1ty == Taarray && dotid->ident == Id::remove) 6199 6200 { 6200 6201 if (!arguments || arguments->dim != 1) 6201 6202 { error("expected key as argument to aa.remove()"); 6202 6203 goto Lagain; 6203 6204 } 6204 6205 Expression *key = (Expression *)arguments->data[0]; 6205 6206 key = key->semantic(sc); 6206 6207 key = resolveProperties(sc, key); 6207 6208 key->rvalue(); 6208 6209 6209 6210 TypeAArray *taa = (TypeAArray *)dotid->e1->type->toBasetype(); 6210 6211 key = key->implicitCastTo(sc, taa->index); 6211 6212 key = key->implicitCastTo(sc, taa->key); 6212 6213 6213 6214 return new RemoveExp(loc, dotid->e1, key); 6214 6215 } 6215 6216 else if (e1ty == Tarray || e1ty == Tsarray || e1ty == Taarray) 6216 6217 { 6217 6218 if (!arguments) 6218 6219 arguments = new Expressions(); 6219 6220 arguments->shift(dotid->e1); 6220 6221 #if DMDV2 6221 6222 e1 = new DotIdExp(dotid->loc, new IdentifierExp(dotid->loc, Id::empty), dotid->ident); 6222 6223 #else 6223 6224 e1 = new IdentifierExp(dotid->loc, dotid->ident); 6224 6225 #endif 6226 } 6227 else if (e1ty == Tclass && dotid->e1->op == TOKsuper) 6228 { 6229 // rewrite super.id into this.baseclass.id 6230 6231 FuncDeclaration *fd = hasThis(sc); 6232 6233 Dsymbol *s = fd->toParent(); 6234 while (s && s->isTemplateInstance()) 6235 s = s->toParent(); 6236 6237 ClassDeclaration *cd = s->isClassDeclaration(); 6238 Expression *dte = new DotTypeExp(dotid->loc, new ThisExp(dotid->loc), cd->baseClass); 6239 e1 = new DotIdExp(dotid->loc, dte, dotid->ident); 6225 6240 } 6226 6241 } 6227 6242 } 6228 6243 6229 6244 #if 1 6230 6245 /* This recognizes: 6231 6246 * foo!(tiargs)(funcargs) 6232 6247 */ 6233 6248 if (e1->op == TOKimport && !e1->type) 6234 6249 { ScopeExp *se = (ScopeExp *)e1; 6235 6250 TemplateInstance *ti = se->sds->isTemplateInstance(); 6236 6251 if (ti && !ti->semanticRun) 6237 6252 { 6238 6253 /* Attempt to instantiate ti. If that works, go with it. 6239 6254 * If not, go with partial explicit specialization. 6240 6255 */ 6241 6256 ti->semanticTiargs(sc); 6242 6257 unsigned errors = global.errors; 6243 6258 global.gag++; 6244 6259 ti->semantic(sc); … … 6478 6493 if (e1->op == TOKdotvar) 6479 6494 dve->var = f; 6480 6495 else 6481 6496 e1 = new DotVarExp(loc, dte->e1, f); 6482 6497 e1->type = f->type; 6483 6498 6484 6499 // See if we need to adjust the 'this' pointer 6485 6500 AggregateDeclaration *ad = f->isThis(); 6486 6501 ClassDeclaration *cd = ue->e1->type->isClassHandle(); 6487 6502 if (ad && cd && ad->isClassDeclaration() && ad != cd && 6488 6503 ue->e1->op != TOKsuper) 6489 6504 { 6490 6505 ue->e1 = ue->e1->castTo(sc, ad->type); //new CastExp(loc, ue->e1, ad->type); 6491 6506 ue->e1 = ue->e1->semantic(sc); 6492 6507 } 6493 6508 } 6494 6509 t1 = e1->type; 6495 6510 } 6496 6511 else if (e1->op == TOKsuper) 6497 6512 { 6513 // TODO: rewrite this to lower super(...) to baseclass(...) ? 6498 6514 // Base class constructor call 6499 6515 ClassDeclaration *cd = NULL; 6500 6516 6501 6517 if (sc->func) 6502 6518 cd = sc->func->toParent()->isClassDeclaration(); 6503 6519 if (!cd || !cd->baseClass || !sc->func->isCtorDeclaration()) 6504 6520 { 6505 6521 error("super class constructor call must be in a constructor"); 6506 6522 type = Type::terror; 6507 6523 return this; 6508 6524 } 6509 6525 else 6510 6526 { 6511 6527 f = cd->baseClass->ctor; 6512 6528 if (!f) 6513 6529 { error("no super class constructor for %s", cd->baseClass->toChars()); 6514 6530 type = Type::terror; 6515 6531 return this; 6516 6532 } 6517 6533 else branches/dmd-1.x/src/inline.c
r505 r640 264 264 return cost; 265 265 } 266 266 267 267 int UnaExp::inlineCost(InlineCostState *ics) 268 268 { 269 269 return 1 + e1->inlineCost(ics); 270 270 } 271 271 272 272 int AssertExp::inlineCost(InlineCostState *ics) 273 273 { 274 274 return 1 + e1->inlineCost(ics) + (msg ? msg->inlineCost(ics) : 0); 275 275 } 276 276 277 277 int BinExp::inlineCost(InlineCostState *ics) 278 278 { 279 279 return 1 + e1->inlineCost(ics) + e2->inlineCost(ics); 280 280 } 281 281 282 282 int CallExp::inlineCost(InlineCostState *ics) 283 283 { 284 // Bugzilla 3500: super.func() calls must be devirtualized, and the inliner285 // can't handle that at present.286 if (e1->op == TOKdotvar && ((DotVarExp *)e1)->e1->op == TOKsuper)287 return COST_MAX;288 289 284 return 1 + e1->inlineCost(ics) + arrayInlineCost(ics, arguments); 290 285 } 291 286 292 287 int SliceExp::inlineCost(InlineCostState *ics) 293 288 { int cost; 294 289 295 290 cost = 1 + e1->inlineCost(ics); 296 291 if (lwr) 297 292 cost += lwr->inlineCost(ics); 298 293 if (upr) 299 294 cost += upr->inlineCost(ics); 300 295 return cost; 301 296 } 302 297 303 298 int ArrayExp::inlineCost(InlineCostState *ics) 304 299 { 305 300 return 1 + e1->inlineCost(ics) + arrayInlineCost(ics, arguments); 306 301 } 307 302 308 303 trunk/src/e2ir.c
r621 r640 3345 3345 int directcall; 3346 3346 FuncDeclaration *fd; 3347 3347 Type *t1 = e1->type->toBasetype(); 3348 3348 Type *ectype = t1; 3349 3349 elem *eeq = NULL; 3350 3350 3351 3351 elem *ehidden = irs->ehidden; 3352 3352 irs->ehidden = NULL; 3353 3353 3354 3354 directcall = 0; 3355 3355 fd = NULL; 3356 3356 if (e1->op == TOKdotvar && t1->ty != Tdelegate) 3357 3357 { DotVarExp *dve = (DotVarExp *)e1; 3358 3358 3359 3359 fd = dve->var->isFuncDeclaration(); 3360 3360 Expression *ex = dve->e1; 3361 3361 while (1) 3362 3362 { 3363 3363 switch (ex->op) 3364 3364 { 3365 case TOKsuper: // super .member() calls directly3365 case TOKsuper: // super(args) ctor calls 3366 3366 case TOKdottype: // type.member() calls directly 3367 3367 directcall = 1; 3368 3368 break; 3369 3369 3370 3370 case TOKcast: 3371 3371 ex = ((CastExp *)ex)->e1; 3372 3372 continue; 3373 3373 3374 3374 default: 3375 3375 //ex->dump(0); 3376 3376 break; 3377 3377 } 3378 3378 break; 3379 3379 } 3380 3380 ec = dve->e1->toElem(irs); 3381 3381 ectype = dve->e1->type->toBasetype(); 3382 3382 } 3383 3383 else if (e1->op == TOKvar) 3384 3384 { 3385 3385 fd = ((VarExp *)e1)->var->isFuncDeclaration(); trunk/src/expression.c
r639 r640 6508 6508 return this; // semantic() already run 6509 6509 #if 0 6510 6510 if (arguments && arguments->dim) 6511 6511 { 6512 6512 Expression *earg = (Expression *)arguments->data[0]; 6513 6513 earg->print(); 6514 6514 if (earg->type) earg->type->print(); 6515 6515 } 6516 6516 #endif 6517 6517 6518 6518 if (e1->op == TOKdelegate) 6519 6519 { DelegateExp *de = (DelegateExp *)e1; 6520 6520 6521 6521 e1 = new DotVarExp(de->loc, de->e1, de->func); 6522 6522 return semantic(sc); 6523 6523 } 6524 6524 6525 6525 /* Transform: 6526 6526 * array.id(args) into .id(array,args) 6527 6527 * aa.remove(arg) into delete aa[arg] 6528 * super.id(args) into parent.id(args) 6528 6529 */ 6529 6530 if (e1->op == TOKdot) 6530 6531 { 6531 6532 // BUG: we should handle array.a.b.c.e(args) too 6532 6533 6533 6534 DotIdExp *dotid = (DotIdExp *)(e1); 6534 6535 dotid->e1 = dotid->e1->semantic(sc); 6535 6536 assert(dotid->e1); 6536 6537 if (dotid->e1->type) 6537 6538 { 6538 6539 TY e1ty = dotid->e1->type->toBasetype()->ty; 6539 6540 if (e1ty == Taarray && dotid->ident == Id::remove) 6540 6541 { 6541 6542 if (!arguments || arguments->dim != 1) 6542 6543 { error("expected key as argument to aa.remove()"); 6543 6544 return new ErrorExp(); 6544 6545 } 6545 6546 Expression *key = (Expression *)arguments->data[0]; 6546 6547 key = key->semantic(sc); 6547 6548 key = resolveProperties(sc, key); … … 6555 6556 else if (e1ty == Tarray || e1ty == Tsarray || 6556 6557 (e1ty == Taarray && dotid->ident != Id::apply && dotid->ident != Id::applyReverse)) 6557 6558 { 6558 6559 if (e1ty == Taarray) 6559 6560 { TypeAArray *taa = (TypeAArray *)dotid->e1->type->toBasetype(); 6560 6561 assert(taa->ty == Taarray); 6561 6562 StructDeclaration *sd = taa->getImpl(); 6562 6563 Dsymbol *s = sd->search(0, dotid->ident, 2); 6563 6564 if (s) 6564 6565 goto L2; 6565 6566 } 6566 6567 if (!arguments) 6567 6568 arguments = new Expressions(); 6568 6569 arguments->shift(dotid->e1); 6569 6570 #if DMDV2 6570 6571 e1 = new DotIdExp(dotid->loc, new IdentifierExp(dotid->loc, Id::empty), dotid->ident); 6571 6572 #else 6572 6573 e1 = new IdentifierExp(dotid->loc, dotid->ident); 6573 6574 #endif 6574 6575 } 6576 else if (e1ty == Tclass && dotid->e1->op == TOKsuper) 6577 { 6578 // rewrite super.id into this.baseclass.id 6579 6580 FuncDeclaration *fd = hasThis(sc); 6581 6582 Dsymbol *s = fd->toParent(); 6583 while (s && s->isTemplateInstance()) 6584 s = s->toParent(); 6585 6586 ClassDeclaration *cd = s->isClassDeclaration(); 6587 Expression *dte = new DotTypeExp(dotid->loc, new ThisExp(dotid->loc), cd->baseClass); 6588 e1 = new DotIdExp(dotid->loc, dte, dotid->ident); 6589 } 6590 6575 6591 L2: 6576 6592 ; 6577 6593 } 6578 6594 } 6579 6595 6580 6596 #if 1 6581 6597 /* This recognizes: 6582 6598 * foo!(tiargs)(funcargs) 6583 6599 */ 6584 6600 if (e1->op == TOKimport && !e1->type) 6585 6601 { ScopeExp *se = (ScopeExp *)e1; 6586 6602 TemplateInstance *ti = se->sds->isTemplateInstance(); 6587 6603 if (ti && !ti->semanticRun) 6588 6604 { 6589 6605 /* Attempt to instantiate ti. If that works, go with it. 6590 6606 * If not, go with partial explicit specialization. 6591 6607 */ 6592 6608 ti->semanticTiargs(sc); 6593 6609 if (ti->needsTypeInference(sc)) 6594 6610 { … … 6922 6938 { VarExp *v = (VarExp *)ue->e1; 6923 6939 if (v->var->storage_class & STCfinal) 6924 6940 error("cannot call mutable method on final struct"); 6925 6941 } 6926 6942 } 6927 6943 6928 6944 // See if we need to adjust the 'this' pointer 6929 6945 AggregateDeclaration *ad = f->isThis(); 6930 6946 ClassDeclaration *cd = ue->e1->type->isClassHandle(); 6931 6947 if (ad && cd && ad->isClassDeclaration() && ad != cd && 6932 6948 ue->e1->op != TOKsuper) 6933 6949 { 6934 6950 ue->e1 = ue->e1->castTo(sc, ad->type); //new CastExp(loc, ue->e1, ad->type); 6935 6951 ue->e1 = ue->e1->semantic(sc); 6936 6952 } 6937 6953 } 6938 6954 t1 = e1->type; 6939 6955 } 6940 6956 else if (e1->op == TOKsuper) 6941 6957 { 6958 // TODO: rewrite this to lower super(...) to baseclass(...) ? 6942 6959 // Base class constructor call 6943 6960 ClassDeclaration *cd = NULL; 6944 6961 6945 6962 if (sc->func) 6946 6963 cd = sc->func->toParent()->isClassDeclaration(); 6947 6964 if (!cd || !cd->baseClass || !sc->func->isCtorDeclaration()) 6948 6965 { 6949 6966 error("super class constructor call must be in a constructor"); 6950 6967 return new ErrorExp(); 6951 6968 } 6952 6969 else 6953 6970 { 6954 6971 if (!cd->baseClass->ctor) 6955 6972 { error("no super class constructor for %s", cd->baseClass->toChars()); 6956 6973 return new ErrorExp(); 6957 6974 } 6958 6975 else 6959 6976 { 6960 6977 if (!sc->intypeof) 6961 6978 { trunk/src/inline.c
r520 r640 265 265 return cost; 266 266 } 267 267 268 268 int UnaExp::inlineCost(InlineCostState *ics) 269 269 { 270 270 return 1 + e1->inlineCost(ics); 271 271 } 272 272 273 273 int AssertExp::inlineCost(InlineCostState *ics) 274 274 { 275 275 return 1 + e1->inlineCost(ics) + (msg ? msg->inlineCost(ics) : 0); 276 276 } 277 277 278 278 int BinExp::inlineCost(InlineCostState *ics) 279 279 { 280 280 return 1 + e1->inlineCost(ics) + e2->inlineCost(ics); 281 281 } 282 282 283 283 int CallExp::inlineCost(InlineCostState *ics) 284 284 { 285 // Bugzilla 3500: super.func() calls must be devirtualized, and the inliner286 // can't handle that at present.287 if (e1->op == TOKdotvar && ((DotVarExp *)e1)->e1->op == TOKsuper)288 return COST_MAX;289 290 285 return 1 + e1->inlineCost(ics) + arrayInlineCost(ics, arguments); 291 286 } 292 287 293 288 int SliceExp::inlineCost(InlineCostState *ics) 294 289 { int cost; 295 290 296 291 cost = 1 + e1->inlineCost(ics); 297 292 if (lwr) 298 293 cost += lwr->inlineCost(ics); 299 294 if (upr) 300 295 cost += upr->inlineCost(ics); 301 296 return cost; 302 297 } 303 298 304 299 int ArrayExp::inlineCost(InlineCostState *ics) 305 300 { 306 301 return 1 + e1->inlineCost(ics) + arrayInlineCost(ics, arguments); 307 302 } 308 303 309 304
