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