-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathboolector_sort.cpp
More file actions
154 lines (130 loc) · 3.46 KB
/
boolector_sort.cpp
File metadata and controls
154 lines (130 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/********************* */
/*! \file boolector_sort.cpp
** \verbatim
** Top contributors (to current version):
** Makai Mann
** This file is part of the smt-switch project.
** Copyright (c) 2020 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file LICENSE in the top-level source
** directory for licensing information.\endverbatim
**
** \brief Boolector implementation of AbsSort
**
**
**/
#include <sstream>
#include "boolector_sort.h"
namespace smt {
/* BoolectorSolver implementation */
BoolectorSortBase::~BoolectorSortBase() { boolector_release_sort(btor, sort); }
std::size_t BoolectorSortBase::hash() const
{
// TODO: come up with better hash function
std::size_t hash = sk;
if(sk == BV)
{
hash ^= get_width();
}
else if(sk == ARRAY)
{
hash ^= get_indexsort()->hash();
hash ^= get_elemsort()->hash();
}
return hash;
}
// by default the following get_* methods don't work
// overloaded in derived classes
uint64_t BoolectorSortBase::get_width() const
{
throw IncorrectUsageException("Only defined for a bit-vector sort.");
};
Sort BoolectorSortBase::get_indexsort() const
{
throw IncorrectUsageException("Only defined for an array sort.");
};
Sort BoolectorSortBase::get_elemsort() const
{
throw IncorrectUsageException("Only defined for an array sort.");
};
SortVec BoolectorSortBase::get_domain_sorts() const
{
throw IncorrectUsageException("Only defined for a function sort.");
};
Sort BoolectorSortBase::get_codomain_sort() const
{
throw IncorrectUsageException("Only defined for a function sort.");
};
std::string BoolectorSortBase::get_uninterpreted_name() const
{
throw IncorrectUsageException(
"Boolector doesn't support uninterpreted sorts.");
}
size_t BoolectorSortBase::get_arity() const
{
throw NotImplementedException(
"Boolector does not support uninterpreted sorts");
}
SortVec BoolectorSortBase::get_uninterpreted_param_sorts() const
{
throw NotImplementedException(
"Boolector does not support uninterpreted sorts.");
}
Datatype BoolectorSortBase::get_datatype() const
{
throw NotImplementedException("get_datatype");
};
bool BoolectorSortBase::compare(const Sort s) const
{
std::shared_ptr<BoolectorSortBase> bs =
std::static_pointer_cast<BoolectorSortBase>(s);
if (sk != bs->get_sort_kind())
{
// Note: bool and bv will still be equal for boolector, because always
// create BV sort even if it's a bool
return false;
}
switch (sk)
{
case ARRAY:
{
return (get_indexsort() == bs->get_indexsort())
&& (get_elemsort() == bs->get_elemsort());
break;
}
case BOOL:
case BV:
{
return get_width() == bs->get_width();
break;
}
case FUNCTION:
{
SortVec domain_sorts = get_domain_sorts();
SortVec bs_domain_sorts = bs->get_domain_sorts();
if (domain_sorts.size() != bs_domain_sorts.size())
{
return false;
}
else if (get_codomain_sort() != bs->get_codomain_sort())
{
return false;
}
bool res = true;
for (unsigned i = 0; i < domain_sorts.size(); ++i)
{
res &= (domain_sorts[i] == bs_domain_sorts[i]);
}
return res;
break;
}
default:
{
Unreachable();
break;
}
}
return false;
}
/* end BoolectorSolver implementation */
} // namespace smt