1.1 --- a/simplify/annotate.py Sat Jun 16 01:57:38 2007 +0200
1.2 +++ b/simplify/annotate.py Sun Jun 17 22:05:04 2007 +0200
1.3 @@ -1436,6 +1436,9 @@
1.4 def has_key(self, name):
1.5 return self.names.has_key(name)
1.6
1.7 + def keys(self):
1.8 + return self.names.keys()
1.9 +
1.10 def items(self):
1.11 return self.names.items()
1.12
2.1 --- a/simplify/simplified/data.py Sat Jun 16 01:57:38 2007 +0200
2.2 +++ b/simplify/simplified/data.py Sun Jun 17 22:05:04 2007 +0200
2.3 @@ -37,6 +37,32 @@
2.4 def full_name(self):
2.5 return "class %s" % self._full_name
2.6
2.7 + def get_instance_attribute_names(self):
2.8 +
2.9 + "Return all attribute names used by the instances of this class."
2.10 +
2.11 + names = set()
2.12 + for instance in self.instances.values():
2.13 + for name in instance.namespace.keys():
2.14 + names.add(name)
2.15 + return names
2.16 +
2.17 + def get_names_to_instances(self):
2.18 +
2.19 + """
2.20 + Return a tuple containing a mapping from names to instances, and a list
2.21 + of sorted instance names.
2.22 + """
2.23 +
2.24 + d = {}
2.25 + names = []
2.26 + for instance in self.instances.values():
2.27 + name = instance.full_name()
2.28 + names.append(name)
2.29 + d[name] = instance
2.30 + names.sort()
2.31 + return d, names
2.32 +
2.33 class SingleInstanceClass(_Class):
2.34
2.35 "A Python class."
2.36 @@ -72,7 +98,7 @@
2.37 self.attributes_for_instances = {}
2.38
2.39 def _get_key(self, node):
2.40 - return id(getattr(node, "original", None)) # self.module.original
2.41 + return getattr(node, "original", None) # self.module.original
2.42
2.43 def has_instance(self, node):
2.44 return self.instances.has_key(self._get_key(node))
2.45 @@ -117,7 +143,7 @@
2.46
2.47 def _get_key(self, node):
2.48 if self.namespace.has_key("__atomic__"):
2.49 - return id(self)
2.50 + return self
2.51 else:
2.52 return MultipleInstanceClass._get_key(self, node)
2.53
2.54 @@ -138,9 +164,9 @@
2.55
2.56 def _get_key(self, node):
2.57 if self.namespace.has_key("__atomic__"):
2.58 - return id(self)
2.59 + return self
2.60 else:
2.61 - return id(node)
2.62 + return node
2.63
2.64 def has_instance(self, node):
2.65 requesting_instance = getattr(node, "instance", None)
2.66 @@ -174,14 +200,6 @@
2.67 else:
2.68 raise ValueError, "__class__"
2.69
2.70 - def __eq__(self, other):
2.71 - # NOTE: Single instance: all instances are the same
2.72 - # NOTE: Multiple instances: all instances are different
2.73 - return self.full_name() == other.full_name()
2.74 -
2.75 - def __hash__(self):
2.76 - return id(self)
2.77 -
2.78 class Constant:
2.79
2.80 "A constant initialised with a type name for future processing."
2.81 @@ -202,12 +220,12 @@
2.82 self.context = context
2.83 self.type = type
2.84
2.85 + def __repr__(self):
2.86 + return "Attribute(%s, %s)" % (repr(self.context), repr(self.type))
2.87 +
2.88 def __eq__(self, other):
2.89 return hasattr(other, "type") and other.type == self.type or other == self.type
2.90
2.91 - def __repr__(self):
2.92 - return "Attribute(%s, %s)" % (repr(self.context), repr(self.type))
2.93 -
2.94 def __hash__(self):
2.95 return id(self.type)
2.96
3.1 --- a/simplify/simplified/program.py Sat Jun 16 01:57:38 2007 +0200
3.2 +++ b/simplify/simplified/program.py Sun Jun 17 22:05:04 2007 +0200
3.3 @@ -95,6 +95,9 @@
3.4 self.types = set()
3.5 self.annotated = 0
3.6
3.7 + def __hash__(self):
3.8 + return id(self)
3.9 +
3.10 def __repr__(self):
3.11
3.12 "Return a readable representation."
4.1 --- a/simplify/viewer.py Sat Jun 16 01:57:38 2007 +0200
4.2 +++ b/simplify/viewer.py Sun Jun 17 22:05:04 2007 +0200
4.3 @@ -197,7 +197,7 @@
4.4
4.5 def _write_classes(self, module):
4.6 self.stream.write("<table cellspacing='5' cellpadding='5'>\n")
4.7 - for structure in self.structures:
4.8 + for structure in self.module.simplifier.structures:
4.9 self._write_class(structure)
4.10 self.stream.write("</table>\n")
4.11
4.12 @@ -214,7 +214,8 @@
4.13
4.14 # ...and all known attribute names.
4.15
4.16 - structure_attributes = self.structure_attributes[structure]
4.17 + structure_attributes = structure.get_instance_attribute_names()
4.18 +
4.19 for name in self.attribute_names:
4.20 if name in structure_attributes:
4.21 self.stream.write("<th class='summary-attr'>%s</th>\n" % self._text(name))
4.22 @@ -224,9 +225,12 @@
4.23
4.24 # Write instances for the class, along with type details for each attribute.
4.25
4.26 - for instance in self.structures_to_instances[structure]:
4.27 + names_to_instances, instance_names = structure.get_names_to_instances()
4.28 +
4.29 + for instance_name in instance_names:
4.30 + instance = names_to_instances[instance_name]
4.31 self.stream.write("<tr>\n")
4.32 - self.stream.write("<th class='summary-instance'>%s</th>\n" % self._text(instance.full_name()))
4.33 + self.stream.write("<th class='summary-instance'>%s</th>\n" % self._text(instance_name))
4.34 for name in self.attribute_names:
4.35 self.stream.write("<td>\n")
4.36 values = instance.namespace.get(name, [])
4.37 @@ -240,50 +244,15 @@
4.38
4.39 def _init_details(self):
4.40 names = set()
4.41 - self.structures_to_instances = {}
4.42 - self.structure_attributes = {}
4.43 - names_to_structures = {}
4.44
4.45 # Visit all structures.
4.46
4.47 for structure in self.module.simplifier.structures:
4.48 -
4.49 - # Map all instance names to instances.
4.50 -
4.51 - names_to_instances = {}
4.52 - attribute_names = set()
4.53 -
4.54 - for instance in structure.instances.values():
4.55 - for name, values in instance.namespace.items():
4.56 - if not name in attribute_names:
4.57 - attribute_names.add(name)
4.58 - if not name in names:
4.59 - names.add(name)
4.60 - names_to_instances[instance.full_name()] = instance
4.61 -
4.62 - # Record the instances in name order for the structure.
4.63 -
4.64 - instance_names = names_to_instances.keys()
4.65 - instance_names.sort()
4.66 - sorted_instances = [names_to_instances[name] for name in instance_names]
4.67 - self.structures_to_instances[structure] = sorted_instances
4.68 -
4.69 - # Record the attributes used in all instances of the structure.
4.70 -
4.71 - self.structure_attributes[structure] = attribute_names
4.72 -
4.73 - # Record the name to structure mapping.
4.74 -
4.75 - names_to_structures[structure.full_name()] = structure
4.76 + names.update(structure.get_instance_attribute_names())
4.77
4.78 self.attribute_names = list(names)
4.79 self.attribute_names.sort()
4.80
4.81 - structure_names = names_to_structures.keys()
4.82 - structure_names.sort()
4.83 -
4.84 - self.structures = [names_to_structures[name] for name in structure_names]
4.85 -
4.86 # Browser classes.
4.87
4.88 class Browser(ASTVisitor, Writer):