ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
python_list.h
Go to the documentation of this file.
1#pragma once
2
3#include <irep2/irep2.h>
4#include <nlohmann/json.hpp>
6#include <util/irep/type.h>
7#include <util/irep/expr.h>
10#include <functional>
11#include <optional>
12#include <set>
13#include <utility>
14
15class exprt;
16class symbolt;
18class type_handler;
19class codet;
20
28
34
36{
37public:
38 python_list(python_converter &converter, const nlohmann::json &list)
39 : converter_(converter), list_value_(list)
40 {
41 }
42
43 // @p from_right selects rsplit() semantics (split at the rightmost @p count
44 // separators) over split() (the leftmost). Defaults to split().
46 python_converter &converter,
47 const nlohmann::json &call_node,
48 const std::string &input,
49 const std::string &separator,
50 long long count,
51 bool from_right = false);
52
54 python_converter &converter,
55 const nlohmann::json &call_node,
56 const exprt &input_expr,
57 const std::string &separator,
58 long long count,
59 bool from_right = false);
60
61 exprt get();
62
73 exprt build_list_from_exprs(const std::vector<exprt> &elems);
74
87 const exprt &size,
88 const exprt &fill_value,
89 const typet &elem_type,
90 const exprt *index_base = nullptr);
91
92 exprt index(const exprt &array, const nlohmann::json &slice_node);
93
106 const exprt &array,
107 const exprt &mask,
108 const nlohmann::json &element);
109
127 const exprt &array,
128 const exprt &mask,
129 const nlohmann::json &element);
130
147 const exprt &array,
148 const exprt &mask,
149 const nlohmann::json &element);
150
156 static bool is_bool_mask_rows_type(const typet &type);
157
171 const exprt &array,
172 const nlohmann::json &slice_node,
173 const nlohmann::json &element);
174
185 const exprt &array,
186 const nlohmann::json &col_index_node,
187 const nlohmann::json &element);
188
202 const exprt &array,
203 const nlohmann::json &col_slice_node,
204 const nlohmann::json &element);
205
221 std::optional<exprt>
222 try_build_diagonal_pointer_view(const exprt &array, long long k);
223
233 std::optional<exprt> build_trace_reduction(const exprt &array, long long k);
234
249 const exprt &array,
250 const nlohmann::json &value_node);
251
263 std::optional<exprt> try_build_ravel_pointer_view(const exprt &array);
264
269 {
270 long long extent = 0;
272 long long stride = 0;
274
275 bool symbolic() const
276 {
277 return extent_expr.is_not_nil() || stride_expr.is_not_nil();
278 }
279 };
280
284 {
287 std::vector<strided_axis> axes;
289 bool readonly = false;
290 };
291
292 std::optional<strided_view_desc> describe_strided_view(const exprt &array);
293 std::optional<exprt> try_build_numpy_param_slice_view(
294 const exprt &array,
295 const typet &resolved_array_type,
296 const nlohmann::json &slice_node);
298 const exprt &array,
299 const typet &elem_type,
300 const nlohmann::json &slice_node) const;
301 std::optional<exprt> unnamed_nd_view_placeholder(
302 const strided_view_desc &view,
303 bool as_view,
304 bool flat_result,
305 const char *unnamed_error) const;
306 std::optional<exprt> alias_contiguous_ravel(
307 const nlohmann::json &arg,
308 const strided_view_desc &view);
310 const nlohmann::json &arg,
311 const strided_view_desc &view,
312 const exprt &count);
313 std::vector<strided_axis> owned_copy_axes(
314 const nlohmann::json &arg,
315 const strided_view_desc &view,
316 bool flatten,
317 const exprt &count);
319 const nlohmann::json &arg,
320 const exprt &count,
321 const std::vector<std::size_t> &new_shape);
323 const nlohmann::json &arg,
324 const strided_axis &source,
325 std::vector<strided_axis> &axes);
327 const std::string &lhs_id,
328 const std::vector<std::size_t> &new_shape);
330 const nlohmann::json &arg,
331 const typet &type,
332 const exprt &init);
334 bool is_any,
335 const nlohmann::json &arg,
336 const strided_view_desc &view);
338 const std::string &function,
339 const nlohmann::json &arg,
340 const strided_view_desc &view,
341 const exprt &count);
343 const exprt &array,
344 const std::vector<nlohmann::json> &idx_nodes,
345 bool allow_plain_array) const;
346 std::optional<strided_axis> runtime_slice_axis(
347 const strided_axis &source,
348 const nlohmann::json &node,
349 exprt &offset);
350 std::optional<strided_axis> slice_strided_axis(
351 const strided_axis &source,
352 const nlohmann::json &node,
353 exprt &offset);
355 const strided_axis &source,
356 const nlohmann::json &node,
357 exprt &offset);
359 const strided_view_desc &src,
360 const std::vector<nlohmann::json> &indices);
361 std::optional<strided_view_desc> contiguous_view_desc(
362 const exprt &array,
363 const typet &elem_type,
364 const std::vector<std::size_t> &shape) const;
366 std::vector<strided_axis> tracked_view_axes(const std::string &view_id) const;
367
371 const strided_view_desc &source,
372 const exprt &offset,
373 const std::vector<strided_axis> &axes,
374 bool readonly = false);
375
380 const strided_view_desc &source,
381 const exprt &offset,
382 const std::vector<strided_axis> &axes,
383 const std::vector<std::size_t> *out_shape = nullptr);
384
385 static exprt axis_extent(const strided_axis &axis);
386 static exprt axis_stride(const strided_axis &axis);
387
390 std::optional<strided_view_desc>
391 symbolic_view_operand(const nlohmann::json &arg);
392
395 const strided_view_desc &view,
396 const std::vector<exprt> &index) const;
397
401 const nlohmann::json &node,
402 const exprt &extent,
403 const std::function<void(const exprt &)> &body);
404
407 void emit_view_loops(
408 const nlohmann::json &node,
409 const strided_view_desc &view,
410 const std::function<void(const exprt &)> &leaf);
411
412 exprt
413 view_element_count(const nlohmann::json &node, const strided_view_desc &view);
414
416 std::optional<exprt> reduce_view_argextreme(
417 const std::string &function,
418 const nlohmann::json &arg);
419 std::optional<exprt> try_reduce_symbolic_view(
420 const std::string &function,
421 const nlohmann::json &arg);
422
425 std::optional<exprt>
426 try_build_symbolic_view_list(const nlohmann::json &arg, bool nested);
427
429 {
432 unknown // depends on a run-time stride
433 };
434
436 static view_contiguity
437 classify_view_contiguity(const strided_view_desc &view);
438
441 std::optional<exprt> try_reshape_symbolic_view(
442 const nlohmann::json &arg,
443 const std::vector<std::size_t> &new_shape);
444
446 std::optional<exprt> try_copy_symbolic_view(
447 const nlohmann::json &arg,
448 bool flatten = false,
449 bool alias_if_contiguous = false);
450
453 const nlohmann::json &node,
454 const char *name,
455 const exprt &value);
456
461 std::optional<exprt> try_build_strided_basic_view(
462 const exprt &array,
463 const std::vector<nlohmann::json> &idx_nodes,
464 bool allow_plain_array = false);
465
467 std::optional<exprt>
468 try_build_strided_view_index(const nlohmann::json &element);
469
472 std::optional<flat_array_shape_info>
473 flat_shape_info_of(const exprt &array) const;
474
478 std::optional<exprt> build_contiguous_shaped_view(
479 const exprt &array,
480 const std::vector<std::size_t> &shape,
481 std::size_t offset,
482 bool readonly);
483
485 exprt scalar_storage_pointer(const exprt &array, const typet &scalar_ptr_type)
486 const;
487
501 std::optional<exprt> try_build_flat_index_assignment_target(
502 const exprt &array,
503 const nlohmann::json &index_node);
504
518 const exprt &array,
519 const std::vector<nlohmann::json> &idx_nodes,
520 const nlohmann::json &element);
521
537 const exprt &array,
538 const std::vector<nlohmann::json> &indices,
539 const nlohmann::json &element);
540
550 const exprt &list_expr,
551 const nlohmann::json &slice_node,
552 const nlohmann::json &value_node);
553
555 const exprt &list_expr,
556 const nlohmann::json &slice_node);
557
558 size_t
559 eq_float_type_id(const std::string &lhs_id, const std::string &rhs_id) const;
560 exprt compare(const exprt &l1, const exprt &l2, const std::string &op);
561
562 exprt contains(const exprt &item, const exprt &list);
563
565 const nlohmann::json &left_node,
566 const nlohmann::json &right_node,
567 const exprt &lhs,
568 const exprt &rhs);
569
581 void retype_element_store(exprt &lhs, exprt &rhs);
582
583 bool has_shared_payload(const typet &type) const;
584
588
591 const nlohmann::json &subscript,
592 const std::string &elem_id,
593 const typet &elem_type);
594
598 std::optional<expr2tc> fast_elem_equality(
599 exprt lhs_val,
600 exprt rhs_val,
601 const typet &lhs_type,
602 const typet &rhs_type) const;
603
609 expr2tc &sizes_ok,
610 std::size_t depth,
611 const exprt &lhs_at,
612 const typet &lhs_type,
613 const exprt &rhs_at,
614 const typet &rhs_type) const;
615
617 const symbolt &list,
618 const nlohmann::json &op,
619 const exprt &elem,
620 bool enable_float_path = true);
621
623 const symbolt &list,
624 const exprt &index,
625 const nlohmann::json &op,
626 const exprt &elem);
627
629 const symbolt &list,
630 const nlohmann::json &op,
631 const exprt &other_list);
632
633 // Build: result = lhs + rhs (concatenation)
635 const exprt &lhs,
636 const exprt &rhs,
637 const nlohmann::json &element);
638
641 std::vector<exprt> literal_elems_for_variable_list(
642 const nlohmann::json *source_node,
643 const exprt &source_list);
644
647 const exprt &source_list,
648 size_t literal_elem_count);
649
652 const nlohmann::json &param_node,
653 const std::string &param_id,
654 const typet &annotated,
655 size_t index);
656
658 bool mixes_list_and_other(const std::string &id) const;
659
662 const exprt &array,
663 const nlohmann::json &slice_node) const;
664
668 const exprt &array,
669 const nlohmann::json &slice_node) const;
670
676
682 exprt handle_comprehension(const nlohmann::json &element);
683
692 const symbolt &list,
693 const exprt &index,
694 const nlohmann::json &element);
695
701 void guard_pop_index(
702 const symbolt &list,
703 const exprt &index,
704 const locationt &location);
705
708 bool
709 store_replaces_element(const typet &old_type, const typet &new_type) const;
710
713 std::optional<exprt> build_element_replacement(
714 const exprt &lhs,
715 const exprt &rhs,
716 const nlohmann::json &op);
717
732 const exprt &pyobject_expr,
733 const typet &elem_type,
734 bool mixed_numeric = false,
735 bool string_safe = false);
736
750 typet infer_literal_element_type(const nlohmann::json &list_literal);
751
770 const exprt &list_arg,
771 const std::string &list_id,
772 const std::string &func_name,
773 irep_idt comparison_op);
774
785 python_converter &converter,
786 const nlohmann::json &range_args,
787 const nlohmann::json &element,
788 bool materialise_elements = true);
789
797 python_converter &converter,
798 const exprt &tuple_expr,
799 const nlohmann::json &element);
800
807 exprt
808 build_copy_list_call(const symbolt &list, const nlohmann::json &element);
809
819 exprt
820 build_shallow_copy_call(const exprt &src_list, const nlohmann::json &element);
821
823 exprt
824 build_tuple_copy_call(const exprt &src_list, const nlohmann::json &element);
825
827 void build_mark_tuple_call(const exprt &list);
828
830 exprt build_is_tuple_call(const exprt &list);
831
837 const symbolt &list,
838 const nlohmann::json &op,
839 const exprt &elem);
840
846 const symbolt &list,
847 const nlohmann::json &op,
848 const exprt &elem);
849
856 const symbolt &list,
857 const nlohmann::json &op,
858 const exprt &elem);
859
866 const symbolt &list,
867 const nlohmann::json &op,
868 const exprt &elem,
869 const exprt &start,
870 const exprt &end);
871
875 const symbolt &list,
876 const nlohmann::json &op,
877 const exprt &elem,
878 const std::string &func_id);
879
889 const symbolt &set,
890 const nlohmann::json &op,
891 const exprt &elem,
892 const std::string &method_name);
893
905 BigInt uniform_elem_size(const std::string &list_id) const;
906
910 BigInt uniform_elem_size(const exprt &list) const;
911
916
919 typet attribute_elem_type(const exprt &array) const;
920
924 recorded_elem_types(const exprt &array) const;
925
928
929 // True when the list's recorded element types include a tagged scalar, whose
930 // payload width is per-element and symbolic (#7716).
931 bool has_tagged_elements(const exprt &list) const;
932
936 const exprt &array,
937 bool constant_index,
938 const nlohmann::json &list_node,
939 const typet &fallback) const;
940
946
952 select_shallow_push(const exprt &src, const exprt &untagged_last_arg) const;
953
955 select_list_extend(const exprt &src, const exprt &untagged_elem_size) const;
956
958 {
959 const symbolt *func;
960 std::vector<exprt> trailing_args;
961 };
962
968 const exprt &l1,
969 const exprt &l2,
970 const symbolt &generic_func,
971 const std::vector<exprt> &generic_trailing_args) const;
972
987 const nlohmann::json &ast_node,
988 const nlohmann::json &target,
989 const exprt &list_expr,
990 codet &target_block);
991
992private:
995 exprt check_unpack_length(
996 const exprt &list_expr,
997 size_t fixed,
998 bool starred,
999 const locationt &loc,
1000 codet &target_block);
1001
1002 typet unpack_elem_type(
1003 const std::string &list_id,
1004 size_t i,
1005 const typet &fallback) const;
1006
1008 size_t
1009 recorded_index_from_end(const std::string &list_id, size_t from_end) const;
1010
1011 void record_starred_elem_types(
1012 const std::string &list_id,
1013 const std::string &star_id,
1014 size_t before_star,
1015 size_t after_star,
1016 const typet &elem_type);
1017
1019 void assign_unpack_target(
1020 const nlohmann::json &ast_node,
1021 const nlohmann::json &tgt_node,
1022 const std::string &list_id,
1023 size_t i,
1024 const exprt &val,
1025 codet &target_block);
1026
1028
1029 // Evaluates value_node once and snapshots it into a fresh temporary, so a
1030 // multi-write caller (try_build_fill_diagonal_mutation) can reuse the
1031 // snapshot instead of re-embedding (and re-evaluating) the same expression
1032 // at each write site. Throws if the value isn't scalar-typed.
1033 exprt snapshot_scalar_value(const nlohmann::json &value_node);
1034
1035 // Repeat the elements in `list_elems` `count` times at runtime (`count` may
1036 // be any integer expression: a constant, a symbol like `n`, or a compound
1037 // like `m + 1`). Each iteration pushes every element in order. Builds a
1038 // fresh list so a literal source's element is not reused (avoids off-by-one).
1039 exprt create_vla(
1040 const nlohmann::json &element,
1041 const exprt &count,
1042 const std::vector<exprt> &list_elems);
1043
1044 exprt build_list_at_call(
1045 const exprt &list,
1046 const exprt &index,
1047 const nlohmann::json &element);
1048
1049 exprt bind_list_element(const exprt &list_at_call);
1050
1052 get_list_element_info(const nlohmann::json &op, const exprt &elem);
1053
1056 void reject_items_view_vs_tuple_set(
1057 const exprt &lhs,
1058 const exprt &rhs,
1059 const exprt &converted_lhs,
1060 const exprt &converted_rhs);
1061
1064 exprt as_object_reference(const nlohmann::json &op, const exprt &elem);
1065
1067 get_tagged_element_info(const nlohmann::json &op, const exprt &elem);
1068
1072 get_lookup_key_info(const nlohmann::json &op, const exprt &key);
1073
1077 get_erased_key_info(const nlohmann::json &op, const exprt &key);
1078
1079 // The type_id a tagged scalar carries when it holds a float, or 0 when the
1080 // caller opts out of the float path (dict values compare via void*).
1081 exprt tagged_float_type_id(bool enable_float_path) const;
1082
1084
1085 exprt
1086 handle_range_slice(const exprt &array, const nlohmann::json &slice_node);
1087
1088 // Propagate a dict view's element types onto its slice result. Split out to
1089 // keep handle_range_slice's own decision count from growing further.
1090 void
1091 copy_dict_view_elem_types(const exprt &array, const std::string &sliced_id);
1092 void copy_list_of_dict_view_elem_types(
1093 const exprt &array,
1094 const std::string &sliced_id);
1095
1096 // Shared core of every ADR-NP-003 scalar pointer view producer; see
1097 // list_access.cpp for the full rationale, including when this declines.
1098 std::optional<exprt> build_scalar_pointer_view(
1099 const exprt &array,
1100 const typet &elem_type,
1101 long long offset,
1102 std::size_t length,
1103 long long stride,
1104 bool readonly);
1105
1106 // ADR-NP-003 etapa 2, first slice: builds a pointer into the base
1107 // array's own storage for a 1-D, unit-stride, literal-bound slice
1108 // assigned directly to a bare name, instead of handle_range_slice()'s
1109 // usual independent copy. Split out to keep that already large
1110 // function's own decision count from growing further; see
1111 // list_access.cpp for the full rationale and the cases intentionally
1112 // left out of this first slice (returns std::nullopt for those, and the
1113 // caller falls through to the existing copy).
1114 std::optional<exprt> try_build_1d_pointer_view(
1115 const exprt &array,
1116 const typet &elem_type,
1117 long long step_val,
1118 bool needs_null_term,
1119 long long literal_start,
1120 long long static_slice_len);
1121
1122 std::optional<exprt> try_build_row_pointer_view(
1123 const exprt &array,
1124 const nlohmann::json &slice_node);
1125
1126 std::optional<exprt> try_build_nd_subarray_pointer_view(
1127 const exprt &array,
1128 const nlohmann::json &slice_node);
1129
1130 std::optional<exprt> try_build_chained_subarray_pointer_view();
1131
1132 std::optional<exprt> try_build_pointer_array_index(
1133 const exprt &array,
1134 const exprt &pos_expr,
1135 const nlohmann::json &slice_node);
1136
1137 exprt build_numpy_array_index_access(
1138 const exprt &array,
1139 const exprt &pos_expr,
1140 const nlohmann::json &slice_node);
1141
1142 std::optional<exprt> try_build_column_pointer_view(
1143 const exprt &array,
1144 const nlohmann::json &col_index_node);
1145
1146 std::optional<exprt> try_build_numpy_view_subview(
1147 const exprt &array,
1148 const nlohmann::json &slice_node);
1149
1150 std::optional<exprt> try_copy_numpy_pointer_view_slice(
1151 const exprt &array,
1152 const typet &elem_type,
1153 const nlohmann::json &slice_node,
1154 long long step_val,
1155 bool literal_step);
1156
1157 void emit_slice_zero_step_raise(
1158 const nlohmann::json &slice_node,
1159 bool literal_zero_step);
1160
1161 exprt normalize_and_scale_index(
1162 const exprt &index,
1163 long long length,
1164 long long stride,
1165 const nlohmann::json &slice_node);
1166
1167 exprt normalize_and_scale_index(
1168 const exprt &index,
1169 const exprt &length,
1170 const exprt &stride,
1171 const nlohmann::json &slice_node);
1172
1173 struct symbolic_slice_params
1174 {
1175 exprt offset;
1176 exprt stride;
1177 exprt length;
1178 };
1179
1182 symbolic_slice_params emit_symbolic_slice_params(
1183 const nlohmann::json &slice_node,
1184 const exprt &extent);
1185
1193 exprt build_symbolic_step_slice(
1194 const exprt &array,
1195 const nlohmann::json &slice_node);
1196
1197 exprt guard_numpy_pointer_view_index(
1198 const exprt &array,
1199 const exprt &index,
1200 const nlohmann::json &slice_node);
1201
1202 exprt guard_numpy_static_array_index(
1203 const exprt &array,
1204 const exprt &index,
1205 const nlohmann::json &slice_node);
1206
1207 exprt
1208 handle_index_access(const exprt &array, const nlohmann::json &slice_node);
1209 exprt index_value(const exprt &index, const nlohmann::json &slice_node);
1210
1211 // True when `array` is a 2-D+ numpy array parameter's decayed pointer
1212 // symbol (register_function_argument's row-pointer decay), i.e. one whose
1213 // pre-decay shape handle_index_access's own negative-index normalization
1214 // needs to consult in numpy_param_shapes_. Split out to keep that
1215 // function's own decision count down.
1216 bool is_numpy_param_negative_index_target(const exprt &array) const;
1217
1218 // handle_index_access's own index/negative-index resolution: normalizes
1219 // pos_expr in place for a literal negative index (a[-1]) against the
1220 // right size source for `array`'s shape (a numpy parameter's pre-decay
1221 // shape, an array_typet's own size, or -- when neither applies -- deferred
1222 // to build_list_at_call's runtime normalization), or sets `index` alone
1223 // for a compile-time-only type lookup. A no-op for anything but a
1224 // UnaryOp(USub)/Constant slice. Split out of handle_index_access to keep
1225 // that function's own decision count down.
1226 void normalize_index_access_position(
1227 const exprt &array,
1228 const nlohmann::json &slice_node,
1229 const nlohmann::json &list_node,
1230 exprt &pos_expr,
1231 size_t &index) const;
1232
1241 std::optional<exprt> resolve_nested_list_element(
1242 const exprt &array,
1243 const exprt &pos_expr,
1244 size_t index,
1245 typet &elem_type);
1246
1262 exprt resolve_fixed_axis_index(
1263 const nlohmann::json &idx_node,
1264 const BigInt &axis_len,
1265 unsigned axis,
1266 const nlohmann::json &element);
1267
1268 // Returns (registering if absent) the __python_str_slice symbol:
1269 // char* __python_str_slice(const char*, long long, long long, long long)
1270 const symbolt &get_str_slice_sym();
1271
1272 exprt remove_function_calls_recursive(exprt &e, const nlohmann::json &node);
1273
1275 element_type_registry &elem_types();
1276 const element_type_registry &elem_types() const;
1277
1288 void emit_list_copy(
1289 const exprt &src,
1290 const symbolt &dst,
1291 const nlohmann::json &element);
1292
1300 static void set_list_symbolic_size(
1301 python_converter &converter,
1302 exprt &list_expr,
1303 const exprt &size_expr,
1304 const nlohmann::json &element);
1305
1319 static exprt handle_symbolic_range(
1320 python_converter &converter,
1321 const nlohmann::json &range_args,
1322 const nlohmann::json &element,
1323 bool materialise_elements);
1324
1336 static exprt build_concrete_range(
1337 python_converter &converter,
1338 const nlohmann::json &range_args,
1339 const nlohmann::json &element,
1340 const std::optional<long long> &arg0,
1341 const std::optional<long long> &arg1,
1342 const std::optional<long long> &arg2);
1343
1344 python_converter &converter_;
1345 const nlohmann::json &list_value_;
1346};
Definition bigint.hh:58
Definition toml.hpp:6607
Definition std_code.h:8
The single owner of per-instance element-type tracking for the Python frontend: "which types does thi...
Definition element_type_registry.h:49
std::vector< entry > entries
Definition element_type_registry.h:54
Definition expr.h:34
Definition irep_idt.h:12
Definition location.h:7
Definition std_expr.h:1168
Main converter for transforming Python AST into ESBMC's intermediate representation.
Definition python_converter.h:76
std::optional< exprt > build_element_replacement(const exprt &lhs, const exprt &rhs, const nlohmann::json &op)
The __ESBMC_list_set_at call storing rhs into the list element lhs reads, when store_replaces_element...
Definition list_mutation.cpp:798
static exprt axis_stride(const strided_axis &axis)
Definition list_strided_consumers.cpp:25
exprt build_insert_list_call(const symbolt &list, const exprt &index, const nlohmann::json &op, const exprt &elem)
Definition list_mutation.cpp:647
bool strided_basic_view_declines(const exprt &array, const std::vector< nlohmann::json > &idx_nodes, bool allow_plain_array) const
Definition list_access.cpp:2264
std::optional< exprt > unnamed_nd_view_placeholder(const strided_view_desc &view, bool as_view, bool flat_result, const char *unnamed_error) const
Definition list_strided_consumers.cpp:336
exprt contains(const exprt &item, const exprt &list)
Definition list_query.cpp:769
exprt handle_comprehension(const nlohmann::json &element)
Convert generator expressions and list comprehensions to lists.
Definition list_comprehension.cpp:8
typet attribute_elem_type(const exprt &array) const
The element type that a program class in the object's MRO annotates the instance-attribute list array...
Definition list_access.cpp:4608
exprt emit_view_accumulator(const nlohmann::json &arg, const typet &type, const exprt &init)
Definition list_strided_consumers.cpp:129
exprt emit_view_copy_buffer(const nlohmann::json &arg, const strided_view_desc &view, const exprt &count)
Definition list_strided_consumers.cpp:373
void handle_list_var_unpacking(const nlohmann::json &ast_node, const nlohmann::json &target, const exprt &list_expr, codet &target_block)
Unpack a list variable into multiple targets, supporting starred expressions.
Definition list_comprehension.cpp:304
std::optional< exprt > build_contiguous_shaped_view(const exprt &array, const std::vector< std::size_t > &shape, std::size_t offset, bool readonly)
Pointer into array's own contiguous storage, offset elements in, that reads as an N-D array of shape;...
Definition list_access.cpp:2531
void guard_pop_index(const symbolt &list, const exprt &index, const locationt &location)
Inside a try body, raises a catchable IndexError ahead of a pop() whose list is empty or whose index ...
Definition list_mutation.cpp:1638
void emit_counted_loop(const nlohmann::json &node, const exprt &extent, const std::function< void(const exprt &)> &body)
idx = 0; while (idx < extent) { body(idx); idx++; }, with the body's statements emitted inside the lo...
Definition list_strided_consumers.cpp:69
exprt build_mixed_slice_tuple_select(const exprt &array, const std::vector< nlohmann::json > &idx_nodes, const nlohmann::json &element)
Lower an N-D mixed slice/index tuple subscript with one or more bounded slice axes and fixed-index ax...
Definition list_access.cpp:1383
std::optional< exprt > try_build_symbolic_view_list(const nlohmann::json &arg, bool nested)
A Python list of a run-time-extent view's elements (nested per axis when nested, flat otherwise).
Definition list_strided_consumers.cpp:291
size_t eq_float_type_id(const std::string &lhs_id, const std::string &rhs_id) const
The float element type_id that lets list_eq compare mixed int and float elements numerically (Python'...
Definition list_query.cpp:126
exprt copy_strided_view(const strided_view_desc &source, const exprt &offset, const std::vector< strided_axis > &axes, const std::vector< std::size_t > *out_shape=nullptr)
Independent array holding the elements a view with these axes reads, in row-major order.
Definition list_access.cpp:2184
exprt build_fancy_index(const exprt &array, const std::vector< nlohmann::json > &indices, const nlohmann::json &element)
Lower integer-array (fancy) indexing a[[0, 2]] to a bounded, unrolled sequence of element reads: each...
Definition list_access.cpp:1563
std::optional< exprt > try_reduce_symbolic_view(const std::string &function, const nlohmann::json &arg)
Definition list_strided_consumers.cpp:255
exprt get()
Definition list_construction.cpp:152
std::vector< strided_axis > tracked_view_axes(const std::string &view_id) const
Axes of the pointer view registered under view_id.
Definition list_access.cpp:2069
void require_stored_types(expr2tc &sizes_ok, std::size_t depth, const exprt &lhs_at, const typet &lhs_type, const exprt &rhs_at, const typet &rhs_type) const
Conjoins to sizes_ok that the slots lhs_at and rhs_at hold lhs_type and rhs_type, for compare()'s nes...
Definition list_query.cpp:97
bool try_build_fill_diagonal_mutation(const exprt &array, const nlohmann::json &value_node)
np.fill_diagonal(a, value): mutates a's main diagonal in place via converter_.add_instruction,...
Definition list_access.cpp:2963
exprt build_index_range_list_call(const symbolt &list, const nlohmann::json &op, const exprt &elem, const exprt &start, const exprt &end)
Build a list.index(x, start[, end]) call — position of the first element equal to x within the slice ...
Definition list_query.cpp:1081
exprt build_pop_list_call(const symbolt &list, const exprt &index, const nlohmann::json &element)
Build a list pop operation.
Definition list_mutation.cpp:1672
bool is_runtime_numpy_slice(const exprt &array, const typet &elem_type, const nlohmann::json &slice_node) const
Definition list_access.cpp:3410
shallow_push_call select_shallow_push(const exprt &src, const exprt &untagged_last_arg) const
Shallow-push entry point for a copy of src.
Definition list_mutation.cpp:1403
typet unrecorded_base_elem_type()
The element type a subscript's base declares when the type map has no record of the list: a name's an...
Definition list_access.cpp:4659
static exprt axis_extent(const strided_axis &axis)
Definition list_strided_consumers.cpp:19
exprt build_list_from_exprs(const std::vector< exprt > &elems)
Materialize a fresh list from already-evaluated element values.
Definition list_construction.cpp:237
std::vector< exprt > literal_elems_for_variable_list(const nlohmann::json *source_node, const exprt &source_list)
The declaring literal's elements for a variable-held list, or empty when the literal cannot be used.
Definition list_mutation.cpp:976
typet bare_list_param_elem_type(const nlohmann::json &param_node, const std::string &param_id, const typet &annotated, size_t index)
Element type recovered for a bare list parameter, or a nil type.
Definition list_access.cpp:4432
bool has_shared_payload(const typet &type) const
Whether a list slot holding type may share its payload with a copy of the list: list copies keep the ...
Definition list_mutation.cpp:417
static bool is_bool_mask_rows_type(const typet &type)
True if type is a result struct built by build_bool_mask_row_select_symbolic (identified by its tag- ...
Definition list_access.cpp:514
exprt index_bool_mask_rows(const exprt &array, const nlohmann::json &slice_node, const nlohmann::json &element)
Index b[i] into a boolean-mask row-selection result (see build_bool_mask_row_select_symbolic): normal...
Definition list_access.cpp:642
std::optional< exprt > alias_contiguous_ravel(const nlohmann::json &arg, const strided_view_desc &view)
Definition list_strided_consumers.cpp:355
exprt build_bool_mask_index(const exprt &array, const exprt &mask, const nlohmann::json &element)
Lower boolean-mask indexing a[mask] to a runtime loop that builds a fresh list holding the elements o...
Definition list_access.cpp:268
exprt build_column_select(const exprt &array, const nlohmann::json &col_index_node, const nlohmann::json &element)
Lower 2-D column selection a[:, j] to a bounded copy over every row of a fixed-shape 2-D array,...
Definition list_access.cpp:1169
bool literal_still_describes_list(const exprt &source_list, size_t literal_elem_count)
True when a list's declaring literal still describes its contents.
Definition list_mutation.cpp:1018
static exprt build_list_from_tuple(python_converter &converter, const exprt &tuple_expr, const nlohmann::json &element)
Materialise a tuple value into a fresh list, pushing each component in order.
Definition list_construction.cpp:375
typet tagged_elem_type_or(const exprt &array, bool constant_index, const nlohmann::json &list_node, const typet &fallback) const
The recorded element type when it is a tagged scalar and the index is not constant; otherwise the fal...
Definition list_access.cpp:4679
exprt list_repetition(const nlohmann::json &left_node, const nlohmann::json &right_node, const exprt &lhs, const exprt &rhs)
Definition list_mutation.cpp:1032
void emit_view_loops(const nlohmann::json &node, const strided_view_desc &view, const std::function< void(const exprt &)> &leaf)
Nested loops over every index of a view; leaf is called once, inside the innermost body,...
Definition list_strided_consumers.cpp:100
std::optional< strided_axis > runtime_slice_axis(const strided_axis &source, const nlohmann::json &node, exprt &offset)
Definition list_access.cpp:2283
exprt build_set_membership_call(const symbolt &set, const nlohmann::json &op, const exprt &elem, const std::string &method_name)
Emit a call to a set membership-mutating C model function.
Definition list_set_ops.cpp:5
exprt build_remove_list_call(const symbolt &list, const nlohmann::json &op, const exprt &elem)
Build a list remove operation (removes first matching element).
Definition list_mutation.cpp:1933
bool store_replaces_element(const typet &old_type, const typet &new_type) const
Whether storing a new_type value into an element read as old_type replaces the element rather than wr...
Definition list_mutation.cpp:762
std::optional< flat_array_shape_info > flat_shape_info_of(const exprt &array) const
Total element count and scalar element type of a fixed-shape array of any rank, or of a contiguous N-...
Definition list_access.cpp:3019
std::optional< exprt > try_build_ravel_pointer_view(const exprt &array)
np.ravel(a)/a.ravel(): a writable, contiguous strided pointer view into a's own buffer (ADR-NP-003 et...
Definition list_access.cpp:3061
void scale_split_axis_strides(const nlohmann::json &arg, const strided_axis &source, std::vector< strided_axis > &axes)
Definition list_strided_consumers.cpp:531
std::optional< exprt > try_build_flat_index_assignment_target(const exprt &array, const nlohmann::json &index_node)
a.flat[i] = x: builds a dereferenced-pointer lvalue into a's own buffer at flat index i (bounds-check...
Definition list_access.cpp:3307
python_list(python_converter &converter, const nlohmann::json &list)
Definition python_list.h:38
void record_element_store(const nlohmann::json &subscript, const std::string &elem_id, const typet &elem_type)
Records elem_type as the type of the element subscript stores to.
Definition list_mutation.cpp:397
exprt reduce_view_truth(bool is_any, const nlohmann::json &arg, const strided_view_desc &view)
Definition list_strided_consumers.cpp:147
std::optional< exprt > reduce_view_argextreme(const std::string &function, const nlohmann::json &arg)
sum / mean / min / max / any / all of a run-time-extent view, as loops.
Definition list_strided_consumers.cpp:202
std::optional< strided_view_desc > contiguous_view_desc(const exprt &array, const typet &elem_type, const std::vector< std::size_t > &shape) const
Definition list_access.cpp:2046
exprt allocate_constructed_object(const exprt &lhs)
Allocates the instance a constructor stores to lhs and returns the pointer to pass as self.
Definition list_mutation.cpp:460
exprt build_copy_list_call(const symbolt &list, const nlohmann::json &element)
Build a list copy operation.
Definition list_mutation.cpp:1753
shallow_push_call select_list_extend(const exprt &src, const exprt &untagged_elem_size) const
Definition list_mutation.cpp:1393
std::optional< exprt > build_trace_reduction(const exprt &array, long long k)
np.trace(a, offset=k): sum of the elements np.diagonal(a, k) would view, computed directly as a scala...
Definition list_access.cpp:2865
static view_contiguity classify_view_contiguity(const strided_view_desc &view)
Whether a view covers its storage densely in row-major order.
Definition list_strided_consumers.cpp:484
const element_type_registry::entries * recorded_elem_types(const exprt &array) const
The type map's record of array, or nullptr when it has none or is an annotated instance attribute.
Definition list_access.cpp:4643
exprt index(const exprt &array, const nlohmann::json &slice_node)
Definition list_access.cpp:252
exprt build_shallow_copy_call(const exprt &src_list, const nlohmann::json &element)
Emit a __ESBMC_list_copy_shallow call producing a shallow copy of src_list (Python copy semantics: sc...
Definition list_mutation.cpp:1826
exprt reduce_view_extreme(const std::string &function, const nlohmann::json &arg, const strided_view_desc &view, const exprt &count)
Definition list_strided_consumers.cpp:166
exprt get_empty_set()
Create an empty set.
exprt extract_pyobject_value(const exprt &pyobject_expr, const typet &elem_type, bool mixed_numeric=false, bool string_safe=false)
Extract and dereference value from a PyObject* expression.
Definition list_access.cpp:5586
bool has_tagged_elements(const exprt &list) const
Definition list_mutation.cpp:1377
exprt scalar_storage_pointer(const exprt &array, const typet &scalar_ptr_type) const
array's storage as a pointer to its scalar element type.
Definition list_access.cpp:3051
std::optional< exprt > try_build_strided_basic_view(const exprt &array, const std::vector< nlohmann::json > &idx_nodes, bool allow_plain_array=false)
v = a[i, :, 1:3, ...] over a rank-3+ array or any N-D view, with literal or run-time indices and slic...
Definition list_access.cpp:2364
void reject_unresolved_element_read(const exprt &array, const nlohmann::json &slice_node) const
Refuses a read that no single recorded element type answers (#8472).
Definition list_access.cpp:4475
bool index_strided_axis(const strided_axis &source, const nlohmann::json &node, exprt &offset)
Definition list_access.cpp:2336
exprt strided_index_offset(const strided_view_desc &src, const std::vector< nlohmann::json > &indices)
Definition list_access.cpp:2435
exprt emit_ll_temp(const nlohmann::json &node, const char *name, const exprt &value)
Signed 64-bit temporary holding value, assigned once here.
Definition list_access.cpp:2022
void handle_subscript_assign_none(const exprt &list_expr, const nlohmann::json &slice_node)
Definition list_access.cpp:4329
std::optional< exprt > try_reshape_symbolic_view(const nlohmann::json &arg, const std::vector< std::size_t > &new_shape)
reshape of a run-time-extent view to constant new_shape: an alias when it is contiguous,...
Definition list_strided_consumers.cpp:571
void emit_reshape_size_guard(const nlohmann::json &arg, const exprt &count, const std::vector< std::size_t > &new_shape)
Definition list_strided_consumers.cpp:507
std::optional< exprt > try_build_diagonal_pointer_view(const exprt &array, long long k)
np.diagonal(a[, offset=k])/a.diagonal([k]): a read-only strided pointer view into a's own buffer (ADR...
Definition list_access.cpp:2816
exprt build_bool_mask_row_select_symbolic(const exprt &array, const exprt &mask, const nlohmann::json &element)
Lower whole-row boolean-mask selection a[mask] on a 2-D array for a symbolic (non-literal) mask: the ...
Definition list_access.cpp:522
view_contiguity
Definition python_list.h:429
@ contiguous
Definition python_list.h:430
@ not_contiguous
Definition python_list.h:431
@ unknown
Definition python_list.h:432
std::optional< expr2tc > fast_elem_equality(exprt lhs_val, exprt rhs_val, const typet &lhs_type, const typet &rhs_type) const
Equality of two list elements read as lhs_type and rhs_type for compare()'s fast path,...
Definition list_query.cpp:56
std::vector< strided_axis > owned_copy_axes(const nlohmann::json &arg, const strided_view_desc &view, bool flatten, const exprt &count)
Definition list_strided_consumers.cpp:408
exprt view_element_count(const nlohmann::json &node, const strided_view_desc &view)
Definition list_strided_consumers.cpp:119
exprt build_concat_list_call(const exprt &lhs, const exprt &rhs, const nlohmann::json &element)
Definition list_mutation.cpp:947
std::optional< strided_view_desc > symbolic_view_operand(const nlohmann::json &arg)
The descriptor of the named view when its extents or strides are known only at run time; nullopt for ...
Definition list_strided_consumers.cpp:32
exprt build_index_list_call(const symbolt &list, const nlohmann::json &op, const exprt &elem)
Build a list.index(x) call — position of the first element equal to x.
Definition list_query.cpp:1015
exprt build_min_max_for_mixed_numeric(const exprt &list_arg, const std::string &list_id, const std::string &func_name, irep_idt comparison_op)
Build an inline min/max computation for a mixed int/float list.
Definition list_query.cpp:904
exprt build_tuple_copy_call(const exprt &src_list, const nlohmann::json &element)
tuple(x) of a list: a shallow copy marked as a tuple (#8777).
Definition list_mutation.cpp:1798
exprt build_bool_mask_row_select(const exprt &array, const exprt &mask, const nlohmann::json &element)
Lower whole-row boolean-mask selection a[mask] on a 2-D array.
Definition list_access.cpp:368
void retype_element_store(exprt &lhs, exprt &rhs)
Turn the store lhs = rhs into a replacement of the element record when the value cannot be written th...
Definition list_mutation.cpp:426
static exprt build_list_from_range(python_converter &converter, const nlohmann::json &range_args, const nlohmann::json &element, bool materialise_elements=true)
Create a list from a range() call.
Definition list_construction.cpp:313
exprt build_extend_list_call(const symbolt &list, const nlohmann::json &op, const exprt &other_list)
Definition list_mutation.cpp:1421
static exprt build_split_list(python_converter &converter, const nlohmann::json &call_node, const std::string &input, const std::string &separator, long long count, bool from_right=false)
Definition list_string_ops.cpp:5
void build_mark_tuple_call(const exprt &list)
Mark list as built by tuple(x) (#8777).
Definition list_mutation.cpp:1808
exprt build_push_list_call(const symbolt &list, const nlohmann::json &op, const exprt &elem, bool enable_float_path=true)
Definition list_mutation.cpp:520
exprt build_is_tuple_call(const exprt &list)
Whether list was built by tuple(x) (#8777).
Definition list_mutation.cpp:1818
exprt build_strided_column_select(const exprt &array, const nlohmann::json &col_slice_node, const nlohmann::json &element)
Lower a strided column slice a[:, start:stop:step] on a fixed-shape 2-D array: the literal slice boun...
Definition list_access.cpp:1251
typet attribute_elem_type_or_any(const exprt &array) const
The element type of array's attribute annotation, or Any without one.
Definition list_access.cpp:4653
std::optional< strided_axis > slice_strided_axis(const strided_axis &source, const nlohmann::json &node, exprt &offset)
Definition list_access.cpp:2310
void reshape_registered_copy(const std::string &lhs_id, const std::vector< std::size_t > &new_shape)
Definition list_strided_consumers.cpp:553
void reject_mixed_member_element_read(const exprt &array, const nlohmann::json &slice_node) const
Refuses an index other than a non-negative constant into a list attribute whose recorded elements hav...
Definition list_access.cpp:4511
typet infer_literal_element_type(const nlohmann::json &list_literal)
Infer the element type of a list literal AST node, accounting for the int->float promotion applied at...
Definition list_type_inference.cpp:291
exprt view_element(const strided_view_desc &view, const std::vector< exprt > &index) const
Element lvalue of a view at a signed 64-bit multi-index.
Definition list_strided_consumers.cpp:51
friend class python_dict_handler
Definition python_list.h:1027
bool mixes_list_and_other(const std::string &id) const
True when the recorded elements of id mix a list with another type.
Definition list_access.cpp:4458
exprt compare(const exprt &l1, const exprt &l2, const std::string &op)
Definition list_query.cpp:155
std::optional< strided_view_desc > describe_strided_view(const exprt &array)
Definition list_access.cpp:2100
BigInt uniform_elem_size(const std::string &list_id) const
The element byte width every recorded element of list_id shares, or 0 when there is no single answer.
Definition list_mutation.cpp:1340
std::optional< exprt > try_build_numpy_param_slice_view(const exprt &array, const typet &resolved_array_type, const nlohmann::json &slice_node)
Definition list_access.cpp:3390
exprt build_count_list_call(const symbolt &list, const nlohmann::json &op, const exprt &elem)
Build a list.count(x) call — number of elements equal to x.
Definition list_query.cpp:1007
list_eq_target select_list_eq(const exprt &l1, const exprt &l2, const symbolt &generic_func, const std::vector< exprt > &generic_trailing_args) const
Equality entry point for l1 == l2 and the arguments that follow the two list operands.
Definition list_query.cpp:37
exprt build_symbolic_fill_list(const exprt &size, const exprt &fill_value, const typet &elem_type, const exprt *index_base=nullptr)
Build a runtime PyListObject filled with fill_value repeated size times.
Definition list_construction.cpp:47
std::optional< exprt > try_build_strided_view_index(const nlohmann::json &element)
b[i][j], b[i, j] or x = b[i] over a registered N-D strided view.
Definition list_access.cpp:2458
exprt register_strided_view(const strided_view_desc &source, const exprt &offset, const std::vector< strided_axis > &axes, bool readonly=false)
base + offset as a registered view with these axes for the assignment target (offset is a size_type e...
Definition list_access.cpp:2140
std::optional< exprt > try_copy_symbolic_view(const nlohmann::json &arg, bool flatten=false, bool alias_if_contiguous=false)
np.copy / np.array / .copy of a run-time-extent view.
Definition list_strided_consumers.cpp:444
exprt build_count_index_list_call(const symbolt &list, const nlohmann::json &op, const exprt &elem, const std::string &func_id)
Shared implementation of build_count_list_call / build_index_list_call; func_id selects the c:@F@__ES...
Definition list_query.cpp:974
void handle_slice_assignment(const exprt &list_expr, const nlohmann::json &slice_node, const nlohmann::json &value_node)
Lower a list slice assignment l[lower:upper:step] = value to a __ESBMC_list_slice_assign model call.
Definition list_access.cpp:4069
Definition symbol.h:12
Definition type_handler.h:113
Definition type.h:9
Definition toml.hpp:1531
int count
Definition cuda.h:51
Classes and definitions for non-stringy internal representation.
irep_container< expr2t > expr2tc
Definition irep2.h:431
static auto create_list(int size, T default_value)
Definition numpy_call_expr.cpp:4866
@ l1
Definition numpy_call_expr.cpp:2087
@ l2
Definition numpy_call_expr.cpp:2086
uint256_t key
Definition solidity_mapping.c:1
unsigned stack_budget_guardt< Tag >::depth
Definition stack_budget.h:72
Definition python_list.h:30
typet elem_type
Definition python_list.h:31
long long total_length
Definition python_list.h:32
Definition module.h:12
Definition python_list.h:22
locationt location
Definition python_list.h:26
symbolt * elem_symbol
Definition python_list.h:24
exprt elem_size
Definition python_list.h:25
symbolt * elem_type_sym
Definition python_list.h:23
Definition python_list.h:958
std::vector< exprt > trailing_args
Definition python_list.h:960
const symbolt * func
Definition python_list.h:959
Definition python_list.h:942
const symbolt * func
Definition python_list.h:943
exprt last_arg
Definition python_list.h:944
One axis of a strided view, in elements: its extent and stride are constants unless the matching expr...
Definition python_list.h:269
long long stride
Definition python_list.h:272
exprt extent_expr
Definition python_list.h:271
long long extent
Definition python_list.h:270
bool symbolic() const
Definition python_list.h:275
exprt stride_expr
Definition python_list.h:273
A numpy array or view as a scalar base pointer plus its axes: the descriptor every N-D view is built ...
Definition python_list.h:284
typet elem_type
Definition python_list.h:286
exprt base
Definition python_list.h:285
std::vector< strided_axis > axes
Definition python_list.h:287
bool readonly
A view of a read-only view (broadcast_to, diagonal) is read-only.
Definition python_list.h:289