Mercurial > projects > dang
diff sema/Scope.d @ 101:fea8d61a2451 new_gen
First step(the other first was a bad one) toward imports. You can now compile two files that use eachother - given that they both are in the command line. Right now it's only root sturcts and methods you can use(i guess...?)
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Wed, 07 May 2008 19:58:13 +0200 |
parents | 857f0d530789 |
children | 189c049cbfcc |
line wrap: on
line diff
--- a/sema/Scope.d Tue May 06 22:49:43 2008 +0200 +++ b/sema/Scope.d Wed May 07 19:58:13 2008 +0200 @@ -18,11 +18,16 @@ this.enclosing = enclosing; this.func = enclosing.func; this.inModule = enclosing.inModule; + this.mHandle = enclosing.mHandle; } Scope enclosing; + ModuleHandler mHandle; Module inModule; + ImportDecl[] imports; + + void add(Identifier id) { symbols[id] = id; @@ -35,16 +40,33 @@ if (auto sym = id in symbols) return *sym; if (enclosing !is null) - return enclosing.find(id); + { + auto type = enclosing.find(id); + if(type is null) + return mHandle.find(getImports, id); + return type; + } return null; } + ImportDecl[] getImports() + { + if(enclosing) + return enclosing.getImports ~ imports; + return imports; + } + DType findType(Identifier id) { if (auto type = id.get in types) return *type; if (enclosing !is null) - return enclosing.findType(id); + { + auto type = enclosing.findType(id); + if(type is null) + return mHandle.findType(getImports, id); + return type; + } return null; } @@ -104,3 +126,43 @@ FuncDecl func; } +class ModuleHandler +{ + void add(Module m) + { + modules[m.moduleName] = m; + } + void add(Module m, char[] file) + { + fileToModule[file] = m.moduleName; + add(m); + } + + DType findType(ImportDecl[] imports, Identifier type) + { + foreach(i ; imports) + if(i.get in modules) + { + auto t = modules[i.get].env.findType(type); + if(t !is null) + return t; + } + return null; + } + + Identifier find(ImportDecl[] imports, Identifier id) + { + foreach(i ; imports) + if(i.get in modules) + { + auto t = modules[i.get].env.find(id); + if(t !is null) + return t; + } + return null; + } + + char[][char[]] fileToModule; + Module[char[]] modules; +} +