ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
converter_stmt.cpp File Reference
#include <boost/algorithm/string/predicate.hpp>
#include <python-frontend/converter/converter_internal.h>
#include <python-frontend/math/convert_float_literal.h>
#include <python-frontend/function_call/expr.h>
#include <python-frontend/json_utils.h>
#include <python-frontend/consteval/python_consteval.h>
#include <python-frontend/python_converter.h>
#include <python-frontend/python_expr_builder.h>
#include <python-frontend/python-dict/python_dict_handler.h>
#include <python-frontend/python_annotation/python_annotation.h>
#include <python-frontend/exception/python_exception_handler.h>
#include <python-frontend/lambda/python_lambda.h>
#include <python-frontend/python-list/python_list.h>
#include <python-frontend/type/python_typechecking.h>
#include <python-frontend/math/python_math.h>
#include <python-frontend/string/string_builder.h>
#include <python-frontend/string/string_handler.h>
#include <python-frontend/symbol_id.h>
#include <python-frontend/tuple/tuple_handler.h>
#include <python-frontend/dynamic_type/dynamic_type_handler.h>
#include <python-frontend/dynamic_type/literal_divergence.h>
#include <python-frontend/type/type_handler.h>
#include <python-frontend/type/type_utils.h>
#include <irep2/irep2_utils.h>
#include <util/arith/arith_tools.h>
#include <util/expr/base_type.h>
#include <util/arith/bitvector.h>
#include <util/lang/c_expr2string.h>
#include <util/lang/c_typecast.h>
#include <util/lang/c_types.h>
#include <util/config/config.h>
#include <util/base/encoding.h>
#include <util/expr/expr_util.h>
#include <util/irep/irep.h>
#include <util/message/message.h>
#include <util/irep/migrate.h>
#include <util/lang/python_types.h>
#include <util/irep/std_code.h>
#include <util/expr/string_constant.h>
#include <util/expr/symbolic_types.h>
#include <algorithm>
#include <array>
#include <functional>
#include <numeric>
#include <stdexcept>
Include dependency graph for converter_stmt.cpp:

Functions

bool is_imported_numpy_module_alias (const nlohmann::json &ast, const std::string &name)
static bool convert_scalar_rhs (const typet &lhs_type, exprt &rhs)
static bool names_builtin (const std::string &spelling, const char *lower, const char *upper, const nlohmann::json &ast)
 True when spelling names the built-in lower / upper and no user-defined class of that name shadows it.
static bool is_scalar_pointee (const typet &ptr)
static bool names_classes (const nlohmann::json &value, const nlohmann::json &ast, std::vector< std::string > &classes)
static const nlohmann::json * assigned_name (const nlohmann::json &node)
static size_t class_assignments (const nlohmann::json &node, const std::string &name, const nlohmann::json &ast, std::vector< std::string > &classes)
static bool json_contains_slice_node (const nlohmann::json &node)
static bool json_literal_contains_boolean (const nlohmann::json &node)
static bool is_shape_attribute_value (const nlohmann::json &subscript_value)
static bool is_method_call_node_shape (const nlohmann::json &call_node)
static const nlohmann::json & first_assign_target (const nlohmann::json &ast_node)
static exprt build_numpy_descriptor_array_value (const std::vector< std::size_t > &shape, const std::vector< exprt > &elems, const typet &elem_type, type_handler &type_handler)
static bool expr_only_references_safe_names (const nlohmann::json &node, const std::function< bool(const std::string &)> &name_is_safe)
static nlohmann::json resolve_func_node_with_params (const nlohmann::json &call_node, const nlohmann::json &ast_body)
static bool is_parameter_name (const nlohmann::json &node, const nlohmann::json &params)
static bool is_parameter_arithmetic (const nlohmann::json &node, const nlohmann::json &params)
static bool is_module_level_import_alias (const nlohmann::json &ast_body, const std::string &alias)
static void constant_view_layout (const std::vector< std::size_t > &view_shape, std::size_t length, const std::vector< long long > &view_strides, long long stride, std::vector< long long > &shape, std::vector< long long > &strides)
static std::optional< std::string > nested_subscript_root_name (const nlohmann::json &node)
static std::size_t fixed_array_depth (const typet &type, const namespacet &ns)
static std::string ast_node_name (const nlohmann::json &node, const std::string &fallback="")
 The bare name an AST node denotes: id for a Name, attr for an Attribute – a qualified module.Class, which is what a base inherited from an operational model looks like.
static void copy_homogeneous_elem_types (element_type_registry &registry, const std::string &src, const std::string &dest)
 Replace dest's recorded element types with src's, but only when every one of src's entries has the same type.
