1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Tim King, Andres Noetzli, Morgan Deters |
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 a constant array (an array in which the element is the |
14 |
|
* same for all indices). |
15 |
|
*/ |
16 |
|
|
17 |
|
#include "expr/array_store_all.h" |
18 |
|
|
19 |
|
#include <iostream> |
20 |
|
|
21 |
|
#include "base/check.h" |
22 |
|
#include "expr/node.h" |
23 |
|
#include "expr/type_node.h" |
24 |
|
|
25 |
|
using namespace std; |
26 |
|
|
27 |
|
namespace cvc5 { |
28 |
|
|
29 |
6175 |
ArrayStoreAll::ArrayStoreAll(const TypeNode& type, const Node& value) |
30 |
6187 |
: d_type(), d_value() |
31 |
|
{ |
32 |
|
// this check is stronger than the assertion check in the expr manager that |
33 |
|
// ArrayTypes are actually array types |
34 |
|
// because this check is done in production builds too |
35 |
6175 |
PrettyCheckArgument( |
36 |
|
type.isArray(), type, |
37 |
|
"array store-all constants can only be created for array types, not `%s'", |
38 |
|
type.toString().c_str()); |
39 |
|
|
40 |
6167 |
PrettyCheckArgument( |
41 |
|
value.getType().isComparableTo(type.getArrayConstituentType()), |
42 |
|
value, |
43 |
|
"expr type `%s' does not match constituent type of array type `%s'", |
44 |
|
value.getType().toString().c_str(), |
45 |
|
type.toString().c_str()); |
46 |
12330 |
Trace("arrays") << "constructing constant array of type: '" << type |
47 |
6165 |
<< "' and value: '" << value << "'" << std::endl; |
48 |
6165 |
PrettyCheckArgument( |
49 |
|
value.isConst(), value, "ArrayStoreAll requires a constant expression"); |
50 |
|
|
51 |
|
// Delay allocation until the checks above have been performed. If these |
52 |
|
// fail, the memory for d_type and d_value should not leak. The alternative |
53 |
|
// is catch, delete and re-throw. |
54 |
6163 |
d_type.reset(new TypeNode(type)); |
55 |
6163 |
d_value.reset(new Node(value)); |
56 |
6163 |
} |
57 |
|
|
58 |
16618 |
ArrayStoreAll::ArrayStoreAll(const ArrayStoreAll& other) |
59 |
16618 |
: d_type(new TypeNode(other.getType())), d_value(new Node(other.getValue())) |
60 |
|
{ |
61 |
16618 |
} |
62 |
|
|
63 |
22781 |
ArrayStoreAll::~ArrayStoreAll() {} |
64 |
|
ArrayStoreAll& ArrayStoreAll::operator=(const ArrayStoreAll& other) { |
65 |
|
(*d_type) = other.getType(); |
66 |
|
(*d_value) = other.getValue(); |
67 |
|
return *this; |
68 |
|
} |
69 |
|
|
70 |
39062 |
const TypeNode& ArrayStoreAll::getType() const { return *d_type; } |
71 |
|
|
72 |
53925 |
const Node& ArrayStoreAll::getValue() const { return *d_value; } |
73 |
|
|
74 |
6717 |
bool ArrayStoreAll::operator==(const ArrayStoreAll& asa) const |
75 |
|
{ |
76 |
6717 |
return getType() == asa.getType() && getValue() == asa.getValue(); |
77 |
|
} |
78 |
|
|
79 |
|
bool ArrayStoreAll::operator!=(const ArrayStoreAll& asa) const |
80 |
|
{ |
81 |
|
return !(*this == asa); |
82 |
|
} |
83 |
|
|
84 |
|
bool ArrayStoreAll::operator<(const ArrayStoreAll& asa) const |
85 |
|
{ |
86 |
|
return (getType() < asa.getType()) |
87 |
|
|| (getType() == asa.getType() && getValue() < asa.getValue()); |
88 |
|
} |
89 |
|
|
90 |
|
bool ArrayStoreAll::operator<=(const ArrayStoreAll& asa) const |
91 |
|
{ |
92 |
|
return (getType() < asa.getType()) |
93 |
|
|| (getType() == asa.getType() && getValue() <= asa.getValue()); |
94 |
|
} |
95 |
|
|
96 |
|
bool ArrayStoreAll::operator>(const ArrayStoreAll& asa) const |
97 |
|
{ |
98 |
|
return !(*this <= asa); |
99 |
|
} |
100 |
|
|
101 |
|
bool ArrayStoreAll::operator>=(const ArrayStoreAll& asa) const |
102 |
|
{ |
103 |
|
return !(*this < asa); |
104 |
|
} |
105 |
|
|
106 |
|
std::ostream& operator<<(std::ostream& out, const ArrayStoreAll& asa) { |
107 |
|
return out << "__array_store_all__(" << asa.getType() << ", " |
108 |
|
<< asa.getValue() << ')'; |
109 |
|
} |
110 |
|
|
111 |
8403 |
size_t ArrayStoreAllHashFunction::operator()(const ArrayStoreAll& asa) const { |
112 |
16806 |
return std::hash<TypeNode>()(asa.getType()) |
113 |
16806 |
* std::hash<Node>()(asa.getValue()); |
114 |
|
} |
115 |
|
|
116 |
28191 |
} // namespace cvc5 |