Changeset 818
- Timestamp:
- 12/27/10 02:31:18 (14 years ago)
- Files:
-
- trunk/src/cast.c (modified) (1 diff)
- trunk/src/mtype.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/cast.c
r774 r818 805 805 return toDelegate(sc, tf->nextOf()); 806 806 } 807 807 #endif 808 808 else 809 809 { 810 810 if (typeb->ty == Tstruct) 811 811 { TypeStruct *ts = (TypeStruct *)typeb; 812 812 if (!(tb->ty == Tstruct && ts->sym == ((TypeStruct *)tb)->sym) && 813 813 ts->sym->aliasthis) 814 814 { /* Forward the cast to our alias this member, rewrite to: 815 815 * cast(to)e1.aliasthis 816 816 */ 817 817 Expression *e1 = new DotIdExp(loc, this, ts->sym->aliasthis->ident); 818 818 Expression *e = new CastExp(loc, e1, tb); 819 819 e = e->semantic(sc); 820 820 return e; 821 821 } 822 822 } 823 823 else if (typeb->ty == Tclass) 824 824 { TypeClass *ts = (TypeClass *)typeb; 825 if (tb->ty != Tclass && 826 ts->sym->aliasthis) 827 { /* Forward the cast to our alias this member, rewrite to: 825 if (ts->sym->aliasthis) 826 { 827 if (tb->ty == Tclass) 828 { 829 ClassDeclaration *cdfrom = typeb->isClassHandle(); 830 ClassDeclaration *cdto = tb->isClassHandle(); 831 int offset; 832 if (cdto->isBaseOf(cdfrom, &offset)) 833 goto L1; 834 } 835 /* Forward the cast to our alias this member, rewrite to: 828 836 * cast(to)e1.aliasthis 829 837 */ 830 838 Expression *e1 = new DotIdExp(loc, this, ts->sym->aliasthis->ident); 831 839 Expression *e = new CastExp(loc, e1, tb); 832 840 e = e->semantic(sc); 833 841 return e; 834 842 } 843 L1: ; 835 844 } 836 845 e = new CastExp(loc, e, tb); 837 846 } 838 847 } 839 848 else 840 849 { 841 850 e = e->copy(); // because of COW for assignment to e->type 842 851 } 843 852 assert(e != this); 844 853 e->type = t; 845 854 //printf("Returning: %s\n", e->toChars()); 846 855 return e; 847 856 } 848 857 849 858 850 859 Expression *RealExp::castTo(Scope *sc, Type *t) 851 860 { Expression *e = this; 852 861 if (type != t) 853 862 { 854 863 if ((type->isreal() && t->isreal()) || trunk/src/mtype.c
r812 r818 7111 7111 return FALSE; 7112 7112 } 7113 7113 7114 7114 static MATCH aliasthisConvTo(AggregateDeclaration *ad, Type *from, Type *to) 7115 7115 { 7116 7116 assert(ad->aliasthis); 7117 7117 Declaration *d = ad->aliasthis->isDeclaration(); 7118 7118 if (d) 7119 7119 { assert(d->type); 7120 7120 Type *t = d->type; 7121 7121 if (d->isVarDeclaration() && d->needThis()) 7122 7122 { 7123 7123 t = t->addMod(from->mod); 7124 7124 } 7125 7125 else if (d->isFuncDeclaration()) 7126 7126 { 7127 7127 FuncDeclaration *fd = (FuncDeclaration *)d; 7128 7128 Expression *ethis = from->defaultInit(0); 7129 7129 fd = fd->overloadResolve(0, ethis, NULL); 7130 7130 if (fd) 7131 { 7131 7132 t = ((TypeFunction *)fd->type)->next; 7132 } 7133 return t->implicitConvTo(to); 7133 } 7134 } 7135 MATCH m = t->implicitConvTo(to); 7136 return m; 7134 7137 } 7135 7138 return MATCHnomatch; 7136 7139 } 7137 7140 7138 7141 MATCH TypeStruct::implicitConvTo(Type *to) 7139 7142 { MATCH m; 7140 7143 7141 7144 //printf("TypeStruct::implicitConvTo(%s => %s)\n", toChars(), to->toChars()); 7142 7145 if (to->ty == Taarray) 7143 7146 { 7144 7147 /* If there is an error instantiating AssociativeArray!(), it shouldn't 7145 7148 * be reported -- it just means implicit conversion is impossible. 7146 7149 */ 7147 7150 ++global.gag; 7148 7151 int errs = global.errors; 7149 7152 to = ((TypeAArray*)to)->getImpl()->type; 7150 7153 --global.gag; 7151 7154 if (errs != global.errors) 7152 7155 { 7153 7156 global.errors = errs;
