summaryrefslogtreecommitdiff
path: root/src/proof/dot/dot_printer.h
blob: 9cc03a2584586c15e684e2f814fd74e35a774727 (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
/******************************************************************************
 * Top contributors (to current version):
 *   Diego Della Rocca de Camargos
 *
 * 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.
 * ****************************************************************************
 *
 * The module for printing dot proofs.
 */

#include "cvc5_private.h"

#ifndef CVC5__PROOF__DOT__DOT_PRINTER_H
#define CVC5__PROOF__DOT__DOT_PRINTER_H

#include <iostream>

#include "printer/let_binding.h"
#include "proof/proof_node.h"

namespace cvc5 {
namespace proof {

class DotPrinter
{
 public:
  DotPrinter();
  ~DotPrinter();

  /**
   * Print the full proof of assertions => false by pn using the dot format.
   * @param out the output stream
   * @param pn the root node of the proof to print
   */
  void print(std::ostream& out, const ProofNode* pn);

 private:
  /**
   * Print the nodes of the proof in the format:
   * $NODE_ID [ label = "{$CONCLUSION|$RULE_NAME($RULE_ARGUMENTS)}",
   * $COLORS_AND_CLASSES_RELATED_TO_THE_RULE ]; and then for each child of the
   * node $CHILD_ID -> $NODE_ID; and then recursively calls the function with
   * the child as argument.
   * @param out the output stream
   * @param pn the proof node to print
   * @param ruleID the id of the rule to print
   * @param scopeCounter counter of how many SCOPE were already depth-first
   * traversed in the proof up to this point
   * @param inPropositionalView flag used to mark the proof node being traversed
   * was generated by the SAT solver and thus belong to the propositional view
   */
  void printInternal(std::ostream& out,
                     const ProofNode* pn,
                     uint64_t& ruleID,
                     uint64_t scopeCounter,
                     bool inPropositionalView);

  /**
   * Return the arguments of a ProofNode
   * @param currentArguments an ostringstream that will store the arguments of
   * pn formatted as "$ARG[0], $ARG[1], ..., $ARG[N-1]"
   * @param pn a ProofNode
   */
  void ruleArguments(std::ostringstream& currentArguments, const ProofNode* pn);

  /** Add an escape character before special characters of the given string.
   * @param s The string to have the characters processed.
   * @return The string with the special characters escaped.
   */
  static std::string sanitizeString(const std::string& s);

  /** As above, but quotes are doubly escaped. */
  static std::string sanitizeStringDoubleQuotes(const std::string& s);

  /** Traverse proof node and populate d_subpfCounter, mapping each proof node
   * to the number of subproofs it contains, including itself
   *
   * @param pn the proof node to be traversed
   */
  void countSubproofs(const ProofNode* pn);

  /** Traverse proof node and populate d_lbind
   *
   * @param pn the proof node to be traversed
   */
  void letifyResults(const ProofNode* pn);

  /** All unique subproofs of a given proof node (counting itself). */
  std::map<const ProofNode*, size_t> d_subpfCounter;

  /** Let binder for terms in proof nodes */
  LetBinding d_lbind;
};

}  // namespace proof
}  // namespace cvc5

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