diff trunk/src/dil/semantic/Scope.d @ 611:6d449e777f5d

Added semantic code to insert symbols into the scope.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Sun, 06 Jan 2008 22:58:49 +0100
parents 39fac5531b85
children f15b054bb27e
line wrap: on
line diff
--- a/trunk/src/dil/semantic/Scope.d	Sun Jan 06 21:07:37 2008 +0100
+++ b/trunk/src/dil/semantic/Scope.d	Sun Jan 06 22:58:49 2008 +0100
@@ -7,6 +7,7 @@
 import dil.semantic.Symbol;
 import dil.semantic.Symbols;
 import dil.lexer.Token;
+import dil.lexer.Identifier;
 import dil.Information;
 import dil.Messages;
 import common;
@@ -30,12 +31,20 @@
     return null;
   }
 
-  /++
-    Add a symbol to this scope.
-  +/
-  void add(Symbol sym)
+  /// Insert a symbol into this scope.
+  void insert(Symbol sym, Identifier* ident)
   {
-
+    auto sym2 = symbol.lookup(ident);
+    if (sym2)
+    {
+      auto loc = sym2.node.begin.getLocation();
+      auto locString = Format("{}({},{})", loc.filePath, loc.lineNum, loc.colNum);
+      error(sym.node.begin, MSG.DeclConflictsWithDecl, ident.str, locString);
+    }
+    else
+      symbol.insert(sym, ident);
+    // Set the current scope symbol as the parent.
+    sym.parent = symbol;
   }
 
   /// Insert a new variable symbol into this scope.