ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
preprocessor.itertools_lowering Namespace Reference

Functions

 _bound_names (node)
 _imports (module)
 _itertools_names (module, counts)
 _function (func, names)
 _repeat_operands (call)
 _as_list (call, names)
 _drained (node, counts)
 _drain_once (stmt, name, counts)
 _is_stable (node, rebindable)
 _inline_single_use (block, names, counts, loads, rebindable)
 _blocks (module)
 lower_itertools (module)

Variables

tuple _FUNCTIONS = ("chain", "repeat")
tuple _DRAINS = ("list", "tuple", "sorted", "set", "sum", "min", "max")
tuple _SIMPLE_STATEMENTS = (ast.Assign, ast.AnnAssign, ast.AugAssign, ast.Expr, ast.Assert, ast.Return)
tuple _LOOPING_SCOPES

Detailed Description

Lower itertools.chain, and itertools.repeat with a count, where a builtin
drains the iterator at once (#8377).

`list(chain(a, b))` becomes `list(list(a) + list(b))` and `sum(repeat(x, n))`
becomes `sum([x] * n)`. A drain runs no code of the program between steps, so
the lazy iterator and the list yield the same elements. A name bound to such a
call and read once, by a drain in the next statement, is replaced there by the
call. Any other use is left as written, which the converter refuses.

Function Documentation

◆ _as_list()

preprocessor.itertools_lowering._as_list ( call,
names )
protected
The list expression yielding what `call` iterates, or None.

◆ _blocks()

preprocessor.itertools_lowering._blocks ( module)
protected

◆ _bound_names()

preprocessor.itertools_lowering._bound_names ( node)
protected

◆ _drain_once()

preprocessor.itertools_lowering._drain_once ( stmt,
name,
counts )
protected
The drain call reading `name` in simple statement `stmt`, run once.

◆ _drained()

preprocessor.itertools_lowering._drained ( node,
counts )
protected
The argument a builtin drain call `node` iterates, or None.

◆ _function()

preprocessor.itertools_lowering._function ( func,
names )
protected

◆ _imports()

preprocessor.itertools_lowering._imports ( module)
protected
(bound name, function or None for the module) per top-level import
from itertools.

◆ _inline_single_use()

preprocessor.itertools_lowering._inline_single_use ( block,
names,
counts,
loads,
rebindable )
protected

◆ _is_stable()

preprocessor.itertools_lowering._is_stable ( node,
rebindable )
protected
Whether `node` reads the same value later in the next statement.

◆ _itertools_names()

preprocessor.itertools_lowering._itertools_names ( module,
counts )
protected
The names bound once, by a top-level import, to the itertools module
and to its modelled functions.

◆ _repeat_operands()

preprocessor.itertools_lowering._repeat_operands ( call)
protected

◆ lower_itertools()

preprocessor.itertools_lowering.lower_itertools ( module)
Lower the drained itertools iterators of `module` to lists.

Variable Documentation

◆ _DRAINS

tuple preprocessor.itertools_lowering._DRAINS = ("list", "tuple", "sorted", "set", "sum", "min", "max")
protected

◆ _FUNCTIONS

tuple preprocessor.itertools_lowering._FUNCTIONS = ("chain", "repeat")
protected

◆ _LOOPING_SCOPES

tuple preprocessor.itertools_lowering._LOOPING_SCOPES
protected
Initial value:
1= (ast.FunctionDef, ast.AsyncFunctionDef, ast.Lambda, ast.ListComp, ast.SetComp,
2 ast.DictComp, ast.GeneratorExp)

◆ _SIMPLE_STATEMENTS

tuple preprocessor.itertools_lowering._SIMPLE_STATEMENTS = (ast.Assign, ast.AnnAssign, ast.AugAssign, ast.Expr, ast.Assert, ast.Return)
protected