1.1 --- a/transresults.py Wed Mar 08 14:54:06 2017 +0100
1.2 +++ b/transresults.py Thu Mar 09 21:55:38 2017 +0100
1.3 @@ -21,7 +21,7 @@
1.4
1.5 from common import first, InstructionSequence
1.6 from encoders import encode_instructions, encode_literal_constant, encode_path
1.7 -from results import ConstantValueRef, InstanceRef, LiteralSequenceRef, \
1.8 +from results import ConstantValueRef, InstanceRef, LiteralSequenceRef, NameRef, \
1.9 ResolvedNameRef, Result
1.10
1.11 # Classes representing intermediate translation results.
1.12 @@ -70,6 +70,9 @@
1.13 def access_location(self):
1.14 return self.location
1.15
1.16 + def access_locations(self):
1.17 + return self.location and [self.location]
1.18 +
1.19 def __str__(self):
1.20
1.21 "Return an output representation of the referenced name."
1.22 @@ -94,7 +97,7 @@
1.23
1.24 # Eliminate assignments between constants.
1.25
1.26 - if ref and isinstance(self.expr, ResolvedNameRef) and self.expr.static():
1.27 + if ref and self.expr.static():
1.28 return ""
1.29
1.30 # Qualified names must be converted into parent-relative assignments.
1.31 @@ -176,6 +179,9 @@
1.32 def access_location(self):
1.33 return self.location
1.34
1.35 + def access_locations(self):
1.36 + return self.location and [self.location]
1.37 +
1.38 def context(self):
1.39 return self.context_identity
1.40
1.41 @@ -199,6 +205,62 @@
1.42 def __repr__(self):
1.43 return "AttrResult(%r, %r, %r)" % (self.instructions, self.refs, self.location)
1.44
1.45 +class AliasResult(NameRef, Result):
1.46 +
1.47 + "An alias for other values."
1.48 +
1.49 + def __init__(self, name_ref, refs, locations):
1.50 + NameRef.__init__(self, name_ref.name, is_global=name_ref.is_global_name())
1.51 + self.name_ref = name_ref
1.52 + self.refs = refs
1.53 + self.locations = locations
1.54 +
1.55 + def references(self):
1.56 + ref = self.name_ref.reference()
1.57 + return self.refs or ref and [ref] or None
1.58 +
1.59 + def reference(self):
1.60 + refs = self.references()
1.61 + return len(refs) == 1 and first(refs) or None
1.62 +
1.63 + def access_location(self):
1.64 + return len(self.locations) == 1 and first(self.locations) or None
1.65 +
1.66 + def access_locations(self):
1.67 + return self.locations
1.68 +
1.69 + def get_name(self):
1.70 + ref = self.reference()
1.71 + return ref and ref.get_name()
1.72 +
1.73 + def get_origin(self):
1.74 + ref = self.reference()
1.75 + return ref and ref.get_origin()
1.76 +
1.77 + def static(self):
1.78 + ref = self.reference()
1.79 + return ref and ref.static()
1.80 +
1.81 + def final(self):
1.82 + ref = self.reference()
1.83 + return ref and ref.final()
1.84 +
1.85 + def has_kind(self, kinds):
1.86 + if not self.refs:
1.87 + return self.name_ref.has_kind(kinds)
1.88 +
1.89 + for ref in self.refs:
1.90 + if ref.has_kind(kinds):
1.91 + return True
1.92 +
1.93 + return False
1.94 +
1.95 + def __str__(self):
1.96 + return str(self.name_ref)
1.97 +
1.98 + def __repr__(self):
1.99 + return "AliasResult(%r, %r)" % (self.name_ref, self.refs)
1.100 +
1.101 class InvocationResult(Result, InstructionSequence):
1.102
1.103 "A translation result for an invocation."