Model¶
Control flow graph for Python programs.
-
class
py2cfg.model.Block(id: int)[source]¶ Basic block in a control flow graph.
Contains a list of statements executed in a program without any control jumps. A block of statements is exited through one of its exits. Exits are a list of Links that represent control flow jumps.
-
get_calls() → str[source]¶ Get a string containing the calls to other functions inside the block.
- Returns
A string containing the names of the functions called inside the block.
-
-
class
py2cfg.model.CFG(name: str, asynchr: bool = False, short: bool = True)[source]¶ Control flow graph (CFG).
A control flow graph is composed of basic blocks and links between them representing control flow jumps. It has a unique entry block and several possible ‘final’ blocks (blocks with no exits representing the end of the CFG).
-
bsearch(lineno: int, lst: Optional[list] = None) → Optional[py2cfg.model.Block][source]¶ Search for a block at line
-
build_visual(filepath: str, format: str, calls: bool = True, show: bool = True, cleanup=True, directory=None, interactive=False, build_keys=True, build_own=False) → str[source]¶ Build a visualisation of the CFG with graphviz and output it in a DOT file.
- Parameters
filename – The name of the output file in which the visualisation must be saved.
format – The format to use for the output file (PDF, …).
show – A boolean indicating whether to automatically open the output file after building the visualisation.
-
highlight_blocks(lines, blocks=None) → int[source]¶ In interactive mode, highlight the block at lineno
-
own_blocks() → Iterator[py2cfg.model.Block][source]¶ Generator that yields all blocks in the current graph, excluding any subgraphs
-
-
class
py2cfg.model.Link(source: py2cfg.model.Block, target: py2cfg.model.Block, exitcase: Optional[_ast.Compare] = None)[source]¶ Link between blocks in a control flow graph.
Represents a control flow jump between two blocks. Contains an exitcase in the form of an expression, representing the case in which the associated control jump is made.