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 method identifier 11 : : */ 12 : : 13 : : #include "proof/method_id.h" 14 : : 15 : : #include "proof/proof_checker.h" 16 : : #include "util/rational.h" 17 : : 18 : : using namespace cvc5::internal::kind; 19 : : 20 : : namespace cvc5::internal { 21 : : 22 : 0 : const char* toString(MethodId id) 23 : : { 24 [ - - ][ - - ]: 0 : switch (id) [ - - ][ - - ] [ - - ][ - - ] [ - - ][ - ] 25 : : { 26 : 0 : case MethodId::RW_REWRITE: return "RW_REWRITE"; 27 : 0 : case MethodId::RW_EXT_REWRITE: return "RW_EXT_REWRITE"; 28 : 0 : case MethodId::RW_EXT_REWRITE_AGG: return "RW_EXT_REWRITE_AGG"; 29 : 0 : case MethodId::RW_REWRITE_EQ_EXT: return "RW_REWRITE_EQ_EXT"; 30 : 0 : case MethodId::RW_EVALUATE: return "RW_EVALUATE"; 31 : 0 : case MethodId::RW_IDENTITY: return "RW_IDENTITY"; 32 : 0 : case MethodId::RW_REWRITE_THEORY_PRE: return "RW_REWRITE_THEORY_PRE"; 33 : 0 : case MethodId::RW_REWRITE_THEORY_POST: return "RW_REWRITE_THEORY_POST"; 34 : 0 : case MethodId::SB_DEFAULT: return "SB_DEFAULT"; 35 : 0 : case MethodId::SB_LITERAL: return "SB_LITERAL"; 36 : 0 : case MethodId::SB_FORMULA: return "SB_FORMULA"; 37 : 0 : case MethodId::SBA_SEQUENTIAL: return "SBA_SEQUENTIAL"; 38 : 0 : case MethodId::SBA_SIMUL: return "SBA_SIMUL"; 39 : 0 : case MethodId::SBA_FIXPOINT: return "SBA_FIXPOINT"; 40 : 0 : default: return "MethodId::Unknown"; 41 : : }; 42 : : } 43 : : 44 : 0 : std::ostream& operator<<(std::ostream& out, MethodId id) 45 : : { 46 : 0 : out << toString(id); 47 : 0 : return out; 48 : : } 49 : : 50 : 1176913 : Node mkMethodId(NodeManager* nm, MethodId id) 51 : : { 52 : 2353826 : return nm->mkConstInt(Rational(static_cast<uint32_t>(id))); 53 : : } 54 : : 55 : 476145 : bool getMethodId(TNode n, MethodId& i) 56 : : { 57 : : uint32_t index; 58 [ - + ]: 476145 : if (!ProofRuleChecker::getUInt32(n, index)) 59 : : { 60 : 0 : return false; 61 : : } 62 : 476145 : i = static_cast<MethodId>(index); 63 : 476145 : return true; 64 : : } 65 : : 66 : 156283 : bool getMethodIds(const std::vector<Node>& args, 67 : : MethodId& ids, 68 : : MethodId& ida, 69 : : MethodId& idr, 70 : : size_t index) 71 : : { 72 : 156283 : ids = MethodId::SB_DEFAULT; 73 : 156283 : ida = MethodId::SBA_SEQUENTIAL; 74 : 156283 : idr = MethodId::RW_REWRITE; 75 [ + + ]: 239527 : for (size_t offset = 0; offset <= 2; offset++) 76 : : { 77 [ + + ]: 235808 : if (args.size() > index + offset) 78 : : { 79 [ + + ][ + + ]: 83244 : MethodId& id = offset == 0 ? ids : (offset == 1 ? ida : idr); 80 [ - + ]: 83244 : if (!getMethodId(args[index + offset], id)) 81 : : { 82 [ - - ]: 0 : Trace("builtin-pfcheck") 83 : 0 : << "Failed to get id from " << args[index + offset] << std::endl; 84 : 0 : return false; 85 : : } 86 : : } 87 : : else 88 : : { 89 : 152564 : break; 90 : : } 91 : : } 92 [ + - ]: 312566 : Trace("builtin-pfcheck") << "Got MethodIds ids/ida/idr: " << ids << " / " 93 : 156283 : << ida << " / " << idr << "\n"; 94 : 156283 : return true; 95 : : } 96 : : 97 : 143062 : void addMethodIds(NodeManager* nm, 98 : : std::vector<Node>& args, 99 : : MethodId ids, 100 : : MethodId ida, 101 : : MethodId idr) 102 : : { 103 : 143062 : bool ndefRewriter = (idr != MethodId::RW_REWRITE); 104 : 143062 : bool ndefApply = (ida != MethodId::SBA_SEQUENTIAL); 105 [ + + ][ + + ]: 143062 : if (ids != MethodId::SB_DEFAULT || ndefRewriter || ndefApply) [ + + ] 106 : : { 107 : 71377 : args.push_back(mkMethodId(nm, ids)); 108 : : } 109 [ + + ][ + + ]: 143062 : if (ndefApply || ndefRewriter) 110 : : { 111 : 71196 : args.push_back(mkMethodId(nm, ida)); 112 : : } 113 [ + + ]: 143062 : if (ndefRewriter) 114 : : { 115 : 23030 : args.push_back(mkMethodId(nm, idr)); 116 : : } 117 : 143062 : } 118 : : 119 : : } // namespace cvc5::internal