ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin Class Reference
Inheritance diagram for preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin:
[legend]

Classes

class  _ListCompExpressionLowerer

Public Member Functions

 visit_Return (self, node)
 visit_Attribute (self, node)
 visit_Subscript (self, node)
 visit_Expr (self, node)
 visit_If (self, node)
 visit_Try (self, node)
 visit_While (self, node)
 visit_Assert (self, node)
 visit_Compare (self, node)

Static Public Member Functions

 replace_filtered_genexp_arg (node)

Public Attributes

 functools_reduce_names = found["reduce"]
 functools_module_names = found["module"]
 list_literal_values
 early_return_generator_funcs
tuple dict_literal_values = (dict(before[0]), dict(before[1]))

Protected Member Functions

 _map_as_listcomp (self, call)
 _map_for_lowerable (self, node, call)
 _map_for_as_plain_for (self, node)
 _map_consumer_slot (self, stmt, name, call)
 _list_call_on (self, stmt, name)
 _inline_single_use_map (self, stmts, i, name_counts)
 _inline_single_use_maps (self, module)
 _rewrite_map_values (self, module)
 _scan_functools_reduce_names (self, module)
 _is_functools_reduce_call (self, node)
 _lower_functools_reduce (self, call)
 _transform_list_truthiness (self, test_expr, source_node)
 _move_test_prefix_into_body (self, node, prefix)
 _simplify_isinstance (self, node)
 _resolve_call_origin (self, node)
 _apply_assert_eq_rewrites (self, node)

Static Protected Member Functions

 _is_map_call (node)
 _is_pure_operand (node)
 _is_unpacking (node)
 _names (node, name)
 _functools_binding (node, alias)
 _is_inlinable_lambda (node)

Protected Attributes

 _is_pure_operand
 _subscript_inferred_vars

Static Protected Attributes

str _REDUCE_FIRST
str _REDUCE_INITIAL
str _REDUCE_CALL_STEP = " {acc} = __function({acc}, {seq}[{i}])\n"
str _REDUCE_LAMBDA_STEP = " {x} = {acc}\n {y} = {seq}[{i}]\n {acc} = __function\n"
tuple _SYMMETRIC_EQ_TRANSFORMS

Member Function Documentation

◆ _apply_assert_eq_rewrites()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._apply_assert_eq_rewrites ( self,
node )
protected

◆ _functools_binding()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._functools_binding ( node,
alias )
staticprotected
"reduce" when @p alias of import @p node binds functools.reduce,
"module" when it binds functools itself, else None.

◆ _inline_single_use_map()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._inline_single_use_map ( self,
stmts,
i,
name_counts )
protected
Move `r = map(f, xs)` into the next statement when that is r's only
use, so the map is consumed where it is built. A map is an iterator:
lowering a bound one to a list would let a second pass over it see the
elements again, where CPython sees none.

◆ _inline_single_use_maps()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._inline_single_use_maps ( self,
module )
protected

◆ _is_functools_reduce_call()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._is_functools_reduce_call ( self,
node )
protected
Whether @p node calls functools.reduce in a form the fold lowers.

◆ _is_inlinable_lambda()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._is_inlinable_lambda ( node)
staticprotected
A two-parameter lambda whose body opens no scope of its own, so
renaming its parameters' loads renames every use of them.

◆ _is_map_call()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._is_map_call ( node)
staticprotected

◆ _is_pure_operand()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._is_pure_operand ( node)
staticprotected

◆ _is_unpacking()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._is_unpacking ( node)
staticprotected

◆ _list_call_on()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._list_call_on ( self,
stmt,
name )
protected
The `list(name)` call @p stmt evaluates at most once, or None.

◆ _lower_functools_reduce()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._lower_functools_reduce ( self,
call )
protected
reduce(f, xs[, initial]) -> the left fold functools.reduce performs,
raising its TypeError on an empty sequence without an initial value.
f is called directly at each step, so its argument and result types
are the caller's.

◆ _map_as_listcomp()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._map_as_listcomp ( self,
call )
protected
map(f, xs) -> [f(t) for t in xs], for a map consumed whole, once.

◆ _map_consumer_slot()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._map_consumer_slot ( self,
stmt,
name,
call )
protected
A setter that puts @p call where @p stmt consumes the iterator
@p name whole, once and in a form lowered here or in visit_Call;
None when @p stmt does not.

◆ _map_for_as_plain_for()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._map_for_as_plain_for ( self,
node )
protected
for v in map(f, xs): body -> for t in xs: v = f(t); body.

f is called once per element, when the element is reached, as the
lazy map calls it.

