-
Notifications
You must be signed in to change notification settings - Fork 0
/
pats-ls
executable file
·102 lines (81 loc) · 2.56 KB
/
pats-ls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
""" Listing of source file declarations. """
import sys
import os
from postiats import declarations
from postiats import images
from postiats import locations
def perror(message):
""" Shorthand to print to `stderr`. """
print(message, file=sys.stderr)
def error(message):
""" `perror` and `sys.exit(1)`. """
perror(message)
sys.exit(1)
def print_loc(loc):
""" Shorthand to parse and print formated loc. """
loc = locations.parse(loc)
loc = locations.ide_formated(loc)
print(loc)
HR1 = "========================="
HR2 = "-------------------------"
LABEL1 = " Name: %s"
LABEL2 = " Sort: %s"
LABEL3 = " Type: %s"
LABEL4 = " Sorts are: %s"
LABEL5 = " Construct: %s"
def dump(path):
""" Dump declarations. """
print(HR1)
print(os.path.relpath(path))
print(HR2)
first = True
if declarations.BASE_SORTS:
print("Base sorts defined or used:")
for name in sorted(declarations.BASE_SORTS):
print(" " + name)
first = False
if declarations.STATIC_CONSTANTS:
if not first:
print(HR2)
print("Static constants defined or used:")
for name in sorted(declarations.STATIC_CONSTANTS.keys()):
sort = declarations.STATIC_CONSTANTS[name]
print(" " + name + ": " + images.sort_image(sort))
first = False
for value in declarations.DECLARATIONS:
if not first:
print(HR2)
first = False
print_loc(value.loc)
print(LABEL1 % value.name)
if value.sort:
print(LABEL2 % images.sort_image(value.sort))
if value.type:
print(LABEL3 % images.type_image(value.type))
print(LABEL4 % images.type_sorts_image(value.type))
print(LABEL5 % (" ".join(value.construct)))
def main():
""" Main. """
my_name = os.path.split(sys.argv[0])[1]
recursive = False
if len(sys.argv) >= 2 and sys.argv[1] == "-r":
recursive = True
del sys.argv[1]
if len(sys.argv) != 2:
error("Usage: %s [-r] file-name." % my_name)
path = sys.argv[1]
declarations.handle_source_file(path)
dump(path)
if recursive:
done = set()
done.add(path)
to_be_done = declarations.STALOADED.difference(done)
while to_be_done:
path = sorted(to_be_done)[0]
declarations.handle_source_file(path)
dump(path)
done.add(path)
to_be_done.update(declarations.STALOADED.difference(done))
if __name__ == "__main__":
main()