30 const irept &parse_tree,
31 const std::unordered_map<irep_idt, smt_identifier_termt> &identifier_table);
34 template <
typename argumentt,
typename... argumentst>
36 std::vector<std::string> &collected_error_messages,
39 if(
const auto messages = argument.get_if_error())
41 collected_error_messages.insert(
42 collected_error_messages.end(), messages->cbegin(), messages->end());
47 template <
typename argumentt,
typename... argumentst>
49 std::vector<std::string> &collected_error_messages,
51 argumentst &&... arguments)
61 template <
typename... argumentst>
64 std::vector<std::string> collected_error_messages;
66 return collected_error_messages;
84 typename smt_to_constructt,
85 typename smt_baset = smt_to_constructt,
86 typename... argumentst>
90 if(!collected_error_messages.empty())
95 smt_to_constructt{(*arguments.get_if_valid())...}};
107 return parse_tree.
pretty(0, 0);
113 if(!parse_tree.
get_sub().empty())
133 if(parse_tree.
get_sub().empty())
135 if(parse_tree.
get_sub().at(0).id() !=
"error")
139 if(parse_tree.
get_sub().size() == 1)
142 "Error response is missing the error message."}};
144 if(parse_tree.
get_sub().size() > 2)
147 "Error response has multiple error messages - \"" +
150 return validation_propagating<smt_error_responset, smt_responset>(
159 [](
const irept &sub) { return sub.get_sub().size() == 2; });
167 if(parse_tree.
get_sub().size() != 3)
169 if(parse_tree.
get_sub().at(0).id() !=
"_")
172 std::smatch match_results;
173 static const std::regex bv_value_regex{R
"(^bv(\d+)$)", std::regex::optimize};
174 if(!std::regex_search(value_string, match_results, bv_value_regex))
177 match_results.size() == 2,
178 "Match results should include digits sub-expression if regex is matched.");
179 const std::string value_digits = match_results[1];
182 const auto bit_width =
193 if(!parse_tree.
get_sub().empty())
195 if(parse_tree.
id() == ID_true)
197 if(parse_tree.
id() == ID_false)
204 static const std::regex binary_format{
"#b[01]+"};
205 if(!std::regex_match(text, binary_format))
209 const std::size_t width = text.size() - 2;
215 static const std::regex hex_format{
"#x[0-9A-Za-z]+"};
216 if(!std::regex_match(text, hex_format))
218 const std::string hex{text.begin() + 2, text.end()};
223 const std::size_t width = (text.size() - 2) * 4;
234 const auto value_string =
id2string(parse_tree.
id());
243 const irept &parse_tree,
244 const std::unordered_map<irep_idt, smt_identifier_termt> &identifier_table)
246 if(parse_tree.
get_sub().empty())
248 if(parse_tree.
get_sub()[0].id() !=
"select")
250 if(parse_tree.
get_sub().size() != 3)
253 "\"select\" is expected to have 2 arguments, but " +
260 if(!error_messages.empty())
263 *array.get_if_valid(), *index.get_if_valid())};
267 const irept &parse_tree,
268 const std::unordered_map<irep_idt, smt_identifier_termt> &identifier_table)
274 const auto find_result = identifier_table.find(parse_tree.
id());
275 if(find_result != identifier_table.end())
278 const auto select_validation =
281 return *select_validation;
289 const irept &pair_parse_tree,
290 const std::unordered_map<irep_idt, smt_identifier_termt> &identifier_table)
294 const auto descriptor_validation =
296 const auto value_validation =
298 const auto error_messages =
300 if(!error_messages.empty())
301 return resultt{error_messages};
302 const auto &valid_descriptor = *descriptor_validation.get_if_valid();
303 const auto &valid_value = *value_validation.get_if_valid();
304 if(valid_descriptor.get_sort() != valid_value.get_sort())
307 "Mismatched descriptor and value sorts in - " +
312 return resultt{{valid_descriptor, valid_value}};
322 const irept &parse_tree,
323 const std::unordered_map<irep_idt, smt_identifier_termt> &identifier_table)
328 if(parse_tree.
get_sub().empty())
332 std::vector<std::string> error_messages;
333 std::vector<smt_get_value_responset::valuation_pairt> valuation_pairs;
334 for(
const auto &pair : parse_tree.
get_sub())
336 const auto pair_validation_result =
338 if(
const auto error = pair_validation_result.get_if_error())
339 error_messages.insert(error_messages.end(), error->begin(), error->end());
340 if(
const auto valid_pair = pair_validation_result.get_if_valid())
341 valuation_pairs.push_back(*valid_pair);
343 if(!error_messages.empty())
353 const irept &parse_tree,
354 const std::unordered_map<irep_idt, smt_identifier_termt> &identifier_table)
356 if(parse_tree.
id() ==
"sat")
359 if(parse_tree.
id() ==
"unsat")
362 if(parse_tree.
id() ==
"unknown")
366 return *error_response;
367 if(parse_tree.
id() ==
"success")
369 if(parse_tree.
id() ==
"unsupported")
372 const auto get_value_response =
375 return *get_value_response;