1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
/********************* */
/*! \file term_context_node.cpp
** \verbatim
** Top contributors (to current version):
** Andrew Reynolds
** This file is part of the CVC4 project.
** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
** in the top-level source directory) and their institutional affiliations.
** All rights reserved. See the file COPYING in the top-level source
** directory for licensing information.\endverbatim
**
** \brief Term context node utility.
**/
#include "expr/term_context_node.h"
#include "expr/term_context.h"
namespace CVC4 {
TCtxNode::TCtxNode(Node n, const TermContext* tctx)
: d_node(n), d_val(tctx->initialValue()), d_tctx(tctx)
{
}
TCtxNode::TCtxNode(Node n, uint32_t val, const TermContext* tctx)
: d_node(n), d_val(val), d_tctx(tctx)
{
}
size_t TCtxNode::getNumChildren() const { return d_node.getNumChildren(); }
TCtxNode TCtxNode::getChild(size_t i) const
{
Assert(i < d_node.getNumChildren());
// we are still computing the same term context, with the given child, where
// the hash has been updated based on the kind, node, current value and child
// index.
return TCtxNode(d_node[i], d_tctx->computeValue(d_node, d_val, i), d_tctx);
}
Node TCtxNode::getNode() const { return d_node; }
uint32_t TCtxNode::getContextId() const { return d_val; }
const TermContext* TCtxNode::getTermContext() const { return d_tctx; }
Node TCtxNode::getNodeHash() const { return computeNodeHash(d_node, d_val); }
Node TCtxNode::computeNodeHash(Node n, uint32_t val)
{
NodeManager* nm = NodeManager::currentNM();
return nm->mkNode(kind::SEXPR, n, nm->mkConst(Rational(val)));
}
Node TCtxNode::decomposeNodeHash(Node h, uint32_t& val)
{
if (h.getKind() != kind::SEXPR || h.getNumChildren() != 2)
{
Assert(false) << "TermContext::decomposeNodeHash: unexpected node " << h;
return Node::null();
}
Node ival = h[1];
if (!ival.isConst() || !ival.getType().isInteger()
|| !ival.getConst<Rational>().getNumerator().fitsUnsignedInt())
{
Assert(false) << "TermContext::decomposeNodeHash: unexpected term context "
"integer in hash "
<< h;
return Node::null();
}
val = ival.getConst<Rational>().getNumerator().toUnsignedInt();
return h[0];
}
} // namespace CVC4
|