Mercurial > projects > ddmd
diff dmd/Import.d @ 79:43073c7c7769
updated to 2.035
also implemented a few missing functions
still crashes in Import.importAll though
author | Trass3r |
---|---|
date | Mon, 30 Aug 2010 03:57:51 +0200 |
parents | 2e2a5c3f943a |
children | 5c859d5fbe27 |
line wrap: on
line diff
--- a/dmd/Import.d Sun Aug 29 14:39:08 2010 +0100 +++ b/dmd/Import.d Mon Aug 30 03:57:51 2010 +0200 @@ -23,8 +23,8 @@ void escapePath(OutBuffer buf, string fname) { - foreach (char c; fname) - { + foreach (char c; fname) + { switch (c) { case '(': @@ -35,26 +35,26 @@ buf.writebyte(*fname); break; } - } + } } class Import : Dsymbol { - Array packages; // array of Identifier's representing packages - Identifier id; // module Identifier - Identifier aliasId; - int isstatic; // !=0 if static import + Array packages; // array of Identifier's representing packages + Identifier id; // module Identifier + Identifier aliasId; + int isstatic; // !=0 if static import - // Pairs of alias=name to bind into current namespace - Array names; - Array aliases; + // Pairs of alias=name to bind into current namespace + Array names; + Array aliases; - Array aliasdecls; // AliasDeclarations for names/aliases + Array aliasdecls; // AliasDeclarations for names/aliases - Module mod; - Package pkg; // leftmost package/module + Module mod; + Package pkg; // leftmost package/module - this(Loc loc, Array packages, Identifier id, Identifier aliasId, int isstatic) + this(Loc loc, Array packages, Identifier id, Identifier aliasId, int isstatic) { super(id); @@ -75,7 +75,7 @@ else if (packages && packages.dim) this.ident = cast(Identifier)packages.data[0]; } - + void addAlias(Identifier name, Identifier alias_) { if (isstatic) @@ -88,32 +88,32 @@ aliases.push(cast(void*)alias_); } - override string kind() + override string kind() { return isstatic ? "static import" : "import"; } - override Dsymbol syntaxCopy(Dsymbol s) // copy only syntax trees + override Dsymbol syntaxCopy(Dsymbol s) // copy only syntax trees { assert(false); } - void load(Scope sc) + void load(Scope sc) { - DsymbolTable dst; - Dsymbol s; - //writef("Import::load('%s')\n", toChars()); // See if existing module - dst = Package.resolve(packages, null, &pkg); + DsymbolTable dst = Package.resolve(packages, null, &pkg); - s = dst.lookup(id); + Dsymbol s = dst.lookup(id); if (s) { -version (TARGET_NET) { +version (TARGET_NET) +{ mod = cast(Module)s; -} else { +} +else +{ if (s.isModule()) mod = cast(Module)s; else @@ -125,7 +125,7 @@ { // Load module mod = Module.load(loc, packages, id); - dst.insert(id, mod); // id may be different from mod->ident, + dst.insert(id, mod); // id may be different from mod.ident, // if so then insert alias if (!mod.importedFrom) mod.importedFrom = sc ? sc.module_.importedFrom : Module.rootModule; @@ -137,15 +137,40 @@ //writef("-Import::load('%s'), pkg = %p\n", toChars(), pkg); } - override void semantic(Scope sc) + override void importAll(Scope sc) + { + if (!mod) + { + load(sc); + mod.importAll(null); + + if (!isstatic && !aliasId && !names.dim) + { + /* Default to private importing + */ + PROT prot = sc.protection; + if (!sc.explicitProtection) + prot = PROT.PROTprivate; + sc.scopesym.importScope(mod, prot); + } + } + } + + override void semantic(Scope sc) { //writef("Import.semantic('%s')\n", toChars()); - load(sc); + // Load if not already done so + if (!mod) + { + load(sc); + mod.importAll(null); + } if (mod) { -static if (false) { +static if (false) +{ if (mod.loc.linnum != 0) { /* If the line number is not 0, then this is not * a 'root' module, i.e. it was not specified on the command line. @@ -193,15 +218,15 @@ { /* The grammar of the file is: * ImportDeclaration - * .= BasicImportDeclaration [ " : " ImportBindList ] [ " . " + * .= BasicImportDeclaration [ " : " ImportBindList ] [ " . " * ModuleAliasIdentifier ] "\n" * * BasicImportDeclaration - * .= ModuleFullyQualifiedName " (" FilePath ") : " Protection + * .= ModuleFullyQualifiedName " (" FilePath ") : " Protection * " [ " static" ] : " ModuleFullyQualifiedName " (" FilePath ")" * * FilePath - * - any string with '(', ')' and '\' escaped with the '\' character + * - any string with '(', ')' and '\' escaped with the '\' character */ OutBuffer ob = global.params.moduleDeps; @@ -261,7 +286,7 @@ //printf("-Import.semantic('%s'), pkg = %p\n", toChars(), pkg); } - override void semantic2(Scope sc) + override void semantic2(Scope sc) { //printf("Import::semantic2('%s')\n", toChars()); mod.semantic2(); @@ -269,7 +294,7 @@ sc.module_.needmoduleinfo = 1; } - override Dsymbol toAlias() + override Dsymbol toAlias() { if (aliasId) return mod; @@ -279,7 +304,7 @@ /***************************** * Add import to sd's symbol table. */ - override bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) + override bool addMember(Scope sc, ScopeDsymbol sd, bool memnum) { bool result = false; @@ -310,7 +335,7 @@ return result; } - override Dsymbol search(Loc loc, Identifier ident, int flags) + override Dsymbol search(Loc loc, Identifier ident, int flags) { //printf("%s.Import.search(ident = '%s', flags = x%x)\n", toChars(), ident.toChars(), flags); @@ -324,16 +349,16 @@ return pkg.search(loc, ident, flags); } - override bool overloadInsert(Dsymbol s) + override bool overloadInsert(Dsymbol s) { // Allow multiple imports of the same name return s.isImport() !is null; } - override void toCBuffer(OutBuffer buf, HdrGenState* hgs) + override void toCBuffer(OutBuffer buf, HdrGenState* hgs) { assert(false); } - override Import isImport() { return this; } + override Import isImport() { return this; } }