GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/printer/smt2/smt2_printer.h Lines: 2 2 100.0 %
Date: 2021-08-06 Branches: 0 0 0.0 %

Line Exec Source
1
/******************************************************************************
2
 * Top contributors (to current version):
3
 *   Abdalrhman Mohamed, Andrew Reynolds, Tim King
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
 * The pretty-printer interface for the SMT2 output language.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__PRINTER__SMT2_PRINTER_H
19
#define CVC5__PRINTER__SMT2_PRINTER_H
20
21
#include "printer/printer.h"
22
23
namespace cvc5 {
24
25
class LetBinding;
26
27
namespace printer {
28
namespace smt2 {
29
30
enum Variant
31
{
32
  no_variant,
33
  smt2_6_variant,  // new-style 2.6 syntax, when it makes a difference, with
34
                   // support for the string standard
35
};                 /* enum Variant */
36
37
11410
class Smt2Printer : public cvc5::Printer
38
{
39
 public:
40
5705
  Smt2Printer(Variant variant = no_variant) : d_variant(variant) {}
41
  using cvc5::Printer::toStream;
42
  void toStream(std::ostream& out,
43
                TNode n,
44
                int toDepth,
45
                size_t dag) const override;
46
  void toStream(std::ostream& out, const CommandStatus* s) const override;
47
  void toStream(std::ostream& out, const smt::Model& m) const override;
48
  /**
49
   * Writes the unsat core to the stream out.
50
   * We use the expression names that are stored in the SMT engine associated
51
   * with the core (UnsatCore::getSmtEngine) for printing named assertions.
52
   */
53
  void toStream(std::ostream& out, const UnsatCore& core) const override;
54
55
  /** Print empty command */
56
  void toStreamCmdEmpty(std::ostream& out,
57
                        const std::string& name) const override;
58
59
  /** Print echo command */
60
  void toStreamCmdEcho(std::ostream& out,
61
                       const std::string& output) const override;
62
63
  /** Print assert command */
64
  void toStreamCmdAssert(std::ostream& out, Node n) const override;
65
66
  /** Print push command */
67
  void toStreamCmdPush(std::ostream& out) const override;
68
69
  /** Print pop command */
70
  void toStreamCmdPop(std::ostream& out) const override;
71
72
  /** Print declare-fun command */
73
  void toStreamCmdDeclareFunction(std::ostream& out,
74
                                  const std::string& id,
75
                                  TypeNode type) const override;
76
77
  /** Print declare-sort command */
78
  void toStreamCmdDeclareType(std::ostream& out,
79
                              TypeNode type) const override;
80
81
  /** Print define-sort command */
82
  void toStreamCmdDefineType(std::ostream& out,
83
                             const std::string& id,
84
                             const std::vector<TypeNode>& params,
85
                             TypeNode t) const override;
86
87
  /** Print define-fun command */
88
  void toStreamCmdDefineFunction(std::ostream& out,
89
                                 const std::string& id,
90
                                 const std::vector<Node>& formals,
91
                                 TypeNode range,
92
                                 Node formula) const override;
93
94
  /** Print define-fun-rec command */
95
  void toStreamCmdDefineFunctionRec(
96
      std::ostream& out,
97
      const std::vector<Node>& funcs,
98
      const std::vector<std::vector<Node>>& formals,
99
      const std::vector<Node>& formulas) const override;
100
101
  /** Print check-sat command */
102
  void toStreamCmdCheckSat(std::ostream& out,
103
                           Node n = Node::null()) const override;
104
105
  /** Print check-sat-assuming command */
106
  void toStreamCmdCheckSatAssuming(
107
      std::ostream& out, const std::vector<Node>& nodes) const override;
108
109
  /** Print query command */
110
  void toStreamCmdQuery(std::ostream& out, Node n) const override;
111
112
  /** Print declare-var command */
113
  void toStreamCmdDeclareVar(std::ostream& out,
114
                             Node var,
115
                             TypeNode type) const override;
116
117
  /** Print synth-fun command */
118
  void toStreamCmdSynthFun(std::ostream& out,
119
                           Node f,
120
                           const std::vector<Node>& vars,
121
                           bool isInv,
122
                           TypeNode sygusType = TypeNode::null()) const override;
123
124
  /** Print constraint command */
125
  void toStreamCmdConstraint(std::ostream& out, Node n) const override;
126
127
  /** Print inv-constraint command */
128
  void toStreamCmdInvConstraint(std::ostream& out,
129
                                Node inv,
130
                                Node pre,
131
                                Node trans,
132
                                Node post) const override;
133
134
  /** Print check-synth command */
135
  void toStreamCmdCheckSynth(std::ostream& out) const override;
136
137
  /** Print simplify command */
138
  void toStreamCmdSimplify(std::ostream& out, Node nodes) const override;
139
140
  /** Print get-value command */
141
  void toStreamCmdGetValue(std::ostream& out,
142
                           const std::vector<Node>& n) const override;
143
144
  /** Print get-assignment command */
145
  void toStreamCmdGetAssignment(std::ostream& out) const override;
146
147
  /** Print get-model command */
148
  void toStreamCmdGetModel(std::ostream& out) const override;
149
150
  /** Print get-proof command */
151
  void toStreamCmdGetProof(std::ostream& out) const override;
152
153
  /** Print get-abduct command */
154
  void toStreamCmdGetAbduct(std::ostream& out,
155
                            const std::string& name,
156
                            Node conj,
157
                            TypeNode sygusType) const override;
158
159
  /** Print get-unsat-assumptions command */
160
  void toStreamCmdGetUnsatAssumptions(std::ostream& out) const override;
161
162
  /** Print get-unsat-core command */
163
  void toStreamCmdGetUnsatCore(std::ostream& out) const override;
164
165
  /** Print get-assertions command */
166
  void toStreamCmdGetAssertions(std::ostream& out) const override;
167
168
  /** Print set-info :status command */
169
  void toStreamCmdSetBenchmarkStatus(std::ostream& out,
170
                                     Result::Sat status) const override;
171
172
  /** Print set-logic command */
173
  void toStreamCmdSetBenchmarkLogic(std::ostream& out,
174
                                    const std::string& logic) const override;
175
176
  /** Print set-info command */
177
  void toStreamCmdSetInfo(std::ostream& out,
178
                          const std::string& flag,
179
                          const std::string& value) const override;
180
181
  /** Print get-info command */
182
  void toStreamCmdGetInfo(std::ostream& out,
183
                          const std::string& flag) const override;
184
185
  /** Print set-option command */
186
  void toStreamCmdSetOption(std::ostream& out,
187
                            const std::string& flag,
188
                            const std::string& value) const override;
189
190
  /** Print get-option command */
191
  void toStreamCmdGetOption(std::ostream& out,
192
                            const std::string& flag) const override;
193
194
  /** Print declare-datatype(s) command */
195
  void toStreamCmdDatatypeDeclaration(
196
      std::ostream& out, const std::vector<TypeNode>& datatypes) const override;
197
198
  /** Print reset command */
199
  void toStreamCmdReset(std::ostream& out) const override;
200
201
  /** Print reset-assertions command */
202
  void toStreamCmdResetAssertions(std::ostream& out) const override;
203
204
  /** Print quit command */
205
  void toStreamCmdQuit(std::ostream& out) const override;
206
207
  /** Print comment command */
208
  void toStreamCmdComment(std::ostream& out,
209
                          const std::string& comment) const override;
210
211
  /** Print declare-heap command */
212
  void toStreamCmdDeclareHeap(std::ostream& out,
213
                              TypeNode locType,
214
                              TypeNode dataType) const override;
215
216
  /** Print command sequence command */
217
  void toStreamCmdCommandSequence(
218
      std::ostream& out, const std::vector<Command*>& sequence) const override;
219
220
  /** Print declaration sequence command */
221
  void toStreamCmdDeclarationSequence(
222
      std::ostream& out, const std::vector<Command*>& sequence) const override;
223
224
  /**
225
   * Get the string for a kind k, which returns how the kind k is printed in
226
   * the SMT-LIB format (with variant v).
227
   */
228
  static std::string smtKindString(Kind k, Variant v = smt2_6_variant);
229
230
 private:
231
  /**
232
   * The main printing method for nodes n.
233
   */
234
  void toStream(std::ostream& out,
235
                TNode n,
236
                int toDepth,
237
                LetBinding* lbind = nullptr) const;
238
  /** To stream type node, which ensures tn is printed in smt2 format */
239
  void toStreamType(std::ostream& out, TypeNode tn) const;
240
  /**
241
   * To stream, with a forced type. This method is used in some corner cases
242
   * to force a node n to be printed as if it had type tn. This is used e.g.
243
   * for the body of define-fun commands and arguments of singleton terms.
244
   */
245
  void toStreamCastToType(std::ostream& out,
246
                          TNode n,
247
                          int toDepth,
248
                          TypeNode tn) const;
249
  void toStream(std::ostream& out, const DType& dt) const;
250
  /**
251
   * To stream model sort. This prints the appropriate output for type
252
   * tn declared via declare-sort or declare-datatype.
253
   */
254
  void toStreamModelSort(std::ostream& out,
255
                         const smt::Model& m,
256
                         TypeNode tn) const override;
257
258
  /**
259
   * To stream model term. This prints the appropriate output for term
260
   * n declared via declare-fun.
261
   */
262
  void toStreamModelTerm(std::ostream& out,
263
                         const smt::Model& m,
264
                         Node n) const override;
265
266
  /**
267
   * To stream with let binding. This prints n, possibly in the scope
268
   * of letification generated by this method based on lbind.
269
   */
270
  void toStreamWithLetify(std::ostream& out,
271
                          Node n,
272
                          int toDepth,
273
                          LetBinding* lbind) const;
274
  Variant d_variant;
275
}; /* class Smt2Printer */
276
277
}  // namespace smt2
278
}  // namespace printer
279
}  // namespace cvc5
280
281
#endif /* CVC5__PRINTER__SMT2_PRINTER_H */