static bool is_name (const nlohmann::json &node, const std::string &name)
static bool any_child (const nlohmann::json &node, const std::string &name, bool(*pred)(const nlohmann::json &, const std::string &))
static bool is_plain_rebind (const nlohmann::json &node, const std::string &name)
 name = v, name: T = v or name op= v: the forms whose target resolves through redirect_nonlocal.
static bool binds_by_field (const nlohmann::json &node, const std::string &name)
 Whether node binds name through a string field: a def, class, except handler, import alias or match capture.
static bool binds_name_otherwise (const nlohmann::json &node, const std::string &name)
 Whether node binds name other than by a plain rebind.
static bool mentions_name (const nlohmann::json &node, const std::string &name)
static bool used_uncalled (const nlohmann::json &node, const std::string &func)
 Whether node uses func other than by calling it, so that it may run after the frame owning its nonlocal names has returned.
static bool is_read_in_other_scope (const nlohmann::json &node, const std::string &name, const std::string &current, bool nested)
static bool is_read_in_other_scope_of_children (const nlohmann::json &node, const std::string &name, const std::string &current, bool nested)
static std::string assign_target_name (const nlohmann::json &ast_node)
 The name a single-target Assign/AnnAssign binds, as assigned_name spells it, or "".
static bool may_tag_binop (const nlohmann::json &value, const dynamic_type_handler &handler)
static bool ctor_arms_are_spellable (const nlohmann::json &ifexp, const std::string &then_class, const std::string &else_class)
static bool is_name_or_attribute (const std::string &kind)
static void fit_numpy_string_store (const exprt &lhs, exprt &rhs)
static const nlohmann::json * copied_node (const nlohmann::json &value, const nlohmann::json &ast)
static const typet & common_array_type (const typet &a, const typet &b)
typet resolve_ternary_type (const typet &then_type, const typet &else_type, const typet &default_type)
static std::optional< bool > constant_string_is_empty (const exprt &str)
static exprt coerce_ternary_branch (const exprt &branch, const typet &result_type, string_handler &strings)
static std::string unsupported_statement_message (const nlohmann::json &element)
static typet numpy_typed_shape (const type_handler &types, const nlohmann::json &arr, const typet &element)
static exprt as_numpy_element (const exprt &value, const typet &element)

Function Documentation

◆ any_child()

bool any_child ( const nlohmann::json & node,
const std::string & name,
bool(* pred )(const nlohmann::json &, const std::string &) )
static

◆ as_numpy_element()

exprt as_numpy_element ( const exprt & value,
const typet & element )
static

◆ assign_target_name()

std::string assign_target_name ( const nlohmann::json & ast_node)
static

The name a single-target Assign/AnnAssign binds, as assigned_name spells it, or "".

◆ assigned_name()

const nlohmann::json * assigned_name ( const nlohmann::json & node)
static

◆ ast_node_name()

std::string ast_node_name ( const nlohmann::json & node,
const std::string & fallback = "" )
static

The bare name an AST node denotes: id for a Name, attr for an Attribute – a qualified module.Class, which is what a base inherited from an operational model looks like.

fallback covers any other shape.

◆ binds_by_field()

bool binds_by_field ( const nlohmann::json & node,
const std::string & name )
static

Whether node binds name through a string field: a def, class, except handler, import alias or match capture.

◆ binds_name_otherwise()

bool binds_name_otherwise ( const nlohmann::json & node,
const std::string & name )
static

Whether node binds name other than by a plain rebind.

Nested defs, classes and lambdas are scopes of their own.

◆ build_numpy_descriptor_array_value()

exprt build_numpy_descriptor_array_value ( const std::vector< std::size_t > & shape,
const std::vector< exprt > & elems,
const typet & elem_type,
type_handler & type_handler )
static

◆ class_assignments()

size_t class_assignments ( const nlohmann::json & node,
const std::string & name,
const nlohmann::json & ast,
std::vector< std::string > & classes )
static

◆ coerce_ternary_branch()

exprt coerce_ternary_branch ( const exprt & branch,
const typet & result_type,
string_handler & strings )
static

◆ common_array_type()

const typet & common_array_type ( const typet & a,
const typet & b )
static

◆ constant_string_is_empty()

std::optional< bool > constant_string_is_empty ( const exprt & str)
static

◆ constant_view_layout()

void constant_view_layout ( const std::vector< std::size_t > & view_shape,
std::size_t length,
const std::vector< long long > & view_strides,
long long stride,
std::vector< long long > & shape,
std::vector< long long > & strides )
static

◆ convert_scalar_rhs()

bool convert_scalar_rhs ( const typet & lhs_type,
exprt & rhs )
static

