8#include <nlohmann/json.hpp>
14#include <unordered_map>
21 static const std::unordered_map<std::string, StatementType> statement_map = {
45 if (!element.contains(
"_type"))
48 auto it = statement_map.find(element[
"_type"]);
53inline const std::unordered_map<std::string, std::string> &
operator_map()
55 static const std::unordered_map<std::string, std::string> m = {
56 {
"add",
"+"}, {
"sub",
"-"}, {
"subtract",
"-"},
57 {
"mult",
"*"}, {
"multiply",
"*"}, {
"dot",
"*"},
58 {
"div",
"/"}, {
"divide",
"/"}, {
"mod",
"mod"},
59 {
"bitor",
"bitor"}, {
"floordiv",
"/"}, {
"bitand",
"bitand"},
60 {
"bitxor",
"bitxor"}, {
"invert",
"bitnot"}, {
"lshift",
"shl"},
61 {
"rshift",
"ashr"}, {
"usub",
"unary-"}, {
"eq",
"="},
62 {
"lt",
"<"}, {
"lte",
"<="}, {
"noteq",
"notequal"},
63 {
"gt",
">"}, {
"gte",
">="}, {
"and",
"and"},
64 {
"or",
"or"}, {
"not",
"not"}, {
"uadd",
"unary+"},
65 {
"is",
"="}, {
"isnot",
"not"}, {
"in",
"="}};
74 std::string lower_op = op;
76 lower_op.begin(), lower_op.end(), lower_op.begin(), [](
unsigned char c) {
77 return std::tolower(c);
81 if (type.is_floatbv())
83 static const std::unordered_map<std::string, std::string> float_ops = {
86 {
"subtract",
"ieee_sub"},
89 {
"multiply",
"ieee_mul"},
91 {
"divide",
"ieee_div"}};
93 auto float_it = float_ops.find(lower_op);
94 if (float_it != float_ops.end())
95 return float_it->second;
101 auto it = m.find(lower_op);
111 const std::string &class_name,
112 const std::string &comp_name,
132 const nlohmann::json class_node =
135 class_node.empty() || !class_node.contains(
"bases") ||
136 !class_node[
"bases"].is_array())
138 for (
const auto &
base : class_node[
"bases"])
139 if (
base.is_object() &&
base.contains(
"id"))
142 const std::string resolved =
144 if (resolved ==
"Enum")
153 if (!node.is_object())
156 node.value(
"_type",
"") ==
"Constant" && node.contains(
"value") &&
157 node[
"value"].is_number_integer())
160 return node.value(
"_type",
"") ==
"UnaryOp" && node.contains(
"op") &&
161 node[
"op"].value(
"_type",
"") ==
"USub" && node.contains(
"operand") &&
162 node[
"operand"].value(
"_type",
"") ==
"Constant" &&
163 node[
"operand"].contains(
"value") &&
164 node[
"operand"][
"value"].is_number_integer();
172 if (node.value(
"_type",
"") ==
"Constant")
173 return node[
"value"].get<
long long>();
175 return -node[
"operand"][
"value"].get<
long long>();
182 if (!slice.contains(
"step") || slice[
"step"].is_null())
186 if (!step || *step == 0)
194 const nlohmann::json &slice,
196 const long long axis_len,
197 const long long step)
199 const bool lower = std::string(name) ==
"lower";
200 if (!slice.contains(name) || slice[name].is_null())
203 return lower ? 0 : axis_len;
204 return lower ? axis_len - 1 : -1;
219inline std::optional<std::size_t>
226 const long long axis_len =
static_cast<long long>(dim);
227 const std::optional<long long> start =
229 const std::optional<long long> stop =
234 const long long span = *step > 0 ? *stop - *start : *start - *stop;
235 const long long stride = *step > 0 ? *step : -*step;
236 return span <= 0 ? 0 : static_cast<std::size_t>((span - 1) / stride + 1);
static const twodig_t base
Definition bigint.cpp:28
typet & type()
Definition irep.h:153
Definition std_types.h:87
void set_access(const irep_idt &access)
Definition std_types.h:136
static void set_member_name(typet &t, const irep_idt &value)
Definition type_utils.h:239
#define log_warning(fmt,...)
Definition message.h:89
JsonType find_class(const JsonType &ast_json, const std::string &class_name)
Definition json_utils.h:159
const std::string get_object_alias(const JsonType &ast, const std::string &obj_name)
Definition json_utils.h:675
Definition converter_internal.h:17
bool is_literal_int_node(const nlohmann::json &node)
Definition converter_internal.h:151
std::string map_operator(const std::string &op, const typet &type)
Definition converter_internal.h:71
std::optional< std::size_t > literal_slice_length(const std::size_t dim, const nlohmann::json &slice)
Definition converter_internal.h:220
StatementType get_statement_type(const nlohmann::json &element)
Definition converter_internal.h:19
std::optional< long long > literal_slice_step(const nlohmann::json &slice)
Definition converter_internal.h:180
bool is_enum_class(const std::string &class_name, const nlohmann::json &ast_json)
Definition converter_internal.h:130
const std::unordered_map< std::string, std::string > & operator_map()
Definition converter_internal.h:53
std::optional< long long > literal_slice_bound(const nlohmann::json &slice, const char *name, const long long axis_len, const long long step)
Definition converter_internal.h:193
std::optional< long long > literal_int_value(const nlohmann::json &node)
Definition converter_internal.h:167
struct_typet::componentt build_component(const std::string &class_name, const std::string &comp_name, const typet &type)
Definition converter_internal.h:110
const T & max(const T &left, const T &right)
Definition min_max.h:10
const T & min(const T &left, const T &right)
Definition min_max.h:19
static std::string lower(std::string s)
Definition st_fb_translator.cpp:95
StatementType
Definition type_utils.h:18
@ BREAK
Definition type_utils.h:31
@ ASSERT
Definition type_utils.h:27
@ RAISE
Definition type_utils.h:33
@ CONTINUE
Definition type_utils.h:32
@ FOR_STATEMENT
Definition type_utils.h:24
@ EXCEPTHANDLER
Definition type_utils.h:38
@ NONLOCAL
Definition type_utils.h:36
@ WHILE_STATEMENT
Definition type_utils.h:23
@ IF_STATEMENT
Definition type_utils.h:22
@ VARIABLE_ASSIGN
Definition type_utils.h:19
@ TRY
Definition type_utils.h:37
@ UNKNOWN
Definition type_utils.h:34
@ GLOBAL
Definition type_utils.h:35
@ DELETE_STATEMENT
Definition type_utils.h:39
@ PASS
Definition type_utils.h:29
@ COMPOUND_ASSIGN
Definition type_utils.h:20
@ RETURN
Definition type_utils.h:26
@ CLASS_DEFINITION
Definition type_utils.h:28
@ EXPR
Definition type_utils.h:25
@ IMPORT
Definition type_utils.h:30
@ FUNC_DEFINITION
Definition type_utils.h:21