2.1 --- a/translator.py Tue Feb 07 23:37:40 2017 +0100
2.2 +++ b/translator.py Tue Feb 07 23:45:16 2017 +0100
2.3 @@ -67,8 +67,7 @@
2.4
2.5 "An abstract translation result mix-in."
2.6
2.7 - def get_accessor_kinds(self):
2.8 - return None
2.9 + pass
2.10
2.11 class ReturnRef(TranslationResult):
2.12
2.13 @@ -91,13 +90,13 @@
2.14
2.15 "A reference to a name in the translation."
2.16
2.17 - def __init__(self, name, ref, expr=None, parameter=None, unsuitable=None):
2.18 + def __init__(self, name, ref, expr=None, parameter=None, location=None):
2.19 results.ResolvedNameRef.__init__(self, name, ref, expr)
2.20 self.parameter = parameter
2.21 - self.unsuitable = unsuitable
2.22 -
2.23 - def unsuitable_invocations(self):
2.24 - return self.unsuitable
2.25 + self.location = location
2.26 +
2.27 + def access_location(self):
2.28 + return self.location
2.29
2.30 def __str__(self):
2.31
2.32 @@ -193,17 +192,16 @@
2.33
2.34 "A translation result for an attribute access."
2.35
2.36 - def __init__(self, instructions, refs, accessor_kinds, unsuitable):
2.37 + def __init__(self, instructions, refs, location):
2.38 InstructionSequence.__init__(self, instructions)
2.39 self.refs = refs
2.40 - self.accessor_kinds = accessor_kinds
2.41 - self.unsuitable = unsuitable
2.42 + self.location = location
2.43
2.44 def references(self):
2.45 return self.refs
2.46
2.47 - def unsuitable_invocations(self):
2.48 - return self.unsuitable
2.49 + def access_location(self):
2.50 + return self.location
2.51
2.52 def get_origin(self):
2.53 return self.refs and len(self.refs) == 1 and first(self.refs).get_origin()
2.54 @@ -216,14 +214,11 @@
2.55 return True
2.56 return False
2.57
2.58 - def get_accessor_kinds(self):
2.59 - return self.accessor_kinds
2.60 -
2.61 def __str__(self):
2.62 return encode_instructions(self.instructions)
2.63
2.64 def __repr__(self):
2.65 - return "AttrResult(%r, %r, %r)" % (self.instructions, self.refs, self.accessor_kinds)
2.66 + return "AttrResult(%r, %r, %r)" % (self.instructions, self.refs, self.location)
2.67
2.68 class InvocationResult(Expression, TranslationResult, InstructionSequence):
2.69
2.70 @@ -734,7 +729,6 @@
2.71
2.72 location = self.get_access_location(name, self.attrs)
2.73 refs = self.get_referenced_attributes(location)
2.74 - unsuitable = self.get_referenced_attribute_invocations(location)
2.75
2.76 # Generate access instructions.
2.77
2.78 @@ -777,7 +771,7 @@
2.79 self.record_temp(temp_subs[sub])
2.80
2.81 del self.attrs[0]
2.82 - return AttrResult(output, refs, self.get_accessor_kinds(location), unsuitable)
2.83 + return AttrResult(output, refs, location)
2.84
2.85 def get_referenced_attributes(self, location):
2.86
2.87 @@ -806,7 +800,7 @@
2.88
2.89 "Return the accessor kinds for 'location'."
2.90
2.91 - return self.optimiser.accessor_kinds[location]
2.92 + return self.optimiser.accessor_kinds.get(location)
2.93
2.94 def get_access_location(self, name, attrnames=None):
2.95
2.96 @@ -1153,6 +1147,7 @@
2.97
2.98 expr = self.process_structure_node(n.node)
2.99 objpath = expr.get_origin()
2.100 + location = expr.access_location()
2.101
2.102 # Identified target details.
2.103
2.104 @@ -1204,7 +1199,7 @@
2.105 # Test for functions and methods.
2.106
2.107 context_required = self.is_method(objpath)
2.108 - accessor_kinds = expr.get_accessor_kinds()
2.109 + accessor_kinds = self.get_accessor_kinds(location)
2.110 instance_accessor = accessor_kinds and \
2.111 len(accessor_kinds) == 1 and \
2.112 first(accessor_kinds) == "<instance>"
2.113 @@ -1222,7 +1217,7 @@
2.114 # Other targets are retrieved at run-time.
2.115
2.116 else:
2.117 - unsuitable = expr.unsuitable_invocations()
2.118 + unsuitable = self.get_referenced_attribute_invocations(location)
2.119
2.120 if unsuitable:
2.121 for ref in unsuitable:
2.122 @@ -1511,13 +1506,12 @@
2.123 # Find any invocation details.
2.124
2.125 location = self.get_access_location(n.name)
2.126 - unsuitable = self.get_referenced_attribute_invocations(location)
2.127
2.128 # Qualified names are used for resolved static references or for
2.129 # static namespace members. The reference should be configured to return
2.130 # such names.
2.131
2.132 - return TrResolvedNameRef(n.name, ref, expr=expr, parameter=parameter, unsuitable=unsuitable)
2.133 + return TrResolvedNameRef(n.name, ref, expr=expr, parameter=parameter, location=location)
2.134
2.135 def process_not_node(self, n):
2.136