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