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 |
19560 |
unique_ptr<Printer> Printer::d_printers[language::output::LANG_MAX]; |
35 |
|
|
36 |
6556 |
unique_ptr<Printer> Printer::makePrinter(OutputLanguage lang) |
37 |
|
{ |
38 |
|
using namespace cvc5::language::output; |
39 |
|
|
40 |
6556 |
switch(lang) { |
41 |
5508 |
case LANG_SMTLIB_V2_6: |
42 |
|
return unique_ptr<Printer>( |
43 |
5508 |
new printer::smt2::Smt2Printer(printer::smt2::smt2_6_variant)); |
44 |
|
|
45 |
41 |
case LANG_TPTP: |
46 |
41 |
return unique_ptr<Printer>(new printer::tptp::TptpPrinter()); |
47 |
|
|
48 |
806 |
case LANG_CVC: return unique_ptr<Printer>(new printer::cvc::CvcPrinter()); |
49 |
|
|
50 |
197 |
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 |
197 |
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 InstantiationVec& i : is.d_inst) |
105 |
|
{ |
106 |
15 |
out << " "; |
107 |
15 |
if (i.d_id != theory::InferenceId::UNKNOWN) |
108 |
|
{ |
109 |
|
out << "(! "; |
110 |
|
} |
111 |
15 |
out << "( "; |
112 |
30 |
for (const Node& n : i.d_vec) |
113 |
|
{ |
114 |
15 |
out << n << " "; |
115 |
|
} |
116 |
15 |
out << ")"; |
117 |
15 |
if (i.d_id != theory::InferenceId::UNKNOWN) |
118 |
|
{ |
119 |
|
out << " :source " << i.d_id; |
120 |
|
if (!i.d_pfArg.isNull()) |
121 |
|
{ |
122 |
|
out << " " << i.d_pfArg; |
123 |
|
} |
124 |
|
out << ")"; |
125 |
|
} |
126 |
15 |
out << std::endl; |
127 |
|
} |
128 |
15 |
out << ")" << std::endl; |
129 |
15 |
} |
130 |
|
|
131 |
9 |
void Printer::toStream(std::ostream& out, const SkolemList& sks) const |
132 |
|
{ |
133 |
9 |
out << "(skolem " << sks.d_quant << std::endl; |
134 |
9 |
out << " ( "; |
135 |
18 |
for (const Node& n : sks.d_sks) |
136 |
|
{ |
137 |
9 |
out << n << " "; |
138 |
|
} |
139 |
9 |
out << ")" << std::endl; |
140 |
9 |
out << ")" << std::endl; |
141 |
9 |
} |
142 |
|
|
143 |
365568 |
Printer* Printer::getPrinter(OutputLanguage lang) |
144 |
|
{ |
145 |
365568 |
if (lang == language::output::LANG_AUTO) |
146 |
|
{ |
147 |
|
// Infer the language to use for output. |
148 |
|
// |
149 |
|
// Options can be null in certain circumstances (e.g., when printing |
150 |
|
// the singleton "null" expr. So we guard against segfault |
151 |
2326 |
if (not Options::isCurrentNull()) |
152 |
|
{ |
153 |
2316 |
if (Options::current().base.outputLanguageWasSetByUser) |
154 |
|
{ |
155 |
4 |
lang = options::outputLanguage(); |
156 |
|
} |
157 |
2316 |
if (lang == language::output::LANG_AUTO |
158 |
2316 |
&& Options::current().base.inputLanguageWasSetByUser) |
159 |
|
{ |
160 |
16 |
lang = language::toOutputLanguage(options::inputLanguage()); |
161 |
|
} |
162 |
|
} |
163 |
2326 |
if (lang == language::output::LANG_AUTO) |
164 |
|
{ |
165 |
2306 |
lang = language::output::LANG_SMTLIB_V2_6; // default |
166 |
|
} |
167 |
|
} |
168 |
365568 |
if (d_printers[lang] == nullptr) |
169 |
|
{ |
170 |
6556 |
d_printers[lang] = makePrinter(lang); |
171 |
|
} |
172 |
365568 |
return d_printers[lang].get(); |
173 |
|
} |
174 |
|
|
175 |
|
void Printer::printUnknownCommand(std::ostream& out, |
176 |
|
const std::string& name) const |
177 |
|
{ |
178 |
|
out << "ERROR: don't know how to print " << name << " command" << std::endl; |
179 |
|
} |
180 |
|
|
181 |
|
void Printer::toStreamCmdEmpty(std::ostream& out, const std::string& name) const |
182 |
|
{ |
183 |
|
printUnknownCommand(out, "empty"); |
184 |
|
} |
185 |
|
|
186 |
|
void Printer::toStreamCmdEcho(std::ostream& out, |
187 |
|
const std::string& output) const |
188 |
|
{ |
189 |
|
printUnknownCommand(out, "echo"); |
190 |
|
} |
191 |
|
|
192 |
|
void Printer::toStreamCmdAssert(std::ostream& out, Node n) const |
193 |
|
{ |
194 |
|
printUnknownCommand(out, "assert"); |
195 |
|
} |
196 |
|
|
197 |
|
void Printer::toStreamCmdPush(std::ostream& out) const |
198 |
|
{ |
199 |
|
printUnknownCommand(out, "push"); |
200 |
|
} |
201 |
|
|
202 |
|
void Printer::toStreamCmdPop(std::ostream& out) const |
203 |
|
{ |
204 |
|
printUnknownCommand(out, "pop"); |
205 |
|
} |
206 |
|
|
207 |
|
void Printer::toStreamCmdDeclareFunction(std::ostream& out, |
208 |
|
const std::string& id, |
209 |
|
TypeNode type) const |
210 |
|
{ |
211 |
|
printUnknownCommand(out, "declare-fun"); |
212 |
|
} |
213 |
|
|
214 |
|
void Printer::toStreamCmdDeclarePool(std::ostream& out, |
215 |
|
const std::string& id, |
216 |
|
TypeNode type, |
217 |
|
const std::vector<Node>& initValue) const |
218 |
|
{ |
219 |
|
printUnknownCommand(out, "declare-pool"); |
220 |
|
} |
221 |
|
|
222 |
|
void Printer::toStreamCmdDeclareType(std::ostream& out, |
223 |
|
TypeNode type) const |
224 |
|
{ |
225 |
|
printUnknownCommand(out, "declare-sort"); |
226 |
|
} |
227 |
|
|
228 |
|
void Printer::toStreamCmdDefineType(std::ostream& out, |
229 |
|
const std::string& id, |
230 |
|
const std::vector<TypeNode>& params, |
231 |
|
TypeNode t) const |
232 |
|
{ |
233 |
|
printUnknownCommand(out, "define-sort"); |
234 |
|
} |
235 |
|
|
236 |
|
void Printer::toStreamCmdDefineFunction(std::ostream& out, |
237 |
|
const std::string& id, |
238 |
|
const std::vector<Node>& formals, |
239 |
|
TypeNode range, |
240 |
|
Node formula) const |
241 |
|
{ |
242 |
|
printUnknownCommand(out, "define-fun"); |
243 |
|
} |
244 |
|
|
245 |
|
void Printer::toStreamCmdDefineFunctionRec( |
246 |
|
std::ostream& out, |
247 |
|
const std::vector<Node>& funcs, |
248 |
|
const std::vector<std::vector<Node>>& formals, |
249 |
|
const std::vector<Node>& formulas) const |
250 |
|
{ |
251 |
|
printUnknownCommand(out, "define-fun-rec"); |
252 |
|
} |
253 |
|
|
254 |
|
void Printer::toStreamCmdSetUserAttribute(std::ostream& out, |
255 |
|
const std::string& attr, |
256 |
|
Node n) const |
257 |
|
{ |
258 |
|
printUnknownCommand(out, "set-user-attribute"); |
259 |
|
} |
260 |
|
|
261 |
|
void Printer::toStreamCmdCheckSat(std::ostream& out, Node n) const |
262 |
|
{ |
263 |
|
printUnknownCommand(out, "check-sat"); |
264 |
|
} |
265 |
|
|
266 |
|
void Printer::toStreamCmdCheckSatAssuming(std::ostream& out, |
267 |
|
const std::vector<Node>& nodes) const |
268 |
|
{ |
269 |
|
printUnknownCommand(out, "check-sat-assuming"); |
270 |
|
} |
271 |
|
|
272 |
|
void Printer::toStreamCmdQuery(std::ostream& out, Node n) const |
273 |
|
{ |
274 |
|
printUnknownCommand(out, "query"); |
275 |
|
} |
276 |
|
|
277 |
|
void Printer::toStreamCmdDeclareVar(std::ostream& out, |
278 |
|
Node var, |
279 |
|
TypeNode type) const |
280 |
|
{ |
281 |
|
printUnknownCommand(out, "declare-var"); |
282 |
|
} |
283 |
|
|
284 |
|
void Printer::toStreamCmdSynthFun(std::ostream& out, |
285 |
|
Node f, |
286 |
|
const std::vector<Node>& vars, |
287 |
|
bool isInv, |
288 |
|
TypeNode sygusType) const |
289 |
|
{ |
290 |
|
printUnknownCommand(out, isInv ? "synth-inv" : "synth-fun"); |
291 |
|
} |
292 |
|
|
293 |
|
void Printer::toStreamCmdConstraint(std::ostream& out, Node n) const |
294 |
|
{ |
295 |
|
printUnknownCommand(out, "constraint"); |
296 |
|
} |
297 |
|
|
298 |
|
void Printer::toStreamCmdInvConstraint( |
299 |
|
std::ostream& out, Node inv, Node pre, Node trans, Node post) const |
300 |
|
{ |
301 |
|
printUnknownCommand(out, "inv-constraint"); |
302 |
|
} |
303 |
|
|
304 |
|
void Printer::toStreamCmdCheckSynth(std::ostream& out) const |
305 |
|
{ |
306 |
|
printUnknownCommand(out, "check-synth"); |
307 |
|
} |
308 |
|
|
309 |
|
void Printer::toStreamCmdSimplify(std::ostream& out, Node n) const |
310 |
|
{ |
311 |
|
printUnknownCommand(out, "simplify"); |
312 |
|
} |
313 |
|
|
314 |
|
void Printer::toStreamCmdGetValue(std::ostream& out, |
315 |
|
const std::vector<Node>& nodes) const |
316 |
|
{ |
317 |
|
printUnknownCommand(out, "get-value"); |
318 |
|
} |
319 |
|
|
320 |
|
void Printer::toStreamCmdGetAssignment(std::ostream& out) const |
321 |
|
{ |
322 |
|
printUnknownCommand(out, "get-assignment"); |
323 |
|
} |
324 |
|
|
325 |
|
void Printer::toStreamCmdGetModel(std::ostream& out) const |
326 |
|
{ |
327 |
|
printUnknownCommand(out, "ge-model"); |
328 |
|
} |
329 |
|
|
330 |
|
void Printer::toStreamCmdBlockModel(std::ostream& out) const |
331 |
|
{ |
332 |
|
printUnknownCommand(out, "block-model"); |
333 |
|
} |
334 |
|
|
335 |
|
void Printer::toStreamCmdBlockModelValues(std::ostream& out, |
336 |
|
const std::vector<Node>& nodes) const |
337 |
|
{ |
338 |
|
printUnknownCommand(out, "block-model-values"); |
339 |
|
} |
340 |
|
|
341 |
|
void Printer::toStreamCmdGetProof(std::ostream& out) const |
342 |
|
{ |
343 |
|
printUnknownCommand(out, "get-proof"); |
344 |
|
} |
345 |
|
|
346 |
|
void Printer::toStreamCmdGetInstantiations(std::ostream& out) const |
347 |
|
{ |
348 |
|
printUnknownCommand(out, "get-instantiations"); |
349 |
|
} |
350 |
|
|
351 |
|
void Printer::toStreamCmdGetInterpol(std::ostream& out, |
352 |
|
const std::string& name, |
353 |
|
Node conj, |
354 |
|
TypeNode sygusType) const |
355 |
|
{ |
356 |
|
printUnknownCommand(out, "get-interpol"); |
357 |
|
} |
358 |
|
|
359 |
|
void Printer::toStreamCmdGetAbduct(std::ostream& out, |
360 |
|
const std::string& name, |
361 |
|
Node conj, |
362 |
|
TypeNode sygusType) const |
363 |
|
{ |
364 |
|
printUnknownCommand(out, "get-abduct"); |
365 |
|
} |
366 |
|
|
367 |
|
void Printer::toStreamCmdGetQuantifierElimination(std::ostream& out, |
368 |
|
Node n) const |
369 |
|
{ |
370 |
|
printUnknownCommand(out, "get-quantifier-elimination"); |
371 |
|
} |
372 |
|
|
373 |
|
void Printer::toStreamCmdGetUnsatAssumptions(std::ostream& out) const |
374 |
|
{ |
375 |
|
printUnknownCommand(out, "get-unsat-assumption"); |
376 |
|
} |
377 |
|
|
378 |
|
void Printer::toStreamCmdGetUnsatCore(std::ostream& out) const |
379 |
|
{ |
380 |
|
printUnknownCommand(out, "get-unsat-core"); |
381 |
|
} |
382 |
|
|
383 |
|
void Printer::toStreamCmdGetAssertions(std::ostream& out) const |
384 |
|
{ |
385 |
|
printUnknownCommand(out, "get-assertions"); |
386 |
|
} |
387 |
|
|
388 |
|
void Printer::toStreamCmdSetBenchmarkStatus(std::ostream& out, |
389 |
|
Result::Sat status) const |
390 |
|
{ |
391 |
|
printUnknownCommand(out, "set-info"); |
392 |
|
} |
393 |
|
|
394 |
|
void Printer::toStreamCmdSetBenchmarkLogic(std::ostream& out, |
395 |
|
const std::string& logic) const |
396 |
|
{ |
397 |
|
printUnknownCommand(out, "set-logic"); |
398 |
|
} |
399 |
|
|
400 |
|
void Printer::toStreamCmdSetInfo(std::ostream& out, |
401 |
|
const std::string& flag, |
402 |
|
const std::string& value) const |
403 |
|
{ |
404 |
|
printUnknownCommand(out, "set-info"); |
405 |
|
} |
406 |
|
|
407 |
|
void Printer::toStreamCmdGetInfo(std::ostream& out, |
408 |
|
const std::string& flag) const |
409 |
|
{ |
410 |
|
printUnknownCommand(out, "get-info"); |
411 |
|
} |
412 |
|
|
413 |
|
void Printer::toStreamCmdSetOption(std::ostream& out, |
414 |
|
const std::string& flag, |
415 |
|
const std::string& value) const |
416 |
|
{ |
417 |
|
printUnknownCommand(out, "set-option"); |
418 |
|
} |
419 |
|
|
420 |
|
void Printer::toStreamCmdGetOption(std::ostream& out, |
421 |
|
const std::string& flag) const |
422 |
|
{ |
423 |
|
printUnknownCommand(out, "get-option"); |
424 |
|
} |
425 |
|
|
426 |
|
void Printer::toStreamCmdSetExpressionName(std::ostream& out, |
427 |
|
Node n, |
428 |
|
const std::string& name) const |
429 |
|
{ |
430 |
|
printUnknownCommand(out, "set-expression-name"); |
431 |
|
} |
432 |
|
|
433 |
|
void Printer::toStreamCmdDatatypeDeclaration( |
434 |
|
std::ostream& out, const std::vector<TypeNode>& datatypes) const |
435 |
|
{ |
436 |
|
printUnknownCommand( |
437 |
|
out, datatypes.size() == 1 ? "declare-datatype" : "declare-datatypes"); |
438 |
|
} |
439 |
|
|
440 |
|
void Printer::toStreamCmdReset(std::ostream& out) const |
441 |
|
{ |
442 |
|
printUnknownCommand(out, "reset"); |
443 |
|
} |
444 |
|
|
445 |
|
void Printer::toStreamCmdResetAssertions(std::ostream& out) const |
446 |
|
{ |
447 |
|
printUnknownCommand(out, "reset-assertions"); |
448 |
|
} |
449 |
|
|
450 |
|
void Printer::toStreamCmdQuit(std::ostream& out) const |
451 |
|
{ |
452 |
|
printUnknownCommand(out, "quit"); |
453 |
|
} |
454 |
|
|
455 |
|
void Printer::toStreamCmdComment(std::ostream& out, |
456 |
|
const std::string& comment) const |
457 |
|
{ |
458 |
|
printUnknownCommand(out, "comment"); |
459 |
|
} |
460 |
|
|
461 |
|
void Printer::toStreamCmdDeclareHeap(std::ostream& out, |
462 |
|
TypeNode locType, |
463 |
|
TypeNode dataType) const |
464 |
|
{ |
465 |
|
printUnknownCommand(out, "declare-heap"); |
466 |
|
} |
467 |
|
|
468 |
|
void Printer::toStreamCmdCommandSequence( |
469 |
|
std::ostream& out, const std::vector<Command*>& sequence) const |
470 |
|
{ |
471 |
|
printUnknownCommand(out, "sequence"); |
472 |
|
} |
473 |
|
|
474 |
|
void Printer::toStreamCmdDeclarationSequence( |
475 |
|
std::ostream& out, const std::vector<Command*>& sequence) const |
476 |
|
{ |
477 |
|
printUnknownCommand(out, "sequence"); |
478 |
|
} |
479 |
|
|
480 |
29340 |
} // namespace cvc5 |