diff trunk/src/dil/Scope.d @ 560:709e223a8eb9

Added code related to symbols. Added class ScopeSymbol. Module inherits from ScopeSymbol now. Added methods classScope() and moduleScope(), and member symbol to class Scope. Added enum SYM. Added member sid to class Symbol. Aggregate and Function inherit from ScopeSymbol now. Added Error to struct Types.
author Aziz K?ksal <aziz.koeksal@gmail.com>
date Wed, 26 Dec 2007 14:17:01 +0100
parents 50e64bab9c7a
children b0533550d64c
line wrap: on
line diff
--- a/trunk/src/dil/Scope.d	Mon Dec 24 20:39:14 2007 +0100
+++ b/trunk/src/dil/Scope.d	Wed Dec 26 14:17:01 2007 +0100
@@ -3,8 +3,12 @@
   License: GPL3
 +/
 module dil.Scope;
+
 import dil.Symbol;
+import dil.Symbols;
 import dil.Information;
+import dil.Messages;
+import dil.Token;
 import common;
 
 class Scope
@@ -12,6 +16,8 @@
   Scope parent; /// The surrounding scope.
   InfoManager infoMan; /// Collects errors reported during the semantic phase.
 
+  ScopeSymbol symbol; /// The current symbol with the symbol table.
+
   this()
   {
   }
@@ -52,9 +58,32 @@
     return sc;
   }
 
-  import dil.Information;
-  import dil.Messages;
-  import dil.Token;
+  /// Search for the enclosing Class scope.
+  Scope classScope()
+  {
+    auto scop = this;
+    while (scop)
+    {
+      if (scop.symbol.sid == SYM.Class)
+        return scop;
+      scop = scop.parent;
+    }
+    return null;
+  }
+
+  /// Search for the enclosing Module scope.
+  Scope moduleScope()
+  {
+    auto scop = this;
+    while (scop)
+    {
+      if (scop.symbol.sid == SYM.Module)
+        return scop;
+      scop = scop.parent;
+    }
+    return null;
+  }
+
   void error(Token* token, MID mid)
   {
     auto location = token.getLocation();