comparison dmd/cast.c @ 1587:def7a1d494fd

Merge DMD 1.051
author Christian Kamm <kamm incasoftware de>
date Fri, 06 Nov 2009 23:58:01 +0100
parents 8026319762be
children c61782a76dff
comparison
equal deleted inserted replaced
1586:7f728c52e63c 1587:def7a1d494fd
1076 return e->Expression::castTo(sc, t); 1076 return e->Expression::castTo(sc, t);
1077 } 1077 }
1078 1078
1079 Expression *SymOffExp::castTo(Scope *sc, Type *t) 1079 Expression *SymOffExp::castTo(Scope *sc, Type *t)
1080 { 1080 {
1081 Type *tb;
1082
1083 #if 0 1081 #if 0
1084 printf("SymOffExp::castTo(this=%s, type=%s, t=%s)\n", 1082 printf("SymOffExp::castTo(this=%s, type=%s, t=%s)\n",
1085 toChars(), type->toChars(), t->toChars()); 1083 toChars(), type->toChars(), t->toChars());
1086 #endif 1084 #endif
1087 Expression *e = this; 1085 Expression *e = this;
1088 1086
1089 tb = t->toBasetype(); 1087 Type *tb = t->toBasetype();
1090 type = type->toBasetype(); 1088 Type *typeb = type->toBasetype();
1091 if (tb != type) 1089 if (tb != typeb)
1092 { 1090 {
1093 // Look for pointers to functions where the functions are overloaded. 1091 // Look for pointers to functions where the functions are overloaded.
1094 FuncDeclaration *f; 1092 FuncDeclaration *f;
1095 1093
1096 if (type->ty == Tpointer && type->next->ty == Tfunction && 1094 if (typeb->ty == Tpointer && typeb->next->ty == Tfunction &&
1097 tb->ty == Tpointer && tb->next->ty == Tfunction) 1095 tb->ty == Tpointer && tb->next->ty == Tfunction)
1098 { 1096 {
1099 f = var->isFuncDeclaration(); 1097 f = var->isFuncDeclaration();
1100 if (f) 1098 if (f)
1101 { 1099 {
1102 f = f->overloadExactMatch(tb->next, m); 1100 f = f->overloadExactMatch(tb->next, m);
1103 if (f) 1101 if (f)
1104 { 1102 {
1105 e = new SymOffExp(loc, f, 0); 1103 #if DMDV2
1106 e->type = t; 1104 if (tb->ty == Tdelegate)
1105 {
1106 if (f->needThis() && hasThis(sc))
1107 {
1108 e = new DelegateExp(loc, new ThisExp(loc), f);
1109 e = e->semantic(sc);
1110 }
1111 else if (f->isNested())
1112 {
1113 e = new DelegateExp(loc, new IntegerExp(0), f);
1114 e = e->semantic(sc);
1115 }
1116 else if (f->needThis())
1117 { error("no 'this' to create delegate for %s", f->toChars());
1118 e = new ErrorExp();
1119 }
1120 else
1121 { error("cannot cast from function pointer to delegate");
1122 e = new ErrorExp();
1123 }
1124 }
1125 else
1126 #endif
1127 {
1128 e = new SymOffExp(loc, f, 0);
1129 e->type = t;
1130 }
1131 #if DMDV2
1132 f->tookAddressOf++;
1133 #endif
1107 return e; 1134 return e;
1108 } 1135 }
1109 } 1136 }
1110 } 1137 }
1111 e = Expression::castTo(sc, t); 1138 e = Expression::castTo(sc, t);
1112 } 1139 }
1113 e->type = t; 1140 else
1141 {
1142 e->type = t;
1143 }
1114 return e; 1144 return e;
1115 } 1145 }
1116 1146
1117 Expression *DelegateExp::castTo(Scope *sc, Type *t) 1147 Expression *DelegateExp::castTo(Scope *sc, Type *t)
1118 { 1148 {
1482 } 1512 }
1483 else if (t1->isintegral() && t2->isintegral()) 1513 else if (t1->isintegral() && t2->isintegral())
1484 { 1514 {
1485 assert(0); 1515 assert(0);
1486 } 1516 }
1487 else if (e1->op == TOKslice && t1->ty == Tarray && 1517 else if (e1->isArrayOperand() && t1->ty == Tarray &&
1488 e2->implicitConvTo(t1->nextOf())) 1518 e2->implicitConvTo(t1->nextOf()))
1489 { // T[] op T 1519 { // T[] op T
1490 e2 = e2->castTo(sc, t1->nextOf()); 1520 e2 = e2->castTo(sc, t1->nextOf());
1491 t = t1->nextOf()->arrayOf(); 1521 t = t1->nextOf()->arrayOf();
1492 } 1522 }
1493 else if (e2->op == TOKslice && t2->ty == Tarray && 1523 else if (e2->isArrayOperand() && t2->ty == Tarray &&
1494 e1->implicitConvTo(t2->nextOf())) 1524 e1->implicitConvTo(t2->nextOf()))
1495 { // T op T[] 1525 { // T op T[]
1496 e1 = e1->castTo(sc, t2->nextOf()); 1526 e1 = e1->castTo(sc, t2->nextOf());
1497 t = t2->nextOf()->arrayOf(); 1527 t = t2->nextOf()->arrayOf();
1498 1528