Skip to content

Commit 70d51bc

Browse files
committed
Implemented expand.py
1 parent f264623 commit 70d51bc

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

expand.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/python3
2+
3+
import sys
4+
import getopt
5+
6+
7+
def output_file(filename, output_comment, output_test):
8+
global src_path
9+
10+
res = []
11+
with open(src_path+filename+'.rs', 'r') as f:
12+
res.append('mod {}{{'.format(filename))
13+
14+
for line in f:
15+
res.append(line.rstrip())
16+
17+
res.append('}')
18+
return res
19+
20+
21+
opt_list = ['output-comment', 'output-test', ]
22+
output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc',
23+
'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue')
24+
dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit,modint',), 'math': ('internal_math',), 'modint': (
25+
'internal_math', 'internal_type_traits'), 'fenwicktree': ('internal_type_traits',), 'twosat': ('internal_scc',), 'scc': ('internal_scc',), 'maxflow': ('internal_queue',)}
26+
src_path = 'src/'
27+
28+
try:
29+
opts, args = getopt.getopt(sys.argv[1:], 'tc', opt_list)
30+
except getopt.GetoptError as e:
31+
print(e)
32+
sys.exit(2)
33+
34+
# unimplemented
35+
output_comment = False
36+
output_test = False
37+
38+
for o, v in opts:
39+
if o == '--output-comment' or o == '-c':
40+
output_comment = True
41+
if o == '--output-test' or o == '-t':
42+
output_test = True
43+
44+
output_list = set()
45+
46+
while len(args) != 0:
47+
pop = args.pop()
48+
if not pop in output_list_all:
49+
print('invalid args:{}'.format(pop))
50+
sys.exit(2)
51+
output_list.add(pop)
52+
if pop in dependency_list:
53+
for d in dependency_list[pop]:
54+
args.append(d)
55+
56+
output_list = list(output_list)
57+
output_list.sort()
58+
59+
output_data = []
60+
for i in output_list:
61+
buf = output_file(i, output_comment, output_test)
62+
output_data.extend(buf)
63+
64+
for i in output_list:
65+
if not i.startswith('internal'):
66+
output_data.append('use {}::*;'.format(i))
67+
68+
for i in output_data:
69+
print(i)

0 commit comments

Comments
 (0)