1.1 --- a/fixnames.py Fri Jul 28 00:20:57 2006 +0200
1.2 +++ b/fixnames.py Sun Jul 30 02:00:33 2006 +0200
1.3 @@ -98,7 +98,7 @@
1.4 value = getattr(node, attr, None)
1.5 if value is not None:
1.6 setattr(node, attr, self.dispatch(value))
1.7 - for attr in ("body", "else_", "finally_", "code"):
1.8 + for attr in ("body", "else_", "finally_", "code", "choices"):
1.9 value = getattr(node, attr, None)
1.10 if value is not None:
1.11 setattr(node, attr, self.dispatches(value))
1.12 @@ -133,4 +133,48 @@
1.13 self.namespace.store(storename.name)
1.14 return storename
1.15
1.16 +class Namespace:
1.17 +
1.18 + """
1.19 + A local namespace which may either relate to a genuine set of function
1.20 + locals or the initialisation of a structure.
1.21 + """
1.22 +
1.23 + def __init__(self, structure=None):
1.24 + self.structure = structure
1.25 + if structure is not None:
1.26 + self.local = "structure"
1.27 + else:
1.28 + self.local = "local"
1.29 + self.names = {}
1.30 + self.not_local = []
1.31 +
1.32 + def make_global(self, name):
1.33 + if name not in self.not_local:
1.34 + self.not_local.append(name)
1.35 +
1.36 + def find_for_store(self, name):
1.37 + if name not in self.not_local:
1.38 + return self.local
1.39 + else:
1.40 + return "global"
1.41 +
1.42 + def find_for_load(self, name):
1.43 + if name not in self.not_local and self.names.has_key(name):
1.44 + return self.local
1.45 + else:
1.46 + return "global"
1.47 +
1.48 + def store(self, name, types=None):
1.49 + if name not in self.not_local:
1.50 + self.names[name] = types
1.51 + else:
1.52 + raise KeyError, name
1.53 +
1.54 + def load(self, name):
1.55 + if name in self.not_local or not self.names.has_key(name):
1.56 + raise KeyError, name
1.57 + else:
1.58 + return self.names[name]
1.59 +
1.60 # vim: tabstop=4 expandtab shiftwidth=4