Mercurial > projects > dang
diff sema/ScopeBuilder.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 | cd066f3b539a |
line wrap: on
line diff
--- a/sema/ScopeBuilder.d Tue May 06 22:49:43 2008 +0200 +++ b/sema/ScopeBuilder.d Wed May 07 19:58:13 2008 +0200 @@ -11,6 +11,12 @@ class ForwardReference : Visitor!(void) { + override void visit(Module[] modules) + { + this.modules = modules; + super.visit(modules); + } + override void visitFuncDecl(FuncDecl d) { visitExp(d.returnType); @@ -53,31 +59,52 @@ return typeOf(i.arrayOf, sc).getAsArray(i.size); return sc.findType(id); } + + Module[] modules; } class ScopeBuilder : Visitor!(void) { + static ModuleHandler mHandle; + + static this() + { + mHandle = new ModuleHandler; + } + this() { + } + + override void visit(Module[] modules) + { + foreach(m ; modules) + visitModule(m); + + auto fr = new ForwardReference(); + + fr.visit(modules); + } + + override void visitModule(Module m) + { table ~= new Scope; - table[0].types["void"] = DType.Void; - table[0].types["bool"] = DType.Bool; - table[0].types["byte"] = DType.Byte; - table[0].types["ubyte"] = DType.UByte; - table[0].types["short"] = DType.Short; - table[0].types["ushort"] = DType.UShort; - table[0].types["int"] = DType.Int; - table[0].types["uint"] = DType.UInt; - table[0].types["long"] = DType.Long; - table[0].types["ulong"] = DType.ULong; - } + table[table.length-1].types["void"] = DType.Void; + table[table.length-1].types["bool"] = DType.Bool; + table[table.length-1].types["byte"] = DType.Byte; + table[table.length-1].types["ubyte"] = DType.UByte; + table[table.length-1].types["short"] = DType.Short; + table[table.length-1].types["ushort"] = DType.UShort; + table[table.length-1].types["int"] = DType.Int; + table[table.length-1].types["uint"] = DType.UInt; + table[table.length-1].types["long"] = DType.Long; + table[table.length-1].types["ulong"] = DType.ULong; - override void visit(Module m) - { current().inModule = m; - visitModule(m); - auto fr = new ForwardReference(); - fr.visit(m); + current().mHandle = mHandle; + mHandle.add(m); + m.env = current(); + super.visitModule(m); } override void visitDecl(Decl d) @@ -86,6 +113,12 @@ super.visitDecl(d); } + override void visitImportDecl(ImportDecl i) + { + i.env.imports ~= i; + super.visitImportDecl(i); + } + override void visitStmt(Stmt s) { s.env = current();