Mercurial > projects > dang
view sema/Scope.d @ 163:362265427838
Fixes to types for constructor and also removed DFunction's from DStruct, DClass and DInterface
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Tue, 22 Jul 2008 16:50:47 +0200 |
parents | 6c5a3c0bb4fb |
children | 7982eb63c0eb |
line wrap: on
line source
module sema.Scope; import tango.io.Stdout; import lexer.Token, ast.Module, ast.Decl; public import sema.DType, sema.Symbol; class Scope { this() {} this(Scope enclosing) { this.enclosing = enclosing; this.func = enclosing.func; this.inModule = enclosing.inModule; this.mHandle = enclosing.mHandle; } Scope enclosing; ModuleHandler mHandle; Module inModule; Scope[] imported; ImportDecl[] imports; void put(char[] id, Decl d) { symbols[id] = d; } Decl find(char[] id) { if(id is null) return null; else if (auto sym = id in symbols) return *sym; else if (enclosing !is null) { auto res = enclosing.find(id); if (res is null) return mHandle.find(getImports, id); return res; } return null; } ImportDecl[] getImports() { if(enclosing) return enclosing.getImports ~ imports; return imports; } DType findType(char[] id) { if (auto type = id in types) return *type; if (enclosing !is null) { auto type = enclosing.findType(id); if(type is null) return mHandle.findType(getImports, id); return type; } return null; } FuncDecl parentFunction() { if (func !is null) return func; else if (enclosing !is null) return enclosing.parentFunction(); else return null; } int stmtIndex() { if (currentStmtIndex != -1) return currentStmtIndex; else if (enclosing !is null) return enclosing.stmtIndex(); else return -1; } int opEquals(Object o) { return this is o; } char[] toString() { if (func) return Stdout.layout.convert("{}: {}", func.identifier.get, symbols.length); return Stdout.layout.convert("root: {}", symbols.length); } FuncDecl parentFunction(FuncDecl f) { func = f; return f; } DType[char[]] types; int currentStmtIndex = -1; private: Decl[char[]] symbols; FuncDecl func; } class ModuleHandler { void add(Module m) { modules[m.moduleName] = m; } void add(Module m, char[] file) { fileToModule[file] = m.moduleName; add(m); } DType findType(ImportDecl[] imports, char[] type) { foreach(i ; imports) if(i.get in modules) { auto t = modules[i.get].env.findType(type); if(t !is null) return t; } return null; } Decl find(ImportDecl[] imports, char[] id) { foreach(i ; imports) if(i.get in modules) { auto t = modules[i.get].env.find(id); if(t !is null) return t; } return null; } char[][char[]] fileToModule; Module[char[]] modules; }