Changeset 232
- Timestamp:
- 11/01/09 05:24:14 (15 years ago)
- Files:
-
- branches/dmd-1.x/src/expression.c (modified) (1 diff)
- trunk/src/expression.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/dmd-1.x/src/expression.c
r230 r232 7108 7108 #if LOGSEMANTIC 7109 7109 printf("CastExp::semantic('%s')\n", toChars()); 7110 7110 #endif 7111 7111 7112 7112 //static int x; assert(++x < 10); 7113 7113 7114 7114 if (type) 7115 7115 return this; 7116 7116 UnaExp::semantic(sc); 7117 7117 if (e1->type) // if not a tuple 7118 7118 { 7119 7119 e1 = resolveProperties(sc, e1); 7120 7120 to = to->semantic(loc, sc); 7121 7121 7122 7122 e = op_overload(sc); 7123 7123 if (e) 7124 7124 { 7125 7125 return e->implicitCastTo(sc, to); 7126 7126 } 7127 7127 7128 if (e1->op == TOKtemplate) 7129 { 7130 error("cannot cast template %s to type %s", e1->toChars(), to->toChars()); 7131 return new ErrorExp(); 7132 } 7133 7128 7134 Type *t1b = e1->type->toBasetype(); 7129 7135 Type *tob = to->toBasetype(); 7130 7136 if (tob->ty == Tstruct && 7131 7137 !tob->equals(t1b) && 7132 7138 ((TypeStruct *)to)->sym->search(0, Id::call, 0) 7133 7139 ) 7134 7140 { 7135 7141 /* Look to replace: 7136 7142 * cast(S)t 7137 7143 * with: 7138 7144 * S(t) 7139 7145 */ 7140 7146 7141 7147 // Rewrite as to.call(e1) 7142 7148 e = new TypeExp(loc, to); 7143 7149 e = new DotIdExp(loc, e, Id::call); 7144 7150 e = new CallExp(loc, e, e1); 7145 7151 e = e->semantic(sc); 7146 7152 return e; 7147 7153 } trunk/src/expression.c
r230 r232 7434 7434 e1 = resolveProperties(sc, e1); 7435 7435 7436 7436 if (!to) 7437 7437 { 7438 7438 /* Handle cast(const) and cast(immutable), etc. 7439 7439 */ 7440 7440 to = e1->type->castMod(mod); 7441 7441 } 7442 7442 else 7443 7443 to = to->semantic(loc, sc); 7444 7444 7445 7445 if (!to->equals(e1->type)) 7446 7446 { 7447 7447 e = op_overload(sc); 7448 7448 if (e) 7449 7449 { 7450 7450 return e->implicitCastTo(sc, to); 7451 7451 } 7452 7452 } 7453 7453 7454 if (e1->op == TOKtemplate) 7455 { 7456 error("cannot cast template %s to type %s", e1->toChars(), to->toChars()); 7457 return new ErrorExp(); 7458 } 7459 7454 7460 Type *t1b = e1->type->toBasetype(); 7455 7461 Type *tob = to->toBasetype(); 7456 7462 if (tob->ty == Tstruct && 7457 7463 !tob->equals(t1b) && 7458 7464 ((TypeStruct *)tob)->sym->search(0, Id::call, 0) 7459 7465 ) 7460 7466 { 7461 7467 /* Look to replace: 7462 7468 * cast(S)t 7463 7469 * with: 7464 7470 * S(t) 7465 7471 */ 7466 7472 7467 7473 // Rewrite as to.call(e1) 7468 7474 e = new TypeExp(loc, to); 7469 7475 e = new DotIdExp(loc, e, Id::call); 7470 7476 e = new CallExp(loc, e, e1); 7471 7477 e = e->semantic(sc); 7472 7478 return e; 7473 7479 }
