comparison dmd/import.c @ 626:e83ba4ae4878

Fix import visibility bugs 313 and 314.
author Christian Kamm <kamm incasoftware de>
date Wed, 01 Oct 2008 19:16:10 +0200
parents aaade6ded589
children bc982f1ad106
comparison
equal deleted inserted replaced
625:7e0a766fef47 626:e83ba4ae4878
31 this->loc = loc; 31 this->loc = loc;
32 this->packages = packages; 32 this->packages = packages;
33 this->id = id; 33 this->id = id;
34 this->aliasId = aliasId; 34 this->aliasId = aliasId;
35 this->isstatic = isstatic; 35 this->isstatic = isstatic;
36 protection = PROTundefined;
36 pkg = NULL; 37 pkg = NULL;
37 mod = NULL; 38 mod = NULL;
38 39
39 if (aliasId) 40 if (aliasId)
40 this->ident = aliasId; 41 this->ident = aliasId;
58 const char *Import::kind() 59 const char *Import::kind()
59 { 60 {
60 return isstatic ? (char *)"static import" : (char *)"import"; 61 return isstatic ? (char *)"static import" : (char *)"import";
61 } 62 }
62 63
64 enum PROT Import::prot()
65 {
66 return protection;
67 }
63 68
64 Dsymbol *Import::syntaxCopy(Dsymbol *s) 69 Dsymbol *Import::syntaxCopy(Dsymbol *s)
65 { 70 {
66 assert(!s); 71 assert(!s);
67 72
129 mod->importedFrom = sc->module->importedFrom; 134 mod->importedFrom = sc->module->importedFrom;
130 assert(mod->importedFrom); 135 assert(mod->importedFrom);
131 } 136 }
132 #endif 137 #endif
133 138
139 /* Default to private importing
140 */
141 protection = sc->protection;
142 if (!sc->explicitProtection)
143 protection = PROTprivate;
144
134 if (!isstatic && !aliasId && !names.dim) 145 if (!isstatic && !aliasId && !names.dim)
135 { 146 {
136 /* Default to private importing 147 sc->scopesym->importScope(mod, protection);
137 */
138 enum PROT prot = sc->protection;
139 if (!sc->explicitProtection)
140 prot = PROTprivate;
141 sc->scopesym->importScope(mod, prot);
142 } 148 }
143 149
144 // Modules need a list of each imported module 150 // Modules need a list of each imported module
145 sc->module->aimports.push(mod); 151 sc->module->aimports.push(mod);
146 152
147 if (mod->needmoduleinfo) 153 if (mod->needmoduleinfo)
148 sc->module->needmoduleinfo = 1; 154 sc->module->needmoduleinfo = 1;
149 155
150 sc = sc->push(mod); 156 sc = sc->push(mod);
151 for (size_t i = 0; i < aliasdecls.dim; i++) 157 for (size_t i = 0; i < aliasdecls.dim; i++)
152 { Dsymbol *s = (Dsymbol *)aliasdecls.data[i]; 158 { AliasDeclaration *ad = (AliasDeclaration *)aliasdecls.data[i];
153 159
154 //printf("\tImport alias semantic('%s')\n", s->toChars()); 160 //printf("\tImport alias semantic('%s')\n", s->toChars());
155 if (!mod->search(loc, (Identifier *)names.data[i], 0)) 161 if (!mod->search(loc, (Identifier *)names.data[i], 0))
156 error("%s not found", ((Identifier *)names.data[i])->toChars()); 162 error("%s not found", ((Identifier *)names.data[i])->toChars());
157 163
158 s->semantic(sc); 164 ad->semantic(sc);
165 ad->protection = protection;
159 } 166 }
160 sc = sc->pop(); 167 sc = sc->pop();
161 } 168 }
162 //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg); 169 //printf("-Import::semantic('%s'), pkg = %p\n", toChars(), pkg);
163 } 170 }