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 : : * Alethe node conversion 11 : : */ 12 : : 13 : : #include "cvc5_private.h" 14 : : 15 : : #ifndef CVC5__PROOF__ALETHE__ALETHE_NODE_CONVERTER_H 16 : : #define CVC5__PROOF__ALETHE__ALETHE_NODE_CONVERTER_H 17 : : 18 : : #include "expr/node.h" 19 : : #include "expr/node_converter.h" 20 : : #include "proof/eo/eo_node_converter.h" 21 : : 22 : : namespace cvc5::internal { 23 : : namespace proof { 24 : : 25 : : /** 26 : : * This is a helper class for the Alethe post-processor that converts nodes into 27 : : * their expected form in Alethe. 28 : : */ 29 : : class AletheNodeConverter : public BaseEoNodeConverter 30 : : { 31 : : public: 32 : : /** Constructor 33 : : * 34 : : * @param nm The node manager 35 : : * @param defineSkolems Whether Skolem definitions will be saved to be printed 36 : : * separately. 37 : : * @param isTesting Whether the converter is running in Alethe testing mode 38 : : * (excludes BV, datatypes, and strings kinds/types). 39 : : */ 40 : 1735 : AletheNodeConverter(NodeManager* nm, 41 : : bool defineSkolems = false, 42 : : bool isTesting = false) 43 : 1735 : : BaseEoNodeConverter(nm), 44 : 1735 : d_defineSkolems(defineSkolems), 45 : 1735 : d_isTesting(isTesting) 46 : : { 47 : 1735 : } 48 : 1735 : ~AletheNodeConverter() {} 49 : : 50 : : /** convert at post-order traversal */ 51 : : Node postConvert(Node n) override; 52 : : 53 : : /** A wrapper for convert that checks whether there was an error during 54 : : * conversion. 55 : : * 56 : : * @param n The node to be converted 57 : : * @param isAssumption Whether the n is an assumption 58 : : * @return The converted node if there was no error, otherwise Node::null(). 59 : : */ 60 : : Node maybeConvert(Node n, bool isAssumption = false); 61 : : 62 : : /** Retrieve the saved error message, if any. */ 63 : : const std::string& getError(); 64 : : 65 : : /** Return original assumption, if any, for a given (converted) node. */ 66 : : Node getOriginalAssumption(Node n); 67 : : 68 : : /** Retrieve a mapping between Skolems and their converted definitions. 69 : : */ 70 : : const std::map<Node, Node>& getSkolemDefinitions(); 71 : : 72 : : /** Retrieve ordered list of Skolems. This list is ordered so that a Skolem 73 : : * whose definition depends on another Skolem will come after that Skolem. 74 : : */ 75 : : const std::vector<Node>& getSkolemList(); 76 : : 77 : : Node mkInternalSymbol(const std::string& name, 78 : : TypeNode tn, 79 : : bool useRawSym = true) override; 80 : : 81 : 0 : Node getOperatorOfTerm(CVC5_UNUSED Node n) override { return Node::null(); }; 82 : : 83 : 0 : Node typeAsNode(CVC5_UNUSED TypeNode tni) override { return Node::null(); }; 84 : : 85 : 0 : Node mkInternalApp(CVC5_UNUSED const std::string& name, 86 : : CVC5_UNUSED const std::vector<Node>& args, 87 : : CVC5_UNUSED TypeNode ret, 88 : : CVC5_UNUSED bool useRawSym = true) override 89 : : { 90 : 0 : return Node::null(); 91 : : }; 92 : : 93 : : private: 94 : : /** Error message saved during failed conversion. */ 95 : : std::string d_error; 96 : : /** Whether Skolem definitions will be saved to be printed separately. */ 97 : : bool d_defineSkolems; 98 : : /** Whether the converter is running in Alethe testing mode. When true, BV, 99 : : * datatypes, and strings kinds/types are reported as unsupported. */ 100 : : bool d_isTesting; 101 : : 102 : : /** Set d_error to indicate that kind k is unsupported and return a null 103 : : * node. */ 104 : : Node recordUnsupportedKind(Kind k); 105 : : 106 : : /** 107 : : * As above but uses the s-expression type. 108 : : */ 109 : : Node mkInternalSymbol(const std::string& name); 110 : : 111 : : /** Maps from internally generated symbols to the built nodes. */ 112 : : std::map<std::pair<TypeNode, std::string>, Node> d_symbolsMap; 113 : : 114 : : /** Map from converted node to original (used only for assumptions). */ 115 : : std::map<Node, Node> d_convToOriginalAssumption; 116 : : 117 : : /** Map between Skolems and their converted definitions. */ 118 : : std::map<Node, Node> d_skolems; 119 : : /** Ordered Skolems such that a given entry does not have subterms occurring 120 : : * in subsequent entries. */ 121 : : std::vector<Node> d_skolemsList; 122 : : }; 123 : : 124 : : } // namespace proof 125 : : } // namespace cvc5::internal 126 : : 127 : : #endif