diff python/c3/scope.py @ 164:e023d3ce1d63

Fix to loc of assignment
author Windel Bouwman
date Mon, 18 Mar 2013 22:15:57 +0100
parents 8104fc8b5e90
children 8b2e5f3cd579
line wrap: on
line diff
--- a/python/c3/scope.py	Mon Mar 18 20:13:57 2013 +0100
+++ b/python/c3/scope.py	Mon Mar 18 22:15:57 2013 +0100
@@ -6,7 +6,21 @@
       self.symbols = {}
       self.parent = parent
    def __iter__(self):
-      return iter(self.symbols.values())
+      # 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):
       if name in self.symbols:
          return self.symbols[name]
@@ -27,12 +41,14 @@
 intType = astnodes.BaseType('int')
 doubleType = astnodes.BaseType('double')
 voidType = astnodes.BaseType('void')
-boolType = astnodes.BaseType('void')
+boolType = astnodes.BaseType('bool')
+stringType = astnodes.BaseType('string')
+byteType = astnodes.BaseType('byte')
 
 def createBuiltins(scope):
    for tn in ['u64', 'u32', 'u16', 'u8']:
       scope.addSymbol(astnodes.BaseType(tn))
-   for t in [intType, doubleType, voidType, boolType]:
+   for t in [intType, doubleType, voidType, boolType, stringType, byteType]:
       scope.addSymbol(t)
 
 topScope = Scope()