Mercurial > projects > dang
diff sema/Scope.d @ 129:ed815b31479b
Added a Symbol
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sat, 21 Jun 2008 20:41:18 +0200 |
parents | 189c049cbfcc |
children | a14ac9e5c858 |
line wrap: on
line diff
--- a/sema/Scope.d Sat Jun 21 17:32:27 2008 +0200 +++ b/sema/Scope.d Sat Jun 21 20:41:18 2008 +0200 @@ -8,7 +8,8 @@ ast.Exp; public -import sema.DType; +import sema.DType, + sema.Symbol; class Scope { @@ -28,24 +29,23 @@ ImportDecl[] imports; - - void add(Identifier id) + void put(Identifier id, Decl d) { - symbols[id] = id; + symbols[id] = d; } - Identifier find(Identifier id) + Decl find(Identifier id) { if(id is null) return null; - if (auto sym = id in symbols) + else if (auto sym = id in symbols) return *sym; - if (enclosing !is null) + else if (enclosing !is null) { - auto type = enclosing.find(id); - if(type is null) + auto res = enclosing.find(id); + if (res is null) return mHandle.find(getImports, id); - return type; + return res; } return null; } @@ -60,7 +60,7 @@ DType findType(Identifier id) { if (auto type = id.get in types) - return *type; + return *type; if (enclosing !is null) { auto type = enclosing.findType(id); @@ -71,6 +71,7 @@ return null; } + /* char[][] names() { char[][] res; @@ -82,6 +83,7 @@ res ~= sym.name ~ " : " ~ (sym.type is null? "?" : sym.type.name); return res; } + */ FuncDecl parentFunction() { @@ -123,7 +125,7 @@ DType[char[]] types; int currentStmtIndex = -1; private: - Identifier[Identifier] symbols; + Decl[Identifier] symbols; FuncDecl func; } @@ -151,7 +153,7 @@ return null; } - Identifier find(ImportDecl[] imports, Identifier id) + Decl find(ImportDecl[] imports, Identifier id) { foreach(i ; imports) if(i.get in modules)