Mercurial > projects > dang
view sema/SymbolTable.d @ 27:9031487e97d7 new_gen
Various changes related to DType
* Drop the typeToLLVM table from LLVMGen
* Removed circular dependency
* Added basic types to DType
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sun, 20 Apr 2008 01:08:50 +0200 |
parents | b4dc2b2c0e38 |
children | 69464d465284 |
line wrap: on
line source
module sema.SymbolTable; import tango.io.Stdout; import lexer.Token, ast.Exp; public import sema.Symbol; class Scope { this() {} this(Scope enclosing) { this.enclosing = enclosing; this.func = enclosing.func; } Scope enclosing; Symbol add(Identifier id) { auto s = new Symbol; s.id = id; symbols[id] = s; return s; } Symbol find(Identifier id) { if (auto sym = id in symbols) return *sym; if (enclosing !is null) return enclosing.find(id); return null; } Symbol findType(Identifier id) { if (auto sym = id in symbols) if(symbols[id].type == null) return *sym; if (enclosing !is null) return enclosing.find(id); return null; } char[][] names() { char[][] res; if (enclosing) res = enclosing.names; foreach (id, sym; symbols) res ~= sym.id.name ~ " : " ~ sym.type.name; return res; } Symbol parentFunction() { if (func !is null) return func; else if (enclosing !is null) return enclosing.parentFunction(); else return null; } int opEquals(Object o) { return this is o; } char[] toString() { if (func) return Stdout.layout.convert("{}: {}", func.id.get, symbols.length); return "root"; } Symbol parentFunction(Symbol f) { func = f; return f; } private: Symbol[Identifier] symbols; Symbol func; }