1.1 --- a/common.py Thu Mar 30 18:48:36 2017 +0200
1.2 +++ b/common.py Thu Mar 30 19:41:24 2017 +0200
1.3 @@ -907,6 +907,62 @@
1.4
1.5 return names, count
1.6
1.7 +# Location classes.
1.8 +
1.9 +class Location:
1.10 +
1.11 + "A generic program location."
1.12 +
1.13 + def __init__(self, path, name, attrnames=None, version=None, access_number=None):
1.14 + self.path = path
1.15 + self.name = name
1.16 + self.attrnames = attrnames
1.17 + self.version = version
1.18 + self.access_number = access_number
1.19 +
1.20 + def __repr__(self):
1.21 + return "Location(%r, %r, %r, %r, %r)" % self.as_tuple()
1.22 +
1.23 + def as_tuple(self):
1.24 + return (self.path, self.name, self.attrnames, self.version, self.access_number)
1.25 +
1.26 + def __hash__(self):
1.27 + return hash(self.as_tuple())
1.28 +
1.29 + def __eq__(self, other):
1.30 + return self.as_tuple() == other.as_tuple()
1.31 +
1.32 + def __cmp__(self, other):
1.33 + return cmp(self.as_tuple(), other.as_tuple())
1.34 +
1.35 + def get_attrname(self):
1.36 +
1.37 + """
1.38 + Extract the first attribute from the attribute names employed in this
1.39 + location.
1.40 + """
1.41 +
1.42 + attrnames = self.attrnames
1.43 + if not attrnames:
1.44 + return attrnames
1.45 + return get_attrnames(attrnames)[0]
1.46 +
1.47 +class AccessLocation(Location):
1.48 +
1.49 + "A specialised access location."
1.50 +
1.51 + def __init__(self, path, name, attrnames, access_number):
1.52 +
1.53 + """
1.54 + Initialise an access location featuring 'path', 'name', 'attrnames' and
1.55 + 'access_number'.
1.56 + """
1.57 +
1.58 + Location.__init__(self, path, name, attrnames, None, access_number)
1.59 +
1.60 + def __repr__(self):
1.61 + return "AccessLocation(%r, %r, %r, %r)" % (self.path, self.name, self.attrnames, self.access_number)
1.62 +
1.63 # Result classes.
1.64
1.65 class InstructionSequence:
1.66 @@ -1405,18 +1461,6 @@
1.67 else:
1.68 return attrnames.split(".")
1.69
1.70 -def get_attrname_from_location(location):
1.71 -
1.72 - """
1.73 - Extract the first attribute from the attribute names employed in a
1.74 - 'location'.
1.75 - """
1.76 -
1.77 - path, name, attrnames, access = location
1.78 - if not attrnames:
1.79 - return attrnames
1.80 - return get_attrnames(attrnames)[0]
1.81 -
1.82 def get_name_path(path, name):
1.83
1.84 "Return a suitable qualified name from the given 'path' and 'name'."