GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/uninterpreted_constant.cpp Lines: 24 37 64.9 %
Date: 2021-09-10 Branches: 29 74 39.2 %

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
18779
UninterpretedConstant::UninterpretedConstant(const TypeNode& type,
31
18779
                                             Integer index)
32
18779
    : 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
18779
  PrettyCheckArgument(index >= 0, index, "index >= 0 required for uninterpreted constant index, not `%s'", index.toString().c_str());
36
18779
}
37
38
20840
UninterpretedConstant::~UninterpretedConstant() {}
39
40
2061
UninterpretedConstant::UninterpretedConstant(const UninterpretedConstant& other)
41
2061
    : d_type(new TypeNode(other.getType())), d_index(other.getIndex())
42
{
43
2061
}
44
45
116921
const TypeNode& UninterpretedConstant::getType() const { return *d_type; }
46
29775
const Integer& UninterpretedConstant::getIndex() const { return d_index; }
47
42551
bool UninterpretedConstant::operator==(const UninterpretedConstant& uc) const
48
{
49
42551
  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
27023
size_t UninterpretedConstantHashFunction::operator()(
91
    const UninterpretedConstant& uc) const
92
{
93
54046
  return std::hash<TypeNode>()(uc.getType())
94
54046
         * IntegerHashFunction()(uc.getIndex());
95
}
96
97
29502
}  // namespace cvc5