80 const nlohmann::json *
ast,
82 const std::vector<nlohmann::json> *extra_asts =
nullptr);
91 is_converting_rhs =
value;
99 current_func_name_ = name;
103 current_element_type = type;
107 return symbol_table_.move_symbol_to_context(symbol);
111 const nlohmann::json &target,
117 return current_func_name_;
126 const std::string &var_name,
127 const nlohmann::json &element);
141 const std::string &op,
144 const nlohmann::json &element);
146 std::string
get_op(
const std::string &op,
const typet &type)
const;
150 const nlohmann::json &annotation,
151 const nlohmann::json &stmt);
156 const std::string &name,
157 const nlohmann::json &return_node,
158 const nlohmann::json &function_node);
165 const nlohmann::json &element,
173 const nlohmann::json &element,
188 const nlohmann::json &annotation_node,
189 const nlohmann::json &element);
200 return dict_handler_;
205 return *exception_handler_;
210 return *exception_handler_;
215 return math_handler_;
220 return complex_handler_;
225 return string_handler_;
230 return *tuple_handler_;
233 const nlohmann::json &
ast()
const
240 return symbol_table_;
245 return type_handler_;
250 return element_type_registry_;
255 return element_type_registry_;
262 call_escaped_lists_.insert(
id);
267 return call_escaped_lists_.find(
id) != call_escaped_lists_.end();
277 deferred_checks_.push_back(std::move(check));
284 return current_python_file;
289 return main_python_file;
294 return current_func_name_;
299 return current_class_name_;
313 return function_call_cache_;
318 return function_call_cache_;
323 symbol_table_.add(s);
329 current_block->copy_to_operands(expr);
351 exprt *outer_lhs = current_lhs;
352 bool outer_is_converting_rhs = is_converting_rhs;
353 bool outer_is_converting_lhs = is_converting_lhs;
354 const nlohmann::json *outer_store_target = lhs_store_target_;
355 typet outer_element_type = current_element_type;
356 get_var_assign(ast_node, *current_block);
357 current_lhs = outer_lhs;
358 is_converting_rhs = outer_is_converting_rhs;
359 is_converting_lhs = outer_is_converting_lhs;
360 lhs_store_target_ = outer_store_target;
361 current_element_type = outer_element_type;
375 return !converting_lambda_body_ && !in_rhs_type_probe_ &&
376 !in_contract_clause_;
400 const nlohmann::json &lambda_node,
401 const std::string &lambda_id,
407 const exprt &operand,
408 const nlohmann::json &element,
409 const std::string &prefix);
418 const std::string &attr_name,
419 const nlohmann::json &element,
420 bool is_self =
false);
428 const std::string &exception,
429 const std::string &message,
435 const nlohmann::json &element);
443 const nlohmann::json &element);
450 const nlohmann::json &element,
451 bool reject_none =
false);
457 const std::string &message,
458 const nlohmann::json &element);
463 const nlohmann::json &
value);
478 return retype_aliases_.count(
id.as_string()) > 0;
499 const nlohmann::json &
module,
504 const std::string &name,
505 const nlohmann::json &use);
510 const nlohmann::json &receiver,
511 const nlohmann::json &use)
const;
515 const std::string &module_name,
516 const nlohmann::json &receiver,
517 const nlohmann::json &use)
const;
523 if (imported_modules.find(module_name) != imported_modules.end())
524 return imported_modules.at(module_name);
530 const std::string &
module,
531 const std::string &name,
532 const std::string &
id,
534 const typet &type)
const;
543 const std::string &name,
562 const std::string &op,
575 const nlohmann::json &ast_node);
595 const nlohmann::json &from,
596 nlohmann::json &to)
const;
599 const std::string &op,
602 const nlohmann::json &element);
607 const nlohmann::json &element,
614 const nlohmann::json &element);
617 const std::string &op,
622 const nlohmann::json &element);
631 return std::exchange(in_contract_clause_, in_contract_clause_ || entering);
635 in_contract_clause_ = saved;
639 return in_contract_clause_;
643 return current_block ? current_block->operands().size() : 0;
651 auto it = class_object_names_.find(
id);
652 return it == class_object_names_.end() ? nullptr : &it->second;
660 const nlohmann::json &element,
661 const std::string &prefix,
662 const std::function<
void(
const expr2tc &,
const locationt &)> &emit_guards);
684 template <
typename Func>
685 decltype(
auto) with_ast(
const nlohmann::json *
new_ast, Func &&f)
687 const nlohmann::json *old_ast = ast_json;
696 void get_var_assign(
const nlohmann::json &ast_node,
codet &target_block);
698 void preregister_global_variables(
const nlohmann::json &ast_body);
705 std::string annotated_optional_class(
const nlohmann::json &annotation)
const;
708 resolve_variable_type(
const std::string &var_name,
const locationt &loc);
710 void get_compound_assign(
const nlohmann::json &ast_node,
codet &target_block);
715 symbolt *find_symbol_in_enclosing_scopes(
const std::string &name);
717 symbolt *resolve_subscript_base_symbol(
718 const nlohmann::json &target,
719 const std::string &name,
724 void mark_augassign_list_escaped(
const exprt &lhs,
const exprt &rhs);
727 get_return_statements(
const nlohmann::json &ast_node,
codet &target_block);
728 void get_return_with_conditional_spelling(
729 const nlohmann::json &ast_node,
730 codet &target_block);
732 void get_function_definition(
const nlohmann::json &function_node);
739 exprt dispatch_mismatched_callees(
741 const nlohmann::json &call,
744 exprt get_function_body_or_unsupported(
const nlohmann::json &function_node);
748 static exprt hoist_local_declarations(
exprt body);
750 bool function_may_be_called(
const nlohmann::json &function_node)
const;
753 get_class_definition(
const nlohmann::json &class_node,
codet &target_block);
755 exprt get_unary_operator_expr(
const nlohmann::json &element);
759 exprt get_named_expr(
const nlohmann::json &element);
765 static bool contains_named_expr(
const nlohmann::json &node);
768 static bool contains_nested_scope_named_expr(
const nlohmann::json &node);
770 exprt get_binary_operator_expr(
const nlohmann::json &element);
772 std::optional<exprt> try_bound_method_compare(
const nlohmann::json &element);
775 std::optional<std::pair<exprt, std::string>>
776 bound_method_operand(
const nlohmann::json &operand);
777 exprt get_binary_operator_expr(
778 const nlohmann::json &element,
779 const nlohmann::json &left,
780 const nlohmann::json &right,
781 const std::string &op,
785 keep_operand_calls(
const exprt &result,
const exprt &lhs,
const exprt &rhs);
791 exprt checked_erased_int(
793 const nlohmann::json &node,
794 const nlohmann::json &element);
796 exprt get_right_operand_expr(
797 const nlohmann::json &element,
798 const nlohmann::json &right,
800 exprt build_division_guarded_binop(
801 const std::string &op,
804 const nlohmann::json &element);
805 exprt build_arithmetic_binop(
806 const std::string &op,
809 const nlohmann::json &element);
812 percent_arg_types(
const nlohmann::json &right,
const exprt &rhs)
const;
815 exprt get_fstring_in_order(
const nlohmann::json &joined);
818 exprt get_percent_format_expr(
819 const nlohmann::json &left,
820 const std::vector<nlohmann::json> &args,
821 const std::map<std::string, nlohmann::json> &mapping,
822 const std::vector<typet> &arg_types);
834 std::string get_python_type_category(
const typet &t)
const;
836 bool is_bytes_literal(
const nlohmann::json &element);
843 const nlohmann::json &left,
844 const nlohmann::json &right);
846 exprt get_binary_operator_expr_for_is(
849 const nlohmann::json &left,
850 const nlohmann::json &right);
852 exprt get_negated_is_expr(
855 const nlohmann::json &left,
856 const nlohmann::json &right);
860 exprt get_function_constant_return(
const exprt &func_value);
862 exprt resolve_function_call(
const exprt &func_expr,
const exprt &args_expr);
864 exprt get_lambda_expr(
865 const nlohmann::json &element,
866 const std::vector<std::optional<typet>> &argument_types = {});
870 std::string remove_quotes_from_type_string(
const std::string &type_string);
872 bool function_has_missing_return_paths(
const nlohmann::json &function_node);
874 bool function_is_generator(
const nlohmann::json &function_node);
876 exprt materialize_list_function_call(
878 const nlohmann::json &element,
879 codet &target_block);
881 std::optional<typet> call_dict_value_type(
const nlohmann::json &call);
883 symbolt create_return_temp_variable(
884 const typet &return_type,
885 const locationt &location,
886 const std::string &func_name);
893 exprt box_value_on_heap(
895 const locationt &location,
896 codet &target_block);
901 exprt box_value_on_heap(
903 const locationt &location,
905 const typet &ptr_type);
907 void register_instance_attribute(
908 const std::string &symbol_id,
909 const std::string &attr_name,
910 const std::string &var_name,
911 const std::string &class_tag);
916 void reject_maybe_unset_instance_attr(
917 bool instance_written,
918 const symbolt &symbol,
919 const std::string &var_name,
920 const std::string &attr_name,
921 const std::string &obj_type_name);
923 bool is_instance_attribute(
924 const std::string &symbol_id,
925 const std::string &attr_name,
926 const std::string &var_name,
927 const std::string &class_tag);
929 exprt create_member_expression(
930 const symbolt &symbol,
931 const std::string &attr_name,
932 const typet &attr_type);
934 typet clean_attribute_type(
const typet &attr_type);
936 std::string create_normalized_self_key(
const std::string &class_tag);
938 std::string extract_class_name_from_tag(
const std::string &tag_name);
942 symbolt *find_class_attribute_symbol(
943 const std::string &class_name,
944 const std::string &attr_name);
949 std::vector<dynamic_type_detail::numeric_bindingt> scope_numeric_bindings(
950 const std::string &name,
952 bool include_later)
const;
954 void reject_inexact_number_join(
955 const nlohmann::json &element,
956 const exprt &expr)
const;
960 std::string class_name_of(
const typet &t);
966 bool is_user_class_struct_type(
const typet &t);
972 bool is_heap_migrated_class_type(
const typet &t);
978 bool is_user_class_pointer(
const typet &t);
983 void retype_placeholder_to_class(symbolt &sym,
const typet &new_type);
985 exprt resolve_identity_function_call(
986 const exprt &func_expr,
987 const exprt &args_expr);
989 bool is_identity_function(
990 const exprt &func_value,
991 const std::string &func_identifier);
993 exprt handle_none_comparison(
994 const std::string &op,
1000 exprt handle_none_operand(
1001 const std::string &op,
1005 void raise_on_optional_none(
1006 const std::string &op,
1007 const exprt &lhs_none,
1008 const exprt &rhs_none,
1011 const nlohmann::json &element);
1018 exprt try_lower_slice_member_is_none(
1019 const std::string &op,
1023 symbolt &create_tmp_symbol(
1024 const nlohmann::json &element,
1025 const std::string var_name,
1026 const typet &symbol_type,
1027 const exprt &symbol_value);
1032 symbolt &create_tmp_symbol(
1033 const locationt &location,
1034 const std::string var_name,
1035 const typet &symbol_type,
1036 const exprt &symbol_value);
1038 exprt get_logical_operator_expr(
const nlohmann::json &element);
1040 exprt get_boolop_operand(
1041 const nlohmann::json &operand,
1042 std::vector<code_blockt> &effects);
1044 exprt lower_short_circuit_boolop(
1045 const exprt &logical_expr,
1046 const std::vector<code_blockt> &effects,
1047 const std::function<exprt(
const exprt &)> &truthy,
1048 const nlohmann::json &element);
1050 exprt emit_guarded_boolop(
1051 const exprt &logical_expr,
1052 const std::vector<code_blockt> &effects,
1053 const std::function<exprt(
const exprt &)> &truthy,
1054 const locationt &location);
1060 exprt get_flat_boolop_test(
1061 const nlohmann::json &test_node,
1062 const std::function<exprt(
const exprt &,
const nlohmann::json &)> &to_bool);
1064 exprt get_conditional_stm(
const nlohmann::json &ast_node);
1077 bool rewrite_divergent_conditional_assign(
1078 const nlohmann::json &ast_node,
1079 codet &target_block);
1081 std::string instantiated_class(
const nlohmann::json &
value)
const;
1083 bool ternary_needs_if_spelling(
const nlohmann::json &ifexp)
const;
1084 void reject_divergent_attribute_classes(
1085 const nlohmann::json &target,
1086 const nlohmann::json &ifexp)
const;
1088 bool is_coverage_mode()
const;
1090 bool is_assert_fold_disabled()
const;
1092 bool is_pytest_generation_mode()
const;
1094 bool is_model_file(
const nlohmann::json &node)
const;
1101 bool is_program_file(
const std::string &file)
const;
1103 exprt get_function_call(
const nlohmann::json &ast_block);
1106 exprt get_call_expr(
const nlohmann::json &element);
1111 exprt get_len_on_class_instance(
const nlohmann::json &element);
1112 static bool is_pure_read(
const nlohmann::json &node);
1114 get_len_on_list_element(
const nlohmann::json &arg,
const locationt &location);
1115 static exprt list_element_type_id(
const exprt &
value);
1116 std::size_t count_user_classes();
1117 exprt checked_len_result(
const exprt &len_call,
const locationt &location);
1123 std::optional<exprt>
1124 try_get_numpy_pointer_view_len(
const nlohmann::json &element);
1125 std::optional<exprt>
1126 try_get_numpy_named_pointer_view_len(
const nlohmann::json &arg)
const;
1127 std::optional<exprt> try_get_numpy_subscript_pointer_view_len(
1128 const nlohmann::json &arg,
1129 const nlohmann::json &element);
1139 std::optional<exprt> try_get_numpy_pointer_view_shape_attr(
1140 const symbolt &symbol,
1141 const std::string &attr_name);
1149 std::optional<exprt> try_get_numpy_param_shape_attr(
1150 const symbolt &symbol,
1151 const std::string &attr_name);
1157 std::optional<exprt>
1158 try_get_numpy_shape_attr(
const symbolt &symbol,
const std::string &attr_name);
1160 std::optional<std::vector<std::size_t>>
1161 tracked_numpy_shape_from_name(
const std::string &name)
const;
1163 std::optional<std::vector<std::size_t>>
1164 numpy_shape_from_indexed_decl(
const std::string &name)
const;
1166 exprt numpy_shape_attr_expr(
1167 const std::vector<std::size_t> &shape,
1168 const std::string &attr_name);
1170 std::optional<std::vector<std::size_t>>
1171 get_numpy_constructor_shape(
const nlohmann::json &node)
const;
1173 std::optional<exprt> try_get_numpy_value_shape_attr(
1174 const exprt &base_expr,
1175 const nlohmann::json &base_node,
1176 const std::string &attr_name);
1178 std::optional<exprt>
1179 try_get_numpy_shape_subscript(
const nlohmann::json &element)
const;
1181 std::optional<exprt> try_get_numpy_tracked_value_shape_attr(
1182 const exprt &base_expr,
1183 const nlohmann::json &base_node,
1184 const std::string &attr_name);
1186 void reject_numpy_shape_attr_on_nonobject_call_result(
1187 const exprt &base_expr,
1188 const nlohmann::json &base_node,
1189 const std::string &attr_name);
1191 bool should_reject_numpy_shape_attr_on_symbol(
1192 const symbolt &symbol,
1193 const std::string &attr_name);
1195 std::optional<exprt> try_get_numpy_bool_mask_rows_shape_attr(
1196 const exprt &base_expr,
1198 const std::string &attr_name);
1201 const nlohmann::json &ast_block,
1202 bool is_function_body =
false,
1203 bool is_loop_body =
false);
1205 exprt get_static_array(
const nlohmann::json &arr,
const typet &shape);
1207 void adjust_statement_types(exprt &lhs, exprt &rhs)
const;
1209 symbol_id create_symbol_id()
const;
1223 void find_entry_function(
1224 const std::string &target,
1225 nlohmann::json &node,
1226 std::string &owning_class)
const;
1228 symbol_id create_symbol_id(
const std::string &filename)
const;
1230 void promote_int_to_float(exprt &op,
const typet &target_type)
const;
1232 void handle_float_division(exprt &lhs, exprt &rhs, exprt &bin_expr)
const;
1234 exprt get_tuple_expr(
const nlohmann::json &element);
1243 exprt build_slice_object(
const nlohmann::json &slice_node);
1252 exprt build_slice_from_args(
1253 const nlohmann::json &args,
1254 const nlohmann::json &source_node);
1256 std::pair<exprt, exprt>
1257 resolve_comparison_operands_internal(
const exprt &lhs,
const exprt &rhs);
1260 has_unsupported_side_effects_internal(
const exprt &lhs,
const exprt &rhs);
1262 TypeFlags infer_types_from_returns(
const nlohmann::json &function_body);
1264 void process_function_arguments(
1265 const nlohmann::json &function_node,
1267 const symbol_id &
id,
1268 const locationt &location);
1274 void track_numpy_param(
1275 const std::string &arg_id,
1276 const std::optional<std::vector<std::size_t>> &numpy_param_full_shape,
1277 bool numpy_array_param,
1278 const typet &array_type);
1282 exprt numpy_param_as_array(
const exprt &operand)
const;
1283 exprt snapshot_left_operand(
1284 const nlohmann::json &left,
1286 const nlohmann::json &right);
1287 bool may_rebind_left(
1288 const nlohmann::json &left,
1290 const nlohmann::json &right)
const;
1291 bool calls_user_code(
const nlohmann::json &node)
const;
1293 materialize_numpy_arithmetic(
const nlohmann::json &node,
const exprt &
value);
1294 std::optional<std::vector<std::size_t>>
1295 numpy_param_shape(
const std::string &symbol_id)
const;
1297 size_t register_function_argument(
1298 const nlohmann::json &element,
1300 const symbol_id &
id,
1301 const locationt &location,
1302 bool is_keyword_only);
1315 code_blockt create_capture_cells(
1316 const nlohmann::json &function_node,
1317 const symbol_id &
id,
1318 const locationt &location);
1320 code_blockt bind_capture_cells(
1321 const std::set<std::string> &free_names,
1322 const std::string &enclosing_scope,
1323 const std::string &func_id,
1324 const locationt &location);
1328 code_blockt pending_captures_;
1332 const nlohmann::json *enclosing_function_node_ =
nullptr;
1352 bool try_infer_numpy_param_type(
1353 const std::string &func_name,
1356 std::set<std::string> &visiting)
const;
1366 std::optional<typet> try_infer_numpy_array_arg_type(
1367 const nlohmann::json &arg,
1368 const nlohmann::json &module_body)
const;
1376 bool try_infer_dynamic_param_type(
1377 const std::string &callee,
1378 const std::string ¶m_name,
1379 size_t param_index)
const;
1381 typet ctor_param_attr_type(
1382 const std::vector<const nlohmann::json *> &module_bodies,
1383 const std::string &class_name,
1384 const std::string ¶m_name,
1385 int param_idx)
const;
1387 void reject_one_sided_tagged_store(
const exprt &lhs,
const exprt &rhs)
const;
1397 bool infer_bytes_param_size_from_call_sites(
1398 const std::string &func_name,
1400 long long &out_size)
const;
1401 bool infer_bytes_param_size_from_call_sites(
1402 const std::string &func_name,
1404 long long &out_size,
1405 std::set<std::string> &visiting)
const;
1410 std::optional<long long> resolve_forwarded_bytes_param_size(
1411 const nlohmann::json &arg,
1412 const nlohmann::json &module_body,
1413 const std::string &enclosing_function,
1414 std::set<std::string> &visiting)
const;
1420 std::optional<long long> resolve_bytes_call_site_arg_size(
1421 const std::string &enclosing_function,
1422 const nlohmann::json &call,
1424 const nlohmann::json &module_body,
1425 std::set<std::string> &visiting)
const;
1431 std::optional<typet> try_infer_bytes_param_size(
1432 const std::string &arg_name,
1433 const typet &arg_type,
1434 const symbol_id &
id,
1435 size_t param_index)
const;
1437 void validate_return_paths(
1438 const nlohmann::json &function_node,
1439 const code_typet &type,
1440 exprt &function_body);
1442 exprt compare_constants_internal(
1443 const std::string &op,
1447 exprt handle_indexed_comparison_internal(
1448 const std::string &op,
1452 exprt handle_type_mismatches(
1453 const std::string &op,
1458 any_attribute_type(
const nlohmann::json &stmt,
const std::string &attr_name);
1459 void get_attributes_from_self(
1460 const nlohmann::json &func_node,
1461 struct_typet &clazz);
1468 typet infer_attr_type_from_usage(
1469 const std::string &class_name,
1470 const std::string &attr_name);
1473 std::vector<const nlohmann::json *> reachable_module_bodies()
const;
1478 typet none_attribute_type(
const std::string &attr_name)
const;
1480 bool held_by_reference(
1481 bool rhs_is_aliased_name,
1482 const std::string &attr_name,
1484 const std::string &annotated_type)
const;
1489 mutable std::set<std::string> untyped_none_attributes_;
1490 mutable std::set<std::string> none_flagged_attributes_;
1492 void add_none_flag_component(
1493 struct_typet &clazz,
1494 const std::string &attr_name)
const;
1495 exprt none_flag_of_attribute(
const exprt &operand)
const;
1496 void guard_none_attribute_operands(
1497 const std::string &op,
1498 const nlohmann::json &left,
1499 const nlohmann::json &right,
1502 const nlohmann::json &element);
1505 const nlohmann::json &ast_node,
1506 codet &target_block)
const;
1524 typet infer_tuple_struct_from_value(
1525 const nlohmann::json &value_node,
1526 const std::unordered_map<std::string, nlohmann::json> ¶m_annotations);
1528 exprt get_return_from_func(
const char *func_symbol_id);
1530 void create_builtin_symbols();
1532 bool import_module_into_block(
1533 const nlohmann::json &import_node,
1534 module_locator &locator,
1537 bool import_one_module(
1538 const nlohmann::json &import_node,
1539 module_locator &locator,
1542 std::vector<const nlohmann::json *>
1543 import_nodes(std::deque<nlohmann::json> &submodules)
const;
1545 std::string module_source_file(
1546 const std::string &module,
1547 const module_locator &locator)
const;
1552 std::vector<nlohmann::json> submodule_imports(
1553 const nlohmann::json &import_node,
1554 const module_locator &locator)
const;
1558 void register_import_alias(
1559 const nlohmann::json &import_node,
1560 const std::string &module_file);
1569 void convert_module_imports(code_blockt &all_imports_block);
1578 void convert_extra_translation_unit(
1579 const nlohmann::json &extra_ast,
1580 code_blockt &init_code,
1581 code_blockt &combined_user_code);
1583 nlohmann::json build_dunder_call(
1584 const nlohmann::json &
object,
1585 const std::string &dunder_name,
1586 const nlohmann::json &args,
1587 const nlohmann::json &source_node)
const;
1591 exprt store_call_result(
1593 const locationt &location,
1594 const std::string &temp_prefix,
1595 codet *block =
nullptr);
1597 void process_module_imports(
1598 const nlohmann::json &module_ast,
1599 module_locator &locator,
1600 code_blockt &accumulated_code);
1609 void pre_collect_module_asts(
1610 const nlohmann::json &module_ast,
1611 module_locator &locator);
1612 void pre_collect_import(
const nlohmann::json &node, module_locator &locator);
1614 symbolt *find_function_in_base_classes(
1615 const std::string &class_name,
1616 const std::string &symbol_id,
1617 std::string method_name,
1618 bool is_ctor)
const;
1623 symbolt *find_function_in_imported_base_classes(
1624 const std::string &class_name,
1625 const std::string &method_name,
1626 bool is_ctor)
const;
1631 std::pair<const nlohmann::json *, std::string>
1632 find_imported_class_module(
const std::string &class_name)
const;
1636 symbolt *find_method_in_imported_base(
1637 const nlohmann::json &base_class_node,
1638 const std::string &base_class,
1639 const std::string &method_name,
1640 bool is_ctor)
const;
1644 symbolt *find_method_in_model_base(
1645 const std::string &base_class,
1646 const std::string &sym_id)
const;
1650 const scope_bindings &module_bindings(
const std::string &name)
const;
1652 map<std::pair<const nlohmann::json *, std::string>,
scope_bindings>
1653 module_bindings_memo_;
1655 std::map<std::string, std::optional<std::vector<std::string>>>;
1661 std::optional<std::vector<std::string>>
1662 class_mro(
const std::string &class_name)
const;
1663 std::optional<std::vector<std::string>>
1664 class_mro(
const std::string &class_name, mro_memo &memo)
const;
1665 static std::optional<std::vector<std::string>>
1666 c3_merge(std::vector<std::vector<std::string>> seqs);
1669 const nlohmann::json *sole_binding(
1670 const std::string &name,
1671 const std::string &statement =
"ClassDef")
const;
1674 const nlohmann::json *sole_method_def(
1675 const std::string &class_name,
1676 const std::string &method)
const;
1680 bool overridden_below(
1681 const std::string &class_name,
1682 const std::string &method)
const;
1687 struct attribute_functions
1690 std::vector<std::string> ids;
1694 const attribute_functions *function_attribute(
const std::string &attr);
1695 static bool same_signature(
const code_typet &a,
const code_typet &b);
1696 void collect_attribute_stores(
1697 const nlohmann::json &node,
1698 const std::string &owner,
1699 const nlohmann::json *method);
1700 void record_function_store(
1701 const std::string &attr,
1702 const std::pair<bool, std::string> &stored);
1704 std::set<std::string> subclasses(
const std::string &class_name)
const;
1705 std::optional<std::pair<bool, std::string>> stored_function(
1706 const nlohmann::json &target,
1707 const nlohmann::json &
value,
1708 const std::string &owner,
1709 const nlohmann::json *method)
const;
1712 std::optional<std::string>
1713 bound_method_id(
const std::string &owner,
const std::string &m)
const;
1714 bool try_bound_method_store(
const nlohmann::json &ast_node, codet &block);
1717 bool try_dedicated_assign(
const nlohmann::json &ast_node, codet &block);
1718 bool try_numpy_nditer_assign(
const nlohmann::json &ast_node);
1719 const nlohmann::json *
1720 numpy_slice_copy_source(
const nlohmann::json &
value)
const;
1721 bool try_numpy_slice_copy_assign(
const nlohmann::json &ast_node);
1722 std::optional<exprt> get_intercepted_expr(
const nlohmann::json &element);
1723 void reject_bound_method_read(
const nlohmann::json &element);
1724 exprt get_class_dunder_attribute(
const nlohmann::json &element);
1725 exprt get_class_attribute(
const nlohmann::json &element);
1726 exprt get_class_name(
const nlohmann::json &
value);
1728 get_module_member(
const std::string &var_name,
const nlohmann::json &element);
1729 void reject_method_value(
const std::string &class_name,
const std::string &m)
1734 const nlohmann::json *,
1735 std::optional<std::map<std::string, std::optional<attribute_functions>>>>
1736 attribute_functions_;
1739 bool class_binds_name(
const std::string &class_name,
const std::string &name)
1742 symbolt *find_imported_symbol(
const std::string &symbol_id)
const;
1745 symbolt *find_symbol_through_module(
const std::string &sym_id)
const;
1746 symbolt *find_nested_function_symbol(
const std::string &name)
const;
1747 symbolt *find_symbol_in_global_scope(
const std::string &symbol_id)
const;
1748 symbolt *find_model_symbol(
const std::string &sym_id)
const;
1749 void collect_model_namespaces();
1750 void build_models_block(code_blockt &models_block,
bool models_precompiled);
1752 void copy_instance_attributes(
1753 const std::string &src_obj_id,
1754 const std::string &target_obj_id);
1756 void update_instance_from_self(
1757 const std::string &class_name,
1758 const std::string &func_name,
1759 const std::string &obj_symbol_id);
1761 void refuse_misaligned_self_calls()
const;
1762 void refuse_misaligned_self_call(
1763 const code_function_callt &call,
1764 const namespacet &ns)
const;
1766 size_t get_type_size(
const nlohmann::json &ast_node);
1768 void append_models_from_directory(
1769 std::list<std::string> &file_list,
1770 const std::string &dir_path);
1772 typet nullable_dict_pointee(
const typet &t)
const;
1773 bool keeps_pointer_type_on_none(
const typet &t);
1774 void guard_none_container(
1777 const nlohmann::json &element);
1778 void guard_none_typed_container(
1779 const std::string &op,
1781 const nlohmann::json &element);
1782 exprt handle_membership_operator(
1785 const nlohmann::json &element,
1787 exprt range_membership(
const exprt &x,
const nlohmann::json &element);
1789 list_or_range_contains(exprt &lhs, exprt &rhs,
const nlohmann::json &element);
1793 typet get_union_type_from_annotation(
1794 const nlohmann::json &annotation_node,
1795 const nlohmann::json &element);
1797 typet narrow_union_to_member(
const std::string &member_name);
1799 std::string extract_non_none_type(
const nlohmann::json &annotation_node);
1802 get_delete_statement(
const nlohmann::json &ast_node, codet &target_block);
1808 std::pair<std::string, typet>
1809 extract_type_info(
const nlohmann::json &ast_node);
1813 void upgrade_param_type_from_default(
1814 code_typet::argumentt ¶m_arg,
1815 const exprt &default_expr);
1818 void refine_any_param_to_list(
1819 code_typet::argumentt ¶m_arg,
1820 const nlohmann::json &body,
1821 const std::string &func_name,
1822 size_t param_index);
1825 bool param_is_list_like(
1826 const std::string ¶m_name,
1827 const nlohmann::json &body,
1828 const std::string &func_name,
1830 typet &elem_type)
const;
1832 bool called_only_with_flat_list_displays(
1833 const std::string &func_name,
1834 size_t param_index)
const;
1837 void refine_any_param_from_elements(
1838 code_typet::argumentt ¶m_arg,
1839 const std::string &func_name,
1840 size_t param_index);
1843 void seed_list_param_element_type(
1844 const nlohmann::json &element,
1845 const symbol_id &
id,
1846 const std::string &arg_id,
1847 size_t param_index);
1850 bool seed_mixed_call_site_elements(
1851 const std::string ¶m_id,
1852 const std::string &func_name,
1853 size_t param_index);
1854 bool infer_list_elem_type_from_call_sites(
1855 const std::string &func_name,
1858 bool param_keeps_positions(
1859 const std::string &func_name,
1861 bool any_index =
false)
const;
1862 bool param_elements(
1863 const nlohmann::json &arg,
1864 const std::string &enclosing_function,
1865 std::vector<nlohmann::json> &out,
1867 unsigned depth)
const;
1868 bool call_site_list_literals(
1869 const std::string &func_name,
1871 std::vector<nlohmann::json> &out,
1873 unsigned depth)
const;
1874 bool literal_element_kinds(
1875 const std::vector<nlohmann::json> &literals,
1876 std::vector<std::vector<typet>> &kinds)
const;
1877 bool record_literal_positions(
1878 const std::string &
id,
1879 const std::vector<nlohmann::json> &literals,
1880 const std::vector<typet> &kinds);
1881 bool record_literal_elements(
1882 const std::string &
id,
1883 const std::vector<nlohmann::json> &literals,
1885 bool mixes_str_and_number(
1886 const std::string &probe,
1887 const std::vector<typet> &kinds);
1889 void handle_array_unpacking(
1890 const nlohmann::json &ast_node,
1891 const nlohmann::json &target,
1893 codet &target_block);
1899 try_tagged_var_assign(
const nlohmann::json &ast_node, codet &target_block);
1903 bool module_scope_rhs_needs_type_probe(
const nlohmann::json &ast_node);
1908 symbolt *mint_retyped_symbol(
1909 const symbolt &orig,
1910 const std::string &alias_key,
1911 const typet &new_type,
1912 const locationt &location,
1913 const symbol_id &sid,
1914 codet &target_block);
1916 void handle_list_literal_unpacking(
1917 const nlohmann::json &ast_node,
1918 const nlohmann::json &target,
1919 codet &target_block);
1921 void set_assigned_value(symbolt &symbol,
const exprt &rhs);
1922 void retype_resized_str(symbolt &symbol, exprt &lhs, exprt &rhs);
1923 bool store_optional_str(symbolt *lhs_symbol,
const exprt &lhs, exprt &rhs);
1927 bool annotation_yields_to_rhs(
1928 const nlohmann::json &ast_node,
1929 const exprt &rhs)
const;
1931 void handle_assignment_type_adjustments(
1932 symbolt *lhs_symbol,
1935 const std::string &lhs_type,
1936 const nlohmann::json &ast_node,
1939 std::string element_kind(
const std::string &
id)
const;
1940 bool element_kinds_differ(
const std::string &a,
const std::string &b)
const;
1944 void propagate_list_type_info(
1947 symbolt *lhs_symbol);
1951 void propagate_dict_member_list_type_info(
1953 const std::string &lhs_identifier);
1970 exprt get_rhs_with_dict_resolution(
1971 const nlohmann::json &ast_node,
1972 const typet &target_type);
1988 std::string infer_type_from_any_annotation(
1989 const nlohmann::json &ast_node,
1990 const std::string &lhs_type);
2011 typet resolve_any_subscript_array_type(
2012 const nlohmann::json &ast_node,
2013 const typet ¤t_type);
2015 typet resolve_call_argument_array_type(
2016 const nlohmann::json &ast_node,
2017 const typet ¤t_type);
2044 typet resolve_numpy_reducer_call_array_type(
2045 const nlohmann::json &ast_node,
2046 const typet ¤t_type);
2063 lambda_call_callee(
const nlohmann::json &call,
const symbolt &var);
2064 typet resolve_lambda_call_result_type(
2065 const nlohmann::json &ast_node,
2066 const typet ¤t_type);
2068 typet resolve_numpy_arithmetic_type(
2069 const nlohmann::json &ast_node,
2071 const typet ¤t_type)
const;
2073 std::string resolve_name_symbol_id(
const std::string &name)
const;
2075 once_bound_exponent(
const nlohmann::json &right,
const exprt &rhs)
const;
2076 symbolt *find_enclosing_scope_symbol(symbol_id sid)
const;
2077 symbolt *find_global_symbol(
const symbol_id &sid);
2078 bool global_has_type(
const std::string &name,
const std::string &type)
const;
2080 module_function_expr(
const std::string &name,
const nlohmann::json &element);
2081 void track_unbound_global(
2082 const std::string &
id,
2083 const nlohmann::json &binding,
2085 void guard_unbound_global(
2086 const std::string &
id,
2087 const std::string &name,
2088 const nlohmann::json &element);
2089 void mark_global_bound(
const nlohmann::json &stmt, code_blockt &block);
2090 typet forward_function_return_type(
const std::string &name,
const exprt &fn);
2093 exprt get_default_expr(
const nlohmann::json &node);
2095 std::string root_name_from_subscript(
const nlohmann::json &node)
const;
2097 bool is_basic_numpy_view_subscript(
const nlohmann::json &node)
const;
2106 bool is_tracked_numpy_view_subscript(
const nlohmann::json &node)
const;
2113 bool is_numpy_view_copy_call_node(
const nlohmann::json &node)
const;
2115 bool is_numpy_array_constructor_expr(
const nlohmann::json &node)
const;
2124 const nlohmann::json *find_numpy_ctor_value_assigned_to(
2125 const nlohmann::json &block,
2127 const std::string &name)
const;
2134 bool block_assigns_numpy_array_to(
2135 const nlohmann::json &block,
2137 const std::string &name)
const;
2155 bool local_var_numpy_array_return(
const nlohmann::json &func_def)
const;
2158 bool numpy_arithmetic_return(
const nlohmann::json &func_def)
const;
2159 bool is_numpy_param_operand(
2160 const nlohmann::json &node,
2161 const nlohmann::json &func_def)
const;
2162 bool is_numpy_arithmetic_node(
2163 const nlohmann::json &node,
2164 const nlohmann::json &func_def)
const;
2165 bool is_numpy_arithmetic_value(
2166 const nlohmann::json &node,
2167 const nlohmann::json &func_def)
const;
2168 bool is_numpy_arithmetic_binding(
2169 const nlohmann::json &node,
2170 const nlohmann::json &func_def)
const;
2171 bool call_passes_numpy_array(
const nlohmann::json &call_node)
const;
2177 const nlohmann::json &
2178 resolve_return_annotation_node(
const nlohmann::json &function_node)
const;
2187 void reject_incompatible_numpy_local_return_branches(
2188 const nlohmann::json &func_def)
const;
2201 bool numpy_param_call_site_has_symbolic_shape(
2202 const std::string &func_name,
2204 const std::string ¶m_name)
const;
2210 const std::vector<numpy_param_call_site> &numpy_call_sites()
const;
2211 mutable std::vector<numpy_param_call_site> numpy_call_sites_cache_;
2212 mutable bool numpy_call_sites_cached_ =
false;
2218 bool module_level_symbolic_ctor_binding(
2219 const nlohmann::json &module_body,
2220 const std::string &arg_name)
const;
2226 void reject_if_symbolic_shape_param(
2227 bool numpy_array_param,
2228 const typet &arg_type,
2229 const std::string &func_name,
2231 const std::string &arg_name)
const;
2240 bool is_numpy_arithmetic_result(
2241 const nlohmann::json &rhs_node,
2242 const exprt &lhs)
const;
2243 bool is_array_returning_call_expr(
2244 const nlohmann::json &rhs_node,
2245 const exprt &lhs)
const;
2247 bool is_numpy_view_copy_expr(
const nlohmann::json &node)
const;
2250 root_name_from_numpy_view_copy_expr(
const nlohmann::json &node)
const;
2252 bool contains_tracked_numpy_view_name(
const nlohmann::json &node);
2254 bool is_tracked_numpy_view_name_node(
const nlohmann::json &node);
2256 bool is_basic_numpy_view_subscript_escape(
const nlohmann::json &node);
2259 exprt probe_expr(
const nlohmann::json &node);
2260 std::optional<typet>
2261 literal_numpy_array_type(
const nlohmann::json &call)
const;
2262 nlohmann::json bind_numpy_constructor_argument(
const nlohmann::json &arg);
2264 bool contains_tracked_numpy_view_object(
const nlohmann::json &node);
2266 void reject_numpy_view_mutating_method_call(
const nlohmann::json &node);
2270 std::string numpy_view_storage_root(
const std::string &
id)
const;
2271 bool is_numpy_storage_escaped(
const nlohmann::json &name)
const;
2272 bool is_closed_return_expression(
2273 const nlohmann::json &
value,
2274 const nlohmann::json ¶ms)
const;
2275 std::optional<nlohmann::json>
2276 simple_call_return_value(
const nlohmann::json &call)
const;
2280 std::optional<nlohmann::json>
2281 fold_numpy_view_call(
const nlohmann::json &call);
2285 get_folded_var_assign(
const nlohmann::json &ast_node, codet &target_block);
2289 void reject_or_defer_numpy_view_return(
2290 const nlohmann::json &ast_node,
2291 codet &target_block);
2292 bool bind_numpy_pointer_view_alias(
2294 const std::string &lhs_id,
2295 const std::string &rhs_id);
2296 void reject_multi_path_numpy_view_return(
const nlohmann::json &call);
2297 bool numpy_subscript_yields_view(
const nlohmann::json &node)
const;
2298 bool holds_numpy_view(
const nlohmann::json &node)
const;
2299 bool is_numpy_module_call(
const nlohmann::json &node)
const;
2300 bool is_numpy_view_value(
const nlohmann::json &node)
const;
2301 void reject_numpy_view_comprehension(
const nlohmann::json &node)
const;
2304 void check_numpy_view_statement(
const nlohmann::json &statement)
const;
2305 void reject_unfoldable_numpy_view_call(
const nlohmann::json &call);
2306 bool reject_or_defer_numpy_view_name_return(
2307 const nlohmann::json &ast_node,
2308 codet &target_block);
2309 nlohmann::json current_user_function_node()
const;
2310 bool is_numpy_module_param(
const std::string &root_name)
const;
2311 bool is_copied_numpy_view_local(
const std::string &name)
const;
2312 bool is_scalar_read_of_numpy_view_param(
2314 const std::string &storage_id)
const;
2315 code_blockt *while_condition_block(
2316 const nlohmann::json &ast_node,
2317 code_blockt &cond_prelude);
2318 void reject_live_numpy_view_copies_of(
const nlohmann::json &args);
2319 bool passes_numpy_view(
const nlohmann::json &arg);
2320 bool is_scalar_numpy_view_call(
const nlohmann::json &call);
2321 bool passes_unnamed_numpy_view_argument(
const nlohmann::json &call);
2322 bool contains_unnamed_numpy_view_argument(
const nlohmann::json &node);
2323 const nlohmann::json &hoist_unnamed_numpy_view_arguments(
2324 const nlohmann::json &statement,
2325 nlohmann::json &rewritten,
2326 codet &target_block);
2327 nlohmann::json bind_numpy_view_temporary(
2328 const nlohmann::json &statement,
2329 const nlohmann::json &
value,
2330 const std::string &prefix,
2331 codet &target_block);
2332 bool hoist_numpy_view_arguments(
2333 const std::string &
key,
2334 nlohmann::json &rewritten,
2335 codet &target_block);
2336 bool needs_numpy_view_call_binding(
const nlohmann::json &node);
2337 std::string numpy_view_callee_name(
const symbol_id &
function)
const;
2338 std::optional<std::pair<std::string, std::size_t>>
2339 numpy_view_method_callee(
const nlohmann::json &call)
const;
2340 bool binds_every_numpy_view_argument(
const nlohmann::json &call);
2341 bool names_python_builtin(
const std::string &name)
const;
2342 bool consumes_numpy_view_as_list(
const nlohmann::json &node)
const;
2343 bool is_builtin_over_numpy_view(
const nlohmann::json &node)
const;
2344 symbolt *find_symbol_in_import(
2345 const nlohmann::json &obj,
2346 const std::string &symbol_id,
2347 const std::string &lookup_name)
const;
2348 symbolt *find_symbol_in_module(
2349 const std::string &symbol_id,
2350 const std::string &module_file,
2351 const std::string &lookup_name,
2352 const std::string &name)
const;
2353 bool import_hides_builtin(
2354 const nlohmann::json &
import,
2355 const std::string &symbol_id,
2356 const std::string &name)
const;
2357 bool needs_fresh_retype_slot(
2360 const std::string &lhs_id)
const;
2361 bool is_numpy_array_to_view_rebind(
2364 const std::string &lhs_id)
const;
2365 std::string pointee_class(
const typet &type)
const;
2366 void retype_for_class_rebind(
2367 const nlohmann::json &target,
2368 const nlohmann::json &ast_node,
2370 const symbol_id &sid,
2371 const locationt &location,
2372 symbolt *&lhs_symbol,
2374 codet &target_block);
2376 reject_numpy_array_retype(
const symbolt &symbol,
const typet &type)
const;
2377 bool needs_fresh_numpy_array_slot(
2380 const std::string &lhs_id)
const;
2381 bool is_numpy_array_reshape_rebind(
2384 const std::string &lhs_id)
const;
2385 bool passes_numpy_view_anywhere(
const nlohmann::json &call);
2386 bool is_handled_numpy_view_call(
const nlohmann::json &call);
2387 bool is_attribute_store_of_numpy_view(
2388 const nlohmann::json &target,
2389 const nlohmann::json &
value);
2390 bool call_needs_view_argument_hoist(
const nlohmann::json &call);
2391 bool takes_numpy_view_argument(
const nlohmann::json &call, std::size_t index);
2392 bool is_rank1_numpy_view(
const nlohmann::json &node)
const;
2393 bool is_rank1_numpy_array_name(
const nlohmann::json &node)
const;
2394 void reject_builtin_over_complex_array(
const nlohmann::json &node)
const;
2395 bool is_foldable_constant_index(
const exprt &expr)
const;
2396 bool adapt_numpy_view_builtin_arguments(nlohmann::json &node);
2397 std::optional<nlohmann::json>
2398 inline_numpy_view_lambda_call(
const nlohmann::json &call);
2399 bool is_inlined_numpy_view_lambda(
const nlohmann::json &statement);
2400 std::optional<bool> bind_lambda_arguments(
2401 const nlohmann::json &signature,
2402 const nlohmann::json &args,
2403 std::map<std::string, nlohmann::json> &values)
const;
2404 std::set<std::string> numpy_inlined_lambdas_;
2405 const nlohmann::json &adapt_numpy_view_builtin_calls(
2406 const nlohmann::json &statement,
2407 nlohmann::json &rewritten);
2408 bool split_conditional_numpy_view_assignment(
2409 const nlohmann::json &statement,
2410 nlohmann::json &rewritten);
2411 bool needs_numpy_view_hoist(
const nlohmann::json &node);
2412 bool freeze_numpy_view_operand(
2413 const nlohmann::json::json_pointer &path,
2414 nlohmann::json &rewritten,
2415 codet &target_block);
2416 bool hoist_first_evaluated_numpy_view_call(
2417 const nlohmann::json::json_pointer &path,
2419 nlohmann::json &rewritten,
2420 codet &target_block);
2421 std::size_t numpy_view_arg_count_ = 0;
2424 bool returns_bound_numpy_view_param(
const nlohmann::json &func_node);
2426 const nlohmann::json *
2427 returned_numpy_view_argument(
const nlohmann::json &call);
2428 bool try_bind_returned_numpy_view_param(
2429 const nlohmann::json &ast_node,
2430 codet &target_block);
2432 const nlohmann::json *numpy_discarded_call_ =
nullptr;
2433 void reject_numpy_view_argument_use(
const nlohmann::json &call);
2434 void reject_numpy_view_method_call(
const nlohmann::json &func)
const;
2435 void reject_numpy_view_callee(
const nlohmann::json &call);
2436 void reject_inline_runtime_numpy_slice(
const nlohmann::json &call)
const;
2437 void reject_numpy_view_container_store(
const nlohmann::json &ast_node);
2438 bool is_numpy_view_syntax(
2439 const nlohmann::json &
value,
2440 const std::string &scope,
2441 std::size_t
depth)
const;
2442 bool is_numpy_storage_syntax(
2443 const nlohmann::json &
value,
2444 const std::string &scope,
2445 std::size_t
depth)
const;
2446 bool is_fold_only_numpy_function(
const nlohmann::json &function_node);
2448 void get_unfolded_function_definition(
const nlohmann::json &function_node);
2450 void track_numpy_view_call_escape(
const nlohmann::json &call);
2451 void reject_escaped_numpy_view_read(
const nlohmann::json &node)
const;
2452 void reject_escaped_numpy_view_write(
const nlohmann::json &target)
const;
2455 void reject_escaped_numpy_view_use(
const nlohmann::json &statement)
const;
2457 void reject_numpy_view_identity_query(
const nlohmann::json &node);
2459 void reject_copied_numpy_view_in_container(
2460 const nlohmann::json &ast_node,
2461 const std::set<std::string> &container_types);
2464 get_ravel_receiver_node(
const nlohmann::json &ravel_call)
const;
2465 bool is_numpy_ravel_receiver(
const nlohmann::json &ravel_call)
const;
2467 flat_subscript_receiver_node(
const nlohmann::json &subscript_node)
const;
2468 bool try_handle_flat_index_assignment(
2469 const nlohmann::json &ast_node,
2470 const nlohmann::json &target,
2471 codet &target_block);
2472 std::optional<exprt> try_build_flat_index_read(
const nlohmann::json &element);
2482 exprt handle_subscript_expr(
const nlohmann::json &element);
2483 std::optional<exprt>
2484 resolve_subscript_base(
const nlohmann::json &element, exprt &array);
2485 std::optional<exprt> try_fold_constant_string_slice(
2486 const nlohmann::json &element,
2487 const exprt &array);
2488 void unwrap_subscript_base_types(
2491 typet &array_type_for_dict,
2492 bool &array_is_dict_pointer,
2493 const nlohmann::json &element);
2494 std::optional<exprt> try_dispatch_tuple_subscript(
2496 const typet &array_type,
2497 const nlohmann::json &slice,
2498 const nlohmann::json &element);
2499 std::optional<exprt> try_dispatch_dict_subscript(
2501 const typet &array_type_for_dict,
2502 bool array_is_dict_pointer,
2503 const nlohmann::json &element);
2504 bool subscript_targets_list_model(
2505 const typet &array_type,
2506 const typet &list_type)
const;
2507 std::optional<exprt> try_dispatch_multidim_tuple_index(
2509 const typet &array_type,
2510 const nlohmann::json &slice,
2511 const nlohmann::json &element,
2512 bool tuple_index_targets_list_model,
2513 const typet &list_type);
2514 std::optional<exprt> try_dispatch_multidim_tuple_axes(
2516 const nlohmann::json &element,
2517 const std::vector<nlohmann::json> &idx_nodes);
2518 std::optional<exprt> try_dispatch_chained_axis_index(
2520 const nlohmann::json &element,
2521 const std::vector<nlohmann::json> &idx_nodes,
2522 const typet &list_type);
2523 std::optional<exprt> try_dispatch_fancy_list_index(
2525 const nlohmann::json &slice,
2526 const nlohmann::json &element,
2527 bool tuple_index_targets_list_model);
2528 std::optional<exprt> try_dispatch_bool_mask_variable_index(
2530 const typet &array_type,
2531 const nlohmann::json &slice,
2532 const nlohmann::json &element,
2533 bool tuple_index_targets_list_model);
2534 std::optional<exprt> try_dispatch_fancy_index_via_list_variable(
2536 const nlohmann::json &slice,
2537 const nlohmann::json &element);
2538 std::optional<exprt> try_dispatch_dunder_getitem(
2539 const nlohmann::json &element,
2540 const nlohmann::json &slice);
2541 void reject_scalar_subscript(
2542 const typet &array_type,
2543 const nlohmann::json &element)
const;
2545 std::optional<nlohmann::json>
2546 select_return_value_for_call(
const nlohmann::json &call_node)
const;
2548 nlohmann::json substitute_call_arguments(
2549 const nlohmann::json &node,
2550 const nlohmann::json &call_node)
const;
2552 bool return_value_uses_call_argument(
2553 const nlohmann::json &return_value,
2554 const nlohmann::json &call_node)
const;
2561 bool return_call_only_references_params_or_modules(
2562 const nlohmann::json &return_value,
2563 const nlohmann::json ¶ms)
const;
2565 void reject_unsafe_numpy_view_target(
const nlohmann::json &target);
2566 void reject_unsafe_numpy_view_write_to(
const std::string &root_id);
2568 void reject_numpy_view_slice_assignment(
const nlohmann::json &target);
2572 bool reject_immutable_item_assignment(
2573 const typet &container_type,
2574 codet &target_block);
2576 void record_numpy_view_copy(
const exprt &lhs,
const nlohmann::json &rhs_node);
2577 std::string numpy_view_source_of(
const std::string &storage_id)
const;
2579 bool is_tracked_numpy_view_id(
const std::string &symbol_id)
const;
2581 void reject_nonconstant_numpy_view_write(
const nlohmann::json &target)
const;
2583 std::optional<std::vector<nlohmann::json>>
2584 build_numpy_nditer_logical_elements(
const nlohmann::json &arg)
const;
2586 std::optional<std::pair<std::vector<std::size_t>, std::vector<exprt>>>
2587 build_numpy_descriptor_materialized_elements(
2588 const nlohmann::json &arg,
2589 const std::string &unsupported_rank_error);
2591 std::optional<std::vector<std::size_t>>
2592 get_empty_numpy_literal_slice_shape(
const nlohmann::json &arg)
const;
2594 std::optional<exprt> build_numpy_descriptor_materialized_list(
2595 const nlohmann::json &arg,
2600 bool numpy_result_is_fresh_copy_ =
false;
2602 bool numpy_result_is_view_ =
false;
2605 bool is_numpy_param_slice(
const nlohmann::json &subscript)
const;
2608 exprt hoist_numpy_element(
const exprt &element);
2611 exprt materialize_numpy_elements(
2612 const nlohmann::json &location_node,
2613 const std::vector<std::size_t> &shape,
2614 const std::vector<exprt> &elems,
2615 const typet &elem_type);
2618 std::optional<exprt> build_numpy_descriptor_materialized_array(
2619 const nlohmann::json &arg,
2620 const std::vector<std::size_t> *reshape_to =
nullptr);
2622 std::optional<std::vector<std::size_t>>
2623 get_numpy_nditer_logical_shape(
const std::string &root_id)
const;
2625 std::optional<typet>
2626 get_numpy_descriptor_element_type(
const std::string &root_id)
const;
2628 bool is_numpy_readonly_view_arg(
const nlohmann::json &arg)
const;
2630 void clear_numpy_view_copy(
const exprt &lhs);
2633 update_numpy_array_binding(
const exprt &lhs,
const nlohmann::json &rhs_node);
2635 bool update_numpy_array_binding_from_name(
2637 const std::string &lhs_id,
2638 const nlohmann::json &rhs_node,
2639 bool unconditional_assignment);
2641 bool preserve_conditional_numpy_alias_shape(
2642 const std::string &lhs_id,
2643 const std::string &rhs_id,
2644 bool unconditional_assignment);
2646 void copy_numpy_alias_shape_state(
2647 const std::string &lhs_id,
2648 const std::string &rhs_id);
2650 void reject_conditional_numpy_alias_rebind(
2652 const nlohmann::json &rhs_node)
const;
2654 bool record_numpy_view_copy_from_returned_argument(
2656 const std::string &lhs_id,
2657 const nlohmann::json &rhs_node);
2659 void clear_numpy_array_storage_aliases_for(
const std::string &symbol_id);
2661 void bind_numpy_array_storage_alias(
2662 const std::string &lhs_id,
2663 const std::string &rhs_id);
2665 symbolt *resolve_numpy_array_storage_alias(symbolt *symbol)
const;
2668 resolve_numpy_array_storage_alias_id(
const std::string &symbol_id)
const;
2676 std::vector<std::string> numpy_views_of(
const std::string &rebound_id)
const;
2678 bool keep_numpy_result_view(
const std::string &lhs_id);
2679 bool is_readonly_numpy_view_expr(
const nlohmann::json &node)
const;
2681 void record_numpy_constructor_binding(
2683 const std::string &lhs_id,
2684 const nlohmann::json &rhs_node,
2685 bool unconditional_assignment);
2687 void detach_numpy_pointer_views_of(
2688 const std::string &rebound_id,
2689 const locationt &location,
2690 codet &target_block);
2693 void detach_numpy_pointer_view(
2694 const std::string &view_id,
2695 const locationt &location,
2696 codet &target_block);
2700 void share_numpy_storage_snapshot(
2701 const std::string &storage_id,
2702 const std::vector<std::string> &view_ids,
2703 const locationt &location,
2704 codet &target_block,
2705 const std::string &heir_id =
"");
2706 std::vector<std::string>
2707 numpy_storage_aliases_of(
const std::string &rebound_id)
const;
2708 std::string hand_numpy_storage_to_alias(
2709 const std::string &rebound_id,
2710 const locationt &location,
2711 codet &target_block);
2713 bool should_rebuild_cached_numpy_row_subscript_rhs(
2714 const nlohmann::json &rhs_node)
const;
2716 bool is_tracked_2d_numpy_array_symbol(
const std::string &source_id)
const;
2718 std::optional<nlohmann::json>
2719 rewrite_numpy_method_call_node(
const nlohmann::json &call_node)
const;
2720 bool is_numpy_subscript_reducer_receiver(
2721 const nlohmann::json &method_base,
2722 const std::string &method_name)
const;
2730 nlohmann::json rewrite_assign_rhs_node(
const nlohmann::json &ast_node)
const;
2731 nlohmann::json numpy_transpose_base(
const nlohmann::json &node)
const;
2738 std::tuple<bool, std::string, nlohmann::json, bool, bool>
2739 classify_numpy_method_call(
const nlohmann::json &call_node)
const;
2742 method_base_is_imported_module(
const std::string &method_base_name)
const;
2745 method_base_is_tracked_numpy_array(
const std::string &method_base_name)
const;
2749 nlohmann::json build_numpy_method_rewrite_node(
2750 const nlohmann::json &call_node,
2751 const std::string &method_name,
2752 const nlohmann::json &method_base)
const;
2769 bool handle_unpacking_assignment(
2770 const nlohmann::json &ast_node,
2771 const nlohmann::json &target,
2772 codet &target_block);
2774 bool unpack_record_is_trusted(
const nlohmann::json &
value)
const;
2780 void unpack_nested_target(
2781 const nlohmann::json &ast_node,
2782 const nlohmann::json &target,
2784 codet &target_block);
2786 exprt hold_tuple_member_list(
2787 const nlohmann::json &ast_node,
2789 codet &target_block);
2799 void desugar_unpacking_with_lvalue_targets(
2800 const nlohmann::json &ast_node,
2801 const nlohmann::json &target,
2802 codet &target_block);
2820 symbolt *create_symbol_for_unannotated_assign(
2821 const nlohmann::json &ast_node,
2822 const nlohmann::json &target,
2823 const symbol_id &sid,
2832 bool is_global_variable(
const symbol_id &sid)
const;
2836 void declare_nonlocal(
const nlohmann::json &element);
2840 void redirect_nonlocal(symbol_id &sid)
const;
2851 std::string extract_target_name(
const nlohmann::json &target)
const;
2859 static const nlohmann::json *
2860 reordering_builtin_arg(
const nlohmann::json &ast_node);
2862 void copy_elem_types_from_reordering_builtin(
2863 const nlohmann::json &ast_node,
2864 const std::string &lhs_id);
2880 std::string user_class_of(
const typet &type);
2881 void reject_attribute_added_on_some_paths(
2882 const std::string &receiver,
2883 const std::string &class_name,
2884 const std::string &attr)
const;
2885 void reject_attribute_scalar_change(
const exprt &lhs,
const exprt &rhs);
2886 void reject_attribute_class_change(
2889 const nlohmann::json &ast_node,
2891 void widen_int_target_for_float_call(
2895 void handle_function_call_rhs(
2896 const nlohmann::json &ast_node,
2897 symbolt *lhs_symbol,
2900 const locationt &location,
2902 codet &target_block);
2904 void wrap_call_result_in_optional(
2905 const nlohmann::json &ast_node,
2908 const locationt &location,
2909 codet &target_block);
2922 exprt handle_string_literal_rhs(
2923 const nlohmann::json &ast_node,
2924 const std::string &lhs_type,
2946 exprt handle_type_identity_check(
2947 const std::string &op,
2950 const nlohmann::json &left,
2951 const nlohmann::json &right);
2954 exprt handle_type_comparison(
2955 const std::string &op,
2958 const nlohmann::json &left,
2959 const nlohmann::json &right);
2961 exprt erased_type_argument(
const nlohmann::json &node);
2965 static constexpr const char *unknown_class_name =
"<unknown class>";
2969 exprt handle_erased_type_comparison(
2970 const std::string &op,
2971 const nlohmann::json &left,
2972 const nlohmann::json &right);
2977 std::optional<std::string>
2978 class_identity_operand(
const nlohmann::json &node,
const exprt &expr)
const;
2983 exprt handle_tagged_scalar_binop(
2984 const std::string &op,
2987 const nlohmann::json &left,
2988 const nlohmann::json &right,
2989 const nlohmann::json &element);
2993 exprt handle_dict_bitwise(
2994 const std::string &op,
2997 const nlohmann::json &element);
3000 build_emptiness_check(
const exprt &
value,
const nlohmann::json &element);
3004 static void convert_function_call_to_side_effect(exprt &expr);
3011 void convert_function_calls_to_side_effects(exprt &lhs, exprt &rhs);
3019 exprt handle_chained_comparisons_logic(
3020 const nlohmann::json &element,
3025 std::pair<exprt, exprt> chained_pair_operands(
3026 const nlohmann::json &element,
3035 exprt bind_chained_comparator(
3036 const exprt &operand,
3037 const nlohmann::json &element,
3043 exprt bind_operand_read_twice(
3044 const exprt &operand,
3045 const nlohmann::json &element,
3059 bool handle_none_check_setup(
3060 const std::string &op,
3078 exprt numpy_array_arithmetic(
3079 const std::string &op,
3082 const locationt &location);
3084 guard_negative_exponents(
const exprt &exponents,
const locationt &location);
3085 exprt numpy_elementwise(
3086 const std::string &op,
3090 exprt raise_in_expression(
3091 const std::string &exception,
3092 const std::string &message,
3094 void reject_unmodelled_array_arithmetic(
3095 const std::string &op,
3098 const nlohmann::json &element);
3100 numpy_float_remainder(
const exprt &x,
const exprt &y,
const typet &type);
3101 exprt numpy_element_op(
3102 const std::string &op,
3106 exprt handle_array_operations(
3107 const std::string &op,
3110 const nlohmann::json &left,
3111 const nlohmann::json &right,
3112 const nlohmann::json &element);
3117 exprt build_bytes_concat(
const exprt &lhs,
const exprt &rhs);
3121 bool is_definite_non_list_addend(
3123 const nlohmann::json &element)
const;
3138 exprt handle_list_operations(
3139 const std::string &op,
3142 const nlohmann::json &left,
3143 const nlohmann::json &right,
3144 const nlohmann::json &element);
3157 exprt handle_relational_type_mismatches(
3158 const std::string &op,
3161 const nlohmann::json &element);
3176 exprt handle_string_binary_operations(
3177 const std::string &op,
3180 const nlohmann::json &left,
3181 const nlohmann::json &right,
3182 const nlohmann::json &element);
3186 exprt str_pointer_add_error(
3187 const std::string &op,
3190 const nlohmann::json &left,
3191 const nlohmann::json &right);
3204 exprt build_binary_expression(
const std::string &op, exprt &lhs, exprt &rhs);
3213 typet infer_return_type_from_body(
const nlohmann::json &body);
3219 exprt handle_string_type_mismatch(
3222 const std::string &op);
3224 void process_forward_reference(
3225 const nlohmann::json &annotation,
3226 codet &target_block);
3230 void build_forward_class(
const typet &type);
3237 typet optional_return_type(
3238 const nlohmann::json &function_node,
3239 const typet &declared);
3240 exprt wrap_in_optional(
const exprt &
value,
const typet &optional_type);
3242 exprt wrap_if_optional(
const exprt &
value,
const typet &type)
3249 exprt wrap_stored_if_optional(
const exprt &
value,
const typet &type);
3250 typet optional_ternary_type(exprt &then, exprt &else_expr,
bool then_is_none);
3251 exprt get_return_value(
const nlohmann::json &
value);
3252 typet subscript_annotation_type(
3253 const std::string &
base,
3254 const nlohmann::json &var_node);
3262 exprt make_enum_member_struct_expr(
3263 const symbolt &int_sym,
3264 const std::string &class_name,
3265 const std::string &member_name);
3267 void adopt_tagged_element(symbolt *lhs_symbol, exprt &lhs,
const exprt &rhs);
3269 void adopt_array_type(symbolt &lhs_symbol, exprt &lhs, exprt &rhs);
3272 exprt materialize_optional(
const exprt &expr,
const nlohmann::json &element);
3273 exprt check_float_fits_int_return(
3274 const nlohmann::json &ast_node,
3276 codet &target_block);
3278 static exprt string_literal_address(
const exprt &array);
3280 decay_string_literal_returns(exprt &node,
const typet &return_type)
const;
3281 exprt coerce_optional_return(
3283 const locationt &location,
3284 codet &target_block);
3285 exprt narrow_optional_return(
3287 const locationt &location,
3288 codet &target_block);
3289 exprt resolve_optional_operands(
3290 const std::string &op,
3293 const nlohmann::json &element,
3294 bool is_none_check);
3295 exprt unwrap_optional_if_needed(
3297 const nlohmann::json &element = nlohmann::json());
3303 static std::string op_to_dunder(
const std::string &op);
3304 static std::string op_to_rdunder(
const std::string &op);
3306 exprt apply_bool_dunder(exprt
cond,
const locationt &location);
3309 exprt fold_tagged_identity(
3310 const std::string &op,
3313 const nlohmann::json &left,
3314 const nlohmann::json &right);
3317 exprt tagged_truthiness(exprt
value,
const nlohmann::json &node);
3320 exprt handle_tagged_unary_operator(
3321 const std::string &op,
3322 const exprt &operand,
3323 const nlohmann::json &element);
3326 void refuse_tagged_boolop_operand(
const exprt &operand)
const;
3330 exprt apply_string_truthiness(
const exprt &str,
const locationt &location);
3333 exprt apply_bool_dunder_for_not(
3334 const std::string &op,
3336 const locationt &location);
3338 symbolt *find_dunder_method(
3339 const std::string &class_name,
3340 const std::string &dunder_name);
3344 std::string instance_class_name(
const nlohmann::json &value_node);
3348 bool is_class_instance(
const nlohmann::json &value_node);
3349 bool has_dunder_method(
3350 const nlohmann::json &value_node,
3351 const std::string &dunder_name);
3352 exprt dispatch_dunder_operator(
3353 const std::string &op,
3356 const locationt &loc);
3357 exprt dispatch_unary_dunder_operator(
3358 const std::string &op,
3360 const locationt &loc);
3366 contextt &symbol_table_;
3367 const nlohmann::json *ast_json;
3372 const nlohmann::json *entry_ast_;
3376 const std::vector<nlohmann::json> *extra_asts_;
3377 const global_scope &global_scope_;
3379 element_type_registry element_type_registry_;
3380 std::vector<std::function<void()>> deferred_checks_;
3381 string_builder *string_builder_;
3382 symbol_generator sym_generator_;
3385 typet current_element_type;
3386 typet current_func_return_type_;
3388 bool current_func_annotated_int_ =
false;
3391 typet ternary_return_target_;
3392 std::string main_python_file;
3393 std::string current_python_file;
3394 size_t not_callable_count_ = 0;
3395 nlohmann::json imported_module_json;
3396 std::string current_func_name_;
3397 std::string current_class_name_;
3398 std::size_t get_expr_depth_ = 0;
3399 code_blockt *current_block;
3403 std::array<const nlohmann::json *, 2> type_compared_operands_{};
3405 python_math math_handler_;
3411 python_lambda *lambda_handler_;
3414 bool is_converting_lhs =
false;
3415 bool is_converting_rhs =
false;
3421 const nlohmann::json *lhs_store_target_ =
nullptr;
3425 bool is_store_target(
const nlohmann::json &node)
const
3427 return is_converting_lhs && lhs_store_target_ == &node;
3435 bool converting_defaults_ =
false;
3436 bool converting_lambda_body_ =
false;
3437 std::map<std::string, irep_idt> lambda_copies_;
3438 bool in_rhs_type_probe_ =
false;
3440 bool in_scratch_probe_ =
false;
3446 bool in_contract_clause_ =
false;
3447 bool in_lazy_operand_ =
false;
3449 unsigned try_body_depth_ = 0;
3452 const nlohmann::json *asserted_test_ =
nullptr;
3454 bool needs_zero_division_guard(
const std::string &op,
const exprt &rhs)
const;
3461 bool any_subscript_array_needs_copy_ =
false;
3466 exprt cached_any_subscript_rhs_;
3467 bool has_cached_any_subscript_rhs_ =
false;
3468 std::set<std::string> numpy_array_symbols_;
3469 std::unordered_map<irep_idt, std::string, irep_id_hash> class_object_names_;
3471 std::map<std::string, int> class_ids_;
3475 bool unpack_record_trusted_ =
false;
3476 std::unordered_map<std::string, std::string> numpy_view_copy_sources_;
3477 std::unordered_map<std::string, std::string> numpy_array_storage_aliases_;
3492 struct numpy_scalar_pointer_view_infot
3497 std::vector<std::size_t> shape;
3498 std::string source_id;
3501 std::set<std::string> other_sources;
3504 std::vector<long long> strides;
3508 std::vector<std::string> shape_symbols;
3509 std::vector<std::string> stride_symbols;
3510 bool is_symbolic()
const
3512 for (
const std::string &
id : shape_symbols)
3515 for (
const std::string &
id : stride_symbols)
3521 std::unordered_map<std::string, numpy_scalar_pointer_view_infot>
3522 numpy_pointer_view_info_;
3525 std::map<std::string, numpy_nditer_state> numpy_nditers_;
3526 std::map<std::string, numpy_nditer_item> numpy_nditer_items_;
3527 nlohmann::json current_nditer_call_;
3528 std::string current_nditer_state_;
3529 unsigned nditer_counter_ = 0;
3530 std::vector<exprt> prebuilt_exprs_;
3531 const numpy_scalar_pointer_view_infot *
3532 find_numpy_pointer_view_info(
const std::string &name)
const;
3536 bool try_infer_numpy_view_param(
3537 const std::string &func_name,
3538 std::size_t param_index,
3539 typet &out_elem_type,
3540 numpy_scalar_pointer_view_infot &out_info)
const;
3541 bool try_infer_numpy_view_param(
3542 const std::string &func_name,
3543 std::size_t param_index,
3544 typet &out_elem_type,
3545 numpy_scalar_pointer_view_infot &out_info,
3546 std::set<std::string> &visiting)
const;
3547 std::optional<typet> numpy_literal_array_type(
3548 const std::string &arr_name,
3551 unsigned depth = 0)
const;
3552 std::optional<typet> numpy_filled_array_type(
3553 const nlohmann::json &
value,
3554 const std::string &
function)
const;
3555 std::optional<typet> numpy_arange_array_type(
3556 const nlohmann::json &
value,
3557 const std::string &
function)
const;
3558 exprt list_argument_expr(
const nlohmann::json &arg);
3561 typet returned_function_return_type(
const nlohmann::json &call);
3562 typet stored_function_return_type(
const nlohmann::json &
value);
3565 std::optional<typet>
3566 dict_function_return_type(
const nlohmann::json &container);
3568 const nlohmann::json &container,
3569 std::vector<nlohmann::json> &out);
3570 typet subscript_call_return_type(
3571 const exprt &func_ptr,
3572 const nlohmann::json &func_node);
3573 std::optional<std::vector<std::size_t>>
3574 numpy_filled_array_shape(
const nlohmann::json &
value)
const;
3575 const std::optional<std::pair<typet, numpy_scalar_pointer_view_infot>> &
3576 inferred_numpy_view_param(
3577 const std::string &func_name,
3578 std::size_t param_index);
3579 bool is_bound_numpy_view_param(
3580 const std::string &func_name,
3581 std::size_t param_index);
3582 void reject_numpy_view_argument_type_mismatch(
const nlohmann::json &call);
3585 std::optional<std::pair<typet, numpy_scalar_pointer_view_infot>>>
3586 numpy_view_param_layouts_;
3589 std::set<std::string> numpy_view_params_decided_;
3590 std::map<std::string, bool> numpy_view_params_assumed_;
3591 static std::optional<numpy_scalar_pointer_view_infot>
3592 slice_view_info(std::size_t length,
const nlohmann::json &slice_node);
3593 static std::optional<numpy_scalar_pointer_view_infot> row_slice_view_info(
3596 const nlohmann::json &slice_node);
3597 static std::optional<numpy_scalar_pointer_view_infot> column_view_info(
3600 const nlohmann::json &slice_node);
3601 static std::optional<numpy_scalar_pointer_view_infot>
3602 view_info_from_subscript(
3603 const std::vector<std::size_t> &src_shape,
3604 const nlohmann::json &slice_node);
3605 static numpy_scalar_pointer_view_infot
3606 runtime_view_info(std::size_t rank = 1);
3607 static std::optional<numpy_scalar_pointer_view_infot>
3608 slice_or_runtime_view_info(
3610 const nlohmann::json &slice_node);
3611 static std::optional<std::pair<typet, numpy_scalar_pointer_view_infot>>
3613 const std::pair<typet, numpy_scalar_pointer_view_infot> &a,
3614 const std::pair<typet, numpy_scalar_pointer_view_infot> &b);
3617 struct numpy_runtime_view_layoutt
3619 std::vector<std::string> extents;
3620 std::vector<std::string> strides;
3624 std::map<std::string, numpy_runtime_view_layoutt> numpy_runtime_view_statics_;
3625 std::map<std::string, std::pair<std::string, numpy_runtime_view_layoutt>>
3626 numpy_runtime_view_locals_;
3627 const nlohmann::json *numpy_runtime_bound_call_ =
nullptr;
3628 const numpy_runtime_view_layoutt &
3629 runtime_numpy_view_statics(
const std::string &
key, std::size_t rank);
3630 void declare_runtime_numpy_view_param(
3631 numpy_scalar_pointer_view_infot &info,
3632 const std::string &arg_id,
3633 const std::string &
key);
3634 void prepend_runtime_numpy_view_prologue(
3635 const std::string &function_id,
3636 exprt &function_body);
3637 void bind_runtime_numpy_view_arguments(
3638 const nlohmann::json &statement,
3639 codet &target_block);
3640 void store_runtime_numpy_view_layout(
3641 const nlohmann::json &call,
3642 const std::string &func_name,
3643 std::size_t param_index,
3644 codet &target_block);
3645 std::string numpy_view_callee_of(
const nlohmann::json &call);
3646 std::vector<std::size_t>
3647 runtime_numpy_view_params(
const std::string &func_name);
3648 void reject_unbound_runtime_numpy_view_call(
const nlohmann::json &call);
3649 static bool same_view_layout(
3650 const std::pair<typet, numpy_scalar_pointer_view_infot> &a,
3651 const std::pair<typet, numpy_scalar_pointer_view_infot> &b);
3652 static std::optional<numpy_scalar_pointer_view_infot> subview_info(
3653 const numpy_scalar_pointer_view_infot &parent,
3654 const nlohmann::json &slice_node);
3655 std::optional<std::pair<typet, numpy_scalar_pointer_view_infot>>
3656 infer_diagonal_view_layout(
3657 const nlohmann::json &call,
3658 const std::string &
function)
const;
3659 std::optional<std::pair<typet, numpy_scalar_pointer_view_infot>>
3660 infer_branch_bound_view_layout(
3661 const nlohmann::json &node,
3663 std::set<std::string> &visiting,
3664 unsigned depth)
const;
3665 std::optional<std::pair<typet, numpy_scalar_pointer_view_infot>>
3666 infer_numpy_view_layout(
3667 const nlohmann::json &node,
3669 std::set<std::string> &visiting,
3670 unsigned depth = 0)
const;
3671 std::optional<numpy_scalar_pointer_view_infot> infer_numpy_view_param_type(
3672 const std::string &func_name,
3673 std::size_t param_index,
3674 const std::string &arg_name,
3675 bool numpy_array_param,
3676 typet &arg_type)
const;
3677 void register_numpy_view_param(
3678 const std::optional<numpy_scalar_pointer_view_infot> &view_param,
3679 const std::string &arg_id,
3680 const std::string &func_name,
3681 std::size_t param_index);
3683 std::optional<exprt>
3684 symbolic_numpy_view_length(
const std::string &name)
const;
3686 exprt numpy_view_extent(
3687 const numpy_scalar_pointer_view_infot &info,
3688 std::size_t axis)
const;
3689 exprt numpy_view_stride(
3690 const numpy_scalar_pointer_view_infot &info,
3691 std::size_t axis)
const;
3694 reject_symbolic_numpy_view(
const numpy_scalar_pointer_view_infot &info);
3697 struct strided_copy_axis
3706 void emit_strided_copy(
3710 const exprt &offset,
3711 const std::vector<strided_copy_axis> &axes,
3712 const locationt &location);
3717 std::string snapshot_symbolic_numpy_view(
3718 const exprt &old_ptr,
3719 numpy_scalar_pointer_view_infot &info,
3720 const locationt &location,
3721 codet &target_block);
3722 void reject_numpy_view_rebind()
const;
3727 bool accepts_numpy_view_binding(
3728 const std::string &lhs_id,
3729 const numpy_scalar_pointer_view_infot &candidate,
3730 const typet &view_ptr_type,
3731 const exprt &source);
3732 bool can_merge_numpy_view_layouts(
const std::string &view_id)
const;
3733 const numpy_runtime_view_layoutt &
3734 numpy_view_layout_vars(
const std::string &view_id, std::size_t rank);
3735 void record_numpy_view_layout(
3736 const std::string &view_id,
3737 const std::string &storage_id);
3738 void merge_numpy_view_binding(
const std::string &view_id,
bool same_kind);
3739 static bool same_numpy_view_kind(
3740 const numpy_scalar_pointer_view_infot &a,
3741 const numpy_scalar_pointer_view_infot &b);
3744 std::map<std::string, numpy_runtime_view_layoutt> numpy_view_layout_vars_;
3745 std::vector<std::string> numpy_view_layout_locals_;
3746 std::set<std::string> numpy_merged_views_;
3747 std::map<std::string, std::set<std::string>> numpy_view_other_sources_;
3748 std::set<std::string> numpy_view_storage_roots(
const std::string &
id)
const;
3749 unsigned numpy_loop_depth_ = 0;
3751 unsigned conditional_expr_depth_ = 0;
3753 bool in_operand_effects_block_ =
false;
3756 std::vector<exprt> read_strided_view_elements(
3758 const std::vector<long long> &strides,
3759 const std::vector<std::size_t> &shape);
3760 std::vector<exprt> read_contiguous_view_elements(
3764 const std::vector<std::size_t> &shape);
3765 std::string snapshot_constant_numpy_view(
3766 const symbolt &view_symbol,
3767 numpy_scalar_pointer_view_infot &info,
3768 const locationt &location,
3769 codet &target_block);
3773 struct numpy_view_containert
3775 std::vector<std::string> elements;
3776 std::map<std::string, std::size_t> keys;
3777 bool is_dict =
false;
3779 std::unordered_map<std::string, numpy_view_containert> numpy_view_containers_;
3780 std::size_t numpy_view_container_count_ = 0;
3781 const numpy_view_containert *
3782 find_numpy_view_container(
const nlohmann::json &node)
const;
3783 std::string numpy_view_container_element(
3784 const numpy_view_containert &container,
3785 const nlohmann::json &slice)
const;
3786 std::optional<nlohmann::json>
3787 resolve_numpy_view_container_use(
const nlohmann::json &node)
const;
3791 rewrite_numpy_view_container_reads(
const nlohmann::json &node)
const;
3792 const nlohmann::json &resolve_numpy_view_containers(
3793 const nlohmann::json &statement,
3794 nlohmann::json &rewritten)
const;
3795 bool try_bind_numpy_view_container(
3796 const nlohmann::json &ast_node,
3797 codet &target_block);
3800 std::unordered_set<std::string> numpy_view_return_functions_;
3803 std::unordered_set<std::string> numpy_fold_only_functions_;
3805 std::unordered_set<std::string> numpy_escaped_storage_;
3807 std::unordered_set<std::string> numpy_readonly_arrays_;
3809 std::vector<std::string> model_namespaces_;
3818 std::unordered_map<std::string, std::vector<std::size_t>> numpy_param_shapes_;
3819 std::unordered_map<std::string, typet> numpy_param_array_types_;
3820 std::unordered_set<std::string> numpy_ambiguous_shape_symbols_;
3823 std::unordered_set<std::string> positional_list_params_;
3826 std::set<std::string> numpy_view_params_;
3828 std::unordered_set<std::string> numpy_view_param_symbols_;
3829 bool is_loading_models =
false;
3830 bool is_importing_module =
false;
3831 bool base_ctor_called =
false;
3832 bool build_static_lists =
false;
3835 typet numpy_element_type;
3844 std::set<std::string> call_escaped_lists_;
3847 std::map<std::string, std::set<std::string>> instance_attr_map;
3850 std::map<std::string, std::set<std::string>> certain_instance_attrs_;
3852 std::unordered_map<std::string, std::string> imported_modules;
3860 std::map<std::string, nlohmann::json> module_ast_pool_;
3864 std::unordered_map<std::string, std::string> input_str_to_len_sym_;
3873 std::unordered_map<std::string, std::string> retype_aliases_;
3876 symbolt *follow_retype_alias(symbolt *symbol)
const;
3878 symbolt *retype_store_symbol(
3879 const nlohmann::json &target,
3881 symbolt *lhs_symbol);
3885 std::unordered_map<std::string, std::pair<std::string, typet>>
3886 unbound_global_flags_;
3890 std::unordered_map<std::string, std::string> unmodelled_base_classes_;
3892 std::unordered_set<std::string> str_valued_symbols_;
3894 std::unordered_set<std::string> str_assigned_symbols_;
3896 std::unordered_set<std::string> out_of_scope_locals_;
3899 void end_block_scope(
const code_blockt &block);
3909 std::unordered_map<std::string, std::string> flow_class_map_;
3913 std::string flow_lvalue_path(
const nlohmann::json &node)
const;
3917 std::string flow_rhs_class(
const nlohmann::json &rhs)
const;
3923 std::string alias_rhs_class(
const nlohmann::json &rhs);
3933 std::string call_return_class(
const nlohmann::json &rhs)
const;
3938 unsigned block_nesting_ = 0;
3950 unsigned function_body_depth_ = 0;
3958 unsigned loop_body_depth_ = 0;
3960 function_call_cache function_call_cache_;
3962 std::vector<std::string> global_declarations;
3965 std::map<std::string, std::string> nonlocal_scopes_;
3966 std::vector<std::string> local_loads;
3967 bool is_right =
false;
3968 std::vector<std::string> scope_stack_;
3970 exprt extract_type_from_boolean_op(
const exprt &bool_op);