ESBMC
Efficient SMT-based Context-Bounded Model Checker
Loading...
Searching...
No Matches
tuple_handler.h
Go to the documentation of this file.
1#ifndef ESBMC_PYTHON_TUPLE_HANDLER_H
2#define ESBMC_PYTHON_TUPLE_HANDLER_H
3
5#include <util/irep/type.h>
6#include <util/irep/expr.h>
7#include <nlohmann/json.hpp>
8#include <string>
9
11class type_handler;
12
20{
21public:
29 static constexpr size_t tuple_str_member_size = 16;
30
37
43 exprt get_tuple_expr(const nlohmann::json &element);
44
53 const exprt &array,
54 const nlohmann::json &slice,
55 const nlohmann::json &element);
56
62 bool is_tuple_type(const typet &type) const;
63
72 const nlohmann::json &ast_node,
73 const nlohmann::json &target,
74 exprt &rhs,
75 codet &target_block);
76
82 typet get_tuple_type_from_annotation(const nlohmann::json &annotation_node);
83
92 const nlohmann::json &ast_node,
93 exprt &rhs,
94 codet &target_block);
95
105 const exprt &lhs,
106 const exprt &rhs,
107 bool invert,
108 const nlohmann::json &element);
109
116 create_tuple_struct_type(const std::vector<typet> &element_types) const;
117
133 const exprt &array,
134 const struct_typet &tuple_type,
135 size_t idx) const;
136
146 const exprt &value,
147 const typet &target,
148 const locationt &loc,
149 codet &target_block);
150
151private:
157 std::string build_tuple_tag(const std::vector<typet> &element_types) const;
158
168 exprt pad_string_element(const exprt &elem) const;
169
171 size_t starred_target_index(const nlohmann::json &targets) const;
172
175 symbolt &unpack_target_symbol(
176 const nlohmann::json &name_node,
177 const typet &type,
178 codet &target_block);
179
180 typet unpack_target_type(const exprt &rhs, const typet &member_type) const;
181
183 void assign_unpacked_element(
184 const exprt &target,
185 const exprt &member_access,
186 const locationt &loc,
187 codet &target_block);
188
191 void assign_starred_elements(
192 const nlohmann::json &ast_node,
193 const nlohmann::json &star_value,
194 const exprt &rhs,
195 size_t first,
196 size_t count,
197 codet &target_block);
198
201 exprt copy_str_to_member(
202 const exprt &str,
203 const array_typet &member_type,
204 const locationt &loc,
205 codet &target_block);
206
208 typet tuple_member_type_from_annotation(const nlohmann::json &node);
209
210 python_converter &converter_;
211 type_handler &type_handler_;
212};
213
214#endif // ESBMC_PYTHON_TUPLE_HANDLER_H
Definition std_types.h:397
Definition toml.hpp:6607
Definition std_code.h:8
Definition expr.h:34
Definition location.h:7
Main converter for transforming Python AST into ESBMC's intermediate representation.
Definition python_converter.h:76
Definition std_types.h:232
Definition symbol.h:12
exprt handle_tuple_membership(const exprt &lhs, const exprt &rhs, bool invert, const nlohmann::json &element)
Handle tuple membership test (e.g., x in tuple).
Definition tuple_handler.cpp:949
tuple_handler(python_converter &converter, type_handler &type_handler)
Construct a new tuple handler.
Definition tuple_handler.cpp:18
void handle_tuple_unpacking(const nlohmann::json &ast_node, const nlohmann::json &target, exprt &rhs, codet &target_block)
Handle tuple unpacking assignments.
Definition tuple_handler.cpp:627
struct_typet create_tuple_struct_type(const std::vector< typet > &element_types) const
Create a tuple struct type from element types.
Definition tuple_handler.cpp:36
typet get_tuple_type_from_annotation(const nlohmann::json &annotation_node)
Get tuple type from annotation (e.g., tuple[int, str]).
Definition tuple_handler.cpp:917
exprt prepare_rhs_for_unpacking(const nlohmann::json &ast_node, exprt &rhs, codet &target_block)
Prepare RHS for unpacking (handle function calls).
Definition tuple_handler.cpp:574
bool is_tuple_type(const typet &type) const
Check if a type represents a tuple.
Definition tuple_handler.cpp:193
exprt get_tuple_expr(const nlohmann::json &element)
Create a tuple expression from AST elements.
Definition tuple_handler.cpp:102
exprt handle_tuple_subscript(const exprt &array, const nlohmann::json &slice, const nlohmann::json &element)
Handle tuple subscripting (e.g., t[0]).
Definition tuple_handler.cpp:323
static constexpr size_t tuple_str_member_size
Fixed byte width of string tuple members (content + NUL padding).
Definition tuple_handler.h:29
exprt get_tuple_element(const exprt &array, const struct_typet &tuple_type, size_t idx) const
Obtain an addressable expression for tuple element idx.
Definition tuple_handler.cpp:202
exprt coerce_to_tuple_type(const exprt &value, const typet &target, const locationt &loc, codet &target_block)
Convert tuple value to the annotation-built tuple type target.
Definition tuple_handler.cpp:287
Definition type_handler.h:113
Definition type.h:9
Definition toml.hpp:1531
int count
Definition cuda.h:51