From fae0423ea19cc3b57afa3d13d016f69737b7d987 Mon Sep 17 00:00:00 2001 From: dawg Date: Wed, 29 Jun 2011 22:25:19 +0200 Subject: [PATCH] proof of concept hack for ordered template instantiation --- src/mars.c | 20 ++++++++++++++++++++ src/module.c | 1 + src/module.h | 1 + src/template.c | 2 +- 4 files changed, 23 insertions(+), 1 deletions(-) diff --git a/src/mars.c b/src/mars.c index d1fd64f..aab1652 100644 --- a/src/mars.c +++ b/src/mars.c @@ -26,6 +26,7 @@ #include "mars.h" #include "module.h" #include "mtype.h" +#include "scope.h" #include "id.h" #include "cond.h" #include "expression.h" @@ -1184,6 +1185,14 @@ int main(int argc, char *argv[]) if (global.errors) fatal(); + { + Module* tmplInst = new Module((char*)"__templateInstances.d", Lexer::idPool("__templateInstances"), 0, 0); + tmplInst->members = new Dsymbols(); + modules.push(tmplInst); + tmplInst->setScope(Scope::createGlobal(tmplInst)); + Module::templateInstances = tmplInst; + } + // Do semantic analysis for (i = 0; i < modules.dim; i++) { @@ -1281,6 +1290,17 @@ int main(int argc, char *argv[]) } } + { + assert(modules.data[modules.dim - 1] == Module::templateInstances); + Module* tmplInst = Module::templateInstances; + for (int i = 0; i < tmplInst->members->dim; i++) + { Dsymbol *s = (Dsymbol*)tmplInst->members->data[i]; + Module *m = s->getModule(); + m->importedFrom->members->push(s); + } + modules.pop(); + } + // Generate output files if (global.params.doXGeneration) diff --git a/src/module.c b/src/module.c index 1d46f57..8623b5c 100644 --- a/src/module.c +++ b/src/module.c @@ -47,6 +47,7 @@ ClassDeclaration *Module::moduleinfo; Module *Module::rootModule; +Module *Module::templateInstances; DsymbolTable *Module::modules; Array Module::amodules; diff --git a/src/module.h b/src/module.h index ccc3dd3..de9f6c7 100644 --- a/src/module.h +++ b/src/module.h @@ -48,6 +48,7 @@ struct Package : ScopeDsymbol struct Module : Package { static Module *rootModule; + static Module *templateInstances; // hold template instantiations static DsymbolTable *modules; // symbol table of all modules static Array amodules; // array of all modules static Array deferred; // deferred Dsymbol's needing semantic() run on them diff --git a/src/template.c b/src/template.c index fc9f095..7f23c7f 100644 --- a/src/template.c +++ b/src/template.c @@ -3953,7 +3953,7 @@ void TemplateInstance::semantic(Scope *sc, Expressions *fargs) a = scx->scopesym->members; } else - { Module *m = sc->module->importedFrom; + { Module *m = Module::templateInstances; //printf("\t2: adding to module %s instead of module %s\n", m->toChars(), sc->module->toChars()); a = m->members; if (m->semanticRun >= 3) -- 1.7.5.4