Changeset 1358:78038e540342
- Timestamp:
- 05/16/09 10:17:33
(16 years ago)
- Author:
- Christian Kamm <kamm incasoftware de>
- Children:
1360:015e00affbb9 1362:194852badf8c
- branch:
- default
- Message:
Fix overload resolution issue in dmd bug 313/314 fix.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| Revision 1195:e961851fb8be |
Revision 1358:78038e540342 |
| 521 | t->ty == Tpointer && t->next->ty == Tfunction && | 521 | t->ty == Tpointer && t->next->ty == Tfunction && |
|---|
| 522 | e1->op == TOKvar) | 522 | e1->op == TOKvar) |
|---|
| 523 | { | 523 | { |
|---|
| 524 | ve = (VarExp *)e1; | 524 | ve = (VarExp *)e1; |
|---|
| 525 | f = ve->var->isFuncDeclaration(); | 525 | f = ve->var->isFuncDeclaration(); |
|---|
| 526 | if (f && f->overloadExactMatch(t->next)) | 526 | if (f && f->overloadExactMatch(t->next, m)) |
|---|
| 527 | result = MATCHexact; | 527 | result = MATCHexact; |
|---|
| 528 | } | 528 | } |
|---|
| 529 | } | 529 | } |
|---|
| 530 | //printf("\tresult = %d\n", result); | 530 | //printf("\tresult = %d\n", result); |
|---|
| 531 | return result; | 531 | return result; |
|---|
| … | | … | |
| 550 | t = t->toBasetype(); | 550 | t = t->toBasetype(); |
|---|
| 551 | if (type->ty == Tpointer && type->next->ty == Tfunction && | 551 | if (type->ty == Tpointer && type->next->ty == Tfunction && |
|---|
| 552 | t->ty == Tpointer && t->next->ty == Tfunction) | 552 | t->ty == Tpointer && t->next->ty == Tfunction) |
|---|
| 553 | { | 553 | { |
|---|
| 554 | f = var->isFuncDeclaration(); | 554 | f = var->isFuncDeclaration(); |
|---|
| 555 | if (f && f->overloadExactMatch(t->next)) | 555 | if (f && f->overloadExactMatch(t->next, m)) |
|---|
| 556 | result = MATCHexact; | 556 | result = MATCHexact; |
|---|
| 557 | } | 557 | } |
|---|
| 558 | } | 558 | } |
|---|
| 559 | //printf("\tresult = %d\n", result); | 559 | //printf("\tresult = %d\n", result); |
|---|
| 560 | return result; | 560 | return result; |
|---|
| … | | … | |
| 577 | | 577 | |
|---|
| 578 | t = t->toBasetype(); | 578 | t = t->toBasetype(); |
|---|
| 579 | if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction && | 579 | if (type->ty == Tdelegate && type->nextOf()->ty == Tfunction && |
|---|
| 580 | t->ty == Tdelegate && t->nextOf()->ty == Tfunction) | 580 | t->ty == Tdelegate && t->nextOf()->ty == Tfunction) |
|---|
| 581 | { | 581 | { |
|---|
| 582 | if (func && func->overloadExactMatch(t->nextOf())) | 582 | if (func && func->overloadExactMatch(t->nextOf(), m)) |
|---|
| 583 | result = MATCHexact; | 583 | result = MATCHexact; |
|---|
| 584 | } | 584 | } |
|---|
| 585 | } | 585 | } |
|---|
| 586 | return result; | 586 | return result; |
|---|
| 587 | } | 587 | } |
|---|
| … | | … | |
| 973 | { | 973 | { |
|---|
| 974 | ve = (VarExp *)e1; | 974 | ve = (VarExp *)e1; |
|---|
| 975 | f = ve->var->isFuncDeclaration(); | 975 | f = ve->var->isFuncDeclaration(); |
|---|
| 976 | if (f) | 976 | if (f) |
|---|
| 977 | { | 977 | { |
|---|
| 978 | f = f->overloadExactMatch(tb->next); | 978 | f = f->overloadExactMatch(tb->next, m); |
|---|
| 979 | if (f) | 979 | if (f) |
|---|
| 980 | { | 980 | { |
|---|
| 981 | e = new VarExp(loc, f); | 981 | e = new VarExp(loc, f); |
|---|
| 982 | e->type = f->type; | 982 | e->type = f->type; |
|---|
| 983 | e = new AddrExp(loc, e); | 983 | e = new AddrExp(loc, e); |
|---|
| … | | … | |
| 1097 | tb->ty == Tpointer && tb->next->ty == Tfunction) | 1097 | tb->ty == Tpointer && tb->next->ty == Tfunction) |
|---|
| 1098 | { | 1098 | { |
|---|
| 1099 | f = var->isFuncDeclaration(); | 1099 | f = var->isFuncDeclaration(); |
|---|
| 1100 | if (f) | 1100 | if (f) |
|---|
| 1101 | { | 1101 | { |
|---|
| 1102 | f = f->overloadExactMatch(tb->next); | 1102 | f = f->overloadExactMatch(tb->next, m); |
|---|
| 1103 | if (f) | 1103 | if (f) |
|---|
| 1104 | { | 1104 | { |
|---|
| 1105 | e = new SymOffExp(loc, f, 0); | 1105 | e = new SymOffExp(loc, f, 0); |
|---|
| 1106 | e->type = t; | 1106 | e->type = t; |
|---|
| 1107 | return e; | 1107 | return e; |
|---|
| … | | … | |
| 1134 | if (type->ty == Tdelegate && type->next->ty == Tfunction && | 1134 | if (type->ty == Tdelegate && type->next->ty == Tfunction && |
|---|
| 1135 | tb->ty == Tdelegate && tb->next->ty == Tfunction) | 1135 | tb->ty == Tdelegate && tb->next->ty == Tfunction) |
|---|
| 1136 | { | 1136 | { |
|---|
| 1137 | if (func) | 1137 | if (func) |
|---|
| 1138 | { | 1138 | { |
|---|
| 1139 | f = func->overloadExactMatch(tb->next); | 1139 | f = func->overloadExactMatch(tb->next, m); |
|---|
| 1140 | if (f) | 1140 | if (f) |
|---|
| 1141 | { int offset; | 1141 | { int offset; |
|---|
| 1142 | if (f->tintro && f->tintro->next->isBaseOf(f->type->next, &offset) && offset) | 1142 | if (f->tintro && f->tintro->next->isBaseOf(f->type->next, &offset) && offset) |
|---|
| 1143 | error("%s", msg); | 1143 | error("%s", msg); |
|---|
| 1144 | e = new DelegateExp(loc, e1, f); | 1144 | e = new DelegateExp(loc, e1, f); |
|---|
| Revision 1195:e961851fb8be |
Revision 1358:78038e540342 |
| 838 | */ | 838 | */ |
|---|
| 839 | return 0; | 839 | return 0; |
|---|
| 840 | } | 840 | } |
|---|
| 841 | FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration(); | 841 | FuncDeclaration *fdstart = s->toAlias()->isFuncDeclaration(); |
|---|
| 842 | //printf("%s fdstart = %p\n", s->kind(), fdstart); | 842 | //printf("%s fdstart = %p\n", s->kind(), fdstart); |
|---|
| 843 | return !overloadApply(fdstart, &isf, fd); | 843 | return !overloadApply(getModule(), fdstart, &isf, fd); |
|---|
| 844 | } | 844 | } |
|---|
| 845 | #endif | 845 | #endif |
|---|
| 846 | | 846 | |
|---|
| 847 | /**************** | 847 | /**************** |
|---|
| 848 | * Find virtual function matching identifier and type. | 848 | * Find virtual function matching identifier and type. |
|---|
| Revision 1309:0c03ba6f7c24 |
Revision 1358:78038e540342 |
| 367 | this->htype = NULL; | 367 | this->htype = NULL; |
|---|
| 368 | this->haliassym = NULL; | 368 | this->haliassym = NULL; |
|---|
| 369 | #endif | 369 | #endif |
|---|
| 370 | this->overnext = NULL; | 370 | this->overnext = NULL; |
|---|
| 371 | this->inSemantic = 0; | 371 | this->inSemantic = 0; |
|---|
| | | 372 | this->importprot = PROTundefined; |
|---|
| 372 | assert(type); | 373 | assert(type); |
|---|
| 373 | } | 374 | } |
|---|
| 374 | | 375 | |
|---|
| 375 | AliasDeclaration::AliasDeclaration(Loc loc, Identifier *id, Dsymbol *s) | 376 | AliasDeclaration::AliasDeclaration(Loc loc, Identifier *id, Dsymbol *s) |
|---|
| 376 | : Declaration(id) | 377 | : Declaration(id) |
|---|
| … | | … | |
| 499 | else | 500 | else |
|---|
| 500 | { | 501 | { |
|---|
| 501 | FuncDeclaration *f = s->toAlias()->isFuncDeclaration(); | 502 | FuncDeclaration *f = s->toAlias()->isFuncDeclaration(); |
|---|
| 502 | if (f) | 503 | if (f) |
|---|
| 503 | { | 504 | { |
|---|
| | | 505 | FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); |
|---|
| | | 506 | fa->importprot = importprot; |
|---|
| 504 | if (overnext) | 507 | if (overnext) |
|---|
| 505 | { | 508 | { |
|---|
| 506 | FuncAliasDeclaration *fa = new FuncAliasDeclaration(f); | | |
|---|
| 507 | if (!fa->overloadInsert(overnext)) | 509 | if (!fa->overloadInsert(overnext)) |
|---|
| 508 | ScopeDsymbol::multiplyDefined(0, f, overnext); | 510 | ScopeDsymbol::multiplyDefined(0, f, overnext); |
|---|
| 509 | overnext = NULL; | 511 | overnext = NULL; |
|---|
| 510 | s = fa; | 512 | } |
|---|
| 511 | s->parent = sc->parent; | 513 | s = fa; |
|---|
| 512 | } | 514 | s->parent = sc->parent; |
|---|
| 513 | } | 515 | } |
|---|
| 514 | if (overnext) | 516 | if (overnext) |
|---|
| 515 | ScopeDsymbol::multiplyDefined(0, s, overnext); | 517 | ScopeDsymbol::multiplyDefined(0, s, overnext); |
|---|
| 516 | if (s == this) | 518 | if (s == this) |
|---|
| 517 | { | 519 | { |
|---|
| Revision 1309:0c03ba6f7c24 |
Revision 1358:78038e540342 |
| 85 | FuncDeclaration *lastf; // last matching function we found | 85 | FuncDeclaration *lastf; // last matching function we found |
|---|
| 86 | FuncDeclaration *nextf; // current matching function | 86 | FuncDeclaration *nextf; // current matching function |
|---|
| 87 | FuncDeclaration *anyf; // pick a func, any func, to use for error recovery | 87 | FuncDeclaration *anyf; // pick a func, any func, to use for error recovery |
|---|
| 88 | }; | 88 | }; |
|---|
| 89 | | 89 | |
|---|
| 90 | void overloadResolveX(Match *m, FuncDeclaration *f, Expressions *arguments); | 90 | void overloadResolveX(Match *m, FuncDeclaration *f, Expressions *arguments, Module* from); |
|---|
| 91 | int overloadApply(FuncDeclaration *fstart, | 91 | int overloadApply(Module* from, FuncDeclaration *fstart, |
|---|
| 92 | int (*fp)(void *, FuncDeclaration *), | 92 | int (*fp)(void *, FuncDeclaration *), |
|---|
| 93 | void *param); | 93 | void *param); |
|---|
| 94 | | 94 | |
|---|
| 95 | /**************************************************************/ | 95 | /**************************************************************/ |
|---|
| 96 | | 96 | |
|---|
| … | | … | |
| 218 | struct AliasDeclaration : Declaration | 218 | struct AliasDeclaration : Declaration |
|---|
| 219 | { | 219 | { |
|---|
| 220 | Dsymbol *aliassym; | 220 | Dsymbol *aliassym; |
|---|
| 221 | Dsymbol *overnext; // next in overload list | 221 | Dsymbol *overnext; // next in overload list |
|---|
| 222 | int inSemantic; | 222 | int inSemantic; |
|---|
| | | 223 | PROT importprot; // if generated by import, store its protection |
|---|
| 223 | | 224 | |
|---|
| 224 | AliasDeclaration(Loc loc, Identifier *ident, Type *type); | 225 | AliasDeclaration(Loc loc, Identifier *ident, Type *type); |
|---|
| 225 | AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s); | 226 | AliasDeclaration(Loc loc, Identifier *ident, Dsymbol *s); |
|---|
| 226 | Dsymbol *syntaxCopy(Dsymbol *); | 227 | Dsymbol *syntaxCopy(Dsymbol *); |
|---|
| 227 | void semantic(Scope *sc); | 228 | void semantic(Scope *sc); |
|---|
| … | | … | |
| 668 | void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 669 | void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
|---|
| 669 | void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); | 670 | void bodyToCBuffer(OutBuffer *buf, HdrGenState *hgs); |
|---|
| 670 | int overrides(FuncDeclaration *fd); | 671 | int overrides(FuncDeclaration *fd); |
|---|
| 671 | int findVtblIndex(Array *vtbl, int dim); | 672 | int findVtblIndex(Array *vtbl, int dim); |
|---|
| 672 | int overloadInsert(Dsymbol *s); | 673 | int overloadInsert(Dsymbol *s); |
|---|
| 673 | FuncDeclaration *overloadExactMatch(Type *t); | 674 | FuncDeclaration *overloadExactMatch(Type *t, Module* from); |
|---|
| 674 | FuncDeclaration *overloadResolve(Loc loc, Expressions *arguments); | 675 | FuncDeclaration *overloadResolve(Loc loc, Expressions *arguments, Module* from); |
|---|
| 675 | LabelDsymbol *searchLabel(Identifier *ident); | 676 | LabelDsymbol *searchLabel(Identifier *ident); |
|---|
| 676 | AggregateDeclaration *isThis(); | 677 | AggregateDeclaration *isThis(); |
|---|
| 677 | AggregateDeclaration *isMember2(); | 678 | AggregateDeclaration *isMember2(); |
|---|
| 678 | int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference | 679 | int getLevel(Loc loc, FuncDeclaration *fd); // lexical nesting level difference |
|---|
| 679 | void appendExp(Expression *e); | 680 | void appendExp(Expression *e); |
|---|
| … | | … | |
| 742 | }; | 743 | }; |
|---|
| 743 | | 744 | |
|---|
| 744 | struct FuncAliasDeclaration : FuncDeclaration | 745 | struct FuncAliasDeclaration : FuncDeclaration |
|---|
| 745 | { | 746 | { |
|---|
| 746 | FuncDeclaration *funcalias; | 747 | FuncDeclaration *funcalias; |
|---|
| 747 | |
748 |
PROT importprot; // if generated by import, store its protection |
|---|
| | |
749 |
|
|---|
| 748 | FuncAliasDeclaration(FuncDeclaration *funcalias); | 750 | FuncAliasDeclaration(FuncDeclaration *funcalias); |
|---|
| 749 | | 751 | |
|---|
| 750 | FuncAliasDeclaration *isFuncAliasDeclaration() { return this; } | 752 | FuncAliasDeclaration *isFuncAliasDeclaration() { return this; } |
|---|
| 751 | const char *kind(); | 753 | const char *kind(); |
|---|
| 752 | #if IN_DMD | 754 | #if IN_DMD |
|---|
| Revision 1147:dbe4af57b240 |
Revision 1358:78038e540342 |
| 683 | //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags); | 683 | //printf("%s->ScopeDsymbol::search(ident='%s', flags=x%x)\n", toChars(), ident->toChars(), flags); |
|---|
| 684 | | 684 | |
|---|
| 685 | // Look in symbols declared in this module | 685 | // Look in symbols declared in this module |
|---|
| 686 | Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; | 686 | Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; |
|---|
| 687 | | 687 | |
|---|
| 688 | // hide private nonlocal symbols |
688 |
// hide the aliases generated by selective or renamed private imports |
|---|
| 689 | if (flags & 1 && s && s->prot() == PROTprivate) |
689 |
if (s && flags & 1) |
|---|
| 690 | s = NULL; |
690 |
if (AliasDeclaration* ad = s->isAliasDeclaration()) |
|---|
| | |
691 |
// may be a private alias to a function that is overloaded. these |
|---|
| | |
692 |
// are sorted out during overload resolution, accept them here |
|---|
| | |
693 |
if (ad->importprot == PROTprivate && !ad->aliassym->isFuncAliasDeclaration()) |
|---|
| | |
694 |
s = NULL; |
|---|
| 691 | | 695 | |
|---|
| 692 | if (s) | 696 | if (s) |
|---|
| 693 | { | 697 | { |
|---|
| 694 | //printf("\ts = '%s.%s'\n",toChars(),s->toChars()); | 698 | //printf("\ts = '%s.%s'\n",toChars(),s->toChars()); |
|---|
| 695 | } | 699 | } |
|---|
| Revision 1258:192529570813 |
Revision 1358:78038e540342 |
| 3619 | | 3619 | |
|---|
| 3620 | FuncDeclaration *f = cd->ctor; | 3620 | FuncDeclaration *f = cd->ctor; |
|---|
| 3621 | if (f) | 3621 | if (f) |
|---|
| 3622 | { | 3622 | { |
|---|
| 3623 | assert(f); | 3623 | assert(f); |
|---|
| 3624 | f = f->overloadResolve(loc, arguments); | 3624 | f = f->overloadResolve(loc, arguments, sc->module); |
|---|
| 3625 | checkDeprecated(sc, f); | 3625 | checkDeprecated(sc, f); |
|---|
| 3626 | member = f->isCtorDeclaration(); | 3626 | member = f->isCtorDeclaration(); |
|---|
| 3627 | assert(member); | 3627 | assert(member); |
|---|
| 3628 | | 3628 | |
|---|
| 3629 | cd->accessCheck(loc, sc, member); | 3629 | cd->accessCheck(loc, sc, member); |
|---|
| … | | … | |
| 3647 | Expression *e = new IntegerExp(loc, cd->size(loc), Type::tsize_t); | 3647 | Expression *e = new IntegerExp(loc, cd->size(loc), Type::tsize_t); |
|---|
| 3648 | if (!newargs) | 3648 | if (!newargs) |
|---|
| 3649 | newargs = new Expressions(); | 3649 | newargs = new Expressions(); |
|---|
| 3650 | newargs->shift(e); | 3650 | newargs->shift(e); |
|---|
| 3651 | | 3651 | |
|---|
| 3652 | f = cd->aggNew->overloadResolve(loc, newargs); | 3652 | f = cd->aggNew->overloadResolve(loc, newargs, sc->module); |
|---|
| 3653 | allocator = f->isNewDeclaration(); | 3653 | allocator = f->isNewDeclaration(); |
|---|
| 3654 | assert(allocator); | 3654 | assert(allocator); |
|---|
| 3655 | | 3655 | |
|---|
| 3656 | tf = (TypeFunction *)f->type; | 3656 | tf = (TypeFunction *)f->type; |
|---|
| 3657 | functionArguments(loc, sc, tf, newargs); | 3657 | functionArguments(loc, sc, tf, newargs); |
|---|
| … | | … | |
| 3680 | e = new IntegerExp(loc, sd->size(loc), Type::tuns32); | 3680 | e = new IntegerExp(loc, sd->size(loc), Type::tuns32); |
|---|
| 3681 | if (!newargs) | 3681 | if (!newargs) |
|---|
| 3682 | newargs = new Expressions(); | 3682 | newargs = new Expressions(); |
|---|
| 3683 | newargs->shift(e); | 3683 | newargs->shift(e); |
|---|
| 3684 | | 3684 | |
|---|
| 3685 | f = f->overloadResolve(loc, newargs); | 3685 | f = f->overloadResolve(loc, newargs, sc->module); |
|---|
| 3686 | allocator = f->isNewDeclaration(); | 3686 | allocator = f->isNewDeclaration(); |
|---|
| 3687 | assert(allocator); | 3687 | assert(allocator); |
|---|
| 3688 | | 3688 | |
|---|
| 3689 | tf = (TypeFunction *)f->type; | 3689 | tf = (TypeFunction *)f->type; |
|---|
| 3690 | functionArguments(loc, sc, tf, newargs); | 3690 | functionArguments(loc, sc, tf, newargs); |
|---|
| … | | … | |
| 3868 | : Expression(loc, TOKsymoff, sizeof(SymOffExp)) | 3868 | : Expression(loc, TOKsymoff, sizeof(SymOffExp)) |
|---|
| 3869 | { | 3869 | { |
|---|
| 3870 | assert(var); | 3870 | assert(var); |
|---|
| 3871 | this->var = var; | 3871 | this->var = var; |
|---|
| 3872 | this->offset = offset; | 3872 | this->offset = offset; |
|---|
| | | 3873 | m = NULL; |
|---|
| 3873 | VarDeclaration *v = var->isVarDeclaration(); | 3874 | VarDeclaration *v = var->isVarDeclaration(); |
|---|
| 3874 | if (v && v->needThis()) | 3875 | if (v && v->needThis()) |
|---|
| 3875 | error("need 'this' for address of %s", v->toChars()); | 3876 | error("need 'this' for address of %s", v->toChars()); |
|---|
| 3876 | } | 3877 | } |
|---|
| 3877 | | 3878 | |
|---|
| … | | … | |
| 3879 | { | 3880 | { |
|---|
| 3880 | #if LOGSEMANTIC | 3881 | #if LOGSEMANTIC |
|---|
| 3881 | printf("SymOffExp::semantic('%s')\n", toChars()); | 3882 | printf("SymOffExp::semantic('%s')\n", toChars()); |
|---|
| 3882 | #endif | 3883 | #endif |
|---|
| 3883 | //var->semantic(sc); | 3884 | //var->semantic(sc); |
|---|
| | | 3885 | m = sc->module; |
|---|
| 3884 | if (!type) | 3886 | if (!type) |
|---|
| 3885 | type = var->type->pointerTo(); | 3887 | type = var->type->pointerTo(); |
|---|
| 3886 | VarDeclaration *v = var->isVarDeclaration(); | 3888 | VarDeclaration *v = var->isVarDeclaration(); |
|---|
| 3887 | if (v) | 3889 | if (v) |
|---|
| 3888 | v->checkNestedReference(sc, loc); | 3890 | v->checkNestedReference(sc, loc); |
|---|
| … | | … | |
| 5856 | | 5858 | |
|---|
| 5857 | DelegateExp::DelegateExp(Loc loc, Expression *e, FuncDeclaration *f) | 5859 | DelegateExp::DelegateExp(Loc loc, Expression *e, FuncDeclaration *f) |
|---|
| 5858 | : UnaExp(loc, TOKdelegate, sizeof(DelegateExp), e) | 5860 | : UnaExp(loc, TOKdelegate, sizeof(DelegateExp), e) |
|---|
| 5859 | { | 5861 | { |
|---|
| 5860 | this->func = f; | 5862 | this->func = f; |
|---|
| | | 5863 | m = NULL; |
|---|
| 5861 | } | 5864 | } |
|---|
| 5862 | | 5865 | |
|---|
| 5863 | Expression *DelegateExp::semantic(Scope *sc) | 5866 | Expression *DelegateExp::semantic(Scope *sc) |
|---|
| 5864 | { | 5867 | { |
|---|
| 5865 | #if LOGSEMANTIC | 5868 | #if LOGSEMANTIC |
|---|
| 5866 | printf("DelegateExp::semantic('%s')\n", toChars()); | 5869 | printf("DelegateExp::semantic('%s')\n", toChars()); |
|---|
| 5867 | #endif | 5870 | #endif |
|---|
| 5868 | if (!type) | 5871 | if (!type) |
|---|
| 5869 | { | 5872 | { |
|---|
| | | 5873 | m = sc->module; |
|---|
| 5870 | e1 = e1->semantic(sc); | 5874 | e1 = e1->semantic(sc); |
|---|
| 5871 | // LDC we need a copy as we store the LLVM tpye in TypeFunction, and delegate/members have different types for 'this' | 5875 | // LDC we need a copy as we store the LLVM tpye in TypeFunction, and delegate/members have different types for 'this' |
|---|
| 5872 | type = new TypeDelegate(func->type->syntaxCopy()); | 5876 | type = new TypeDelegate(func->type->syntaxCopy()); |
|---|
| 5873 | type = type->semantic(loc, sc); | 5877 | type = type->semantic(loc, sc); |
|---|
| 5874 | AggregateDeclaration *ad = func->toParent()->isAggregateDeclaration(); | 5878 | AggregateDeclaration *ad = func->toParent()->isAggregateDeclaration(); |
|---|
| … | | … | |
| 6200 | { // Do overload resolution | 6204 | { // Do overload resolution |
|---|
| 6201 | dve = (DotVarExp *)(e1); | 6205 | dve = (DotVarExp *)(e1); |
|---|
| 6202 | | 6206 | |
|---|
| 6203 | f = dve->var->isFuncDeclaration(); | 6207 | f = dve->var->isFuncDeclaration(); |
|---|
| 6204 | assert(f); | 6208 | assert(f); |
|---|
| 6205 | f = f->overloadResolve(loc, arguments); | 6209 | f = f->overloadResolve(loc, arguments, sc->module); |
|---|
| 6206 | | 6210 | |
|---|
| 6207 | ad = f->toParent()->isAggregateDeclaration(); | 6211 | ad = f->toParent()->isAggregateDeclaration(); |
|---|
| 6208 | } | 6212 | } |
|---|
| 6209 | else | 6213 | else |
|---|
| 6210 | { dte = (DotTemplateExp *)(e1); | 6214 | { dte = (DotTemplateExp *)(e1); |
|---|
| … | | … | |
| 6301 | if (sc->callSuper & (CSXsuper_ctor | CSXthis_ctor)) | 6305 | if (sc->callSuper & (CSXsuper_ctor | CSXthis_ctor)) |
|---|
| 6302 | error("multiple constructor calls"); | 6306 | error("multiple constructor calls"); |
|---|
| 6303 | sc->callSuper |= CSXany_ctor | CSXsuper_ctor; | 6307 | sc->callSuper |= CSXany_ctor | CSXsuper_ctor; |
|---|
| 6304 | } | 6308 | } |
|---|
| 6305 | | 6309 | |
|---|
| 6306 | f = f->overloadResolve(loc, arguments); | 6310 | f = f->overloadResolve(loc, arguments, sc->module); |
|---|
| 6307 | checkDeprecated(sc, f); | 6311 | checkDeprecated(sc, f); |
|---|
| 6308 | #if DMDV2 | 6312 | #if DMDV2 |
|---|
| 6309 | checkPurity(sc, f); | 6313 | checkPurity(sc, f); |
|---|
| 6310 | #endif | 6314 | #endif |
|---|
| 6311 | e1 = new DotVarExp(e1->loc, e1, f); | 6315 | e1 = new DotVarExp(e1->loc, e1, f); |
|---|
| … | | … | |
| 6341 | error("multiple constructor calls"); | 6345 | error("multiple constructor calls"); |
|---|
| 6342 | sc->callSuper |= CSXany_ctor | CSXthis_ctor; | 6346 | sc->callSuper |= CSXany_ctor | CSXthis_ctor; |
|---|
| 6343 | } | 6347 | } |
|---|
| 6344 | | 6348 | |
|---|
| 6345 | f = cd->ctor; | 6349 | f = cd->ctor; |
|---|
| 6346 | f = f->overloadResolve(loc, arguments); | 6350 | f = f->overloadResolve(loc, arguments, sc->module); |
|---|
| 6347 | checkDeprecated(sc, f); | 6351 | checkDeprecated(sc, f); |
|---|
| 6348 | #if DMDV2 | 6352 | #if DMDV2 |
|---|
| 6349 | checkPurity(sc, f); | 6353 | checkPurity(sc, f); |
|---|
| 6350 | #endif | 6354 | #endif |
|---|
| 6351 | e1 = new DotVarExp(e1->loc, e1, f); | 6355 | e1 = new DotVarExp(e1->loc, e1, f); |
|---|
| … | | … | |
| 6435 | istemp = 1; | 6439 | istemp = 1; |
|---|
| 6436 | goto Lagain; | 6440 | goto Lagain; |
|---|
| 6437 | } | 6441 | } |
|---|
| 6438 | } | 6442 | } |
|---|
| 6439 | | 6443 | |
|---|
| 6440 | f = f->overloadResolve(loc, arguments); | 6444 | f = f->overloadResolve(loc, arguments, sc->module); |
|---|
| 6441 | checkDeprecated(sc, f); | 6445 | checkDeprecated(sc, f); |
|---|
| 6442 | #if DMDV2 | 6446 | #if DMDV2 |
|---|
| 6443 | checkPurity(sc, f); | 6447 | checkPurity(sc, f); |
|---|
| 6444 | #endif | 6448 | #endif |
|---|
| 6445 | | 6449 | |
|---|
| … | | … | |
| 6579 | /************************************************************/ | 6583 | /************************************************************/ |
|---|
| 6580 | | 6584 | |
|---|
| 6581 | AddrExp::AddrExp(Loc loc, Expression *e) | 6585 | AddrExp::AddrExp(Loc loc, Expression *e) |
|---|
| 6582 | : UnaExp(loc, TOKaddress, sizeof(AddrExp), e) | 6586 | : UnaExp(loc, TOKaddress, sizeof(AddrExp), e) |
|---|
| 6583 | { | 6587 | { |
|---|
| | | 6588 | m = NULL; |
|---|
| 6584 | } | 6589 | } |
|---|
| 6585 | | 6590 | |
|---|
| 6586 | Expression *AddrExp::semantic(Scope *sc) | 6591 | Expression *AddrExp::semantic(Scope *sc) |
|---|
| 6587 | { | 6592 | { |
|---|
| 6588 | #if LOGSEMANTIC | 6593 | #if LOGSEMANTIC |
|---|
| 6589 | printf("AddrExp::semantic('%s')\n", toChars()); | 6594 | printf("AddrExp::semantic('%s')\n", toChars()); |
|---|
| 6590 | #endif | 6595 | #endif |
|---|
| 6591 | if (!type) | 6596 | if (!type) |
|---|
| 6592 | { | 6597 | { |
|---|
| | | 6598 | m = sc->module; |
|---|
| 6593 | UnaExp::semantic(sc); | 6599 | UnaExp::semantic(sc); |
|---|
| 6594 | e1 = e1->toLvalue(sc, NULL); | 6600 | e1 = e1->toLvalue(sc, NULL); |
|---|
| 6595 | if (!e1->type) | 6601 | if (!e1->type) |
|---|
| 6596 | { | 6602 | { |
|---|
| 6597 | error("cannot take address of %s", e1->toChars()); | 6603 | error("cannot take address of %s", e1->toChars()); |
|---|
| Revision 1195:e961851fb8be |
Revision 1358:78038e540342 |
| 71 | void initPrecedence(); | 71 | void initPrecedence(); |
|---|
| 72 | | 72 | |
|---|
| 73 | Expression *resolveProperties(Scope *sc, Expression *e); | 73 | Expression *resolveProperties(Scope *sc, Expression *e); |
|---|
| 74 | void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d); | 74 | void accessCheck(Loc loc, Scope *sc, Expression *e, Declaration *d); |
|---|
| 75 | Dsymbol *search_function(AggregateDeclaration *ad, Identifier *funcid); | 75 | Dsymbol *search_function(AggregateDeclaration *ad, Identifier *funcid); |
|---|
| 76 | void inferApplyArgTypes(enum TOK op, Arguments *arguments, Expression *aggr); | 76 | void inferApplyArgTypes(enum TOK op, Arguments *arguments, Expression *aggr, Module* from); |
|---|
| 77 | void argExpTypesToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs); | 77 | void argExpTypesToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs); |
|---|
| 78 | void argsToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs); | 78 | void argsToCBuffer(OutBuffer *buf, Expressions *arguments, HdrGenState *hgs); |
|---|
| 79 | void expandTuples(Expressions *exps); | 79 | void expandTuples(Expressions *exps); |
|---|
| 80 | FuncDeclaration *hasThis(Scope *sc); | 80 | FuncDeclaration *hasThis(Scope *sc); |
|---|
| 81 | Expression *fromConstInitializer(int result, Expression *e); | 81 | Expression *fromConstInitializer(int result, Expression *e); |
|---|
| … | | … | |
| 632 | | 632 | |
|---|
| 633 | struct SymOffExp : Expression | 633 | struct SymOffExp : Expression |
|---|
| 634 | { | 634 | { |
|---|
| 635 | Declaration *var; | 635 | Declaration *var; |
|---|
| 636 | unsigned offset; | 636 | unsigned offset; |
|---|
| | | 637 | Module* m; // starting point for overload resolution |
|---|
| 637 | | 638 | |
|---|
| 638 | SymOffExp(Loc loc, Declaration *var, unsigned offset); | 639 | SymOffExp(Loc loc, Declaration *var, unsigned offset); |
|---|
| 639 | Expression *semantic(Scope *sc); | 640 | Expression *semantic(Scope *sc); |
|---|
| 640 | void checkEscape(); | 641 | void checkEscape(); |
|---|
| 641 | void toCBuffer(OutBuffer *buf, HdrGenState *hgs); | 642 | void toCBuffer(OutBuffer *buf, HdrGenState *hgs); |
|---|
| … | | … | |
| 967 | }; | 968 | }; |
|---|
| 968 | | 969 | |
|---|
| 969 | struct DelegateExp : UnaExp | 970 | struct DelegateExp : UnaExp |
|---|
| 970 | { | 971 | { |
|---|
| 971 | FuncDeclaration *func; | 972 | FuncDeclaration *func; |
|---|
| | | 973 | Module* m; // starting point for overload resolution |
|---|
| 972 | | 974 | |
|---|
| 973 | DelegateExp(Loc loc, Expression *e, FuncDeclaration *func); | 975 | DelegateExp(Loc loc, Expression *e, FuncDeclaration *func); |
|---|
| 974 | Expression *semantic(Scope *sc); | 976 | Expression *semantic(Scope *sc); |
|---|
| 975 | MATCH implicitConvTo(Type *t); | 977 | MATCH implicitConvTo(Type *t); |
|---|
| 976 | Expression *castTo(Scope *sc, Type *t); | 978 | Expression *castTo(Scope *sc, Type *t); |
|---|
| … | | … | |
| 1034 | #endif | 1036 | #endif |
|---|
| 1035 | }; | 1037 | }; |
|---|
| 1036 | | 1038 | |
|---|
| 1037 | struct AddrExp : UnaExp | 1039 | struct AddrExp : UnaExp |
|---|
| 1038 | { | 1040 | { |
|---|
| | | 1041 | Module* m; // starting point for overload resolution |
|---|
| | | 1042 | |
|---|
| 1039 | AddrExp(Loc loc, Expression *e); | 1043 | AddrExp(Loc loc, Expression *e); |
|---|
| 1040 | Expression *semantic(Scope *sc); | 1044 | Expression *semantic(Scope *sc); |
|---|
| 1041 | #if IN_DMD | 1045 | #if IN_DMD |
|---|
| 1042 | elem *toElem(IRState *irs); | 1046 | elem *toElem(IRState *irs); |
|---|
| 1043 | #endif | 1047 | #endif |
|---|
| Revision 1326:a41a40deff73 |
Revision 1358:78038e540342 |
| 324 | if (cd->baseClass) | 324 | if (cd->baseClass) |
|---|
| 325 | { Dsymbol *s = cd->baseClass->search(loc, ident, 0); | 325 | { Dsymbol *s = cd->baseClass->search(loc, ident, 0); |
|---|
| 326 | if (s) | 326 | if (s) |
|---|
| 327 | { | 327 | { |
|---|
| 328 | FuncDeclaration *f = s->isFuncDeclaration(); | 328 | FuncDeclaration *f = s->isFuncDeclaration(); |
|---|
| 329 | f = f->overloadExactMatch(type); | 329 | f = f->overloadExactMatch(type, getModule()); |
|---|
| 330 | if (f && f->isFinal() && f->prot() != PROTprivate) | 330 | if (f && f->isFinal() && f->prot() != PROTprivate) |
|---|
| 331 | error("cannot override final function %s", f->toPrettyChars()); | 331 | error("cannot override final function %s", f->toPrettyChars()); |
|---|
| 332 | } | 332 | } |
|---|
| 333 | } | 333 | } |
|---|
| 334 | | 334 | |
|---|
| … | | … | |
| 1528 | * Returns: | 1528 | * Returns: |
|---|
| 1529 | * 0 continue | 1529 | * 0 continue |
|---|
| 1530 | * 1 done | 1530 | * 1 done |
|---|
| 1531 | */ | 1531 | */ |
|---|
| 1532 | | 1532 | |
|---|
| 1533 | int overloadApply(FuncDeclaration *fstart, | 1533 | int overloadApply(Module* from, FuncDeclaration *fstart, |
|---|
| 1534 | int (*fp)(void *, FuncDeclaration *), | 1534 | int (*fp)(void *, FuncDeclaration *), |
|---|
| 1535 | void *param) | 1535 | void *param) |
|---|
| 1536 | { | 1536 | { |
|---|
| 1537 | FuncDeclaration *f; | 1537 | FuncDeclaration *f; |
|---|
| 1538 | Declaration *d; | 1538 | Declaration *d; |
|---|
| … | | … | |
| 1541 | for (d = fstart; d; d = next) | 1541 | for (d = fstart; d; d = next) |
|---|
| 1542 | { FuncAliasDeclaration *fa = d->isFuncAliasDeclaration(); | 1542 | { FuncAliasDeclaration *fa = d->isFuncAliasDeclaration(); |
|---|
| 1543 | | 1543 | |
|---|
| 1544 | if (fa) | 1544 | if (fa) |
|---|
| 1545 | { | 1545 | { |
|---|
| 1546 | if (overloadApply(fa->funcalias, fp, param)) |
1546 |
if (fa->getModule() == from || fa->importprot != PROTprivate) |
|---|
| 1547 | return 1; |
1547 |
if (overloadApply(from, fa->funcalias, fp, param)) |
|---|
| | |
1548 |
return 1; |
|---|
| 1548 | next = fa->overnext; | 1549 | next = fa->overnext; |
|---|
| 1549 | } | 1550 | } |
|---|
| 1550 | else | 1551 | else |
|---|
| 1551 | { | 1552 | { |
|---|
| 1552 | AliasDeclaration *a = d->isAliasDeclaration(); | 1553 | AliasDeclaration *a = d->isAliasDeclaration(); |
|---|
| … | | … | |
| 1611 | } | 1612 | } |
|---|
| 1612 | #endif | 1613 | #endif |
|---|
| 1613 | return 0; | 1614 | return 0; |
|---|
| 1614 | } | 1615 | } |
|---|
| 1615 | | 1616 | |
|---|
| 1616 | FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) | 1617 | FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t, Module* from) |
|---|
| 1617 | { | 1618 | { |
|---|
| 1618 | Param1 p; | 1619 | Param1 p; |
|---|
| 1619 | p.t = t; | 1620 | p.t = t; |
|---|
| 1620 | p.f = NULL; | 1621 | p.f = NULL; |
|---|
| 1621 | overloadApply(this, &fp1, &p); | 1622 | overloadApply(from, this, &fp1, &p); |
|---|
| 1622 | return p.f; | 1623 | return p.f; |
|---|
| 1623 | } | 1624 | } |
|---|
| 1624 | | 1625 | |
|---|
| 1625 | #if 0 | 1626 | #if 0 |
|---|
| 1626 | FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) | 1627 | FuncDeclaration *FuncDeclaration::overloadExactMatch(Type *t) |
|---|
| … | | … | |
| 1719 | } | 1720 | } |
|---|
| 1720 | return 0; | 1721 | return 0; |
|---|
| 1721 | } | 1722 | } |
|---|
| 1722 | | 1723 | |
|---|
| 1723 | | 1724 | |
|---|
| 1724 | void overloadResolveX(Match *m, FuncDeclaration *fstart, Expressions *arguments) | 1725 | void overloadResolveX(Match *m, FuncDeclaration *fstart, Expressions *arguments, Module* from) |
|---|
| 1725 | { | 1726 | { |
|---|
| 1726 | Param2 p; | 1727 | Param2 p; |
|---|
| 1727 | p.m = m; | 1728 | p.m = m; |
|---|
| 1728 | p.arguments = arguments; | 1729 | p.arguments = arguments; |
|---|
| 1729 | overloadApply(fstart, &fp2, &p); | 1730 | overloadApply(from, fstart, &fp2, &p); |
|---|
| 1730 | } | 1731 | } |
|---|
| 1731 | | 1732 | |
|---|
| 1732 | #if 0 | 1733 | #if 0 |
|---|
| 1733 | // Recursive helper function | 1734 | // Recursive helper function |
|---|
| 1734 | | 1735 | |
|---|
| … | | … | |
| 1809 | } | 1810 | } |
|---|
| 1810 | } | 1811 | } |
|---|
| 1811 | } | 1812 | } |
|---|
| 1812 | #endif | 1813 | #endif |
|---|
| 1813 | | 1814 | |
|---|
| 1814 | FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments) | 1815 | FuncDeclaration *FuncDeclaration::overloadResolve(Loc loc, Expressions *arguments, Module* from) |
|---|
| 1815 | { | 1816 | { |
|---|
| 1816 | TypeFunction *tf; | 1817 | TypeFunction *tf; |
|---|
| 1817 | Match m; | 1818 | Match m; |
|---|
| 1818 | | 1819 | |
|---|
| 1819 | #if 0 | 1820 | #if 0 |
|---|
| … | | … | |
| 1832 | } | 1833 | } |
|---|
| 1833 | #endif | 1834 | #endif |
|---|
| 1834 | | 1835 | |
|---|
| 1835 | memset(&m, 0, sizeof(m)); | 1836 | memset(&m, 0, sizeof(m)); |
|---|
| 1836 | m.last = MATCHnomatch; | 1837 | m.last = MATCHnomatch; |
|---|
| 1837 | overloadResolveX(&m, this, arguments); | 1838 | overloadResolveX(&m, this, arguments, from); |
|---|
| 1838 | | 1839 | |
|---|
| 1839 | if (m.count == 1) // exactly one match | 1840 | if (m.count == 1) // exactly one match |
|---|
| 1840 | { | 1841 | { |
|---|
| 1841 | return m.lastf; | 1842 | return m.lastf; |
|---|
| 1842 | } | 1843 | } |
|---|
| … | | … | |
| 2251 | : FuncDeclaration(funcalias->loc, funcalias->endloc, funcalias->ident, | 2252 | : FuncDeclaration(funcalias->loc, funcalias->endloc, funcalias->ident, |
|---|
| 2252 | (enum STC)funcalias->storage_class, funcalias->type) | 2253 | (enum STC)funcalias->storage_class, funcalias->type) |
|---|
| 2253 | { | 2254 | { |
|---|
| 2254 | assert(funcalias != this); | 2255 | assert(funcalias != this); |
|---|
| 2255 | this->funcalias = funcalias; | 2256 | this->funcalias = funcalias; |
|---|
| | | 2257 | importprot = PROTundefined; |
|---|
| 2256 | } | 2258 | } |
|---|
| 2257 | | 2259 | |
|---|
| 2258 | const char *FuncAliasDeclaration::kind() | 2260 | const char *FuncAliasDeclaration::kind() |
|---|
| 2259 | { | 2261 | { |
|---|
| 2260 | return "function alias"; | 2262 | return "function alias"; |
|---|
| Revision 875:330f999ade44 |
Revision 1358:78038e540342 |
| 161 | | 161 | |
|---|
| 162 | //printf("\tImport alias semantic('%s')\n", s->toChars()); | 162 | //printf("\tImport alias semantic('%s')\n", s->toChars()); |
|---|
| 163 | if (!mod->search(loc, (Identifier *)names.data[i], 0)) | 163 | if (!mod->search(loc, (Identifier *)names.data[i], 0)) |
|---|
| 164 | error("%s not found", ((Identifier *)names.data[i])->toChars()); | 164 | error("%s not found", ((Identifier *)names.data[i])->toChars()); |
|---|
| 165 | | 165 | |
|---|
| | | 166 | ad->importprot = protection; |
|---|
| 166 | ad->semantic(sc); | 167 | ad->semantic(sc); |
|---|
| 167 | ad->protection = protection; | | |
|---|
| 168 | } | 168 | } |
|---|
| 169 | sc = sc->pop(); | 169 | sc = sc->pop(); |
|---|
| 170 | } | 170 | } |
|---|
| 171 | //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); | 171 | //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); |
|---|
| 172 | } | 172 | } |
|---|
| Revision 1195:e961851fb8be |
Revision 1358:78038e540342 |
| 26 | #include "expression.h" | 26 | #include "expression.h" |
|---|
| 27 | #include "id.h" | 27 | #include "id.h" |
|---|
| 28 | #include "declaration.h" | 28 | #include "declaration.h" |
|---|
| 29 | #include "aggregate.h" | 29 | #include "aggregate.h" |
|---|
| 30 | #include "template.h" | 30 | #include "template.h" |
|---|
| | | 31 | #include "scope.h" |
|---|
| 31 | | 32 | |
|---|
| 32 | static Expression *build_overload(Loc loc, Scope *sc, Expression *ethis, Expression *earg, Identifier *id); | 33 | static Expression *build_overload(Loc loc, Scope *sc, Expression *ethis, Expression *earg, Identifier *id); |
|---|
| 33 | static void inferApplyArgTypesX(FuncDeclaration *fstart, Arguments *arguments); | 34 | static void inferApplyArgTypesX(Module* from, FuncDeclaration *fstart, Arguments *arguments); |
|---|
| 34 | static int inferApplyArgTypesY(TypeFunction *tf, Arguments *arguments); | 35 | static int inferApplyArgTypesY(TypeFunction *tf, Arguments *arguments); |
|---|
| 35 | static void templateResolve(Match *m, TemplateDeclaration *td, Scope *sc, Loc loc, Objects *targsi, Expressions *arguments); | 36 | static void templateResolve(Match *m, TemplateDeclaration *td, Scope *sc, Loc loc, Objects *targsi, Expressions *arguments); |
|---|
| 36 | | 37 | |
|---|
| 37 | /******************************** Expression **************************/ | 38 | /******************************** Expression **************************/ |
|---|
| 38 | | 39 | |
|---|
| … | | … | |
| 261 | if (s) | 262 | if (s) |
|---|
| 262 | { | 263 | { |
|---|
| 263 | fd = s->isFuncDeclaration(); | 264 | fd = s->isFuncDeclaration(); |
|---|
| 264 | if (fd) | 265 | if (fd) |
|---|
| 265 | { | 266 | { |
|---|
| 266 | overloadResolveX(&m, fd, &args2); | 267 | overloadResolveX(&m, fd, &args2, sc->module); |
|---|
| 267 | } | 268 | } |
|---|
| 268 | else | 269 | else |
|---|
| 269 | { td = s->isTemplateDeclaration(); | 270 | { td = s->isTemplateDeclaration(); |
|---|
| 270 | templateResolve(&m, td, sc, loc, NULL, &args2); | 271 | templateResolve(&m, td, sc, loc, NULL, &args2); |
|---|
| 271 | } | 272 | } |
|---|
| … | | … | |
| 276 | if (s_r) | 277 | if (s_r) |
|---|
| 277 | { | 278 | { |
|---|
| 278 | fd = s_r->isFuncDeclaration(); | 279 | fd = s_r->isFuncDeclaration(); |
|---|
| 279 | if (fd) | 280 | if (fd) |
|---|
| 280 | { | 281 | { |
|---|
| 281 | overloadResolveX(&m, fd, &args1); | 282 | overloadResolveX(&m, fd, &args1, sc->module); |
|---|
| 282 | } | 283 | } |
|---|
| 283 | else | 284 | else |
|---|
| 284 | { td = s_r->isTemplateDeclaration(); | 285 | { td = s_r->isTemplateDeclaration(); |
|---|
| 285 | templateResolve(&m, td, sc, loc, NULL, &args1); | 286 | templateResolve(&m, td, sc, loc, NULL, &args1); |
|---|
| 286 | } | 287 | } |
|---|
| … | | … | |
| 350 | if (s_r) | 351 | if (s_r) |
|---|
| 351 | { | 352 | { |
|---|
| 352 | fd = s_r->isFuncDeclaration(); | 353 | fd = s_r->isFuncDeclaration(); |
|---|
| 353 | if (fd) | 354 | if (fd) |
|---|
| 354 | { | 355 | { |
|---|
| 355 | overloadResolveX(&m, fd, &args2); | 356 | overloadResolveX(&m, fd, &args2, sc->module); |
|---|
| 356 | } | 357 | } |
|---|
| 357 | else | 358 | else |
|---|
| 358 | { td = s_r->isTemplateDeclaration(); | 359 | { td = s_r->isTemplateDeclaration(); |
|---|
| 359 | templateResolve(&m, td, sc, loc, NULL, &args2); | 360 | templateResolve(&m, td, sc, loc, NULL, &args2); |
|---|
| 360 | } | 361 | } |
|---|
| … | | … | |
| 364 | if (s) | 365 | if (s) |
|---|
| 365 | { | 366 | { |
|---|
| 366 | fd = s->isFuncDeclaration(); | 367 | fd = s->isFuncDeclaration(); |
|---|
| 367 | if (fd) | 368 | if (fd) |
|---|
| 368 | { | 369 | { |
|---|
| 369 | overloadResolveX(&m, fd, &args1); | 370 | overloadResolveX(&m, fd, &args1, sc->module); |
|---|
| 370 | } | 371 | } |
|---|
| 371 | else | 372 | else |
|---|
| 372 | { td = s->isTemplateDeclaration(); | 373 | { td = s->isTemplateDeclaration(); |
|---|
| 373 | templateResolve(&m, td, sc, loc, NULL, &args1); | 374 | templateResolve(&m, td, sc, loc, NULL, &args1); |
|---|
| 374 | } | 375 | } |
|---|
| … | | … | |
| 480 | * Given array of arguments and an aggregate type, | 481 | * Given array of arguments and an aggregate type, |
|---|
| 481 | * if any of the argument types are missing, attempt to infer | 482 | * if any of the argument types are missing, attempt to infer |
|---|
| 482 | * them from the aggregate type. | 483 | * them from the aggregate type. |
|---|
| 483 | */ | 484 | */ |
|---|
| 484 | | 485 | |
|---|
| 485 | void inferApplyArgTypes(enum TOK op, Arguments *arguments, Expression *aggr) | 486 | void inferApplyArgTypes(enum TOK op, Arguments *arguments, Expression *aggr, Module* from) |
|---|
| 486 | { | 487 | { |
|---|
| 487 | if (!arguments || !arguments->dim) | 488 | if (!arguments || !arguments->dim) |
|---|
| 488 | return; | 489 | return; |
|---|
| 489 | | 490 | |
|---|
| 490 | /* Return if no arguments need types. | 491 | /* Return if no arguments need types. |
|---|
| … | | … | |
| 569 | : Id::apply); | 570 | : Id::apply); |
|---|
| 570 | if (s) | 571 | if (s) |
|---|
| 571 | { | 572 | { |
|---|
| 572 | fd = s->isFuncDeclaration(); | 573 | fd = s->isFuncDeclaration(); |
|---|
| 573 | if (fd) | 574 | if (fd) |
|---|
| 574 | inferApplyArgTypesX(fd, arguments); | 575 | inferApplyArgTypesX(from, fd, arguments); |
|---|
| 575 | } | 576 | } |
|---|
| 576 | break; | 577 | break; |
|---|
| 577 | } | 578 | } |
|---|
| 578 | | 579 | |
|---|
| 579 | case Tdelegate: | 580 | case Tdelegate: |
|---|
| … | | … | |
| 581 | if (0 && aggr->op == TOKdelegate) | 582 | if (0 && aggr->op == TOKdelegate) |
|---|
| 582 | { DelegateExp *de = (DelegateExp *)aggr; | 583 | { DelegateExp *de = (DelegateExp *)aggr; |
|---|
| 583 | | 584 | |
|---|
| 584 | fd = de->func->isFuncDeclaration(); | 585 | fd = de->func->isFuncDeclaration(); |
|---|
| 585 | if (fd) | 586 | if (fd) |
|---|
| 586 | inferApplyArgTypesX(fd, arguments); | 587 | inferApplyArgTypesX(from, fd, arguments); |
|---|
| 587 | } | 588 | } |
|---|
| 588 | else | 589 | else |
|---|
| 589 | { | 590 | { |
|---|
| 590 | inferApplyArgTypesY((TypeFunction *)tab->nextOf(), arguments); | 591 | inferApplyArgTypesY((TypeFunction *)tab->nextOf(), arguments); |
|---|
| 591 | } | 592 | } |
|---|
| … | | … | |
| 611 | if (arguments->dim == 0) | 612 | if (arguments->dim == 0) |
|---|
| 612 | return 1; | 613 | return 1; |
|---|
| 613 | return 0; | 614 | return 0; |
|---|
| 614 | } | 615 | } |
|---|
| 615 | | 616 | |
|---|
| 616 | static void inferApplyArgTypesX(FuncDeclaration *fstart, Arguments *arguments) | 617 | static void inferApplyArgTypesX(Module* from, FuncDeclaration *fstart, Arguments *arguments) |
|---|
| 617 | { | 618 | { |
|---|
| 618 | overloadApply(fstart, &fp3, arguments); | 619 | overloadApply(from, fstart, &fp3, arguments); |
|---|
| 619 | } | 620 | } |
|---|
| 620 | | 621 | |
|---|
| 621 | #if 0 | 622 | #if 0 |
|---|
| 622 | static void inferApplyArgTypesX(FuncDeclaration *fstart, Arguments *arguments) | 623 | static void inferApplyArgTypesX(FuncDeclaration *fstart, Arguments *arguments) |
|---|
| 623 | { | 624 | { |
|---|
| Revision 1195:e961851fb8be |
Revision 1358:78038e540342 |
| 1275 | { | 1275 | { |
|---|
| 1276 | error("invalid foreach aggregate %s", aggr->toChars()); | 1276 | error("invalid foreach aggregate %s", aggr->toChars()); |
|---|
| 1277 | return this; | 1277 | return this; |
|---|
| 1278 | } | 1278 | } |
|---|
| 1279 | | 1279 | |
|---|
| 1280 | inferApplyArgTypes(op, arguments, aggr); | 1280 | inferApplyArgTypes(op, arguments, aggr, sc->module); |
|---|
| 1281 | | 1281 | |
|---|
| 1282 | /* Check for inference errors | 1282 | /* Check for inference errors |
|---|
| 1283 | */ | 1283 | */ |
|---|
| 1284 | if (dim != arguments->dim) | 1284 | if (dim != arguments->dim) |
|---|
| 1285 | { | 1285 | { |
|---|
| Revision 1195:e961851fb8be |
Revision 1358:78038e540342 |
| 344 | for (int i = 0; i < 2; i++) | 344 | for (int i = 0; i < 2; i++) |
|---|
| 345 | { | 345 | { |
|---|
| 346 | Dsymbol *s = search_function(this, id); | 346 | Dsymbol *s = search_function(this, id); |
|---|
| 347 | FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; | 347 | FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL; |
|---|
| 348 | if (fdx) | 348 | if (fdx) |
|---|
| 349 | { FuncDeclaration *fd = fdx->overloadExactMatch(tfeqptr); | 349 | { FuncDeclaration *fd = fdx->overloadExactMatch(tfeqptr, getModule()); |
|---|
| 350 | if (!fd) | 350 | if (!fd) |
|---|
| 351 | { fd = fdx->overloadExactMatch(tfeq); | 351 | { fd = fdx->overloadExactMatch(tfeq, getModule()); |
|---|
| 352 | if (fd) | 352 | if (fd) |
|---|
| 353 | { // Create the thunk, fdptr | 353 | { // Create the thunk, fdptr |
|---|
| 354 | FuncDeclaration *fdptr = new FuncDeclaration(loc, loc, fdx->ident, STCundefined, tfeqptr); | 354 | FuncDeclaration *fdptr = new FuncDeclaration(loc, loc, fdx->ident, STCundefined, tfeqptr); |
|---|
| 355 | Expression *e = new IdentifierExp(loc, Id::p); | 355 | Expression *e = new IdentifierExp(loc, Id::p); |
|---|
| 356 | e = new PtrExp(loc, e); | 356 | e = new PtrExp(loc, e); |
|---|
| Revision 1345:712662f45ee4 |
Revision 1358:78038e540342 |
| 747 | | 747 | |
|---|
| 748 | s = search_function(sd, Id::tohash); | 748 | s = search_function(sd, Id::tohash); |
|---|
| 749 | fdx = s ? s->isFuncDeclaration() : NULL; | 749 | fdx = s ? s->isFuncDeclaration() : NULL; |
|---|
| 750 | if (fdx) | 750 | if (fdx) |
|---|
| 751 | { | 751 | { |
|---|
| 752 | fd = fdx->overloadExactMatch(tftohash); | 752 | fd = fdx->overloadExactMatch(tftohash, getModule()); |
|---|
| 753 | if (fd) { | 753 | if (fd) { |
|---|
| 754 | fd->codegen(Type::sir); | 754 | fd->codegen(Type::sir); |
|---|
| 755 | assert(fd->ir.irFunc->func != 0); | 755 | assert(fd->ir.irFunc->func != 0); |
|---|
| 756 | LLConstant* c = isaConstant(fd->ir.irFunc->func); | 756 | LLConstant* c = isaConstant(fd->ir.irFunc->func); |
|---|
| 757 | assert(c); | 757 | assert(c); |
|---|
| … | | … | |
| 773 | { | 773 | { |
|---|
| 774 | //Logger::println("************** C %d", i); | 774 | //Logger::println("************** C %d", i); |
|---|
| 775 | ptty = isaPointer(stype->getElementType(5+i)); | 775 | ptty = isaPointer(stype->getElementType(5+i)); |
|---|
| 776 | if (fdx) | 776 | if (fdx) |
|---|
| 777 | { | 777 | { |
|---|
| 778 | fd = fdx->overloadExactMatch(tfeqptr); | 778 | fd = fdx->overloadExactMatch(tfeqptr, getModule()); |
|---|
| 779 | if (fd) { | 779 | if (fd) { |
|---|
| 780 | fd->codegen(Type::sir); | 780 | fd->codegen(Type::sir); |
|---|
| 781 | assert(fd->ir.irFunc->func != 0); | 781 | assert(fd->ir.irFunc->func != 0); |
|---|
| 782 | LLConstant* c = isaConstant(fd->ir.irFunc->func); | 782 | LLConstant* c = isaConstant(fd->ir.irFunc->func); |
|---|
| 783 | assert(c); | 783 | assert(c); |
|---|
| … | | … | |
| 801 | ptty = isaPointer(stype->getElementType(7)); | 801 | ptty = isaPointer(stype->getElementType(7)); |
|---|
| 802 | s = search_function(sd, Id::tostring); | 802 | s = search_function(sd, Id::tostring); |
|---|
| 803 | fdx = s ? s->isFuncDeclaration() : NULL; | 803 | fdx = s ? s->isFuncDeclaration() : NULL; |
|---|
| 804 | if (fdx) | 804 | if (fdx) |
|---|
| 805 | { | 805 | { |
|---|
| 806 | fd = fdx->overloadExactMatch(tftostring); | 806 | fd = fdx->overloadExactMatch(tftostring, getModule()); |
|---|
| 807 | if (fd) { | 807 | if (fd) { |
|---|
| 808 | fd->codegen(Type::sir); | 808 | fd->codegen(Type::sir); |
|---|
| 809 | assert(fd->ir.irFunc->func != 0); | 809 | assert(fd->ir.irFunc->func != 0); |
|---|
| 810 | LLConstant* c = isaConstant(fd->ir.irFunc->func); | 810 | LLConstant* c = isaConstant(fd->ir.irFunc->func); |
|---|
| 811 | assert(c); | 811 | assert(c); |
|---|