Skip to content

Commit

Permalink
Revert "Merge pull request dlang#2256 from 9rnsr/fix_imports"
Browse files Browse the repository at this point in the history
This reverts most of commit 6cf3992
  • Loading branch information
9rnsr committed Mar 21, 2014
1 parent d0f461a commit 4350a08
Show file tree
Hide file tree
Showing 64 changed files with 228 additions and 1,230 deletions.
29 changes: 1 addition & 28 deletions src/class.c
Expand Up @@ -26,13 +26,10 @@
#include "mtype.h"
#include "scope.h"
#include "module.h"
#include "import.h"
#include "expression.h"
#include "statement.h"
#include "template.h"

bool isFriendOf(AggregateDeclaration *ad, AggregateDeclaration *cd);

/********************************* ClassDeclaration ****************************/

ClassDeclaration *ClassDeclaration::object;
Expand Down Expand Up @@ -617,28 +614,6 @@ void ClassDeclaration::semantic(Scope *sc)
size_t members_dim = members->dim;
sizeok = SIZEOKnone;

// Merge base class imports in this class
for (size_t i = 0; i < baseclasses->dim; i++)
{
ClassDeclaration *cd = (*baseclasses)[i]->base;
if (cd && cd->imports)
{
for (size_t j = 0; j < cd->imports->dim; j++)
{
Import *imp = (*cd->imports)[j]->isImport();
PROT prot = cd->prots[j];
if (imp && (prot == PROTpublic || prot == PROTprotected))
{
imp = imp->copy();
imp->protection = prot;
imp->isstatic = true; // Don't insert to sc->scopesym->imports
imp->overnext = NULL;
imp->importScope(sc);
}
}
}
}

