Skip to content
 
 

Repository files navigation

Environment

sudo apt-get install git graphviz graphviz-doc
pip install -r requirements.txt

for windows

Need to download Visual Studio Build Tools

Introduction

IST is the abbreviation for Style Change by Tree Sitter, this tool aims to change a program to a specific style through tree-sitter. Up till now, it can change C/C++/python with 148 rules, and it can also show the visual AST tree with graphviz and tokenize the code. It will be continuous updated...

How to use

This code is to define a class IST, the parametre is the language of the codes.

ist = IST('c')

After that, you can change the single file's style using code below, where the first parametre is the target style, this function will return the changed code and whether the original code is changed successfully.

new_code, succ = ist.change_file_style([8.11], code)

You can also change the style of a directory which contains many code files with the same language, the parametres respectively represent target style list, original directory path, output directory path and output choice:

  • -1: do not output
  • 0: output only files changed successfully
  • 1: output all files splited by succ and fail
  • 2: output all files merged
ist.change_dir_style([style_choice], 'dataset/gcjpy_format', f'change/{style_choice}', output_choice=-1)

You can get the popularity of the single file's/directory's original styles by:

ist.get_file_popularity(5.1, code)
ist.get_dir_popularity(5.1, 'dataset/ProgramData/2')

You can see the style's information in {language}/transform*.py's cvt_* function's comments.

If you want to get AST's pdf, you can use:

ist.see_tree(code)

AST

If you want to get code's tokens, you can use:

ist.tokenize(code)

If you want to generate CFG of C program, you can run CFG.py

python CFG.py

捕获

Batch_sample Generator

We have built a batch sample generator based on code equivalence transformations implemented with Tree-sitter. Here is a summary of the types of equivalence transformations , followed by simple usage instructions for the sample generator.

The sample generator can be run directly and input the paramenters through graphical interface or provide them directly

python BatchSample_Generator.py --dpath "./dataset/programs/C" --trans 11.1 9.2 

You can get detailed usage through our user manul

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages