| | 7110 | static MATCH aliasthisConvTo(AggregateDeclaration *ad, Type *from, Type *to) |
|---|
| | 7111 | { |
|---|
| | 7112 | assert(ad->aliasthis); |
|---|
| | 7113 | Declaration *d = ad->aliasthis->isDeclaration(); |
|---|
| | 7114 | if (d) |
|---|
| | 7115 | { assert(d->type); |
|---|
| | 7116 | Type *t = d->type; |
|---|
| | 7117 | if (d->isVarDeclaration() && d->needThis()) |
|---|
| | 7118 | { |
|---|
| | 7119 | t = t->addMod(from->mod); |
|---|
| | 7120 | } |
|---|
| | 7121 | else if (d->isFuncDeclaration()) |
|---|
| | 7122 | { |
|---|
| | 7123 | FuncDeclaration *fd = (FuncDeclaration *)d; |
|---|
| | 7124 | Expression *ethis = from->defaultInit(0); |
|---|
| | 7125 | fd = fd->overloadResolve(0, ethis, NULL); |
|---|
| | 7126 | if (fd) |
|---|
| | 7127 | t = ((TypeFunction *)fd->type)->next; |
|---|
| | 7128 | } |
|---|
| | 7129 | return t->implicitConvTo(to); |
|---|
| | 7130 | } |
|---|
| | 7131 | return MATCHnomatch; |
|---|
| | 7132 | } |
|---|
| | 7133 | |
|---|
| 7110 | 7134 | MATCH TypeStruct::implicitConvTo(Type *to) |
|---|
| 7111 | 7135 | { MATCH m; |
|---|
| 7112 | 7136 | |
|---|
| 7113 | 7137 | //printf("TypeStruct::implicitConvTo(%s => %s)\n", toChars(), to->toChars()); |
|---|
| 7114 | 7138 | if (to->ty == Taarray) |
|---|
| 7115 | 7139 | { |
|---|
| 7116 | 7140 | /* If there is an error instantiating AssociativeArray!(), it shouldn't |
|---|
| 7117 | 7141 | * be reported -- it just means implicit conversion is impossible. |
|---|
| 7118 | 7142 | */ |
|---|
| 7119 | 7143 | ++global.gag; |
|---|
| 7120 | 7144 | int errs = global.errors; |
|---|
| 7121 | 7145 | to = ((TypeAArray*)to)->getImpl()->type; |
|---|
| 7122 | 7146 | --global.gag; |
|---|
| 7123 | 7147 | if (errs != global.errors) |
|---|
| 7124 | 7148 | { global.errors = errs; |
|---|
| 7125 | 7149 | return MATCHnomatch; |
|---|
| 7126 | 7150 | } |
|---|
| 7127 | 7151 | } |
|---|
| 7128 | 7152 | |
|---|
| 7129 | 7153 | if (ty == to->ty && sym == ((TypeStruct *)to)->sym) |
|---|
| 7139 | 7163 | for (int i = 0; i < sym->fields.dim; i++) |
|---|
| 7140 | 7164 | { Dsymbol *s = (Dsymbol *)sym->fields.data[i]; |
|---|
| 7141 | 7165 | VarDeclaration *v = s->isVarDeclaration(); |
|---|
| 7142 | 7166 | assert(v && v->storage_class & STCfield); |
|---|
| 7143 | 7167 | |
|---|
| 7144 | 7168 | // 'from' type |
|---|
| 7145 | 7169 | Type *tvf = v->type->addMod(mod); |
|---|
| 7146 | 7170 | |
|---|
| 7147 | 7171 | // 'to' type |
|---|
| 7148 | 7172 | Type *tv = v->type->castMod(to->mod); |
|---|
| 7149 | 7173 | |
|---|
| 7150 | 7174 | //printf("\t%s => %s, match = %d\n", v->type->toChars(), tv->toChars(), tvf->implicitConvTo(tv)); |
|---|
| 7151 | 7175 | if (tvf->implicitConvTo(tv) < MATCHconst) |
|---|
| 7152 | 7176 | return MATCHnomatch; |
|---|
| 7153 | 7177 | } |
|---|
| 7154 | 7178 | m = MATCHconst; |
|---|
| 7155 | 7179 | } |
|---|
| 7156 | 7180 | } |
|---|
| 7157 | 7181 | } |
|---|
| 7158 | 7182 | else if (sym->aliasthis) |
|---|
| 7563 | 7579 | //printf("TypeClass::implicitConvTo(to = '%s') %s\n", to->toChars(), toChars()); |
|---|
| 7564 | 7580 | MATCH m = constConv(to); |
|---|
| 7565 | 7581 | if (m != MATCHnomatch) |
|---|
| 7566 | 7582 | return m; |
|---|
| 7567 | 7583 | |
|---|
| 7568 | 7584 | ClassDeclaration *cdto = to->isClassHandle(); |
|---|
| 7569 | 7585 | if (cdto && cdto->isBaseOf(sym, NULL)) |
|---|
| 7570 | 7586 | { //printf("'to' is base\n"); |
|---|
| 7571 | 7587 | return MATCHconvert; |
|---|
| 7572 | 7588 | } |
|---|
| 7573 | 7589 | |
|---|
| 7574 | 7590 | if (global.params.Dversion == 1) |
|---|
| 7575 | 7591 | { |
|---|
| 7576 | 7592 | // Allow conversion to (void *) |
|---|
| 7577 | 7593 | if (to->ty == Tpointer && ((TypePointer *)to)->next->ty == Tvoid) |
|---|
| 7578 | 7594 | return MATCHconvert; |
|---|
| 7579 | 7595 | } |
|---|
| 7580 | 7596 | |
|---|
| 7581 | 7597 | m = MATCHnomatch; |
|---|
| 7582 | 7598 | if (sym->aliasthis) |
|---|