LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/decision - justify_stack.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 37 40 92.5 %
Date: 2026-02-27 11:41:18 Functions: 11 11 100.0 %
Branches: 11 30 36.7 %

           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                 :            :  * Justification stack.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "decision/justify_stack.h"
      14                 :            : 
      15                 :            : namespace cvc5::internal {
      16                 :            : namespace decision {
      17                 :            : 
      18                 :      40326 : JustifyStack::JustifyStack(context::Context* c)
      19                 :      40326 :     : d_context(c), d_current(c), d_stack(c), d_stackSizeValid(c, 0)
      20                 :            : {
      21                 :      40326 : }
      22                 :      40134 : JustifyStack::~JustifyStack() {}
      23                 :            : 
      24                 :   27879669 : void JustifyStack::reset(TNode curr)
      25                 :            : {
      26                 :   27879669 :   d_current = curr;
      27                 :   27879669 :   d_stackSizeValid = 0;
      28                 :   27879669 :   pushToStack(curr, prop::SAT_VALUE_TRUE);
      29                 :   27879669 : }
      30                 :   27968410 : void JustifyStack::clear()
      31                 :            : {
      32                 :   27968410 :   d_current = TNode::null();
      33                 :   27968410 :   d_stackSizeValid = 0;
      34                 :   27968410 : }
      35                 :            : 
      36                 :    3983669 : size_t JustifyStack::size() const { return d_stackSizeValid.get(); }
      37                 :            : 
      38                 :   57210142 : TNode JustifyStack::getCurrentAssertion() const { return d_current.get(); }
      39                 :   43155043 : bool JustifyStack::hasCurrentAssertion() const
      40                 :            : {
      41                 :   43155043 :   return !d_current.get().isNull();
      42                 :            : }
      43                 :  117576195 : JustifyInfo* JustifyStack::getCurrent()
      44                 :            : {
      45         [ +  + ]:  117576195 :   if (d_stackSizeValid.get() == 0)
      46                 :            :   {
      47                 :   27644868 :     return nullptr;
      48                 :            :   }
      49 [ -  + ][ -  + ]:   89931327 :   Assert(d_stack.size() >= d_stackSizeValid.get());
                 [ -  - ]
      50                 :   89931327 :   return d_stack[d_stackSizeValid.get() - 1].get();
      51                 :            : }
      52                 :            : 
      53                 :   31863338 : void JustifyStack::pushToStack(TNode n, prop::SatValue desiredVal)
      54                 :            : {
      55         [ -  + ]:   31863338 :   if (TraceIsOn("jh-stack"))
      56                 :            :   {
      57         [ -  - ]:          0 :     for (size_t i = 0, ssize = d_stackSizeValid.get(); i < ssize; i++)
      58                 :            :     {
      59         [ -  - ]:          0 :       Trace("jh-stack") << " ";
      60                 :            :     }
      61         [ -  - ]:          0 :     Trace("jh-stack") << "- " << n << " " << desiredVal << std::endl;
      62                 :            :   }
      63                 :            :   // note that n is possibly negated here
      64                 :   31863338 :   JustifyInfo* ji = getOrAllocJustifyInfo(d_stackSizeValid.get());
      65                 :   31863338 :   ji->set(n, desiredVal);
      66                 :   31863338 :   d_stackSizeValid = d_stackSizeValid + 1;
      67                 :   31863338 : }
      68                 :            : 
      69                 :   31478997 : void JustifyStack::popStack()
      70                 :            : {
      71 [ -  + ][ -  + ]:   31478997 :   Assert(d_stackSizeValid.get() > 0);
                 [ -  - ]
      72                 :   31478997 :   d_stackSizeValid = d_stackSizeValid - 1;
      73                 :   31478997 : }
      74                 :            : 
      75                 :   31863338 : JustifyInfo* JustifyStack::getOrAllocJustifyInfo(size_t i)
      76                 :            : {
      77                 :            :   // don't request stack beyond the bound
      78 [ -  + ][ -  + ]:   31863338 :   Assert(i <= d_stack.size());
                 [ -  - ]
      79         [ +  + ]:   31863338 :   if (i == d_stack.size())
      80                 :            :   {
      81                 :     190961 :     d_stack.push_back(std::make_shared<JustifyInfo>(d_context));
      82                 :            :   }
      83                 :   31863338 :   return d_stack[i].get();
      84                 :            : }
      85                 :            : 
      86                 :            : }
      87                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14