1.1 --- a/annotate.py Sun Aug 13 22:23:54 2006 +0200
1.2 +++ b/annotate.py Sun Aug 20 01:11:17 2006 +0200
1.3 @@ -21,6 +21,21 @@
1.4 License along with this library; see the file LICENCE.txt
1.5 If not, write to the Free Software Foundation, Inc.,
1.6 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.7 +
1.8 +--------
1.9 +
1.10 +To annotate a module, first obtain an Annotator:
1.11 +
1.12 +annotator = Annotator()
1.13 +
1.14 +Then, process the Simplifier object which holds the details of the module:
1.15 +
1.16 +annotator.process(simplifier)
1.17 +
1.18 +If a module containing built-in classes and functions has already been
1.19 +annotated, such a module should be passed in as an additional argument:
1.20 +
1.21 +annotator.process(simplifier, builtins_simplifier)
1.22 """
1.23
1.24 from simplified import *
1.25 @@ -28,7 +43,11 @@
1.26
1.27 class System:
1.28
1.29 - "A class maintaining the state of the annotation system."
1.30 + """
1.31 + A class maintaining the state of the annotation system. When the system
1.32 + counter can no longer be incremented by any annotation operation, the
1.33 + system may be considered stable and fully annotated.
1.34 + """
1.35
1.36 def __init__(self):
1.37 self.count = 0
1.38 @@ -54,9 +73,21 @@
1.39 considered operation. Such types are also recorded on the nodes, and a
1.40 special "system" record is maintained to monitor the level of annotation
1.41 activity with a view to recognising when no more annotations are possible.
1.42 +
1.43 + Throughout the annotation activity, type information consists of lists of
1.44 + Attribute objects where such objects retain information about the context of
1.45 + the type (since a value in the program may be associated with an object or
1.46 + class) and the actual type of the value being manipulated. Upon accessing
1.47 + attribute information on namespaces, additional accessor information is also
1.48 + exchanged - this provides a means of distinguishing between the different
1.49 + types possible when the means of constructing the namespace may depend on
1.50 + run-time behaviour.
1.51 """
1.52
1.53 def __init__(self):
1.54 +
1.55 + "Initialise the visitor."
1.56 +
1.57 Visitor.__init__(self)
1.58 self.system = system
1.59
1.60 @@ -382,6 +413,8 @@
1.61 context = None
1.62 target = subprogram
1.63
1.64 + print target
1.65 +
1.66 # Provide the correct namespace for the invocation.
1.67
1.68 if getattr(invoke, "same_frame", 0):
1.69 @@ -486,10 +519,18 @@
1.70
1.71 """
1.72 A local namespace which may either relate to a genuine set of function
1.73 - locals or the initialisation of a structure.
1.74 + locals or the initialisation of a structure or module.
1.75 """
1.76
1.77 def __init__(self):
1.78 +
1.79 + """
1.80 + Initialise the namespace with a mapping of local names to possible
1.81 + types, a list of return values and of possible returned local
1.82 + namespaces. The namespace also tracks the "current" types and a mapping
1.83 + of temporary value names to types.
1.84 + """
1.85 +
1.86 self.names = {}
1.87 self.returns = []
1.88 self.return_locals = []
1.89 @@ -497,7 +538,6 @@
1.90 self.types = []
1.91
1.92 def set_types(self, types):
1.93 - print "Setting", types
1.94 self.types = types
1.95
1.96 def store(self, name, types):
1.97 @@ -578,7 +618,7 @@
1.98
1.99 if isinstance(structure, Instance):
1.100 for cls in structure.namespace.load("__class__"):
1.101 - l = find_attributes(cls, name)
1.102 + l = get_attributes(cls, name)
1.103 for attribute in l:
1.104 if attribute not in attributes:
1.105 attributes.append(attribute)
1.106 @@ -602,7 +642,7 @@
1.107 # class or its own base classes.
1.108
1.109 for base_ref in base_refs:
1.110 - l = find_attributes(base_ref, name)
1.111 + l = get_attributes(base_ref, name)
1.112 for attribute in l:
1.113 if attribute not in base_attributes:
1.114 base_attributes.append(attribute)