9#include <nlohmann/json.hpp>
11#include <unordered_map>
12#include <unordered_set>
30 std::unordered_set<std::string>
39 const std::unordered_set<std::string> &dynamic_type_names,
40 const nlohmann::json &ast_node);
47 bool is_tagged(
const std::string &name)
const;
75 const std::string &name,
96 const std::string &op,
107 const std::string &op,
125 const std::string &type_name,
126 bool type_is_user_class)
const;
149 const std::string &name,
150 const nlohmann::json &scope_body,
151 const nlohmann::json &module_body = nlohmann::json())
const;
160 codet &target_block);
169 const typet &result_type,
186 const std::string &name,
187 codet &target_block);
199 const std::unordered_set<std::string> &dynamic_type_names);
204 std::unordered_set<std::string> added_;
215 std::vector<codet> build_tag_field_assigns(
225 symbolt *find_tag_symbol(
const std::string &name)
const;
232 bool joins_divergent_kinds(
233 const std::string &name,
234 std::unordered_set<std::string> &kinds,
235 bool keeps_value)
const;
242 exprt build_literal_compare_call(
243 const std::string &num_func_name,
244 const std::string &str_func_name,
246 const exprt &literal);
249 exprt build_ordered_literal(
250 const std::string &op,
252 const exprt &literal);
254 build_ordered_obj(
const std::string &op,
const exprt &lhs,
const exprt &rhs);
255 exprt build_add_literal(
257 const exprt &literal,
258 bool tagged_is_left);
259 exprt build_sub_literal(
261 const exprt &literal,
262 bool tagged_is_left);
263 exprt build_div_literal(
265 const exprt &literal,
270 exprt build_div_tagged(
279 exprt operands_type_ok(
280 const std::string &op,
282 const exprt &rhs)
const;
288 void guard_zero_division(
289 const exprt &divisor,
290 const exprt &type_ok,
298 std::unordered_set<std::string> tagged_names_;
304 std::unordered_map<std::string, std::string> aliases_;
~scope_guard()
Definition dynamic_type_handler.cpp:1685
scope_guard(dynamic_type_handler &handler, const std::unordered_set< std::string > &dynamic_type_names)
Definition dynamic_type_handler.cpp:1675
bool is_tagged(const std::string &name) const
True if name currently resolves to a tagged-object symbol, either because it is one of the current if...
Definition dynamic_type_handler.cpp:769
std::unordered_set< std::string > detect_dynamic_type_names(const nlohmann::json &if_node) const
Names assigned genuinely incompatible literal types across every branch of if_node,...
Definition dynamic_type_handler.cpp:594
symbol_id bound_symbol_id(const std::string &name) const
The id of the symbol name binds in the scope being converted: a variable, or class C's own attribute ...
Definition dynamic_type_handler.cpp:754
exprt build_neg_tagged(const exprt &tagged, const locationt &location)
Builds unary minus on a tagged-scalar operand, as 0 - tagged, after guard_type_error for that subtrac...
Definition dynamic_type_handler.cpp:1226
dynamic_type_handler(python_converter &converter, type_handler &type_handler)
Definition dynamic_type_handler.cpp:587
exprt build_tagged_value(const exprt &value, const locationt &location, codet &target_block)
Builds a tagged-object temporary from an already-converted value, for use as either a RETURN value or...
Definition dynamic_type_handler.cpp:1494
void assign(const exprt &rhs, const locationt &location, const std::string &name, codet &target_block)
Fills in the tagged-object fields for name from an already-converted value.
Definition dynamic_type_handler.cpp:898
exprt build_numeric_conversion(const exprt &tagged, const typet &result_type, const locationt &location)
int(tagged) or float(tagged), as result_type says: a str is parsed at runtime and raises ValueError w...
Definition dynamic_type_handler.cpp:1516
exprt handle_comparison(const std::string &op, const exprt &lhs, const exprt &rhs)
Dispatches Eq/NotEq/Lt/LtE/Gt/GtE between a tagged-scalar operand and the other side.
Definition dynamic_type_handler.cpp:973
void resolve_read(symbolt *&symbol) const
Redirects symbol to its tagged-object alias, if a pre-existing variable was aliased for it; no-op oth...
Definition dynamic_type_handler.cpp:910
void refuse_tagged_argument() const
Throws the shared "tagged argument, no known parameter type" refusal.
Definition dynamic_type_handler.cpp:1655
void assign_tagged_object(const exprt &rhs, const locationt &location, const std::string &name, codet &target_block)
Whole-struct copy: fills name's tagged-object symbol from a value that is already tagged-object-typed...
Definition dynamic_type_handler.cpp:1662
bool parameter_call_returns_tagged(const nlohmann::json &call) const
call goes through a parameter of the current function, and every call of that function passes a def r...
Definition dynamic_type_handler.cpp:1466
void refuse_float_tag_operation(const exprt &lhs, const exprt &rhs) const
Throws when a tag may hold a float and lhs op rhs is not a str operation.
Definition dynamic_type_handler.cpp:1641
std::string tagged_symbol_id(const std::string &name) const
The id of the symbol that currently holds name's tagged object, following the alias created for a pre...
Definition dynamic_type_handler.cpp:783
void declare_dynamic_type_names(const std::unordered_set< std::string > &dynamic_type_names, const nlohmann::json &ast_node)
Declares (or aliases) each name's tagged-object symbol before either branch converts,...
Definition dynamic_type_handler.cpp:668
exprt build_truthiness(const exprt &tagged)
Python truthiness of a tagged value, decided by its runtime type.
Definition dynamic_type_handler.cpp:1452
exprt handle_arithmetic(const std::string &op, const exprt &lhs, const exprt &rhs, const locationt &location)
Dispatches Add/Sub/Div between a tagged-scalar operand and a literal.
Definition dynamic_type_handler.cpp:1191
bool scope_assigns_divergent_literal_types(const std::string &name, const nlohmann::json &scope_body, const nlohmann::json &module_body=nlohmann::json()) const
True if some top-level If in scope_body (a function body or the module body) assigns name genuinely i...
Definition dynamic_type_handler.cpp:1485
bool detect_dynamic_return_type(const nlohmann::json &function_node) const
True if a function's top-level if/elif/else chain – including an early return with no else,...
Definition dynamic_type_handler.cpp:1479
exprt build_isinstance_check(const exprt &tagged, const std::string &type_name, bool type_is_user_class) const
Builds isinstance(tagged, type_name).
Definition dynamic_type_handler.cpp:1402
bool tagged_binop_result_may_be_tagged(const std::string &op) const
True if op on two tagged operands can produce either scalar type at runtime (only '+' today); an unta...
Definition dynamic_type_handler.cpp:790
void guard_type_error(const std::string &op, const exprt &lhs, const exprt &rhs, const locationt &location)
Inside a try body, raises a catchable TypeError ahead of an Add/Sub/Div or ordered comparison on the ...
Definition dynamic_type_handler.cpp:1363
Main converter for transforming Python AST into ESBMC's intermediate representation.
Definition python_converter.h:76
Definition type_handler.h:113