LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/expr - term_context_node.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 3 28 10.7 %
Date: 2026-03-09 11:40:42 Functions: 1 10 10.0 %
Branches: 0 0 -

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

Generated by: LCOV version 1.14