comparison python/ppci/c3/scope.py @ 307:e609d5296ee9

Massive rewrite of codegenerator
author Windel Bouwman
date Thu, 12 Dec 2013 20:42:56 +0100
parents b145f8e6050b
children 5477e499b039
comparison
equal deleted inserted replaced
306:b145f8e6050b 307:e609d5296ee9
1 from .astnodes import Constant, Variable, Function, BaseType 1 from .astnodes import Constant, Variable, Function, BaseType, Symbol
2 2
3 3
4 class Scope: 4 class Scope:
5 """ A scope contains all symbols in a scope. It also has a parent scope, 5 """ A scope contains all symbols in a scope. It also has a parent scope,
6 when looking for a symbol, also the parent scopes are checked. """ 6 when looking for a symbol, also the parent scopes are checked. """
52 def __contains__(self, name): 52 def __contains__(self, name):
53 return self.hasSymbol(name) 53 return self.hasSymbol(name)
54 54
55 def addSymbol(self, sym): 55 def addSymbol(self, sym):
56 assert sym.name not in self.symbols 56 assert sym.name not in self.symbols
57 assert isinstance(sym, Symbol)
57 self.symbols[sym.name] = sym 58 self.symbols[sym.name] = sym
58 59
59 def __repr__(self): 60 def __repr__(self):
60 return 'Scope with {} symbols'.format(len(self.symbols)) 61 return 'Scope with {} symbols'.format(len(self.symbols))
61 62