/* Set scope so if there are forward references, we still might be able to
* resolve individual members like enums.
*/
Expand Down Expand Up @@ -980,9 +955,7 @@ Dsymbol *ClassDeclaration::search(Loc loc, Identifier *ident, int flags)
error("base %s is forward referenced", b->base->ident->toChars());
else
{
int flags2 = flags | IgnoreImportedFQN;
if (!isFriendOf(this, b->base)) flags2 |= IgnorePrivateImports;
s = b->base->search(loc, ident, flags2);
s = b->base->search(loc, ident, flags);
if (s == this) // happens if s is nested in this and derives from this
s = NULL;
else if (s)
Expand Down
81 changes: 9 additions & 72 deletions src/dsymbol.c
Expand Up @@ -442,15 +442,15 @@ Dsymbol *Dsymbol::searchX(Loc loc, Scope *sc, RootObject *id)
switch (id->dyncast())
{
case DYNCAST_IDENTIFIER:
sm = s->search(loc, (Identifier *)id, IgnoreImportedFQN);
sm = s->search(loc, (Identifier *)id);
break;

case DYNCAST_DSYMBOL:
{ // It's a template instance
//printf("\ttemplate instance id\n");
Dsymbol *st = (Dsymbol *)id;
TemplateInstance *ti = st->isTemplateInstance();
sm = s->search(loc, ti->name, IgnoreImportedFQN);
sm = s->search(loc, ti->name);
if (!sm)
{
sm = s->search_correct(ti->name);
Expand Down Expand Up @@ -834,7 +834,6 @@ bool Dsymbol::inNonRoot()
OverloadSet::OverloadSet(Identifier *ident)
: Dsymbol(ident)
{
bug12359 = false;
}

void OverloadSet::push(Dsymbol *s)
Expand All @@ -857,7 +856,6 @@ ScopeDsymbol::ScopeDsymbol()
symtab = NULL;
imports = NULL;
prots = NULL;
pkgtab = NULL;
}

ScopeDsymbol::ScopeDsymbol(Identifier *id)
Expand All @@ -867,7 +865,6 @@ ScopeDsymbol::ScopeDsymbol(Identifier *id)
symtab = NULL;
imports = NULL;
prots = NULL;
pkgtab = NULL;
}

Dsymbol *ScopeDsymbol::syntaxCopy(Dsymbol *s)
Expand Down Expand Up @@ -898,62 +895,7 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
//printf("\ts1 = %p, imports = %p, %d\n", s1, imports, imports ? imports->dim : 0);
if (s1)
{
//printf("\ts = '%s.%s', prot = %d\n", toChars(), s1->toChars(), s1->prot());
// The found symbol which has private access should be invisible
// FIXME: Issue 10604 - Not consistent access check for overloaded symbols
if ((flags & IgnorePrivateMembers) && s1->prot() == PROTprivate)
s1 = NULL;
#if 1
if (!s1 || !imports)
return s1;

Dsymbol *s = s1;
if (!s->isFuncDeclaration())
return s1;

OverloadSet *a = NULL;
for (size_t n = 0; n < imports->dim; n++)
{
Import *ss = (*imports)[n]->isImport();
if (!ss || ss->names.dim == 0)
continue;

Dsymbol *s2 = ss->search(loc, ident, flags & IgnorePrivateImports);
if (!s2)
continue;

if (!s2->isFuncDeclaration())
continue;

if (!a)
{
a = new OverloadSet(s->ident);
a->parent = this;
a->bug12359 = true;
}
/* Don't add to a[] if s2 is alias of previous sym
*/
for (size_t j = 0; j < a->a.dim; j++)
{
Dsymbol *s3 = a->a[j];
if (s2 == s3)
{
if (s3->isDeprecated() ||
s2->prot() > s3->prot() && s2->prot() != PROTnone)
a->a[j] = s2;
goto LcontinueX;
}
}
a->push(s2);
LcontinueX:
continue;
}
if (a)
{
a->push(s);
s1 = a;
}
#endif
//printf("\ts = '%s.%s'\n",toChars(),s1->toChars());
return s1;
}

Expand All @@ -966,13 +908,15 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
for (size_t i = 0; i < imports->dim; i++)
{
// If private import, don't search it
if ((flags & IgnorePrivateSymbols) && prots[i] == PROTprivate)
if ((flags & IgnorePrivateMembers) && prots[i] == PROTprivate)
continue;

Dsymbol *ss = (*imports)[i];

//printf("\tscanning imports[%d] : %s '%s', prots = %d\n", i, ss->kind(), ss->toChars(), prots[i]);
Dsymbol *s2 = ss->search(loc, ident, flags & IgnorePrivateImports);
//printf("\tscanning import '%s', prots = %d, isModule = %p, isImport = %p\n", ss->toChars(), prots[i], ss->isModule(), ss->isImport());
/* Don't find private members if ss is a module
*/
Dsymbol *s2 = ss->search(loc, ident, ss->isModule() ? IgnorePrivateMembers : IgnoreNone);
if (!s)
s = s2;
else if (s2 && s != s2)
Expand Down Expand Up @@ -1059,9 +1003,7 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
s = a;
}

// FIXME: Issue 10604 - Not consistent access check for overloaded symbols
if (!(flags & IgnoreErrors) &&
s->prot() == PROTprivate && !s->parent->isTemplateMixin())
if (!(flags & IgnoreErrors) && s->prot() == PROTprivate && !s->parent->isTemplateMixin())
{
if (!s->isImport())
error(loc, "%s %s is private", s->kind(), s->toPrettyChars());
Expand All @@ -1070,11 +1012,6 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags)
}
}

if (!(flags & IgnoreImportedFQN) && pkgtab)
{
// find leftmost package/module name for FQN access
s1 = pkgtab->lookup(ident);
}
return s1;
}

Expand Down
7 changes: 0 additions & 7 deletions src/dsymbol.h
Expand Up @@ -123,10 +123,6 @@ enum
IgnorePrivateMembers = 0x01, // don't find private members
IgnoreErrors = 0x02, // don't give error messages
IgnoreAmbiguous = 0x04, // return NULL if ambiguous
IgnoreImportedFQN = 0x08, // don't find imported FQNs
IgnorePrivateImports = 0x10, // don't find privately imported symbols

IgnorePrivateSymbols = IgnorePrivateMembers | IgnorePrivateImports,
};

typedef int (*Dsymbol_apply_ft_t)(Dsymbol *, void *);
Expand Down Expand Up @@ -283,8 +279,6 @@ class ScopeDsymbol : public Dsymbol
Dsymbols *imports; // imported Dsymbol's
PROT *prots; // array of PROT, one for each import

DsymbolTable *pkgtab; // accessible packages/modules from this scope

