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)