1.1 --- a/annotate.py Fri Jul 28 00:20:57 2006 +0200
1.2 +++ b/annotate.py Sun Jul 30 02:00:33 2006 +0200
1.3 @@ -46,6 +46,39 @@
1.4
1.5 # Namespaces and related abstractions.
1.6
1.7 +class Namespace:
1.8 +
1.9 + """
1.10 + A local namespace which may either relate to a genuine set of function
1.11 + locals or the initialisation of a structure.
1.12 + """
1.13 +
1.14 + def __init__(self, structure=None):
1.15 + self.structure = structure
1.16 + self.names = {}
1.17 +
1.18 + def store(self, name, types):
1.19 + self.names[name] = types
1.20 +
1.21 + def load(self, name):
1.22 + return self.names[name]
1.23 +
1.24 + def merge(self, name, types):
1.25 + if not self.names.has_key(name):
1.26 + self.names[name] = types
1.27 + else:
1.28 + existing = self.names[name]
1.29 + for type in types:
1.30 + if type not in existing:
1.31 + existing.append(type)
1.32 +
1.33 + def merge_namespace(self, namespace):
1.34 + self.merge_items(namespace.names.items())
1.35 +
1.36 + def merge_items(self, items):
1.37 + for name, types in items:
1.38 + self.merge(name, types)
1.39 +
1.40 class Attribute:
1.41
1.42 """
1.43 @@ -94,7 +127,7 @@
1.44
1.45 self.namespace = Namespace(structure=getattr(node, "structure", None))
1.46 if locals is not None:
1.47 - self.namespace.merge(locals)
1.48 + self.namespace.merge_namespace(locals)
1.49
1.50 # Determine the global namespace.
1.51
1.52 @@ -153,11 +186,6 @@
1.53 def dispatch(self, node, *args):
1.54 return Visitor.dispatch(self, node, *args)
1.55
1.56 - def visitGlobal(self, global_):
1.57 - for name in global_.names:
1.58 - self.namespace.make_global(name)
1.59 - return global_
1.60 -
1.61 def visitLoadRef(self, loadref):
1.62 self.types = [loadref.ref]
1.63 self.annotate(loadref)
1.64 @@ -181,10 +209,7 @@
1.65
1.66 def visitStoreGlobal(self, storeglobal):
1.67 storeglobal.expr = self.dispatch(storeglobal.expr)
1.68 -
1.69 - # NOTE: This may always be a merge operation.
1.70 -
1.71 - self.global_namespace.store(storeglobal.name, self.types)
1.72 + self.global_namespace.merge(storeglobal.name, self.types)
1.73 return storeglobal
1.74
1.75 def visitLoadTemp(self, loadtemp):