From 271012bcfcbb8a487baf632f2739638fa02caf10 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 1 Oct 2008 19:16:10 +0200 Subject: [PATCH] Fix import visibility bugs 313 and 314. --- dmd/dsymbol.c | 5 +++++ dmd/import.c | 23 +++++++++++++++-------- dmd/import.h | 2 ++ gen/toobj.cpp | 2 +- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/dmd/dsymbol.c b/dmd/dsymbol.c index 8f5e7e5c..196665d4 100644 --- a/dmd/dsymbol.c +++ b/dmd/dsymbol.c @@ -646,6 +646,11 @@ Dsymbol *ScopeDsymbol::search(Loc loc, Identifier *ident, int flags) // Look in symbols declared in this module Dsymbol *s = symtab ? symtab->lookup(ident) : NULL; + + // hide private nonlocal symbols + if (flags & 1 && s && s->prot() == PROTprivate) + s = NULL; + if (s) { //printf("\ts = '%s.%s'\n",toChars(),s->toChars()); diff --git a/dmd/import.c b/dmd/import.c index c713a70f..630a0010 100644 --- a/dmd/import.c +++ b/dmd/import.c @@ -33,6 +33,7 @@ Import::Import(Loc loc, Array *packages, Identifier *id, Identifier *aliasId, this->id = id; this->aliasId = aliasId; this->isstatic = isstatic; + protection = PROTundefined; pkg = NULL; mod = NULL; @@ -60,6 +61,10 @@ const char *Import::kind() return isstatic ? (char *)"static import" : (char *)"import"; } +enum PROT Import::prot() +{ + return protection; +} Dsymbol *Import::syntaxCopy(Dsymbol *s) { @@ -131,14 +136,15 @@ void Import::semantic(Scope *sc) } #endif + /* Default to private importing + */ + protection = sc->protection; + if (!sc->explicitProtection) + protection = PROTprivate; + if (!isstatic && !aliasId && !names.dim) { - /* Default to private importing - */ - enum PROT prot = sc->protection; - if (!sc->explicitProtection) - prot = PROTprivate; - sc->scopesym->importScope(mod, prot); + sc->scopesym->importScope(mod, protection); } // Modules need a list of each imported module @@ -149,13 +155,14 @@ void Import::semantic(Scope *sc) sc = sc->push(mod); for (size_t i = 0; i < aliasdecls.dim; i++) - { Dsymbol *s = (Dsymbol *)aliasdecls.data[i]; + { AliasDeclaration *ad = (AliasDeclaration *)aliasdecls.data[i]; //printf("\tImport alias semantic('%s')\n", s->toChars()); if (!mod->search(loc, (Identifier *)names.data[i], 0)) error("%s not found", ((Identifier *)names.data[i])->toChars()); - s->semantic(sc); + ad->semantic(sc); + ad->protection = protection; } sc = sc->pop(); } diff --git a/dmd/import.h b/dmd/import.h index 6ea18e5a..96c884a0 100644 --- a/dmd/import.h +++ b/dmd/import.h @@ -34,6 +34,7 @@ struct Import : Dsymbol Identifier *id; // module Identifier Identifier *aliasId; int isstatic; // !=0 if static import + enum PROT protection; // Pairs of alias=name to bind into current namespace Array names; @@ -49,6 +50,7 @@ struct Import : Dsymbol void addAlias(Identifier *name, Identifier *alias); const char *kind(); + enum PROT prot(); Dsymbol *syntaxCopy(Dsymbol *s); // copy only syntax trees void load(Scope *sc); void semantic(Scope *sc); diff --git a/gen/toobj.cpp b/gen/toobj.cpp index 0074da7d..d9217c9b 100644 --- a/gen/toobj.cpp +++ b/gen/toobj.cpp @@ -64,7 +64,7 @@ void Module::genobjfile(int multiobj) Logger::println("Generating module: %s\n", (md ? md->toChars() : toChars())); LOG_SCOPE; - printf("codegen: %s\n", srcfile->toChars()); +// printf("codegen: %s\n", srcfile->toChars()); // start by deleting the old object file deleteObjFile();