Mercurial > projects > ddmd
diff dmd/Module.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 | ad4792a1cfd6 |
children | 722df8e7509c |
line wrap: on
line diff
--- a/dmd/Module.d Sun Aug 29 14:39:08 2010 +0100 +++ b/dmd/Module.d Mon Aug 30 03:57:51 2010 +0200 @@ -12,6 +12,7 @@ import dmd.ModuleDeclaration; import dmd.File; import dmd.Identifier; +import dmd.Json; import dmd.Dsymbol; import dmd.ModuleInfoDeclaration; import dmd.FuncDeclaration; @@ -397,6 +398,38 @@ { assert(false); } + + override void toJsonBuffer(OutBuffer buf) + { + buf.writestring("{\n"); + + JsonProperty(buf, Pname, md.toChars()); + + JsonProperty(buf, Pkind, kind()); + + JsonProperty(buf, Pfile, srcfile.toChars()); + + if (comment) + JsonProperty(buf, Pcomment, comment); + + JsonString(buf, Pmembers); + buf.writestring(" : [\n"); + + size_t offset = buf.offset; + foreach (Dsymbol s; members) + { + if (offset != buf.offset) + { + buf.writestring(","); + offset = buf.offset; + } + s.toJsonBuffer(buf); + } + + buf.writestring("]\n"); + + buf.writestring("}\n"); + } override string kind() { @@ -612,7 +645,7 @@ */ if (buflen >= 4 && memcmp(buf, "Ddoc".ptr, 4) == 0) { - comment = buf + 4; + comment = cast(string) ((buf + 4)[0 .. buflen]); isDocFile = 1; if (!docfile) setDocfile(); @@ -627,7 +660,8 @@ ///buf = dbuf.data; ///buflen = dbuf.offset; -version (IN_GCC) { +version (IN_GCC) +{ // dump extracted source ///if (dump_source) /// d_gcc_dump_source(srcname, "d.utf-8", buf, buflen); @@ -673,10 +707,57 @@ } } + override void importAll(Scope prevsc) + { + //writef("+Module.importAll(this = %p, '%s'): parent = %p\n", this, toChars(), parent); + + if (scope_ !is null) + return; // already done + + /* Note that modules get their own scope, from scratch. + * This is so regardless of where in the syntax a module + * gets imported, it is unaffected by context. + * Ignore prevsc. + */ + Scope sc = Scope.createGlobal(this); // create root scope + + // Add import of "object" if this module isn't "object" + if (ident != Id.object) + { + if (members.dim == 0 || members[0].ident != Id.object) + { + Import im = new Import(Loc(), null, Id.object, null, 0); + members.shift(im); + } + } + + if (!symtab) + { + // Add all symbols into module's symbol table + symtab = new DsymbolTable(); + foreach (Dsymbol s; members) + s.addMember(null, sc.scopesym, 1); + } + // anything else should be run after addMember, so version/debug symbols are defined + + /* Set scope for the symbols so that if we forward reference + * a symbol, it can possibly be resolved on the spot. + * If this works out well, it can be extended to all modules + * before any semantic() on any of them. + */ + setScope(sc); // remember module scope for semantic + foreach (Dsymbol s; members) + s.setScope(sc); + + foreach (Dsymbol s; members) + s.importAll(sc); + + sc = sc.pop(); + sc.pop(); // 2 pops because Scope::createGlobal() created 2 + } + void semantic() // semantic analysis { - int i; - if (semanticstarted) return; @@ -686,10 +767,17 @@ // Note that modules get their own scope, from scratch. // This is so regardless of where in the syntax a module // gets imported, it is unaffected by context. - Scope sc = Scope.createGlobal(this); // create root scope + Scope sc = scope_; // // see if already got one from importAll() + if (!sc) + { + writef("test2\n"); + Scope.createGlobal(this); // create root scope + } - //printf("Module = %p, linkage = %d\n", sc.scopesym, sc.linkage); + //writef("Module = %p, linkage = %d\n", sc.scopesym, sc.linkage); +static if (false) +{ // Add import of "object" if this module isn't "object" if (ident !is Id.object) { @@ -711,6 +799,7 @@ */ foreach(Dsymbol s; members) s.setScope(sc); +} // Pass 1 semantic routines: do public side of the definition foreach (Dsymbol s; members) @@ -720,8 +809,11 @@ runDeferredSemantic(); } - sc = sc.pop(); - sc.pop(); // 2 pops because Scope.createGlobal() created 2 + if (!scope_) + { + sc = sc.pop(); + sc.pop(); // 2 pops because Scope.createGlobal() created 2 + } semanticRun = semanticstarted; //printf("-Module.semantic(this = %p, '%s'): parent = %p\n", this, toChars(), parent); } @@ -788,8 +880,6 @@ override void inlineScan() // scan for functions to inline { - int i; - if (semanticstarted >= 4) return; @@ -1144,13 +1234,14 @@ { /* Since modules can be circularly referenced, * need to stop infinite recursive searches. + * This is done with the cache. */ //printf("%s Module.search('%s', flags = %d) insearch = %d\n", toChars(), ident.toChars(), flags, insearch); Dsymbol s; if (insearch) s = null; - else if (searchCacheIdent == ident && searchCacheFlags == flags && searchCacheSymbol) + else if (searchCacheIdent == ident && searchCacheFlags == flags) { s = searchCacheSymbol; //printf("%s Module.search('%s', flags = %d) insearch = %d searchCacheSymbol = %s\n", toChars(), ident.toChars(), flags, insearch, searchCacheSymbol ? searchCacheSymbol.toChars() : "null"); @@ -1176,6 +1267,12 @@ docfile.remove(); } + override Dsymbol symtabInsert(Dsymbol s) + { + searchCacheIdent = null; // symbol is inserted, so invalidate cache + return Package.symtabInsert(s); + } + /******************************************* * Can't run semantic on s now, try again later. */ @@ -1190,7 +1287,7 @@ return; } - //printf("Module::addDeferredSemantic('%s')\n", s->toChars()); + //printf("Module::addDeferredSemantic('%s')\n", s.toChars()); deferred.push(cast(void*)s); }