Set of methods for source code decomposition.
$ git clone [email protected]:acheshkov/program_slicing.git$ cd program_slicing$ git submodule update --recursive --init$ pip3 install ./program_slicingYou should have access to global network to use pip. Python 3.9 with corresponding C compiler is required. Run Python Console to check the version of C compiler.
This project can be used via Command Line Interface, or it can be included into any other Python project as a submodule.
slice
Use this command if you want to decompose source files by complete computation slice (Nikolaos Tsantalis and Alexander Chatzigeorgiou. 2011. Identification of extract method refactoring opportunities for the decomposition of methods).
$ python cli.py slice [-h]
[-o OUTPUT]
sourcePositional arguments:
source - source folder, file or url
Optional arguments:
-o, --output OUTPUT - output file or directory: depending on what you set as output, you will get folder full of slice decompositions or a single file with it. It uses stdout if not specified
-h, --help - show this help message and exit
Examples:
$ python cli.py slice MyProjectPath$ python cli.py slice MyFile.java$ python cli.py slice MyProjectPath --output MyResultPath$ python cli.py slice MyFile.java --output MyResultPathControl Dependence Graph - structure that represents Control Dependence Graph (inherited from networkx.DiGraph) with corresponding methods.
from program_slicing.graph.cdg import ControlDependenceGraphControl Flow Graph - structure that represents Control Flow Graph (inherited from networkx.DiGraph) with corresponding methods.
from program_slicing.graph.cfg import ControlFlowGraphData Dependence Graph - structure that represents Data Dependence Graph (inherited from networkx.DiGraph) with corresponding methods.
from program_slicing.graph.ddg import DataDependenceGraphProgram Dependence Graph - structure that represents Program Dependence Graph (inherited from networkx.DiGraph) with corresponding methods.
from program_slicing.graph.pdg import ProgramDependenceGraphStatement - structure that represents Control Dependence Graph, Data Dependence Graph or Program Dependence Graph nodes.
from program_slicing.graph.statement import StatementStatementType - structure that enumerates Statement types.
from program_slicing.graph.statement import StatementTypei = 0, i += 1, i++, etc).{} or empty body in if (...) a = 0).if, try, catch, switch).for and while).break, continue, throw, return and even else).Basic Block - structure that represents Control Flow Graph nodes.
from program_slicing.graph.basic_block import BasicBlockProgram Graphs Manager - structure that contains different types of program graphs (such as Control Flow Graph or Control Dependence Graph) based on same source code and provides a set of methods for their analysis.
from program_slicing.graph.parse import Lang
from program_slicing.graph.parse import control_dependence_graph
from program_slicing.graph.parse import control_flow_graph
from program_slicing.graph.manager import ProgramGraphsManager
manager_by_source = ProgramGraphsManager(source_code, Lang.JAVA)
manager_by_cdg = ProgramGraphsManager.from_control_dependence_graph(control_dependence_graph(source_code, Lang.JAVA))
manager_by_cfg = ProgramGraphsManager.from_control_flow_graph(control_flow_graph(source_code, Lang.JAVA))Properties:
start_point,
then by decreasing of their end_point.SCOPE, BRANCH, LOOP, FUNCTION or EXIT Statement).SCOPE, BRANCH, LOOP or FUNCTION Statements.Public methods:
FUNCTION Statement in which the given Statement is placed.SCOPE, LOOP, BRANCH) Statement
that contains a given Statement.VARIABLE Statements that represent variables changed
in the given set of Statements.VARIABLE Statements that represent variables involved
(including usage) in the given set of Statements.Class methods:
parse - set of functions that allow to build different graphs from the specified source code string and programming language specification.
from program_slicing.graph.cdg import ControlDependenceGraph
from program_slicing.graph.parse import control_dependence_graph, Lang
cdg: ControlDependenceGraph = control_dependence_graph(source_code, Lang.JAVA)from program_slicing.graph.cfg import ControlFlowGraph
from program_slicing.graph.parse import control_flow_graph, Lang
cfg: ControlFlowGraph = control_flow_graph(source_code, Lang.JAVA)from program_slicing.graph.ddg import DataDependenceGraph
from program_slicing.graph.parse import data_dependence_graph, Lang
ddg: DataDependenceGraph = data_dependence_graph(source_code, Lang.JAVA)from program_slicing.graph.pdg import ProgramDependenceGraph
from program_slicing.graph.parse import program_dependence_graph, Lang
pdg: ProgramDependenceGraph = program_dependence_graph(source_code, Lang.JAVA)from tree_sitter import Tree
from program_slicing.graph.parse import tree_sitter_ast, Lang
ast: Tree = tree_sitter_ast(source_code, Lang.JAVA)convert - there is also an option to convert one type of graph to another:
from program_slicing.graph import convert
from program_slicing.graph.cdg import ControlDependenceGraph
from program_slicing.graph.cfg import ControlFlowGraph
cdg: ControlDependenceGraph = ControlDependenceGraph()
cfg: ControlFlowGraph = convert.cdg.to_cfg(cdg)
new_cdg: ControlDependenceGraph = convert.cfg.to_cdg(cfg)