Mercurial > projects > dil
changeset 592:b8dd677e0ace
Moved dil.Scope to dil.semantic.Scope.
author | Aziz K?ksal <aziz.koeksal@gmail.com> |
---|---|
date | Sat, 05 Jan 2008 23:52:41 +0100 |
parents | 26addda6365b |
children | 2848ce3becf5 |
files | trunk/src/dil/Module.d trunk/src/dil/Scope.d trunk/src/dil/ast/Declarations.d trunk/src/dil/ast/Expressions.d trunk/src/dil/ast/Statements.d trunk/src/dil/ast/Types.d trunk/src/dil/semantic/Analysis.d trunk/src/dil/semantic/Scope.d |
diffstat | 8 files changed, 128 insertions(+), 128 deletions(-) [+] |
line wrap: on
line diff
--- a/trunk/src/dil/Module.d Sat Jan 05 23:47:06 2008 +0100 +++ b/trunk/src/dil/Module.d Sat Jan 05 23:52:41 2008 +0100 @@ -10,7 +10,7 @@ import dil.parser.ImportParser; import dil.lexer.Lexer; import dil.File; -import dil.Scope; +import dil.semantic.Scope; import dil.semantic.Symbol; import dil.semantic.Symbols; import dil.Information;
--- a/trunk/src/dil/Scope.d Sat Jan 05 23:47:06 2008 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,122 +0,0 @@ -/++ - Author: Aziz Köksal - License: GPL3 -+/ -module dil.Scope; - -import dil.semantic.Symbol; -import dil.semantic.Symbols; -import dil.Information; -import dil.Messages; -import dil.Token; -import common; - -class Scope -{ - Scope parent; /// The surrounding scope. - InfoManager infoMan; /// Collects errors reported during the semantic phase. - - ScopeSymbol symbol; /// The current symbol with the symbol table. - - this() - { - } - - /++ - Find an identifier in this scope. - +/ - Symbol find(char[] ident) - { - return null; - } - - /++ - Add a symbol to this scope. - +/ - void add(Symbol sym) - { - - } - - /// Insert a new variable symbol into this scope. - void insert(Variable var) - { - auto sym = symbol.lookup(var.ident); - if (sym) - { - auto loc = sym.node.begin.getLocation(); - auto locString = Format("{}({},{})", loc.filePath, loc.lineNum, loc.colNum); - error(var.node.begin, MSG.VariableConflictsWithDecl, var.ident.str, locString); - } - else - symbol.insert(var, var.ident); - // Set the current scope symbol as the parent. - var.parent = symbol; - } - - /++ - Create a new inner scope. - +/ - Scope push(ScopeSymbol symbol) - { - auto sc = new Scope(); - sc.parent = this; - sc.infoMan = this.infoMan; - sc.symbol = symbol; - return sc; - } - - /++ - Destroy this scope and return the outer scope. - +/ - Scope pop() - { - auto sc = parent; - // delete this; - return sc; - } - - bool isInterface() - { - return symbol.isInterface; - } - - /// Search for the enclosing Class scope. - Scope classScope() - { - auto scop = this; - while (scop) - { - if (scop.symbol.isClass) - return scop; - scop = scop.parent; - } - return null; - } - - /// Search for the enclosing Module scope. - Scope moduleScope() - { - auto scop = this; - while (scop) - { - if (scop.symbol.isModule) - return scop; - scop = scop.parent; - } - return null; - } - - void error(Token* token, MID mid) - { - auto location = token.getLocation(); - infoMan ~= new SemanticError(location, GetMsg(mid)); - } - - void error(Token* token, char[] formatMsg, ...) - { - auto location = token.getLocation(); - auto msg = Format(_arguments, _argptr, formatMsg); - infoMan ~= new SemanticError(location, msg); - } -}
--- a/trunk/src/dil/ast/Declarations.d Sat Jan 05 23:47:06 2008 +0100 +++ b/trunk/src/dil/ast/Declarations.d Sat Jan 05 23:52:41 2008 +0100 @@ -10,8 +10,8 @@ import dil.ast.Statements; import dil.Token; import dil.Enums; -import dil.Scope; import dil.IdTable; +import dil.semantic.Scope; import dil.semantic.Analysis; import dil.semantic.Symbols; import dil.semantic.Types;
--- a/trunk/src/dil/ast/Expressions.d Sat Jan 05 23:47:06 2008 +0100 +++ b/trunk/src/dil/ast/Expressions.d Sat Jan 05 23:52:41 2008 +0100 @@ -10,7 +10,7 @@ import dil.ast.Statements; import dil.Token; import dil.Identifier; -import dil.Scope; +import dil.semantic.Scope; import dil.semantic.Types; import common;
--- a/trunk/src/dil/ast/Statements.d Sat Jan 05 23:47:06 2008 +0100 +++ b/trunk/src/dil/ast/Statements.d Sat Jan 05 23:52:41 2008 +0100 @@ -10,7 +10,7 @@ import dil.ast.Types; import dil.Token; import dil.IdTable; -import dil.Scope; +import dil.semantic.Scope; import dil.semantic.Analysis; abstract class Statement : Node
--- a/trunk/src/dil/ast/Types.d Sat Jan 05 23:47:06 2008 +0100 +++ b/trunk/src/dil/ast/Types.d Sat Jan 05 23:52:41 2008 +0100 @@ -9,7 +9,7 @@ import dil.ast.Expressions; import dil.Enums; import dil.Identifier; -import dil.Scope; +import dil.semantic.Scope; import dil.semantic.Types; class Parameter : Node
--- a/trunk/src/dil/semantic/Analysis.d Sat Jan 05 23:47:06 2008 +0100 +++ b/trunk/src/dil/semantic/Analysis.d Sat Jan 05 23:52:41 2008 +0100 @@ -7,7 +7,7 @@ import dil.ast.Node; import dil.ast.Expressions; import dil.Token; -import dil.Scope; +import dil.semantic.Scope; import dil.IdTable; import common;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/trunk/src/dil/semantic/Scope.d Sat Jan 05 23:52:41 2008 +0100 @@ -0,0 +1,122 @@ +/++ + Author: Aziz Köksal + License: GPL3 ++/ +module dil.semantic.Scope; + +import dil.semantic.Symbol; +import dil.semantic.Symbols; +import dil.Information; +import dil.Messages; +import dil.Token; +import common; + +class Scope +{ + Scope parent; /// The surrounding scope. + InfoManager infoMan; /// Collects errors reported during the semantic phase. + + ScopeSymbol symbol; /// The current symbol with the symbol table. + + this() + { + } + + /++ + Find an identifier in this scope. + +/ + Symbol find(char[] ident) + { + return null; + } + + /++ + Add a symbol to this scope. + +/ + void add(Symbol sym) + { + + } + + /// Insert a new variable symbol into this scope. + void insert(Variable var) + { + auto sym = symbol.lookup(var.ident); + if (sym) + { + auto loc = sym.node.begin.getLocation(); + auto locString = Format("{}({},{})", loc.filePath, loc.lineNum, loc.colNum); + error(var.node.begin, MSG.VariableConflictsWithDecl, var.ident.str, locString); + } + else + symbol.insert(var, var.ident); + // Set the current scope symbol as the parent. + var.parent = symbol; + } + + /++ + Create a new inner scope. + +/ + Scope push(ScopeSymbol symbol) + { + auto sc = new Scope(); + sc.parent = this; + sc.infoMan = this.infoMan; + sc.symbol = symbol; + return sc; + } + + /++ + Destroy this scope and return the outer scope. + +/ + Scope pop() + { + auto sc = parent; + // delete this; + return sc; + } + + bool isInterface() + { + return symbol.isInterface; + } + + /// Search for the enclosing Class scope. + Scope classScope() + { + auto scop = this; + while (scop) + { + if (scop.symbol.isClass) + return scop; + scop = scop.parent; + } + return null; + } + + /// Search for the enclosing Module scope. + Scope moduleScope() + { + auto scop = this; + while (scop) + { + if (scop.symbol.isModule) + return scop; + scop = scop.parent; + } + return null; + } + + void error(Token* token, MID mid) + { + auto location = token.getLocation(); + infoMan ~= new SemanticError(location, GetMsg(mid)); + } + + void error(Token* token, char[] formatMsg, ...) + { + auto location = token.getLocation(); + auto msg = Format(_arguments, _argptr, formatMsg); + infoMan ~= new SemanticError(location, msg); + } +}