1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Andrew Reynolds, Haniel Barbosa, Gereon Kremer |
4 |
|
* |
5 |
|
* This file is part of the cvc5 project. |
6 |
|
* |
7 |
|
* Copyright (c) 2009-2021 by the authors listed in the file AUTHORS |
8 |
|
* in the top-level source directory and their institutional affiliations. |
9 |
|
* All rights reserved. See the file COPYING in the top-level source |
10 |
|
* directory for licensing information. |
11 |
|
* **************************************************************************** |
12 |
|
* |
13 |
|
* Conversion from ProofNode to s-expressions. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "cvc5_private.h" |
17 |
|
|
18 |
|
#ifndef CVC5__PROOF__PROOF_NODE_TO_SEXPR_H |
19 |
|
#define CVC5__PROOF__PROOF_NODE_TO_SEXPR_H |
20 |
|
|
21 |
|
#include <map> |
22 |
|
|
23 |
|
#include "expr/kind.h" |
24 |
|
#include "expr/node.h" |
25 |
|
#include "proof/method_id.h" |
26 |
|
#include "proof/proof_rule.h" |
27 |
|
#include "theory/inference_id.h" |
28 |
|
#include "theory/theory_id.h" |
29 |
|
|
30 |
|
namespace cvc5 { |
31 |
|
|
32 |
|
class ProofNode; |
33 |
|
|
34 |
|
/** A class to convert ProofNode objects to s-expressions */ |
35 |
|
class ProofNodeToSExpr |
36 |
|
{ |
37 |
|
public: |
38 |
|
ProofNodeToSExpr(); |
39 |
42422 |
~ProofNodeToSExpr() {} |
40 |
|
/** Convert the given proof node to an s-expression |
41 |
|
* |
42 |
|
* This is useful for operations where it is useful to view a ProofNode as |
43 |
|
* a Node. Printing is one such example, where a ProofNode can be printed |
44 |
|
* as a dag after this conversion. |
45 |
|
* |
46 |
|
* The s-expression for a ProofNode has the form: |
47 |
|
* (SEXPR (VAR "<d_rule>") S1 ... Sn (VAR ":args") (SEXPR <d_args>)) |
48 |
|
* where S1, ..., Sn are the s-expressions for its <d_children>. |
49 |
|
*/ |
50 |
|
Node convertToSExpr(const ProofNode* pn); |
51 |
|
|
52 |
|
private: |
53 |
|
/** argument format, determines how to print an argument */ |
54 |
|
enum class ArgFormat |
55 |
|
{ |
56 |
|
// just use the argument itself |
57 |
|
DEFAULT, |
58 |
|
// print the argument as a kind |
59 |
|
KIND, |
60 |
|
// print the argument as a theory id |
61 |
|
THEORY_ID, |
62 |
|
// print the argument as a method id |
63 |
|
METHOD_ID, |
64 |
|
// print the argument as an inference id |
65 |
|
INFERENCE_ID, |
66 |
|
// print a variable whose name is the term (see getOrMkNodeVariable) |
67 |
|
NODE_VAR |
68 |
|
}; |
69 |
|
/** map proof rules to a variable */ |
70 |
|
std::map<PfRule, Node> d_pfrMap; |
71 |
|
/** map kind to a variable displaying the kind they represent */ |
72 |
|
std::map<Kind, Node> d_kindMap; |
73 |
|
/** map theory ids to a variable displaying the theory id they represent */ |
74 |
|
std::map<theory::TheoryId, Node> d_tidMap; |
75 |
|
/** map method ids to a variable displaying the method id they represent */ |
76 |
|
std::map<MethodId, Node> d_midMap; |
77 |
|
/** map infer ids to a variable displaying the method id they represent */ |
78 |
|
std::map<theory::InferenceId, Node> d_iidMap; |
79 |
|
/** Dummy ":args" marker */ |
80 |
|
Node d_argsMarker; |
81 |
|
/** Dummy ":conclusion" marker */ |
82 |
|
Node d_conclusionMarker; |
83 |
|
/** map proof nodes to their s-expression */ |
84 |
|
std::map<const ProofNode*, Node> d_pnMap; |
85 |
|
/** |
86 |
|
* map nodes to a bound variable, used for nodes that have special AST status |
87 |
|
* like builtin operators |
88 |
|
*/ |
89 |
|
std::map<TNode, Node> d_nodeMap; |
90 |
|
/** get or make pf rule variable */ |
91 |
|
Node getOrMkPfRuleVariable(PfRule r); |
92 |
|
/** get or make kind variable from the kind embedded in n */ |
93 |
|
Node getOrMkKindVariable(TNode n); |
94 |
|
/** get or make theory id variable */ |
95 |
|
Node getOrMkTheoryIdVariable(TNode n); |
96 |
|
/** get or make method id variable */ |
97 |
|
Node getOrMkMethodIdVariable(TNode n); |
98 |
|
/** get or make inference id variable */ |
99 |
|
Node getOrMkInferenceIdVariable(TNode n); |
100 |
|
/** |
101 |
|
* Get or make node variable that prints the same as n but has SEXPR type. |
102 |
|
* This is used to ensure the type checker does not complain when trying to |
103 |
|
* print e.g. builtin operators as first-class terms in the SEXPR. |
104 |
|
*/ |
105 |
|
Node getOrMkNodeVariable(TNode n); |
106 |
|
/** get argument based on the provided format */ |
107 |
|
Node getArgument(Node arg, ArgFormat f); |
108 |
|
/** get argument format for proof node */ |
109 |
|
ArgFormat getArgumentFormat(const ProofNode* pn, size_t i); |
110 |
|
}; |
111 |
|
|
112 |
|
} // namespace cvc5 |
113 |
|
|
114 |
|
#endif /* CVC5__PROOF__PROOF_RULE_H */ |