Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Representation of a constant array (an array in which the element is the 11 : : * same for all indices). 12 : : */ 13 : : 14 : : #include "expr/array_store_all.h" 15 : : 16 : : #include <iostream> 17 : : 18 : : #include "base/check.h" 19 : : #include "expr/node.h" 20 : : #include "expr/type_node.h" 21 : : 22 : : using namespace std; 23 : : 24 : : namespace cvc5::internal { 25 : : 26 : 19859 : ArrayStoreAll::ArrayStoreAll(const TypeNode& type, const Node& value) 27 : 19859 : : d_type(), d_value() 28 : : { 29 : : // this check is stronger than the assertion check in the expr manager that 30 : : // ArrayTypes are actually array types 31 : : // because this check is done in production builds too 32 [ - + ][ - - ]: 19859 : Assert(type.isArray()) 33 : : << "array store-all constants can only be created for array types, not `" 34 [ - + ][ - + ]: 19859 : << type.toString().c_str() << "'"; [ - - ] 35 [ - + ][ - - ]: 39718 : Assert(value.getType() == type.getArrayConstituentType()) 36 : 19859 : << "expr type `" << value.getType().toString().c_str() 37 : : << "' does not match constituent type of array type `" 38 [ - + ][ - + ]: 19859 : << type.toString().c_str() << "'"; [ - - ] 39 [ + - ]: 39718 : Trace("arrays") << "constructing constant array of type: '" << type 40 : 19859 : << "' and value: '" << value << "'" << std::endl; 41 [ - + ][ - + ]: 19859 : Assert(value.isConst()) << "ArrayStoreAll requires a constant expression"; [ - - ] 42 : : 43 : : // Delay allocation until the checks above have been performed. If these 44 : : // fail, the memory for d_type and d_value should not leak. The alternative 45 : : // is catch, delete and re-throw. 46 : 19859 : d_type.reset(new TypeNode(type)); 47 : 19859 : d_value.reset(new Node(value)); 48 : 19859 : } 49 : : 50 : 31786 : ArrayStoreAll::ArrayStoreAll(const ArrayStoreAll& other) 51 : 31786 : : d_type(new TypeNode(other.getType())), d_value(new Node(other.getValue())) 52 : : { 53 : 31786 : } 54 : : 55 : 51507 : ArrayStoreAll::~ArrayStoreAll() {} 56 : 0 : ArrayStoreAll& ArrayStoreAll::operator=(const ArrayStoreAll& other) 57 : : { 58 : 0 : (*d_type) = other.getType(); 59 : 0 : (*d_value) = other.getValue(); 60 : 0 : return *this; 61 : : } 62 : : 63 : 134422 : const TypeNode& ArrayStoreAll::getType() const { return *d_type; } 64 : : 65 : 148649 : const Node& ArrayStoreAll::getValue() const { return *d_value; } 66 : : 67 : 25936 : bool ArrayStoreAll::operator==(const ArrayStoreAll& asa) const 68 : : { 69 [ + - ][ + - ]: 25936 : return getType() == asa.getType() && getValue() == asa.getValue(); 70 : : } 71 : : 72 : 0 : bool ArrayStoreAll::operator!=(const ArrayStoreAll& asa) const 73 : : { 74 : 0 : return !(*this == asa); 75 : : } 76 : : 77 : 0 : bool ArrayStoreAll::operator<(const ArrayStoreAll& asa) const 78 : : { 79 : 0 : return (getType() < asa.getType()) 80 [ - - ][ - - ]: 0 : || (getType() == asa.getType() && getValue() < asa.getValue()); [ - - ] 81 : : } 82 : : 83 : 0 : bool ArrayStoreAll::operator<=(const ArrayStoreAll& asa) const 84 : : { 85 : 0 : return (getType() < asa.getType()) 86 [ - - ][ - - ]: 0 : || (getType() == asa.getType() && getValue() <= asa.getValue()); [ - - ] 87 : : } 88 : : 89 : 0 : bool ArrayStoreAll::operator>(const ArrayStoreAll& asa) const 90 : : { 91 : 0 : return !(*this <= asa); 92 : : } 93 : : 94 : 0 : bool ArrayStoreAll::operator>=(const ArrayStoreAll& asa) const 95 : : { 96 : 0 : return !(*this < asa); 97 : : } 98 : : 99 : 0 : std::ostream& operator<<(std::ostream& out, const ArrayStoreAll& asa) 100 : : { 101 : 0 : return out << "__array_store_all__(" << asa.getType() << ", " 102 : 0 : << asa.getValue() << ')'; 103 : : } 104 : : 105 : 45007 : size_t ArrayStoreAllHashFunction::operator()(const ArrayStoreAll& asa) const 106 : : { 107 : 45007 : return std::hash<TypeNode>()(asa.getType()) 108 : 45007 : * std::hash<Node>()(asa.getValue()); 109 : : } 110 : : 111 : : } // namespace cvc5::internal