◆ _map_for_lowerable()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._map_for_lowerable ( self,
node,
call )
protected
Whether `for ... in call` can call f per element: f must be a name
the loop does not rebind.

◆ _move_test_prefix_into_body()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._move_test_prefix_into_body ( self,
node,
prefix )
protected
Rewrite `while <test>` as `while True` whose body starts with
`<prefix>; if not <test>: break`, so the statements a comprehension in
the test lowers to run before every evaluation of the test, not once
before the loop. Breaks were already rewritten for while-else, so this
one still lets the else clause run.

◆ _names()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._names ( node,
name )
staticprotected

◆ _resolve_call_origin()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._resolve_call_origin ( self,
node )
protected
Return a deepcopy of ``x``'s tracked Call origin when ``node`` is
the Name ``x``, else return ``node`` unchanged. Refuse the inline
for items-view origins on non-dict receivers — the downstream
cascade only rejects receivers explicitly recorded as non-dict, so
an unannotated user class with .items() would otherwise be rewritten
into a dict-membership check.

◆ _rewrite_map_values()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._rewrite_map_values ( self,
module )
protected
Lower the map() uses whose result is consumed once, in full: as the
value of an unpacking, as a for-loop iterable, and through a name used
only by the next statement. list(map(...)) is lowered in visit_Call.

◆ _scan_functools_reduce_names()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._scan_functools_reduce_names ( self,
module )
protected
Names that can only mean functools.reduce, and names that can only
mean the functools module: each bound once, by its import.

◆ _simplify_isinstance()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._simplify_isinstance ( self,
node )
protected

◆ _transform_list_truthiness()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._transform_list_truthiness ( self,
test_expr,
source_node )
protected

◆ replace_filtered_genexp_arg()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.replace_filtered_genexp_arg ( node)
static
Swap a filtered generator argument for the equivalent list comp.

An eager consumer of a generator drops the generator's `if` clauses on
the C++ side, so `sum(x for x in xs if x > 2)` silently summed every
element. The comprehension lowering keeps the filter, so hand it the
list comprehension instead, as the str.join rewrite already does.

◆ visit_Assert()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_Assert ( self,
node )

◆ visit_Attribute()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_Attribute ( self,
node )

◆ visit_Compare()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_Compare ( self,
node )

◆ visit_Expr()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_Expr ( self,
node )

◆ visit_If()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_If ( self,
node )

◆ visit_Return()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_Return ( self,
node )

◆ visit_Subscript()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_Subscript ( self,
node )

◆ visit_Try()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_Try ( self,
node )

◆ visit_While()

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.visit_While ( self,
node )

Member Data Documentation

◆ _is_pure_operand

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._is_pure_operand
protected

◆ _REDUCE_CALL_STEP

str preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._REDUCE_CALL_STEP = " {acc} = __function({acc}, {seq}[{i}])\n"
staticprotected

◆ _REDUCE_FIRST

str preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._REDUCE_FIRST
staticprotected
Initial value:
= """\
{seq} = list(__iterable)
if len({seq}) == 0:
raise TypeError("reduce() of empty iterable with no initial value")
{acc} = {seq}[0]
for {i} in range(1, len({seq})):
"""

◆ _REDUCE_INITIAL

str preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._REDUCE_INITIAL
staticprotected
Initial value:
= """\
{seq} = list(__iterable)
{acc} = __initial
for {i} in range(0, len({seq})):
"""

◆ _REDUCE_LAMBDA_STEP

str preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._REDUCE_LAMBDA_STEP = " {x} = {acc}\n {y} = {seq}[{i}]\n {acc} = __function\n"
staticprotected

◆ _subscript_inferred_vars

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._subscript_inferred_vars
protected

◆ _SYMMETRIC_EQ_TRANSFORMS

tuple preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin._SYMMETRIC_EQ_TRANSFORMS
staticprotected
Initial value:
= (
"_try_transform_items_set_eq",
"_try_transform_items_list_eq",
"_try_transform_keys_view_eq",
"_try_transform_values_view_eq",
"_try_transform_list_tuple_eq",
)

◆ dict_literal_values

tuple preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.dict_literal_values = (dict(before[0]), dict(before[1]))

◆ early_return_generator_funcs

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.early_return_generator_funcs

◆ functools_module_names

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.functools_module_names = found["module"]

◆ functools_reduce_names

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.functools_reduce_names = found["reduce"]

◆ list_literal_values

preprocessor.expression_rewrite_mixin.ExpressionRewriteMixin.list_literal_values

The documentation for this class was generated from the following file: