lyra.frontend package¶
Submodules¶
-
class
lyra.frontend.cfg_generator.
CFGFactory
(id_gen)[source]¶ Bases:
object
A helper class that encapsulates a partial CFG and possibly some statements not yet attached to CFG.
Whenever the method complete_basic_block() is called, it is ensured that all unattached statements are properly attached to partial CFG. The partial CFG can be retrieved at any time by property cfg.
-
add_stmts
(stmts)[source]¶ Adds statements to the currently open block. :param stmts: a single statement or an iterable of statements :return:
-
cfg
¶
-
-
class
lyra.frontend.cfg_generator.
CFGVisitor
[source]¶ Bases:
ast.NodeVisitor
AST visitor that generates a CFG.
-
class
NodeIdentifierGenerator
[source]¶ Bases:
object
Helper class that generates an increasing sequence of node identifiers.
-
next
¶
-
-
visit
(node, *args, **kwargs)[source]¶ Visit an AST node.
Parameters: - node – node to be visited
- arguments –
- types – dictionary mapping (variable) names to their corresponding (lyra) type
- typ – type of the current node
Returns: either a statement or a partial CFG, depending on the visited node
-
visit_AnnAssign
(node, types=None, typ=None)[source]¶ Visitor function for an assignment with a type annotation. The attribute target stores the target of the assignment (a Name, Attribute, or Subscript). The attribute annotation stores the type annotation (a Str or Name). The attribute value opionally stores the assigned value.
-
visit_Assign
(node, types=None, typ=None)[source]¶ Visitor function for an assignment. The attribute targets stores a list of targets of the assignment. The attribute value stores the assigned value.
-
visit_AugAssign
(node, types=None, typ=None)[source]¶ Visitor function for an augmented assignment. The attribute target stores the target of the assignment (a Name, Attribute, or Subscript). The attributes op and value store the operation and the assigned value, respectively.
-
visit_BinOp
(node, types=None, typ=None)[source]¶ Visitor function for a binary operation. The attributes op, left, and right store the operator and any expression nodes, respectively.
-
visit_BoolOp
(node, types=None, typ=None)[source]¶ Visitor function for a boolean operation. The attributes op and values store the operand and a list of any expression node representing the operand involed, respectively.
-
visit_Call
(node, types=None, typ=None)[source]¶ Visitor function for a call. The attribute func stores the function being called (often a Name or Attribute object). The attribute args stores a list fo the arguments passed by position.
-
visit_Compare
(node, types=None, typ=None)[source]¶ Visitor function for a comparison operation. The attributes left, ops, and comparators store the first value in the comparison, the list of operators, and the list of compared values after the first.
-
visit_Dict
(node, types=None, typ=None)[source]¶ Visitor function for a dictionary. The attributes keys and values store lists of nodes with matching order representing the keys and the values, respectively.
-
visit_Expr
(node, types=None, typ=None)[source]¶ Visitor function for an expression statement (whose return value is unused). The attribute value stored another AST node.
-
visit_IfExp
(node, targets, op=None, types=None, typ=None)[source]¶ Visitor function for an if expression. The components of the expression are stored in the attributes test, body, and orelse.
-
visit_List
(node, types=None, typ=None)[source]¶ Visitor function for a list. The elts attribute stores a list of nodes representing the elements. The ctx attribute is Store if the container is an assignment target, and Load otherwise.
-
visit_Name
(node, types=None, typ=None)[source]¶ Visitor function for a variable name. The attribute id stores the name as a string. The attribute ctx is Store (to assign a new value to the variable), Load (to load the value of the variable), or Del (to delete the variable).
-
visit_NameConstant
(node, types=None, typ=None)[source]¶ Visitor function for True, False or None. The value attribute stores the constant.
-
visit_Num
(node, types=None, typ=None)[source]¶ Visitor function for a number (integer, float, or complex). The n attribute stores the value, already converted to the relevant type.
-
visit_Raise
(node, types=None, typ=None)[source]¶ Visitor function for an exception raise. The attribute exc stores the exception object to be raised (normally a Call or Name, or None for a standalone raise).
-
visit_Set
(node, types=None, typ=None)[source]¶ Visitor function for a set. The elts attribute stores a list of nodes representing the elements.
-
visit_Str
(node, types=None, typ=None)[source]¶ Visitor function for a string. The s attribute stores the value.
-
visit_Subscript
(node, types=None, typ=None)[source]¶ Visitor function for a subscript. The attribute value stores the target of the subscript (often a Name). The attribute slice is one of Index, Slice, or ExtSlice. The attribute ctx is Load, Store, or Del.
-
visit_Tuple
(node, types=None, typ=None)[source]¶ Visitor function for a tuple. The elts attribute stores a list of nodes representing the elements. The ctx attribute is Store if the container is an assignment target, and Load otherwise.
-
class
-
class
lyra.frontend.cfg_generator.
LooseControlFlowGraph
(nodes: typing.Set[lyra.core.cfg.Node] = None, in_node: lyra.core.cfg.Node = None, out_node: lyra.core.cfg.Node = None, edges: typing.Set[lyra.core.cfg.Edge] = None, loose_in_edges=None, loose_out_edges=None, both_loose_edges=None)[source]¶ Bases:
object
-
both_loose_edges
¶
-
edges
¶
-
in_node
¶
-
loose_in_edges
¶
-
loose_out_edges
¶
-
nodes
¶
-
out_node
¶
-
special_edges
¶
-