GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/array_store_all.cpp Lines: 22 41 53.7 %
Date: 2021-03-22 Branches: 47 106 44.3 %

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