GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/printer/smt2/smt2_printer.h Lines: 2 2 100.0 %
Date: 2021-09-29 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
8588
class Smt2Printer : public cvc5::Printer
38
{
39
 public:
40
4294
  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-logic command */
175
  void toStreamCmdSetBenchmarkLogic(std::ostream& out,
176
                                    const std::string& logic) const override;
177
178
  /** Print set-info command */
179
  void toStreamCmdSetInfo(std::ostream& out,
180
                          const std::string& flag,
181
                          const std::string& value) const override;
182
183
  /** Print get-info command */
184
  void toStreamCmdGetInfo(std::ostream& out,
185
                          const std::string& flag) const override;
186
187
  /** Print set-option command */
188
  void toStreamCmdSetOption(std::ostream& out,
189
                            const std::string& flag,
190
                            const std::string& value) const override;
191
192
  /** Print get-option command */
193
  void toStreamCmdGetOption(std::ostream& out,
194
                            const std::string& flag) const override;
195
196
  /** Print declare-datatype(s) command */
197
  void toStreamCmdDatatypeDeclaration(
198
      std::ostream& out, const std::vector<TypeNode>& datatypes) const override;
199
200
  /** Print reset command */
201
  void toStreamCmdReset(std::ostream& out) const override;
202
203
  /** Print reset-assertions command */
204
  void toStreamCmdResetAssertions(std::ostream& out) const override;
205
206
  /** Print quit command */
207
  void toStreamCmdQuit(std::ostream& out) const override;
208
209
  /** Print declare-heap command */
210
  void toStreamCmdDeclareHeap(std::ostream& out,
211
                              TypeNode locType,
212
                              TypeNode dataType) const override;
213
214
  /** Print command sequence command */
215
  void toStreamCmdCommandSequence(
216
      std::ostream& out, const std::vector<Command*>& sequence) const override;
217
218
  /** Print declaration sequence command */
219
  void toStreamCmdDeclarationSequence(
220
      std::ostream& out, const std::vector<Command*>& sequence) const override;
221
222
  /**
223
   * Get the string for a kind k, which returns how the kind k is printed in
224
   * the SMT-LIB format (with variant v).
225
   */
226
  static std::string smtKindString(Kind k, Variant v = smt2_6_variant);
227
228
 private:
229
  /**
230
   * The main printing method for nodes n.
231
   */
232
  void toStream(std::ostream& out,
233
                TNode n,
234
                int toDepth,
235
                LetBinding* lbind = nullptr) const;
236
  /** To stream type node, which ensures tn is printed in smt2 format */
237
  void toStreamType(std::ostream& out, TypeNode tn) const;
238
  /**
239
   * To stream, with a forced type. This method is used in some corner cases
240
   * to force a node n to be printed as if it had type tn. This is used e.g.
241
   * for the body of define-fun commands and arguments of singleton terms.
242
   */
243
  void toStreamCastToType(std::ostream& out,
244
                          TNode n,
245
                          int toDepth,
246
                          TypeNode tn) const;
247
  void toStream(std::ostream& out, const DType& dt) const;
248
  /**
249
   * To stream model sort. This prints the appropriate output for type
250
   * tn declared via declare-sort or declare-datatype.
251
   */
252
  void toStreamModelSort(std::ostream& out,
253
                         TypeNode tn,
254
                         const std::vector<Node>& elements) const override;
255
256
  /**
257
   * To stream model term. This prints the appropriate output for term
258
   * n declared via declare-fun.
259
   */
260
  void toStreamModelTerm(std::ostream& out,
261
                         const Node& n,
262
                         const Node& value) const override;
263
264
  /**
265
   * To stream with let binding. This prints n, possibly in the scope
266
   * of letification generated by this method based on lbind.
267
   */
268
  void toStreamWithLetify(std::ostream& out,
269
                          Node n,
270
                          int toDepth,
271
                          LetBinding* lbind) const;
272
  Variant d_variant;
273
}; /* class Smt2Printer */
274
275
}  // namespace smt2
276
}  // namespace printer
277
}  // namespace cvc5
278
279
#endif /* CVC5__PRINTER__SMT2_PRINTER_H */