ScopeDsymbol();
ScopeDsymbol(Identifier *id);
Dsymbol *syntaxCopy(Dsymbol *s);
Expand Down Expand Up @@ -348,7 +342,6 @@ class OverloadSet : public Dsymbol
{
public:
Dsymbols a; // array of Dsymbols
bool bug12359;

OverloadSet(Identifier *ident);
void push(Dsymbol *s);
Expand Down
72 changes: 8 additions & 64 deletions src/expression.c
Expand Up @@ -3262,8 +3262,8 @@ Expression *DsymbolExp::semantic(Scope *sc)
error("forward reference of import %s", imp->toChars());
return new ErrorExp();
}
type = Type::tvoid;
return this;
ScopeExp *ie = new ScopeExp(loc, imp->pkg);
return ie->semantic(sc);
}
if (Package *pkg = s->isPackage())
{
Expand Down Expand Up @@ -6933,13 +6933,6 @@ Expression *DotIdExp::semanticX(Scope *sc)
e = e->semantic(sc);
return e;
}
case TOKdsymbol:
if (Import *imp = ((DsymbolExp *)e1)->s->isImport())
{
ds = imp->mod;
goto L1;
}
break;
default:
break;
}
Expand Down Expand Up @@ -7048,54 +7041,18 @@ Expression *DotIdExp::semanticY(Scope *sc, int flag)

Type *t1b = e1->type->toBasetype();

ScopeExp *ie = NULL;
Dsymbol *s;
if (eright->op == TOKdsymbol && ((DsymbolExp *)eright)->s->isImport())
{
Import *imp = (Import *)((DsymbolExp *)eright)->s;
if (imp->mod == sc->module)
s = imp->mod->search(loc, ident, IgnoreImportedFQN);
else
s = imp->search(loc, ident, IgnoreImportedFQN | IgnorePrivateMembers);
if (s)
goto L1;
else if (ident == Id::stringof)
{
OutBuffer buf;
buf.writestring(imp->mod->kind());
buf.writestring(" ");
buf.writestring(imp->mod->toChars());
buf.writeByte(0);
char *str = buf.extractData();
e = new StringExp(loc, str, strlen(str), 'c');
e = e->semantic(sc);
return e;
}
else
{
s = imp->search_correct(ident);
if (s)
error("undefined identifier '%s', did you mean '%s %s'?",
ident->toChars(), s->kind(), s->toChars());
else
error("undefined identifier '%s'", ident->toChars());
return new ErrorExp();
}
}
if (eright->op == TOKimport) // also used for template alias's
{
ie = (ScopeExp *)eright;
ScopeExp *ie = (ScopeExp *)eright;

/* Disable access to another module's private imports.
* The check for 'is sds our current module' is because
* the current module should have access to its own imports.
*/
s = ie->sds->search(loc, ident,
(ie->sds->isModule() && ie->sds != sc->module ? IgnoreImportedFQN | IgnorePrivateMembers : IgnoreNone)
);
Dsymbol *s = ie->sds->search(loc, ident,
(ie->sds->isModule() && ie->sds != sc->module) ? IgnorePrivateMembers : IgnoreNone);
if (s)
{
L1:
/* Check for access before resolving aliases because public
* aliases to private symbols are public.
*/
Expand Down Expand Up @@ -7201,8 +7158,8 @@ Expression *DotIdExp::semanticY(Scope *sc, int flag)
Import *imp = s->isImport();
if (imp)
{
DsymbolExp *se = new DsymbolExp(loc, imp);
return se->semantic(sc);
ie = new ScopeExp(loc, imp->pkg);
return ie->semantic(sc);
}

// BUG: handle other cases like in IdentifierExp::semantic()
Expand Down Expand Up @@ -8462,8 +8419,6 @@ Expression *CallExp::semantic(Scope *sc)
OverExp *eo = (OverExp *)e1;
FuncDeclaration *f = NULL;
Dsymbol *s = NULL;
bool err = false;
size_t lastmatch = eo->vars->a.dim;
for (size_t i = 0; i < eo->vars->a.dim; i++)
{
s = eo->vars->a[i];
Expand All @@ -8479,29 +8434,18 @@ Expression *CallExp::semantic(Scope *sc)
/* Error if match in more than one overload set,
* even if one is a 'better' match than the other.
*/
if (eo->vars->bug12359)
continue;
err = true;
ScopeDsymbol::multiplyDefined(loc, f, f2);
}
else
{
f = f2;
lastmatch = i;
}
}
}
if (!f)
{
/* No overload matches
{ /* No overload matches
*/
error("no overload matches for %s", s->toChars());
return new ErrorExp();
}
if (eo->vars->bug12359 && !err && lastmatch != eo->vars->a.dim - 1)
{
deprecation("implicit overload merging with selective/renamed import is now removed.");
}
if (ethis)
e1 = new DotVarExp(loc, ethis, f);
else
Expand Down

0 comments on commit 4350a08

Please sign in to comment.