GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/printer/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, 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
7028
  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) const;
135
136
  /** Print check-sat-assuming command */
137
  virtual void toStreamCmdCheckSatAssuming(
138
      std::ostream& out, const std::vector<Node>& nodes) const;
139
140
  /** Print query command */
141
  virtual void toStreamCmdQuery(std::ostream& out, Node n) const;
142
143
  /** Print declare-var command */
144
  virtual void toStreamCmdDeclareVar(std::ostream& out,
145
                                     Node var,
146
                                     TypeNode type) const;
147
148
  /** Print synth-fun command */
149
  virtual void toStreamCmdSynthFun(std::ostream& out,
150
                                   Node f,
151
                                   const std::vector<Node>& vars,
152
                                   bool isInv,
153
                                   TypeNode sygusType = TypeNode::null()) const;
154
155
  /** Print constraint command */
156
  virtual void toStreamCmdConstraint(std::ostream& out, Node n) const;
157
158
  /** Print assume command */
159
  virtual void toStreamCmdAssume(std::ostream& out, Node n) const;
160
161
  /** Print inv-constraint command */
162
  virtual void toStreamCmdInvConstraint(
163
      std::ostream& out, Node inv, Node pre, Node trans, Node post) const;
164
165
  /** Print check-synth command */
166
  virtual void toStreamCmdCheckSynth(std::ostream& out) const;
167
168
  /** Print simplify command */
169
  virtual void toStreamCmdSimplify(std::ostream& out, Node n) const;
170
171
  /** Print get-value command */
172
  virtual void toStreamCmdGetValue(std::ostream& out,
173
                                   const std::vector<Node>& nodes) const;
174
175
  /** Print get-assignment command */
176
  virtual void toStreamCmdGetAssignment(std::ostream& out) const;
177
178
  /** Print get-model command */
179
  virtual void toStreamCmdGetModel(std::ostream& out) const;
180
181
  /** Print block-model command */
182
  virtual void toStreamCmdBlockModel(std::ostream& out) const;
183
184
  /** Print block-model-values command */
185
  virtual void toStreamCmdBlockModelValues(
186
      std::ostream& out, const std::vector<Node>& nodes) const;
187
188
  /** Print get-proof command */
189
  virtual void toStreamCmdGetProof(std::ostream& out) const;
190
191
  /** Print get-instantiations command */
192
  void toStreamCmdGetInstantiations(std::ostream& out) const;
193
194
  /** Print get-interpol command */
195
  virtual void toStreamCmdGetInterpol(std::ostream& out,
196
                                      const std::string& name,
197
                                      Node conj,
198
                                      TypeNode sygusType) const;
199
200
  /** Print get-abduct command */
201
  virtual void toStreamCmdGetAbduct(std::ostream& out,
202
                                    const std::string& name,
203
                                    Node conj,
204
                                    TypeNode sygusType) const;
205
206
  /** Print get-quantifier-elimination command */
207
  virtual void toStreamCmdGetQuantifierElimination(std::ostream& out,
208
                                                   Node n,
209
                                                   bool doFull) const;
210
211
  /** Print get-unsat-assumptions command */
212
  virtual void toStreamCmdGetUnsatAssumptions(std::ostream& out) const;
213
214
  /** Print get-unsat-core command */
215
  virtual void toStreamCmdGetUnsatCore(std::ostream& out) const;
216
217
  /** Print get-difficulty command */
218
  virtual void toStreamCmdGetDifficulty(std::ostream& out) const;
219
220
  /** Print get-assertions command */
221
  virtual void toStreamCmdGetAssertions(std::ostream& out) const;
222
223
  /** Print set-logic command */
224
  virtual void toStreamCmdSetBenchmarkLogic(std::ostream& out,
225
                                            const std::string& logic) const;
226
227
  /** Print set-info command */
228
  virtual void toStreamCmdSetInfo(std::ostream& out,
229
                                  const std::string& flag,
230
                                  const std::string& value) const;
231
232
  /** Print get-info command */
233
  virtual void toStreamCmdGetInfo(std::ostream& out,
234
                                  const std::string& flag) const;
235
236
  /** Print set-option command */
237
  virtual void toStreamCmdSetOption(std::ostream& out,
238
                                    const std::string& flag,
239
                                    const std::string& value) const;
240
241
  /** Print get-option command */
242
  virtual void toStreamCmdGetOption(std::ostream& out,
243
                                    const std::string& flag) const;
244
245
  /** Print set-expression-name command */
246
  void toStreamCmdSetExpressionName(std::ostream& out,
247
                                    Node n,
248
                                    const std::string& name) const;
249
250
  /** Print declare-datatype(s) command */
251
  virtual void toStreamCmdDatatypeDeclaration(
252
      std::ostream& out, const std::vector<TypeNode>& datatypes) const;
253
254
  /** Print reset command */
255
  virtual void toStreamCmdReset(std::ostream& out) const;
256
257
  /** Print reset-assertions command */
258
  virtual void toStreamCmdResetAssertions(std::ostream& out) const;
259
260
  /** Print quit command */
261
  virtual void toStreamCmdQuit(std::ostream& out) const;
262
263
  /** Declare heap command */
264
  virtual void toStreamCmdDeclareHeap(std::ostream& out,
265
                                      TypeNode locType,
266
                                      TypeNode dataType) const;
267
268
  /** Print command sequence command */
269
  virtual void toStreamCmdCommandSequence(
270
      std::ostream& out, const std::vector<Command*>& sequence) const;
271
272
  /** Print declaration sequence command */
273
  virtual void toStreamCmdDeclarationSequence(
274
      std::ostream& out, const std::vector<Command*>& sequence) const;
275
276
 protected:
277
  /** Derived classes can construct, but no one else. */
278
7028
  Printer() {}
279
280
  /**
281
   * To stream model sort. This prints the appropriate output for type
282
   * tn declared via declare-sort.
283
   */
284
  virtual void toStreamModelSort(std::ostream& out,
285
                                 TypeNode tn,
286
                                 const std::vector<Node>& elements) const = 0;
287
288
  /**
289
   * To stream model term. This prints the appropriate output for term
290
   * n declared via declare-fun.
291
   */
292
  virtual void toStreamModelTerm(std::ostream& out,
293
                                 const Node& n,
294
                                 const Node& value) const = 0;
295
296
  /** write model response to command using another language printer */
297
  void toStreamUsing(Language lang,
298
                     std::ostream& out,
299
                     const smt::Model& m) const;
300
301
  /**
302
   * Write an error to `out` stating that command `name` is not supported by
303
   * this printer.
304
   */
305
  void printUnknownCommand(std::ostream& out, const std::string& name) const;
306
307
 private:
308
  /** Disallow copy, assignment  */
309
  Printer(const Printer&) = delete;
310
  Printer& operator=(const Printer&) = delete;
311
312
  /** Make a Printer for a given Language */
313
  static std::unique_ptr<Printer> makePrinter(Language lang);
314
315
  /** Printers for each Language */
316
  static std::unique_ptr<Printer>
317
      d_printers[static_cast<size_t>(Language::LANG_MAX)];
318
319
}; /* class Printer */
320
321
}  // namespace cvc5
322
323
#endif /* CVC5__PRINTER__PRINTER_H */