LCOV - code coverage report
Current view: top level - buildbot/coverage/build/src/proof - proof_node_to_sexpr.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 1 100.0 %
Date: 2026-04-03 10:41:34 Functions: 1 1 100.0 %
Branches: 0 0 -

           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                 :            :  * Conversion from ProofNode to s-expressions.
      11                 :            :  */
      12                 :            : 
      13                 :            : #include "cvc5_private.h"
      14                 :            : 
      15                 :            : #ifndef CVC5__PROOF__PROOF_NODE_TO_SEXPR_H
      16                 :            : #define CVC5__PROOF__PROOF_NODE_TO_SEXPR_H
      17                 :            : 
      18                 :            : #include <map>
      19                 :            : 
      20                 :            : #include "cvc5/cvc5_proof_rule.h"
      21                 :            : #include "expr/kind.h"
      22                 :            : #include "expr/node.h"
      23                 :            : #include "proof/method_id.h"
      24                 :            : #include "proof/trust_id.h"
      25                 :            : #include "rewriter/rewrites.h"
      26                 :            : #include "theory/inference_id.h"
      27                 :            : #include "theory/theory_id.h"
      28                 :            : 
      29                 :            : namespace cvc5::internal {
      30                 :            : 
      31                 :            : class ProofNode;
      32                 :            : 
      33                 :            : /** A class to convert ProofNode objects to s-expressions */
      34                 :            : class ProofNodeToSExpr
      35                 :            : {
      36                 :            :  public:
      37                 :            :   ProofNodeToSExpr(NodeManager* nm);
      38                 :        255 :   ~ProofNodeToSExpr() {}
      39                 :            :   /** Convert the given proof node to an s-expression
      40                 :            :    *
      41                 :            :    * This is useful for operations where it is useful to view a ProofNode as
      42                 :            :    * a Node. Printing is one such example, where a ProofNode can be printed
      43                 :            :    * as a dag after this conversion.
      44                 :            :    *
      45                 :            :    * The s-expression for a ProofNode has the form:
      46                 :            :    *   (SEXPR (VAR "<d_rule>") S1 ... Sn (VAR ":args") (SEXPR <d_args>))
      47                 :            :    * where S1, ..., Sn are the s-expressions for its <d_children>.
      48                 :            :    * 
      49                 :            :    * @param pn The proof node to print
      50                 :            :    * @param printConclusion Whether to print conclusions
      51                 :            :    */
      52                 :            :   Node convertToSExpr(const ProofNode* pn, bool printConclusion = false);
      53                 :            : 
      54                 :            :   /** argument format, determines how to print an argument */
      55                 :            :   enum class ArgFormat
      56                 :            :   {
      57                 :            :     // just use the argument itself
      58                 :            :     DEFAULT,
      59                 :            :     // print the argument as a kind
      60                 :            :     KIND,
      61                 :            :     // print the argument as a theory id
      62                 :            :     THEORY_ID,
      63                 :            :     // print the argument as a method id
      64                 :            :     METHOD_ID,
      65                 :            :     // print the arugment as a trust id
      66                 :            :     TRUST_ID,
      67                 :            :     // print the argument as an inference id
      68                 :            :     INFERENCE_ID,
      69                 :            :     // print the argument as a DSL rewrite id
      70                 :            :     DSL_REWRITE_ID,
      71                 :            :     // print a variable whose name is the term (see getOrMkNodeVariable)
      72                 :            :     NODE_VAR
      73                 :            :   };
      74                 :            :   /** get argument format for proof node */
      75                 :            :   ArgFormat getArgumentFormat(const ProofNode* pn, size_t i);
      76                 :            :   /** get argument based on the provided format */
      77                 :            :   Node getArgument(Node arg, ArgFormat f);
      78                 :            : 
      79                 :            :  private:
      80                 :            :   /** the associated node manager */
      81                 :            :   NodeManager* d_nm;
      82                 :            :   /** map proof rules to a variable */
      83                 :            :   std::map<ProofRule, Node> d_pfrMap;
      84                 :            :   /** map kind to a variable displaying the kind they represent */
      85                 :            :   std::map<Kind, Node> d_kindMap;
      86                 :            :   /** map theory ids to a variable displaying the theory id they represent */
      87                 :            :   std::map<theory::TheoryId, Node> d_tidMap;
      88                 :            :   /** map method ids to a variable displaying the method id they represent */
      89                 :            :   std::map<MethodId, Node> d_midMap;
      90                 :            :   /** map trust ids to a variable displaying the method id they represent */
      91                 :            :   std::map<TrustId, Node> d_tridMap;
      92                 :            :   /** map infer ids to a variable displaying the inference id they represent */
      93                 :            :   std::map<theory::InferenceId, Node> d_iidMap;
      94                 :            :   /** map dsl rewrite ids to a variable displaying the dsl rewrite id they
      95                 :            :    * represent */
      96                 :            :   std::map<ProofRewriteRule, Node> d_dslrMap;
      97                 :            :   /** Dummy ":args" marker */
      98                 :            :   Node d_argsMarker;
      99                 :            :   /** Dummy ":conclusion" marker */
     100                 :            :   Node d_conclusionMarker;
     101                 :            :   /** map proof nodes to their s-expression */
     102                 :            :   std::map<const ProofNode*, Node> d_pnMap;
     103                 :            :   /**
     104                 :            :    * map nodes to a bound variable, used for nodes that have special AST status
     105                 :            :    * like builtin operators
     106                 :            :    */
     107                 :            :   std::map<TNode, Node> d_nodeMap;
     108                 :            :   /** get or make pf rule variable */
     109                 :            :   Node getOrMkProofRuleVariable(ProofRule r);
     110                 :            :   /** get or make kind variable from the kind embedded in n */
     111                 :            :   Node getOrMkKindVariable(TNode n);
     112                 :            :   /** get or make theory id variable */
     113                 :            :   Node getOrMkTheoryIdVariable(TNode n);
     114                 :            :   /** get or make method id variable */
     115                 :            :   Node getOrMkMethodIdVariable(TNode n);
     116                 :            :   /** get or make trust id variable */
     117                 :            :   Node getOrMkTrustIdVariable(TNode n);
     118                 :            :   /** get or make inference id variable */
     119                 :            :   Node getOrMkInferenceIdVariable(TNode n);
     120                 :            :   /** get or make DSL rewrite id variable */
     121                 :            :   Node getOrMkDslRewriteVariable(TNode n);
     122                 :            :   /**
     123                 :            :    * Get or make node variable that prints the same as n but has SEXPR type.
     124                 :            :    * This is used to ensure the type checker does not complain when trying to
     125                 :            :    * print e.g. builtin operators as first-class terms in the SEXPR.
     126                 :            :    */
     127                 :            :   Node getOrMkNodeVariable(TNode n);
     128                 :            : };
     129                 :            : 
     130                 :            : }  // namespace cvc5::internal
     131                 :            : 
     132                 :            : #endif /* CVC5__PROOF__PROOF_NODE_TO_SEXPR_H */

Generated by: LCOV version 1.14