1.1 --- a/annotate.py Tue Jul 25 23:04:14 2006 +0200
1.2 +++ b/annotate.py Fri Jul 28 00:20:57 2006 +0200
1.3 @@ -46,63 +46,6 @@
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 - if structure is not None:
1.17 - self.local = "structure"
1.18 - else:
1.19 - self.local = "local"
1.20 - self.names = {}
1.21 - self.not_local = []
1.22 -
1.23 - def make_global(self, name):
1.24 - if name not in self.not_local:
1.25 - self.not_local.append(name)
1.26 -
1.27 - def find_for_store(self, name):
1.28 - if name not in self.not_local:
1.29 - return self.local
1.30 - else:
1.31 - return "global"
1.32 -
1.33 - def find_for_load(self, name):
1.34 - if name not in self.not_local and self.names.has_key(name):
1.35 - return self.local
1.36 - else:
1.37 - return "global"
1.38 -
1.39 - def store(self, name, types):
1.40 - if name not in self.not_local:
1.41 - self.names[name] = types
1.42 - else:
1.43 - raise KeyError, name
1.44 -
1.45 - def load(self, name):
1.46 - if name in self.not_local or not self.names.has_key(name):
1.47 - raise KeyError, name
1.48 - else:
1.49 - return self.names[name]
1.50 -
1.51 - def merge(self, namespace):
1.52 - self.merge_items(namespace.names.items())
1.53 -
1.54 - def merge_items(self, items):
1.55 - for name, types in items:
1.56 - if not self.names.has_key(name):
1.57 - self.names[name] = types
1.58 - else:
1.59 - existing = self.names[name]
1.60 - for type in types:
1.61 - if type not in existing:
1.62 - existing.append(type)
1.63 -
1.64 class Attribute:
1.65
1.66 """
1.67 @@ -221,27 +164,15 @@
1.68 return loadref
1.69
1.70 def visitLoadName(self, loadname):
1.71 - scope = self.namespace.find_for_load(loadname.name)
1.72 - if scope == "structure":
1.73 - result = self.dispatch(LoadAttr(expr=LoadRef(ref=self.namespace.structure), name=loadname.name))
1.74 - elif scope == "global":
1.75 - result = self.dispatch(LoadGlobal(name=loadname.name))
1.76 - else:
1.77 - self.types = self.namespace.load(loadname.name)
1.78 - result = loadname
1.79 - self.annotate(result)
1.80 + self.types = self.namespace.load(loadname.name)
1.81 + result = loadname
1.82 + self.annotate(result)
1.83 return result
1.84
1.85 def visitStoreName(self, storename):
1.86 - scope = self.namespace.find_for_store(storename.name)
1.87 - if scope == "structure":
1.88 - return self.dispatch(StoreAttr(lvalue=LoadRef(ref=self.namespace.structure), name=storename.name, expr=storename.expr))
1.89 - elif scope == "global":
1.90 - return self.dispatch(StoreGlobal(name=storename.name, expr=storename.expr))
1.91 - else:
1.92 - storename.expr = self.dispatch(storename.expr)
1.93 - self.namespace.store(storename.name, self.types)
1.94 - return storename
1.95 + storename.expr = self.dispatch(storename.expr)
1.96 + self.namespace.store(storename.name, self.types)
1.97 + return storename
1.98
1.99 def visitLoadGlobal(self, loadglobal):
1.100 self.types = self.global_namespace.load(loadglobal.name)