1.1 --- a/simplify/fixinstances.py Mon Jun 18 01:47:51 2007 +0200
1.2 +++ b/simplify/fixinstances.py Tue Jun 19 01:37:10 2007 +0200
1.3 @@ -87,7 +87,14 @@
1.4 for specialised in subprogram.active():
1.5 self.subprograms.append(self.process_node(specialised))
1.6
1.7 - def process_node(self, node, namespace=None):
1.8 + # Visit structures and instances.
1.9 +
1.10 + for structure in self.module.simplifier.structures:
1.11 + for instance in structure.instances.values():
1.12 + for attrs in instance.namespace.values():
1.13 + self._replace(attrs)
1.14 +
1.15 + def process_node(self, node):
1.16
1.17 """
1.18 Process a subprogram or module 'node', discovering from attributes on
1.19 @@ -126,7 +133,7 @@
1.20 if hasattr(node, name):
1.21 attrs = getattr(node, name)
1.22 self._replace(attrs)
1.23 - for name in ("accesses", "writes"):
1.24 + for name in ("accesses", "writes", "paramtypes"):
1.25 if hasattr(node, name):
1.26 d = getattr(node, name)
1.27 for expr, attrs in d.items():
1.28 @@ -144,21 +151,40 @@
1.29 for attr in ("body", "else_", "handler", "finally_", "code", "choices", "nodes"):
1.30 if hasattr(node, attr):
1.31 self.dispatches(getattr(node, attr))
1.32 + if hasattr(node, "params"):
1.33 + for param, default in node.params:
1.34 + self.dispatch(default)
1.35 + for attr in ("star", "dstar"):
1.36 + if getattr(node, attr, None):
1.37 + param, default = getattr(node, attr)
1.38 + self.dispatch(default)
1.39
1.40 return node
1.41
1.42 - def _replace(self, attrs, name=None):
1.43 - to_replace = {}
1.44 - for attr in attrs:
1.45 + def _replace(self, items, name=None):
1.46 + to_replace = set()
1.47 + for item in items:
1.48 if name == "accesses":
1.49 - _attr, accessor = attr
1.50 - value = _attr.type
1.51 + attr, accessor = item
1.52 + value = attr.type
1.53 else:
1.54 + attr = item
1.55 value = attr.type
1.56 - if isinstance(value, Instance) and not to_replace.has_key(value):
1.57 + if isinstance(value, Instance):
1.58 distinct_instances = value.get_class().get_distinct_instances()
1.59 if distinct_instances.has_key(value):
1.60 - attr.type = distinct_instances[value]
1.61 + to_replace.add((item, distinct_instances[value]))
1.62 +
1.63 + for item, replacement in to_replace:
1.64 + items.remove(item)
1.65 +
1.66 + for item, replacement in to_replace:
1.67 + if name == "accesses":
1.68 + attr, accessor = item
1.69 + items.append((Attribute(attr.context, replacement), accessor))
1.70 + else:
1.71 + attr = item
1.72 + items.add(Attribute(attr.context, replacement))
1.73
1.74 def dispatch(self, node, *args):
1.75 return Visitor.dispatch(self, node, *args)
1.76 @@ -176,10 +202,7 @@
1.77 # The special case of internal subprogram invocation is addressed by
1.78 # propagating namespace information to the subprogram and processing it.
1.79
1.80 - if invoke.share_locals:
1.81 - subprogram = self.process_node(invoke.ref, self.namespace)
1.82 - else:
1.83 - subprogram = self.process_node(invoke.ref)
1.84 + subprogram = self.process_node(invoke.ref)
1.85
1.86 if subprogram is not None:
1.87 self.subprograms.append(subprogram)