1.1 --- a/transresults.py Wed Aug 30 01:49:28 2023 +0200
1.2 +++ b/transresults.py Fri Sep 01 22:46:09 2023 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Translation result abstractions.
1.6
1.7 -Copyright (C) 2016, 2017, 2018, 2023 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2016, 2017, 2018, 2021, 2023 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -68,6 +68,20 @@
1.13 ResolvedNameRef.__init__(self, name, ref, expr, is_global)
1.14 self.location = location
1.15
1.16 + # For sources, any identified static origin will be constant and thus
1.17 + # usable directly. For targets, no constant should be assigned and thus
1.18 + # the alias (or any plain name) will be used.
1.19 +
1.20 + self.static_ref = self.static()
1.21 + origin = self.static_ref and self.get_origin()
1.22 + self.static_name = origin and encode_path(origin)
1.23 +
1.24 + # Determine whether a qualified name is involved.
1.25 +
1.26 + t = (not self.is_constant_alias() and self.get_name() or self.name).rsplit(".", 1)
1.27 + self.parent = len(t) > 1 and t[0] or None
1.28 + self.attrname = t[-1] and encode_path(t[-1])
1.29 +
1.30 def access_location(self):
1.31 return self.location
1.32
1.33 @@ -83,58 +97,42 @@
1.34 else:
1.35 return encode_path(self.name)
1.36
1.37 - # For sources, any identified static origin will be constant and thus
1.38 - # usable directly. For targets, no constant should be assigned and thus
1.39 - # the alias (or any plain name) will be used.
1.40 -
1.41 - ref = self.static()
1.42 - origin = ref and self.get_origin()
1.43 - static_name = origin and encode_path(origin)
1.44 -
1.45 - # Determine whether a qualified name is involved.
1.46 -
1.47 - t = (not self.is_constant_alias() and self.get_name() or self.name).rsplit(".", 1)
1.48 - parent = len(t) > 1 and t[0] or None
1.49 - attrname = t[-1] and encode_path(t[-1])
1.50 -
1.51 # Assignments.
1.52
1.53 if self.expr:
1.54
1.55 # Eliminate assignments between constants.
1.56
1.57 - if ref and self.expr.static():
1.58 + if self.static_ref and self.expr.static():
1.59 return ""
1.60
1.61 # Qualified names must be converted into parent-relative assignments.
1.62
1.63 - elif parent:
1.64 + elif self.parent:
1.65 return "__store_via_object(&%s, %s, %s)" % (
1.66 - encode_path(parent), attrname, self.expr)
1.67 + encode_path(self.parent), self.attrname, self.expr)
1.68
1.69 # All other assignments involve the names as they were given.
1.70 # To support value replacement, a special operation is used.
1.71
1.72 else:
1.73 - return "__set_local(&%s, %s)" % (attrname, self.expr)
1.74 + return "__set_local(&%s, %s)" % (self.attrname, self.expr)
1.75
1.76 # Expressions.
1.77
1.78 - elif static_name:
1.79 - parent = ref.parent()
1.80 - context = ref.has_kind("<function>") and encode_path(parent) or None
1.81 - return "__ATTRVALUE(&%s)" % static_name
1.82 + elif self.static_name:
1.83 + return "__ATTRVALUE(&%s)" % self.static_name
1.84
1.85 # Qualified names must be converted into parent-relative accesses.
1.86
1.87 - elif parent:
1.88 + elif self.parent:
1.89 return "__load_via_object(&%s, %s)" % (
1.90 - encode_path(parent), attrname)
1.91 + encode_path(self.parent), self.attrname)
1.92
1.93 # All other accesses involve the names as they were given.
1.94
1.95 else:
1.96 - return "(%s)" % attrname
1.97 + return "(%s)" % self.attrname
1.98
1.99 class TrConstantValueRef(ConstantValueRef):
1.100