2.1 --- a/simplify/fixinstances.py Mon Jun 18 01:47:51 2007 +0200
2.2 +++ b/simplify/fixinstances.py Tue Jun 19 01:37:10 2007 +0200
2.3 @@ -87,7 +87,14 @@
2.4 for specialised in subprogram.active():
2.5 self.subprograms.append(self.process_node(specialised))
2.6
2.7 - def process_node(self, node, namespace=None):
2.8 + # Visit structures and instances.
2.9 +
2.10 + for structure in self.module.simplifier.structures:
2.11 + for instance in structure.instances.values():
2.12 + for attrs in instance.namespace.values():
2.13 + self._replace(attrs)
2.14 +
2.15 + def process_node(self, node):
2.16
2.17 """
2.18 Process a subprogram or module 'node', discovering from attributes on
2.19 @@ -126,7 +133,7 @@
2.20 if hasattr(node, name):
2.21 attrs = getattr(node, name)
2.22 self._replace(attrs)
2.23 - for name in ("accesses", "writes"):
2.24 + for name in ("accesses", "writes", "paramtypes"):
2.25 if hasattr(node, name):
2.26 d = getattr(node, name)
2.27 for expr, attrs in d.items():
2.28 @@ -144,21 +151,40 @@
2.29 for attr in ("body", "else_", "handler", "finally_", "code", "choices", "nodes"):
2.30 if hasattr(node, attr):
2.31 self.dispatches(getattr(node, attr))
2.32 + if hasattr(node, "params"):
2.33 + for param, default in node.params:
2.34 + self.dispatch(default)
2.35 + for attr in ("star", "dstar"):
2.36 + if getattr(node, attr, None):
2.37 + param, default = getattr(node, attr)
2.38 + self.dispatch(default)
2.39
2.40 return node
2.41
2.42 - def _replace(self, attrs, name=None):
2.43 - to_replace = {}
2.44 - for attr in attrs:
2.45 + def _replace(self, items, name=None):
2.46 + to_replace = set()
2.47 + for item in items:
2.48 if name == "accesses":
2.49 - _attr, accessor = attr
2.50 - value = _attr.type
2.51 + attr, accessor = item
2.52 + value = attr.type
2.53 else:
2.54 + attr = item
2.55 value = attr.type
2.56 - if isinstance(value, Instance) and not to_replace.has_key(value):
2.57 + if isinstance(value, Instance):
2.58 distinct_instances = value.get_class().get_distinct_instances()
2.59 if distinct_instances.has_key(value):
2.60 - attr.type = distinct_instances[value]
2.61 + to_replace.add((item, distinct_instances[value]))
2.62 +
2.63 + for item, replacement in to_replace:
2.64 + items.remove(item)
2.65 +
2.66 + for item, replacement in to_replace:
2.67 + if name == "accesses":
2.68 + attr, accessor = item
2.69 + items.append((Attribute(attr.context, replacement), accessor))
2.70 + else:
2.71 + attr = item
2.72 + items.add(Attribute(attr.context, replacement))
2.73
2.74 def dispatch(self, node, *args):
2.75 return Visitor.dispatch(self, node, *args)
2.76 @@ -176,10 +202,7 @@
2.77 # The special case of internal subprogram invocation is addressed by
2.78 # propagating namespace information to the subprogram and processing it.
2.79
2.80 - if invoke.share_locals:
2.81 - subprogram = self.process_node(invoke.ref, self.namespace)
2.82 - else:
2.83 - subprogram = self.process_node(invoke.ref)
2.84 + subprogram = self.process_node(invoke.ref)
2.85
2.86 if subprogram is not None:
2.87 self.subprograms.append(subprogram)
3.1 --- a/simplify/simplified/data.py Mon Jun 18 01:47:51 2007 +0200
3.2 +++ b/simplify/simplified/data.py Tue Jun 19 01:37:10 2007 +0200
3.3 @@ -99,6 +99,7 @@
3.4 except ValueError:
3.5 names_found.append(names)
3.6 instances_found.append(instance)
3.7 + instances[instance] = instance
3.8
3.9 return instances
3.10
3.11 @@ -263,9 +264,9 @@
3.12 return "Attribute(%s, %s)" % (repr(self.context), repr(self.type))
3.13
3.14 def __eq__(self, other):
3.15 - return hasattr(other, "type") and other.type == self.type or other == self.type
3.16 + return hasattr(other, "type") and other.type == self.type
3.17
3.18 def __hash__(self):
3.19 - return id(self.type)
3.20 + return hash(self.type)
3.21
3.22 # vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/test.py Mon Jun 18 01:47:51 2007 +0200
4.2 +++ b/test.py Tue Jun 19 01:37:10 2007 +0200
4.3 @@ -28,6 +28,7 @@
4.4 else:
4.5 if "-i" in sys.argv:
4.6 simplify.fixinstances.fix(module)
4.7 + simplify.fixinstances.fix(builtins)
4.8 if "-d" in sys.argv:
4.9 simplify.viewer.makedocs(module, importer.modules.values(), builtins, distinct=("-i" in sys.argv))
4.10