# HG changeset patch # User paulb@localhost.localdomain # Date 1185836724 -7200 # Node ID aa73f702c9a6143e8d222cbb9844f28948f75eff # Parent aa1175e4af84b14502c799558fd332c38886c11b Changed the invocations annotation to be a set, and added fixing of the contents of such sets. Added a specialisations method to Subprogram, producing only subprograms related to distinct instances. diff -r aa1175e4af84 -r aa73f702c9a6 simplify/annotate.py --- a/simplify/annotate.py Mon Jul 30 00:35:54 2007 +0200 +++ b/simplify/annotate.py Tue Jul 31 01:05:24 2007 +0200 @@ -461,7 +461,7 @@ # the target may be a class or object, and there may be many different # related subprograms. - invocations = [] + invocations = set() # Visit each callable in turn, finding subprograms. @@ -516,8 +516,7 @@ # If a subprogram is defined, invoke it. self.invoke_subprogram(invoke, attribute) - if attribute.type not in invocations: - invocations.append(attribute.type) + invocations.add(attribute.type) elif not isinstance(attr.type, GeneralClass): print "Invocation type is None for", accessor diff -r aa1175e4af84 -r aa73f702c9a6 simplify/fixinstances.py --- a/simplify/fixinstances.py Mon Jul 30 00:35:54 2007 +0200 +++ b/simplify/fixinstances.py Tue Jul 31 01:05:24 2007 +0200 @@ -146,10 +146,10 @@ # Process annotations. - for name in ("non_accesses", "non_writes", "raises", "returns", "types"): + for name in ("non_accesses", "non_writes", "raises", "returns", "types", "invocations"): if hasattr(node, name): attrs = getattr(node, name) - setattr(node, name, self._replace(attrs)) + setattr(node, name, self._replace(attrs, name)) for name in ("accesses", "writes", "paramtypes"): if hasattr(node, name): d = getattr(node, name) @@ -199,6 +199,8 @@ attr, accessor = item value = attr.type new_items.append((Attribute(self._get_replacement(attr.context), self._get_replacement(value)), self._get_replacement(accessor))) + elif name == "invocations": + new_items.add(self._get_replacement(item)) else: attr = item value = attr.type diff -r aa1175e4af84 -r aa73f702c9a6 simplify/simplified/program.py --- a/simplify/simplified/program.py Mon Jul 30 00:35:54 2007 +0200 +++ b/simplify/simplified/program.py Tue Jul 31 01:05:24 2007 +0200 @@ -499,4 +499,25 @@ self.paramtypes = {} self.namespace = Namespace() # NOTE: Temporary. + def specialisations(self): + + "Return the active specialisations using only distinct instances." + + distinct_instances = {} + + subprograms = set() + for instance, subprogram in self.copies.items() or [(None, self)]: + if instance is None: + subprograms.add(subprogram) + continue + + cls = instance.get_class() + if not distinct_instances.has_key(cls): + distinct_instances[cls] = cls.get_distinct_instances() + distinct_instance = distinct_instances[cls][instance] + if instance is distinct_instance: + subprograms.add(subprogram) + + return subprograms + # vim: tabstop=4 expandtab shiftwidth=4 diff -r aa1175e4af84 -r aa73f702c9a6 simplify/viewer.py --- a/simplify/viewer.py Mon Jul 30 00:35:54 2007 +0200 +++ b/simplify/viewer.py Tue Jul 31 01:05:24 2007 +0200 @@ -1150,10 +1150,10 @@ return self._invocations(_node.active()) def _invocations(self, nodes): - invocations = [] + invocations = set() for node in nodes: if hasattr(node, "invocations"): - invocations += node.invocations + invocations.update(node.invocations) # Record each link, avoiding duplicates.