# HG changeset patch # User Paul Boddie # Date 1189034306 -7200 # Node ID 504dc5d62374c34d7e06eae49ecb11fae8d0534e # Parent 0eb7bcd2b354b29f2683c0fbf86db70069f33d86 Added a fully-qualified name method for WithName-derived classes, producing a more usable global name for applications such as the viewer. Added a method for returning "visible" class attributes to GeneralClass. Added an attribute table production function for integration with the explicit distribution, along with a test program option for generating such a table. diff -r 0eb7bcd2b354 -r 504dc5d62374 simplify/generator.py --- a/simplify/generator.py Tue Sep 04 01:06:47 2007 +0200 +++ b/simplify/generator.py Thu Sep 06 01:18:26 2007 +0200 @@ -193,6 +193,41 @@ # Convenience functions. +def get_attribute_table(importer): + + """ + Return an attribute table for all structures known to the given 'importer'. + """ + + master_table = {} + for module in importer.get_modules(): + for structure in module.simplifier.structures: + classname = structure.fully_qualified_name() + master_table[classname] = [] + + # NOTE: Assume enquiries of class attribute items produce the same + # NOTE: ordering every time. + + positions = {} + for name, (defining_cls, defs) in structure.get_visible_class_attributes().items(): + first = 1 + for attr in defs: + if not first: + print "Ambiguous attribute '%s' in '%s'." % (name, classname) + break + if not positions.has_key(defining_cls): + positions[defining_cls] = 1 + master_table[classname].append((name, ("A", defining_cls.fully_qualified_name(), positions[defining_cls]))) + positions[defining_cls] += 1 + first = 0 + + i = 1 + for name in structure.get_instance_attribute_names(): + master_table[classname].append((name, ("A", "I", i))) + i += 1 + + return master_table + def generate(module): generator = Generator() generator.process(module) diff -r 0eb7bcd2b354 -r 504dc5d62374 simplify/simplified/data.py --- a/simplify/simplified/data.py Tue Sep 04 01:06:47 2007 +0200 +++ b/simplify/simplified/data.py Thu Sep 06 01:18:26 2007 +0200 @@ -44,6 +44,24 @@ # Utility methods. + def get_visible_class_attributes(self): + + "Return a dictionary of visible class attributes." + + reverse_base_refs = self.base_refs + reverse_base_refs.reverse() + + attributes = {} + + for base_defs in reverse_base_refs: + for base_def in base_defs: + attributes.update(base_def.type.get_visible_class_attributes()) + + for name, defs in self.namespace.items(): + attributes[name] = self, defs + + return attributes + def get_instance_attribute_names(self): "Return all attribute names used by the instances of this class." diff -r 0eb7bcd2b354 -r 504dc5d62374 simplify/simplified/utils.py --- a/simplify/simplified/utils.py Tue Sep 04 01:06:47 2007 +0200 +++ b/simplify/simplified/utils.py Thu Sep 06 01:18:26 2007 +0200 @@ -129,6 +129,20 @@ return self._full_name + def fully_qualified_name(self): + + """ + Return a fully-qualified name including module and structure components. + """ + + module = self.module.name + name = self.name + if hasattr(self, "structures"): + structures = [x.name for x in self.structures] + else: + structures = [] + return ".".join([module] + structures + [name]) + # Comparable nodes based on naming. class Comparable: diff -r 0eb7bcd2b354 -r 504dc5d62374 simplify/viewer.py --- a/simplify/viewer.py Tue Sep 04 01:06:47 2007 +0200 +++ b/simplify/viewer.py Thu Sep 06 01:18:26 2007 +0200 @@ -1161,9 +1161,7 @@ for invocation in invocations: fn = getattr(invocation, "copy_of", invocation).full_name() module = invocation.module.name - name = invocation.name - structures = [x.name for x in invocation.structures] - qualified_name = ".".join([module] + structures + [name]) + qualified_name = invocation.fully_qualified_name() # Record the label and the link texts. diff -r 0eb7bcd2b354 -r 504dc5d62374 test.py --- a/test.py Tue Sep 04 01:06:47 2007 +0200 +++ b/test.py Thu Sep 06 01:18:26 2007 +0200 @@ -29,5 +29,7 @@ if "-g" in sys.argv: code = simplify.generator.generate(module) code.dump() + if "-t" in sys.argv: + master_table = simplify.generator.get_attribute_table(importer) # vim: tabstop=4 expandtab shiftwidth=4