summaryrefslogtreecommitdiff
path: root/src/proof/lfsc/lfsc_print_channel.h
blob: 655fa192cd163ede82a27821d0e2dbeccdb0fe08 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/******************************************************************************
 * Top contributors (to current version):
 *   Andrew Reynolds
 *
 * This file is part of the cvc5 project.
 *
 * Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
 * in the top-level source directory and their institutional affiliations.
 * All rights reserved.  See the file COPYING in the top-level source
 * directory for licensing information.
 * ****************************************************************************
 *
 * Print channels for LFSC proofs.
 */

#include "cvc5_private.h"

#ifndef CVC4__PROOF__LFSC__LFSC_PRINT_CHANNEL_H
#define CVC4__PROOF__LFSC__LFSC_PRINT_CHANNEL_H

#include <iostream>
#include <map>

#include "expr/node.h"
#include "printer/let_binding.h"
#include "proof/lfsc/lfsc_util.h"
#include "proof/proof_node.h"

namespace cvc5 {
namespace proof {

/**
 * LFSC proofs are printed in two phases: the first phase computes the
 * letification of terms in the proof as well as other information that is
 * required for printing the preamble of the proof. The second phase prints the
 * proof to an output stream. This is the base class for these two phases.
 */
class LfscPrintChannel
{
 public:
  LfscPrintChannel() {}
  virtual ~LfscPrintChannel() {}
  /** Print node n */
  virtual void printNode(TNode n) {}
  /** Print type node n */
  virtual void printTypeNode(TypeNode tn) {}
  /** Print a hole */
  virtual void printHole() {}
  /**
   * Print an application of the trusting the result res, whose source is the
   * given proof rule.
   */
  virtual void printTrust(TNode res, PfRule src) {}
  /** Print the opening of the rule of proof rule pn, e.g. "(and_elim ". */
  virtual void printOpenRule(const ProofNode* pn) {}
  /** Print the opening of LFSC rule lr, e.g. "(cong " */
  virtual void printOpenLfscRule(LfscRule lr) {}
  /** Print the closing of # nparen proof rules */
  virtual void printCloseRule(size_t nparen = 1) {}
  /** Print a letified proof with the given identifier */
  virtual void printProofId(size_t id) {}
  /** Print a proof assumption with the given identifier */
  virtual void printAssumeId(size_t id) {}
  /** Print an end line */
  virtual void printEndLine() {}
};

/** Prints the proof to output stream d_out */
class LfscPrintChannelOut : public LfscPrintChannel
{
 public:
  LfscPrintChannelOut(std::ostream& out);
  void printNode(TNode n) override;
  void printTypeNode(TypeNode tn) override;
  void printHole() override;
  void printTrust(TNode res, PfRule src) override;
  void printOpenRule(const ProofNode* pn) override;
  void printOpenLfscRule(LfscRule lr) override;
  void printCloseRule(size_t nparen = 1) override;
  void printProofId(size_t id) override;
  void printAssumeId(size_t id) override;
  void printEndLine() override;
  //------------------- helper methods
  /**
   * Print node to stream in the expected format of LFSC.
   */
  static void printNodeInternal(std::ostream& out, Node n);
  /**
   * Print type node to stream in the expected format of LFSC.
   */
  static void printTypeNodeInternal(std::ostream& out, TypeNode tn);
  static void printRule(std::ostream& out, const ProofNode* pn);
  static void printId(std::ostream& out, size_t id);
  static void printProofId(std::ostream& out, size_t id);
  static void printAssumeId(std::ostream& out, size_t id);
  //------------------- end helper methods
 private:
  /**
   * Replaces "(_ " with "(" to eliminate indexed symbols
   * Replaces "__LFSC_TMP" with ""
   */
  static void cleanSymbols(std::string& s);
  /** The output stream */
  std::ostream& d_out;
};

/**
 * Run on the proof before it is printed, and does two preparation steps:
 * - Computes the letification of nodes that appear in the proof.
 * - Computes the set of DSL rules that appear in the proof.
 */
class LfscPrintChannelPre : public LfscPrintChannel
{
 public:
  LfscPrintChannelPre(LetBinding& lbind);
  void printNode(TNode n) override;
  void printTrust(TNode res, PfRule src) override;
  void printOpenRule(const ProofNode* pn) override;

 private:
  /** The let binding */
  LetBinding& d_lbind;
};

}  // namespace proof
}  // namespace cvc5

#endif
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback