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 |
159247899 |
TheoryId& operator++(TheoryId& id) |
30 |
|
{ |
31 |
159247899 |
return id = static_cast<TheoryId>(static_cast<int>(id) + 1); |
32 |
|
} |
33 |
|
|
34 |
2995718 |
std::ostream& operator<<(std::ostream& out, TheoryId theoryId) |
35 |
|
{ |
36 |
2995718 |
switch (theoryId) |
37 |
|
{ |
38 |
341250 |
case THEORY_BUILTIN: out << "THEORY_BUILTIN"; break; |
39 |
33861 |
case THEORY_BOOL: out << "THEORY_BOOL"; break; |
40 |
678992 |
case THEORY_UF: out << "THEORY_UF"; break; |
41 |
834802 |
case THEORY_ARITH: out << "THEORY_ARITH"; break; |
42 |
274681 |
case THEORY_BV: out << "THEORY_BV"; break; |
43 |
5934 |
case THEORY_FP: out << "THEORY_FP"; break; |
44 |
176757 |
case THEORY_ARRAYS: out << "THEORY_ARRAYS"; break; |
45 |
386648 |
case THEORY_DATATYPES: out << "THEORY_DATATYPES"; break; |
46 |
|
case THEORY_SAT_SOLVER: out << "THEORY_SAT_SOLVER"; break; |
47 |
1793 |
case THEORY_SEP: out << "THEORY_SEP"; break; |
48 |
53229 |
case THEORY_SETS: out << "THEORY_SETS"; break; |
49 |
8944 |
case THEORY_BAGS: out << "THEORY_BAGS"; break; |
50 |
197718 |
case THEORY_STRINGS: out << "THEORY_STRINGS"; break; |
51 |
1109 |
case THEORY_QUANTIFIERS: out << "THEORY_QUANTIFIERS"; break; |
52 |
|
|
53 |
|
default: out << "UNKNOWN_THEORY"; break; |
54 |
|
} |
55 |
2995718 |
return out; |
56 |
|
} |
57 |
|
|
58 |
1247692 |
std::string getStatsPrefix(TheoryId theoryId) |
59 |
|
{ |
60 |
1247692 |
switch (theoryId) |
61 |
|
{ |
62 |
95290 |
case THEORY_BUILTIN: return "theory::builtin::"; break; |
63 |
95278 |
case THEORY_BOOL: return "theory::bool::"; break; |
64 |
95278 |
case THEORY_UF: return "theory::uf::"; break; |
65 |
95278 |
case THEORY_ARITH: return "theory::arith::"; break; |
66 |
104722 |
case THEORY_BV: return "theory::bv::"; break; |
67 |
95224 |
case THEORY_FP: return "theory::fp::"; break; |
68 |
95278 |
case THEORY_ARRAYS: return "theory::arrays::"; break; |
69 |
95224 |
case THEORY_DATATYPES: return "theory::datatypes::"; break; |
70 |
95224 |
case THEORY_SEP: return "theory::sep::"; break; |
71 |
95224 |
case THEORY_SETS: return "theory::sets::"; break; |
72 |
95224 |
case THEORY_BAGS: return "theory::bags::"; break; |
73 |
95224 |
case THEORY_STRINGS: return "theory::strings::"; break; |
74 |
95224 |
case THEORY_QUANTIFIERS: return "theory::quantifiers::"; break; |
75 |
|
|
76 |
|
default: break; |
77 |
|
} |
78 |
|
return "unknown::"; |
79 |
|
} |
80 |
|
|
81 |
50191556 |
TheoryId TheoryIdSetUtil::setPop(TheoryIdSet& set) |
82 |
|
{ |
83 |
50191556 |
uint32_t i = ffs(set); // Find First Set (bit) |
84 |
50191556 |
if (i == 0) |
85 |
|
{ |
86 |
7908142 |
return THEORY_LAST; |
87 |
|
} |
88 |
42283414 |
TheoryId id = static_cast<TheoryId>(i - 1); |
89 |
42283414 |
set = setRemove(id, set); |
90 |
42283414 |
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 |
3316963 |
size_t TheoryIdSetUtil::setIndex(TheoryId id, TheoryIdSet set) |
104 |
|
{ |
105 |
3316963 |
Assert(setContains(id, set)); |
106 |
3316963 |
size_t count = 0; |
107 |
11366659 |
while (setPop(set) != id) |
108 |
|
{ |
109 |
4024848 |
++count; |
110 |
|
} |
111 |
3316963 |
return count; |
112 |
|
} |
113 |
|
|
114 |
72398668 |
TheoryIdSet TheoryIdSetUtil::setInsert(TheoryId theory, TheoryIdSet set) |
115 |
|
{ |
116 |
72398668 |
return set | (1 << theory); |
117 |
|
} |
118 |
|
|
119 |
43423092 |
TheoryIdSet TheoryIdSetUtil::setRemove(TheoryId theory, TheoryIdSet set) |
120 |
|
{ |
121 |
43423092 |
return setDifference(set, setInsert(theory)); |
122 |
|
} |
123 |
|
|
124 |
210087922 |
bool TheoryIdSetUtil::setContains(TheoryId theory, TheoryIdSet set) |
125 |
|
{ |
126 |
210087922 |
return set & (1 << theory); |
127 |
|
} |
128 |
|
|
129 |
|
TheoryIdSet TheoryIdSetUtil::setComplement(TheoryIdSet a) |
130 |
|
{ |
131 |
|
return (~a) & AllTheories; |
132 |
|
} |
133 |
|
|
134 |
17323767 |
TheoryIdSet TheoryIdSetUtil::setIntersection(TheoryIdSet a, TheoryIdSet b) |
135 |
|
{ |
136 |
17323767 |
return a & b; |
137 |
|
} |
138 |
|
|
139 |
7645075 |
TheoryIdSet TheoryIdSetUtil::setUnion(TheoryIdSet a, TheoryIdSet b) |
140 |
|
{ |
141 |
7645075 |
return a | b; |
142 |
|
} |
143 |
|
|
144 |
113865018 |
TheoryIdSet TheoryIdSetUtil::setDifference(TheoryIdSet a, TheoryIdSet b) |
145 |
|
{ |
146 |
113865018 |
return (~b) & a; |
147 |
|
} |
148 |
|
|
149 |
1342641 |
std::string TheoryIdSetUtil::setToString(TheoryIdSet theorySet) |
150 |
|
{ |
151 |
2685282 |
std::stringstream ss; |
152 |
1342641 |
ss << "["; |
153 |
18796974 |
for (unsigned theoryId = 0; theoryId < THEORY_LAST; ++theoryId) |
154 |
|
{ |
155 |
17454333 |
TheoryId tid = static_cast<TheoryId>(theoryId); |
156 |
17454333 |
if (setContains(tid, theorySet)) |
157 |
|
{ |
158 |
2422246 |
ss << tid << " "; |
159 |
|
} |
160 |
|
} |
161 |
1342641 |
ss << "]"; |
162 |
2685282 |
return ss.str(); |
163 |
|
} |
164 |
|
|
165 |
|
} // namespace theory |
166 |
|
} // namespace cvc5 |