Lichen

Changeset

959:0ec288e54b7a
2021-11-14 Paul Boddie raw files shortlog changelog graph Moved various resolved name details into the instance initialiser.
transresults.py (file)
     1.1 --- a/transresults.py	Sun Nov 14 00:31:50 2021 +0100
     1.2 +++ b/transresults.py	Sun Nov 14 00:37:02 2021 +0100
     1.3 @@ -67,6 +67,20 @@
     1.4          ResolvedNameRef.__init__(self, name, ref, expr, is_global)
     1.5          self.location = location
     1.6  
     1.7 +        # For sources, any identified static origin will be constant and thus
     1.8 +        # usable directly. For targets, no constant should be assigned and thus
     1.9 +        # the alias (or any plain name) will be used.
    1.10 +
    1.11 +        self.static_ref = self.static()
    1.12 +        origin = self.static_ref and self.get_origin()
    1.13 +        self.static_name = origin and encode_path(origin)
    1.14 +
    1.15 +        # Determine whether a qualified name is involved.
    1.16 +
    1.17 +        t = (not self.is_constant_alias() and self.get_name() or self.name).rsplit(".", 1)
    1.18 +        self.parent = len(t) > 1 and t[0] or None
    1.19 +        self.attrname = t[-1] and encode_path(t[-1])
    1.20 +
    1.21      def access_location(self):
    1.22          return self.location
    1.23  
    1.24 @@ -82,55 +96,41 @@
    1.25              else:
    1.26                  return encode_path(self.name)
    1.27  
    1.28 -        # For sources, any identified static origin will be constant and thus
    1.29 -        # usable directly. For targets, no constant should be assigned and thus
    1.30 -        # the alias (or any plain name) will be used.
    1.31 -
    1.32 -        ref = self.static()
    1.33 -        origin = ref and self.get_origin()
    1.34 -        static_name = origin and encode_path(origin)
    1.35 -
    1.36 -        # Determine whether a qualified name is involved.
    1.37 -
    1.38 -        t = (not self.is_constant_alias() and self.get_name() or self.name).rsplit(".", 1)
    1.39 -        parent = len(t) > 1 and t[0] or None
    1.40 -        attrname = t[-1] and encode_path(t[-1])
    1.41 -
    1.42          # Assignments.
    1.43  
    1.44          if self.expr:
    1.45  
    1.46              # Eliminate assignments between constants.
    1.47  
    1.48 -            if ref and self.expr.static():
    1.49 +            if self.static_ref and self.expr.static():
    1.50                  return ""
    1.51  
    1.52              # Qualified names must be converted into parent-relative assignments.
    1.53  
    1.54 -            elif parent:
    1.55 +            elif self.parent:
    1.56                  return "__store_via_object(&%s, %s, %s)" % (
    1.57 -                    encode_path(parent), attrname, self.expr)
    1.58 +                    encode_path(self.parent), self.attrname, self.expr)
    1.59  
    1.60              # All other assignments involve the names as they were given.
    1.61  
    1.62              else:
    1.63 -                return "%s = %s" % (attrname, self.expr)
    1.64 +                return "%s = %s" % (self.attrname, self.expr)
    1.65  
    1.66          # Expressions.
    1.67  
    1.68 -        elif static_name:
    1.69 -            return "__ATTRVALUE(&%s)" % static_name
    1.70 +        elif self.static_name:
    1.71 +            return "__ATTRVALUE(&%s)" % self.static_name
    1.72  
    1.73          # Qualified names must be converted into parent-relative accesses.
    1.74  
    1.75 -        elif parent:
    1.76 +        elif self.parent:
    1.77              return "__load_via_object(&%s, %s)" % (
    1.78 -                encode_path(parent), attrname)
    1.79 +                encode_path(self.parent), self.attrname)
    1.80  
    1.81          # All other accesses involve the names as they were given.
    1.82  
    1.83          else:
    1.84 -            return "(%s)" % attrname
    1.85 +            return "(%s)" % self.attrname
    1.86  
    1.87  class TrConstantValueRef(ConstantValueRef):
    1.88