1.1 --- a/translator.py Thu Nov 24 23:42:19 2016 +0100
1.2 +++ b/translator.py Fri Nov 25 00:53:22 2016 +0100
1.3 @@ -55,7 +55,8 @@
1.4
1.5 "An abstract translation result mix-in."
1.6
1.7 - pass
1.8 + def get_accessor_kinds(self):
1.9 + return None
1.10
1.11 class ReturnRef(TranslationResult):
1.12
1.13 @@ -156,9 +157,10 @@
1.14
1.15 "A translation result for an attribute access."
1.16
1.17 - def __init__(self, s, refs):
1.18 + def __init__(self, s, refs, accessor_kinds):
1.19 Expression.__init__(self, s)
1.20 self.refs = refs
1.21 + self.accessor_kinds = accessor_kinds
1.22
1.23 def get_origin(self):
1.24 return self.refs and len(self.refs) == 1 and first(self.refs).get_origin()
1.25 @@ -171,6 +173,9 @@
1.26 return True
1.27 return False
1.28
1.29 + def get_accessor_kinds(self):
1.30 + return self.accessor_kinds
1.31 +
1.32 def __repr__(self):
1.33 return "AttrResult(%r, %r)" % (self.s, self.get_origin())
1.34
1.35 @@ -653,7 +658,7 @@
1.36 out = "(\n%s\n)" % ",\n".join(output)
1.37
1.38 del self.attrs[0]
1.39 - return AttrResult(out, refs)
1.40 + return AttrResult(out, refs, self.get_accessor_kinds(location))
1.41
1.42 def get_referenced_attributes(self, location):
1.43
1.44 @@ -668,6 +673,12 @@
1.45 refs.append(attr)
1.46 return refs
1.47
1.48 + def get_accessor_kinds(self, location):
1.49 +
1.50 + "Return the accessor kinds for 'location'."
1.51 +
1.52 + return self.optimiser.accessor_kinds[location]
1.53 +
1.54 def get_access_location(self, name):
1.55
1.56 """
1.57 @@ -869,12 +880,24 @@
1.58
1.59 elif objpath:
1.60 parameters = self.importer.function_parameters.get(objpath)
1.61 +
1.62 + # Class invocation involves instantiators.
1.63 +
1.64 if expr.has_kind("<class>"):
1.65 target = encode_instantiator_pointer(objpath)
1.66 target_structure = encode_initialiser_pointer(objpath)
1.67 +
1.68 + # Only plain functions and bound methods employ function pointers.
1.69 +
1.70 elif expr.has_kind("<function>"):
1.71 - target = encode_function_pointer(objpath)
1.72 - target_structure = encode_path(objpath)
1.73 +
1.74 + # Test for functions and methods.
1.75 +
1.76 + accessor_kinds = expr.get_accessor_kinds()
1.77 +
1.78 + if not self.is_method(objpath) or accessor_kinds and len(accessor_kinds) == 1 and first(accessor_kinds) == "<instance>":
1.79 + target = encode_function_pointer(objpath)
1.80 + target_structure = encode_path(objpath)
1.81
1.82 # Other targets are retrieved at run-time.
1.83