CBMC
smt_array_theory.cpp
Go to the documentation of this file.
1 // Author: Diffblue Ltd.
2 
3 #include "smt_array_theory.h"
4 
6 {
7  return "select";
8 }
9 
11  const smt_termt &array,
12  const smt_termt &index)
13 {
14  return array.get_sort().cast<smt_array_sortt>()->element_sort();
15 }
16 
18  const smt_termt &array,
19  const smt_termt &index)
20 {
21  const auto array_sort = array.get_sort().cast<smt_array_sortt>();
22  if(!array_sort)
23  return {"\"select\" may only select from an array."};
24  if(array_sort->index_sort() != index.get_sort())
25  return {"Sort of arrays index must match the sort of the index supplied."};
26  return {};
27 }
28 
30  const smt_termt &array,
31  const smt_termt &index)
32 {
33  const auto validation_errors = selectt::validation_errors(array, index);
34  INVARIANT(validation_errors.empty(), validation_errors[0]);
35 }
36 
39 
41 {
42  return "store";
43 }
45  const smt_termt &array,
46  const smt_termt &index,
47  const smt_termt &value)
48 {
49  return array.get_sort();
50 }
52  const smt_termt &array,
53  const smt_termt &index,
54  const smt_termt &value)
55 {
56  const auto array_sort = array.get_sort().cast<smt_array_sortt>();
57  INVARIANT(array_sort, "\"store\" may only update an array.");
58  INVARIANT(
59  array_sort->index_sort() == index.get_sort(),
60  "Sort of arrays index must match the sort of the index supplied.");
61  INVARIANT(
62  array_sort->element_sort() == value.get_sort(),
63  "Sort of arrays value must match the sort of the value supplied.");
64 }
65 
static const smt_function_application_termt::factoryt< storet > store
static const smt_function_application_termt::factoryt< selectt > select
const sub_classt * cast() const &
const smt_sortt & get_sort() const
Definition: smt_terms.cpp:36
static const char * identifier()
static smt_sortt return_sort(const smt_termt &array, const smt_termt &index)
static void validate(const smt_termt &array, const smt_termt &index)
static std::vector< std::string > validation_errors(const smt_termt &array, const smt_termt &index)
static const char * identifier()
static void validate(const smt_termt &array, const smt_termt &index, const smt_termt &value)
static smt_sortt return_sort(const smt_termt &array, const smt_termt &index, const smt_termt &value)