1.1 --- a/annotate.py Mon Aug 21 00:54:44 2006 +0200
1.2 +++ b/annotate.py Mon Aug 21 00:55:12 2006 +0200
1.3 @@ -369,22 +369,42 @@
1.4 # Inspect each attribute and extract the subprogram.
1.5
1.6 for attribute, accessor in attributes:
1.7 - if attribute is None:
1.8 - print "Invocation type is None"
1.9 - continue
1.10 -
1.11 - subprogram = attribute.type
1.12 -
1.13 - # If a subprogram is defined, invoke it.
1.14 -
1.15 - self.invoke_subprogram(invoke, subprogram)
1.16 - invocations[callable] = subprogram
1.17
1.18 # If a class is involved, presume that it must create a new
1.19 # object.
1.20
1.21 if isinstance(attr.type, Class):
1.22 - self.namespace.set_types([Attribute(None, attribute.context)])
1.23 +
1.24 + # Instantiate the class.
1.25 + # NOTE: Should probably only allocate a single instance.
1.26 +
1.27 + instance = Instance()
1.28 + instance.namespace = Namespace()
1.29 + instance.namespace.store("__class__", [attr.type])
1.30 + instance = Attribute(None, instance)
1.31 +
1.32 + # For instantiations, switch the context.
1.33 +
1.34 + if attribute is not None:
1.35 + attribute = Attribute(instance, attribute.type)
1.36 +
1.37 + # Skip cases where no callable is found.
1.38 +
1.39 + if attribute is not None:
1.40 +
1.41 + # If a subprogram is defined, invoke it.
1.42 +
1.43 + self.invoke_subprogram(invoke, attribute)
1.44 + invocations[callable] = attribute.type
1.45 +
1.46 + else:
1.47 + print "Invocation type is None"
1.48 +
1.49 + if isinstance(attr.type, Class):
1.50 +
1.51 + # Associate the instance with the result of this invocation.
1.52 +
1.53 + self.namespace.set_types([instance])
1.54 self.annotate(invoke)
1.55
1.56 invoke.invocations = invocations
1.57 @@ -413,7 +433,7 @@
1.58 context = None
1.59 target = subprogram
1.60
1.61 - print target
1.62 + print subprogram, "->", context, target
1.63
1.64 # Provide the correct namespace for the invocation.
1.65
1.66 @@ -426,11 +446,11 @@
1.67
1.68 # Process the subprogram.
1.69
1.70 - self.process_node(subprogram, namespace)
1.71 + self.process_node(target, namespace)
1.72
1.73 # NOTE: Improve and verify this.
1.74
1.75 - if getattr(subprogram, "returns_value", 0):
1.76 + if getattr(target, "returns_value", 0):
1.77 self.namespace.set_types(self.last_returns)
1.78 self.annotate(invoke)
1.79
1.80 @@ -450,7 +470,7 @@
1.81 """
1.82
1.83 if context is not None:
1.84 - args = [context] + invocation.args
1.85 + args = [Self(context)] + invocation.args
1.86 else:
1.87 args = invocation.args
1.88
1.89 @@ -590,6 +610,10 @@
1.90 def __repr__(self):
1.91 return "Attribute of type %s (context %s)" % (self.type, self.context)
1.92
1.93 +class Self:
1.94 + def __init__(self, attribute):
1.95 + self.types = [attribute]
1.96 +
1.97 def find_attributes(structure, name):
1.98
1.99 """
1.100 @@ -664,6 +688,12 @@
1.101
1.102 if isinstance(structure, Attribute):
1.103 structure = structure.type
1.104 - return find_attributes(structure, name)
1.105 + results = []
1.106 + for attribute, accessor in find_attributes(structure, name):
1.107 + if attribute is not None and isinstance(structure, Structure):
1.108 + results.append((Attribute(structure, attribute.type), accessor))
1.109 + else:
1.110 + results.append((attribute, accessor))
1.111 + return results
1.112
1.113 # vim: tabstop=4 expandtab shiftwidth=4