1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Aina Niemetz, Mudathir Mohamed |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* [[ Add one-line brief description here ]] |
14 |
|
* |
15 |
|
* [[ Add lengthier description here ]] |
16 |
|
* \todo document this file |
17 |
|
*/ |
18 |
|
|
19 |
|
#include "theory/theory_id.h" |
20 |
|
|
21 |
|
#include <sstream> |
22 |
|
|
23 |
|
#include "base/check.h" |
24 |
|
#include "lib/ffs.h" |
25 |
|
|
26 |
|
namespace cvc5 { |
27 |
|
namespace theory { |
28 |
|
|
29 |
291960800 |
TheoryId& operator++(TheoryId& id) |
30 |
|
{ |
31 |
291960800 |
return id = static_cast<TheoryId>(static_cast<int>(id) + 1); |
32 |
|
} |
33 |
|
|
34 |
3855115 |
std::ostream& operator<<(std::ostream& out, TheoryId theoryId) |
35 |
|
{ |
36 |
3855115 |
switch (theoryId) |
37 |
|
{ |
38 |
379821 |
case THEORY_BUILTIN: out << "THEORY_BUILTIN"; break; |
39 |
34777 |
case THEORY_BOOL: out << "THEORY_BOOL"; break; |
40 |
824245 |
case THEORY_UF: out << "THEORY_UF"; break; |
41 |
1107120 |
case THEORY_ARITH: out << "THEORY_ARITH"; break; |
42 |
343842 |
case THEORY_BV: out << "THEORY_BV"; break; |
43 |
13497 |
case THEORY_FP: out << "THEORY_FP"; break; |
44 |
131326 |
case THEORY_ARRAYS: out << "THEORY_ARRAYS"; break; |
45 |
609720 |
case THEORY_DATATYPES: out << "THEORY_DATATYPES"; break; |
46 |
|
case THEORY_SAT_SOLVER: out << "THEORY_SAT_SOLVER"; break; |
47 |
1680 |
case THEORY_SEP: out << "THEORY_SEP"; break; |
48 |
68093 |
case THEORY_SETS: out << "THEORY_SETS"; break; |
49 |
12780 |
case THEORY_BAGS: out << "THEORY_BAGS"; break; |
50 |
325391 |
case THEORY_STRINGS: out << "THEORY_STRINGS"; break; |
51 |
2823 |
case THEORY_QUANTIFIERS: out << "THEORY_QUANTIFIERS"; break; |
52 |
|
|
53 |
|
default: out << "UNKNOWN_THEORY"; break; |
54 |
|
} |
55 |
3855115 |
return out; |
56 |
|
} |
57 |
|
|
58 |
2029506 |
std::string getStatsPrefix(TheoryId theoryId) |
59 |
|
{ |
60 |
2029506 |
switch (theoryId) |
61 |
|
{ |
62 |
156156 |
case THEORY_BUILTIN: return "theory::builtin::"; break; |
63 |
156144 |
case THEORY_BOOL: return "theory::bool::"; break; |
64 |
156144 |
case THEORY_UF: return "theory::uf::"; break; |
65 |
156144 |
case THEORY_ARITH: return "theory::arith::"; break; |
66 |
156144 |
case THEORY_BV: return "theory::bv::"; break; |
67 |
156090 |
case THEORY_FP: return "theory::fp::"; break; |
68 |
156144 |
case THEORY_ARRAYS: return "theory::arrays::"; break; |
69 |
156090 |
case THEORY_DATATYPES: return "theory::datatypes::"; break; |
70 |
156090 |
case THEORY_SEP: return "theory::sep::"; break; |
71 |
156090 |
case THEORY_SETS: return "theory::sets::"; break; |
72 |
156090 |
case THEORY_BAGS: return "theory::bags::"; break; |
73 |
156090 |
case THEORY_STRINGS: return "theory::strings::"; break; |
74 |
156090 |
case THEORY_QUANTIFIERS: return "theory::quantifiers::"; break; |
75 |
|
|
76 |
|
default: break; |
77 |
|
} |
78 |
|
return "unknown::"; |
79 |
|
} |
80 |
|
|
81 |
86636418 |
TheoryId TheoryIdSetUtil::setPop(TheoryIdSet& set) |
82 |
|
{ |
83 |
86636418 |
uint32_t i = ffs(set); // Find First Set (bit) |
84 |
86636418 |
if (i == 0) |
85 |
|
{ |
86 |
12907894 |
return THEORY_LAST; |
87 |
|
} |
88 |
73728524 |
TheoryId id = static_cast<TheoryId>(i - 1); |
89 |
73728524 |
set = setRemove(id, set); |
90 |
73728524 |
return id; |
91 |
|
} |
92 |
|
|
93 |
|
size_t TheoryIdSetUtil::setSize(TheoryIdSet set) |
94 |
|
{ |
95 |
|
size_t count = 0; |
96 |
|
while (setPop(set) != THEORY_LAST) |
97 |
|
{ |
98 |
|
++count; |
99 |
|
} |
100 |
|
return count; |
101 |
|
} |
102 |
|
|
103 |
3939198 |
size_t TheoryIdSetUtil::setIndex(TheoryId id, TheoryIdSet set) |
104 |
|
{ |
105 |
3939198 |
Assert(setContains(id, set)); |
106 |
3939198 |
size_t count = 0; |
107 |
17011346 |
while (setPop(set) != id) |
108 |
|
{ |
109 |
6536074 |
++count; |
110 |
|
} |
111 |
3939198 |
return count; |
112 |
|
} |
113 |
|
|
114 |
118374393 |
TheoryIdSet TheoryIdSetUtil::setInsert(TheoryId theory, TheoryIdSet set) |
115 |
|
{ |
116 |
118374393 |
return set | (1 << theory); |
117 |
|
} |
118 |
|
|
119 |
75411696 |
TheoryIdSet TheoryIdSetUtil::setRemove(TheoryId theory, TheoryIdSet set) |
120 |
|
{ |
121 |
75411696 |
return setDifference(set, setInsert(theory)); |
122 |
|
} |
123 |
|
|
124 |
352754786 |
bool TheoryIdSetUtil::setContains(TheoryId theory, TheoryIdSet set) |
125 |
|
{ |
126 |
352754786 |
return set & (1 << theory); |
127 |
|
} |
128 |
|
|
129 |
|
TheoryIdSet TheoryIdSetUtil::setComplement(TheoryIdSet a) |
130 |
|
{ |
131 |
|
return (~a) & AllTheories; |
132 |
|
} |
133 |
|
|
134 |
27987094 |
TheoryIdSet TheoryIdSetUtil::setIntersection(TheoryIdSet a, TheoryIdSet b) |
135 |
|
{ |
136 |
27987094 |
return a & b; |
137 |
|
} |
138 |
|
|
139 |
10749642 |
TheoryIdSet TheoryIdSetUtil::setUnion(TheoryIdSet a, TheoryIdSet b) |
140 |
|
{ |
141 |
10749642 |
return a | b; |
142 |
|
} |
143 |
|
|
144 |
194481080 |
TheoryIdSet TheoryIdSetUtil::setDifference(TheoryIdSet a, TheoryIdSet b) |
145 |
|
{ |
146 |
194481080 |
return (~b) & a; |
147 |
|
} |
148 |
|
|
149 |
1781796 |
std::string TheoryIdSetUtil::setToString(TheoryIdSet theorySet) |
150 |
|
{ |
151 |
3563592 |
std::stringstream ss; |
152 |
1781796 |
ss << "["; |
153 |
24945144 |
for (unsigned theoryId = 0; theoryId < THEORY_LAST; ++theoryId) |
154 |
|
{ |
155 |
23163348 |
TheoryId tid = static_cast<TheoryId>(theoryId); |
156 |
23163348 |
if (setContains(tid, theorySet)) |
157 |
|
{ |
158 |
3232941 |
ss << tid << " "; |
159 |
|
} |
160 |
|
} |
161 |
1781796 |
ss << "]"; |
162 |
3563592 |
return ss.str(); |
163 |
|
} |
164 |
|
|
165 |
|
} // namespace theory |
166 |
|
} // namespace cvc5 |