1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Abdalrhman Mohamed, Andrew Reynolds, Morgan Deters |
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 |
|
#include "printer/printer.h" |
16 |
|
|
17 |
|
#include <string> |
18 |
|
|
19 |
|
#include "options/base_options.h" |
20 |
|
#include "options/language.h" |
21 |
|
#include "printer/ast/ast_printer.h" |
22 |
|
#include "printer/cvc/cvc_printer.h" |
23 |
|
#include "printer/smt2/smt2_printer.h" |
24 |
|
#include "printer/tptp/tptp_printer.h" |
25 |
|
#include "proof/unsat_core.h" |
26 |
|
#include "smt/command.h" |
27 |
|
#include "smt/node_command.h" |
28 |
|
#include "theory/quantifiers/instantiation_list.h" |
29 |
|
|
30 |
|
using namespace std; |
31 |
|
|
32 |
|
namespace cvc5 { |
33 |
|
|
34 |
18794 |
unique_ptr<Printer> Printer::d_printers[language::output::LANG_MAX]; |
35 |
|
|
36 |
6305 |
unique_ptr<Printer> Printer::makePrinter(OutputLanguage lang) |
37 |
|
{ |
38 |
|
using namespace cvc5::language::output; |
39 |
|
|
40 |
6305 |
switch(lang) { |
41 |
5256 |
case LANG_SMTLIB_V2_6: |
42 |
|
return unique_ptr<Printer>( |
43 |
5256 |
new printer::smt2::Smt2Printer(printer::smt2::smt2_6_variant)); |
44 |
|
|
45 |
43 |
case LANG_TPTP: |
46 |
43 |
return unique_ptr<Printer>(new printer::tptp::TptpPrinter()); |
47 |
|
|
48 |
808 |
case LANG_CVC: return unique_ptr<Printer>(new printer::cvc::CvcPrinter()); |
49 |
|
|
50 |
194 |
case LANG_SYGUS_V2: |
51 |
|
// sygus version 2.0 does not have discrepancies with smt2, hence we use |
52 |
|
// a normal smt2 variant here. |
53 |
|
return unique_ptr<Printer>( |
54 |
194 |
new printer::smt2::Smt2Printer(printer::smt2::smt2_6_variant)); |
55 |
|
|
56 |
4 |
case LANG_AST: |
57 |
4 |
return unique_ptr<Printer>(new printer::ast::AstPrinter()); |
58 |
|
|
59 |
|
default: Unhandled() << lang; |
60 |
|
} |
61 |
|
} |
62 |
|
|
63 |
25 |
void Printer::toStream(std::ostream& out, const smt::Model& m) const |
64 |
|
{ |
65 |
|
// print the declared sorts |
66 |
25 |
const std::vector<TypeNode>& dsorts = m.getDeclaredSorts(); |
67 |
29 |
for (const TypeNode& tn : dsorts) |
68 |
|
{ |
69 |
4 |
toStreamModelSort(out, m, tn); |
70 |
|
} |
71 |
|
|
72 |
|
// print the declared terms |
73 |
25 |
const std::vector<Node>& dterms = m.getDeclaredTerms(); |
74 |
55 |
for (const Node& n : dterms) |
75 |
|
{ |
76 |
|
// take into account model core, independently of the format |
77 |
30 |
if (!m.isModelCoreSymbol(n)) |
78 |
|
{ |
79 |
|
continue; |
80 |
|
} |
81 |
30 |
toStreamModelTerm(out, m, n); |
82 |
|
} |
83 |
|
|
84 |
25 |
}/* Printer::toStream(Model) */ |
85 |
|
|
86 |
|
void Printer::toStreamUsing(OutputLanguage lang, |
87 |
|
std::ostream& out, |
88 |
|
const smt::Model& m) const |
89 |
|
{ |
90 |
|
getPrinter(lang)->toStream(out, m); |
91 |
|
} |
92 |
|
|
93 |
|
void Printer::toStream(std::ostream& out, const UnsatCore& core) const |
94 |
|
{ |
95 |
|
for(UnsatCore::iterator i = core.begin(); i != core.end(); ++i) { |
96 |
|
toStreamCmdAssert(out, *i); |
97 |
|
out << std::endl; |
98 |
|
} |
99 |
|
}/* Printer::toStream(UnsatCore) */ |
100 |
|
|
101 |
15 |
void Printer::toStream(std::ostream& out, const InstantiationList& is) const |
102 |
|
{ |
103 |
15 |
out << "(instantiations " << is.d_quant << std::endl; |
104 |
30 |
for (const std::vector<Node>& i : is.d_inst) |
105 |
|
{ |
106 |
15 |
out << " ( "; |
107 |
30 |
for (const Node& n : i) |
108 |
|
{ |
109 |
15 |
out << n << " "; |
110 |
|
} |
111 |
15 |
out << ")" << std::endl; |
112 |
|
} |
113 |
15 |
out << ")" << std::endl; |
114 |
15 |
} |
115 |
|
|
116 |
9 |
void Printer::toStream(std::ostream& out, const SkolemList& sks) const |
117 |
|
{ |
118 |
9 |
out << "(skolem " << sks.d_quant << std::endl; |
119 |
9 |
out << " ( "; |
120 |
18 |
for (const Node& n : sks.d_sks) |
121 |
|
{ |
122 |
9 |
out << n << " "; |
123 |
|
} |
124 |
9 |
out << ")" << std::endl; |
125 |
9 |
out << ")" << std::endl; |
126 |
9 |
} |
127 |
|
|
128 |
376153 |
Printer* Printer::getPrinter(OutputLanguage lang) |
129 |
|
{ |
130 |
376153 |
if (lang == language::output::LANG_AUTO) |
131 |
|
{ |
132 |
|
// Infer the language to use for output. |
133 |
|
// |
134 |
|
// Options can be null in certain circumstances (e.g., when printing |
135 |
|
// the singleton "null" expr. So we guard against segfault |
136 |
2322 |
if (not Options::isCurrentNull()) |
137 |
|
{ |
138 |
70071 |
if (Options::current().wasSetByUser(options::outputLanguage)) |
139 |
|
{ |
140 |
4 |
lang = options::outputLanguage(); |
141 |
|
} |
142 |
2312 |
if (lang == language::output::LANG_AUTO |
143 |
901474 |
&& Options::current().wasSetByUser(options::inputLanguage)) |
144 |
|
{ |
145 |
16 |
lang = language::toOutputLanguage(options::inputLanguage()); |
146 |
|
} |
147 |
|
} |
148 |
2322 |
if (lang == language::output::LANG_AUTO) |
149 |
|
{ |
150 |
2302 |
lang = language::output::LANG_SMTLIB_V2_6; // default |
151 |
|
} |
152 |
|
} |
153 |
376153 |
if (d_printers[lang] == nullptr) |
154 |
|
{ |
155 |
6305 |
d_printers[lang] = makePrinter(lang); |
156 |
|
} |
157 |
376153 |
return d_printers[lang].get(); |
158 |
|
} |
159 |
|
|
160 |
|
void Printer::printUnknownCommand(std::ostream& out, |
161 |
|
const std::string& name) const |
162 |
|
{ |
163 |
|
out << "ERROR: don't know how to print " << name << " command" << std::endl; |
164 |
|
} |
165 |
|
|
166 |
|
void Printer::toStreamCmdEmpty(std::ostream& out, const std::string& name) const |
167 |
|
{ |
168 |
|
printUnknownCommand(out, "empty"); |
169 |
|
} |
170 |
|
|
171 |
|
void Printer::toStreamCmdEcho(std::ostream& out, |
172 |
|
const std::string& output) const |
173 |
|
{ |
174 |
|
printUnknownCommand(out, "echo"); |
175 |
|
} |
176 |
|
|
177 |
|
void Printer::toStreamCmdAssert(std::ostream& out, Node n) const |
178 |
|
{ |
179 |
|
printUnknownCommand(out, "assert"); |
180 |
|
} |
181 |
|
|
182 |
|
void Printer::toStreamCmdPush(std::ostream& out) const |
183 |
|
{ |
184 |
|
printUnknownCommand(out, "push"); |
185 |
|
} |
186 |
|
|
187 |
|
void Printer::toStreamCmdPop(std::ostream& out) const |
188 |
|
{ |
189 |
|
printUnknownCommand(out, "pop"); |
190 |
|
} |
191 |
|
|
192 |
|
void Printer::toStreamCmdDeclareFunction(std::ostream& out, |
193 |
|
const std::string& id, |
194 |
|
TypeNode type) const |
195 |
|
{ |
196 |
|
printUnknownCommand(out, "declare-fun"); |
197 |
|
} |
198 |
|
|
199 |
|
void Printer::toStreamCmdDeclarePool(std::ostream& out, |
200 |
|
const std::string& id, |
201 |
|
TypeNode type, |
202 |
|
const std::vector<Node>& initValue) const |
203 |
|
{ |
204 |
|
printUnknownCommand(out, "declare-pool"); |
205 |
|
} |
206 |
|
|
207 |
|
void Printer::toStreamCmdDeclareType(std::ostream& out, |
208 |
|
TypeNode type) const |
209 |
|
{ |
210 |
|
printUnknownCommand(out, "declare-sort"); |
211 |
|
} |
212 |
|
|
213 |
|
void Printer::toStreamCmdDefineType(std::ostream& out, |
214 |
|
const std::string& id, |
215 |
|
const std::vector<TypeNode>& params, |
216 |
|
TypeNode t) const |
217 |
|
{ |
218 |
|
printUnknownCommand(out, "define-sort"); |
219 |
|
} |
220 |
|
|
221 |
|
void Printer::toStreamCmdDefineFunction(std::ostream& out, |
222 |
|
const std::string& id, |
223 |
|
const std::vector<Node>& formals, |
224 |
|
TypeNode range, |
225 |
|
Node formula) const |
226 |
|
{ |
227 |
|
printUnknownCommand(out, "define-fun"); |
228 |
|
} |
229 |
|
|
230 |
|
void Printer::toStreamCmdDefineFunctionRec( |
231 |
|
std::ostream& out, |
232 |
|
const std::vector<Node>& funcs, |
233 |
|
const std::vector<std::vector<Node>>& formals, |
234 |
|
const std::vector<Node>& formulas) const |
235 |
|
{ |
236 |
|
printUnknownCommand(out, "define-fun-rec"); |
237 |
|
} |
238 |
|
|
239 |
|
void Printer::toStreamCmdSetUserAttribute(std::ostream& out, |
240 |
|
const std::string& attr, |
241 |
|
Node n) const |
242 |
|
{ |
243 |
|
printUnknownCommand(out, "set-user-attribute"); |
244 |
|
} |
245 |
|
|
246 |
|
void Printer::toStreamCmdCheckSat(std::ostream& out, Node n) const |
247 |
|
{ |
248 |
|
printUnknownCommand(out, "check-sat"); |
249 |
|
} |
250 |
|
|
251 |
|
void Printer::toStreamCmdCheckSatAssuming(std::ostream& out, |
252 |
|
const std::vector<Node>& nodes) const |
253 |
|
{ |
254 |
|
printUnknownCommand(out, "check-sat-assuming"); |
255 |
|
} |
256 |
|
|
257 |
|
void Printer::toStreamCmdQuery(std::ostream& out, Node n) const |
258 |
|
{ |
259 |
|
printUnknownCommand(out, "query"); |
260 |
|
} |
261 |
|
|
262 |
|
void Printer::toStreamCmdDeclareVar(std::ostream& out, |
263 |
|
Node var, |
264 |
|
TypeNode type) const |
265 |
|
{ |
266 |
|
printUnknownCommand(out, "declare-var"); |
267 |
|
} |
268 |
|
|
269 |
|
void Printer::toStreamCmdSynthFun(std::ostream& out, |
270 |
|
Node f, |
271 |
|
const std::vector<Node>& vars, |
272 |
|
bool isInv, |
273 |
|
TypeNode sygusType) const |
274 |
|
{ |
275 |
|
printUnknownCommand(out, isInv ? "synth-inv" : "synth-fun"); |
276 |
|
} |
277 |
|
|
278 |
|
void Printer::toStreamCmdConstraint(std::ostream& out, Node n) const |
279 |
|
{ |
280 |
|
printUnknownCommand(out, "constraint"); |
281 |
|
} |
282 |
|
|
283 |
|
void Printer::toStreamCmdInvConstraint( |
284 |
|
std::ostream& out, Node inv, Node pre, Node trans, Node post) const |
285 |
|
{ |
286 |
|
printUnknownCommand(out, "inv-constraint"); |
287 |
|
} |
288 |
|
|
289 |
|
void Printer::toStreamCmdCheckSynth(std::ostream& out) const |
290 |
|
{ |
291 |
|
printUnknownCommand(out, "check-synth"); |
292 |
|
} |
293 |
|
|
294 |
|
void Printer::toStreamCmdSimplify(std::ostream& out, Node n) const |
295 |
|
{ |
296 |
|
printUnknownCommand(out, "simplify"); |
297 |
|
} |
298 |
|
|
299 |
|
void Printer::toStreamCmdGetValue(std::ostream& out, |
300 |
|
const std::vector<Node>& nodes) const |
301 |
|
{ |
302 |
|
printUnknownCommand(out, "get-value"); |
303 |
|
} |
304 |
|
|
305 |
|
void Printer::toStreamCmdGetAssignment(std::ostream& out) const |
306 |
|
{ |
307 |
|
printUnknownCommand(out, "get-assignment"); |
308 |
|
} |
309 |
|
|
310 |
|
void Printer::toStreamCmdGetModel(std::ostream& out) const |
311 |
|
{ |
312 |
|
printUnknownCommand(out, "ge-model"); |
313 |
|
} |
314 |
|
|
315 |
|
void Printer::toStreamCmdBlockModel(std::ostream& out) const |
316 |
|
{ |
317 |
|
printUnknownCommand(out, "block-model"); |
318 |
|
} |
319 |
|
|
320 |
|
void Printer::toStreamCmdBlockModelValues(std::ostream& out, |
321 |
|
const std::vector<Node>& nodes) const |
322 |
|
{ |
323 |
|
printUnknownCommand(out, "block-model-values"); |
324 |
|
} |
325 |
|
|
326 |
|
void Printer::toStreamCmdGetProof(std::ostream& out) const |
327 |
|
{ |
328 |
|
printUnknownCommand(out, "get-proof"); |
329 |
|
} |
330 |
|
|
331 |
|
void Printer::toStreamCmdGetInstantiations(std::ostream& out) const |
332 |
|
{ |
333 |
|
printUnknownCommand(out, "get-instantiations"); |
334 |
|
} |
335 |
|
|
336 |
|
void Printer::toStreamCmdGetInterpol(std::ostream& out, |
337 |
|
const std::string& name, |
338 |
|
Node conj, |
339 |
|
TypeNode sygusType) const |
340 |
|
{ |
341 |
|
printUnknownCommand(out, "get-interpol"); |
342 |
|
} |
343 |
|
|
344 |
|
void Printer::toStreamCmdGetAbduct(std::ostream& out, |
345 |
|
const std::string& name, |
346 |
|
Node conj, |
347 |
|
TypeNode sygusType) const |
348 |
|
{ |
349 |
|
printUnknownCommand(out, "get-abduct"); |
350 |
|
} |
351 |
|
|
352 |
|
void Printer::toStreamCmdGetQuantifierElimination(std::ostream& out, |
353 |
|
Node n) const |
354 |
|
{ |
355 |
|
printUnknownCommand(out, "get-quantifier-elimination"); |
356 |
|
} |
357 |
|
|
358 |
|
void Printer::toStreamCmdGetUnsatAssumptions(std::ostream& out) const |
359 |
|
{ |
360 |
|
printUnknownCommand(out, "get-unsat-assumption"); |
361 |
|
} |
362 |
|
|
363 |
|
void Printer::toStreamCmdGetUnsatCore(std::ostream& out) const |
364 |
|
{ |
365 |
|
printUnknownCommand(out, "get-unsat-core"); |
366 |
|
} |
367 |
|
|
368 |
|
void Printer::toStreamCmdGetAssertions(std::ostream& out) const |
369 |
|
{ |
370 |
|
printUnknownCommand(out, "get-assertions"); |
371 |
|
} |
372 |
|
|
373 |
|
void Printer::toStreamCmdSetBenchmarkStatus(std::ostream& out, |
374 |
|
Result::Sat status) const |
375 |
|
{ |
376 |
|
printUnknownCommand(out, "set-info"); |
377 |
|
} |
378 |
|
|
379 |
|
void Printer::toStreamCmdSetBenchmarkLogic(std::ostream& out, |
380 |
|
const std::string& logic) const |
381 |
|
{ |
382 |
|
printUnknownCommand(out, "set-logic"); |
383 |
|
} |
384 |
|
|
385 |
|
void Printer::toStreamCmdSetInfo(std::ostream& out, |
386 |
|
const std::string& flag, |
387 |
|
const std::string& value) const |
388 |
|
{ |
389 |
|
printUnknownCommand(out, "set-info"); |
390 |
|
} |
391 |
|
|
392 |
|
void Printer::toStreamCmdGetInfo(std::ostream& out, |
393 |
|
const std::string& flag) const |
394 |
|
{ |
395 |
|
printUnknownCommand(out, "get-info"); |
396 |
|
} |
397 |
|
|
398 |
|
void Printer::toStreamCmdSetOption(std::ostream& out, |
399 |
|
const std::string& flag, |
400 |
|
const std::string& value) const |
401 |
|
{ |
402 |
|
printUnknownCommand(out, "set-option"); |
403 |
|
} |
404 |
|
|
405 |
|
void Printer::toStreamCmdGetOption(std::ostream& out, |
406 |
|
const std::string& flag) const |
407 |
|
{ |
408 |
|
printUnknownCommand(out, "get-option"); |
409 |
|
} |
410 |
|
|
411 |
|
void Printer::toStreamCmdSetExpressionName(std::ostream& out, |
412 |
|
Node n, |
413 |
|
const std::string& name) const |
414 |
|
{ |
415 |
|
printUnknownCommand(out, "set-expression-name"); |
416 |
|
} |
417 |
|
|
418 |
|
void Printer::toStreamCmdDatatypeDeclaration( |
419 |
|
std::ostream& out, const std::vector<TypeNode>& datatypes) const |
420 |
|
{ |
421 |
|
printUnknownCommand( |
422 |
|
out, datatypes.size() == 1 ? "declare-datatype" : "declare-datatypes"); |
423 |
|
} |
424 |
|
|
425 |
|
void Printer::toStreamCmdReset(std::ostream& out) const |
426 |
|
{ |
427 |
|
printUnknownCommand(out, "reset"); |
428 |
|
} |
429 |
|
|
430 |
|
void Printer::toStreamCmdResetAssertions(std::ostream& out) const |
431 |
|
{ |
432 |
|
printUnknownCommand(out, "reset-assertions"); |
433 |
|
} |
434 |
|
|
435 |
|
void Printer::toStreamCmdQuit(std::ostream& out) const |
436 |
|
{ |
437 |
|
printUnknownCommand(out, "quit"); |
438 |
|
} |
439 |
|
|
440 |
|
void Printer::toStreamCmdComment(std::ostream& out, |
441 |
|
const std::string& comment) const |
442 |
|
{ |
443 |
|
printUnknownCommand(out, "comment"); |
444 |
|
} |
445 |
|
|
446 |
|
void Printer::toStreamCmdDeclareHeap(std::ostream& out, |
447 |
|
TypeNode locType, |
448 |
|
TypeNode dataType) const |
449 |
|
{ |
450 |
|
printUnknownCommand(out, "declare-heap"); |
451 |
|
} |
452 |
|
|
453 |
|
void Printer::toStreamCmdCommandSequence( |
454 |
|
std::ostream& out, const std::vector<Command*>& sequence) const |
455 |
|
{ |
456 |
|
printUnknownCommand(out, "sequence"); |
457 |
|
} |
458 |
|
|
459 |
|
void Printer::toStreamCmdDeclarationSequence( |
460 |
|
std::ostream& out, const std::vector<Command*>& sequence) const |
461 |
|
{ |
462 |
|
printUnknownCommand(out, "sequence"); |
463 |
|
} |
464 |
|
|
465 |
995112 |
} // namespace cvc5 |