◆ copied_node()

const nlohmann::json * copied_node ( const nlohmann::json & value,
const nlohmann::json & ast )
static

◆ copy_homogeneous_elem_types()

void copy_homogeneous_elem_types ( element_type_registry & registry,
const std::string & src,
const std::string & dest )
static

Replace dest's recorded element types with src's, but only when every one of src's entries has the same type.

sorted()/reversed() permute their argument, so a per-position copy would misattribute the elements of a heterogeneous list; a homogeneous one is permutation-invariant.

◆ ctor_arms_are_spellable()

bool ctor_arms_are_spellable ( const nlohmann::json & ifexp,
const std::string & then_class,
const std::string & else_class )
static

◆ expr_only_references_safe_names()

bool expr_only_references_safe_names ( const nlohmann::json & node,
const std::function< bool(const std::string &)> & name_is_safe )
static

◆ first_assign_target()

const nlohmann::json & first_assign_target ( const nlohmann::json & ast_node)
static

◆ fit_numpy_string_store()

void fit_numpy_string_store ( const exprt & lhs,
exprt & rhs )
static

◆ fixed_array_depth()

std::size_t fixed_array_depth ( const typet & type,
const namespacet & ns )
static

◆ is_imported_numpy_module_alias()

bool is_imported_numpy_module_alias ( const nlohmann::json & ast,
const std::string & name )

◆ is_method_call_node_shape()

bool is_method_call_node_shape ( const nlohmann::json & call_node)
static

◆ is_module_level_import_alias()

bool is_module_level_import_alias ( const nlohmann::json & ast_body,
const std::string & alias )
static

◆ is_name()

bool is_name ( const nlohmann::json & node,
const std::string & name )
static

◆ is_name_or_attribute()

bool is_name_or_attribute ( const std::string & kind)
static

◆ is_parameter_arithmetic()

bool is_parameter_arithmetic ( const nlohmann::json & node,
const nlohmann::json & params )
static

◆ is_parameter_name()

bool is_parameter_name ( const nlohmann::json & node,
const nlohmann::json & params )
static

◆ is_plain_rebind()

bool is_plain_rebind ( const nlohmann::json & node,
const std::string & name )
static

name = v, name: T = v or name op= v: the forms whose target resolves through redirect_nonlocal.

◆ is_read_in_other_scope()

bool is_read_in_other_scope ( const nlohmann::json & node,
const std::string & name,
const std::string & current,
bool nested )
static

◆ is_read_in_other_scope_of_children()

bool is_read_in_other_scope_of_children ( const nlohmann::json & node,
const std::string & name,
const std::string & current,
bool nested )
static

◆ is_scalar_pointee()

bool is_scalar_pointee ( const typet & ptr)
static

◆ is_shape_attribute_value()

bool is_shape_attribute_value ( const nlohmann::json & subscript_value)
static

◆ json_contains_slice_node()

bool json_contains_slice_node ( const nlohmann::json & node)
static

◆ json_literal_contains_boolean()

bool json_literal_contains_boolean ( const nlohmann::json & node)
static

◆ may_tag_binop()

bool may_tag_binop ( const nlohmann::json & value,
const dynamic_type_handler & handler )
static

◆ mentions_name()

bool mentions_name ( const nlohmann::json & node,
const std::string & name )
static

◆ names_builtin()

bool names_builtin ( const std::string & spelling,
const char * lower,
const char * upper,
const nlohmann::json & ast )
static

True when spelling names the built-in lower / upper and no user-defined class of that name shadows it.

◆ names_classes()

bool names_classes ( const nlohmann::json & value,
const nlohmann::json & ast,
std::vector< std::string > & classes )
static

◆ nested_subscript_root_name()

std::optional< std::string > nested_subscript_root_name ( const nlohmann::json & node)
static

◆ numpy_typed_shape()

typet numpy_typed_shape ( const type_handler & types,
const nlohmann::json & arr,
const typet & element )
static

◆ resolve_func_node_with_params()

nlohmann::json resolve_func_node_with_params ( const nlohmann::json & call_node,
const nlohmann::json & ast_body )
static

◆ resolve_ternary_type()

typet resolve_ternary_type ( const typet & then_type,
const typet & else_type,
const typet & default_type )

◆ unsupported_statement_message()

std::string unsupported_statement_message ( const nlohmann::json & element)
static

◆ used_uncalled()

bool used_uncalled ( const nlohmann::json & node,
const std::string & func )
static

Whether node uses func other than by calling it, so that it may run after the frame owning its nonlocal names has returned.

Another nested scope may itself outlive the frame, so any mention there counts.