1 /******************************************************************************
2 * Top contributors (to current version):
5 * This file is part of the cvc5 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.
11 * ****************************************************************************
13 * Representation of bound variables in codatatype values
16 #include "expr/codatatype_bound_variable.h"
23 #include "base/check.h"
24 #include "expr/type_node.h"
30 CodatatypeBoundVariable::CodatatypeBoundVariable(const TypeNode
& type
,
32 : d_type(new TypeNode(type
)), d_index(index
)
34 PrettyCheckArgument(type
.isCodatatype(),
36 "codatatype bound variables can only be created for "
37 "codatatype sorts, not `%s'",
38 type
.toString().c_str());
42 "index >= 0 required for codatatype bound variable index, not `%s'",
43 index
.toString().c_str());
46 CodatatypeBoundVariable::~CodatatypeBoundVariable() {}
48 CodatatypeBoundVariable::CodatatypeBoundVariable(
49 const CodatatypeBoundVariable
& other
)
50 : d_type(new TypeNode(other
.getType())), d_index(other
.getIndex())
54 const TypeNode
& CodatatypeBoundVariable::getType() const { return *d_type
; }
55 const Integer
& CodatatypeBoundVariable::getIndex() const { return d_index
; }
56 bool CodatatypeBoundVariable::operator==(
57 const CodatatypeBoundVariable
& cbv
) const
59 return getType() == cbv
.getType() && d_index
== cbv
.d_index
;
61 bool CodatatypeBoundVariable::operator!=(
62 const CodatatypeBoundVariable
& cbv
) const
64 return !(*this == cbv
);
67 bool CodatatypeBoundVariable::operator<(
68 const CodatatypeBoundVariable
& cbv
) const
70 return getType() < cbv
.getType()
71 || (getType() == cbv
.getType() && d_index
< cbv
.d_index
);
73 bool CodatatypeBoundVariable::operator<=(
74 const CodatatypeBoundVariable
& cbv
) const
76 return getType() < cbv
.getType()
77 || (getType() == cbv
.getType() && d_index
<= cbv
.d_index
);
79 bool CodatatypeBoundVariable::operator>(
80 const CodatatypeBoundVariable
& cbv
) const
82 return !(*this <= cbv
);
84 bool CodatatypeBoundVariable::operator>=(
85 const CodatatypeBoundVariable
& cbv
) const
87 return !(*this < cbv
);
90 std::ostream
& operator<<(std::ostream
& out
, const CodatatypeBoundVariable
& cbv
)
94 std::string
st(ss
.str());
95 // must remove delimiting quotes from the name of the type
96 // this prevents us from printing symbols like |@cbv_|T|_n|
99 while ((pos
= st
.find(q
)) != std::string::npos
)
101 st
.replace(pos
, 1, "");
103 return out
<< "cbv_" << st
.c_str() << "_" << cbv
.getIndex();
106 size_t CodatatypeBoundVariableHashFunction::operator()(
107 const CodatatypeBoundVariable
& cbv
) const
109 return std::hash
<TypeNode
>()(cbv
.getType())
110 * IntegerHashFunction()(cbv
.getIndex());