1 |
|
/****************************************************************************** |
2 |
|
* Top contributors (to current version): |
3 |
|
* Tim King, Abdalrhman Mohamed, 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 |
|
* Implementation of command objects. |
14 |
|
*/ |
15 |
|
|
16 |
|
#include "smt/command.h" |
17 |
|
|
18 |
|
#include <exception> |
19 |
|
#include <iostream> |
20 |
|
#include <iterator> |
21 |
|
#include <sstream> |
22 |
|
#include <utility> |
23 |
|
#include <vector> |
24 |
|
|
25 |
|
#include "api/cpp/cvc5.h" |
26 |
|
#include "base/check.h" |
27 |
|
#include "base/modal_exception.h" |
28 |
|
#include "base/output.h" |
29 |
|
#include "expr/expr_iomanip.h" |
30 |
|
#include "expr/node.h" |
31 |
|
#include "expr/symbol_manager.h" |
32 |
|
#include "expr/type_node.h" |
33 |
|
#include "options/options.h" |
34 |
|
#include "options/main_options.h" |
35 |
|
#include "options/printer_options.h" |
36 |
|
#include "options/smt_options.h" |
37 |
|
#include "printer/printer.h" |
38 |
|
#include "proof/unsat_core.h" |
39 |
|
#include "smt/dump.h" |
40 |
|
#include "smt/model.h" |
41 |
|
#include "smt/smt_engine.h" |
42 |
|
#include "smt/smt_engine_scope.h" |
43 |
|
#include "util/unsafe_interrupt_exception.h" |
44 |
|
#include "util/utility.h" |
45 |
|
|
46 |
|
using namespace std; |
47 |
|
|
48 |
|
namespace cvc5 { |
49 |
|
|
50 |
12671 |
std::string sexprToString(api::Term sexpr) |
51 |
|
{ |
52 |
|
// if sexpr is a constant string, return the stored constant string. We don't |
53 |
|
// call Term::toString as its result depends on the output language. |
54 |
|
// Notice that we only check for string constants. The sexprs generated by the |
55 |
|
// parser don't contains other constants, so we can ignore them. |
56 |
12671 |
if (sexpr.isStringValue()) |
57 |
|
{ |
58 |
|
// convert std::wstring to std::string |
59 |
25308 |
std::wstring wstring = sexpr.getStringValue(); |
60 |
12654 |
return std::string(wstring.cbegin(), wstring.cend()); |
61 |
|
} |
62 |
|
|
63 |
|
// if sexpr is not a spec constant, make sure it is an array of sub-sexprs |
64 |
17 |
Assert(sexpr.getKind() == api::SEXPR); |
65 |
|
|
66 |
34 |
std::stringstream ss; |
67 |
34 |
auto it = sexpr.begin(); |
68 |
|
|
69 |
|
// recursively print the sub-sexprs |
70 |
17 |
ss << '(' << sexprToString(*it); |
71 |
17 |
++it; |
72 |
59 |
while (it != sexpr.end()) |
73 |
|
{ |
74 |
21 |
ss << ' ' << sexprToString(*it); |
75 |
21 |
++it; |
76 |
|
} |
77 |
17 |
ss << ')'; |
78 |
|
|
79 |
17 |
return ss.str(); |
80 |
|
} |
81 |
|
|
82 |
9774 |
const int CommandPrintSuccess::s_iosIndex = std::ios_base::xalloc(); |
83 |
9774 |
const CommandSuccess* CommandSuccess::s_instance = new CommandSuccess(); |
84 |
9774 |
const CommandInterrupted* CommandInterrupted::s_instance = |
85 |
9774 |
new CommandInterrupted(); |
86 |
|
|
87 |
22 |
std::ostream& operator<<(std::ostream& out, const Command& c) |
88 |
|
{ |
89 |
44 |
c.toStream(out, |
90 |
22 |
Node::setdepth::getDepth(out), |
91 |
|
Node::dag::getDag(out), |
92 |
22 |
Node::setlanguage::getLanguage(out)); |
93 |
22 |
return out; |
94 |
|
} |
95 |
|
|
96 |
11 |
ostream& operator<<(ostream& out, const Command* c) |
97 |
|
{ |
98 |
11 |
if (c == NULL) |
99 |
|
{ |
100 |
|
out << "null"; |
101 |
|
} |
102 |
|
else |
103 |
|
{ |
104 |
11 |
out << *c; |
105 |
|
} |
106 |
11 |
return out; |
107 |
|
} |
108 |
|
|
109 |
281812 |
std::ostream& operator<<(std::ostream& out, const CommandStatus& s) |
110 |
|
{ |
111 |
281812 |
s.toStream(out, Node::setlanguage::getLanguage(out)); |
112 |
281812 |
return out; |
113 |
|
} |
114 |
|
|
115 |
|
ostream& operator<<(ostream& out, const CommandStatus* s) |
116 |
|
{ |
117 |
|
if (s == NULL) |
118 |
|
{ |
119 |
|
out << "null"; |
120 |
|
} |
121 |
|
else |
122 |
|
{ |
123 |
|
out << *s; |
124 |
|
} |
125 |
|
return out; |
126 |
|
} |
127 |
|
|
128 |
|
/* output stream insertion operator for benchmark statuses */ |
129 |
|
std::ostream& operator<<(std::ostream& out, BenchmarkStatus status) |
130 |
|
{ |
131 |
|
switch (status) |
132 |
|
{ |
133 |
|
case SMT_SATISFIABLE: return out << "sat"; |
134 |
|
|
135 |
|
case SMT_UNSATISFIABLE: return out << "unsat"; |
136 |
|
|
137 |
|
case SMT_UNKNOWN: return out << "unknown"; |
138 |
|
|
139 |
|
default: return out << "BenchmarkStatus::[UNKNOWNSTATUS!]"; |
140 |
|
} |
141 |
|
} |
142 |
|
|
143 |
|
/* -------------------------------------------------------------------------- */ |
144 |
|
/* class CommandPrintSuccess */ |
145 |
|
/* -------------------------------------------------------------------------- */ |
146 |
|
|
147 |
142 |
void CommandPrintSuccess::applyPrintSuccess(std::ostream& out) |
148 |
|
{ |
149 |
142 |
out.iword(s_iosIndex) = d_printSuccess; |
150 |
142 |
} |
151 |
|
|
152 |
281755 |
bool CommandPrintSuccess::getPrintSuccess(std::ostream& out) |
153 |
|
{ |
154 |
281755 |
return out.iword(s_iosIndex); |
155 |
|
} |
156 |
|
|
157 |
|
void CommandPrintSuccess::setPrintSuccess(std::ostream& out, bool printSuccess) |
158 |
|
{ |
159 |
|
out.iword(s_iosIndex) = printSuccess; |
160 |
|
} |
161 |
|
|
162 |
142 |
std::ostream& operator<<(std::ostream& out, CommandPrintSuccess cps) |
163 |
|
{ |
164 |
142 |
cps.applyPrintSuccess(out); |
165 |
142 |
return out; |
166 |
|
} |
167 |
|
|
168 |
|
/* -------------------------------------------------------------------------- */ |
169 |
|
/* class Command */ |
170 |
|
/* -------------------------------------------------------------------------- */ |
171 |
|
|
172 |
304381 |
Command::Command() : d_commandStatus(nullptr), d_muted(false) {} |
173 |
|
|
174 |
|
Command::Command(const Command& cmd) |
175 |
|
{ |
176 |
|
d_commandStatus = |
177 |
|
(cmd.d_commandStatus == NULL) ? NULL : &cmd.d_commandStatus->clone(); |
178 |
|
d_muted = cmd.d_muted; |
179 |
|
} |
180 |
|
|
181 |
608762 |
Command::~Command() |
182 |
|
{ |
183 |
304381 |
if (d_commandStatus != NULL && d_commandStatus != CommandSuccess::instance()) |
184 |
|
{ |
185 |
57 |
delete d_commandStatus; |
186 |
|
} |
187 |
304381 |
} |
188 |
|
|
189 |
298883 |
bool Command::ok() const |
190 |
|
{ |
191 |
|
// either we haven't run the command yet, or it ran successfully |
192 |
298883 |
return d_commandStatus == NULL |
193 |
298883 |
|| dynamic_cast<const CommandSuccess*>(d_commandStatus) != NULL; |
194 |
|
} |
195 |
|
|
196 |
298908 |
bool Command::fail() const |
197 |
|
{ |
198 |
298908 |
return d_commandStatus != NULL |
199 |
298908 |
&& dynamic_cast<const CommandFailure*>(d_commandStatus) != NULL; |
200 |
|
} |
201 |
|
|
202 |
290608 |
bool Command::interrupted() const |
203 |
|
{ |
204 |
290608 |
return d_commandStatus != NULL |
205 |
290608 |
&& dynamic_cast<const CommandInterrupted*>(d_commandStatus) != NULL; |
206 |
|
} |
207 |
|
|
208 |
298910 |
void Command::invoke(api::Solver* solver, SymbolManager* sm, std::ostream& out) |
209 |
|
{ |
210 |
298910 |
invoke(solver, sm); |
211 |
298910 |
if (!(isMuted() && ok())) |
212 |
|
{ |
213 |
293071 |
printResult( |
214 |
|
out, |
215 |
586142 |
std::stoul(solver->getOption("command-verbosity:" + getCommandName()))); |
216 |
|
} |
217 |
298910 |
} |
218 |
|
|
219 |
|
std::string Command::toString() const |
220 |
|
{ |
221 |
|
std::stringstream ss; |
222 |
|
toStream(ss); |
223 |
|
return ss.str(); |
224 |
|
} |
225 |
|
|
226 |
283785 |
void CommandStatus::toStream(std::ostream& out, OutputLanguage language) const |
227 |
|
{ |
228 |
283785 |
Printer::getPrinter(language)->toStream(out, this); |
229 |
283785 |
} |
230 |
|
|
231 |
281908 |
void Command::printResult(std::ostream& out, uint32_t verbosity) const |
232 |
|
{ |
233 |
281908 |
if (d_commandStatus != NULL) |
234 |
|
{ |
235 |
281821 |
if ((!ok() && verbosity >= 1) || verbosity >= 2) |
236 |
|
{ |
237 |
281812 |
out << *d_commandStatus; |
238 |
|
} |
239 |
|
} |
240 |
281908 |
} |
241 |
|
|
242 |
49 |
void Command::resetSolver(api::Solver* solver) |
243 |
|
{ |
244 |
98 |
std::unique_ptr<Options> opts = std::make_unique<Options>(); |
245 |
49 |
opts->copyValues(*solver->d_originalOptions); |
246 |
|
// This reconstructs a new solver object at the same memory location as the |
247 |
|
// current one. Note that this command does not own the solver object! |
248 |
|
// It may be safer to instead make the ResetCommand a special case in the |
249 |
|
// CommandExecutor such that this reconstruction can be done within the |
250 |
|
// CommandExecutor, who actually owns the solver. |
251 |
49 |
solver->~Solver(); |
252 |
49 |
new (solver) api::Solver(opts.get()); |
253 |
49 |
} |
254 |
|
|
255 |
256 |
Node Command::termToNode(const api::Term& term) { return term.getNode(); } |
256 |
|
|
257 |
220 |
std::vector<Node> Command::termVectorToNodes( |
258 |
|
const std::vector<api::Term>& terms) |
259 |
|
{ |
260 |
220 |
return api::Term::termVectorToNodes(terms); |
261 |
|
} |
262 |
|
|
263 |
10 |
TypeNode Command::sortToTypeNode(const api::Sort& sort) |
264 |
|
{ |
265 |
10 |
return sort.getTypeNode(); |
266 |
|
} |
267 |
|
|
268 |
|
std::vector<TypeNode> Command::sortVectorToTypeNodes( |
269 |
|
const std::vector<api::Sort>& sorts) |
270 |
|
{ |
271 |
|
return api::Sort::sortVectorToTypeNodes(sorts); |
272 |
|
} |
273 |
|
|
274 |
1 |
TypeNode Command::grammarToTypeNode(api::Grammar* grammar) |
275 |
|
{ |
276 |
|
return grammar == nullptr ? TypeNode::null() |
277 |
1 |
: sortToTypeNode(grammar->resolve()); |
278 |
|
} |
279 |
|
|
280 |
|
Options& Command::getOriginalOptionsFrom(api::Solver* s) |
281 |
|
{ |
282 |
|
return *s->d_originalOptions.get(); |
283 |
|
} |
284 |
|
|
285 |
|
/* -------------------------------------------------------------------------- */ |
286 |
|
/* class EmptyCommand */ |
287 |
|
/* -------------------------------------------------------------------------- */ |
288 |
|
|
289 |
440 |
EmptyCommand::EmptyCommand(std::string name) : d_name(name) {} |
290 |
|
std::string EmptyCommand::getName() const { return d_name; } |
291 |
434 |
void EmptyCommand::invoke(api::Solver* solver, SymbolManager* sm) |
292 |
|
{ |
293 |
|
/* empty commands have no implementation */ |
294 |
434 |
d_commandStatus = CommandSuccess::instance(); |
295 |
434 |
} |
296 |
|
|
297 |
|
Command* EmptyCommand::clone() const { return new EmptyCommand(d_name); } |
298 |
868 |
std::string EmptyCommand::getCommandName() const { return "empty"; } |
299 |
|
|
300 |
|
void EmptyCommand::toStream(std::ostream& out, |
301 |
|
int toDepth, |
302 |
|
size_t dag, |
303 |
|
OutputLanguage language) const |
304 |
|
{ |
305 |
|
Printer::getPrinter(language)->toStreamCmdEmpty(out, d_name); |
306 |
|
} |
307 |
|
|
308 |
|
/* -------------------------------------------------------------------------- */ |
309 |
|
/* class EchoCommand */ |
310 |
|
/* -------------------------------------------------------------------------- */ |
311 |
|
|
312 |
9 |
EchoCommand::EchoCommand(std::string output) |
313 |
|
{ |
314 |
|
// escape all double-quotes |
315 |
9 |
size_t pos = 0; |
316 |
21 |
while ((pos = output.find('"', pos)) != string::npos) |
317 |
|
{ |
318 |
6 |
output.replace(pos, 1, "\"\""); |
319 |
6 |
pos += 2; |
320 |
|
} |
321 |
9 |
d_output = '"' + output + '"'; |
322 |
9 |
} |
323 |
|
|
324 |
|
std::string EchoCommand::getOutput() const { return d_output; } |
325 |
|
void EchoCommand::invoke(api::Solver* solver, SymbolManager* sm) |
326 |
|
{ |
327 |
|
/* we don't have an output stream here, nothing to do */ |
328 |
|
d_commandStatus = CommandSuccess::instance(); |
329 |
|
} |
330 |
|
|
331 |
9 |
void EchoCommand::invoke(api::Solver* solver, |
332 |
|
SymbolManager* sm, |
333 |
|
std::ostream& out) |
334 |
|
{ |
335 |
9 |
out << d_output << std::endl; |
336 |
18 |
Trace("dtview::command") << "* ~COMMAND: echo |" << d_output << "|~" |
337 |
9 |
<< std::endl; |
338 |
9 |
d_commandStatus = CommandSuccess::instance(); |
339 |
18 |
printResult( |
340 |
|
out, |
341 |
18 |
std::stoul(solver->getOption("command-verbosity:" + getCommandName()))); |
342 |
9 |
} |
343 |
|
|
344 |
|
Command* EchoCommand::clone() const { return new EchoCommand(d_output); } |
345 |
18 |
std::string EchoCommand::getCommandName() const { return "echo"; } |
346 |
|
|
347 |
|
void EchoCommand::toStream(std::ostream& out, |
348 |
|
int toDepth, |
349 |
|
size_t dag, |
350 |
|
OutputLanguage language) const |
351 |
|
{ |
352 |
|
Printer::getPrinter(language)->toStreamCmdEcho(out, d_output); |
353 |
|
} |
354 |
|
|
355 |
|
/* -------------------------------------------------------------------------- */ |
356 |
|
/* class AssertCommand */ |
357 |
|
/* -------------------------------------------------------------------------- */ |
358 |
|
|
359 |
79975 |
AssertCommand::AssertCommand(const api::Term& t) : d_term(t) {} |
360 |
|
|
361 |
|
api::Term AssertCommand::getTerm() const { return d_term; } |
362 |
79925 |
void AssertCommand::invoke(api::Solver* solver, SymbolManager* sm) |
363 |
|
{ |
364 |
|
try |
365 |
|
{ |
366 |
79925 |
solver->assertFormula(d_term); |
367 |
79924 |
d_commandStatus = CommandSuccess::instance(); |
368 |
|
} |
369 |
|
catch (UnsafeInterruptException& e) |
370 |
|
{ |
371 |
|
d_commandStatus = new CommandInterrupted(); |
372 |
|
} |
373 |
2 |
catch (exception& e) |
374 |
|
{ |
375 |
1 |
d_commandStatus = new CommandFailure(e.what()); |
376 |
|
} |
377 |
79925 |
} |
378 |
|
|
379 |
|
Command* AssertCommand::clone() const { return new AssertCommand(d_term); } |
380 |
|
|
381 |
159850 |
std::string AssertCommand::getCommandName() const { return "assert"; } |
382 |
|
|
383 |
|
void AssertCommand::toStream(std::ostream& out, |
384 |
|
int toDepth, |
385 |
|
size_t dag, |
386 |
|
OutputLanguage language) const |
387 |
|
{ |
388 |
|
Printer::getPrinter(language)->toStreamCmdAssert(out, termToNode(d_term)); |
389 |
|
} |
390 |
|
|
391 |
|
/* -------------------------------------------------------------------------- */ |
392 |
|
/* class PushCommand */ |
393 |
|
/* -------------------------------------------------------------------------- */ |
394 |
|
|
395 |
3342 |
void PushCommand::invoke(api::Solver* solver, SymbolManager* sm) |
396 |
|
{ |
397 |
|
try |
398 |
|
{ |
399 |
3342 |
solver->push(); |
400 |
3342 |
d_commandStatus = CommandSuccess::instance(); |
401 |
|
} |
402 |
|
catch (UnsafeInterruptException& e) |
403 |
|
{ |
404 |
|
d_commandStatus = new CommandInterrupted(); |
405 |
|
} |
406 |
|
catch (exception& e) |
407 |
|
{ |
408 |
|
d_commandStatus = new CommandFailure(e.what()); |
409 |
|
} |
410 |
3342 |
} |
411 |
|
|
412 |
|
Command* PushCommand::clone() const { return new PushCommand(); } |
413 |
6674 |
std::string PushCommand::getCommandName() const { return "push"; } |
414 |
|
|
415 |
|
void PushCommand::toStream(std::ostream& out, |
416 |
|
int toDepth, |
417 |
|
size_t dag, |
418 |
|
OutputLanguage language) const |
419 |
|
{ |
420 |
|
Printer::getPrinter(language)->toStreamCmdPush(out); |
421 |
|
} |
422 |
|
|
423 |
|
/* -------------------------------------------------------------------------- */ |
424 |
|
/* class PopCommand */ |
425 |
|
/* -------------------------------------------------------------------------- */ |
426 |
|
|
427 |
2815 |
void PopCommand::invoke(api::Solver* solver, SymbolManager* sm) |
428 |
|
{ |
429 |
|
try |
430 |
|
{ |
431 |
2815 |
solver->pop(); |
432 |
2815 |
d_commandStatus = CommandSuccess::instance(); |
433 |
|
} |
434 |
|
catch (UnsafeInterruptException& e) |
435 |
|
{ |
436 |
|
d_commandStatus = new CommandInterrupted(); |
437 |
|
} |
438 |
|
catch (exception& e) |
439 |
|
{ |
440 |
|
d_commandStatus = new CommandFailure(e.what()); |
441 |
|
} |
442 |
2815 |
} |
443 |
|
|
444 |
|
Command* PopCommand::clone() const { return new PopCommand(); } |
445 |
5474 |
std::string PopCommand::getCommandName() const { return "pop"; } |
446 |
|
|
447 |
|
void PopCommand::toStream(std::ostream& out, |
448 |
|
int toDepth, |
449 |
|
size_t dag, |
450 |
|
OutputLanguage language) const |
451 |
|
{ |
452 |
|
Printer::getPrinter(language)->toStreamCmdPop(out); |
453 |
|
} |
454 |
|
|
455 |
|
/* -------------------------------------------------------------------------- */ |
456 |
|
/* class CheckSatCommand */ |
457 |
|
/* -------------------------------------------------------------------------- */ |
458 |
|
|
459 |
475 |
CheckSatCommand::CheckSatCommand() : d_term() {} |
460 |
|
|
461 |
8740 |
CheckSatCommand::CheckSatCommand(const api::Term& term) : d_term(term) {} |
462 |
|
|
463 |
|
api::Term CheckSatCommand::getTerm() const { return d_term; } |
464 |
9197 |
void CheckSatCommand::invoke(api::Solver* solver, SymbolManager* sm) |
465 |
|
{ |
466 |
18394 |
Trace("dtview::command") << "* ~COMMAND: " << getCommandName() << "~" |
467 |
9197 |
<< std::endl; |
468 |
|
try |
469 |
|
{ |
470 |
9180 |
d_result = |
471 |
18377 |
d_term.isNull() ? solver->checkSat() : solver->checkSatAssuming(d_term); |
472 |
|
|
473 |
9180 |
d_commandStatus = CommandSuccess::instance(); |
474 |
|
} |
475 |
34 |
catch (exception& e) |
476 |
|
{ |
477 |
17 |
d_commandStatus = new CommandFailure(e.what()); |
478 |
|
} |
479 |
9197 |
} |
480 |
|
|
481 |
9197 |
api::Result CheckSatCommand::getResult() const { return d_result; } |
482 |
9197 |
void CheckSatCommand::printResult(std::ostream& out, uint32_t verbosity) const |
483 |
|
{ |
484 |
9197 |
if (!ok()) |
485 |
|
{ |
486 |
17 |
this->Command::printResult(out, verbosity); |
487 |
|
} |
488 |
|
else |
489 |
|
{ |
490 |
9180 |
Trace("dtview::command") << "* RESULT: " << d_result << std::endl; |
491 |
9180 |
out << d_result << endl; |
492 |
|
} |
493 |
9197 |
} |
494 |
|
|
495 |
|
Command* CheckSatCommand::clone() const |
496 |
|
{ |
497 |
|
CheckSatCommand* c = new CheckSatCommand(d_term); |
498 |
|
c->d_result = d_result; |
499 |
|
return c; |
500 |
|
} |
501 |
|
|
502 |
27591 |
std::string CheckSatCommand::getCommandName() const { return "check-sat"; } |
503 |
|
|
504 |
|
void CheckSatCommand::toStream(std::ostream& out, |
505 |
|
int toDepth, |
506 |
|
size_t dag, |
507 |
|
OutputLanguage language) const |
508 |
|
{ |
509 |
|
Printer::getPrinter(language)->toStreamCmdCheckSat(out, termToNode(d_term)); |
510 |
|
} |
511 |
|
|
512 |
|
/* -------------------------------------------------------------------------- */ |
513 |
|
/* class CheckSatAssumingCommand */ |
514 |
|
/* -------------------------------------------------------------------------- */ |
515 |
|
|
516 |
|
CheckSatAssumingCommand::CheckSatAssumingCommand(api::Term term) |
517 |
|
: d_terms({term}) |
518 |
|
{ |
519 |
|
} |
520 |
|
|
521 |
992 |
CheckSatAssumingCommand::CheckSatAssumingCommand( |
522 |
992 |
const std::vector<api::Term>& terms) |
523 |
992 |
: d_terms(terms) |
524 |
|
{ |
525 |
992 |
} |
526 |
|
|
527 |
|
const std::vector<api::Term>& CheckSatAssumingCommand::getTerms() const |
528 |
|
{ |
529 |
|
return d_terms; |
530 |
|
} |
531 |
|
|
532 |
992 |
void CheckSatAssumingCommand::invoke(api::Solver* solver, SymbolManager* sm) |
533 |
|
{ |
534 |
1984 |
Trace("dtview::command") << "* ~COMMAND: (check-sat-assuming ( " << d_terms |
535 |
992 |
<< " )~" << std::endl; |
536 |
|
try |
537 |
|
{ |
538 |
992 |
d_result = solver->checkSatAssuming(d_terms); |
539 |
992 |
d_commandStatus = CommandSuccess::instance(); |
540 |
|
} |
541 |
|
catch (exception& e) |
542 |
|
{ |
543 |
|
d_commandStatus = new CommandFailure(e.what()); |
544 |
|
} |
545 |
992 |
} |
546 |
|
|
547 |
992 |
api::Result CheckSatAssumingCommand::getResult() const |
548 |
|
{ |
549 |
992 |
Trace("dtview::command") << "* ~RESULT: " << d_result << "~" << std::endl; |
550 |
992 |
return d_result; |
551 |
|
} |
552 |
|
|
553 |
992 |
void CheckSatAssumingCommand::printResult(std::ostream& out, |
554 |
|
uint32_t verbosity) const |
555 |
|
{ |
556 |
992 |
if (!ok()) |
557 |
|
{ |
558 |
|
this->Command::printResult(out, verbosity); |
559 |
|
} |
560 |
|
else |
561 |
|
{ |
562 |
992 |
out << d_result << endl; |
563 |
|
} |
564 |
992 |
} |
565 |
|
|
566 |
|
Command* CheckSatAssumingCommand::clone() const |
567 |
|
{ |
568 |
|
CheckSatAssumingCommand* c = new CheckSatAssumingCommand(d_terms); |
569 |
|
c->d_result = d_result; |
570 |
|
return c; |
571 |
|
} |
572 |
|
|
573 |
1984 |
std::string CheckSatAssumingCommand::getCommandName() const |
574 |
|
{ |
575 |
1984 |
return "check-sat-assuming"; |
576 |
|
} |
577 |
|
|
578 |
|
void CheckSatAssumingCommand::toStream(std::ostream& out, |
579 |
|
int toDepth, |
580 |
|
size_t dag, |
581 |
|
OutputLanguage language) const |
582 |
|
{ |
583 |
|
Printer::getPrinter(language)->toStreamCmdCheckSatAssuming( |
584 |
|
out, termVectorToNodes(d_terms)); |
585 |
|
} |
586 |
|
|
587 |
|
/* -------------------------------------------------------------------------- */ |
588 |
|
/* class QueryCommand */ |
589 |
|
/* -------------------------------------------------------------------------- */ |
590 |
|
|
591 |
616 |
QueryCommand::QueryCommand(const api::Term& t) : d_term(t) {} |
592 |
|
|
593 |
|
api::Term QueryCommand::getTerm() const { return d_term; } |
594 |
608 |
void QueryCommand::invoke(api::Solver* solver, SymbolManager* sm) |
595 |
|
{ |
596 |
|
try |
597 |
|
{ |
598 |
608 |
d_result = solver->checkEntailed(d_term); |
599 |
604 |
d_commandStatus = CommandSuccess::instance(); |
600 |
|
} |
601 |
8 |
catch (exception& e) |
602 |
|
{ |
603 |
4 |
d_commandStatus = new CommandFailure(e.what()); |
604 |
|
} |
605 |
608 |
} |
606 |
|
|
607 |
608 |
api::Result QueryCommand::getResult() const { return d_result; } |
608 |
608 |
void QueryCommand::printResult(std::ostream& out, uint32_t verbosity) const |
609 |
|
{ |
610 |
608 |
if (!ok()) |
611 |
|
{ |
612 |
4 |
this->Command::printResult(out, verbosity); |
613 |
|
} |
614 |
|
else |
615 |
|
{ |
616 |
604 |
out << d_result << endl; |
617 |
|
} |
618 |
608 |
} |
619 |
|
|
620 |
|
Command* QueryCommand::clone() const |
621 |
|
{ |
622 |
|
QueryCommand* c = new QueryCommand(d_term); |
623 |
|
c->d_result = d_result; |
624 |
|
return c; |
625 |
|
} |
626 |
|
|
627 |
1216 |
std::string QueryCommand::getCommandName() const { return "query"; } |
628 |
|
|
629 |
|
void QueryCommand::toStream(std::ostream& out, |
630 |
|
int toDepth, |
631 |
|
size_t dag, |
632 |
|
OutputLanguage language) const |
633 |
|
{ |
634 |
|
Printer::getPrinter(language)->toStreamCmdQuery(out, termToNode(d_term)); |
635 |
|
} |
636 |
|
|
637 |
|
/* -------------------------------------------------------------------------- */ |
638 |
|
/* class DeclareSygusVarCommand */ |
639 |
|
/* -------------------------------------------------------------------------- */ |
640 |
|
|
641 |
302 |
DeclareSygusVarCommand::DeclareSygusVarCommand(const std::string& id, |
642 |
|
api::Term var, |
643 |
302 |
api::Sort sort) |
644 |
302 |
: DeclarationDefinitionCommand(id), d_var(var), d_sort(sort) |
645 |
|
{ |
646 |
302 |
} |
647 |
|
|
648 |
|
api::Term DeclareSygusVarCommand::getVar() const { return d_var; } |
649 |
|
api::Sort DeclareSygusVarCommand::getSort() const { return d_sort; } |
650 |
|
|
651 |
302 |
void DeclareSygusVarCommand::invoke(api::Solver* solver, SymbolManager* sm) |
652 |
|
{ |
653 |
302 |
d_commandStatus = CommandSuccess::instance(); |
654 |
302 |
} |
655 |
|
|
656 |
|
Command* DeclareSygusVarCommand::clone() const |
657 |
|
{ |
658 |
|
return new DeclareSygusVarCommand(d_symbol, d_var, d_sort); |
659 |
|
} |
660 |
|
|
661 |
604 |
std::string DeclareSygusVarCommand::getCommandName() const |
662 |
|
{ |
663 |
604 |
return "declare-var"; |
664 |
|
} |
665 |
|
|
666 |
1 |
void DeclareSygusVarCommand::toStream(std::ostream& out, |
667 |
|
int toDepth, |
668 |
|
size_t dag, |
669 |
|
OutputLanguage language) const |
670 |
|
{ |
671 |
2 |
Printer::getPrinter(language)->toStreamCmdDeclareVar( |
672 |
2 |
out, termToNode(d_var), sortToTypeNode(d_sort)); |
673 |
1 |
} |
674 |
|
|
675 |
|
/* -------------------------------------------------------------------------- */ |
676 |
|
/* class SynthFunCommand */ |
677 |
|
/* -------------------------------------------------------------------------- */ |
678 |
|
|
679 |
285 |
SynthFunCommand::SynthFunCommand(const std::string& id, |
680 |
|
api::Term fun, |
681 |
|
const std::vector<api::Term>& vars, |
682 |
|
api::Sort sort, |
683 |
|
bool isInv, |
684 |
285 |
api::Grammar* g) |
685 |
|
: DeclarationDefinitionCommand(id), |
686 |
|
d_fun(fun), |
687 |
|
d_vars(vars), |
688 |
|
d_sort(sort), |
689 |
|
d_isInv(isInv), |
690 |
285 |
d_grammar(g) |
691 |
|
{ |
692 |
285 |
} |
693 |
|
|
694 |
|
api::Term SynthFunCommand::getFunction() const { return d_fun; } |
695 |
|
|
696 |
|
const std::vector<api::Term>& SynthFunCommand::getVars() const |
697 |
|
{ |
698 |
|
return d_vars; |
699 |
|
} |
700 |
|
|
701 |
|
api::Sort SynthFunCommand::getSort() const { return d_sort; } |
702 |
|
bool SynthFunCommand::isInv() const { return d_isInv; } |
703 |
|
|
704 |
|
const api::Grammar* SynthFunCommand::getGrammar() const { return d_grammar; } |
705 |
|
|
706 |
285 |
void SynthFunCommand::invoke(api::Solver* solver, SymbolManager* sm) |
707 |
|
{ |
708 |
285 |
sm->addFunctionToSynthesize(d_fun); |
709 |
285 |
d_commandStatus = CommandSuccess::instance(); |
710 |
285 |
} |
711 |
|
|
712 |
|
Command* SynthFunCommand::clone() const |
713 |
|
{ |
714 |
|
return new SynthFunCommand( |
715 |
|
d_symbol, d_fun, d_vars, d_sort, d_isInv, d_grammar); |
716 |
|
} |
717 |
|
|
718 |
570 |
std::string SynthFunCommand::getCommandName() const |
719 |
|
{ |
720 |
570 |
return d_isInv ? "synth-inv" : "synth-fun"; |
721 |
|
} |
722 |
|
|
723 |
2 |
void SynthFunCommand::toStream(std::ostream& out, |
724 |
|
int toDepth, |
725 |
|
size_t dag, |
726 |
|
OutputLanguage language) const |
727 |
|
{ |
728 |
4 |
std::vector<Node> nodeVars = termVectorToNodes(d_vars); |
729 |
6 |
Printer::getPrinter(language)->toStreamCmdSynthFun( |
730 |
|
out, |
731 |
4 |
termToNode(d_fun), |
732 |
|
nodeVars, |
733 |
2 |
d_isInv, |
734 |
4 |
d_grammar == nullptr ? TypeNode::null() : grammarToTypeNode(d_grammar)); |
735 |
2 |
} |
736 |
|
|
737 |
|
/* -------------------------------------------------------------------------- */ |
738 |
|
/* class SygusConstraintCommand */ |
739 |
|
/* -------------------------------------------------------------------------- */ |
740 |
|
|
741 |
604 |
SygusConstraintCommand::SygusConstraintCommand(const api::Term& t) : d_term(t) |
742 |
|
{ |
743 |
604 |
} |
744 |
|
|
745 |
604 |
void SygusConstraintCommand::invoke(api::Solver* solver, SymbolManager* sm) |
746 |
|
{ |
747 |
|
try |
748 |
|
{ |
749 |
604 |
solver->addSygusConstraint(d_term); |
750 |
604 |
d_commandStatus = CommandSuccess::instance(); |
751 |
|
} |
752 |
|
catch (exception& e) |
753 |
|
{ |
754 |
|
d_commandStatus = new CommandFailure(e.what()); |
755 |
|
} |
756 |
604 |
} |
757 |
|
|
758 |
|
api::Term SygusConstraintCommand::getTerm() const { return d_term; } |
759 |
|
|
760 |
|
Command* SygusConstraintCommand::clone() const |
761 |
|
{ |
762 |
|
return new SygusConstraintCommand(d_term); |
763 |
|
} |
764 |
|
|
765 |
1208 |
std::string SygusConstraintCommand::getCommandName() const |
766 |
|
{ |
767 |
1208 |
return "constraint"; |
768 |
|
} |
769 |
|
|
770 |
1 |
void SygusConstraintCommand::toStream(std::ostream& out, |
771 |
|
int toDepth, |
772 |
|
size_t dag, |
773 |
|
OutputLanguage language) const |
774 |
|
{ |
775 |
1 |
Printer::getPrinter(language)->toStreamCmdConstraint(out, termToNode(d_term)); |
776 |
1 |
} |
777 |
|
|
778 |
|
/* -------------------------------------------------------------------------- */ |
779 |
|
/* class SygusInvConstraintCommand */ |
780 |
|
/* -------------------------------------------------------------------------- */ |
781 |
|
|
782 |
14 |
SygusInvConstraintCommand::SygusInvConstraintCommand( |
783 |
14 |
const std::vector<api::Term>& predicates) |
784 |
14 |
: d_predicates(predicates) |
785 |
|
{ |
786 |
14 |
} |
787 |
|
|
788 |
|
SygusInvConstraintCommand::SygusInvConstraintCommand(const api::Term& inv, |
789 |
|
const api::Term& pre, |
790 |
|
const api::Term& trans, |
791 |
|
const api::Term& post) |
792 |
|
: SygusInvConstraintCommand(std::vector<api::Term>{inv, pre, trans, post}) |
793 |
|
{ |
794 |
|
} |
795 |
|
|
796 |
14 |
void SygusInvConstraintCommand::invoke(api::Solver* solver, SymbolManager* sm) |
797 |
|
{ |
798 |
|
try |
799 |
|
{ |
800 |
56 |
solver->addSygusInvConstraint( |
801 |
56 |
d_predicates[0], d_predicates[1], d_predicates[2], d_predicates[3]); |
802 |
14 |
d_commandStatus = CommandSuccess::instance(); |
803 |
|
} |
804 |
|
catch (exception& e) |
805 |
|
{ |
806 |
|
d_commandStatus = new CommandFailure(e.what()); |
807 |
|
} |
808 |
14 |
} |
809 |
|
|
810 |
|
const std::vector<api::Term>& SygusInvConstraintCommand::getPredicates() const |
811 |
|
{ |
812 |
|
return d_predicates; |
813 |
|
} |
814 |
|
|
815 |
|
Command* SygusInvConstraintCommand::clone() const |
816 |
|
{ |
817 |
|
return new SygusInvConstraintCommand(d_predicates); |
818 |
|
} |
819 |
|
|
820 |
28 |
std::string SygusInvConstraintCommand::getCommandName() const |
821 |
|
{ |
822 |
28 |
return "inv-constraint"; |
823 |
|
} |
824 |
|
|
825 |
1 |
void SygusInvConstraintCommand::toStream(std::ostream& out, |
826 |
|
int toDepth, |
827 |
|
size_t dag, |
828 |
|
OutputLanguage language) const |
829 |
|
{ |
830 |
2 |
Printer::getPrinter(language)->toStreamCmdInvConstraint( |
831 |
|
out, |
832 |
2 |
termToNode(d_predicates[0]), |
833 |
2 |
termToNode(d_predicates[1]), |
834 |
2 |
termToNode(d_predicates[2]), |
835 |
2 |
termToNode(d_predicates[3])); |
836 |
1 |
} |
837 |
|
|
838 |
|
/* -------------------------------------------------------------------------- */ |
839 |
|
/* class CheckSynthCommand */ |
840 |
|
/* -------------------------------------------------------------------------- */ |
841 |
|
|
842 |
192 |
void CheckSynthCommand::invoke(api::Solver* solver, SymbolManager* sm) |
843 |
|
{ |
844 |
|
try |
845 |
|
{ |
846 |
192 |
d_result = solver->checkSynth(); |
847 |
183 |
d_commandStatus = CommandSuccess::instance(); |
848 |
183 |
d_solution.clear(); |
849 |
|
// check whether we should print the status |
850 |
366 |
if (!d_result.isUnsat() |
851 |
880 |
|| options::sygusOut() == options::SygusSolutionOutMode::STATUS_AND_DEF |
852 |
358 |
|| options::sygusOut() == options::SygusSolutionOutMode::STATUS) |
853 |
|
{ |
854 |
180 |
if (options::sygusOut() == options::SygusSolutionOutMode::STANDARD) |
855 |
|
{ |
856 |
|
d_solution << "fail" << endl; |
857 |
|
} |
858 |
|
else |
859 |
|
{ |
860 |
180 |
d_solution << d_result << endl; |
861 |
|
} |
862 |
|
} |
863 |
|
// check whether we should print the solution |
864 |
366 |
if (d_result.isUnsat() |
865 |
183 |
&& options::sygusOut() != options::SygusSolutionOutMode::STATUS) |
866 |
|
{ |
867 |
6 |
std::vector<api::Term> synthFuns = sm->getFunctionsToSynthesize(); |
868 |
3 |
d_solution << "(" << std::endl; |
869 |
3 |
Printer* p = Printer::getPrinter(language::output::LANG_SYGUS_V2); |
870 |
7 |
for (api::Term& f : synthFuns) |
871 |
|
{ |
872 |
8 |
api::Term sol = solver->getSynthSolution(f); |
873 |
8 |
std::vector<api::Term> formals; |
874 |
4 |
if (sol.getKind() == api::LAMBDA) |
875 |
|
{ |
876 |
3 |
formals.insert(formals.end(), sol[0].begin(), sol[0].end()); |
877 |
3 |
sol = sol[1]; |
878 |
|
} |
879 |
8 |
api::Sort rangeSort = f.getSort(); |
880 |
4 |
if (rangeSort.isFunction()) |
881 |
|
{ |
882 |
3 |
rangeSort = rangeSort.getFunctionCodomainSort(); |
883 |
|
} |
884 |
4 |
p->toStreamCmdDefineFunction(d_solution, |
885 |
8 |
f.toString(), |
886 |
8 |
termVectorToNodes(formals), |
887 |
8 |
sortToTypeNode(rangeSort), |
888 |
8 |
termToNode(sol)); |
889 |
|
} |
890 |
3 |
d_solution << ")" << std::endl; |
891 |
|
} |
892 |
|
} |
893 |
18 |
catch (exception& e) |
894 |
|
{ |
895 |
9 |
d_commandStatus = new CommandFailure(e.what()); |
896 |
|
} |
897 |
192 |
} |
898 |
|
|
899 |
|
api::Result CheckSynthCommand::getResult() const { return d_result; } |
900 |
192 |
void CheckSynthCommand::printResult(std::ostream& out, uint32_t verbosity) const |
901 |
|
{ |
902 |
192 |
if (!ok()) |
903 |
|
{ |
904 |
9 |
this->Command::printResult(out, verbosity); |
905 |
|
} |
906 |
|
else |
907 |
|
{ |
908 |
183 |
out << d_solution.str(); |
909 |
|
} |
910 |
192 |
} |
911 |
|
|
912 |
|
Command* CheckSynthCommand::clone() const { return new CheckSynthCommand(); } |
913 |
|
|
914 |
384 |
std::string CheckSynthCommand::getCommandName() const { return "check-synth"; } |
915 |
|
|
916 |
1 |
void CheckSynthCommand::toStream(std::ostream& out, |
917 |
|
int toDepth, |
918 |
|
size_t dag, |
919 |
|
OutputLanguage language) const |
920 |
|
{ |
921 |
1 |
Printer::getPrinter(language)->toStreamCmdCheckSynth(out); |
922 |
1 |
} |
923 |
|
|
924 |
|
/* -------------------------------------------------------------------------- */ |
925 |
|
/* class ResetCommand */ |
926 |
|
/* -------------------------------------------------------------------------- */ |
927 |
|
|
928 |
49 |
void ResetCommand::invoke(api::Solver* solver, SymbolManager* sm) |
929 |
|
{ |
930 |
|
try |
931 |
|
{ |
932 |
49 |
sm->reset(); |
933 |
49 |
resetSolver(solver); |
934 |
49 |
d_commandStatus = CommandSuccess::instance(); |
935 |
|
} |
936 |
|
catch (exception& e) |
937 |
|
{ |
938 |
|
d_commandStatus = new CommandFailure(e.what()); |
939 |
|
} |
940 |
49 |
} |
941 |
|
|
942 |
|
Command* ResetCommand::clone() const { return new ResetCommand(); } |
943 |
98 |
std::string ResetCommand::getCommandName() const { return "reset"; } |
944 |
|
|
945 |
|
void ResetCommand::toStream(std::ostream& out, |
946 |
|
int toDepth, |
947 |
|
size_t dag, |
948 |
|
OutputLanguage language) const |
949 |
|
{ |
950 |
|
Printer::getPrinter(language)->toStreamCmdReset(out); |
951 |
|
} |
952 |
|
|
953 |
|
/* -------------------------------------------------------------------------- */ |
954 |
|
/* class ResetAssertionsCommand */ |
955 |
|
/* -------------------------------------------------------------------------- */ |
956 |
|
|
957 |
36 |
void ResetAssertionsCommand::invoke(api::Solver* solver, SymbolManager* sm) |
958 |
|
{ |
959 |
|
try |
960 |
|
{ |
961 |
36 |
sm->resetAssertions(); |
962 |
36 |
solver->resetAssertions(); |
963 |
36 |
d_commandStatus = CommandSuccess::instance(); |
964 |
|
} |
965 |
|
catch (exception& e) |
966 |
|
{ |
967 |
|
d_commandStatus = new CommandFailure(e.what()); |
968 |
|
} |
969 |
36 |
} |
970 |
|
|
971 |
|
Command* ResetAssertionsCommand::clone() const |
972 |
|
{ |
973 |
|
return new ResetAssertionsCommand(); |
974 |
|
} |
975 |
|
|
976 |
72 |
std::string ResetAssertionsCommand::getCommandName() const |
977 |
|
{ |
978 |
72 |
return "reset-assertions"; |
979 |
|
} |
980 |
|
|
981 |
|
void ResetAssertionsCommand::toStream(std::ostream& out, |
982 |
|
int toDepth, |
983 |
|
size_t dag, |
984 |
|
OutputLanguage language) const |
985 |
|
{ |
986 |
|
Printer::getPrinter(language)->toStreamCmdResetAssertions(out); |
987 |
|
} |
988 |
|
|
989 |
|
/* -------------------------------------------------------------------------- */ |
990 |
|
/* class QuitCommand */ |
991 |
|
/* -------------------------------------------------------------------------- */ |
992 |
|
|
993 |
734 |
void QuitCommand::invoke(api::Solver* solver, SymbolManager* sm) |
994 |
|
{ |
995 |
734 |
Dump("benchmark") << *this; |
996 |
734 |
d_commandStatus = CommandSuccess::instance(); |
997 |
734 |
} |
998 |
|
|
999 |
|
Command* QuitCommand::clone() const { return new QuitCommand(); } |
1000 |
1468 |
std::string QuitCommand::getCommandName() const { return "exit"; } |
1001 |
|
|
1002 |
|
void QuitCommand::toStream(std::ostream& out, |
1003 |
|
int toDepth, |
1004 |
|
size_t dag, |
1005 |
|
OutputLanguage language) const |
1006 |
|
{ |
1007 |
|
Printer::getPrinter(language)->toStreamCmdQuit(out); |
1008 |
|
} |
1009 |
|
|
1010 |
|
/* -------------------------------------------------------------------------- */ |
1011 |
|
/* class CommentCommand */ |
1012 |
|
/* -------------------------------------------------------------------------- */ |
1013 |
|
|
1014 |
|
CommentCommand::CommentCommand(std::string comment) : d_comment(comment) {} |
1015 |
|
std::string CommentCommand::getComment() const { return d_comment; } |
1016 |
|
void CommentCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1017 |
|
{ |
1018 |
|
Dump("benchmark") << *this; |
1019 |
|
d_commandStatus = CommandSuccess::instance(); |
1020 |
|
} |
1021 |
|
|
1022 |
|
Command* CommentCommand::clone() const { return new CommentCommand(d_comment); } |
1023 |
|
std::string CommentCommand::getCommandName() const { return "comment"; } |
1024 |
|
|
1025 |
|
void CommentCommand::toStream(std::ostream& out, |
1026 |
|
int toDepth, |
1027 |
|
size_t dag, |
1028 |
|
OutputLanguage language) const |
1029 |
|
{ |
1030 |
|
Printer::getPrinter(language)->toStreamCmdComment(out, d_comment); |
1031 |
|
} |
1032 |
|
|
1033 |
|
/* -------------------------------------------------------------------------- */ |
1034 |
|
/* class CommandSequence */ |
1035 |
|
/* -------------------------------------------------------------------------- */ |
1036 |
|
|
1037 |
5104 |
CommandSequence::CommandSequence() : d_index(0) {} |
1038 |
10371 |
CommandSequence::~CommandSequence() |
1039 |
|
{ |
1040 |
13020 |
for (unsigned i = d_index; i < d_commandSequence.size(); ++i) |
1041 |
|
{ |
1042 |
7916 |
delete d_commandSequence[i]; |
1043 |
|
} |
1044 |
5267 |
} |
1045 |
|
|
1046 |
7916 |
void CommandSequence::addCommand(Command* cmd) |
1047 |
|
{ |
1048 |
7916 |
d_commandSequence.push_back(cmd); |
1049 |
7916 |
} |
1050 |
|
|
1051 |
|
void CommandSequence::clear() { d_commandSequence.clear(); } |
1052 |
|
void CommandSequence::invoke(api::Solver* solver, SymbolManager* sm) |
1053 |
|
{ |
1054 |
|
for (; d_index < d_commandSequence.size(); ++d_index) |
1055 |
|
{ |
1056 |
|
d_commandSequence[d_index]->invoke(solver, sm); |
1057 |
|
if (!d_commandSequence[d_index]->ok()) |
1058 |
|
{ |
1059 |
|
// abort execution |
1060 |
|
d_commandStatus = d_commandSequence[d_index]->getCommandStatus(); |
1061 |
|
return; |
1062 |
|
} |
1063 |
|
delete d_commandSequence[d_index]; |
1064 |
|
} |
1065 |
|
|
1066 |
|
AlwaysAssert(d_commandStatus == NULL); |
1067 |
|
d_commandStatus = CommandSuccess::instance(); |
1068 |
|
} |
1069 |
|
|
1070 |
|
void CommandSequence::invoke(api::Solver* solver, |
1071 |
|
SymbolManager* sm, |
1072 |
|
std::ostream& out) |
1073 |
|
{ |
1074 |
|
for (; d_index < d_commandSequence.size(); ++d_index) |
1075 |
|
{ |
1076 |
|
d_commandSequence[d_index]->invoke(solver, sm, out); |
1077 |
|
if (!d_commandSequence[d_index]->ok()) |
1078 |
|
{ |
1079 |
|
// abort execution |
1080 |
|
d_commandStatus = d_commandSequence[d_index]->getCommandStatus(); |
1081 |
|
return; |
1082 |
|
} |
1083 |
|
delete d_commandSequence[d_index]; |
1084 |
|
} |
1085 |
|
|
1086 |
|
AlwaysAssert(d_commandStatus == NULL); |
1087 |
|
d_commandStatus = CommandSuccess::instance(); |
1088 |
|
} |
1089 |
|
|
1090 |
|
Command* CommandSequence::clone() const |
1091 |
|
{ |
1092 |
|
CommandSequence* seq = new CommandSequence(); |
1093 |
|
for (const_iterator i = begin(); i != end(); ++i) |
1094 |
|
{ |
1095 |
|
seq->addCommand((*i)->clone()); |
1096 |
|
} |
1097 |
|
seq->d_index = d_index; |
1098 |
|
return seq; |
1099 |
|
} |
1100 |
|
|
1101 |
|
CommandSequence::const_iterator CommandSequence::begin() const |
1102 |
|
{ |
1103 |
|
return d_commandSequence.begin(); |
1104 |
|
} |
1105 |
|
|
1106 |
|
CommandSequence::const_iterator CommandSequence::end() const |
1107 |
|
{ |
1108 |
|
return d_commandSequence.end(); |
1109 |
|
} |
1110 |
|
|
1111 |
4970 |
CommandSequence::iterator CommandSequence::begin() |
1112 |
|
{ |
1113 |
4970 |
return d_commandSequence.begin(); |
1114 |
|
} |
1115 |
|
|
1116 |
12746 |
CommandSequence::iterator CommandSequence::end() |
1117 |
|
{ |
1118 |
12746 |
return d_commandSequence.end(); |
1119 |
|
} |
1120 |
|
|
1121 |
|
std::string CommandSequence::getCommandName() const { return "sequence"; } |
1122 |
|
|
1123 |
|
void CommandSequence::toStream(std::ostream& out, |
1124 |
|
int toDepth, |
1125 |
|
size_t dag, |
1126 |
|
OutputLanguage language) const |
1127 |
|
{ |
1128 |
|
Printer::getPrinter(language)->toStreamCmdCommandSequence(out, |
1129 |
|
d_commandSequence); |
1130 |
|
} |
1131 |
|
|
1132 |
|
/* -------------------------------------------------------------------------- */ |
1133 |
|
/* class DeclarationSequence */ |
1134 |
|
/* -------------------------------------------------------------------------- */ |
1135 |
|
|
1136 |
|
void DeclarationSequence::toStream(std::ostream& out, |
1137 |
|
int toDepth, |
1138 |
|
size_t dag, |
1139 |
|
OutputLanguage language) const |
1140 |
|
{ |
1141 |
|
Printer::getPrinter(language)->toStreamCmdDeclarationSequence( |
1142 |
|
out, d_commandSequence); |
1143 |
|
} |
1144 |
|
|
1145 |
|
/* -------------------------------------------------------------------------- */ |
1146 |
|
/* class DeclarationDefinitionCommand */ |
1147 |
|
/* -------------------------------------------------------------------------- */ |
1148 |
|
|
1149 |
179905 |
DeclarationDefinitionCommand::DeclarationDefinitionCommand( |
1150 |
179905 |
const std::string& id) |
1151 |
179905 |
: d_symbol(id) |
1152 |
|
{ |
1153 |
179905 |
} |
1154 |
|
|
1155 |
|
std::string DeclarationDefinitionCommand::getSymbol() const { return d_symbol; } |
1156 |
|
|
1157 |
|
/* -------------------------------------------------------------------------- */ |
1158 |
|
/* class DeclareFunctionCommand */ |
1159 |
|
/* -------------------------------------------------------------------------- */ |
1160 |
|
|
1161 |
172975 |
DeclareFunctionCommand::DeclareFunctionCommand(const std::string& id, |
1162 |
|
api::Term func, |
1163 |
172975 |
api::Sort sort) |
1164 |
172975 |
: DeclarationDefinitionCommand(id), d_func(func), d_sort(sort) |
1165 |
|
{ |
1166 |
172975 |
} |
1167 |
|
|
1168 |
|
api::Term DeclareFunctionCommand::getFunction() const { return d_func; } |
1169 |
|
api::Sort DeclareFunctionCommand::getSort() const { return d_sort; } |
1170 |
|
|
1171 |
172809 |
void DeclareFunctionCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1172 |
|
{ |
1173 |
|
// mark that it will be printed in the model |
1174 |
172809 |
sm->addModelDeclarationTerm(d_func); |
1175 |
172809 |
d_commandStatus = CommandSuccess::instance(); |
1176 |
172809 |
} |
1177 |
|
|
1178 |
|
Command* DeclareFunctionCommand::clone() const |
1179 |
|
{ |
1180 |
|
DeclareFunctionCommand* dfc = |
1181 |
|
new DeclareFunctionCommand(d_symbol, d_func, d_sort); |
1182 |
|
return dfc; |
1183 |
|
} |
1184 |
|
|
1185 |
345618 |
std::string DeclareFunctionCommand::getCommandName() const |
1186 |
|
{ |
1187 |
345618 |
return "declare-fun"; |
1188 |
|
} |
1189 |
|
|
1190 |
|
void DeclareFunctionCommand::toStream(std::ostream& out, |
1191 |
|
int toDepth, |
1192 |
|
size_t dag, |
1193 |
|
OutputLanguage language) const |
1194 |
|
{ |
1195 |
|
Printer::getPrinter(language)->toStreamCmdDeclareFunction( |
1196 |
|
out, d_func.toString(), sortToTypeNode(d_sort)); |
1197 |
|
} |
1198 |
|
|
1199 |
|
/* -------------------------------------------------------------------------- */ |
1200 |
|
/* class DeclareFunctionCommand */ |
1201 |
|
/* -------------------------------------------------------------------------- */ |
1202 |
|
|
1203 |
3 |
DeclarePoolCommand::DeclarePoolCommand(const std::string& id, |
1204 |
|
api::Term func, |
1205 |
|
api::Sort sort, |
1206 |
3 |
const std::vector<api::Term>& initValue) |
1207 |
|
: DeclarationDefinitionCommand(id), |
1208 |
|
d_func(func), |
1209 |
|
d_sort(sort), |
1210 |
3 |
d_initValue(initValue) |
1211 |
|
{ |
1212 |
3 |
} |
1213 |
|
|
1214 |
|
api::Term DeclarePoolCommand::getFunction() const { return d_func; } |
1215 |
|
api::Sort DeclarePoolCommand::getSort() const { return d_sort; } |
1216 |
|
const std::vector<api::Term>& DeclarePoolCommand::getInitialValue() const |
1217 |
|
{ |
1218 |
|
return d_initValue; |
1219 |
|
} |
1220 |
|
|
1221 |
3 |
void DeclarePoolCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1222 |
|
{ |
1223 |
|
// Notice that the pool is already declared by the parser so that it the |
1224 |
|
// symbol is bound eagerly. This is analogous to DeclareSygusVarCommand. |
1225 |
|
// Hence, we do nothing here. |
1226 |
3 |
d_commandStatus = CommandSuccess::instance(); |
1227 |
3 |
} |
1228 |
|
|
1229 |
|
Command* DeclarePoolCommand::clone() const |
1230 |
|
{ |
1231 |
|
DeclarePoolCommand* dfc = |
1232 |
|
new DeclarePoolCommand(d_symbol, d_func, d_sort, d_initValue); |
1233 |
|
return dfc; |
1234 |
|
} |
1235 |
|
|
1236 |
6 |
std::string DeclarePoolCommand::getCommandName() const |
1237 |
|
{ |
1238 |
6 |
return "declare-pool"; |
1239 |
|
} |
1240 |
|
|
1241 |
|
void DeclarePoolCommand::toStream(std::ostream& out, |
1242 |
|
int toDepth, |
1243 |
|
size_t dag, |
1244 |
|
OutputLanguage language) const |
1245 |
|
{ |
1246 |
|
Printer::getPrinter(language)->toStreamCmdDeclarePool( |
1247 |
|
out, |
1248 |
|
d_func.toString(), |
1249 |
|
sortToTypeNode(d_sort), |
1250 |
|
termVectorToNodes(d_initValue)); |
1251 |
|
} |
1252 |
|
|
1253 |
|
/* -------------------------------------------------------------------------- */ |
1254 |
|
/* class DeclareSortCommand */ |
1255 |
|
/* -------------------------------------------------------------------------- */ |
1256 |
|
|
1257 |
3875 |
DeclareSortCommand::DeclareSortCommand(const std::string& id, |
1258 |
|
size_t arity, |
1259 |
3875 |
api::Sort sort) |
1260 |
3875 |
: DeclarationDefinitionCommand(id), d_arity(arity), d_sort(sort) |
1261 |
|
{ |
1262 |
3875 |
} |
1263 |
|
|
1264 |
|
size_t DeclareSortCommand::getArity() const { return d_arity; } |
1265 |
|
api::Sort DeclareSortCommand::getSort() const { return d_sort; } |
1266 |
3831 |
void DeclareSortCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1267 |
|
{ |
1268 |
|
// mark that it will be printed in the model |
1269 |
3831 |
sm->addModelDeclarationSort(d_sort); |
1270 |
3831 |
d_commandStatus = CommandSuccess::instance(); |
1271 |
3831 |
} |
1272 |
|
|
1273 |
|
Command* DeclareSortCommand::clone() const |
1274 |
|
{ |
1275 |
|
return new DeclareSortCommand(d_symbol, d_arity, d_sort); |
1276 |
|
} |
1277 |
|
|
1278 |
7662 |
std::string DeclareSortCommand::getCommandName() const |
1279 |
|
{ |
1280 |
7662 |
return "declare-sort"; |
1281 |
|
} |
1282 |
|
|
1283 |
|
void DeclareSortCommand::toStream(std::ostream& out, |
1284 |
|
int toDepth, |
1285 |
|
size_t dag, |
1286 |
|
OutputLanguage language) const |
1287 |
|
{ |
1288 |
|
Printer::getPrinter(language)->toStreamCmdDeclareType(out, |
1289 |
|
sortToTypeNode(d_sort)); |
1290 |
|
} |
1291 |
|
|
1292 |
|
/* -------------------------------------------------------------------------- */ |
1293 |
|
/* class DefineSortCommand */ |
1294 |
|
/* -------------------------------------------------------------------------- */ |
1295 |
|
|
1296 |
|
DefineSortCommand::DefineSortCommand(const std::string& id, api::Sort sort) |
1297 |
|
: DeclarationDefinitionCommand(id), d_params(), d_sort(sort) |
1298 |
|
{ |
1299 |
|
} |
1300 |
|
|
1301 |
206 |
DefineSortCommand::DefineSortCommand(const std::string& id, |
1302 |
|
const std::vector<api::Sort>& params, |
1303 |
206 |
api::Sort sort) |
1304 |
206 |
: DeclarationDefinitionCommand(id), d_params(params), d_sort(sort) |
1305 |
|
{ |
1306 |
206 |
} |
1307 |
|
|
1308 |
|
const std::vector<api::Sort>& DefineSortCommand::getParameters() const |
1309 |
|
{ |
1310 |
|
return d_params; |
1311 |
|
} |
1312 |
|
|
1313 |
|
api::Sort DefineSortCommand::getSort() const { return d_sort; } |
1314 |
206 |
void DefineSortCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1315 |
|
{ |
1316 |
206 |
d_commandStatus = CommandSuccess::instance(); |
1317 |
206 |
} |
1318 |
|
|
1319 |
|
Command* DefineSortCommand::clone() const |
1320 |
|
{ |
1321 |
|
return new DefineSortCommand(d_symbol, d_params, d_sort); |
1322 |
|
} |
1323 |
|
|
1324 |
412 |
std::string DefineSortCommand::getCommandName() const { return "define-sort"; } |
1325 |
|
|
1326 |
|
void DefineSortCommand::toStream(std::ostream& out, |
1327 |
|
int toDepth, |
1328 |
|
size_t dag, |
1329 |
|
OutputLanguage language) const |
1330 |
|
{ |
1331 |
|
Printer::getPrinter(language)->toStreamCmdDefineType( |
1332 |
|
out, d_symbol, sortVectorToTypeNodes(d_params), sortToTypeNode(d_sort)); |
1333 |
|
} |
1334 |
|
|
1335 |
|
/* -------------------------------------------------------------------------- */ |
1336 |
|
/* class DefineFunctionCommand */ |
1337 |
|
/* -------------------------------------------------------------------------- */ |
1338 |
|
|
1339 |
5 |
DefineFunctionCommand::DefineFunctionCommand(const std::string& id, |
1340 |
|
api::Term func, |
1341 |
|
api::Term formula, |
1342 |
5 |
bool global) |
1343 |
|
: DeclarationDefinitionCommand(id), |
1344 |
|
d_func(func), |
1345 |
|
d_formals(), |
1346 |
|
d_formula(formula), |
1347 |
5 |
d_global(global) |
1348 |
|
{ |
1349 |
5 |
} |
1350 |
|
|
1351 |
2254 |
DefineFunctionCommand::DefineFunctionCommand( |
1352 |
|
const std::string& id, |
1353 |
|
api::Term func, |
1354 |
|
const std::vector<api::Term>& formals, |
1355 |
|
api::Term formula, |
1356 |
2254 |
bool global) |
1357 |
|
: DeclarationDefinitionCommand(id), |
1358 |
|
d_func(func), |
1359 |
|
d_formals(formals), |
1360 |
|
d_formula(formula), |
1361 |
2254 |
d_global(global) |
1362 |
|
{ |
1363 |
2254 |
} |
1364 |
|
|
1365 |
|
api::Term DefineFunctionCommand::getFunction() const { return d_func; } |
1366 |
|
const std::vector<api::Term>& DefineFunctionCommand::getFormals() const |
1367 |
|
{ |
1368 |
|
return d_formals; |
1369 |
|
} |
1370 |
|
|
1371 |
|
api::Term DefineFunctionCommand::getFormula() const { return d_formula; } |
1372 |
2255 |
void DefineFunctionCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1373 |
|
{ |
1374 |
|
try |
1375 |
|
{ |
1376 |
2255 |
if (!d_func.isNull()) |
1377 |
|
{ |
1378 |
2255 |
solver->defineFun(d_func, d_formals, d_formula, d_global); |
1379 |
|
} |
1380 |
2255 |
d_commandStatus = CommandSuccess::instance(); |
1381 |
|
} |
1382 |
|
catch (exception& e) |
1383 |
|
{ |
1384 |
|
d_commandStatus = new CommandFailure(e.what()); |
1385 |
|
} |
1386 |
2255 |
} |
1387 |
|
|
1388 |
|
Command* DefineFunctionCommand::clone() const |
1389 |
|
{ |
1390 |
|
return new DefineFunctionCommand( |
1391 |
|
d_symbol, d_func, d_formals, d_formula, d_global); |
1392 |
|
} |
1393 |
|
|
1394 |
4510 |
std::string DefineFunctionCommand::getCommandName() const |
1395 |
|
{ |
1396 |
4510 |
return "define-fun"; |
1397 |
|
} |
1398 |
|
|
1399 |
3 |
void DefineFunctionCommand::toStream(std::ostream& out, |
1400 |
|
int toDepth, |
1401 |
|
size_t dag, |
1402 |
|
OutputLanguage language) const |
1403 |
|
{ |
1404 |
6 |
TypeNode rangeType = termToNode(d_func).getType(); |
1405 |
3 |
if (rangeType.isFunction()) |
1406 |
|
{ |
1407 |
3 |
rangeType = rangeType.getRangeType(); |
1408 |
|
} |
1409 |
12 |
Printer::getPrinter(language)->toStreamCmdDefineFunction( |
1410 |
|
out, |
1411 |
6 |
d_func.toString(), |
1412 |
6 |
termVectorToNodes(d_formals), |
1413 |
|
rangeType, |
1414 |
6 |
termToNode(d_formula)); |
1415 |
3 |
} |
1416 |
|
|
1417 |
|
/* -------------------------------------------------------------------------- */ |
1418 |
|
/* class DefineFunctionRecCommand */ |
1419 |
|
/* -------------------------------------------------------------------------- */ |
1420 |
|
|
1421 |
76 |
DefineFunctionRecCommand::DefineFunctionRecCommand( |
1422 |
|
|
1423 |
|
api::Term func, |
1424 |
|
const std::vector<api::Term>& formals, |
1425 |
|
api::Term formula, |
1426 |
76 |
bool global) |
1427 |
76 |
: d_global(global) |
1428 |
|
{ |
1429 |
76 |
d_funcs.push_back(func); |
1430 |
76 |
d_formals.push_back(formals); |
1431 |
76 |
d_formulas.push_back(formula); |
1432 |
76 |
} |
1433 |
|
|
1434 |
44 |
DefineFunctionRecCommand::DefineFunctionRecCommand( |
1435 |
|
|
1436 |
|
const std::vector<api::Term>& funcs, |
1437 |
|
const std::vector<std::vector<api::Term>>& formals, |
1438 |
|
const std::vector<api::Term>& formulas, |
1439 |
44 |
bool global) |
1440 |
44 |
: d_funcs(funcs), d_formals(formals), d_formulas(formulas), d_global(global) |
1441 |
|
{ |
1442 |
44 |
} |
1443 |
|
|
1444 |
|
const std::vector<api::Term>& DefineFunctionRecCommand::getFunctions() const |
1445 |
|
{ |
1446 |
|
return d_funcs; |
1447 |
|
} |
1448 |
|
|
1449 |
|
const std::vector<std::vector<api::Term>>& |
1450 |
|
DefineFunctionRecCommand::getFormals() const |
1451 |
|
{ |
1452 |
|
return d_formals; |
1453 |
|
} |
1454 |
|
|
1455 |
|
const std::vector<api::Term>& DefineFunctionRecCommand::getFormulas() const |
1456 |
|
{ |
1457 |
|
return d_formulas; |
1458 |
|
} |
1459 |
|
|
1460 |
120 |
void DefineFunctionRecCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1461 |
|
{ |
1462 |
|
try |
1463 |
|
{ |
1464 |
120 |
solver->defineFunsRec(d_funcs, d_formals, d_formulas, d_global); |
1465 |
117 |
d_commandStatus = CommandSuccess::instance(); |
1466 |
|
} |
1467 |
6 |
catch (exception& e) |
1468 |
|
{ |
1469 |
3 |
d_commandStatus = new CommandFailure(e.what()); |
1470 |
|
} |
1471 |
120 |
} |
1472 |
|
|
1473 |
|
Command* DefineFunctionRecCommand::clone() const |
1474 |
|
{ |
1475 |
|
return new DefineFunctionRecCommand(d_funcs, d_formals, d_formulas, d_global); |
1476 |
|
} |
1477 |
|
|
1478 |
240 |
std::string DefineFunctionRecCommand::getCommandName() const |
1479 |
|
{ |
1480 |
240 |
return "define-fun-rec"; |
1481 |
|
} |
1482 |
|
|
1483 |
|
void DefineFunctionRecCommand::toStream(std::ostream& out, |
1484 |
|
int toDepth, |
1485 |
|
size_t dag, |
1486 |
|
OutputLanguage language) const |
1487 |
|
{ |
1488 |
|
std::vector<std::vector<Node>> formals; |
1489 |
|
formals.reserve(d_formals.size()); |
1490 |
|
for (const std::vector<api::Term>& formal : d_formals) |
1491 |
|
{ |
1492 |
|
formals.push_back(termVectorToNodes(formal)); |
1493 |
|
} |
1494 |
|
|
1495 |
|
Printer::getPrinter(language)->toStreamCmdDefineFunctionRec( |
1496 |
|
out, termVectorToNodes(d_funcs), formals, termVectorToNodes(d_formulas)); |
1497 |
|
} |
1498 |
|
/* -------------------------------------------------------------------------- */ |
1499 |
|
/* class DeclareHeapCommand */ |
1500 |
|
/* -------------------------------------------------------------------------- */ |
1501 |
87 |
DeclareHeapCommand::DeclareHeapCommand(api::Sort locSort, api::Sort dataSort) |
1502 |
87 |
: d_locSort(locSort), d_dataSort(dataSort) |
1503 |
|
{ |
1504 |
87 |
} |
1505 |
|
|
1506 |
|
api::Sort DeclareHeapCommand::getLocationSort() const { return d_locSort; } |
1507 |
|
api::Sort DeclareHeapCommand::getDataSort() const { return d_dataSort; } |
1508 |
|
|
1509 |
87 |
void DeclareHeapCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1510 |
|
{ |
1511 |
87 |
solver->declareSeparationHeap(d_locSort, d_dataSort); |
1512 |
87 |
} |
1513 |
|
|
1514 |
|
Command* DeclareHeapCommand::clone() const |
1515 |
|
{ |
1516 |
|
return new DeclareHeapCommand(d_locSort, d_dataSort); |
1517 |
|
} |
1518 |
|
|
1519 |
174 |
std::string DeclareHeapCommand::getCommandName() const |
1520 |
|
{ |
1521 |
174 |
return "declare-heap"; |
1522 |
|
} |
1523 |
|
|
1524 |
|
void DeclareHeapCommand::toStream(std::ostream& out, |
1525 |
|
int toDepth, |
1526 |
|
size_t dag, |
1527 |
|
OutputLanguage language) const |
1528 |
|
{ |
1529 |
|
Printer::getPrinter(language)->toStreamCmdDeclareHeap( |
1530 |
|
out, sortToTypeNode(d_locSort), sortToTypeNode(d_dataSort)); |
1531 |
|
} |
1532 |
|
|
1533 |
|
/* -------------------------------------------------------------------------- */ |
1534 |
|
/* class SetUserAttributeCommand */ |
1535 |
|
/* -------------------------------------------------------------------------- */ |
1536 |
|
|
1537 |
208 |
SetUserAttributeCommand::SetUserAttributeCommand( |
1538 |
|
const std::string& attr, |
1539 |
|
api::Term term, |
1540 |
|
const std::vector<api::Term>& termValues, |
1541 |
208 |
const std::string& strValue) |
1542 |
208 |
: d_attr(attr), d_term(term), d_termValues(termValues), d_strValue(strValue) |
1543 |
|
{ |
1544 |
208 |
} |
1545 |
|
|
1546 |
208 |
SetUserAttributeCommand::SetUserAttributeCommand(const std::string& attr, |
1547 |
208 |
api::Term term) |
1548 |
208 |
: SetUserAttributeCommand(attr, term, {}, "") |
1549 |
|
{ |
1550 |
208 |
} |
1551 |
|
|
1552 |
|
SetUserAttributeCommand::SetUserAttributeCommand( |
1553 |
|
const std::string& attr, |
1554 |
|
api::Term term, |
1555 |
|
const std::vector<api::Term>& values) |
1556 |
|
: SetUserAttributeCommand(attr, term, values, "") |
1557 |
|
{ |
1558 |
|
} |
1559 |
|
|
1560 |
|
SetUserAttributeCommand::SetUserAttributeCommand(const std::string& attr, |
1561 |
|
api::Term term, |
1562 |
|
const std::string& value) |
1563 |
|
: SetUserAttributeCommand(attr, term, {}, value) |
1564 |
|
{ |
1565 |
|
} |
1566 |
|
|
1567 |
208 |
void SetUserAttributeCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1568 |
|
{ |
1569 |
|
try |
1570 |
|
{ |
1571 |
208 |
if (!d_term.isNull()) |
1572 |
|
{ |
1573 |
416 |
solver->getSmtEngine()->setUserAttribute(d_attr, |
1574 |
416 |
termToNode(d_term), |
1575 |
416 |
termVectorToNodes(d_termValues), |
1576 |
|
d_strValue); |
1577 |
|
} |
1578 |
208 |
d_commandStatus = CommandSuccess::instance(); |
1579 |
|
} |
1580 |
|
catch (exception& e) |
1581 |
|
{ |
1582 |
|
d_commandStatus = new CommandFailure(e.what()); |
1583 |
|
} |
1584 |
208 |
} |
1585 |
|
|
1586 |
|
Command* SetUserAttributeCommand::clone() const |
1587 |
|
{ |
1588 |
|
return new SetUserAttributeCommand(d_attr, d_term, d_termValues, d_strValue); |
1589 |
|
} |
1590 |
|
|
1591 |
208 |
std::string SetUserAttributeCommand::getCommandName() const |
1592 |
|
{ |
1593 |
208 |
return "set-user-attribute"; |
1594 |
|
} |
1595 |
|
|
1596 |
|
void SetUserAttributeCommand::toStream(std::ostream& out, |
1597 |
|
int toDepth, |
1598 |
|
size_t dag, |
1599 |
|
OutputLanguage language) const |
1600 |
|
{ |
1601 |
|
Printer::getPrinter(language)->toStreamCmdSetUserAttribute( |
1602 |
|
out, d_attr, termToNode(d_term)); |
1603 |
|
} |
1604 |
|
|
1605 |
|
/* -------------------------------------------------------------------------- */ |
1606 |
|
/* class SimplifyCommand */ |
1607 |
|
/* -------------------------------------------------------------------------- */ |
1608 |
|
|
1609 |
|
SimplifyCommand::SimplifyCommand(api::Term term) : d_term(term) {} |
1610 |
|
api::Term SimplifyCommand::getTerm() const { return d_term; } |
1611 |
|
void SimplifyCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1612 |
|
{ |
1613 |
|
try |
1614 |
|
{ |
1615 |
|
d_result = solver->simplify(d_term); |
1616 |
|
d_commandStatus = CommandSuccess::instance(); |
1617 |
|
} |
1618 |
|
catch (UnsafeInterruptException& e) |
1619 |
|
{ |
1620 |
|
d_commandStatus = new CommandInterrupted(); |
1621 |
|
} |
1622 |
|
catch (exception& e) |
1623 |
|
{ |
1624 |
|
d_commandStatus = new CommandFailure(e.what()); |
1625 |
|
} |
1626 |
|
} |
1627 |
|
|
1628 |
|
api::Term SimplifyCommand::getResult() const { return d_result; } |
1629 |
|
void SimplifyCommand::printResult(std::ostream& out, uint32_t verbosity) const |
1630 |
|
{ |
1631 |
|
if (!ok()) |
1632 |
|
{ |
1633 |
|
this->Command::printResult(out, verbosity); |
1634 |
|
} |
1635 |
|
else |
1636 |
|
{ |
1637 |
|
out << d_result << endl; |
1638 |
|
} |
1639 |
|
} |
1640 |
|
|
1641 |
|
Command* SimplifyCommand::clone() const |
1642 |
|
{ |
1643 |
|
SimplifyCommand* c = new SimplifyCommand(d_term); |
1644 |
|
c->d_result = d_result; |
1645 |
|
return c; |
1646 |
|
} |
1647 |
|
|
1648 |
|
std::string SimplifyCommand::getCommandName() const { return "simplify"; } |
1649 |
|
|
1650 |
|
void SimplifyCommand::toStream(std::ostream& out, |
1651 |
|
int toDepth, |
1652 |
|
size_t dag, |
1653 |
|
OutputLanguage language) const |
1654 |
|
{ |
1655 |
|
Printer::getPrinter(language)->toStreamCmdSimplify(out, termToNode(d_term)); |
1656 |
|
} |
1657 |
|
|
1658 |
|
/* -------------------------------------------------------------------------- */ |
1659 |
|
/* class GetValueCommand */ |
1660 |
|
/* -------------------------------------------------------------------------- */ |
1661 |
|
|
1662 |
6 |
GetValueCommand::GetValueCommand(api::Term term) : d_terms() |
1663 |
|
{ |
1664 |
6 |
d_terms.push_back(term); |
1665 |
6 |
} |
1666 |
|
|
1667 |
58 |
GetValueCommand::GetValueCommand(const std::vector<api::Term>& terms) |
1668 |
58 |
: d_terms(terms) |
1669 |
|
{ |
1670 |
58 |
PrettyCheckArgument( |
1671 |
|
terms.size() >= 1, terms, "cannot get-value of an empty set of terms"); |
1672 |
58 |
} |
1673 |
|
|
1674 |
|
const std::vector<api::Term>& GetValueCommand::getTerms() const |
1675 |
|
{ |
1676 |
|
return d_terms; |
1677 |
|
} |
1678 |
64 |
void GetValueCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1679 |
|
{ |
1680 |
|
try |
1681 |
|
{ |
1682 |
126 |
std::vector<api::Term> result = solver->getValue(d_terms); |
1683 |
62 |
Assert(result.size() == d_terms.size()); |
1684 |
152 |
for (int i = 0, size = d_terms.size(); i < size; i++) |
1685 |
|
{ |
1686 |
180 |
api::Term request = d_terms[i]; |
1687 |
180 |
api::Term value = result[i]; |
1688 |
90 |
result[i] = solver->mkTerm(api::SEXPR, request, value); |
1689 |
|
} |
1690 |
62 |
d_result = solver->mkTerm(api::SEXPR, result); |
1691 |
62 |
d_commandStatus = CommandSuccess::instance(); |
1692 |
|
} |
1693 |
4 |
catch (api::CVC5ApiRecoverableException& e) |
1694 |
|
{ |
1695 |
2 |
d_commandStatus = new CommandRecoverableFailure(e.what()); |
1696 |
|
} |
1697 |
|
catch (UnsafeInterruptException& e) |
1698 |
|
{ |
1699 |
|
d_commandStatus = new CommandInterrupted(); |
1700 |
|
} |
1701 |
|
catch (exception& e) |
1702 |
|
{ |
1703 |
|
d_commandStatus = new CommandFailure(e.what()); |
1704 |
|
} |
1705 |
64 |
} |
1706 |
|
|
1707 |
|
api::Term GetValueCommand::getResult() const { return d_result; } |
1708 |
64 |
void GetValueCommand::printResult(std::ostream& out, uint32_t verbosity) const |
1709 |
|
{ |
1710 |
64 |
if (!ok()) |
1711 |
|
{ |
1712 |
2 |
this->Command::printResult(out, verbosity); |
1713 |
|
} |
1714 |
|
else |
1715 |
|
{ |
1716 |
124 |
expr::ExprDag::Scope scope(out, false); |
1717 |
62 |
out << d_result << endl; |
1718 |
|
} |
1719 |
64 |
} |
1720 |
|
|
1721 |
|
Command* GetValueCommand::clone() const |
1722 |
|
{ |
1723 |
|
GetValueCommand* c = new GetValueCommand(d_terms); |
1724 |
|
c->d_result = d_result; |
1725 |
|
return c; |
1726 |
|
} |
1727 |
|
|
1728 |
128 |
std::string GetValueCommand::getCommandName() const { return "get-value"; } |
1729 |
|
|
1730 |
|
void GetValueCommand::toStream(std::ostream& out, |
1731 |
|
int toDepth, |
1732 |
|
size_t dag, |
1733 |
|
OutputLanguage language) const |
1734 |
|
{ |
1735 |
|
Printer::getPrinter(language)->toStreamCmdGetValue( |
1736 |
|
out, termVectorToNodes(d_terms)); |
1737 |
|
} |
1738 |
|
|
1739 |
|
/* -------------------------------------------------------------------------- */ |
1740 |
|
/* class GetAssignmentCommand */ |
1741 |
|
/* -------------------------------------------------------------------------- */ |
1742 |
|
|
1743 |
10 |
GetAssignmentCommand::GetAssignmentCommand() {} |
1744 |
10 |
void GetAssignmentCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1745 |
|
{ |
1746 |
|
try |
1747 |
|
{ |
1748 |
20 |
std::map<api::Term, std::string> enames = sm->getExpressionNames(); |
1749 |
20 |
std::vector<api::Term> terms; |
1750 |
20 |
std::vector<std::string> names; |
1751 |
22 |
for (const std::pair<const api::Term, std::string>& e : enames) |
1752 |
|
{ |
1753 |
12 |
terms.push_back(e.first); |
1754 |
12 |
names.push_back(e.second); |
1755 |
|
} |
1756 |
|
// Must use vector version of getValue to ensure error is thrown regardless |
1757 |
|
// of whether terms is empty. |
1758 |
18 |
std::vector<api::Term> values = solver->getValue(terms); |
1759 |
8 |
Assert(values.size() == names.size()); |
1760 |
16 |
std::vector<api::Term> sexprs; |
1761 |
20 |
for (size_t i = 0, nterms = terms.size(); i < nterms; i++) |
1762 |
|
{ |
1763 |
|
// Treat the expression name as a variable name as opposed to a string |
1764 |
|
// constant to avoid printing double quotes around the name. |
1765 |
24 |
api::Term name = solver->mkVar(solver->getBooleanSort(), names[i]); |
1766 |
12 |
sexprs.push_back(solver->mkTerm(api::SEXPR, name, values[i])); |
1767 |
|
} |
1768 |
8 |
d_result = solver->mkTerm(api::SEXPR, sexprs); |
1769 |
8 |
d_commandStatus = CommandSuccess::instance(); |
1770 |
|
} |
1771 |
4 |
catch (api::CVC5ApiRecoverableException& e) |
1772 |
|
{ |
1773 |
2 |
d_commandStatus = new CommandRecoverableFailure(e.what()); |
1774 |
|
} |
1775 |
|
catch (UnsafeInterruptException& e) |
1776 |
|
{ |
1777 |
|
d_commandStatus = new CommandInterrupted(); |
1778 |
|
} |
1779 |
|
catch (exception& e) |
1780 |
|
{ |
1781 |
|
d_commandStatus = new CommandFailure(e.what()); |
1782 |
|
} |
1783 |
10 |
} |
1784 |
|
|
1785 |
|
api::Term GetAssignmentCommand::getResult() const { return d_result; } |
1786 |
10 |
void GetAssignmentCommand::printResult(std::ostream& out, |
1787 |
|
uint32_t verbosity) const |
1788 |
|
{ |
1789 |
10 |
if (!ok()) |
1790 |
|
{ |
1791 |
2 |
this->Command::printResult(out, verbosity); |
1792 |
|
} |
1793 |
|
else |
1794 |
|
{ |
1795 |
8 |
out << d_result << endl; |
1796 |
|
} |
1797 |
10 |
} |
1798 |
|
|
1799 |
|
Command* GetAssignmentCommand::clone() const |
1800 |
|
{ |
1801 |
|
GetAssignmentCommand* c = new GetAssignmentCommand(); |
1802 |
|
c->d_result = d_result; |
1803 |
|
return c; |
1804 |
|
} |
1805 |
|
|
1806 |
20 |
std::string GetAssignmentCommand::getCommandName() const |
1807 |
|
{ |
1808 |
20 |
return "get-assignment"; |
1809 |
|
} |
1810 |
|
|
1811 |
|
void GetAssignmentCommand::toStream(std::ostream& out, |
1812 |
|
int toDepth, |
1813 |
|
size_t dag, |
1814 |
|
OutputLanguage language) const |
1815 |
|
{ |
1816 |
|
Printer::getPrinter(language)->toStreamCmdGetAssignment(out); |
1817 |
|
} |
1818 |
|
|
1819 |
|
/* -------------------------------------------------------------------------- */ |
1820 |
|
/* class GetModelCommand */ |
1821 |
|
/* -------------------------------------------------------------------------- */ |
1822 |
|
|
1823 |
30 |
GetModelCommand::GetModelCommand() : d_result(nullptr) {} |
1824 |
30 |
void GetModelCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1825 |
|
{ |
1826 |
|
try |
1827 |
|
{ |
1828 |
30 |
d_result = solver->getSmtEngine()->getModel(); |
1829 |
|
// set the model declarations, which determines what is printed in the model |
1830 |
25 |
d_result->clearModelDeclarations(); |
1831 |
50 |
std::vector<api::Sort> declareSorts = sm->getModelDeclareSorts(); |
1832 |
29 |
for (const api::Sort& s : declareSorts) |
1833 |
|
{ |
1834 |
4 |
d_result->addDeclarationSort(sortToTypeNode(s)); |
1835 |
|
} |
1836 |
50 |
std::vector<api::Term> declareTerms = sm->getModelDeclareTerms(); |
1837 |
55 |
for (const api::Term& t : declareTerms) |
1838 |
|
{ |
1839 |
30 |
d_result->addDeclarationTerm(termToNode(t)); |
1840 |
|
} |
1841 |
25 |
d_commandStatus = CommandSuccess::instance(); |
1842 |
|
} |
1843 |
10 |
catch (RecoverableModalException& e) |
1844 |
|
{ |
1845 |
5 |
d_commandStatus = new CommandRecoverableFailure(e.what()); |
1846 |
|
} |
1847 |
|
catch (UnsafeInterruptException& e) |
1848 |
|
{ |
1849 |
|
d_commandStatus = new CommandInterrupted(); |
1850 |
|
} |
1851 |
|
catch (exception& e) |
1852 |
|
{ |
1853 |
|
d_commandStatus = new CommandFailure(e.what()); |
1854 |
|
} |
1855 |
30 |
} |
1856 |
|
|
1857 |
|
/* Model is private to the library -- for now |
1858 |
|
Model* GetModelCommand::getResult() const { |
1859 |
|
return d_result; |
1860 |
|
} |
1861 |
|
*/ |
1862 |
|
|
1863 |
30 |
void GetModelCommand::printResult(std::ostream& out, uint32_t verbosity) const |
1864 |
|
{ |
1865 |
30 |
if (!ok()) |
1866 |
|
{ |
1867 |
5 |
this->Command::printResult(out, verbosity); |
1868 |
|
} |
1869 |
|
else |
1870 |
|
{ |
1871 |
25 |
out << *d_result; |
1872 |
|
} |
1873 |
30 |
} |
1874 |
|
|
1875 |
|
Command* GetModelCommand::clone() const |
1876 |
|
{ |
1877 |
|
GetModelCommand* c = new GetModelCommand(); |
1878 |
|
c->d_result = d_result; |
1879 |
|
return c; |
1880 |
|
} |
1881 |
|
|
1882 |
60 |
std::string GetModelCommand::getCommandName() const { return "get-model"; } |
1883 |
|
|
1884 |
|
void GetModelCommand::toStream(std::ostream& out, |
1885 |
|
int toDepth, |
1886 |
|
size_t dag, |
1887 |
|
OutputLanguage language) const |
1888 |
|
{ |
1889 |
|
Printer::getPrinter(language)->toStreamCmdGetModel(out); |
1890 |
|
} |
1891 |
|
|
1892 |
|
/* -------------------------------------------------------------------------- */ |
1893 |
|
/* class BlockModelCommand */ |
1894 |
|
/* -------------------------------------------------------------------------- */ |
1895 |
|
|
1896 |
14 |
BlockModelCommand::BlockModelCommand() {} |
1897 |
14 |
void BlockModelCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1898 |
|
{ |
1899 |
|
try |
1900 |
|
{ |
1901 |
14 |
solver->blockModel(); |
1902 |
14 |
d_commandStatus = CommandSuccess::instance(); |
1903 |
|
} |
1904 |
|
catch (api::CVC5ApiRecoverableException& e) |
1905 |
|
{ |
1906 |
|
d_commandStatus = new CommandRecoverableFailure(e.what()); |
1907 |
|
} |
1908 |
|
catch (UnsafeInterruptException& e) |
1909 |
|
{ |
1910 |
|
d_commandStatus = new CommandInterrupted(); |
1911 |
|
} |
1912 |
|
catch (exception& e) |
1913 |
|
{ |
1914 |
|
d_commandStatus = new CommandFailure(e.what()); |
1915 |
|
} |
1916 |
14 |
} |
1917 |
|
|
1918 |
|
Command* BlockModelCommand::clone() const |
1919 |
|
{ |
1920 |
|
BlockModelCommand* c = new BlockModelCommand(); |
1921 |
|
return c; |
1922 |
|
} |
1923 |
|
|
1924 |
28 |
std::string BlockModelCommand::getCommandName() const { return "block-model"; } |
1925 |
|
|
1926 |
|
void BlockModelCommand::toStream(std::ostream& out, |
1927 |
|
int toDepth, |
1928 |
|
size_t dag, |
1929 |
|
OutputLanguage language) const |
1930 |
|
{ |
1931 |
|
Printer::getPrinter(language)->toStreamCmdBlockModel(out); |
1932 |
|
} |
1933 |
|
|
1934 |
|
/* -------------------------------------------------------------------------- */ |
1935 |
|
/* class BlockModelValuesCommand */ |
1936 |
|
/* -------------------------------------------------------------------------- */ |
1937 |
|
|
1938 |
8 |
BlockModelValuesCommand::BlockModelValuesCommand( |
1939 |
8 |
const std::vector<api::Term>& terms) |
1940 |
8 |
: d_terms(terms) |
1941 |
|
{ |
1942 |
8 |
PrettyCheckArgument(terms.size() >= 1, |
1943 |
|
terms, |
1944 |
|
"cannot block-model-values of an empty set of terms"); |
1945 |
8 |
} |
1946 |
|
|
1947 |
|
const std::vector<api::Term>& BlockModelValuesCommand::getTerms() const |
1948 |
|
{ |
1949 |
|
return d_terms; |
1950 |
|
} |
1951 |
8 |
void BlockModelValuesCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1952 |
|
{ |
1953 |
|
try |
1954 |
|
{ |
1955 |
8 |
solver->blockModelValues(d_terms); |
1956 |
8 |
d_commandStatus = CommandSuccess::instance(); |
1957 |
|
} |
1958 |
|
catch (api::CVC5ApiRecoverableException& e) |
1959 |
|
{ |
1960 |
|
d_commandStatus = new CommandRecoverableFailure(e.what()); |
1961 |
|
} |
1962 |
|
catch (UnsafeInterruptException& e) |
1963 |
|
{ |
1964 |
|
d_commandStatus = new CommandInterrupted(); |
1965 |
|
} |
1966 |
|
catch (exception& e) |
1967 |
|
{ |
1968 |
|
d_commandStatus = new CommandFailure(e.what()); |
1969 |
|
} |
1970 |
8 |
} |
1971 |
|
|
1972 |
|
Command* BlockModelValuesCommand::clone() const |
1973 |
|
{ |
1974 |
|
BlockModelValuesCommand* c = new BlockModelValuesCommand(d_terms); |
1975 |
|
return c; |
1976 |
|
} |
1977 |
|
|
1978 |
16 |
std::string BlockModelValuesCommand::getCommandName() const |
1979 |
|
{ |
1980 |
16 |
return "block-model-values"; |
1981 |
|
} |
1982 |
|
|
1983 |
|
void BlockModelValuesCommand::toStream(std::ostream& out, |
1984 |
|
int toDepth, |
1985 |
|
size_t dag, |
1986 |
|
OutputLanguage language) const |
1987 |
|
{ |
1988 |
|
Printer::getPrinter(language)->toStreamCmdBlockModelValues( |
1989 |
|
out, termVectorToNodes(d_terms)); |
1990 |
|
} |
1991 |
|
|
1992 |
|
/* -------------------------------------------------------------------------- */ |
1993 |
|
/* class GetProofCommand */ |
1994 |
|
/* -------------------------------------------------------------------------- */ |
1995 |
|
|
1996 |
1 |
GetProofCommand::GetProofCommand() {} |
1997 |
1 |
void GetProofCommand::invoke(api::Solver* solver, SymbolManager* sm) |
1998 |
|
{ |
1999 |
|
try |
2000 |
|
{ |
2001 |
1 |
d_result = solver->getProof(); |
2002 |
1 |
d_commandStatus = CommandSuccess::instance(); |
2003 |
|
} |
2004 |
|
catch (api::CVC5ApiRecoverableException& e) |
2005 |
|
{ |
2006 |
|
d_commandStatus = new CommandRecoverableFailure(e.what()); |
2007 |
|
} |
2008 |
|
catch (exception& e) |
2009 |
|
{ |
2010 |
|
d_commandStatus = new CommandFailure(e.what()); |
2011 |
|
} |
2012 |
1 |
} |
2013 |
|
|
2014 |
1 |
void GetProofCommand::printResult(std::ostream& out, uint32_t verbosity) const |
2015 |
|
{ |
2016 |
1 |
if (ok()) |
2017 |
|
{ |
2018 |
1 |
out << d_result; |
2019 |
|
} |
2020 |
|
else |
2021 |
|
{ |
2022 |
|
this->Command::printResult(out, verbosity); |
2023 |
|
} |
2024 |
1 |
} |
2025 |
|
|
2026 |
|
Command* GetProofCommand::clone() const |
2027 |
|
{ |
2028 |
|
GetProofCommand* c = new GetProofCommand(); |
2029 |
|
return c; |
2030 |
|
} |
2031 |
|
|
2032 |
2 |
std::string GetProofCommand::getCommandName() const { return "get-proof"; } |
2033 |
|
|
2034 |
|
void GetProofCommand::toStream(std::ostream& out, |
2035 |
|
int toDepth, |
2036 |
|
size_t dag, |
2037 |
|
OutputLanguage language) const |
2038 |
|
{ |
2039 |
|
Printer::getPrinter(language)->toStreamCmdGetProof(out); |
2040 |
|
} |
2041 |
|
|
2042 |
|
/* -------------------------------------------------------------------------- */ |
2043 |
|
/* class GetInstantiationsCommand */ |
2044 |
|
/* -------------------------------------------------------------------------- */ |
2045 |
|
|
2046 |
15 |
GetInstantiationsCommand::GetInstantiationsCommand() : d_solver(nullptr) {} |
2047 |
153 |
bool GetInstantiationsCommand::isEnabled(api::Solver* solver, |
2048 |
|
const api::Result& res) |
2049 |
|
{ |
2050 |
153 |
return (solver->getOptions().printer.instFormatMode |
2051 |
|
!= options::InstFormatMode::SZS |
2052 |
153 |
&& (res.isSat() |
2053 |
153 |
|| (res.isSatUnknown() |
2054 |
|
&& res.getUnknownExplanation() == api::Result::INCOMPLETE))) |
2055 |
306 |
|| res.isUnsat() || res.isEntailed(); |
2056 |
|
} |
2057 |
15 |
void GetInstantiationsCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2058 |
|
{ |
2059 |
|
try |
2060 |
|
{ |
2061 |
15 |
d_solver = solver; |
2062 |
15 |
d_commandStatus = CommandSuccess::instance(); |
2063 |
|
} |
2064 |
|
catch (exception& e) |
2065 |
|
{ |
2066 |
|
d_commandStatus = new CommandFailure(e.what()); |
2067 |
|
} |
2068 |
15 |
} |
2069 |
|
|
2070 |
15 |
void GetInstantiationsCommand::printResult(std::ostream& out, |
2071 |
|
uint32_t verbosity) const |
2072 |
|
{ |
2073 |
15 |
if (!ok()) |
2074 |
|
{ |
2075 |
|
this->Command::printResult(out, verbosity); |
2076 |
|
} |
2077 |
|
else |
2078 |
|
{ |
2079 |
15 |
d_solver->printInstantiations(out); |
2080 |
|
} |
2081 |
15 |
} |
2082 |
|
|
2083 |
|
Command* GetInstantiationsCommand::clone() const |
2084 |
|
{ |
2085 |
|
GetInstantiationsCommand* c = new GetInstantiationsCommand(); |
2086 |
|
// c->d_result = d_result; |
2087 |
|
c->d_solver = d_solver; |
2088 |
|
return c; |
2089 |
|
} |
2090 |
|
|
2091 |
30 |
std::string GetInstantiationsCommand::getCommandName() const |
2092 |
|
{ |
2093 |
30 |
return "get-instantiations"; |
2094 |
|
} |
2095 |
|
|
2096 |
|
void GetInstantiationsCommand::toStream(std::ostream& out, |
2097 |
|
int toDepth, |
2098 |
|
size_t dag, |
2099 |
|
OutputLanguage language) const |
2100 |
|
{ |
2101 |
|
Printer::getPrinter(language)->toStreamCmdGetInstantiations(out); |
2102 |
|
} |
2103 |
|
|
2104 |
|
/* -------------------------------------------------------------------------- */ |
2105 |
|
/* class GetInterpolCommand */ |
2106 |
|
/* -------------------------------------------------------------------------- */ |
2107 |
|
|
2108 |
|
GetInterpolCommand::GetInterpolCommand(const std::string& name, api::Term conj) |
2109 |
|
: d_name(name), d_conj(conj), d_resultStatus(false) |
2110 |
|
{ |
2111 |
|
} |
2112 |
8 |
GetInterpolCommand::GetInterpolCommand(const std::string& name, |
2113 |
|
api::Term conj, |
2114 |
8 |
api::Grammar* g) |
2115 |
8 |
: d_name(name), d_conj(conj), d_sygus_grammar(g), d_resultStatus(false) |
2116 |
|
{ |
2117 |
8 |
} |
2118 |
|
|
2119 |
|
api::Term GetInterpolCommand::getConjecture() const { return d_conj; } |
2120 |
|
|
2121 |
|
const api::Grammar* GetInterpolCommand::getGrammar() const |
2122 |
|
{ |
2123 |
|
return d_sygus_grammar; |
2124 |
|
} |
2125 |
|
|
2126 |
|
api::Term GetInterpolCommand::getResult() const { return d_result; } |
2127 |
|
|
2128 |
8 |
void GetInterpolCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2129 |
|
{ |
2130 |
|
try |
2131 |
|
{ |
2132 |
8 |
if (d_sygus_grammar == nullptr) |
2133 |
|
{ |
2134 |
7 |
d_resultStatus = solver->getInterpolant(d_conj, d_result); |
2135 |
|
} |
2136 |
|
else |
2137 |
|
{ |
2138 |
1 |
d_resultStatus = |
2139 |
1 |
solver->getInterpolant(d_conj, *d_sygus_grammar, d_result); |
2140 |
|
} |
2141 |
8 |
d_commandStatus = CommandSuccess::instance(); |
2142 |
|
} |
2143 |
|
catch (exception& e) |
2144 |
|
{ |
2145 |
|
d_commandStatus = new CommandFailure(e.what()); |
2146 |
|
} |
2147 |
8 |
} |
2148 |
|
|
2149 |
8 |
void GetInterpolCommand::printResult(std::ostream& out, |
2150 |
|
uint32_t verbosity) const |
2151 |
|
{ |
2152 |
8 |
if (!ok()) |
2153 |
|
{ |
2154 |
|
this->Command::printResult(out, verbosity); |
2155 |
|
} |
2156 |
|
else |
2157 |
|
{ |
2158 |
16 |
expr::ExprDag::Scope scope(out, false); |
2159 |
8 |
if (d_resultStatus) |
2160 |
|
{ |
2161 |
8 |
out << "(define-fun " << d_name << " () Bool " << d_result << ")" |
2162 |
8 |
<< std::endl; |
2163 |
|
} |
2164 |
|
else |
2165 |
|
{ |
2166 |
|
out << "none" << std::endl; |
2167 |
|
} |
2168 |
|
} |
2169 |
8 |
} |
2170 |
|
|
2171 |
|
Command* GetInterpolCommand::clone() const |
2172 |
|
{ |
2173 |
|
GetInterpolCommand* c = |
2174 |
|
new GetInterpolCommand(d_name, d_conj, d_sygus_grammar); |
2175 |
|
c->d_result = d_result; |
2176 |
|
c->d_resultStatus = d_resultStatus; |
2177 |
|
return c; |
2178 |
|
} |
2179 |
|
|
2180 |
16 |
std::string GetInterpolCommand::getCommandName() const |
2181 |
|
{ |
2182 |
16 |
return "get-interpol"; |
2183 |
|
} |
2184 |
|
|
2185 |
|
void GetInterpolCommand::toStream(std::ostream& out, |
2186 |
|
int toDepth, |
2187 |
|
size_t dag, |
2188 |
|
OutputLanguage language) const |
2189 |
|
{ |
2190 |
|
Printer::getPrinter(language)->toStreamCmdGetInterpol( |
2191 |
|
out, d_name, termToNode(d_conj), grammarToTypeNode(d_sygus_grammar)); |
2192 |
|
} |
2193 |
|
|
2194 |
|
/* -------------------------------------------------------------------------- */ |
2195 |
|
/* class GetAbductCommand */ |
2196 |
|
/* -------------------------------------------------------------------------- */ |
2197 |
|
|
2198 |
|
GetAbductCommand::GetAbductCommand(const std::string& name, api::Term conj) |
2199 |
|
: d_name(name), d_conj(conj), d_resultStatus(false) |
2200 |
|
{ |
2201 |
|
} |
2202 |
12 |
GetAbductCommand::GetAbductCommand(const std::string& name, |
2203 |
|
api::Term conj, |
2204 |
12 |
api::Grammar* g) |
2205 |
12 |
: d_name(name), d_conj(conj), d_sygus_grammar(g), d_resultStatus(false) |
2206 |
|
{ |
2207 |
12 |
} |
2208 |
|
|
2209 |
|
api::Term GetAbductCommand::getConjecture() const { return d_conj; } |
2210 |
|
|
2211 |
|
const api::Grammar* GetAbductCommand::getGrammar() const |
2212 |
|
{ |
2213 |
|
return d_sygus_grammar; |
2214 |
|
} |
2215 |
|
|
2216 |
|
std::string GetAbductCommand::getAbductName() const { return d_name; } |
2217 |
|
api::Term GetAbductCommand::getResult() const { return d_result; } |
2218 |
|
|
2219 |
12 |
void GetAbductCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2220 |
|
{ |
2221 |
|
try |
2222 |
|
{ |
2223 |
12 |
if (d_sygus_grammar == nullptr) |
2224 |
|
{ |
2225 |
8 |
d_resultStatus = solver->getAbduct(d_conj, d_result); |
2226 |
|
} |
2227 |
|
else |
2228 |
|
{ |
2229 |
4 |
d_resultStatus = solver->getAbduct(d_conj, *d_sygus_grammar, d_result); |
2230 |
|
} |
2231 |
10 |
d_commandStatus = CommandSuccess::instance(); |
2232 |
|
} |
2233 |
4 |
catch (exception& e) |
2234 |
|
{ |
2235 |
2 |
d_commandStatus = new CommandFailure(e.what()); |
2236 |
|
} |
2237 |
12 |
} |
2238 |
|
|
2239 |
12 |
void GetAbductCommand::printResult(std::ostream& out, uint32_t verbosity) const |
2240 |
|
{ |
2241 |
12 |
if (!ok()) |
2242 |
|
{ |
2243 |
2 |
this->Command::printResult(out, verbosity); |
2244 |
|
} |
2245 |
|
else |
2246 |
|
{ |
2247 |
20 |
expr::ExprDag::Scope scope(out, false); |
2248 |
10 |
if (d_resultStatus) |
2249 |
|
{ |
2250 |
10 |
out << "(define-fun " << d_name << " () Bool " << d_result << ")" |
2251 |
10 |
<< std::endl; |
2252 |
|
} |
2253 |
|
else |
2254 |
|
{ |
2255 |
|
out << "none" << std::endl; |
2256 |
|
} |
2257 |
|
} |
2258 |
12 |
} |
2259 |
|
|
2260 |
|
Command* GetAbductCommand::clone() const |
2261 |
|
{ |
2262 |
|
GetAbductCommand* c = new GetAbductCommand(d_name, d_conj, d_sygus_grammar); |
2263 |
|
c->d_result = d_result; |
2264 |
|
c->d_resultStatus = d_resultStatus; |
2265 |
|
return c; |
2266 |
|
} |
2267 |
|
|
2268 |
24 |
std::string GetAbductCommand::getCommandName() const { return "get-abduct"; } |
2269 |
|
|
2270 |
|
void GetAbductCommand::toStream(std::ostream& out, |
2271 |
|
int toDepth, |
2272 |
|
size_t dag, |
2273 |
|
OutputLanguage language) const |
2274 |
|
{ |
2275 |
|
Printer::getPrinter(language)->toStreamCmdGetAbduct( |
2276 |
|
out, d_name, termToNode(d_conj), grammarToTypeNode(d_sygus_grammar)); |
2277 |
|
} |
2278 |
|
|
2279 |
|
/* -------------------------------------------------------------------------- */ |
2280 |
|
/* class GetQuantifierEliminationCommand */ |
2281 |
|
/* -------------------------------------------------------------------------- */ |
2282 |
|
|
2283 |
|
GetQuantifierEliminationCommand::GetQuantifierEliminationCommand() |
2284 |
|
: d_term(), d_doFull(true) |
2285 |
|
{ |
2286 |
|
} |
2287 |
8 |
GetQuantifierEliminationCommand::GetQuantifierEliminationCommand( |
2288 |
8 |
const api::Term& term, bool doFull) |
2289 |
8 |
: d_term(term), d_doFull(doFull) |
2290 |
|
{ |
2291 |
8 |
} |
2292 |
|
|
2293 |
|
api::Term GetQuantifierEliminationCommand::getTerm() const { return d_term; } |
2294 |
|
bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull; } |
2295 |
8 |
void GetQuantifierEliminationCommand::invoke(api::Solver* solver, |
2296 |
|
SymbolManager* sm) |
2297 |
|
{ |
2298 |
|
try |
2299 |
|
{ |
2300 |
8 |
if (d_doFull) |
2301 |
|
{ |
2302 |
7 |
d_result = solver->getQuantifierElimination(d_term); |
2303 |
|
} |
2304 |
|
else |
2305 |
|
{ |
2306 |
1 |
d_result = solver->getQuantifierEliminationDisjunct(d_term); |
2307 |
|
} |
2308 |
8 |
d_commandStatus = CommandSuccess::instance(); |
2309 |
|
} |
2310 |
|
catch (exception& e) |
2311 |
|
{ |
2312 |
|
d_commandStatus = new CommandFailure(e.what()); |
2313 |
|
} |
2314 |
8 |
} |
2315 |
|
|
2316 |
|
api::Term GetQuantifierEliminationCommand::getResult() const |
2317 |
|
{ |
2318 |
|
return d_result; |
2319 |
|
} |
2320 |
8 |
void GetQuantifierEliminationCommand::printResult(std::ostream& out, |
2321 |
|
uint32_t verbosity) const |
2322 |
|
{ |
2323 |
8 |
if (!ok()) |
2324 |
|
{ |
2325 |
|
this->Command::printResult(out, verbosity); |
2326 |
|
} |
2327 |
|
else |
2328 |
|
{ |
2329 |
8 |
out << d_result << endl; |
2330 |
|
} |
2331 |
8 |
} |
2332 |
|
|
2333 |
|
Command* GetQuantifierEliminationCommand::clone() const |
2334 |
|
{ |
2335 |
|
GetQuantifierEliminationCommand* c = |
2336 |
|
new GetQuantifierEliminationCommand(d_term, d_doFull); |
2337 |
|
c->d_result = d_result; |
2338 |
|
return c; |
2339 |
|
} |
2340 |
|
|
2341 |
16 |
std::string GetQuantifierEliminationCommand::getCommandName() const |
2342 |
|
{ |
2343 |
16 |
return d_doFull ? "get-qe" : "get-qe-disjunct"; |
2344 |
|
} |
2345 |
|
|
2346 |
|
void GetQuantifierEliminationCommand::toStream(std::ostream& out, |
2347 |
|
int toDepth, |
2348 |
|
size_t dag, |
2349 |
|
OutputLanguage language) const |
2350 |
|
{ |
2351 |
|
Printer::getPrinter(language)->toStreamCmdGetQuantifierElimination( |
2352 |
|
out, termToNode(d_term)); |
2353 |
|
} |
2354 |
|
|
2355 |
|
/* -------------------------------------------------------------------------- */ |
2356 |
|
/* class GetUnsatAssumptionsCommand */ |
2357 |
|
/* -------------------------------------------------------------------------- */ |
2358 |
|
|
2359 |
11 |
GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {} |
2360 |
|
|
2361 |
11 |
void GetUnsatAssumptionsCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2362 |
|
{ |
2363 |
|
try |
2364 |
|
{ |
2365 |
11 |
d_result = solver->getUnsatAssumptions(); |
2366 |
11 |
d_commandStatus = CommandSuccess::instance(); |
2367 |
|
} |
2368 |
|
catch (api::CVC5ApiRecoverableException& e) |
2369 |
|
{ |
2370 |
|
d_commandStatus = new CommandRecoverableFailure(e.what()); |
2371 |
|
} |
2372 |
|
catch (exception& e) |
2373 |
|
{ |
2374 |
|
d_commandStatus = new CommandFailure(e.what()); |
2375 |
|
} |
2376 |
11 |
} |
2377 |
|
|
2378 |
|
std::vector<api::Term> GetUnsatAssumptionsCommand::getResult() const |
2379 |
|
{ |
2380 |
|
return d_result; |
2381 |
|
} |
2382 |
|
|
2383 |
11 |
void GetUnsatAssumptionsCommand::printResult(std::ostream& out, |
2384 |
|
uint32_t verbosity) const |
2385 |
|
{ |
2386 |
11 |
if (!ok()) |
2387 |
|
{ |
2388 |
|
this->Command::printResult(out, verbosity); |
2389 |
|
} |
2390 |
|
else |
2391 |
|
{ |
2392 |
11 |
container_to_stream(out, d_result, "(", ")\n", " "); |
2393 |
|
} |
2394 |
11 |
} |
2395 |
|
|
2396 |
|
Command* GetUnsatAssumptionsCommand::clone() const |
2397 |
|
{ |
2398 |
|
GetUnsatAssumptionsCommand* c = new GetUnsatAssumptionsCommand; |
2399 |
|
c->d_result = d_result; |
2400 |
|
return c; |
2401 |
|
} |
2402 |
|
|
2403 |
22 |
std::string GetUnsatAssumptionsCommand::getCommandName() const |
2404 |
|
{ |
2405 |
22 |
return "get-unsat-assumptions"; |
2406 |
|
} |
2407 |
|
|
2408 |
|
void GetUnsatAssumptionsCommand::toStream(std::ostream& out, |
2409 |
|
int toDepth, |
2410 |
|
size_t dag, |
2411 |
|
OutputLanguage language) const |
2412 |
|
{ |
2413 |
|
Printer::getPrinter(language)->toStreamCmdGetUnsatAssumptions(out); |
2414 |
|
} |
2415 |
|
|
2416 |
|
/* -------------------------------------------------------------------------- */ |
2417 |
|
/* class GetUnsatCoreCommand */ |
2418 |
|
/* -------------------------------------------------------------------------- */ |
2419 |
|
|
2420 |
14 |
GetUnsatCoreCommand::GetUnsatCoreCommand() : d_sm(nullptr) {} |
2421 |
14 |
void GetUnsatCoreCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2422 |
|
{ |
2423 |
|
try |
2424 |
|
{ |
2425 |
14 |
d_sm = sm; |
2426 |
14 |
d_result = solver->getUnsatCore(); |
2427 |
|
|
2428 |
12 |
d_commandStatus = CommandSuccess::instance(); |
2429 |
|
} |
2430 |
4 |
catch (api::CVC5ApiRecoverableException& e) |
2431 |
|
{ |
2432 |
2 |
d_commandStatus = new CommandRecoverableFailure(e.what()); |
2433 |
|
} |
2434 |
|
catch (exception& e) |
2435 |
|
{ |
2436 |
|
d_commandStatus = new CommandFailure(e.what()); |
2437 |
|
} |
2438 |
14 |
} |
2439 |
|
|
2440 |
14 |
void GetUnsatCoreCommand::printResult(std::ostream& out, |
2441 |
|
uint32_t verbosity) const |
2442 |
|
{ |
2443 |
14 |
if (!ok()) |
2444 |
|
{ |
2445 |
2 |
this->Command::printResult(out, verbosity); |
2446 |
|
} |
2447 |
|
else |
2448 |
|
{ |
2449 |
9878 |
if (options::dumpUnsatCoresFull()) |
2450 |
|
{ |
2451 |
|
// use the assertions |
2452 |
6 |
UnsatCore ucr(termVectorToNodes(d_result)); |
2453 |
3 |
ucr.toStream(out); |
2454 |
|
} |
2455 |
|
else |
2456 |
|
{ |
2457 |
|
// otherwise, use the names |
2458 |
18 |
std::vector<std::string> names; |
2459 |
9 |
d_sm->getExpressionNames(d_result, names, true); |
2460 |
18 |
UnsatCore ucr(names); |
2461 |
9 |
ucr.toStream(out); |
2462 |
|
} |
2463 |
|
} |
2464 |
14 |
} |
2465 |
|
|
2466 |
|
const std::vector<api::Term>& GetUnsatCoreCommand::getUnsatCore() const |
2467 |
|
{ |
2468 |
|
// of course, this will be empty if the command hasn't been invoked yet |
2469 |
|
return d_result; |
2470 |
|
} |
2471 |
|
|
2472 |
|
Command* GetUnsatCoreCommand::clone() const |
2473 |
|
{ |
2474 |
|
GetUnsatCoreCommand* c = new GetUnsatCoreCommand; |
2475 |
|
c->d_sm = d_sm; |
2476 |
|
c->d_result = d_result; |
2477 |
|
return c; |
2478 |
|
} |
2479 |
|
|
2480 |
28 |
std::string GetUnsatCoreCommand::getCommandName() const |
2481 |
|
{ |
2482 |
28 |
return "get-unsat-core"; |
2483 |
|
} |
2484 |
|
|
2485 |
|
void GetUnsatCoreCommand::toStream(std::ostream& out, |
2486 |
|
int toDepth, |
2487 |
|
size_t dag, |
2488 |
|
OutputLanguage language) const |
2489 |
|
{ |
2490 |
|
Printer::getPrinter(language)->toStreamCmdGetUnsatCore(out); |
2491 |
|
} |
2492 |
|
|
2493 |
|
/* -------------------------------------------------------------------------- */ |
2494 |
|
/* class GetAssertionsCommand */ |
2495 |
|
/* -------------------------------------------------------------------------- */ |
2496 |
|
|
2497 |
|
GetAssertionsCommand::GetAssertionsCommand() {} |
2498 |
|
void GetAssertionsCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2499 |
|
{ |
2500 |
|
try |
2501 |
|
{ |
2502 |
|
stringstream ss; |
2503 |
|
const vector<api::Term> v = solver->getAssertions(); |
2504 |
|
ss << "(\n"; |
2505 |
|
copy(v.begin(), v.end(), ostream_iterator<api::Term>(ss, "\n")); |
2506 |
|
ss << ")\n"; |
2507 |
|
d_result = ss.str(); |
2508 |
|
d_commandStatus = CommandSuccess::instance(); |
2509 |
|
} |
2510 |
|
catch (exception& e) |
2511 |
|
{ |
2512 |
|
d_commandStatus = new CommandFailure(e.what()); |
2513 |
|
} |
2514 |
|
} |
2515 |
|
|
2516 |
|
std::string GetAssertionsCommand::getResult() const { return d_result; } |
2517 |
|
void GetAssertionsCommand::printResult(std::ostream& out, |
2518 |
|
uint32_t verbosity) const |
2519 |
|
{ |
2520 |
|
if (!ok()) |
2521 |
|
{ |
2522 |
|
this->Command::printResult(out, verbosity); |
2523 |
|
} |
2524 |
|
else |
2525 |
|
{ |
2526 |
|
out << d_result; |
2527 |
|
} |
2528 |
|
} |
2529 |
|
|
2530 |
|
Command* GetAssertionsCommand::clone() const |
2531 |
|
{ |
2532 |
|
GetAssertionsCommand* c = new GetAssertionsCommand(); |
2533 |
|
c->d_result = d_result; |
2534 |
|
return c; |
2535 |
|
} |
2536 |
|
|
2537 |
|
std::string GetAssertionsCommand::getCommandName() const |
2538 |
|
{ |
2539 |
|
return "get-assertions"; |
2540 |
|
} |
2541 |
|
|
2542 |
|
void GetAssertionsCommand::toStream(std::ostream& out, |
2543 |
|
int toDepth, |
2544 |
|
size_t dag, |
2545 |
|
OutputLanguage language) const |
2546 |
|
{ |
2547 |
|
Printer::getPrinter(language)->toStreamCmdGetAssertions(out); |
2548 |
|
} |
2549 |
|
|
2550 |
|
/* -------------------------------------------------------------------------- */ |
2551 |
|
/* class SetBenchmarkStatusCommand */ |
2552 |
|
/* -------------------------------------------------------------------------- */ |
2553 |
|
|
2554 |
|
SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status) |
2555 |
|
: d_status(status) |
2556 |
|
{ |
2557 |
|
} |
2558 |
|
|
2559 |
|
BenchmarkStatus SetBenchmarkStatusCommand::getStatus() const |
2560 |
|
{ |
2561 |
|
return d_status; |
2562 |
|
} |
2563 |
|
|
2564 |
|
void SetBenchmarkStatusCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2565 |
|
{ |
2566 |
|
try |
2567 |
|
{ |
2568 |
|
stringstream ss; |
2569 |
|
ss << d_status; |
2570 |
|
solver->setInfo("status", ss.str()); |
2571 |
|
d_commandStatus = CommandSuccess::instance(); |
2572 |
|
} |
2573 |
|
catch (exception& e) |
2574 |
|
{ |
2575 |
|
d_commandStatus = new CommandFailure(e.what()); |
2576 |
|
} |
2577 |
|
} |
2578 |
|
|
2579 |
|
Command* SetBenchmarkStatusCommand::clone() const |
2580 |
|
{ |
2581 |
|
return new SetBenchmarkStatusCommand(d_status); |
2582 |
|
} |
2583 |
|
|
2584 |
|
std::string SetBenchmarkStatusCommand::getCommandName() const |
2585 |
|
{ |
2586 |
|
return "set-info"; |
2587 |
|
} |
2588 |
|
|
2589 |
|
void SetBenchmarkStatusCommand::toStream(std::ostream& out, |
2590 |
|
int toDepth, |
2591 |
|
size_t dag, |
2592 |
|
OutputLanguage language) const |
2593 |
|
{ |
2594 |
|
Result::Sat status = Result::SAT_UNKNOWN; |
2595 |
|
switch (d_status) |
2596 |
|
{ |
2597 |
|
case BenchmarkStatus::SMT_SATISFIABLE: status = Result::SAT; break; |
2598 |
|
case BenchmarkStatus::SMT_UNSATISFIABLE: status = Result::UNSAT; break; |
2599 |
|
case BenchmarkStatus::SMT_UNKNOWN: status = Result::SAT_UNKNOWN; break; |
2600 |
|
} |
2601 |
|
|
2602 |
|
Printer::getPrinter(language)->toStreamCmdSetBenchmarkStatus(out, status); |
2603 |
|
} |
2604 |
|
|
2605 |
|
/* -------------------------------------------------------------------------- */ |
2606 |
|
/* class SetBenchmarkLogicCommand */ |
2607 |
|
/* -------------------------------------------------------------------------- */ |
2608 |
|
|
2609 |
5571 |
SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic) |
2610 |
5571 |
: d_logic(logic) |
2611 |
|
{ |
2612 |
5571 |
} |
2613 |
|
|
2614 |
|
std::string SetBenchmarkLogicCommand::getLogic() const { return d_logic; } |
2615 |
5529 |
void SetBenchmarkLogicCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2616 |
|
{ |
2617 |
|
try |
2618 |
|
{ |
2619 |
5529 |
solver->setLogic(d_logic); |
2620 |
5529 |
d_commandStatus = CommandSuccess::instance(); |
2621 |
|
} |
2622 |
|
catch (exception& e) |
2623 |
|
{ |
2624 |
|
d_commandStatus = new CommandFailure(e.what()); |
2625 |
|
} |
2626 |
5529 |
} |
2627 |
|
|
2628 |
|
Command* SetBenchmarkLogicCommand::clone() const |
2629 |
|
{ |
2630 |
|
return new SetBenchmarkLogicCommand(d_logic); |
2631 |
|
} |
2632 |
|
|
2633 |
11058 |
std::string SetBenchmarkLogicCommand::getCommandName() const |
2634 |
|
{ |
2635 |
11058 |
return "set-logic"; |
2636 |
|
} |
2637 |
|
|
2638 |
1 |
void SetBenchmarkLogicCommand::toStream(std::ostream& out, |
2639 |
|
int toDepth, |
2640 |
|
size_t dag, |
2641 |
|
OutputLanguage language) const |
2642 |
|
{ |
2643 |
1 |
Printer::getPrinter(language)->toStreamCmdSetBenchmarkLogic(out, d_logic); |
2644 |
1 |
} |
2645 |
|
|
2646 |
|
/* -------------------------------------------------------------------------- */ |
2647 |
|
/* class SetInfoCommand */ |
2648 |
|
/* -------------------------------------------------------------------------- */ |
2649 |
|
|
2650 |
5683 |
SetInfoCommand::SetInfoCommand(const std::string& flag, |
2651 |
5683 |
const std::string& value) |
2652 |
5683 |
: d_flag(flag), d_value(value) |
2653 |
|
{ |
2654 |
5683 |
} |
2655 |
|
|
2656 |
|
const std::string& SetInfoCommand::getFlag() const { return d_flag; } |
2657 |
|
const std::string& SetInfoCommand::getValue() const { return d_value; } |
2658 |
5679 |
void SetInfoCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2659 |
|
{ |
2660 |
|
try |
2661 |
|
{ |
2662 |
5679 |
solver->setInfo(d_flag, d_value); |
2663 |
5666 |
d_commandStatus = CommandSuccess::instance(); |
2664 |
|
} |
2665 |
26 |
catch (api::CVC5ApiRecoverableException&) |
2666 |
|
{ |
2667 |
|
// As per SMT-LIB spec, silently accept unknown set-info keys |
2668 |
13 |
d_commandStatus = CommandSuccess::instance(); |
2669 |
|
} |
2670 |
|
catch (exception& e) |
2671 |
|
{ |
2672 |
|
d_commandStatus = new CommandFailure(e.what()); |
2673 |
|
} |
2674 |
5679 |
} |
2675 |
|
|
2676 |
|
Command* SetInfoCommand::clone() const |
2677 |
|
{ |
2678 |
|
return new SetInfoCommand(d_flag, d_value); |
2679 |
|
} |
2680 |
|
|
2681 |
11358 |
std::string SetInfoCommand::getCommandName() const { return "set-info"; } |
2682 |
|
|
2683 |
|
void SetInfoCommand::toStream(std::ostream& out, |
2684 |
|
int toDepth, |
2685 |
|
size_t dag, |
2686 |
|
OutputLanguage language) const |
2687 |
|
{ |
2688 |
|
Printer::getPrinter(language)->toStreamCmdSetInfo(out, d_flag, d_value); |
2689 |
|
} |
2690 |
|
|
2691 |
|
/* -------------------------------------------------------------------------- */ |
2692 |
|
/* class GetInfoCommand */ |
2693 |
|
/* -------------------------------------------------------------------------- */ |
2694 |
|
|
2695 |
20 |
GetInfoCommand::GetInfoCommand(std::string flag) : d_flag(flag) {} |
2696 |
|
std::string GetInfoCommand::getFlag() const { return d_flag; } |
2697 |
20 |
void GetInfoCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2698 |
|
{ |
2699 |
|
try |
2700 |
|
{ |
2701 |
40 |
std::vector<api::Term> v; |
2702 |
20 |
v.push_back(solver->mkString(":" + d_flag)); |
2703 |
20 |
v.push_back(solver->mkString(solver->getInfo(d_flag))); |
2704 |
12 |
d_result = sexprToString(solver->mkTerm(api::SEXPR, v)); |
2705 |
12 |
d_commandStatus = CommandSuccess::instance(); |
2706 |
|
} |
2707 |
14 |
catch (api::CVC5ApiRecoverableException& e) |
2708 |
|
{ |
2709 |
7 |
d_commandStatus = new CommandRecoverableFailure(e.what()); |
2710 |
|
} |
2711 |
2 |
catch (exception& e) |
2712 |
|
{ |
2713 |
1 |
d_commandStatus = new CommandFailure(e.what()); |
2714 |
|
} |
2715 |
20 |
} |
2716 |
|
|
2717 |
|
std::string GetInfoCommand::getResult() const { return d_result; } |
2718 |
20 |
void GetInfoCommand::printResult(std::ostream& out, uint32_t verbosity) const |
2719 |
|
{ |
2720 |
20 |
if (!ok()) |
2721 |
|
{ |
2722 |
8 |
this->Command::printResult(out, verbosity); |
2723 |
|
} |
2724 |
12 |
else if (d_result != "") |
2725 |
|
{ |
2726 |
12 |
out << d_result << endl; |
2727 |
|
} |
2728 |
20 |
} |
2729 |
|
|
2730 |
|
Command* GetInfoCommand::clone() const |
2731 |
|
{ |
2732 |
|
GetInfoCommand* c = new GetInfoCommand(d_flag); |
2733 |
|
c->d_result = d_result; |
2734 |
|
return c; |
2735 |
|
} |
2736 |
|
|
2737 |
29 |
std::string GetInfoCommand::getCommandName() const { return "get-info"; } |
2738 |
|
|
2739 |
11 |
void GetInfoCommand::toStream(std::ostream& out, |
2740 |
|
int toDepth, |
2741 |
|
size_t dag, |
2742 |
|
OutputLanguage language) const |
2743 |
|
{ |
2744 |
11 |
Printer::getPrinter(language)->toStreamCmdGetInfo(out, d_flag); |
2745 |
11 |
} |
2746 |
|
|
2747 |
|
/* -------------------------------------------------------------------------- */ |
2748 |
|
/* class SetOptionCommand */ |
2749 |
|
/* -------------------------------------------------------------------------- */ |
2750 |
|
|
2751 |
7363 |
SetOptionCommand::SetOptionCommand(const std::string& flag, |
2752 |
7363 |
const std::string& value) |
2753 |
7363 |
: d_flag(flag), d_value(value) |
2754 |
|
{ |
2755 |
7363 |
} |
2756 |
|
|
2757 |
|
const std::string& SetOptionCommand::getFlag() const { return d_flag; } |
2758 |
|
const std::string& SetOptionCommand::getValue() const { return d_value; } |
2759 |
7363 |
void SetOptionCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2760 |
|
{ |
2761 |
|
try |
2762 |
|
{ |
2763 |
7363 |
solver->setOption(d_flag, d_value); |
2764 |
7361 |
d_commandStatus = CommandSuccess::instance(); |
2765 |
|
} |
2766 |
|
catch (api::CVC5ApiRecoverableException&) |
2767 |
|
{ |
2768 |
|
d_commandStatus = new CommandUnsupported(); |
2769 |
|
} |
2770 |
4 |
catch (exception& e) |
2771 |
|
{ |
2772 |
2 |
d_commandStatus = new CommandFailure(e.what()); |
2773 |
|
} |
2774 |
7363 |
} |
2775 |
|
|
2776 |
|
Command* SetOptionCommand::clone() const |
2777 |
|
{ |
2778 |
|
return new SetOptionCommand(d_flag, d_value); |
2779 |
|
} |
2780 |
|
|
2781 |
9261 |
std::string SetOptionCommand::getCommandName() const { return "set-option"; } |
2782 |
|
|
2783 |
1 |
void SetOptionCommand::toStream(std::ostream& out, |
2784 |
|
int toDepth, |
2785 |
|
size_t dag, |
2786 |
|
OutputLanguage language) const |
2787 |
|
{ |
2788 |
1 |
Printer::getPrinter(language)->toStreamCmdSetOption(out, d_flag, d_value); |
2789 |
1 |
} |
2790 |
|
|
2791 |
|
/* -------------------------------------------------------------------------- */ |
2792 |
|
/* class GetOptionCommand */ |
2793 |
|
/* -------------------------------------------------------------------------- */ |
2794 |
|
|
2795 |
41 |
GetOptionCommand::GetOptionCommand(std::string flag) : d_flag(flag) {} |
2796 |
|
std::string GetOptionCommand::getFlag() const { return d_flag; } |
2797 |
41 |
void GetOptionCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2798 |
|
{ |
2799 |
|
try |
2800 |
|
{ |
2801 |
41 |
d_result = solver->getOption(d_flag); |
2802 |
41 |
d_commandStatus = CommandSuccess::instance(); |
2803 |
|
} |
2804 |
|
catch (api::CVC5ApiRecoverableException&) |
2805 |
|
{ |
2806 |
|
d_commandStatus = new CommandUnsupported(); |
2807 |
|
} |
2808 |
|
catch (exception& e) |
2809 |
|
{ |
2810 |
|
d_commandStatus = new CommandFailure(e.what()); |
2811 |
|
} |
2812 |
41 |
} |
2813 |
|
|
2814 |
|
std::string GetOptionCommand::getResult() const { return d_result; } |
2815 |
41 |
void GetOptionCommand::printResult(std::ostream& out, uint32_t verbosity) const |
2816 |
|
{ |
2817 |
41 |
if (!ok()) |
2818 |
|
{ |
2819 |
|
this->Command::printResult(out, verbosity); |
2820 |
|
} |
2821 |
41 |
else if (d_result != "") |
2822 |
|
{ |
2823 |
41 |
out << d_result << endl; |
2824 |
|
} |
2825 |
41 |
} |
2826 |
|
|
2827 |
|
Command* GetOptionCommand::clone() const |
2828 |
|
{ |
2829 |
|
GetOptionCommand* c = new GetOptionCommand(d_flag); |
2830 |
|
c->d_result = d_result; |
2831 |
|
return c; |
2832 |
|
} |
2833 |
|
|
2834 |
82 |
std::string GetOptionCommand::getCommandName() const { return "get-option"; } |
2835 |
|
|
2836 |
|
void GetOptionCommand::toStream(std::ostream& out, |
2837 |
|
int toDepth, |
2838 |
|
size_t dag, |
2839 |
|
OutputLanguage language) const |
2840 |
|
{ |
2841 |
|
Printer::getPrinter(language)->toStreamCmdGetOption(out, d_flag); |
2842 |
|
} |
2843 |
|
|
2844 |
|
/* -------------------------------------------------------------------------- */ |
2845 |
|
/* class DatatypeDeclarationCommand */ |
2846 |
|
/* -------------------------------------------------------------------------- */ |
2847 |
|
|
2848 |
|
DatatypeDeclarationCommand::DatatypeDeclarationCommand( |
2849 |
|
const api::Sort& datatype) |
2850 |
|
: d_datatypes() |
2851 |
|
{ |
2852 |
|
d_datatypes.push_back(datatype); |
2853 |
|
} |
2854 |
|
|
2855 |
1049 |
DatatypeDeclarationCommand::DatatypeDeclarationCommand( |
2856 |
1049 |
const std::vector<api::Sort>& datatypes) |
2857 |
1049 |
: d_datatypes(datatypes) |
2858 |
|
{ |
2859 |
1049 |
} |
2860 |
|
|
2861 |
|
const std::vector<api::Sort>& DatatypeDeclarationCommand::getDatatypes() const |
2862 |
|
{ |
2863 |
|
return d_datatypes; |
2864 |
|
} |
2865 |
|
|
2866 |
1035 |
void DatatypeDeclarationCommand::invoke(api::Solver* solver, SymbolManager* sm) |
2867 |
|
{ |
2868 |
1035 |
d_commandStatus = CommandSuccess::instance(); |
2869 |
1035 |
} |
2870 |
|
|
2871 |
|
Command* DatatypeDeclarationCommand::clone() const |
2872 |
|
{ |
2873 |
|
return new DatatypeDeclarationCommand(d_datatypes); |
2874 |
|
} |
2875 |
|
|
2876 |
2070 |
std::string DatatypeDeclarationCommand::getCommandName() const |
2877 |
|
{ |
2878 |
2070 |
return "declare-datatypes"; |
2879 |
|
} |
2880 |
|
|
2881 |
|
void DatatypeDeclarationCommand::toStream(std::ostream& out, |
2882 |
|
int toDepth, |
2883 |
|
size_t dag, |
2884 |
|
OutputLanguage language) const |
2885 |
|
{ |
2886 |
|
Printer::getPrinter(language)->toStreamCmdDatatypeDeclaration( |
2887 |
|
out, sortVectorToTypeNodes(d_datatypes)); |
2888 |
|
} |
2889 |
|
|
2890 |
29322 |
} // namespace cvc5 |