GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/uninterpreted_constant.cpp Lines: 24 37 64.9 %
Date: 2021-03-22 Branches: 30 78 38.5 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file uninterpreted_constant.cpp
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Andres Noetzli, Andrew Reynolds, Tim King
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 constants of uninterpreted sorts
13
 **
14
 ** Representation of constants of uninterpreted sorts.
15
 **/
16
17
#include "expr/uninterpreted_constant.h"
18
19
#include <algorithm>
20
#include <iostream>
21
#include <sstream>
22
#include <string>
23
24
#include "base/check.h"
25
#include "expr/type_node.h"
26
27
using namespace std;
28
29
namespace CVC4 {
30
31
21386
UninterpretedConstant::UninterpretedConstant(const TypeNode& type,
32
21386
                                             Integer index)
33
21386
    : d_type(new TypeNode(type)), d_index(index)
34
{
35
  //PrettyCheckArgument(type.isSort(), type, "uninterpreted constants can only be created for uninterpreted sorts, not `%s'", type.toString().c_str());
36
21386
  PrettyCheckArgument(index >= 0, index, "index >= 0 required for uninterpreted constant index, not `%s'", index.toString().c_str());
37
21386
}
38
39
23345
UninterpretedConstant::~UninterpretedConstant() {}
40
41
1959
UninterpretedConstant::UninterpretedConstant(const UninterpretedConstant& other)
42
1959
    : d_type(new TypeNode(other.getType())), d_index(other.getIndex())
43
{
44
1959
}
45
46
137323
const TypeNode& UninterpretedConstant::getType() const { return *d_type; }
47
31980
const Integer& UninterpretedConstant::getIndex() const { return d_index; }
48
51791
bool UninterpretedConstant::operator==(const UninterpretedConstant& uc) const
49
{
50
51791
  return getType() == uc.getType() && d_index == uc.d_index;
51
}
52
bool UninterpretedConstant::operator!=(const UninterpretedConstant& uc) const
53
{
54
  return !(*this == uc);
55
}
56
57
bool UninterpretedConstant::operator<(const UninterpretedConstant& uc) const
58
{
59
  return getType() < uc.getType()
60
         || (getType() == uc.getType() && d_index < uc.d_index);
61
}
62
bool UninterpretedConstant::operator<=(const UninterpretedConstant& uc) const
63
{
64
  return getType() < uc.getType()
65
         || (getType() == uc.getType() && d_index <= uc.d_index);
66
}
67
bool UninterpretedConstant::operator>(const UninterpretedConstant& uc) const
68
{
69
  return !(*this <= uc);
70
}
71
bool UninterpretedConstant::operator>=(const UninterpretedConstant& uc) const
72
{
73
  return !(*this < uc);
74
}
75
76
1
std::ostream& operator<<(std::ostream& out, const UninterpretedConstant& uc) {
77
2
  std::stringstream ss;
78
1
  ss << uc.getType();
79
2
  std::string st(ss.str());
80
  // must remove delimiting quotes from the name of the type
81
  // this prevents us from printing symbols like |@uc_|T|_n|
82
2
  std::string q("|");
83
  size_t pos;
84
1
  while ((pos = st.find(q)) != std::string::npos)
85
  {
86
    st.replace(pos, 1, "");
87
  }
88
2
  return out << "uc_" << st.c_str() << "_" << uc.getIndex();
89
}
90
91
29222
size_t UninterpretedConstantHashFunction::operator()(
92
    const UninterpretedConstant& uc) const
93
{
94
58444
  return TypeNodeHashFunction()(uc.getType())
95
58444
         * IntegerHashFunction()(uc.getIndex());
96
}
97
98
26676
}/* CVC4 namespace */