diff python/c3/scope.py @ 217:8b2e5f3cd579

Removed some stale python source files
author Windel Bouwman
date Fri, 05 Jul 2013 14:13:59 +0200
parents e023d3ce1d63
children 521567d17388
line wrap: on
line diff
--- a/python/c3/scope.py	Fri Jul 05 13:26:51 2013 +0200
+++ b/python/c3/scope.py	Fri Jul 05 14:13:59 2013 +0200
@@ -1,42 +1,53 @@
 from . import astnodes
 
 class Scope:
-   """ A scope contains all symbols in a scope """
-   def __init__(self, parent=None):
-      self.symbols = {}
-      self.parent = parent
-   def __iter__(self):
+    """ A scope contains all symbols in a scope """
+    def __init__(self, parent=None):
+        self.symbols = {}
+        self.parent = parent
+
+    def __iter__(self):
       # Iterate in a deterministic manner:
       return iter(self.Constants + self.Variables + self.Functions)
-   @property
-   def Syms(self):
-      syms = self.symbols.values()
-      return sorted(syms, key=lambda v: v.name)
-   @property
-   def Constants(self):
-      return [s for s in self.Syms if type(s) is astnodes.Constant]
-   @property
-   def Variables(self):
-      return [s for s in self.Syms if type(s) is astnodes.Variable]
-   @property
-   def Functions(self):
-      return [s for s in self.Syms if type(s) is astnodes.Function]
-   def getSymbol(self, name):
+
+    @property
+    def Syms(self):
+        syms = self.symbols.values()
+        return sorted(syms, key=lambda v: v.name)
+
+    @property
+    def Constants(self):
+        return [s for s in self.Syms if type(s) is astnodes.Constant]
+
+    @property
+    def Variables(self):
+        return [s for s in self.Syms if type(s) is astnodes.Variable]
+
+    @property
+    def Functions(self):
+        return [s for s in self.Syms if type(s) is astnodes.Function]
+
+    def getSymbol(self, name):
       if name in self.symbols:
          return self.symbols[name]
       # Look for symbol:
       if self.parent:
          return self.parent.getSymbol(name)
       raise CompilerException("Symbol {0} not found".format(name), name.loc)
-   def hasSymbol(self, name):
+
+    def hasSymbol(self, name):
       if name in self.symbols:
          return True
       if self.parent:
          return self.parent.hasSymbol(name)
       return False
-   def addSymbol(self, sym):
+
+    def addSymbol(self, sym):
       self.symbols[sym.name] = sym
 
+    def __repr__(self):
+        return 'Scope with {} symbols'.format(len(self.symbols))
+
 # buildin types:
 intType = astnodes.BaseType('int')
 doubleType = astnodes.BaseType('double')