Mercurial > projects > dang
comparison sema/Scope.d @ 168:7982eb63c0eb
Some changes to get function overloading to work. Also class inherit works now - to some extend. needs vtables and all the complex stuff of it.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Thu, 24 Jul 2008 12:06:48 +0200 |
parents | 6c5a3c0bb4fb |
children |
comparison
equal
deleted
inserted
replaced
166:9cfa33517526 | 168:7982eb63c0eb |
---|---|
28 | 28 |
29 ImportDecl[] imports; | 29 ImportDecl[] imports; |
30 | 30 |
31 void put(char[] id, Decl d) | 31 void put(char[] id, Decl d) |
32 { | 32 { |
33 symbols[id] = d; | 33 symbols[id] ~= d; |
34 } | 34 } |
35 | 35 |
36 Decl find(char[] id) | 36 Decl[] find(char[] id) |
37 { | 37 { |
38 if(id is null) | 38 if(id is "") |
39 return null; | 39 return null; |
40 else if (auto sym = id in symbols) | 40 else if (auto sym = id in symbols) |
41 { | |
41 return *sym; | 42 return *sym; |
43 } | |
42 else if (enclosing !is null) | 44 else if (enclosing !is null) |
43 { | 45 { |
44 auto res = enclosing.find(id); | 46 auto res = enclosing.find(id) ~ mHandle.find(getImports, id); |
45 if (res is null) | |
46 return mHandle.find(getImports, id); | |
47 return res; | 47 return res; |
48 } | 48 } |
49 return null; | 49 return []; |
50 } | 50 } |
51 | 51 |
52 ImportDecl[] getImports() | 52 ImportDecl[] getImports() |
53 { | 53 { |
54 if(enclosing) | 54 if(enclosing) |
108 return f; | 108 return f; |
109 } | 109 } |
110 DType[char[]] types; | 110 DType[char[]] types; |
111 int currentStmtIndex = -1; | 111 int currentStmtIndex = -1; |
112 private: | 112 private: |
113 Decl[char[]] symbols; | 113 Decl[][char[]] symbols; |
114 FuncDecl func; | 114 FuncDecl func; |
115 } | 115 } |
116 | 116 |
117 class ModuleHandler | 117 class ModuleHandler |
118 { | 118 { |
136 return t; | 136 return t; |
137 } | 137 } |
138 return null; | 138 return null; |
139 } | 139 } |
140 | 140 |
141 Decl find(ImportDecl[] imports, char[] id) | 141 Decl[] find(ImportDecl[] imports, char[] id) |
142 { | 142 { |
143 foreach(i ; imports) | 143 foreach(i ; imports) |
144 if(i.get in modules) | 144 if(i.get in modules) |
145 { | 145 { |
146 auto t = modules[i.get].env.find(id); | 146 auto t = modules[i.get].env.find(id); |
147 if(t !is null) | 147 if(t !is null) |
148 return t; | 148 return t; |
149 } | 149 } |
150 return null; | 150 return []; |
151 } | 151 } |
152 | 152 |
153 char[][char[]] fileToModule; | 153 char[][char[]] fileToModule; |
154 Module[char[]] modules; | 154 Module[char[]] modules; |
155 } | 155 } |