13 std::string Cpp_Converter::build_operand(
const std::string& operand)
const
15 if (operand.find(
"?") != std::string::npos)
17 return operand.substr(1);
19 if (operand.find(
"sub_") != std::string::npos)
25 return "values[" + operand.substr(4) +
"]";
28 log_error(
"z3_utils",
"Unkown operand format for {}!", operand);
30 return "NOT IMPLEMENTED REACHED";
33 std::string Cpp_Converter::build_operation(
const Converter::Operation& operation,
const std::vector<std::string>& operands)
const
40 for (
const auto& o : operands)
42 op += (build_operand(o) +
" & ");
44 op.erase(op.size() - 3);
47 if (operands.size() > 1)
49 log_error(
"z3_utils",
"unhandled amount of operands for operation");
50 return "NOT IMPLEMENTED REACHED";
52 op =
"!" + build_operand(operands.front());
55 for (
const auto& o : operands)
57 op += (build_operand(o) +
" | ");
59 op.erase(op.size() - 3);
62 for (
const auto& o : operands)
64 op += (build_operand(o) +
" ^ ");
66 op.erase(op.size() - 3);
70 return "NOT IMPLEMENTED REACHED";
77 std::string Cpp_Converter::generate_assignment(
const std::string& l)
const
82 auto sub_expressions_start = l.find(lhs) + lhs.size() + 1;
83 auto sub_expressions_size = l.size() - sub_expressions_start - 2;
84 auto sub_expressions_string = l.substr(sub_expressions_start, sub_expressions_size);
91 return "bool " + lhs +
" = " + rhs +
";\n";
94 std::string Cpp_Converter::generate_initialization(
const std::vector<std::string>& input_vars)
const
96 std::string init =
"";
97 for (
const auto& var : input_vars)
101 log_error(
"z3_utils",
"Wrong variable format for {}! Expecting 'var_<INDEX>'.", var);
102 return "WRONG VAR FORMAT";
105 init = init + var.substr(4) +
",\n";
111 std::string Cpp_Converter::construct_function(
const std::string& assignments,
const std::string& initalization,
const std::vector<std::string>& input_vars)
const
113 std::string func = m_function_corpus;
116 const auto last_assigment_pos = assignments.rfind(
"bool") + 5;
117 const auto last_line = assignments.substr(last_assigment_pos);
122 func =
replace_all(func,
"<ASSIGNMENTS>", assignments);
std::string replace_all(const std::string &str, const std::string &from, const std::string &to) const
std::map< std::string, std::string > extract_sub_exrepssions(const std::string &l) const
std::string extract_lhs(const std::string &l) const
std::map< std::string, std::string > translate_sub_expressions(const std::map< std::string, std::string > &se) const
std::string merge_sub_expressions(const std::map< std::string, std::string > &translated_sub_expressions) const
std::string operation_to_string(const Operation &op) const
#define log_error(channel,...)
bool starts_with(const T &s, const T &start)