1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andres Noetzli, Andrew Reynolds, Tim King |
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 |
|
* Representation of constants of uninterpreted sorts. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "expr/uninterpreted_constant.h" |
17 |
|
|
18 |
|
#include <algorithm> |
19 |
|
#include <iostream> |
20 |
|
#include <sstream> |
21 |
|
#include <string> |
22 |
|
|
23 |
|
#include "base/check.h" |
24 |
|
#include "expr/type_node.h" |
25 |
|
|
26 |
|
using namespace std; |
27 |
|
|
28 |
|
namespace cvc5 { |
29 |
|
|
30 |
19367 |
UninterpretedConstant::UninterpretedConstant(const TypeNode& type, |
31 |
19367 |
Integer index) |
32 |
19367 |
: d_type(new TypeNode(type)), d_index(index) |
33 |
|
{ |
34 |
|
//PrettyCheckArgument(type.isSort(), type, "uninterpreted constants can only be created for uninterpreted sorts, not `%s'", type.toString().c_str()); |
35 |
19367 |
PrettyCheckArgument(index >= 0, index, "index >= 0 required for uninterpreted constant index, not `%s'", index.toString().c_str()); |
36 |
19367 |
} |
37 |
|
|
38 |
21437 |
UninterpretedConstant::~UninterpretedConstant() {} |
39 |
|
|
40 |
2070 |
UninterpretedConstant::UninterpretedConstant(const UninterpretedConstant& other) |
41 |
2070 |
: d_type(new TypeNode(other.getType())), d_index(other.getIndex()) |
42 |
|
{ |
43 |
2070 |
} |
44 |
|
|
45 |
118930 |
const TypeNode& UninterpretedConstant::getType() const { return *d_type; } |
46 |
30536 |
const Integer& UninterpretedConstant::getIndex() const { return d_index; } |
47 |
43233 |
bool UninterpretedConstant::operator==(const UninterpretedConstant& uc) const |
48 |
|
{ |
49 |
43233 |
return getType() == uc.getType() && d_index == uc.d_index; |
50 |
|
} |
51 |
|
bool UninterpretedConstant::operator!=(const UninterpretedConstant& uc) const |
52 |
|
{ |
53 |
|
return !(*this == uc); |
54 |
|
} |
55 |
|
|
56 |
|
bool UninterpretedConstant::operator<(const UninterpretedConstant& uc) const |
57 |
|
{ |
58 |
|
return getType() < uc.getType() |
59 |
|
|| (getType() == uc.getType() && d_index < uc.d_index); |
60 |
|
} |
61 |
|
bool UninterpretedConstant::operator<=(const UninterpretedConstant& uc) const |
62 |
|
{ |
63 |
|
return getType() < uc.getType() |
64 |
|
|| (getType() == uc.getType() && d_index <= uc.d_index); |
65 |
|
} |
66 |
|
bool UninterpretedConstant::operator>(const UninterpretedConstant& uc) const |
67 |
|
{ |
68 |
|
return !(*this <= uc); |
69 |
|
} |
70 |
|
bool UninterpretedConstant::operator>=(const UninterpretedConstant& uc) const |
71 |
|
{ |
72 |
|
return !(*this < uc); |
73 |
|
} |
74 |
|
|
75 |
9 |
std::ostream& operator<<(std::ostream& out, const UninterpretedConstant& uc) { |
76 |
18 |
std::stringstream ss; |
77 |
9 |
ss << uc.getType(); |
78 |
18 |
std::string st(ss.str()); |
79 |
|
// must remove delimiting quotes from the name of the type |
80 |
|
// this prevents us from printing symbols like |@uc_|T|_n| |
81 |
18 |
std::string q("|"); |
82 |
|
size_t pos; |
83 |
9 |
while ((pos = st.find(q)) != std::string::npos) |
84 |
|
{ |
85 |
|
st.replace(pos, 1, ""); |
86 |
|
} |
87 |
18 |
return out << "uc_" << st.c_str() << "_" << uc.getIndex(); |
88 |
|
} |
89 |
|
|
90 |
27647 |
size_t UninterpretedConstantHashFunction::operator()( |
91 |
|
const UninterpretedConstant& uc) const |
92 |
|
{ |
93 |
55294 |
return std::hash<TypeNode>()(uc.getType()) |
94 |
55294 |
* IntegerHashFunction()(uc.getIndex()); |
95 |
|
} |
96 |
|
|
97 |
29505 |
} // namespace cvc5 |