GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/printer/smt2/smt2_printer.h Lines: 2 2 100.0 %
Date: 2021-09-16 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
11508
class Smt2Printer : public cvc5::Printer
38
{
39
 public:
40
5754
  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 assume command */
128
  void toStreamCmdAssume(std::ostream& out, Node n) const override;
129
130
  /** Print inv-constraint command */
131
  void toStreamCmdInvConstraint(std::ostream& out,
132
                                Node inv,
133
                                Node pre,
134
                                Node trans,
135
                                Node post) const override;
136
137
  /** Print check-synth command */
138
  void toStreamCmdCheckSynth(std::ostream& out) const override;
139
140
  /** Print simplify command */
141
  void toStreamCmdSimplify(std::ostream& out, Node nodes) const override;
142
143
  /** Print get-value command */
144
  void toStreamCmdGetValue(std::ostream& out,
145
                           const std::vector<Node>& n) const override;
146
147
  /** Print get-assignment command */
148
  void toStreamCmdGetAssignment(std::ostream& out) const override;
149
150
  /** Print get-model command */
151
  void toStreamCmdGetModel(std::ostream& out) const override;
152
153
  /** Print get-proof command */
154
  void toStreamCmdGetProof(std::ostream& out) const override;
155
156
  /** Print get-abduct command */
157
  void toStreamCmdGetAbduct(std::ostream& out,
158
                            const std::string& name,
159
                            Node conj,
160
                            TypeNode sygusType) const override;
161
162
  /** Print get-unsat-assumptions command */
163
  void toStreamCmdGetUnsatAssumptions(std::ostream& out) const override;
164
165
  /** Print get-unsat-core command */
166
  void toStreamCmdGetUnsatCore(std::ostream& out) const override;
167
168
  /** Print get-difficulty command */
169
  void toStreamCmdGetDifficulty(std::ostream& out) const override;
170
171
  /** Print get-assertions command */
172
  void toStreamCmdGetAssertions(std::ostream& out) const override;
173
174
  /** Print set-info :status command */
175
  void toStreamCmdSetBenchmarkStatus(std::ostream& out,
176
                                     Result::Sat status) const override;
177
178
  /** Print set-logic command */
179
  void toStreamCmdSetBenchmarkLogic(std::ostream& out,
180
                                    const std::string& logic) const override;
181
182
  /** Print set-info command */
183
  void toStreamCmdSetInfo(std::ostream& out,
184
                          const std::string& flag,
185
                          const std::string& value) const override;
186
187
  /** Print get-info command */
188
  void toStreamCmdGetInfo(std::ostream& out,
189
                          const std::string& flag) const override;
190
191
  /** Print set-option command */
192
  void toStreamCmdSetOption(std::ostream& out,
193
                            const std::string& flag,
194
                            const std::string& value) const override;
195
196
  /** Print get-option command */
197
  void toStreamCmdGetOption(std::ostream& out,
198
                            const std::string& flag) const override;
199
200
  /** Print declare-datatype(s) command */
201
  void toStreamCmdDatatypeDeclaration(
202
      std::ostream& out, const std::vector<TypeNode>& datatypes) const override;
203
204
  /** Print reset command */
205
  void toStreamCmdReset(std::ostream& out) const override;
206
207
  /** Print reset-assertions command */
208
  void toStreamCmdResetAssertions(std::ostream& out) const override;
209
210
  /** Print quit command */
211
  void toStreamCmdQuit(std::ostream& out) const override;
212
213
  /** Print comment command */
214
  void toStreamCmdComment(std::ostream& out,
215
                          const std::string& comment) const override;
216
217
  /** Print declare-heap command */
218
  void toStreamCmdDeclareHeap(std::ostream& out,
219
                              TypeNode locType,
220
                              TypeNode dataType) const override;
221
222
  /** Print command sequence command */
223
  void toStreamCmdCommandSequence(
224
      std::ostream& out, const std::vector<Command*>& sequence) const override;
225
226
  /** Print declaration sequence command */
227
  void toStreamCmdDeclarationSequence(
228
      std::ostream& out, const std::vector<Command*>& sequence) const override;
229
230
  /**
231
   * Get the string for a kind k, which returns how the kind k is printed in
232
   * the SMT-LIB format (with variant v).
233
   */
234
  static std::string smtKindString(Kind k, Variant v = smt2_6_variant);
235
236
 private:
237
  /**
238
   * The main printing method for nodes n.
239
   */
240
  void toStream(std::ostream& out,
241
                TNode n,
242
                int toDepth,
243
                LetBinding* lbind = nullptr) const;
244
  /** To stream type node, which ensures tn is printed in smt2 format */
245
  void toStreamType(std::ostream& out, TypeNode tn) const;
246
  /**
247
   * To stream, with a forced type. This method is used in some corner cases
248
   * to force a node n to be printed as if it had type tn. This is used e.g.
249
   * for the body of define-fun commands and arguments of singleton terms.
250
   */
251
  void toStreamCastToType(std::ostream& out,
252
                          TNode n,
253
                          int toDepth,
254
                          TypeNode tn) const;
255
  void toStream(std::ostream& out, const DType& dt) const;
256
  /**
257
   * To stream model sort. This prints the appropriate output for type
258
   * tn declared via declare-sort or declare-datatype.
259
   */
260
  void toStreamModelSort(std::ostream& out,
261
                         TypeNode tn,
262
                         const std::vector<Node>& elements) const override;
263
264
  /**
265
   * To stream model term. This prints the appropriate output for term
266
   * n declared via declare-fun.
267
   */
268
  void toStreamModelTerm(std::ostream& out,
269
                         const Node& n,
270
                         const Node& value) const override;
271
272
  /**
273
   * To stream with let binding. This prints n, possibly in the scope
274
   * of letification generated by this method based on lbind.
275
   */
276
  void toStreamWithLetify(std::ostream& out,
277
                          Node n,
278
                          int toDepth,
279
                          LetBinding* lbind) const;
280
  Variant d_variant;
281
}; /* class Smt2Printer */
282
283
}  // namespace smt2
284
}  // namespace printer
285
}  // namespace cvc5
286
287
#endif /* CVC5__PRINTER__SMT2_PRINTER_H */