LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/theory - theory_id.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 64 84 76.2 %
Date: 2026-09-29 09:33:19 Functions: 12 15 80.0 %
Branches: 35 47 74.5 %

           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                 :            :  * [[ Add one-line brief description here ]]
      11                 :            :  *
      12                 :            :  * [[ Add lengthier description here ]]
      13                 :            :  * \todo document this file
      14                 :            :  */
      15                 :            : 
      16                 :            : #include "theory/theory_id.h"
      17                 :            : 
      18                 :            : #include <sstream>
      19                 :            : 
      20                 :            : #include "base/check.h"
      21                 :            : #include "lib/ffs.h"
      22                 :            : 
      23                 :            : namespace cvc5::internal {
      24                 :            : namespace theory {
      25                 :            : 
      26                 :  355164479 : TheoryId& operator++(TheoryId& id)
      27                 :            : {
      28                 :  355164479 :   return id = static_cast<TheoryId>(static_cast<int>(id) + 1);
      29                 :            : }
      30                 :            : 
      31                 :     380735 : const char* toString(TheoryId theoryId)
      32                 :            : {
      33 [ +  + ][ +  + ]:     380735 :   switch (theoryId)
         [ +  + ][ +  + ]
         [ +  - ][ +  + ]
         [ +  + ][ +  + ]
      34                 :            :   {
      35                 :      27168 :     case THEORY_BUILTIN: return "THEORY_BUILTIN"; break;
      36                 :      27169 :     case THEORY_BOOL: return "THEORY_BOOL"; break;
      37                 :      27182 :     case THEORY_UF: return "THEORY_UF"; break;
      38                 :      27459 :     case THEORY_ARITH: return "THEORY_ARITH"; break;
      39                 :      27168 :     case THEORY_BV: return "THEORY_BV"; break;
      40                 :      27165 :     case THEORY_FF: return "THEORY_FF"; break;
      41                 :      27165 :     case THEORY_FP: return "THEORY_FP"; break;
      42                 :      27170 :     case THEORY_ARRAYS: return "THEORY_ARRAYS"; break;
      43                 :      27173 :     case THEORY_DATATYPES: return "THEORY_DATATYPES"; break;
      44                 :          0 :     case THEORY_SAT_SOLVER: return "THEORY_SAT_SOLVER"; break;
      45                 :      27166 :     case THEORY_SEP: return "THEORY_SEP"; break;
      46                 :      27166 :     case THEORY_SETS: return "THEORY_SETS"; break;
      47                 :      27165 :     case THEORY_BAGS: return "THEORY_BAGS"; break;
      48                 :      27220 :     case THEORY_STRINGS: return "THEORY_STRINGS"; break;
      49                 :      27168 :     case THEORY_QUANTIFIERS: return "THEORY_QUANTIFIERS"; break;
      50                 :         31 :     default: break;
      51                 :            :   }
      52                 :         31 :   return "UNKNOWN_THEORY";
      53                 :            : }
      54                 :            : 
      55                 :        407 : std::ostream& operator<<(std::ostream& out, TheoryId theoryId)
      56                 :            : {
      57                 :        407 :   out << toString(theoryId);
      58                 :        407 :   return out;
      59                 :            : }
      60                 :            : 
      61                 :    2135555 : std::string getStatsPrefix(TheoryId theoryId)
      62                 :            : {
      63 [ +  + ][ +  + ]:    2135555 :   switch (theoryId)
         [ +  + ][ +  + ]
         [ +  + ][ +  + ]
            [ +  + ][ - ]
      64                 :            :   {
      65                 :     150610 :     case THEORY_BUILTIN: return "theory::builtin::"; break;
      66                 :     150604 :     case THEORY_BOOL: return "theory::bool::"; break;
      67                 :     150604 :     case THEORY_UF: return "theory::uf::"; break;
      68                 :     150604 :     case THEORY_ARITH: return "theory::arith::"; break;
      69                 :     150604 :     case THEORY_BV: return "theory::bv::"; break;
      70                 :     177760 :     case THEORY_FF: return "theory::ff::"; break;
      71                 :     150595 :     case THEORY_FP: return "theory::fp::"; break;
      72                 :     150604 :     case THEORY_ARRAYS: return "theory::arrays::"; break;
      73                 :     150595 :     case THEORY_DATATYPES: return "theory::datatypes::"; break;
      74                 :     150595 :     case THEORY_SEP: return "theory::sep::"; break;
      75                 :     150595 :     case THEORY_SETS: return "theory::sets::"; break;
      76                 :     150595 :     case THEORY_BAGS: return "theory::bags::"; break;
      77                 :     150595 :     case THEORY_STRINGS: return "theory::strings::"; break;
      78                 :     150595 :     case THEORY_QUANTIFIERS: return "theory::quantifiers::"; break;
      79                 :            : 
      80                 :          0 :     default: break;
      81                 :            :   }
      82                 :          0 :   return "unknown::";
      83                 :            : }
      84                 :            : 
      85                 :  137975392 : TheoryId TheoryIdSetUtil::setPop(TheoryIdSet& set)
      86                 :            : {
      87                 :  137975392 :   uint32_t i = ffs(set);  // Find First Set (bit)
      88         [ +  + ]:  137975392 :   if (i == 0)
      89                 :            :   {
      90                 :   17460544 :     return THEORY_LAST;
      91                 :            :   }
      92                 :  120514848 :   TheoryId id = static_cast<TheoryId>(i - 1);
      93                 :  120514848 :   set = setRemove(id, set);
      94                 :  120514848 :   return id;
      95                 :            : }
      96                 :            : 
      97                 :          0 : size_t TheoryIdSetUtil::setSize(TheoryIdSet set)
      98                 :            : {
      99                 :          0 :   size_t count = 0;
     100         [ -  - ]:          0 :   while (setPop(set) != THEORY_LAST)
     101                 :            :   {
     102                 :          0 :     ++count;
     103                 :            :   }
     104                 :          0 :   return count;
     105                 :            : }
     106                 :            : 
     107                 :    2447891 : size_t TheoryIdSetUtil::setIndex(TheoryId id, TheoryIdSet set)
     108                 :            : {
     109 [ -  + ][ -  + ]:    2447891 :   Assert(setContains(id, set));
                 [ -  - ]
     110                 :    2447891 :   size_t count = 0;
     111         [ +  + ]:   12262807 :   while (setPop(set) != id)
     112                 :            :   {
     113                 :    9814916 :     ++count;
     114                 :            :   }
     115                 :    2447891 :   return count;
     116                 :            : }
     117                 :            : 
     118                 :  206698923 : TheoryIdSet TheoryIdSetUtil::setInsert(TheoryId theory, TheoryIdSet set)
     119                 :            : {
     120                 :  206698923 :   return set | (1 << theory);
     121                 :            : }
     122                 :            : 
     123                 :  123204640 : TheoryIdSet TheoryIdSetUtil::setRemove(TheoryId theory, TheoryIdSet set)
     124                 :            : {
     125                 :  123204640 :   return setDifference(set, setInsert(theory));
     126                 :            : }
     127                 :            : 
     128                 :  501135138 : bool TheoryIdSetUtil::setContains(TheoryId theory, TheoryIdSet set)
     129                 :            : {
     130                 :  501135138 :   return set & (1 << theory);
     131                 :            : }
     132                 :            : 
     133                 :          0 : TheoryIdSet TheoryIdSetUtil::setComplement(TheoryIdSet a)
     134                 :            : {
     135                 :          0 :   return (~a) & AllTheories;
     136                 :            : }
     137                 :            : 
     138                 :   42595988 : TheoryIdSet TheoryIdSetUtil::setIntersection(TheoryIdSet a, TheoryIdSet b)
     139                 :            : {
     140                 :   42595988 :   return a & b;
     141                 :            : }
     142                 :            : 
     143                 :   21679295 : TheoryIdSet TheoryIdSetUtil::setUnion(TheoryIdSet a, TheoryIdSet b)
     144                 :            : {
     145                 :   21679295 :   return a | b;
     146                 :            : }
     147                 :            : 
     148                 :  291180743 : TheoryIdSet TheoryIdSetUtil::setDifference(TheoryIdSet a, TheoryIdSet b)
     149                 :            : {
     150                 :  291180743 :   return (~b) & a;
     151                 :            : }
     152                 :            : 
     153                 :          0 : std::string TheoryIdSetUtil::setToString(TheoryIdSet theorySet)
     154                 :            : {
     155                 :          0 :   std::stringstream ss;
     156                 :          0 :   ss << "[";
     157         [ -  - ]:          0 :   for (unsigned theoryId = 0; theoryId < THEORY_LAST; ++theoryId)
     158                 :            :   {
     159                 :          0 :     TheoryId tid = static_cast<TheoryId>(theoryId);
     160         [ -  - ]:          0 :     if (setContains(tid, theorySet))
     161                 :            :     {
     162                 :          0 :       ss << tid << " ";
     163                 :            :     }
     164                 :            :   }
     165                 :          0 :   ss << "]";
     166                 :          0 :   return ss.str();
     167                 :          0 : }
     168                 :            : 
     169                 :            : }  // namespace theory
     170                 :            : }  // namespace cvc5::internal

Generated by: LCOV version 1.14