1.1 --- a/simplify/generator.py Tue Sep 04 01:06:47 2007 +0200
1.2 +++ b/simplify/generator.py Thu Sep 06 01:18:26 2007 +0200
1.3 @@ -193,6 +193,41 @@
1.4
1.5 # Convenience functions.
1.6
1.7 +def get_attribute_table(importer):
1.8 +
1.9 + """
1.10 + Return an attribute table for all structures known to the given 'importer'.
1.11 + """
1.12 +
1.13 + master_table = {}
1.14 + for module in importer.get_modules():
1.15 + for structure in module.simplifier.structures:
1.16 + classname = structure.fully_qualified_name()
1.17 + master_table[classname] = []
1.18 +
1.19 + # NOTE: Assume enquiries of class attribute items produce the same
1.20 + # NOTE: ordering every time.
1.21 +
1.22 + positions = {}
1.23 + for name, (defining_cls, defs) in structure.get_visible_class_attributes().items():
1.24 + first = 1
1.25 + for attr in defs:
1.26 + if not first:
1.27 + print "Ambiguous attribute '%s' in '%s'." % (name, classname)
1.28 + break
1.29 + if not positions.has_key(defining_cls):
1.30 + positions[defining_cls] = 1
1.31 + master_table[classname].append((name, ("A", defining_cls.fully_qualified_name(), positions[defining_cls])))
1.32 + positions[defining_cls] += 1
1.33 + first = 0
1.34 +
1.35 + i = 1
1.36 + for name in structure.get_instance_attribute_names():
1.37 + master_table[classname].append((name, ("A", "I", i)))
1.38 + i += 1
1.39 +
1.40 + return master_table
1.41 +
1.42 def generate(module):
1.43 generator = Generator()
1.44 generator.process(module)
2.1 --- a/simplify/simplified/data.py Tue Sep 04 01:06:47 2007 +0200
2.2 +++ b/simplify/simplified/data.py Thu Sep 06 01:18:26 2007 +0200
2.3 @@ -44,6 +44,24 @@
2.4
2.5 # Utility methods.
2.6
2.7 + def get_visible_class_attributes(self):
2.8 +
2.9 + "Return a dictionary of visible class attributes."
2.10 +
2.11 + reverse_base_refs = self.base_refs
2.12 + reverse_base_refs.reverse()
2.13 +
2.14 + attributes = {}
2.15 +
2.16 + for base_defs in reverse_base_refs:
2.17 + for base_def in base_defs:
2.18 + attributes.update(base_def.type.get_visible_class_attributes())
2.19 +
2.20 + for name, defs in self.namespace.items():
2.21 + attributes[name] = self, defs
2.22 +
2.23 + return attributes
2.24 +
2.25 def get_instance_attribute_names(self):
2.26
2.27 "Return all attribute names used by the instances of this class."
3.1 --- a/simplify/simplified/utils.py Tue Sep 04 01:06:47 2007 +0200
3.2 +++ b/simplify/simplified/utils.py Thu Sep 06 01:18:26 2007 +0200
3.3 @@ -129,6 +129,20 @@
3.4
3.5 return self._full_name
3.6
3.7 + def fully_qualified_name(self):
3.8 +
3.9 + """
3.10 + Return a fully-qualified name including module and structure components.
3.11 + """
3.12 +
3.13 + module = self.module.name
3.14 + name = self.name
3.15 + if hasattr(self, "structures"):
3.16 + structures = [x.name for x in self.structures]
3.17 + else:
3.18 + structures = []
3.19 + return ".".join([module] + structures + [name])
3.20 +
3.21 # Comparable nodes based on naming.
3.22
3.23 class Comparable:
4.1 --- a/simplify/viewer.py Tue Sep 04 01:06:47 2007 +0200
4.2 +++ b/simplify/viewer.py Thu Sep 06 01:18:26 2007 +0200
4.3 @@ -1161,9 +1161,7 @@
4.4 for invocation in invocations:
4.5 fn = getattr(invocation, "copy_of", invocation).full_name()
4.6 module = invocation.module.name
4.7 - name = invocation.name
4.8 - structures = [x.name for x in invocation.structures]
4.9 - qualified_name = ".".join([module] + structures + [name])
4.10 + qualified_name = invocation.fully_qualified_name()
4.11
4.12 # Record the label and the link texts.
4.13
5.1 --- a/test.py Tue Sep 04 01:06:47 2007 +0200
5.2 +++ b/test.py Thu Sep 06 01:18:26 2007 +0200
5.3 @@ -29,5 +29,7 @@
5.4 if "-g" in sys.argv:
5.5 code = simplify.generator.generate(module)
5.6 code.dump()
5.7 + if "-t" in sys.argv:
5.8 + master_table = simplify.generator.get_attribute_table(importer)
5.9
5.10 # vim: tabstop=4 expandtab shiftwidth=4