blob: 533497d88691e71bdea5f5cca2801bc9059cb008 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
class Scope(object):
__shared_state = {}
__current_function = None
__functions = {}
def __init__(self):
self.__dict__ = self.__shared_state
def new(self, name, symbols = []):
if getattr(self.__functions, name, None):
raise ScopeError("multiple definitions of %s" % name)
self.__functions[name] = []
self.__current_function = name
self.add(symbols)
def add(self, symbols):
if type(symbols) != type([]):
symbols = [symbols]
for symbol in symbols:
if symbol not in self.__functions[self.__current_function]:
self.__functions[self.__current_function].append(symbol)
def contains(self, name):
return name in self.__functions[self.__current_function]
def __str__(self):
return "<Scope: %s>" % str(self.__functions)
|