GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/uninterpreted_constant.cpp Lines: 25 38 65.8 %
Date: 2021-11-07 Branches: 31 84 36.9 %

Line Exec Source
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
17519
UninterpretedConstant::UninterpretedConstant(const TypeNode& type,
31
17519
                                             Integer index)
32
17519
    : d_type(new TypeNode(type)), d_index(index)
33
{
34
17519
  PrettyCheckArgument(type.isSort(),
35
                      type,
36
                      "uninterpreted constants can only be created for "
37
                      "uninterpreted sorts, not `%s'",
38
                      type.toString().c_str());
39
17519
  PrettyCheckArgument(index >= 0, index, "index >= 0 required for uninterpreted constant index, not `%s'", index.toString().c_str());
40
17519
}
41
42
19459
UninterpretedConstant::~UninterpretedConstant() {}
43
44
1940
UninterpretedConstant::UninterpretedConstant(const UninterpretedConstant& other)
45
1940
    : d_type(new TypeNode(other.getType())), d_index(other.getIndex())
46
{
47
1940
}
48
49
112583
const TypeNode& UninterpretedConstant::getType() const { return *d_type; }
50
27418
const Integer& UninterpretedConstant::getIndex() const { return d_index; }
51
41386
bool UninterpretedConstant::operator==(const UninterpretedConstant& uc) const
52
{
53
41386
  return getType() == uc.getType() && d_index == uc.d_index;
54
}
55
bool UninterpretedConstant::operator!=(const UninterpretedConstant& uc) const
56
{
57
  return !(*this == uc);
58
}
59
60
bool UninterpretedConstant::operator<(const UninterpretedConstant& uc) const
61
{
62
  return getType() < uc.getType()
63
         || (getType() == uc.getType() && d_index < uc.d_index);
64
}
65
bool UninterpretedConstant::operator<=(const UninterpretedConstant& uc) const
66
{
67
  return getType() < uc.getType()
68
         || (getType() == uc.getType() && d_index <= uc.d_index);
69
}
70
bool UninterpretedConstant::operator>(const UninterpretedConstant& uc) const
71
{
72
  return !(*this <= uc);
73
}
74
bool UninterpretedConstant::operator>=(const UninterpretedConstant& uc) const
75
{
76
  return !(*this < uc);
77
}
78
79
15
std::ostream& operator<<(std::ostream& out, const UninterpretedConstant& uc) {
80
30
  std::stringstream ss;
81
15
  ss << uc.getType();
82
30
  std::string st(ss.str());
83
  // must remove delimiting quotes from the name of the type
84
  // this prevents us from printing symbols like |@uc_|T|_n|
85
30
  std::string q("|");
86
  size_t pos;
87
15
  while ((pos = st.find(q)) != std::string::npos)
88
  {
89
    st.replace(pos, 1, "");
90
  }
91
30
  return out << "uc_" << st.c_str() << "_" << uc.getIndex();
92
}
93
94
25263
size_t UninterpretedConstantHashFunction::operator()(
95
    const UninterpretedConstant& uc) const
96
{
97
50526
  return std::hash<TypeNode>()(uc.getType())
98
50526
         * IntegerHashFunction()(uc.getIndex());
99
}
100
101
31137
}  // namespace cvc5