lyra.abstract_domains package¶
Subpackages¶
Submodules¶
Basis Abstract Domain¶
Interface of an abstract domain mapping variables to lattice elements.
Author: | Caterina Urban |
---|
-
class
lyra.abstract_domains.basis.
Basis
(variables: typing.Set[lyra.core.expressions.VariableIdentifier], lattices: typing.Dict[lyra.core.types.LyraType, typing.Type[lyra.abstract_domains.lattice.Lattice]], arguments: typing.Dict[lyra.core.types.LyraType, typing.Dict[str, typing.Any]] = defaultdict(<function Basis.<lambda>>, {}), precursory: lyra.abstract_domains.state.State = None)[source]¶ Bases:
lyra.abstract_domains.store.Store
,lyra.abstract_domains.state.State
Analysis basic state. A mutable element of a basis abstract domain.
Warning
Lattice operations and statements modify the current state.
-
class
ExpressionEvaluation
[source]¶ Bases:
lyra.core.expressions.ExpressionVisitor
Visitor that performs the evaluation of an expression in the lattice.
-
visit_AttributeReference
(expr: lyra.core.expressions.AttributeReference, state=None, evaluation=None)[source]¶ Visit of an attribute reference.
-
visit_BinaryArithmeticOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a binary arithmetic operation.
-
visit_BinaryBooleanOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a binary boolean operation.
-
visit_BinaryComparisonOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a binary comparison operation.
-
visit_BinarySequenceOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a binary sequence operation.
-
visit_DictDisplay
(expr: lyra.core.expressions.DictDisplay, state=None, evaluation=None)[source]¶ Visit of dictionary display.
-
visit_Input
(expr: lyra.core.expressions.Input, state=None, evaluation=None)[source]¶ Visit of an input call expression.
-
visit_LengthIdentifier
(expr: lyra.core.expressions.LengthIdentifier, state=None, evaluation=None)[source]¶ Visit of a sequence or collection length.
-
visit_ListDisplay
(expr: lyra.core.expressions.ListDisplay, state=None, evaluation=None)[source]¶ Visit of a list display.
-
visit_Literal
(expr: lyra.core.expressions.Literal, state=None, evaluation=None)[source]¶ Visit of a literal expression.
-
visit_Range
(expr: lyra.core.expressions.Range, state=None, evaluation=None)[source]¶ Visit of a range call expression.
-
visit_SetDisplay
(expr: lyra.core.expressions.SetDisplay, state=None, evaluation=None)[source]¶ Visit of a set display.
-
visit_Slicing
(expr: lyra.core.expressions.Slicing, state=None, evaluation=None)[source]¶ Visit of a slicing expression.
-
visit_Subscription
(expr: lyra.core.expressions.Subscription, state=None, evaluation=None)[source]¶ Visit of a subscription expression.
-
visit_TupleDisplay
(expr: lyra.core.expressions.TupleDisplay, state=None, evaluation=None)[source]¶ Visit of a tuple display.
-
visit_UnaryArithmeticOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a unary arithmetic operation.
-
-
class
ExpressionRefinement
[source]¶ Bases:
lyra.core.expressions.ExpressionVisitor
Visitor that:
- refines the value of an evaluated expression based on a given lattice element; and
- modifies the current state based on the refined value of the expression.
-
visit_AttributeReference
(expr, evaluation=None, value=None, state=None)[source]¶ Visit of an attribute reference.
-
visit_BinaryArithmeticOperation
(expr, evaluation=None, value=None, state=None)[source]¶ Visit of a binary arithmetic operation.
-
visit_BinaryBooleanOperation
(expr, evaluation=None, value=None, state=None)[source]¶ Visit of a binary boolean operation.
-
visit_BinaryComparisonOperation
(expr, evaluation=None, value=None, state=None)[source]¶ Visit of a binary comparison operation.
-
visit_BinarySequenceOperation
(expr, evaluation=None, value=None, state=None)[source]¶ Visit of a binary sequence operation.
-
visit_DictDisplay
(expr: lyra.core.expressions.DictDisplay, evaluation=None, value=None, state=None)[source]¶ Visit of dictionary display.
-
visit_Input
(expr: lyra.core.expressions.Input, evaluation=None, value=None, state=None)[source]¶ Visit of an input call expression.
-
visit_LengthIdentifier
(expr, evaluation=None, value=None, state=None)[source]¶ Visit of a sequence or collection length.
-
visit_ListDisplay
(expr: lyra.core.expressions.ListDisplay, evaluation=None, value=None, state=None)[source]¶ Visit of a list display.
-
visit_Literal
(expr: lyra.core.expressions.Literal, evaluation=None, value=None, state=None)[source]¶ Visit of a literal expression.
-
visit_Range
(expr: lyra.core.expressions.Range, state=None, evaluation=None)[source]¶ Visit of a range call expression.
-
visit_SetDisplay
(expr: lyra.core.expressions.SetDisplay, evaluation=None, value=None, state=None)[source]¶ Visit of a set display.
-
visit_Slicing
(expr: lyra.core.expressions.Slicing, evaluation=None, value=None, state=None)[source]¶ Visit of a slicing expression.
-
visit_Subscription
(expr: lyra.core.expressions.Subscription, evaluation=None, value=None, state=None)[source]¶ Visit of a subscription expression.
-
visit_TupleDisplay
(expr: lyra.core.expressions.TupleDisplay, evaluation=None, value=None, state=None)[source]¶ Visit of a tuple display.
-
visit_UnaryArithmeticOperation
(expr, evaluation=None, value=None, state=None)[source]¶ Visit of a unary arithmetic operation.
-
class
LengthEvaluation
[source]¶ Bases:
lyra.core.expressions.ExpressionVisitor
Visitor that computes the length of an expression corresponding to a sequence type.
-
visit_AttributeReference
(expr: lyra.core.expressions.AttributeReference, state=None, evaluation=None)[source]¶ Visit of an attribute reference.
-
visit_BinaryArithmeticOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a binary arithmetic operation.
-
visit_BinaryBooleanOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a binary boolean operation.
-
visit_BinaryComparisonOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a binary comparison operation.
-
visit_BinarySequenceOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a binary sequence operation.
-
visit_DictDisplay
(expr: lyra.core.expressions.DictDisplay, state=None, evaluation=None)[source]¶ Visit of dictionary display.
-
visit_Input
(expr: lyra.core.expressions.Input, state=None, evaluation=None)[source]¶ Visit of an input call expression.
-
visit_LengthIdentifier
(expr: lyra.core.expressions.LengthIdentifier, state=None, evaluation=None)[source]¶ Visit of a sequence or collection length.
-
visit_ListDisplay
(expr: lyra.core.expressions.ListDisplay, state=None, evaluation=None)[source]¶ Visit of a list display.
-
visit_Literal
(expr: lyra.core.expressions.Literal, state=None)[source]¶ Visit of a literal expression.
-
visit_Range
(expr: lyra.core.expressions.Range, state=None, evaluation=None)[source]¶ Visit of a range call expression.
-
visit_SetDisplay
(expr: lyra.core.expressions.SetDisplay, state=None, evaluation=None)[source]¶ Visit of a set display.
-
visit_Slicing
(expr: lyra.core.expressions.Slicing, state=None, evaluation=None)[source]¶ Visit of a slicing expression.
-
visit_Subscription
(expr: lyra.core.expressions.Subscription, state=None, evaluation=None)[source]¶ Visit of a subscription expression.
-
visit_TupleDisplay
(expr: lyra.core.expressions.TupleDisplay, state=None, evaluation=None)[source]¶ Visit of a tuple display.
-
visit_UnaryArithmeticOperation
(expr, state=None, evaluation=None)[source]¶ Visit of a unary arithmetic operation.
-
-
enter_if
()[source]¶ Enter a conditional if statement.
Warning
The current state could also be bottom or top.
Returns: current state modified to enter a conditional if statement
-
enter_loop
()[source]¶ Enter a loop.
Warning
The current state could also be bottom or top.
Returns: current state modified to enter a loop
-
exit_if
()[source]¶ Exit a conditional if statement.
Warning
The current state could also be bottom or top.
Returns: current state modified to enter a conditional if statement
-
class
Lattice¶
Interface of a lattice. Lattice elements support lattice operations.
Author: | Caterina Urban |
---|
-
class
lyra.abstract_domains.lattice.
ArithmeticMixin
[source]¶ Bases:
lyra.abstract_domains.lattice.Lattice
Mixin to add arithmetic operations to a lattice.
-
add
(other: lyra.abstract_domains.lattice.ArithmeticMixin) → lyra.abstract_domains.lattice.ArithmeticMixin[source]¶ Addition between two lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the sum
-
div
(other: lyra.abstract_domains.lattice.ArithmeticMixin) → lyra.abstract_domains.lattice.ArithmeticMixin[source]¶ Multiplication between two lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the product
-
mult
(other: lyra.abstract_domains.lattice.ArithmeticMixin) → lyra.abstract_domains.lattice.ArithmeticMixin[source]¶ Multiplication between two lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the product
-
-
class
lyra.abstract_domains.lattice.
BooleanMixin
[source]¶ Bases:
lyra.abstract_domains.lattice.Lattice
Mixin to add boolean operations to a lattice.
-
compl
() → lyra.abstract_domains.lattice.BooleanMixin[source]¶ Complement of a lattice elements.
Returns: current lattice element modified to be its complement
-
conj
(other: lyra.abstract_domains.lattice.BooleanMixin) → lyra.abstract_domains.lattice.BooleanMixin[source]¶ Conjunction between two lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the conjunction
-
disj
(other: lyra.abstract_domains.lattice.BooleanMixin) → lyra.abstract_domains.lattice.BooleanMixin[source]¶ Disjunction between two lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the disjunction
-
false
() → lyra.abstract_domains.lattice.BooleanMixin[source]¶ False lattice element.
Returns: current lattice element modified to be the false lattice element
-
is_false
() → bool[source]¶ Test whether the lattice element is false.
Returns: whether the lattice element is false
-
is_maybe
() → bool[source]¶ Test whether the lattice element is maybe.
Returns: whether the lattice element is maybe
-
is_true
() → bool[source]¶ Test whether the lattice element is true.
Returns: whether the lattice element is true
-
-
class
lyra.abstract_domains.lattice.
BottomMixin
[source]¶ Bases:
lyra.abstract_domains.lattice.KindMixin
Mixin to add a predefined bottom element to a lattice.
Warning
Subclasses are expected to provide consistent method implementations that check for the eventuality of
is_bottom()
being true.
-
class
lyra.abstract_domains.lattice.
BoundedLattice
[source]¶ Bases:
lyra.abstract_domains.lattice.TopMixin
,lyra.abstract_domains.lattice.BottomMixin
Mutable lattice element, with predefined bottom and top elements.
Warning
Lattice operations modify the current lattice element.
-
bottom
() → lyra.abstract_domains.lattice.BoundedLattice[source]¶ Bottom lattice element.
Returns: current lattice element modified to be the bottom lattice element
-
is_bottom
() → bool[source]¶ Test whether the lattice element is bottom.
Returns: whether the lattice element is bottom
-
-
class
lyra.abstract_domains.lattice.
KindMixin
[source]¶ Bases:
lyra.abstract_domains.lattice.Lattice
Mixin to add an explicit distinction between bottom, default, and top lattice elements.
-
kind
¶ The kind of the current lattice element.
-
-
class
lyra.abstract_domains.lattice.
Lattice
[source]¶ Bases:
object
Mutable lattice element.
Warning
Lattice operations modify the current lattice element.
Subclasses are expected to provide consistent method implementations for
bottom()
,is_bottom()
,top()
andis_top()
.-
big_join
(elements: typing.List[_ForwardRef(‘Lattice’)]) → lyra.abstract_domains.lattice.Lattice[source]¶ Least upper bound between multiple lattice elements.
Parameters: elements – lattice elements to compute the least upper bound of Returns: current lattice element modified to be the least upper bound
-
big_meet
(elements: typing.List[_ForwardRef(‘Lattice’)]) → lyra.abstract_domains.lattice.Lattice[source]¶ Greatest lower bound between multiple lattice elements.
Parameters: elements – lattice elements to compute the greatest lower bound of Returns: current lattice element modified to be the least upper bound
-
bottom
()[source]¶ Bottom lattice element.
Returns: current lattice element modified to be the bottom lattice element
-
is_bottom
() → bool[source]¶ Test whether the lattice element is bottom.
Returns: whether the lattice element is bottom
-
is_top
() → bool[source]¶ Test whether the lattice element is top.
Returns: whether the lattice element is top
-
join
(other: lyra.abstract_domains.lattice.Lattice) → lyra.abstract_domains.lattice.Lattice[source]¶ Least upper bound between lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the least upper bound
-
less_equal
(other: lyra.abstract_domains.lattice.Lattice) → bool[source]¶ Partial order between lattice elements.
Parameters: other – other lattice element Returns: whether the current lattice element is less than or equal to the other element
-
meet
(other: lyra.abstract_domains.lattice.Lattice)[source]¶ Greatest lower bound between lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the greatest lower bound
-
-
class
lyra.abstract_domains.lattice.
SequenceMixin
[source]¶ Bases:
lyra.abstract_domains.lattice.Lattice
Mixin to add sequence operations to a lattice.
-
class
lyra.abstract_domains.lattice.
TopMixin
[source]¶ Bases:
lyra.abstract_domains.lattice.KindMixin
Mixin to add a predefined top element to another lattice.
Warning
Subclasses are expected to provide consistent method implementations that check for the eventuality of
is_top()
being true.
Stack¶
Stack of lattices.
Authors: | Caterina Urban and Simon Wehrli |
---|
-
class
lyra.abstract_domains.stack.
Stack
(lattice: typing.Type, arguments: typing.Dict[str, typing.Any])[source]¶ Bases:
lyra.abstract_domains.lattice.BoundedLattice
Mutable stack of elements of a lattice.
Warning
Lattice operations modify the current stack.
-
_less_equal
(other: lyra.abstract_domains.stack.Stack) → bool[source]¶ Partial order between default lattice elements.
Parameters: other – other lattice element Returns: whether the current lattice element is less than or equal to the other element The comparison is performed point-wise for each stack element.
-
_meet
(other: lyra.abstract_domains.stack.Stack)[source]¶ Greatest lower bound between default lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the greatest lower bound The meet is performed point-wise for each stack element.
-
_join
(other: lyra.abstract_domains.stack.Stack) → lyra.abstract_domains.stack.Stack[source]¶ Least upper bound between default lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the least upper bound The join is performed point-wise for each stack element.
-
lattice
¶ Lattice element currently on top of the stack.
-
stack
¶ Current stack of lattice elements.
-
Abstract Domain¶
Interface of an abstract domain. Abstract domain elements support lattice operations and program statements.
Author: | Caterina Urban |
---|
-
class
lyra.abstract_domains.state.
EnvironmentMixin
(precursory: typing.Union[lyra.abstract_domains.state.State, NoneType] = None)[source]¶ Bases:
lyra.abstract_domains.state.State
Mixin to add environment modification operations to another state.
-
add_variable
(variable: lyra.core.expressions.VariableIdentifier)[source]¶ Add a variable.
Parameters: variable – variable to be added Returns: current state modified by the variable addition
-
-
class
lyra.abstract_domains.state.
State
(precursory: typing.Union[lyra.abstract_domains.state.State, NoneType] = None)[source]¶ Bases:
lyra.abstract_domains.lattice.Lattice
Analysis state. A mutable element of an abstract domain.
Warning
Lattice operations and statements modify the current state.
-
assign
(left: typing.Set[lyra.core.expressions.Expression], right: typing.Set[lyra.core.expressions.Expression]) → lyra.abstract_domains.state.State[source]¶ Assign an expression to another expression.
Parameters: - left – set of expressions representing the expression to be assigned to
- right – set of expressions representing the expression to assign
Returns: current state modified by the assignment
-
assume
(condition: typing.Set[lyra.core.expressions.Expression]) → lyra.abstract_domains.state.State[source]¶ Assume that some condition holds in the current state.
Parameters: condition – set of expressions representing the assumed condition Returns: current state modified to satisfy the assumption
-
before
(pp: lyra.core.statements.ProgramPoint, precursory: typing.Union[_ForwardRef(‘State’), NoneType]) → lyra.abstract_domains.state.State[source]¶ Set the program point of the currently analyzed statement and the current precursory analysis state.
Parameters: - pp – current program point
- precursory – current precursory analysis state
Returns: current state modified to set the current program point and precursory state
-
enter_if
() → lyra.abstract_domains.state.State[source]¶ Enter a conditional if statement.
Warning
The current state could also be bottom or top.
Returns: current state modified to enter a conditional if statement
-
enter_loop
() → lyra.abstract_domains.state.State[source]¶ Enter a loop.
Warning
The current state could also be bottom or top.
Returns: current state modified to enter a loop
-
exit_if
() → lyra.abstract_domains.state.State[source]¶ Exit a conditional if statement.
Warning
The current state could also be bottom or top.
Returns: current state modified to enter a conditional if statement
-
exit_loop
() → lyra.abstract_domains.state.State[source]¶ Exit a loop.
Warning
The current state could also be bottom or top.
Returns: current state modified to exit a loop
-
filter
() → lyra.abstract_domains.state.State[source]¶ Assume that the current result holds in the current state.
Returns: current state modified to satisfy the current result
-
output
(output: typing.Set[lyra.core.expressions.Expression]) → lyra.abstract_domains.state.State[source]¶ Outputs something in the current state.
Parameters: output – set of expressions representing the output Returns: current state modified by the output
-
pp
¶ Program point of the currently analyzed statement.
-
precursory
¶ Current precursory analysis state.
-
raise_error
() → lyra.abstract_domains.state.State[source]¶ Raise an error.
Returns: current state modified to be the bottom state
-
result
¶ Result of the previously analyzed statement.
-
substitute
(left: typing.Set[lyra.core.expressions.Expression], right: typing.Set[lyra.core.expressions.Expression]) → lyra.abstract_domains.state.State[source]¶ Substitute an expression to another expression.
Parameters: - left – set of expressions representing the expression to be substituted
- right – set of expressions representing the expression to substitute
Returns: current state modified by the substitution
-
Store¶
Lifting of a lattice to a set of program variables.
Authors: | Caterina Urban and Simon Wehrli |
---|
-
class
lyra.abstract_domains.store.
Store
(variables: typing.Set[lyra.core.expressions.VariableIdentifier], lattices: typing.Dict[lyra.core.types.LyraType, typing.Type[lyra.abstract_domains.lattice.Lattice]], arguments: typing.Dict[lyra.core.types.LyraType, typing.Dict[str, typing.Any]] = defaultdict(<function Store.<lambda>>, {}))[source]¶ Bases:
lyra.abstract_domains.lattice.Lattice
Mutable element of a store
Var -> L
, lifting a latticeL
to a set of program variablesVar
.Warning
Lattice operations modify the current store.
-
_less_equal
(other: lyra.abstract_domains.store.Store) → bool[source]¶ Partial order between default lattice elements.
Parameters: other – other lattice element Returns: whether the current lattice element is less than or equal to the other element The comparison is performed point-wise for each variable.
-
_meet
(other: lyra.abstract_domains.store.Store)[source]¶ Greatest lower bound between default lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the greatest lower bound The meet is performed point-wise for each variable.
-
_join
(other: lyra.abstract_domains.store.Store) → lyra.abstract_domains.store.Store[source]¶ Least upper bound between default lattice elements.
Parameters: other – other lattice element Returns: current lattice element modified to be the least upper bound The join is performed point-wise for each variable.
-
arguments
¶ Current dictionary from variable types to argument of the corresponding lattices.
-
bottom
() → lyra.abstract_domains.store.Store[source]¶ Bottom lattice element.
Returns: current lattice element modified to be the bottom lattice element
-
is_bottom
() → bool[source]¶ Test whether the lattice element is bottom.
Returns: whether the lattice element is bottom The current store is bottom if any of its variables map to a bottom element.
-
is_top
() → bool[source]¶ Test whether the lattice element is top.
Returns: whether the lattice element is top The current store is top if all of its variables map to a top element.
-
lattices
¶ Current dictionary fro variable types to the corresponding lattice types.
-
store
¶ Current mapping from variables to their corresponding lattice element.
-
top
() → lyra.abstract_domains.store.Store[source]¶ Top lattice element.
Returns: current lattice element modified to be the top lattice element
-
variables
¶ Variables of the current store.
-