LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory/quantifiers - inst_match.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 43 65 66.2 %
Date: 2026-04-18 10:29:03 Functions: 8 11 72.7 %
Branches: 31 72 43.1 %

           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                 :            :  * Implementation of inst match class.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "theory/quantifiers/inst_match.h"
      14                 :            : 
      15                 :            : #include "options/quantifiers_options.h"
      16                 :            : #include "theory/quantifiers/quantifiers_state.h"
      17                 :            : #include "theory/quantifiers/term_registry.h"
      18                 :            : 
      19                 :            : namespace cvc5::internal {
      20                 :            : namespace theory {
      21                 :            : namespace quantifiers {
      22                 :            : 
      23                 :      95057 : InstMatch::InstMatch(Env& env, QuantifiersState& qs, TermRegistry& tr, TNode q)
      24                 :      95057 :     : EnvObj(env), d_qs(qs), d_tr(tr), d_quant(q), d_ieval(nullptr)
      25                 :            : {
      26                 :      95057 :   d_vals.resize(q[0].getNumChildren());
      27 [ -  + ][ -  + ]:      95057 :   Assert(!d_vals.empty());
                 [ -  - ]
      28                 :            :   // resize must initialize with null nodes
      29 [ -  + ][ -  + ]:      95057 :   Assert(d_vals[0].isNull());
                 [ -  - ]
      30                 :      95057 : }
      31                 :            : 
      32                 :     305918 : void InstMatch::setEvaluatorMode(ieval::TermEvaluatorMode tev)
      33                 :            : {
      34                 :            :   // should only do this if we are empty
      35 [ -  + ][ -  + ]:     305918 :   Assert(empty());
                 [ -  - ]
      36                 :            :   // get the instantiation evaluator and reset it
      37                 :     305918 :   d_ieval = d_tr.getEvaluator(d_quant, tev);
      38         [ +  + ]:     305918 :   if (d_ieval != nullptr)
      39                 :            :   {
      40                 :     305084 :     d_ieval->resetAll();
      41                 :            :   }
      42                 :     305918 : }
      43                 :            : 
      44                 :          0 : void InstMatch::debugPrint(CVC5_UNUSED const char* c)
      45                 :            : {
      46         [ -  - ]:          0 :   for (unsigned i = 0, size = d_vals.size(); i < size; i++)
      47                 :            :   {
      48         [ -  - ]:          0 :     if (!d_vals[i].isNull())
      49                 :            :     {
      50         [ -  - ]:          0 :       Trace(c) << "   " << i << " -> " << d_vals[i] << std::endl;
      51                 :            :     }
      52                 :            :   }
      53                 :          0 : }
      54                 :            : 
      55                 :          0 : void InstMatch::toStream(std::ostream& out) const
      56                 :            : {
      57                 :          0 :   out << "INST_MATCH( ";
      58                 :          0 :   bool printed = false;
      59         [ -  - ]:          0 :   for (size_t i = 0, size = d_vals.size(); i < size; i++)
      60                 :            :   {
      61         [ -  - ]:          0 :     if (!d_vals[i].isNull())
      62                 :            :     {
      63         [ -  - ]:          0 :       if (printed)
      64                 :            :       {
      65                 :          0 :         out << ", ";
      66                 :            :       }
      67                 :          0 :       out << i << " -> " << d_vals[i];
      68                 :          0 :       printed = true;
      69                 :            :     }
      70                 :            :   }
      71                 :          0 :   out << " )";
      72                 :          0 : }
      73                 :            : 
      74                 :          0 : bool InstMatch::isComplete() const
      75                 :            : {
      76         [ -  - ]:          0 :   for (const Node& v : d_vals)
      77                 :            :   {
      78         [ -  - ]:          0 :     if (v.isNull())
      79                 :            :     {
      80                 :          0 :       return false;
      81                 :            :     }
      82                 :            :   }
      83                 :          0 :   return true;
      84                 :            : }
      85                 :            : 
      86                 :     305918 : bool InstMatch::empty() const
      87                 :            : {
      88         [ +  + ]:    1078318 :   for (const Node& v : d_vals)
      89                 :            :   {
      90         [ -  + ]:     772400 :     if (!v.isNull())
      91                 :            :     {
      92                 :          0 :       return false;
      93                 :            :     }
      94                 :            :   }
      95                 :     305918 :   return true;
      96                 :            : }
      97                 :            : 
      98                 :     387253 : void InstMatch::resetAll()
      99                 :            : {
     100         [ +  + ]:    1392694 :   for (size_t i = 0, nvals = d_vals.size(); i < nvals; i++)
     101                 :            :   {
     102                 :    1005441 :     d_vals[i] = Node::null();
     103                 :            :   }
     104                 :            :   // clear information from the evaluator
     105         [ +  + ]:     387253 :   if (d_ieval != nullptr)
     106                 :            :   {
     107                 :     360976 :     d_ieval->resetAll();
     108                 :            :   }
     109                 :     387253 : }
     110                 :            : 
     111                 :    7426621 : Node InstMatch::get(size_t i) const
     112                 :            : {
     113 [ -  + ][ -  + ]:    7426621 :   Assert(i < d_vals.size());
                 [ -  - ]
     114                 :    7426621 :   return d_vals[i];
     115                 :            : }
     116                 :            : 
     117                 :    6607041 : bool InstMatch::set(size_t i, TNode n)
     118                 :            : {
     119 [ -  + ][ -  + ]:    6607041 :   Assert(i < d_vals.size());
                 [ -  - ]
     120         [ +  + ]:    6607041 :   if (!d_vals[i].isNull())
     121                 :            :   {
     122                 :            :     // if they are equal, we do nothing
     123                 :    1755579 :     return d_qs.areEqual(d_vals[i], n);
     124                 :            :   }
     125         [ +  + ]:    4851462 :   if (d_ieval != nullptr)
     126                 :            :   {
     127                 :            :     // if applicable, check if the instantiation evaluator is ok
     128         [ +  + ]:    4772391 :     if (!d_ieval->push(d_quant[0][i], n))
     129                 :            :     {
     130                 :    2449078 :       return false;
     131                 :            :     }
     132                 :            :     // The above checks may also have triggered a conflict due to term
     133                 :            :     // indexing, we fail in this case as well.
     134         [ +  + ]:    2323313 :     if (d_qs.isInConflict())
     135                 :            :     {
     136                 :         72 :       return false;
     137                 :            :     }
     138                 :            :   }
     139                 :            :   // otherwise, we update the value
     140                 :    2402312 :   d_vals[i] = n;
     141                 :    2402312 :   return true;
     142                 :            : }
     143                 :            : 
     144                 :    2314567 : void InstMatch::reset(size_t i)
     145                 :            : {
     146 [ -  + ][ -  + ]:    2314567 :   Assert(!d_vals[i].isNull());
                 [ -  - ]
     147         [ +  + ]:    2314567 :   if (d_ieval != nullptr)
     148                 :            :   {
     149                 :    2241461 :     d_ieval->pop();
     150                 :            :   }
     151                 :    2314567 :   d_vals[i] = Node::null();
     152                 :    2314567 : }
     153                 :            : 
     154                 :      44880 : const std::vector<Node>& InstMatch::get() const { return d_vals; }
     155                 :            : 
     156                 :            : }  // namespace quantifiers
     157                 :            : }  // namespace theory
     158                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14