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-16 11:40:47 Functions: 11 11 100.0 %
Branches: 11 30 36.7 %

           Branch data     Line data    Source code
       1                 :            : /******************************************************************************
       2                 :            :  * Top contributors (to current version):
       3                 :            :  *   Andrew Reynolds, Gereon Kremer
       4                 :            :  *
       5                 :            :  * This file is part of the cvc5 project.
       6                 :            :  *
       7                 :            :  * Copyright (c) 2009-2025 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                 :            :  * ****************************************************************************
      12                 :            :  *
      13                 :            :  * Justification stack.
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "decision/justify_stack.h"
      17                 :            : 
      18                 :            : namespace cvc5::internal {
      19                 :            : namespace decision {
      20                 :            : 
      21                 :      40291 : JustifyStack::JustifyStack(context::Context* c)
      22                 :      40291 :     : d_context(c), d_current(c), d_stack(c), d_stackSizeValid(c, 0)
      23                 :            : {
      24                 :      40291 : }
      25                 :      40099 : JustifyStack::~JustifyStack() {}
      26                 :            : 
      27                 :   27296800 : void JustifyStack::reset(TNode curr)
      28                 :            : {
      29                 :   27296800 :   d_current = curr;
      30                 :   27296800 :   d_stackSizeValid = 0;
      31                 :   27296800 :   pushToStack(curr, prop::SAT_VALUE_TRUE);
      32                 :   27296800 : }
      33                 :   27384500 : void JustifyStack::clear()
      34                 :            : {
      35                 :   27384500 :   d_current = TNode::null();
      36                 :   27384500 :   d_stackSizeValid = 0;
      37                 :   27384500 : }
      38                 :            : 
      39                 :    3893980 : size_t JustifyStack::size() const { return d_stackSizeValid.get(); }
      40                 :            : 
      41                 :   56020900 : TNode JustifyStack::getCurrentAssertion() const { return d_current.get(); }
      42                 :   42421000 : bool JustifyStack::hasCurrentAssertion() const
      43                 :            : {
      44                 :   42421000 :   return !d_current.get().isNull();
      45                 :            : }
      46                 :  115481000 : JustifyInfo* JustifyStack::getCurrent()
      47                 :            : {
      48         [ +  + ]:  115481000 :   if (d_stackSizeValid.get() == 0)
      49                 :            :   {
      50                 :   27104300 :     return nullptr;
      51                 :            :   }
      52 [ -  + ][ -  + ]:   88376400 :   Assert(d_stack.size() >= d_stackSizeValid.get());
                 [ -  - ]
      53                 :   88376400 :   return d_stack[d_stackSizeValid.get() - 1].get();
      54                 :            : }
      55                 :            : 
      56                 :   31190700 : void JustifyStack::pushToStack(TNode n, prop::SatValue desiredVal)
      57                 :            : {
      58         [ -  + ]:   31190700 :   if (TraceIsOn("jh-stack"))
      59                 :            :   {
      60         [ -  - ]:          0 :     for (size_t i = 0, ssize = d_stackSizeValid.get(); i < ssize; i++)
      61                 :            :     {
      62         [ -  - ]:          0 :       Trace("jh-stack") << " ";
      63                 :            :     }
      64         [ -  - ]:          0 :     Trace("jh-stack") << "- " << n << " " << desiredVal << std::endl;
      65                 :            :   }
      66                 :            :   // note that n is possibly negated here
      67                 :   31190700 :   JustifyInfo* ji = getOrAllocJustifyInfo(d_stackSizeValid.get());
      68                 :   31190700 :   ji->set(n, desiredVal);
      69                 :   31190700 :   d_stackSizeValid = d_stackSizeValid + 1;
      70                 :   31190700 : }
      71                 :            : 
      72                 :   30848900 : void JustifyStack::popStack()
      73                 :            : {
      74 [ -  + ][ -  + ]:   30848900 :   Assert(d_stackSizeValid.get() > 0);
                 [ -  - ]
      75                 :   30848900 :   d_stackSizeValid = d_stackSizeValid - 1;
      76                 :   30848900 : }
      77                 :            : 
      78                 :   31190700 : JustifyInfo* JustifyStack::getOrAllocJustifyInfo(size_t i)
      79                 :            : {
      80                 :            :   // don't request stack beyond the bound
      81 [ -  + ][ -  + ]:   31190700 :   Assert(i <= d_stack.size());
                 [ -  - ]
      82         [ +  + ]:   31190700 :   if (i == d_stack.size())
      83                 :            :   {
      84                 :     190002 :     d_stack.push_back(std::make_shared<JustifyInfo>(d_context));
      85                 :            :   }
      86                 :   31190700 :   return d_stack[i].get();
      87                 :            : }
      88                 :            : 
      89                 :            : }
      90                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14