GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/printer/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, Aina Niemetz
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
 * Base of the pretty-printer interface.
14
 */
15
16
#include "cvc5_private.h"
17
18
#ifndef CVC5__PRINTER__PRINTER_H
19
#define CVC5__PRINTER__PRINTER_H
20
21
#include <string>
22
23
#include "expr/node.h"
24
#include "options/language.h"
25
#include "smt/model.h"
26
#include "util/result.h"
27
28
namespace cvc5 {
29
30
class Command;
31
class CommandStatus;
32
class UnsatCore;
33
struct InstantiationList;
34
struct SkolemList;
35
36
class Printer
37
{
38
 public:
39
  /**
40
   * Since the printers are managed as unique_ptr, we need public acces to
41
   * the virtual destructor.
42
   */
43
4339
  virtual ~Printer() {}
44
45
  /** Get the Printer for a given Language */
46
  static Printer* getPrinter(Language lang);
47
48
  /** Write a Node out to a stream with this Printer. */
49
  virtual void toStream(std::ostream& out,
50
                        TNode n,
51
                        int toDepth,
52
                        size_t dag) const = 0;
53
54
  /** Write a CommandStatus out to a stream with this Printer. */
55
  virtual void toStream(std::ostream& out, const CommandStatus* s) const = 0;
56
57
  /** Write a Model out to a stream with this Printer. */
58
  virtual void toStream(std::ostream& out, const smt::Model& m) const;
59
60
  /** Write an UnsatCore out to a stream with this Printer. */
61
  virtual void toStream(std::ostream& out, const UnsatCore& core) const;
62
63
  /** Write an instantiation list out to a stream with this Printer. */
64
  virtual void toStream(std::ostream& out, const InstantiationList& is) const;
65
66
  /** Write a skolem list out to a stream with this Printer. */
67
  virtual void toStream(std::ostream& out, const SkolemList& sks) const;
68
69
  /** Print empty command */
70
  virtual void toStreamCmdEmpty(std::ostream& out,
71
                                const std::string& name) const;
72
73
  /** Print echo command */
74
  virtual void toStreamCmdEcho(std::ostream& out,
75
                               const std::string& output) const;
76
77
  /** Print assert command */
78
  virtual void toStreamCmdAssert(std::ostream& out, Node n) const;
79
80
  /** Print push command */
81
  virtual void toStreamCmdPush(std::ostream& out) const;
82
83
  /** Print pop command */
84
  virtual void toStreamCmdPop(std::ostream& out) const;
85
86
  /** Print declare-fun command */
87
  virtual void toStreamCmdDeclareFunction(std::ostream& out,
88
                                          const std::string& id,
89
                                          TypeNode type) const;
90
  /** Variant of above for a pre-existing variable */
91
  void toStreamCmdDeclareFunction(std::ostream& out, const Node& v) const;
92
  /** Print declare-pool command */
93
  virtual void toStreamCmdDeclarePool(std::ostream& out,
94
                                      const std::string& id,
95
                                      TypeNode type,
96
                                      const std::vector<Node>& initValue) const;
97
98
  /** Print declare-sort command */
99
  virtual void toStreamCmdDeclareType(std::ostream& out,
100
                                      TypeNode type) const;
101
102
  /** Print define-sort command */
103
  virtual void toStreamCmdDefineType(std::ostream& out,
104
                                     const std::string& id,
105
                                     const std::vector<TypeNode>& params,
106
                                     TypeNode t) const;
107
108
  /** Print define-fun command */
109
  virtual void toStreamCmdDefineFunction(std::ostream& out,
110
                                         const std::string& id,
111
                                         const std::vector<Node>& formals,
112
                                         TypeNode range,
113
                                         Node formula) const;
114
  /** Variant of above that takes the definition */
115
  void toStreamCmdDefineFunction(std::ostream& out, Node v, Node lambda) const;
116
117
  /** Print define-fun-rec command */
118
  virtual void toStreamCmdDefineFunctionRec(
119
      std::ostream& out,
120
      const std::vector<Node>& funcs,
121
      const std::vector<std::vector<Node>>& formals,
122
      const std::vector<Node>& formulas) const;
123
  /** Variant of above that takes the definition */
124
  void toStreamCmdDefineFunctionRec(std::ostream& out,
125
                                    const std::vector<Node>& funcs,
126
                                    const std::vector<Node>& lambdas) const;
127
128
  /** Print set-user-attribute command */
129
  void toStreamCmdSetUserAttribute(std::ostream& out,
130
                                   const std::string& attr,
131
                                   Node n) const;
132
133
  /** Print check-sat command */
134
  virtual void toStreamCmdCheckSat(std::ostream& out,
135
                                   Node n = Node::null()) const;
136
137
  /** Print check-sat-assuming command */
138
  virtual void toStreamCmdCheckSatAssuming(
139
      std::ostream& out, const std::vector<Node>& nodes) const;
140
141
  /** Print query command */
142
  virtual void toStreamCmdQuery(std::ostream& out, Node n) const;
143
144
  /** Print declare-var command */
145
  virtual void toStreamCmdDeclareVar(std::ostream& out,
146
                                     Node var,
147
                                     TypeNode type) const;
148
149
  /** Print synth-fun command */
150
  virtual void toStreamCmdSynthFun(std::ostream& out,
151
                                   Node f,
152
                                   const std::vector<Node>& vars,
153
                                   bool isInv,
154
                                   TypeNode sygusType = TypeNode::null()) const;
155
156
  /** Print constraint command */
157
  virtual void toStreamCmdConstraint(std::ostream& out, Node n) const;
158
159
  /** Print assume command */
160
  virtual void toStreamCmdAssume(std::ostream& out, Node n) const;
161
162
  /** Print inv-constraint command */
163
  virtual void toStreamCmdInvConstraint(
164
      std::ostream& out, Node inv, Node pre, Node trans, Node post) const;
165
166
  /** Print check-synth command */
167
  virtual void toStreamCmdCheckSynth(std::ostream& out) const;
168
169
  /** Print simplify command */
170
  virtual void toStreamCmdSimplify(std::ostream& out, Node n) const;
171
172
  /** Print get-value command */
173
  virtual void toStreamCmdGetValue(std::ostream& out,
174
                                   const std::vector<Node>& nodes) const;
175
176
  /** Print get-assignment command */
177
  virtual void toStreamCmdGetAssignment(std::ostream& out) const;
178
179
  /** Print get-model command */
180
  virtual void toStreamCmdGetModel(std::ostream& out) const;
181
182
  /** Print block-model command */
183
  void toStreamCmdBlockModel(std::ostream& out) const;
184
185
  /** Print block-model-values command */
186
  void toStreamCmdBlockModelValues(std::ostream& out,
187
                                   const std::vector<Node>& nodes) const;
188
189
  /** Print get-proof command */
190
  virtual void toStreamCmdGetProof(std::ostream& out) const;
191
192
  /** Print get-instantiations command */
193
  void toStreamCmdGetInstantiations(std::ostream& out) const;
194
195
  /** Print get-interpol command */
196
  void toStreamCmdGetInterpol(std::ostream& out,
197
                              const std::string& name,
198
                              Node conj,
199
                              TypeNode sygusType) const;
200
201
  /** Print get-abduct command */
202
  virtual void toStreamCmdGetAbduct(std::ostream& out,
203
                                    const std::string& name,
204
                                    Node conj,
205
                                    TypeNode sygusType) const;
206
207
  /** Print get-quantifier-elimination command */
208
  void toStreamCmdGetQuantifierElimination(std::ostream& out, Node n) const;
209
210
  /** Print get-unsat-assumptions command */
211
  virtual void toStreamCmdGetUnsatAssumptions(std::ostream& out) const;
212
213
  /** Print get-unsat-core command */
214
  virtual void toStreamCmdGetUnsatCore(std::ostream& out) const;
215
216
  /** Print get-difficulty command */
217
  virtual void toStreamCmdGetDifficulty(std::ostream& out) const;
218
219
  /** Print get-assertions command */
220
  virtual void toStreamCmdGetAssertions(std::ostream& out) const;
221
222
  /** Print set-logic command */
223
  virtual void toStreamCmdSetBenchmarkLogic(std::ostream& out,
224
                                            const std::string& logic) const;
225
226
  /** Print set-info command */
227
  virtual void toStreamCmdSetInfo(std::ostream& out,
228
                                  const std::string& flag,
229
                                  const std::string& value) const;
230
231
  /** Print get-info command */
232
  virtual void toStreamCmdGetInfo(std::ostream& out,
233
                                  const std::string& flag) const;
234
235
  /** Print set-option command */
236
  virtual void toStreamCmdSetOption(std::ostream& out,
237
                                    const std::string& flag,
238
                                    const std::string& value) const;
239
240
  /** Print get-option command */
241
  virtual void toStreamCmdGetOption(std::ostream& out,
242
                                    const std::string& flag) const;
243
244
  /** Print set-expression-name command */
245
  void toStreamCmdSetExpressionName(std::ostream& out,
246
                                    Node n,
247
                                    const std::string& name) const;
248
249
  /** Print declare-datatype(s) command */
250
  virtual void toStreamCmdDatatypeDeclaration(
251
      std::ostream& out, const std::vector<TypeNode>& datatypes) const;
252
253
  /** Print reset command */
254
  virtual void toStreamCmdReset(std::ostream& out) const;
255
256
  /** Print reset-assertions command */
257
  virtual void toStreamCmdResetAssertions(std::ostream& out) const;
258
259
  /** Print quit command */
260
  virtual void toStreamCmdQuit(std::ostream& out) const;
261
262
  /** Declare heap command */
263
  virtual void toStreamCmdDeclareHeap(std::ostream& out,
264
                                      TypeNode locType,
265
                                      TypeNode dataType) const;
266
267
  /** Print command sequence command */
268
  virtual void toStreamCmdCommandSequence(
269
      std::ostream& out, const std::vector<Command*>& sequence) const;
270
271
  /** Print declaration sequence command */
272
  virtual void toStreamCmdDeclarationSequence(
273
      std::ostream& out, const std::vector<Command*>& sequence) const;
274
275
 protected:
276
  /** Derived classes can construct, but no one else. */
277
4339
  Printer() {}
278
279
  /**
280
   * To stream model sort. This prints the appropriate output for type
281
   * tn declared via declare-sort.
282
   */
283
  virtual void toStreamModelSort(std::ostream& out,
284
                                 TypeNode tn,
285
                                 const std::vector<Node>& elements) const = 0;
286
287
  /**
288
   * To stream model term. This prints the appropriate output for term
289
   * n declared via declare-fun.
290
   */
291
  virtual void toStreamModelTerm(std::ostream& out,
292
                                 const Node& n,
293
                                 const Node& value) const = 0;
294
295
  /** write model response to command using another language printer */
296
  void toStreamUsing(Language lang,
297
                     std::ostream& out,
298
                     const smt::Model& m) const;
299
300
  /**
301
   * Write an error to `out` stating that command `name` is not supported by
302
   * this printer.
303
   */
304
  void printUnknownCommand(std::ostream& out, const std::string& name) const;
305
306
 private:
307
  /** Disallow copy, assignment  */
308
  Printer(const Printer&) = delete;
309
  Printer& operator=(const Printer&) = delete;
310
311
  /** Make a Printer for a given Language */
312
  static std::unique_ptr<Printer> makePrinter(Language lang);
313
314
  /** Printers for each Language */
315
  static std::unique_ptr<Printer>
316
      d_printers[static_cast<size_t>(Language::LANG_MAX)];
317
318
}; /* class Printer */
319
320
}  // namespace cvc5
321
322
#endif /* CVC5__PRINTER__PRINTER_H */