Mercurial > projects > dang
comparison 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 |
comparison
equal
deleted
inserted
replaced
100:5f258eaf9517 | 101:fea8d61a2451 |
---|---|
9 import sema.Visitor, | 9 import sema.Visitor, |
10 basic.SmallArray; | 10 basic.SmallArray; |
11 | 11 |
12 class ForwardReference : Visitor!(void) | 12 class ForwardReference : Visitor!(void) |
13 { | 13 { |
14 override void visit(Module[] modules) | |
15 { | |
16 this.modules = modules; | |
17 super.visit(modules); | |
18 } | |
19 | |
14 override void visitFuncDecl(FuncDecl d) | 20 override void visitFuncDecl(FuncDecl d) |
15 { | 21 { |
16 visitExp(d.returnType); | 22 visitExp(d.returnType); |
17 visitExp(d.identifier); | 23 visitExp(d.identifier); |
18 foreach (arg; d.funcArgs) | 24 foreach (arg; d.funcArgs) |
51 return (typeOf(i.pointerOf, sc)).getPointerTo(); | 57 return (typeOf(i.pointerOf, sc)).getPointerTo(); |
52 if(auto i = cast(ArrayIdentifier)id) | 58 if(auto i = cast(ArrayIdentifier)id) |
53 return typeOf(i.arrayOf, sc).getAsArray(i.size); | 59 return typeOf(i.arrayOf, sc).getAsArray(i.size); |
54 return sc.findType(id); | 60 return sc.findType(id); |
55 } | 61 } |
62 | |
63 Module[] modules; | |
56 } | 64 } |
57 | 65 |
58 class ScopeBuilder : Visitor!(void) | 66 class ScopeBuilder : Visitor!(void) |
59 { | 67 { |
68 static ModuleHandler mHandle; | |
69 | |
70 static this() | |
71 { | |
72 mHandle = new ModuleHandler; | |
73 } | |
74 | |
60 this() | 75 this() |
61 { | 76 { |
77 } | |
78 | |
79 override void visit(Module[] modules) | |
80 { | |
81 foreach(m ; modules) | |
82 visitModule(m); | |
83 | |
84 auto fr = new ForwardReference(); | |
85 | |
86 fr.visit(modules); | |
87 } | |
88 | |
89 override void visitModule(Module m) | |
90 { | |
62 table ~= new Scope; | 91 table ~= new Scope; |
63 table[0].types["void"] = DType.Void; | 92 table[table.length-1].types["void"] = DType.Void; |
64 table[0].types["bool"] = DType.Bool; | 93 table[table.length-1].types["bool"] = DType.Bool; |
65 table[0].types["byte"] = DType.Byte; | 94 table[table.length-1].types["byte"] = DType.Byte; |
66 table[0].types["ubyte"] = DType.UByte; | 95 table[table.length-1].types["ubyte"] = DType.UByte; |
67 table[0].types["short"] = DType.Short; | 96 table[table.length-1].types["short"] = DType.Short; |
68 table[0].types["ushort"] = DType.UShort; | 97 table[table.length-1].types["ushort"] = DType.UShort; |
69 table[0].types["int"] = DType.Int; | 98 table[table.length-1].types["int"] = DType.Int; |
70 table[0].types["uint"] = DType.UInt; | 99 table[table.length-1].types["uint"] = DType.UInt; |
71 table[0].types["long"] = DType.Long; | 100 table[table.length-1].types["long"] = DType.Long; |
72 table[0].types["ulong"] = DType.ULong; | 101 table[table.length-1].types["ulong"] = DType.ULong; |
73 } | 102 |
74 | |
75 override void visit(Module m) | |
76 { | |
77 current().inModule = m; | 103 current().inModule = m; |
78 visitModule(m); | 104 current().mHandle = mHandle; |
79 auto fr = new ForwardReference(); | 105 mHandle.add(m); |
80 fr.visit(m); | 106 m.env = current(); |
107 super.visitModule(m); | |
81 } | 108 } |
82 | 109 |
83 override void visitDecl(Decl d) | 110 override void visitDecl(Decl d) |
84 { | 111 { |
85 d.env = current(); | 112 d.env = current(); |
86 super.visitDecl(d); | 113 super.visitDecl(d); |
114 } | |
115 | |
116 override void visitImportDecl(ImportDecl i) | |
117 { | |
118 i.env.imports ~= i; | |
119 super.visitImportDecl(i); | |
87 } | 120 } |
88 | 121 |
89 override void visitStmt(Stmt s) | 122 override void visitStmt(Stmt s) |
90 { | 123 { |
91 s.env = current(); | 124 s.env = current(); |