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_classCFG Create a new sub-CFG for a class definition and add it to the class CFGs of the CFG being built.
Method new_func_block Create a new function 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 new_try_block Undocumented
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_ClassDef Undocumented
Method visit_Continue Undocumented
Method visit_ExceptHandler 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_Try Undocumented
Method visit_While Undocumented
Method visit_Yield Undocumented
Instance Variable cfg Undocumented
Instance Variable current_block Undocumented
Instance Variable current_id Undocumented
Instance Variable isShort Undocumented
Property loop_stack Undocumented
Property try_stack Undocumented
Instance Variable _callbuf Undocumented
Instance Variable _treebuf Undocumented
def __init__(self, short=True, treebuf=None): (source)

Undocumented

Parameters
short:boolUndocumented
treebuf:DefaultDict[str, Deque]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.

Parameters
block:BlockUndocumented
nextblock:BlockUndocumented
exitcase:Union[Compare, None, ast.BoolOp, ast.expr]Undocumented
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.

Parameters
block:BlockUndocumented
statement:Union[stmt, Call]Undocumented
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.

Parameters
name:strUndocumented
tree:ModuleUndocumented
asynchr:boolUndocumented
entry_id:intUndocumented
Returns
CFGUndocumented
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.

Parameters
name:strUndocumented
filepath:strUndocumented
Returns
CFGUndocumented
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.

Parameters
name:strUndocumented
src:strUndocumented
Returns
CFGUndocumented
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).

Parameters
block:BlockUndocumented
visited:Set[Block]Undocumented
def new_block(self, statement=None): (source)

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

Returns
BlockUndocumented
def new_classCFG(self, node, asynchr=False): (source)

Create a new sub-CFG for a class definition and add it to the class CFGs of the CFG being built. Args: node: The AST node containing the class definition. async: Boolean indicating whether the class for which the CFG is being built is asynchronous or not.

Parameters
node:ClassDefUndocumented
asynchr:boolUndocumented
def new_func_block(self): (source)

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

Returns
FuncBlockUndocumented
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.

Parameters
node:FunctionDefUndocumented
asynchr:boolUndocumented
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.

Returns
BlockUndocumented
def new_try_block(self, statement=None): (source)

Undocumented

def visit_AnnAssign(self, node): (source)

Undocumented

Parameters
node:AnnAssignUndocumented
def visit_Assert(self, node): (source)

Undocumented

def visit_Assign(self, node): (source)

Undocumented

Parameters
node:AssignUndocumented
def visit_AsyncFunctionDef(self, node): (source)

Undocumented

def visit_AugAssign(self, node): (source)

Undocumented

Parameters
node:AugAssignUndocumented
def visit_Await(self, node): (source)

Undocumented

def visit_Break(self, node): (source)

Undocumented

Parameters
node:BreakUndocumented
def visit_Call(self, node): (source)

Undocumented

Parameters
node:CallUndocumented
def visit_ClassDef(self, node): (source)

Undocumented

Parameters
node:ClassDefUndocumented
def visit_Continue(self, node): (source)

Undocumented

def visit_ExceptHandler(self, node): (source)

Undocumented

Parameters
node:ExceptHandlerUndocumented
def visit_Expr(self, node): (source)

Undocumented

Parameters
node:ExprUndocumented
def visit_For(self, node): (source)

Undocumented

Parameters
node:ForUndocumented
def visit_FunctionDef(self, node): (source)

Undocumented

Parameters
node:FunctionDefUndocumented
def visit_If(self, node): (source)

Undocumented

Parameters
node:IfUndocumented
def visit_Import(self, node): (source)

Undocumented

Parameters
node:ImportUndocumented
def visit_ImportFrom(self, node): (source)

Undocumented

Parameters
node:ImportFromUndocumented
def visit_Raise(self, node): (source)

Undocumented

def visit_Return(self, node): (source)

Undocumented

Parameters
node:ReturnUndocumented
def visit_Try(self, node): (source)

Undocumented

Parameters
node:TryUndocumented
def visit_While(self, node): (source)

Undocumented

Parameters
node:WhileUndocumented
def visit_Yield(self, node): (source)

Undocumented

Parameters
node:YieldUndocumented

Undocumented

current_block = (source)

Undocumented

current_id = (source)

Undocumented

Undocumented

Undocumented

@property
try_stack: Deque[TryStackObject] = (source)

Undocumented

_callbuf: List[FuncBlock] = (source)

Undocumented

_treebuf = (source)

Undocumented