Mercurial > projects > ldc
comparison dmd/func.c @ 1358:78038e540342
Fix overload resolution issue in dmd bug 313/314 fix.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 16 May 2009 12:17:33 +0200 |
parents | a41a40deff73 |
children | 194852badf8c |
comparison
equal
deleted
inserted
replaced
1357:48747003a5de | 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"; |