GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/expr/term_context_node.cpp Lines: 4 30 13.3 %
Date: 2021-03-22 Branches: 6 140 4.3 %

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