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 new_block Create a new block with a new id.
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_AsyncFunctionDef Undocumented
Method visit_AugAssign Undocumented
Method visit_Await Undocumented
Method visit_Break Undocumented
Method visit_Call Undocumented
Method visit_Continue Undocumented
Method visit_Expr Undocumented
Method visit_For Undocumented
Method visit_FunctionDef Undocumented
Method visit_If Undocumented
Method visit_Import Undocumented
Method visit_ImportFrom Undocumented
Method visit_Raise Undocumented
Method visit_Return Undocumented
Method visit_While Undocumented
Method visit_Yield 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
def __init__(self): (source)

Undocumented

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

Add a new exit to a block. Args: block: A block to which an exit must be added. nextblock: The block to which control jumps from the new exit. exitcase: An 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. Args: block: A Block object to which a statement must be added. statement: An AST node representing the statement that must be added to the current block.

def build(self, name, tree, asynchr=False, entry_id=0): (source)

Build a CFG from an AST. Args: name: The name of the CFG being built. tree: The root of the AST from which the CFG must be built. async: Boolean 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. entry_id: Value for the id of the entry block of the CFG. Returns: The CFG produced from the AST.

def build_from_file(self, name, filepath): (source)

Build a CFG from some Python source file. Args: name: The name of the CFG being built. filepath: The path to the file containing the Python source code to build the CFG from. Returns: The CFG produced from the source file.

def build_from_src(self, name, src): (source)

Build a CFG from some Python source code. Args: name: The name of the CFG being built. src: A string containing the source code to build the CFG from. Returns: The CFG produced from the source code.

def clean_cfg(self, block, visited=[]): (source)

Remove the useless (empty) blocks from a CFG. Args: block: The block from which to start traversing the CFG to clean it. visited: A list of blocks that already have been visited by clean_cfg (recursive function).

def new_block(self): (source)

Create a new block with a new id. Returns: A Block object with a new unique id.

def new_functionCFG(self, node, asynchr=False): (source)

Create a new sub-CFG for a function definition and add it to the function CFGs of the CFG being built. Args: node: The AST node containing the function definition. async: Boolean 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_AsyncFunctionDef(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_Continue(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_If(self, node): (source)

Undocumented

def visit_Import(self, node): (source)

Undocumented

def visit_ImportFrom(self, node): (source)

Undocumented

def visit_Raise(self, node): (source)

Undocumented

def visit_Return(self, node): (source)

Undocumented

def visit_While(self, node): (source)

Undocumented

def visit_Yield(self, node): (source)

Undocumented

after_loop_block_stack: list = (source)

Undocumented

Undocumented

curr_loop_guard_stack: list = (source)

Undocumented

current_block = (source)

Undocumented

current_id = (source)

Undocumented