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