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

Classes

class  _Analysis
class  _Rewriter

Functions

 _own_scope_nodes (node)
 _target_names (target)
 _binding_targets (stmt)
 _bound_ids (stmt)
 _untracked_names (node)
 _candidates (func)
 _unconditional_reads (expr, out)
 _head_exprs (stmt)
 _meet (states)
 _flag_assign (name, value)
 _local_error (name)
 _global_error (name)
 _guard (name, error)
 _located (new_nodes, anchor)
 _guard_function (func)
 _module_candidates (module)
 _names_bound_elsewhere (module)
 _guard_module (module)
 guard_unbound_locals (module)

Variables

tuple _NESTED_SCOPES
str _FLAG_PREFIX = "__ESBMC_bound_"

Detailed Description

Raise UnboundLocalError where a function reads a local it may not have bound.

A function-local read is checked against a definite-assignment analysis. A
name some read may reach unbound gets a flag, set at each of its bindings and
tested before that read. A name is left alone when the analysis cannot see all
of its bindings (walrus, except-as, del, import, nested def, match capture,
global/nonlocal) or when a nested scope references it.

Module-level code gets the same check, raising NameError, for a name bound only
by module-level defs, such as a call placed above the def of its function.

Function Documentation

◆ _binding_targets()

preprocessor.unbound_locals._binding_targets ( stmt)
protected
Return the targets a statement binds by a form the analysis tracks.

◆ _bound_ids()

preprocessor.unbound_locals._bound_ids ( stmt)
protected
Return the names a statement binds (an AnnAssign without value binds none).

◆ _candidates()

preprocessor.unbound_locals._candidates ( func)
protected
Return the locals whose every binding the analysis tracks.

◆ _flag_assign()

preprocessor.unbound_locals._flag_assign ( name,
value )
protected

◆ _global_error()

preprocessor.unbound_locals._global_error ( name)
protected

◆ _guard()

preprocessor.unbound_locals._guard ( name,
error )
protected

◆ _guard_function()

preprocessor.unbound_locals._guard_function ( func)
protected

◆ _guard_module()

preprocessor.unbound_locals._guard_module ( module)
protected

◆ _head_exprs()

preprocessor.unbound_locals._head_exprs ( stmt)
protected
Return the expressions a statement evaluates on reaching it.

◆ _local_error()

preprocessor.unbound_locals._local_error ( name)
protected

◆ _located()

preprocessor.unbound_locals._located ( new_nodes,
anchor )
protected

◆ _meet()

preprocessor.unbound_locals._meet ( states)
protected
Intersect the reachable states; None when none is reachable.

◆ _module_candidates()

preprocessor.unbound_locals._module_candidates ( module)
protected
Return the globals bound only by module-level defs the analysis sees.

◆ _names_bound_elsewhere()

preprocessor.unbound_locals._names_bound_elsewhere ( module)
protected
Return the globals a nested scope may bind, or None if any name may be.

◆ _own_scope_nodes()

preprocessor.unbound_locals._own_scope_nodes ( node)
protected
Yield the nodes of a function body, not descending into nested scopes.

◆ _target_names()

preprocessor.unbound_locals._target_names ( target)
protected
Return the Name nodes an assignment target binds.

◆ _unconditional_reads()

preprocessor.unbound_locals._unconditional_reads ( expr,
out )
protected
Collect the names an expression always reads when it is evaluated.

◆ _untracked_names()

preprocessor.unbound_locals._untracked_names ( node)
protected
Return the names a node binds, or hides, in a way the analysis does not see.

◆ guard_unbound_locals()

preprocessor.unbound_locals.guard_unbound_locals ( module)
Make every function in `module` raise UnboundLocalError on an unbound read,
and its module-level code raise NameError on a read of a def not yet run.

Variable Documentation

◆ _FLAG_PREFIX

str preprocessor.unbound_locals._FLAG_PREFIX = "__ESBMC_bound_"
protected

◆ _NESTED_SCOPES

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