1.1 --- a/encoders.py Sun Jun 24 18:47:03 2018 +0200
1.2 +++ b/encoders.py Mon Jun 25 14:27:00 2018 +0200
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Encoder functions, producing representations of program objects.
1.6
1.7 -Copyright (C) 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2016, 2017, 2018 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 @@ -87,6 +87,26 @@
1.13 t.access_number is not None and ":#%d" % t.access_number or "",
1.14 invocation and "!" or "")
1.15
1.16 +def decode_alias_location(s):
1.17 +
1.18 + "Decode the alias location 's'."
1.19 +
1.20 + path, name, rest = s.split(":", 2)
1.21 + attrnames = version = access_number = None
1.22 + invocation = rest.endswith("!")
1.23 +
1.24 + t = rest.rstrip("!").split(":#")
1.25 + if len(t) > 1:
1.26 + rest = t[0]; access_number = int(t[1])
1.27 +
1.28 + t = rest.split(":=")
1.29 + if len(t) > 1:
1.30 + attrnames = t[0]; version = int(t[1])
1.31 + else:
1.32 + attrnames = rest
1.33 +
1.34 + return path, name, attrnames, version, access_number, invocation
1.35 +
1.36 def encode_location(t):
1.37
1.38 "Encode the general location 't' in a concise form."
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/tools/showalias.py Mon Jun 25 14:27:00 2018 +0200
2.3 @@ -0,0 +1,53 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +from os.path import abspath, split
2.7 +import sys
2.8 +
2.9 +# Find the modules.
2.10 +
2.11 +try:
2.12 + import encoders
2.13 +except ImportError:
2.14 + parent = abspath(split(split(__file__)[0])[0])
2.15 + if split(parent)[1] == "Lichen":
2.16 + sys.path.append(parent)
2.17 +
2.18 +from encoders import decode_alias_location
2.19 +
2.20 +if len(sys.argv) < 3:
2.21 + print >>sys.stderr, "Usage: %s <filename> <alias>" % sys.argv[0]
2.22 + sys.exit(1)
2.23 +
2.24 +filename = sys.argv[1]
2.25 +alias = sys.argv[2]
2.26 +
2.27 +f = open(filename)
2.28 +try:
2.29 + for line in f.xreadlines():
2.30 + columns = line.rstrip().split(" ")
2.31 + if not columns[0].startswith(alias):
2.32 + continue
2.33 +
2.34 + first = True
2.35 +
2.36 + for column in columns:
2.37 + location = decode_alias_location(column.rstrip(","))
2.38 + path, name, attrnames, version, access_number, invocation = location
2.39 +
2.40 + print first and "Alias:" or "Path:", path
2.41 + print "Name:", name
2.42 + print "Attribute names:", attrnames
2.43 + print "Version:", version is None and "{}" or version
2.44 + print "Access number:", access_number is None and "{}" or access_number
2.45 + print "Invocation:", invocation and "true" or "false"
2.46 + print
2.47 +
2.48 + first = False
2.49 +
2.50 + print "----"
2.51 + print
2.52 +
2.53 +finally:
2.54 + f.close()
2.55 +
2.56 +# vim: tabstop=4 expandtab shiftwidth=4
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tools/showplan.py Mon Jun 25 14:27:00 2018 +0200
3.3 @@ -0,0 +1,42 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +import sys
3.7 +
3.8 +if len(sys.argv) < 3:
3.9 + print >>sys.stderr, "Usage: %s <filename> <access>" % sys.argv[0]
3.10 + sys.exit(1)
3.11 +
3.12 +filename = sys.argv[1]
3.13 +access = sys.argv[2]
3.14 +
3.15 +f = open(filename)
3.16 +try:
3.17 + for line in f.xreadlines():
3.18 + columns = line.rstrip().split()
3.19 + if not columns[0].startswith(access):
3.20 + continue
3.21 +
3.22 + location, name, test, test_type, base, traversed, traversal_modes, \
3.23 + attrnames, context, context_test, first_method, final_method, attr, \
3.24 + accessor_kinds = columns
3.25 +
3.26 + print "Location:", location
3.27 + print "Name:", name
3.28 + print "Test:", test
3.29 + print "Test type:", test_type
3.30 + print "Base:", base
3.31 + print "Traversed:", traversed
3.32 + print "Traversal modes:", traversal_modes
3.33 + print "Attribute names:", attrnames
3.34 + print "Context:", context
3.35 + print "Context test:", context_test
3.36 + print "First method:", first_method
3.37 + print "Final method:", final_method
3.38 + print "Origin/attribute:", attr
3.39 + print "Accessor kinds:", accessor_kinds
3.40 + print
3.41 +
3.42 +finally:
3.43 + f.close()
3.44 +
3.45 +# vim: tabstop=4 expandtab shiftwidth=4