class documentation

Control flow graph builder.

A control flow graph builder is an ast.NodeVisitor that can walk through a program's AST and iteratively build the corresponding CFG.

Method __init__ Undocumented
Method add_exit Add a new exit to a block.
Method add_statement Add a statement to a block.
Method build Build a CFG from an AST.
Method build_from_file Build a CFG from some Python source file.
Method build_from_src Build a CFG from some Python source code.
Method clean_cfg Remove the useless (empty) blocks from a CFG.
Method goto_new_block Undocumented
Method new_block Create a new block with a new id.
Method new_ClassCFG Create a new sub-CFG for a class definition and add it to the function CFGs of the CFG being built.
Method new_functionCFG Create a new sub-CFG for a function definition and add it to the function CFGs of the CFG being built.
Method new_loopguard Create a new block for a loop's guard if the current block is not empty. Links the current block to the new loop guard.
Method visit_AnnAssign Undocumented
Method visit_Assert Undocumented
Method visit_Assign Undocumented
Method visit_AsyncFor Undocumented
Method visit_AsyncFunctionDef Undocumented
Method visit_AsyncWith Undocumented
Method visit_AugAssign Undocumented
Method visit_Await Undocumented
Method visit_Break Undocumented
Method visit_Call Undocumented
Method visit_ClassDef Undocumented
Method visit_Continue Undocumented
Method visit_Delete Undocumented
Method visit_Expr Undocumented
Method visit_For Undocumented
Method visit_FunctionDef Undocumented
Method visit_Global Undocumented
Method visit_If Undocumented
Method visit_Import Undocumented
Method visit_ImportFrom Undocumented
Method visit_Nonlocal Undocumented
Method visit_Pass Undocumented
Method visit_Raise Undocumented
Method visit_Return Undocumented
Method visit_Try Undocumented
Method visit_While Undocumented
Method visit_With Undocumented
Method visit_Yield Undocumented
Class Variable __all__ Undocumented
Instance Variable after_loop_block_stack Undocumented
Instance Variable cfg Undocumented
Instance Variable curr_loop_guard_stack Undocumented
Instance Variable current_block Undocumented
Instance Variable current_id Undocumented
Instance Variable enter_func_def Undocumented
Instance Variable separate_node_blocks Undocumented
def __init__(self, separate=False): (source)

Undocumented

def add_exit(self, block, nextblock, exitcase=None): (source)

Add a new exit to a block.

Parameters
blockA block to which an exit must be added.
nextblockThe block to which control jumps from the new exit.
exitcaseAn AST node representing the 'case' (or condition) leading to the exit from the block in the program.
def add_statement(self, block, statement): (source)

Add a statement to a block.

Parameters
blockA Block object to which a statement must be added.
statementAn AST node representing the statement that must be added to the current block.
def build(self, name, tree, asynchr=False, entry_id=0, flattened=False): (source)

Build a CFG from an AST.

Parameters
nameThe name of the CFG being built.
treeThe root of the AST from which the CFG must be built.
asynchrUndocumented
entry_idValue for the id of the entry block of the CFG.
flattenedif use k-v format for all CFGs while hiding its nested information. Key will be fully-qualified names.
asyncBoolean indicating whether the CFG being built represents an asynchronous function or not. When the CFG of a Python program is being built, it is considered like a synchronous 'main' function.
Returns
The CFG produced from the AST.
def build_from_file(self, name, filepath, flattened=False): (source)

Build a CFG from some Python source file.

Parameters
nameThe name of the CFG being built.
filepathThe path to the file containing the Python source code to build the CFG from.
flattenedif use k-v format for all CFGs while hiding its nested information. Key will be fully-qualified names.
Returns
The CFG produced from the source file.
def build_from_src(self, name, src, flattened=False): (source)

Build a CFG from some Python source code.

Parameters
nameThe name of the CFG being built.
srcA string containing the source code to build the CFG from.
flattenedif use k-v format for all CFGs while hiding its nested information. Key will be fully-qualified names.
Returns
The CFG produced from the source code.
def clean_cfg(self, block, visited): (source)

Remove the useless (empty) blocks from a CFG.

Parameters
blockThe block from which to start traversing the CFG to clean it.
visitedA list of blocks that already have been visited by clean_cfg (recursive function).
def goto_new_block(self, node): (source)

Undocumented

def new_block(self): (source)

Create a new block with a new id.

Returns
A Block object with a new unique id.
def new_ClassCFG(self, node, asynchr=False): (source)

Create a new sub-CFG for a class definition and add it to the function CFGs of the CFG being built.

Parameters
nodeThe AST node containing the function definition.
asynchrBoolean indicating whether the function for which the CFG is being built is asynchronous or not.
def new_functionCFG(self, node, asynchr=False, enclosing_block_id=-1): (source)

Create a new sub-CFG for a function definition and add it to the function CFGs of the CFG being built.

Parameters
nodeThe AST node containing the function definition.
asynchrUndocumented
enclosing_block_idUndocumented
asyncBoolean indicating whether the function for which the CFG is being built is asynchronous or not.
def new_loopguard(self): (source)

Create a new block for a loop's guard if the current block is not empty. Links the current block to the new loop guard.

Returns
The block to be used as new loop guard.
def visit_AnnAssign(self, node): (source)

Undocumented

def visit_Assert(self, node): (source)

Undocumented

def visit_Assign(self, node): (source)

Undocumented

def visit_AsyncFor(self, node): (source)

Undocumented

def visit_AsyncFunctionDef(self, node): (source)

Undocumented

def visit_AsyncWith(self, node): (source)

Undocumented

def visit_AugAssign(self, node): (source)

Undocumented

def visit_Await(self, node): (source)

Undocumented

def visit_Break(self, node): (source)

Undocumented

def visit_Call(self, node): (source)

Undocumented

def visit_ClassDef(self, node): (source)

Undocumented

def visit_Continue(self, node): (source)

Undocumented

def visit_Delete(self, node): (source)

Undocumented

def visit_Expr(self, node): (source)

Undocumented

def visit_For(self, node): (source)

Undocumented

def visit_FunctionDef(self, node): (source)

Undocumented

def visit_Global(self, node): (source)

Undocumented

def visit_If(self, node): (source)

Undocumented

def visit_Import(self, node): (source)

Undocumented

def visit_ImportFrom(self, node): (source)

Undocumented

def visit_Nonlocal(self, node): (source)

Undocumented

def visit_Pass(self, node): (source)

Undocumented

def visit_Raise(self, node): (source)

Undocumented

def visit_Return(self, node): (source)

Undocumented

def visit_Try(self, node): (source)

Undocumented

def visit_While(self, node): (source)

Undocumented

def visit_With(self, node): (source)

Undocumented

def visit_Yield(self, node): (source)

Undocumented

Undocumented

after_loop_block_stack: list = (source)

Undocumented

Undocumented

curr_loop_guard_stack: list = (source)

Undocumented

current_block = (source)

Undocumented

current_id = (source)

Undocumented

enter_func_def: bool = (source)

Undocumented

separate_node_blocks = (source)

Undocumented