-
Notifications
You must be signed in to change notification settings - Fork 30
Implement code expander #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
70d51bc
Implemented expand.py
manta1130 c1ce090
Changed the order of codes.
manta1130 2f36d26
Implemented option(output_comment,output_test)
manta1130 c1ca28e
Added comments
manta1130 21d6f5d
Added usage
manta1130 ddc4dfb
Added output header
manta1130 839e3d7
Fixed dependency list
manta1130 deda790
Add tests for expand.py
manta1130 ac05f13
Fixed help
manta1130 e9e290b
Removed some options.
manta1130 2e036ca
Added -a --all options
manta1130 83783b3
Changed if start with no args,it shows usage.
manta1130 d8a8147
Changed the test code
manta1130 eee7f85
Added the process of rustfmt
manta1130 ee9defa
Added rustfmt install command
manta1130 47bd974
show error message
manta1130 9760ead
Formatted codes
manta1130 d6ed636
Added EOL
manta1130 c3cbe59
Change the process if rustfmt returns error
manta1130 7363691
Change the test environment construction method
manta1130 23ba807
Sort output_list_all,dependency_list in lexicographical order
manta1130 fcacbc1
Remove unnecessary space
manta1130 0872289
Fix dependency_list
manta1130 fb47859
Change module definition(mod -> pub mod)
manta1130 2bcaf15
Format codes
manta1130 4b7e468
Merge remote-tracking branch 'upstream/master' into code-expander
qryxip File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
TEST_MODULES=(convolution dsu fenwicktree lazysegtree math maxflow mincostflow modint scc segtree string twosat --all) | ||
TMP_PATH=$(mktemp -d) | ||
SCRIPT_DIR=$(cd $(dirname $0); pwd) | ||
TEST_FILE="test.rs" | ||
FILE_HEAD="fn main() {}" | ||
|
||
if [ -v CI ];then | ||
rustup component add rustfmt | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fi | ||
|
||
for MODULE in ${TEST_MODULES[@]};do | ||
echo Test module $MODULE | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
python3 $SCRIPT_DIR/../../expand.py $MODULE > $TMP_PATH/$TEST_FILE | ||
echo "Output" $(wc -c < $TMP_PATH/$TEST_FILE) "Bytes" | ||
echo $FILE_HEAD >> $TMP_PATH/$TEST_FILE | ||
rustc -A warnings $TMP_PATH/$TEST_FILE | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if [ $? -ne 0 ];then | ||
echo "Error compiling for $MODULE" | ||
exit 1 | ||
else | ||
echo "Test passed" | ||
fi | ||
done | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#!/usr/bin/python3 | ||
|
||
import sys | ||
import getopt | ||
import tempfile | ||
import subprocess | ||
|
||
usage = '''Usage:expand.py [options] <output modules> | ||
Output Modules: | ||
convolution | ||
dsu | ||
fenwicktree | ||
lazysegtree | ||
math | ||
maxflow | ||
mincostflow | ||
modint | ||
scc | ||
segtree | ||
string | ||
twosat | ||
|
||
You can select multiple modules for <output modules> | ||
e.g.)expand.py math segtree | ||
|
||
Options: | ||
-a --all import all modules | ||
qryxip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
-h --help print help | ||
''' | ||
output_header = '//https://github.com/rust-lang-ja/ac-library-rs\n' | ||
opt_list = ['help', 'all'] | ||
output_list_all = ('lazysegtree', 'segtree', 'convolution', 'twosat', 'scc', | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'fenwicktree', 'math', 'modint', 'maxflow', 'dsu', 'mincostflow', 'string', 'internal_bit', 'internal_math', 'internal_type_traits', 'internal_scc', 'internal_queue') | ||
dependency_list = {'lazysegtree': ('internal_bit',), 'segtree': ('internal_bit',), 'convolution': ('internal_bit', 'modint',), 'math': ('internal_math',), 'modint': ( | ||
'internal_math', 'internal_type_traits'), 'fenwicktree': ('internal_type_traits',), 'twosat': ('internal_scc',), 'scc': ('internal_scc',), 'maxflow': ('internal_queue', 'internal_type_traits',), 'mincostflow': ('internal_type_traits',)} | ||
src_path = 'src/' | ||
|
||
|
||
def output_file(filename): | ||
global src_path | ||
|
||
res = [] | ||
with open(src_path+filename+'.rs', 'r') as f: | ||
res.append('mod {}{{'.format(filename)) | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
for line in f: | ||
res.append(line.rstrip()) | ||
|
||
res.append('}') | ||
return res | ||
|
||
|
||
try: | ||
opts, args = getopt.getopt(sys.argv[1:], 'ah', opt_list) | ||
except getopt.GetoptError as e: | ||
print(e) | ||
print(usage) | ||
sys.exit(2) | ||
|
||
if len(opts) == 0 and len(args) == 0: | ||
print(usage) | ||
sys.exit(0) | ||
|
||
for o, v in opts: | ||
if o == '--help' or o == '-h': | ||
print(usage) | ||
sys.exit(0) | ||
elif o == '--all' or o == '-a': | ||
args = list(output_list_all) | ||
|
||
output_list = set() | ||
|
||
while len(args) != 0: | ||
pop = args.pop() | ||
if not pop in output_list_all: | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print('invalid args:{}'.format(pop)) | ||
print(usage) | ||
sys.exit(2) | ||
output_list.add(pop) | ||
if pop in dependency_list: | ||
for d in dependency_list[pop]: | ||
args.append(d) | ||
|
||
output_list = list(output_list) | ||
output_list.sort() | ||
|
||
output_data = [] | ||
for i in output_list: | ||
buf = output_file(i) | ||
output_data.extend(buf) | ||
|
||
for i in output_list: | ||
# Modules that begin with 'internal' are for internal use, so they are not declared. | ||
qryxip marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not i.startswith('internal'): | ||
output_data.append('use {}::*;'.format(i)) | ||
|
||
# rustfmt | ||
with tempfile.TemporaryDirectory() as temp_dir: | ||
temp_file = temp_dir + '/output.rs' | ||
with open(temp_file, 'w') as f: | ||
print(output_header, file=f) | ||
for i in output_data: | ||
print(i, file=f) | ||
output_data = subprocess.run(["rustfmt", temp_file]) | ||
manta1130 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
with open(temp_file, 'r') as f: | ||
for line in f: | ||
print(line, end="") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.