1.1 --- a/simplify/simplified/data.py Sat Jun 16 01:57:38 2007 +0200
1.2 +++ b/simplify/simplified/data.py Sun Jun 17 22:05:04 2007 +0200
1.3 @@ -37,6 +37,32 @@
1.4 def full_name(self):
1.5 return "class %s" % self._full_name
1.6
1.7 + def get_instance_attribute_names(self):
1.8 +
1.9 + "Return all attribute names used by the instances of this class."
1.10 +
1.11 + names = set()
1.12 + for instance in self.instances.values():
1.13 + for name in instance.namespace.keys():
1.14 + names.add(name)
1.15 + return names
1.16 +
1.17 + def get_names_to_instances(self):
1.18 +
1.19 + """
1.20 + Return a tuple containing a mapping from names to instances, and a list
1.21 + of sorted instance names.
1.22 + """
1.23 +
1.24 + d = {}
1.25 + names = []
1.26 + for instance in self.instances.values():
1.27 + name = instance.full_name()
1.28 + names.append(name)
1.29 + d[name] = instance
1.30 + names.sort()
1.31 + return d, names
1.32 +
1.33 class SingleInstanceClass(_Class):
1.34
1.35 "A Python class."
1.36 @@ -72,7 +98,7 @@
1.37 self.attributes_for_instances = {}
1.38
1.39 def _get_key(self, node):
1.40 - return id(getattr(node, "original", None)) # self.module.original
1.41 + return getattr(node, "original", None) # self.module.original
1.42
1.43 def has_instance(self, node):
1.44 return self.instances.has_key(self._get_key(node))
1.45 @@ -117,7 +143,7 @@
1.46
1.47 def _get_key(self, node):
1.48 if self.namespace.has_key("__atomic__"):
1.49 - return id(self)
1.50 + return self
1.51 else:
1.52 return MultipleInstanceClass._get_key(self, node)
1.53
1.54 @@ -138,9 +164,9 @@
1.55
1.56 def _get_key(self, node):
1.57 if self.namespace.has_key("__atomic__"):
1.58 - return id(self)
1.59 + return self
1.60 else:
1.61 - return id(node)
1.62 + return node
1.63
1.64 def has_instance(self, node):
1.65 requesting_instance = getattr(node, "instance", None)
1.66 @@ -174,14 +200,6 @@
1.67 else:
1.68 raise ValueError, "__class__"
1.69
1.70 - def __eq__(self, other):
1.71 - # NOTE: Single instance: all instances are the same
1.72 - # NOTE: Multiple instances: all instances are different
1.73 - return self.full_name() == other.full_name()
1.74 -
1.75 - def __hash__(self):
1.76 - return id(self)
1.77 -
1.78 class Constant:
1.79
1.80 "A constant initialised with a type name for future processing."
1.81 @@ -202,12 +220,12 @@
1.82 self.context = context
1.83 self.type = type
1.84
1.85 + def __repr__(self):
1.86 + return "Attribute(%s, %s)" % (repr(self.context), repr(self.type))
1.87 +
1.88 def __eq__(self, other):
1.89 return hasattr(other, "type") and other.type == self.type or other == self.type
1.90
1.91 - def __repr__(self):
1.92 - return "Attribute(%s, %s)" % (repr(self.context), repr(self.type))
1.93 -
1.94 def __hash__(self):
1.95 return id(self.type)
1.96