1 /********************* */
4 ** Top contributors (to current version):
5 ** Tim King, Morgan Deters, Andrew Reynolds
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2019 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.\endverbatim
12 ** \brief Implementation of command objects.
14 ** Implementation of command objects.
17 #include "smt/command.h"
26 #include "base/check.h"
27 #include "base/output.h"
28 #include "expr/expr_iomanip.h"
29 #include "expr/node.h"
30 #include "options/options.h"
31 #include "options/smt_options.h"
32 #include "printer/printer.h"
34 #include "smt/model.h"
35 #include "smt/smt_engine.h"
36 #include "smt/smt_engine_scope.h"
37 #include "util/sexpr.h"
38 #include "util/utility.h"
46 std::vector
<Expr
> ExportTo(ExprManager
* exprManager
,
47 ExprManagerMapCollection
& variableMap
,
48 const std::vector
<Expr
>& exprs
)
50 std::vector
<Expr
> exported
;
51 exported
.reserve(exprs
.size());
52 for (const Expr
& expr
: exprs
)
54 exported
.push_back(expr
.exportTo(exprManager
, variableMap
));
61 const int CommandPrintSuccess::s_iosIndex
= std::ios_base::xalloc();
62 const CommandSuccess
* CommandSuccess::s_instance
= new CommandSuccess();
63 const CommandInterrupted
* CommandInterrupted::s_instance
=
64 new CommandInterrupted();
66 std::ostream
& operator<<(std::ostream
& out
, const Command
& c
)
69 Node::setdepth::getDepth(out
),
70 Node::printtypes::getPrintTypes(out
),
71 Node::dag::getDag(out
),
72 Node::setlanguage::getLanguage(out
));
76 ostream
& operator<<(ostream
& out
, const Command
* c
)
89 std::ostream
& operator<<(std::ostream
& out
, const CommandStatus
& s
)
91 s
.toStream(out
, Node::setlanguage::getLanguage(out
));
95 ostream
& operator<<(ostream
& out
, const CommandStatus
* s
)
109 /* output stream insertion operator for benchmark statuses */
110 std::ostream
& operator<<(std::ostream
& out
, BenchmarkStatus status
)
114 case SMT_SATISFIABLE
: return out
<< "sat";
116 case SMT_UNSATISFIABLE
: return out
<< "unsat";
118 case SMT_UNKNOWN
: return out
<< "unknown";
120 default: return out
<< "BenchmarkStatus::[UNKNOWNSTATUS!]";
124 /* -------------------------------------------------------------------------- */
125 /* class CommandPrintSuccess */
126 /* -------------------------------------------------------------------------- */
128 void CommandPrintSuccess::applyPrintSuccess(std::ostream
& out
)
130 out
.iword(s_iosIndex
) = d_printSuccess
;
133 bool CommandPrintSuccess::getPrintSuccess(std::ostream
& out
)
135 return out
.iword(s_iosIndex
);
138 void CommandPrintSuccess::setPrintSuccess(std::ostream
& out
, bool printSuccess
)
140 out
.iword(s_iosIndex
) = printSuccess
;
143 std::ostream
& operator<<(std::ostream
& out
, CommandPrintSuccess cps
)
145 cps
.applyPrintSuccess(out
);
149 /* -------------------------------------------------------------------------- */
151 /* -------------------------------------------------------------------------- */
153 Command::Command() : d_commandStatus(NULL
), d_muted(false) {}
154 Command::Command(const Command
& cmd
)
157 (cmd
.d_commandStatus
== NULL
) ? NULL
: &cmd
.d_commandStatus
->clone();
158 d_muted
= cmd
.d_muted
;
163 if (d_commandStatus
!= NULL
&& d_commandStatus
!= CommandSuccess::instance())
165 delete d_commandStatus
;
169 bool Command::ok() const
171 // either we haven't run the command yet, or it ran successfully
172 return d_commandStatus
== NULL
173 || dynamic_cast<const CommandSuccess
*>(d_commandStatus
) != NULL
;
176 bool Command::fail() const
178 return d_commandStatus
!= NULL
179 && dynamic_cast<const CommandFailure
*>(d_commandStatus
) != NULL
;
182 bool Command::interrupted() const
184 return d_commandStatus
!= NULL
185 && dynamic_cast<const CommandInterrupted
*>(d_commandStatus
) != NULL
;
188 void Command::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
191 if (!(isMuted() && ok()))
194 smtEngine
->getOption("command-verbosity:" + getCommandName())
200 std::string
Command::toString() const
202 std::stringstream ss
;
207 void Command::toStream(std::ostream
& out
,
211 OutputLanguage language
) const
213 Printer::getPrinter(language
)->toStream(out
, this, toDepth
, types
, dag
);
216 void CommandStatus::toStream(std::ostream
& out
, OutputLanguage language
) const
218 Printer::getPrinter(language
)->toStream(out
, this);
221 void Command::printResult(std::ostream
& out
, uint32_t verbosity
) const
223 if (d_commandStatus
!= NULL
)
225 if ((!ok() && verbosity
>= 1) || verbosity
>= 2)
227 out
<< *d_commandStatus
;
232 /* -------------------------------------------------------------------------- */
233 /* class EmptyCommand */
234 /* -------------------------------------------------------------------------- */
236 EmptyCommand::EmptyCommand(std::string name
) : d_name(name
) {}
237 std::string
EmptyCommand::getName() const { return d_name
; }
238 void EmptyCommand::invoke(SmtEngine
* smtEngine
)
240 /* empty commands have no implementation */
241 d_commandStatus
= CommandSuccess::instance();
244 Command
* EmptyCommand::exportTo(ExprManager
* exprManager
,
245 ExprManagerMapCollection
& variableMap
)
247 return new EmptyCommand(d_name
);
250 Command
* EmptyCommand::clone() const { return new EmptyCommand(d_name
); }
251 std::string
EmptyCommand::getCommandName() const { return "empty"; }
253 /* -------------------------------------------------------------------------- */
254 /* class EchoCommand */
255 /* -------------------------------------------------------------------------- */
257 EchoCommand::EchoCommand(std::string output
) : d_output(output
) {}
258 std::string
EchoCommand::getOutput() const { return d_output
; }
259 void EchoCommand::invoke(SmtEngine
* smtEngine
)
261 /* we don't have an output stream here, nothing to do */
262 d_commandStatus
= CommandSuccess::instance();
265 void EchoCommand::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
267 out
<< d_output
<< std::endl
;
268 Trace("dtview::command") << "* ~COMMAND: echo |" << d_output
<< "|~"
270 d_commandStatus
= CommandSuccess::instance();
272 smtEngine
->getOption("command-verbosity:" + getCommandName())
277 Command
* EchoCommand::exportTo(ExprManager
* exprManager
,
278 ExprManagerMapCollection
& variableMap
)
280 return new EchoCommand(d_output
);
283 Command
* EchoCommand::clone() const { return new EchoCommand(d_output
); }
284 std::string
EchoCommand::getCommandName() const { return "echo"; }
286 /* -------------------------------------------------------------------------- */
287 /* class AssertCommand */
288 /* -------------------------------------------------------------------------- */
290 AssertCommand::AssertCommand(const Expr
& e
, bool inUnsatCore
)
291 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
295 Expr
AssertCommand::getExpr() const { return d_expr
; }
296 void AssertCommand::invoke(SmtEngine
* smtEngine
)
300 smtEngine
->assertFormula(d_expr
, d_inUnsatCore
);
301 d_commandStatus
= CommandSuccess::instance();
303 catch (UnsafeInterruptException
& e
)
305 d_commandStatus
= new CommandInterrupted();
309 d_commandStatus
= new CommandFailure(e
.what());
313 Command
* AssertCommand::exportTo(ExprManager
* exprManager
,
314 ExprManagerMapCollection
& variableMap
)
316 return new AssertCommand(d_expr
.exportTo(exprManager
, variableMap
),
320 Command
* AssertCommand::clone() const
322 return new AssertCommand(d_expr
, d_inUnsatCore
);
325 std::string
AssertCommand::getCommandName() const { return "assert"; }
327 /* -------------------------------------------------------------------------- */
328 /* class PushCommand */
329 /* -------------------------------------------------------------------------- */
331 void PushCommand::invoke(SmtEngine
* smtEngine
)
336 d_commandStatus
= CommandSuccess::instance();
338 catch (UnsafeInterruptException
& e
)
340 d_commandStatus
= new CommandInterrupted();
344 d_commandStatus
= new CommandFailure(e
.what());
348 Command
* PushCommand::exportTo(ExprManager
* exprManager
,
349 ExprManagerMapCollection
& variableMap
)
351 return new PushCommand();
354 Command
* PushCommand::clone() const { return new PushCommand(); }
355 std::string
PushCommand::getCommandName() const { return "push"; }
357 /* -------------------------------------------------------------------------- */
358 /* class PopCommand */
359 /* -------------------------------------------------------------------------- */
361 void PopCommand::invoke(SmtEngine
* smtEngine
)
366 d_commandStatus
= CommandSuccess::instance();
368 catch (UnsafeInterruptException
& e
)
370 d_commandStatus
= new CommandInterrupted();
374 d_commandStatus
= new CommandFailure(e
.what());
378 Command
* PopCommand::exportTo(ExprManager
* exprManager
,
379 ExprManagerMapCollection
& variableMap
)
381 return new PopCommand();
384 Command
* PopCommand::clone() const { return new PopCommand(); }
385 std::string
PopCommand::getCommandName() const { return "pop"; }
387 /* -------------------------------------------------------------------------- */
388 /* class CheckSatCommand */
389 /* -------------------------------------------------------------------------- */
391 CheckSatCommand::CheckSatCommand() : d_expr() {}
393 CheckSatCommand::CheckSatCommand(const Expr
& expr
) : d_expr(expr
) {}
395 Expr
CheckSatCommand::getExpr() const { return d_expr
; }
396 void CheckSatCommand::invoke(SmtEngine
* smtEngine
)
398 Trace("dtview::command") << "* ~COMMAND: " << getCommandName() << "~"
402 d_result
= smtEngine
->checkSat(d_expr
);
403 d_commandStatus
= CommandSuccess::instance();
407 d_commandStatus
= new CommandFailure(e
.what());
411 Result
CheckSatCommand::getResult() const { return d_result
; }
412 void CheckSatCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
416 this->Command::printResult(out
, verbosity
);
420 Trace("dtview::command") << "* RESULT: " << d_result
<< std::endl
;
421 out
<< d_result
<< endl
;
425 Command
* CheckSatCommand::exportTo(ExprManager
* exprManager
,
426 ExprManagerMapCollection
& variableMap
)
429 new CheckSatCommand(d_expr
.exportTo(exprManager
, variableMap
));
430 c
->d_result
= d_result
;
434 Command
* CheckSatCommand::clone() const
436 CheckSatCommand
* c
= new CheckSatCommand(d_expr
);
437 c
->d_result
= d_result
;
441 std::string
CheckSatCommand::getCommandName() const { return "check-sat"; }
443 /* -------------------------------------------------------------------------- */
444 /* class CheckSatAssumingCommand */
445 /* -------------------------------------------------------------------------- */
447 CheckSatAssumingCommand::CheckSatAssumingCommand(Expr term
) : d_terms({term
}) {}
449 CheckSatAssumingCommand::CheckSatAssumingCommand(const std::vector
<Expr
>& terms
)
454 const std::vector
<Expr
>& CheckSatAssumingCommand::getTerms() const
459 void CheckSatAssumingCommand::invoke(SmtEngine
* smtEngine
)
461 Trace("dtview::command") << "* ~COMMAND: (check-sat-assuming ( " << d_terms
462 << " )~" << std::endl
;
465 d_result
= smtEngine
->checkSat(d_terms
);
466 d_commandStatus
= CommandSuccess::instance();
470 d_commandStatus
= new CommandFailure(e
.what());
474 Result
CheckSatAssumingCommand::getResult() const
476 Trace("dtview::command") << "* ~RESULT: " << d_result
<< "~" << std::endl
;
480 void CheckSatAssumingCommand::printResult(std::ostream
& out
,
481 uint32_t verbosity
) const
485 this->Command::printResult(out
, verbosity
);
489 out
<< d_result
<< endl
;
493 Command
* CheckSatAssumingCommand::exportTo(
494 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
496 vector
<Expr
> exportedTerms
;
497 for (const Expr
& e
: d_terms
)
499 exportedTerms
.push_back(e
.exportTo(exprManager
, variableMap
));
501 CheckSatAssumingCommand
* c
= new CheckSatAssumingCommand(exportedTerms
);
502 c
->d_result
= d_result
;
506 Command
* CheckSatAssumingCommand::clone() const
508 CheckSatAssumingCommand
* c
= new CheckSatAssumingCommand(d_terms
);
509 c
->d_result
= d_result
;
513 std::string
CheckSatAssumingCommand::getCommandName() const
515 return "check-sat-assuming";
518 /* -------------------------------------------------------------------------- */
519 /* class QueryCommand */
520 /* -------------------------------------------------------------------------- */
522 QueryCommand::QueryCommand(const Expr
& e
, bool inUnsatCore
)
523 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
527 Expr
QueryCommand::getExpr() const { return d_expr
; }
528 void QueryCommand::invoke(SmtEngine
* smtEngine
)
532 d_result
= smtEngine
->query(d_expr
);
533 d_commandStatus
= CommandSuccess::instance();
537 d_commandStatus
= new CommandFailure(e
.what());
541 Result
QueryCommand::getResult() const { return d_result
; }
542 void QueryCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
546 this->Command::printResult(out
, verbosity
);
550 out
<< d_result
<< endl
;
554 Command
* QueryCommand::exportTo(ExprManager
* exprManager
,
555 ExprManagerMapCollection
& variableMap
)
557 QueryCommand
* c
= new QueryCommand(d_expr
.exportTo(exprManager
, variableMap
),
559 c
->d_result
= d_result
;
563 Command
* QueryCommand::clone() const
565 QueryCommand
* c
= new QueryCommand(d_expr
, d_inUnsatCore
);
566 c
->d_result
= d_result
;
570 std::string
QueryCommand::getCommandName() const { return "query"; }
572 /* -------------------------------------------------------------------------- */
573 /* class DeclareSygusVarCommand */
574 /* -------------------------------------------------------------------------- */
576 DeclareSygusVarCommand::DeclareSygusVarCommand(const std::string
& id
,
579 : DeclarationDefinitionCommand(id
), d_var(var
), d_type(t
)
583 Expr
DeclareSygusVarCommand::getVar() const { return d_var
; }
584 Type
DeclareSygusVarCommand::getType() const { return d_type
; }
586 void DeclareSygusVarCommand::invoke(SmtEngine
* smtEngine
)
590 smtEngine
->declareSygusVar(d_symbol
, d_var
, d_type
);
591 d_commandStatus
= CommandSuccess::instance();
595 d_commandStatus
= new CommandFailure(e
.what());
599 Command
* DeclareSygusVarCommand::exportTo(ExprManager
* exprManager
,
600 ExprManagerMapCollection
& variableMap
)
602 return new DeclareSygusVarCommand(d_symbol
,
603 d_var
.exportTo(exprManager
, variableMap
),
604 d_type
.exportTo(exprManager
, variableMap
));
607 Command
* DeclareSygusVarCommand::clone() const
609 return new DeclareSygusVarCommand(d_symbol
, d_var
, d_type
);
612 std::string
DeclareSygusVarCommand::getCommandName() const
614 return "declare-var";
617 /* -------------------------------------------------------------------------- */
618 /* class DeclareSygusPrimedVarCommand */
619 /* -------------------------------------------------------------------------- */
621 DeclareSygusPrimedVarCommand::DeclareSygusPrimedVarCommand(
622 const std::string
& id
, Type t
)
623 : DeclarationDefinitionCommand(id
), d_type(t
)
627 Type
DeclareSygusPrimedVarCommand::getType() const { return d_type
; }
629 void DeclareSygusPrimedVarCommand::invoke(SmtEngine
* smtEngine
)
633 smtEngine
->declareSygusPrimedVar(d_symbol
, d_type
);
634 d_commandStatus
= CommandSuccess::instance();
638 d_commandStatus
= new CommandFailure(e
.what());
642 Command
* DeclareSygusPrimedVarCommand::exportTo(
643 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
645 return new DeclareSygusPrimedVarCommand(
646 d_symbol
, d_type
.exportTo(exprManager
, variableMap
));
649 Command
* DeclareSygusPrimedVarCommand::clone() const
651 return new DeclareSygusPrimedVarCommand(d_symbol
, d_type
);
654 std::string
DeclareSygusPrimedVarCommand::getCommandName() const
656 return "declare-primed-var";
659 /* -------------------------------------------------------------------------- */
660 /* class DeclareSygusFunctionCommand */
661 /* -------------------------------------------------------------------------- */
663 DeclareSygusFunctionCommand::DeclareSygusFunctionCommand(const std::string
& id
,
666 : DeclarationDefinitionCommand(id
), d_func(func
), d_type(t
)
670 Expr
DeclareSygusFunctionCommand::getFunction() const { return d_func
; }
671 Type
DeclareSygusFunctionCommand::getType() const { return d_type
; }
673 void DeclareSygusFunctionCommand::invoke(SmtEngine
* smtEngine
)
677 smtEngine
->declareSygusFunctionVar(d_symbol
, d_func
, d_type
);
678 d_commandStatus
= CommandSuccess::instance();
682 d_commandStatus
= new CommandFailure(e
.what());
686 Command
* DeclareSygusFunctionCommand::exportTo(
687 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
689 return new DeclareSygusFunctionCommand(
691 d_func
.exportTo(exprManager
, variableMap
),
692 d_type
.exportTo(exprManager
, variableMap
));
695 Command
* DeclareSygusFunctionCommand::clone() const
697 return new DeclareSygusFunctionCommand(d_symbol
, d_func
, d_type
);
700 std::string
DeclareSygusFunctionCommand::getCommandName() const
702 return "declare-fun";
705 /* -------------------------------------------------------------------------- */
706 /* class SynthFunCommand */
707 /* -------------------------------------------------------------------------- */
709 SynthFunCommand::SynthFunCommand(const std::string
& id
,
713 const std::vector
<Expr
>& vars
)
714 : DeclarationDefinitionCommand(id
),
716 d_sygusType(sygusType
),
722 SynthFunCommand::SynthFunCommand(const std::string
& id
,
726 : SynthFunCommand(id
, func
, sygusType
, isInv
, {})
730 Expr
SynthFunCommand::getFunction() const { return d_func
; }
731 const std::vector
<Expr
>& SynthFunCommand::getVars() const { return d_vars
; }
732 Type
SynthFunCommand::getSygusType() const { return d_sygusType
; }
733 bool SynthFunCommand::isInv() const { return d_isInv
; }
735 void SynthFunCommand::invoke(SmtEngine
* smtEngine
)
739 smtEngine
->declareSynthFun(d_symbol
, d_func
, d_sygusType
, d_isInv
, d_vars
);
740 d_commandStatus
= CommandSuccess::instance();
744 d_commandStatus
= new CommandFailure(e
.what());
748 Command
* SynthFunCommand::exportTo(ExprManager
* exprManager
,
749 ExprManagerMapCollection
& variableMap
)
751 return new SynthFunCommand(d_symbol
,
752 d_func
.exportTo(exprManager
, variableMap
),
753 d_sygusType
.exportTo(exprManager
, variableMap
),
757 Command
* SynthFunCommand::clone() const
759 return new SynthFunCommand(d_symbol
, d_func
, d_sygusType
, d_isInv
, d_vars
);
762 std::string
SynthFunCommand::getCommandName() const
764 return d_isInv
? "synth-inv" : "synth-fun";
767 /* -------------------------------------------------------------------------- */
768 /* class SygusConstraintCommand */
769 /* -------------------------------------------------------------------------- */
771 SygusConstraintCommand::SygusConstraintCommand(const Expr
& e
) : d_expr(e
) {}
773 void SygusConstraintCommand::invoke(SmtEngine
* smtEngine
)
777 smtEngine
->assertSygusConstraint(d_expr
);
778 d_commandStatus
= CommandSuccess::instance();
782 d_commandStatus
= new CommandFailure(e
.what());
786 Expr
SygusConstraintCommand::getExpr() const { return d_expr
; }
788 Command
* SygusConstraintCommand::exportTo(ExprManager
* exprManager
,
789 ExprManagerMapCollection
& variableMap
)
791 return new SygusConstraintCommand(d_expr
.exportTo(exprManager
, variableMap
));
794 Command
* SygusConstraintCommand::clone() const
796 return new SygusConstraintCommand(d_expr
);
799 std::string
SygusConstraintCommand::getCommandName() const
804 /* -------------------------------------------------------------------------- */
805 /* class SygusInvConstraintCommand */
806 /* -------------------------------------------------------------------------- */
808 SygusInvConstraintCommand::SygusInvConstraintCommand(
809 const std::vector
<Expr
>& predicates
)
810 : d_predicates(predicates
)
814 SygusInvConstraintCommand::SygusInvConstraintCommand(const Expr
& inv
,
818 : SygusInvConstraintCommand(std::vector
<Expr
>{inv
, pre
, trans
, post
})
822 void SygusInvConstraintCommand::invoke(SmtEngine
* smtEngine
)
826 smtEngine
->assertSygusInvConstraint(
827 d_predicates
[0], d_predicates
[1], d_predicates
[2], d_predicates
[3]);
828 d_commandStatus
= CommandSuccess::instance();
832 d_commandStatus
= new CommandFailure(e
.what());
836 const std::vector
<Expr
>& SygusInvConstraintCommand::getPredicates() const
841 Command
* SygusInvConstraintCommand::exportTo(
842 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
844 return new SygusInvConstraintCommand(d_predicates
);
847 Command
* SygusInvConstraintCommand::clone() const
849 return new SygusInvConstraintCommand(d_predicates
);
852 std::string
SygusInvConstraintCommand::getCommandName() const
854 return "inv-constraint";
857 /* -------------------------------------------------------------------------- */
858 /* class CheckSynthCommand */
859 /* -------------------------------------------------------------------------- */
861 void CheckSynthCommand::invoke(SmtEngine
* smtEngine
)
865 d_result
= smtEngine
->checkSynth();
866 d_commandStatus
= CommandSuccess::instance();
867 smt::SmtScope
scope(smtEngine
);
869 // check whether we should print the status
870 if (d_result
.asSatisfiabilityResult() != Result::UNSAT
871 || options::sygusOut() == options::SygusSolutionOutMode::STATUS_AND_DEF
872 || options::sygusOut() == options::SygusSolutionOutMode::STATUS
)
874 if (options::sygusOut() == options::SygusSolutionOutMode::STANDARD
)
876 d_solution
<< "(fail)" << endl
;
880 d_solution
<< d_result
<< endl
;
883 // check whether we should print the solution
884 if (d_result
.asSatisfiabilityResult() == Result::UNSAT
885 && options::sygusOut() != options::SygusSolutionOutMode::STATUS
)
887 // printing a synthesis solution is a non-constant
888 // method, since it invokes a sophisticated algorithm
889 // (Figure 5 of Reynolds et al. CAV 2015).
890 // Hence, we must call here print solution here,
891 // instead of during printResult.
892 smtEngine
->printSynthSolution(d_solution
);
897 d_commandStatus
= new CommandFailure(e
.what());
901 Result
CheckSynthCommand::getResult() const { return d_result
; }
902 void CheckSynthCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
906 this->Command::printResult(out
, verbosity
);
910 out
<< d_solution
.str();
914 Command
* CheckSynthCommand::exportTo(ExprManager
* exprManager
,
915 ExprManagerMapCollection
& variableMap
)
917 return new CheckSynthCommand();
920 Command
* CheckSynthCommand::clone() const { return new CheckSynthCommand(); }
922 std::string
CheckSynthCommand::getCommandName() const { return "check-synth"; }
924 /* -------------------------------------------------------------------------- */
925 /* class ResetCommand */
926 /* -------------------------------------------------------------------------- */
928 void ResetCommand::invoke(SmtEngine
* smtEngine
)
933 d_commandStatus
= CommandSuccess::instance();
937 d_commandStatus
= new CommandFailure(e
.what());
941 Command
* ResetCommand::exportTo(ExprManager
* exprManager
,
942 ExprManagerMapCollection
& variableMap
)
944 return new ResetCommand();
947 Command
* ResetCommand::clone() const { return new ResetCommand(); }
948 std::string
ResetCommand::getCommandName() const { return "reset"; }
950 /* -------------------------------------------------------------------------- */
951 /* class ResetAssertionsCommand */
952 /* -------------------------------------------------------------------------- */
954 void ResetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
958 smtEngine
->resetAssertions();
959 d_commandStatus
= CommandSuccess::instance();
963 d_commandStatus
= new CommandFailure(e
.what());
967 Command
* ResetAssertionsCommand::exportTo(ExprManager
* exprManager
,
968 ExprManagerMapCollection
& variableMap
)
970 return new ResetAssertionsCommand();
973 Command
* ResetAssertionsCommand::clone() const
975 return new ResetAssertionsCommand();
978 std::string
ResetAssertionsCommand::getCommandName() const
980 return "reset-assertions";
983 /* -------------------------------------------------------------------------- */
984 /* class QuitCommand */
985 /* -------------------------------------------------------------------------- */
987 void QuitCommand::invoke(SmtEngine
* smtEngine
)
989 Dump("benchmark") << *this;
990 d_commandStatus
= CommandSuccess::instance();
993 Command
* QuitCommand::exportTo(ExprManager
* exprManager
,
994 ExprManagerMapCollection
& variableMap
)
996 return new QuitCommand();
999 Command
* QuitCommand::clone() const { return new QuitCommand(); }
1000 std::string
QuitCommand::getCommandName() const { return "exit"; }
1002 /* -------------------------------------------------------------------------- */
1003 /* class CommentCommand */
1004 /* -------------------------------------------------------------------------- */
1006 CommentCommand::CommentCommand(std::string comment
) : d_comment(comment
) {}
1007 std::string
CommentCommand::getComment() const { return d_comment
; }
1008 void CommentCommand::invoke(SmtEngine
* smtEngine
)
1010 Dump("benchmark") << *this;
1011 d_commandStatus
= CommandSuccess::instance();
1014 Command
* CommentCommand::exportTo(ExprManager
* exprManager
,
1015 ExprManagerMapCollection
& variableMap
)
1017 return new CommentCommand(d_comment
);
1020 Command
* CommentCommand::clone() const { return new CommentCommand(d_comment
); }
1021 std::string
CommentCommand::getCommandName() const { return "comment"; }
1023 /* -------------------------------------------------------------------------- */
1024 /* class CommandSequence */
1025 /* -------------------------------------------------------------------------- */
1027 CommandSequence::CommandSequence() : d_index(0) {}
1028 CommandSequence::~CommandSequence()
1030 for (unsigned i
= d_index
; i
< d_commandSequence
.size(); ++i
)
1032 delete d_commandSequence
[i
];
1036 void CommandSequence::addCommand(Command
* cmd
)
1038 d_commandSequence
.push_back(cmd
);
1041 void CommandSequence::clear() { d_commandSequence
.clear(); }
1042 void CommandSequence::invoke(SmtEngine
* smtEngine
)
1044 for (; d_index
< d_commandSequence
.size(); ++d_index
)
1046 d_commandSequence
[d_index
]->invoke(smtEngine
);
1047 if (!d_commandSequence
[d_index
]->ok())
1050 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
1053 delete d_commandSequence
[d_index
];
1056 AlwaysAssert(d_commandStatus
== NULL
);
1057 d_commandStatus
= CommandSuccess::instance();
1060 void CommandSequence::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
1062 for (; d_index
< d_commandSequence
.size(); ++d_index
)
1064 d_commandSequence
[d_index
]->invoke(smtEngine
, out
);
1065 if (!d_commandSequence
[d_index
]->ok())
1068 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
1071 delete d_commandSequence
[d_index
];
1074 AlwaysAssert(d_commandStatus
== NULL
);
1075 d_commandStatus
= CommandSuccess::instance();
1078 Command
* CommandSequence::exportTo(ExprManager
* exprManager
,
1079 ExprManagerMapCollection
& variableMap
)
1081 CommandSequence
* seq
= new CommandSequence();
1082 for (iterator i
= begin(); i
!= end(); ++i
)
1084 Command
* cmd_to_export
= *i
;
1085 Command
* cmd
= cmd_to_export
->exportTo(exprManager
, variableMap
);
1086 seq
->addCommand(cmd
);
1087 Debug("export") << "[export] so far converted: " << seq
<< endl
;
1089 seq
->d_index
= d_index
;
1093 Command
* CommandSequence::clone() const
1095 CommandSequence
* seq
= new CommandSequence();
1096 for (const_iterator i
= begin(); i
!= end(); ++i
)
1098 seq
->addCommand((*i
)->clone());
1100 seq
->d_index
= d_index
;
1104 CommandSequence::const_iterator
CommandSequence::begin() const
1106 return d_commandSequence
.begin();
1109 CommandSequence::const_iterator
CommandSequence::end() const
1111 return d_commandSequence
.end();
1114 CommandSequence::iterator
CommandSequence::begin()
1116 return d_commandSequence
.begin();
1119 CommandSequence::iterator
CommandSequence::end()
1121 return d_commandSequence
.end();
1124 std::string
CommandSequence::getCommandName() const { return "sequence"; }
1126 /* -------------------------------------------------------------------------- */
1127 /* class DeclarationDefinitionCommand */
1128 /* -------------------------------------------------------------------------- */
1130 DeclarationDefinitionCommand::DeclarationDefinitionCommand(
1131 const std::string
& id
)
1136 std::string
DeclarationDefinitionCommand::getSymbol() const { return d_symbol
; }
1138 /* -------------------------------------------------------------------------- */
1139 /* class DeclareFunctionCommand */
1140 /* -------------------------------------------------------------------------- */
1142 DeclareFunctionCommand::DeclareFunctionCommand(const std::string
& id
,
1145 : DeclarationDefinitionCommand(id
),
1148 d_printInModel(true),
1149 d_printInModelSetByUser(false)
1153 Expr
DeclareFunctionCommand::getFunction() const { return d_func
; }
1154 Type
DeclareFunctionCommand::getType() const { return d_type
; }
1155 bool DeclareFunctionCommand::getPrintInModel() const { return d_printInModel
; }
1156 bool DeclareFunctionCommand::getPrintInModelSetByUser() const
1158 return d_printInModelSetByUser
;
1161 void DeclareFunctionCommand::setPrintInModel(bool p
)
1164 d_printInModelSetByUser
= true;
1167 void DeclareFunctionCommand::invoke(SmtEngine
* smtEngine
)
1169 d_commandStatus
= CommandSuccess::instance();
1172 Command
* DeclareFunctionCommand::exportTo(ExprManager
* exprManager
,
1173 ExprManagerMapCollection
& variableMap
)
1175 DeclareFunctionCommand
* dfc
=
1176 new DeclareFunctionCommand(d_symbol
,
1177 d_func
.exportTo(exprManager
, variableMap
),
1178 d_type
.exportTo(exprManager
, variableMap
));
1179 dfc
->d_printInModel
= d_printInModel
;
1180 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
1184 Command
* DeclareFunctionCommand::clone() const
1186 DeclareFunctionCommand
* dfc
=
1187 new DeclareFunctionCommand(d_symbol
, d_func
, d_type
);
1188 dfc
->d_printInModel
= d_printInModel
;
1189 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
1193 std::string
DeclareFunctionCommand::getCommandName() const
1195 return "declare-fun";
1198 /* -------------------------------------------------------------------------- */
1199 /* class DeclareTypeCommand */
1200 /* -------------------------------------------------------------------------- */
1202 DeclareTypeCommand::DeclareTypeCommand(const std::string
& id
,
1205 : DeclarationDefinitionCommand(id
), d_arity(arity
), d_type(t
)
1209 size_t DeclareTypeCommand::getArity() const { return d_arity
; }
1210 Type
DeclareTypeCommand::getType() const { return d_type
; }
1211 void DeclareTypeCommand::invoke(SmtEngine
* smtEngine
)
1213 d_commandStatus
= CommandSuccess::instance();
1216 Command
* DeclareTypeCommand::exportTo(ExprManager
* exprManager
,
1217 ExprManagerMapCollection
& variableMap
)
1219 return new DeclareTypeCommand(
1220 d_symbol
, d_arity
, d_type
.exportTo(exprManager
, variableMap
));
1223 Command
* DeclareTypeCommand::clone() const
1225 return new DeclareTypeCommand(d_symbol
, d_arity
, d_type
);
1228 std::string
DeclareTypeCommand::getCommandName() const
1230 return "declare-sort";
1233 /* -------------------------------------------------------------------------- */
1234 /* class DefineTypeCommand */
1235 /* -------------------------------------------------------------------------- */
1237 DefineTypeCommand::DefineTypeCommand(const std::string
& id
, Type t
)
1238 : DeclarationDefinitionCommand(id
), d_params(), d_type(t
)
1242 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
1243 const std::vector
<Type
>& params
,
1245 : DeclarationDefinitionCommand(id
), d_params(params
), d_type(t
)
1249 const std::vector
<Type
>& DefineTypeCommand::getParameters() const
1254 Type
DefineTypeCommand::getType() const { return d_type
; }
1255 void DefineTypeCommand::invoke(SmtEngine
* smtEngine
)
1257 d_commandStatus
= CommandSuccess::instance();
1260 Command
* DefineTypeCommand::exportTo(ExprManager
* exprManager
,
1261 ExprManagerMapCollection
& variableMap
)
1263 vector
<Type
> params
;
1264 transform(d_params
.begin(),
1266 back_inserter(params
),
1267 ExportTransformer(exprManager
, variableMap
));
1268 Type type
= d_type
.exportTo(exprManager
, variableMap
);
1269 return new DefineTypeCommand(d_symbol
, params
, type
);
1272 Command
* DefineTypeCommand::clone() const
1274 return new DefineTypeCommand(d_symbol
, d_params
, d_type
);
1277 std::string
DefineTypeCommand::getCommandName() const { return "define-sort"; }
1279 /* -------------------------------------------------------------------------- */
1280 /* class DefineFunctionCommand */
1281 /* -------------------------------------------------------------------------- */
1283 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1286 : DeclarationDefinitionCommand(id
),
1293 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1295 const std::vector
<Expr
>& formals
,
1297 : DeclarationDefinitionCommand(id
),
1304 Expr
DefineFunctionCommand::getFunction() const { return d_func
; }
1305 const std::vector
<Expr
>& DefineFunctionCommand::getFormals() const
1310 Expr
DefineFunctionCommand::getFormula() const { return d_formula
; }
1311 void DefineFunctionCommand::invoke(SmtEngine
* smtEngine
)
1315 if (!d_func
.isNull())
1317 smtEngine
->defineFunction(d_func
, d_formals
, d_formula
);
1319 d_commandStatus
= CommandSuccess::instance();
1321 catch (exception
& e
)
1323 d_commandStatus
= new CommandFailure(e
.what());
1327 Command
* DefineFunctionCommand::exportTo(ExprManager
* exprManager
,
1328 ExprManagerMapCollection
& variableMap
)
1330 Expr func
= d_func
.exportTo(
1331 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1332 vector
<Expr
> formals
;
1333 transform(d_formals
.begin(),
1335 back_inserter(formals
),
1336 ExportTransformer(exprManager
, variableMap
));
1337 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1338 return new DefineFunctionCommand(d_symbol
, func
, formals
, formula
);
1341 Command
* DefineFunctionCommand::clone() const
1343 return new DefineFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1346 std::string
DefineFunctionCommand::getCommandName() const
1348 return "define-fun";
1351 /* -------------------------------------------------------------------------- */
1352 /* class DefineNamedFunctionCommand */
1353 /* -------------------------------------------------------------------------- */
1355 DefineNamedFunctionCommand::DefineNamedFunctionCommand(
1356 const std::string
& id
,
1358 const std::vector
<Expr
>& formals
,
1360 : DefineFunctionCommand(id
, func
, formals
, formula
)
1364 void DefineNamedFunctionCommand::invoke(SmtEngine
* smtEngine
)
1366 this->DefineFunctionCommand::invoke(smtEngine
);
1367 if (!d_func
.isNull() && d_func
.getType().isBoolean())
1369 smtEngine
->addToAssignment(d_func
);
1371 d_commandStatus
= CommandSuccess::instance();
1374 Command
* DefineNamedFunctionCommand::exportTo(
1375 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1377 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
1378 vector
<Expr
> formals
;
1379 transform(d_formals
.begin(),
1381 back_inserter(formals
),
1382 ExportTransformer(exprManager
, variableMap
));
1383 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1384 return new DefineNamedFunctionCommand(d_symbol
, func
, formals
, formula
);
1387 Command
* DefineNamedFunctionCommand::clone() const
1389 return new DefineNamedFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1392 /* -------------------------------------------------------------------------- */
1393 /* class DefineFunctionRecCommand */
1394 /* -------------------------------------------------------------------------- */
1396 DefineFunctionRecCommand::DefineFunctionRecCommand(
1397 Expr func
, const std::vector
<Expr
>& formals
, Expr formula
)
1399 d_funcs
.push_back(func
);
1400 d_formals
.push_back(formals
);
1401 d_formulas
.push_back(formula
);
1404 DefineFunctionRecCommand::DefineFunctionRecCommand(
1405 const std::vector
<Expr
>& funcs
,
1406 const std::vector
<std::vector
<Expr
>>& formals
,
1407 const std::vector
<Expr
>& formulas
)
1409 d_funcs
.insert(d_funcs
.end(), funcs
.begin(), funcs
.end());
1410 d_formals
.insert(d_formals
.end(), formals
.begin(), formals
.end());
1411 d_formulas
.insert(d_formulas
.end(), formulas
.begin(), formulas
.end());
1414 const std::vector
<Expr
>& DefineFunctionRecCommand::getFunctions() const
1419 const std::vector
<std::vector
<Expr
>>& DefineFunctionRecCommand::getFormals()
1425 const std::vector
<Expr
>& DefineFunctionRecCommand::getFormulas() const
1430 void DefineFunctionRecCommand::invoke(SmtEngine
* smtEngine
)
1434 smtEngine
->defineFunctionsRec(d_funcs
, d_formals
, d_formulas
);
1435 d_commandStatus
= CommandSuccess::instance();
1437 catch (exception
& e
)
1439 d_commandStatus
= new CommandFailure(e
.what());
1443 Command
* DefineFunctionRecCommand::exportTo(
1444 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1446 std::vector
<Expr
> funcs
;
1447 for (unsigned i
= 0, size
= d_funcs
.size(); i
< size
; i
++)
1449 Expr func
= d_funcs
[i
].exportTo(
1450 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1451 funcs
.push_back(func
);
1453 std::vector
<std::vector
<Expr
>> formals
;
1454 for (unsigned i
= 0, size
= d_formals
.size(); i
< size
; i
++)
1456 std::vector
<Expr
> formals_c
;
1457 transform(d_formals
[i
].begin(),
1459 back_inserter(formals_c
),
1460 ExportTransformer(exprManager
, variableMap
));
1461 formals
.push_back(formals_c
);
1463 std::vector
<Expr
> formulas
;
1464 for (unsigned i
= 0, size
= d_formulas
.size(); i
< size
; i
++)
1466 Expr formula
= d_formulas
[i
].exportTo(exprManager
, variableMap
);
1467 formulas
.push_back(formula
);
1469 return new DefineFunctionRecCommand(funcs
, formals
, formulas
);
1472 Command
* DefineFunctionRecCommand::clone() const
1474 return new DefineFunctionRecCommand(d_funcs
, d_formals
, d_formulas
);
1477 std::string
DefineFunctionRecCommand::getCommandName() const
1479 return "define-fun-rec";
1482 /* -------------------------------------------------------------------------- */
1483 /* class SetUserAttribute */
1484 /* -------------------------------------------------------------------------- */
1486 SetUserAttributeCommand::SetUserAttributeCommand(
1487 const std::string
& attr
,
1489 const std::vector
<Expr
>& expr_values
,
1490 const std::string
& str_value
)
1493 d_expr_values(expr_values
),
1494 d_str_value(str_value
)
1498 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1500 : SetUserAttributeCommand(attr
, expr
, {}, "")
1504 SetUserAttributeCommand::SetUserAttributeCommand(
1505 const std::string
& attr
, Expr expr
, const std::vector
<Expr
>& values
)
1506 : SetUserAttributeCommand(attr
, expr
, values
, "")
1510 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1512 const std::string
& value
)
1513 : SetUserAttributeCommand(attr
, expr
, {}, value
)
1517 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
)
1521 if (!d_expr
.isNull())
1523 smtEngine
->setUserAttribute(d_attr
, d_expr
, d_expr_values
, d_str_value
);
1525 d_commandStatus
= CommandSuccess::instance();
1527 catch (exception
& e
)
1529 d_commandStatus
= new CommandFailure(e
.what());
1533 Command
* SetUserAttributeCommand::exportTo(
1534 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1536 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
1537 return new SetUserAttributeCommand(d_attr
, expr
, d_expr_values
, d_str_value
);
1540 Command
* SetUserAttributeCommand::clone() const
1542 return new SetUserAttributeCommand(
1543 d_attr
, d_expr
, d_expr_values
, d_str_value
);
1546 std::string
SetUserAttributeCommand::getCommandName() const
1548 return "set-user-attribute";
1551 /* -------------------------------------------------------------------------- */
1552 /* class SimplifyCommand */
1553 /* -------------------------------------------------------------------------- */
1555 SimplifyCommand::SimplifyCommand(Expr term
) : d_term(term
) {}
1556 Expr
SimplifyCommand::getTerm() const { return d_term
; }
1557 void SimplifyCommand::invoke(SmtEngine
* smtEngine
)
1561 d_result
= smtEngine
->simplify(d_term
);
1562 d_commandStatus
= CommandSuccess::instance();
1564 catch (UnsafeInterruptException
& e
)
1566 d_commandStatus
= new CommandInterrupted();
1568 catch (exception
& e
)
1570 d_commandStatus
= new CommandFailure(e
.what());
1574 Expr
SimplifyCommand::getResult() const { return d_result
; }
1575 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1579 this->Command::printResult(out
, verbosity
);
1583 out
<< d_result
<< endl
;
1587 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
,
1588 ExprManagerMapCollection
& variableMap
)
1590 SimplifyCommand
* c
=
1591 new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
1592 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1596 Command
* SimplifyCommand::clone() const
1598 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
1599 c
->d_result
= d_result
;
1603 std::string
SimplifyCommand::getCommandName() const { return "simplify"; }
1605 /* -------------------------------------------------------------------------- */
1606 /* class ExpandDefinitionsCommand */
1607 /* -------------------------------------------------------------------------- */
1609 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) : d_term(term
) {}
1610 Expr
ExpandDefinitionsCommand::getTerm() const { return d_term
; }
1611 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
)
1613 d_result
= smtEngine
->expandDefinitions(d_term
);
1614 d_commandStatus
= CommandSuccess::instance();
1617 Expr
ExpandDefinitionsCommand::getResult() const { return d_result
; }
1618 void ExpandDefinitionsCommand::printResult(std::ostream
& out
,
1619 uint32_t verbosity
) const
1623 this->Command::printResult(out
, verbosity
);
1627 out
<< d_result
<< endl
;
1631 Command
* ExpandDefinitionsCommand::exportTo(
1632 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1634 ExpandDefinitionsCommand
* c
=
1635 new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
1636 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1640 Command
* ExpandDefinitionsCommand::clone() const
1642 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
1643 c
->d_result
= d_result
;
1647 std::string
ExpandDefinitionsCommand::getCommandName() const
1649 return "expand-definitions";
1652 /* -------------------------------------------------------------------------- */
1653 /* class GetValueCommand */
1654 /* -------------------------------------------------------------------------- */
1656 GetValueCommand::GetValueCommand(Expr term
) : d_terms()
1658 d_terms
.push_back(term
);
1661 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
)
1664 PrettyCheckArgument(
1665 terms
.size() >= 1, terms
, "cannot get-value of an empty set of terms");
1668 const std::vector
<Expr
>& GetValueCommand::getTerms() const { return d_terms
; }
1669 void GetValueCommand::invoke(SmtEngine
* smtEngine
)
1673 ExprManager
* em
= smtEngine
->getExprManager();
1674 NodeManager
* nm
= NodeManager::fromExprManager(em
);
1675 smt::SmtScope
scope(smtEngine
);
1676 vector
<Expr
> result
= smtEngine
->getValues(d_terms
);
1677 Assert(result
.size() == d_terms
.size());
1678 for (int i
= 0, size
= d_terms
.size(); i
< size
; i
++)
1680 Expr e
= d_terms
[i
];
1681 Assert(nm
== NodeManager::fromExprManager(e
.getExprManager()));
1682 Node request
= Node::fromExpr(
1683 options::expandDefinitions() ? smtEngine
->expandDefinitions(e
) : e
);
1684 Node value
= Node::fromExpr(result
[i
]);
1685 if (value
.getType().isInteger() && request
.getType() == nm
->realType())
1687 // Need to wrap in division-by-one so that output printers know this
1688 // is an integer-looking constant that really should be output as
1689 // a rational. Necessary for SMT-LIB standards compliance.
1690 value
= nm
->mkNode(kind::DIVISION
, value
, nm
->mkConst(Rational(1)));
1692 result
[i
] = nm
->mkNode(kind::SEXPR
, request
, value
).toExpr();
1694 d_result
= em
->mkExpr(kind::SEXPR
, result
);
1695 d_commandStatus
= CommandSuccess::instance();
1697 catch (RecoverableModalException
& e
)
1699 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1701 catch (UnsafeInterruptException
& e
)
1703 d_commandStatus
= new CommandInterrupted();
1705 catch (exception
& e
)
1707 d_commandStatus
= new CommandFailure(e
.what());
1711 Expr
GetValueCommand::getResult() const { return d_result
; }
1712 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1716 this->Command::printResult(out
, verbosity
);
1720 expr::ExprDag::Scope
scope(out
, false);
1721 out
<< d_result
<< endl
;
1725 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
,
1726 ExprManagerMapCollection
& variableMap
)
1728 vector
<Expr
> exportedTerms
;
1729 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1733 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1735 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1736 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1740 Command
* GetValueCommand::clone() const
1742 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1743 c
->d_result
= d_result
;
1747 std::string
GetValueCommand::getCommandName() const { return "get-value"; }
1749 /* -------------------------------------------------------------------------- */
1750 /* class GetAssignmentCommand */
1751 /* -------------------------------------------------------------------------- */
1753 GetAssignmentCommand::GetAssignmentCommand() {}
1754 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
)
1758 std::vector
<std::pair
<Expr
, Expr
>> assignments
= smtEngine
->getAssignment();
1759 vector
<SExpr
> sexprs
;
1760 for (const auto& p
: assignments
)
1763 v
.emplace_back(SExpr::Keyword(p
.first
.toString()));
1764 v
.emplace_back(SExpr::Keyword(p
.second
.toString()));
1765 sexprs
.emplace_back(v
);
1767 d_result
= SExpr(sexprs
);
1768 d_commandStatus
= CommandSuccess::instance();
1770 catch (RecoverableModalException
& e
)
1772 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1774 catch (UnsafeInterruptException
& e
)
1776 d_commandStatus
= new CommandInterrupted();
1778 catch (exception
& e
)
1780 d_commandStatus
= new CommandFailure(e
.what());
1784 SExpr
GetAssignmentCommand::getResult() const { return d_result
; }
1785 void GetAssignmentCommand::printResult(std::ostream
& out
,
1786 uint32_t verbosity
) const
1790 this->Command::printResult(out
, verbosity
);
1794 out
<< d_result
<< endl
;
1798 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
,
1799 ExprManagerMapCollection
& variableMap
)
1801 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1802 c
->d_result
= d_result
;
1806 Command
* GetAssignmentCommand::clone() const
1808 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1809 c
->d_result
= d_result
;
1813 std::string
GetAssignmentCommand::getCommandName() const
1815 return "get-assignment";
1818 /* -------------------------------------------------------------------------- */
1819 /* class GetModelCommand */
1820 /* -------------------------------------------------------------------------- */
1822 GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
1823 void GetModelCommand::invoke(SmtEngine
* smtEngine
)
1827 d_result
= smtEngine
->getModel();
1828 d_smtEngine
= smtEngine
;
1829 d_commandStatus
= CommandSuccess::instance();
1831 catch (RecoverableModalException
& e
)
1833 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1835 catch (UnsafeInterruptException
& e
)
1837 d_commandStatus
= new CommandInterrupted();
1839 catch (exception
& e
)
1841 d_commandStatus
= new CommandFailure(e
.what());
1845 /* Model is private to the library -- for now
1846 Model* GetModelCommand::getResult() const {
1851 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1855 this->Command::printResult(out
, verbosity
);
1863 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
,
1864 ExprManagerMapCollection
& variableMap
)
1866 GetModelCommand
* c
= new GetModelCommand();
1867 c
->d_result
= d_result
;
1868 c
->d_smtEngine
= d_smtEngine
;
1872 Command
* GetModelCommand::clone() const
1874 GetModelCommand
* c
= new GetModelCommand();
1875 c
->d_result
= d_result
;
1876 c
->d_smtEngine
= d_smtEngine
;
1880 std::string
GetModelCommand::getCommandName() const { return "get-model"; }
1882 /* -------------------------------------------------------------------------- */
1883 /* class BlockModelCommand */
1884 /* -------------------------------------------------------------------------- */
1886 BlockModelCommand::BlockModelCommand() {}
1887 void BlockModelCommand::invoke(SmtEngine
* smtEngine
)
1891 smtEngine
->blockModel();
1892 d_commandStatus
= CommandSuccess::instance();
1894 catch (RecoverableModalException
& e
)
1896 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1898 catch (UnsafeInterruptException
& e
)
1900 d_commandStatus
= new CommandInterrupted();
1902 catch (exception
& e
)
1904 d_commandStatus
= new CommandFailure(e
.what());
1908 Command
* BlockModelCommand::exportTo(ExprManager
* exprManager
,
1909 ExprManagerMapCollection
& variableMap
)
1911 BlockModelCommand
* c
= new BlockModelCommand();
1915 Command
* BlockModelCommand::clone() const
1917 BlockModelCommand
* c
= new BlockModelCommand();
1921 std::string
BlockModelCommand::getCommandName() const { return "block-model"; }
1923 /* -------------------------------------------------------------------------- */
1924 /* class BlockModelValuesCommand */
1925 /* -------------------------------------------------------------------------- */
1927 BlockModelValuesCommand::BlockModelValuesCommand(const std::vector
<Expr
>& terms
)
1930 PrettyCheckArgument(terms
.size() >= 1,
1932 "cannot block-model-values of an empty set of terms");
1935 const std::vector
<Expr
>& BlockModelValuesCommand::getTerms() const
1939 void BlockModelValuesCommand::invoke(SmtEngine
* smtEngine
)
1943 smtEngine
->blockModelValues(d_terms
);
1944 d_commandStatus
= CommandSuccess::instance();
1946 catch (RecoverableModalException
& e
)
1948 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1950 catch (UnsafeInterruptException
& e
)
1952 d_commandStatus
= new CommandInterrupted();
1954 catch (exception
& e
)
1956 d_commandStatus
= new CommandFailure(e
.what());
1960 Command
* BlockModelValuesCommand::exportTo(
1961 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1963 vector
<Expr
> exportedTerms
;
1964 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1968 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1970 BlockModelValuesCommand
* c
= new BlockModelValuesCommand(exportedTerms
);
1974 Command
* BlockModelValuesCommand::clone() const
1976 BlockModelValuesCommand
* c
= new BlockModelValuesCommand(d_terms
);
1980 std::string
BlockModelValuesCommand::getCommandName() const
1982 return "block-model-values";
1985 /* -------------------------------------------------------------------------- */
1986 /* class GetProofCommand */
1987 /* -------------------------------------------------------------------------- */
1989 GetProofCommand::GetProofCommand() : d_smtEngine(nullptr), d_result(nullptr) {}
1990 void GetProofCommand::invoke(SmtEngine
* smtEngine
)
1994 d_smtEngine
= smtEngine
;
1995 d_result
= &smtEngine
->getProof();
1996 d_commandStatus
= CommandSuccess::instance();
1998 catch (RecoverableModalException
& e
)
2000 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2002 catch (UnsafeInterruptException
& e
)
2004 d_commandStatus
= new CommandInterrupted();
2006 catch (exception
& e
)
2008 d_commandStatus
= new CommandFailure(e
.what());
2012 const Proof
& GetProofCommand::getResult() const { return *d_result
; }
2013 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2017 this->Command::printResult(out
, verbosity
);
2021 smt::SmtScope
scope(d_smtEngine
);
2022 d_result
->toStream(out
);
2026 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
,
2027 ExprManagerMapCollection
& variableMap
)
2029 GetProofCommand
* c
= new GetProofCommand();
2030 c
->d_result
= d_result
;
2031 c
->d_smtEngine
= d_smtEngine
;
2035 Command
* GetProofCommand::clone() const
2037 GetProofCommand
* c
= new GetProofCommand();
2038 c
->d_result
= d_result
;
2039 c
->d_smtEngine
= d_smtEngine
;
2043 std::string
GetProofCommand::getCommandName() const { return "get-proof"; }
2045 /* -------------------------------------------------------------------------- */
2046 /* class GetInstantiationsCommand */
2047 /* -------------------------------------------------------------------------- */
2049 GetInstantiationsCommand::GetInstantiationsCommand() : d_smtEngine(nullptr) {}
2050 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
)
2054 d_smtEngine
= smtEngine
;
2055 d_commandStatus
= CommandSuccess::instance();
2057 catch (exception
& e
)
2059 d_commandStatus
= new CommandFailure(e
.what());
2063 void GetInstantiationsCommand::printResult(std::ostream
& out
,
2064 uint32_t verbosity
) const
2068 this->Command::printResult(out
, verbosity
);
2072 d_smtEngine
->printInstantiations(out
);
2076 Command
* GetInstantiationsCommand::exportTo(
2077 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2079 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
2080 // c->d_result = d_result;
2081 c
->d_smtEngine
= d_smtEngine
;
2085 Command
* GetInstantiationsCommand::clone() const
2087 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
2088 // c->d_result = d_result;
2089 c
->d_smtEngine
= d_smtEngine
;
2093 std::string
GetInstantiationsCommand::getCommandName() const
2095 return "get-instantiations";
2098 /* -------------------------------------------------------------------------- */
2099 /* class GetSynthSolutionCommand */
2100 /* -------------------------------------------------------------------------- */
2102 GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
2103 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
)
2107 d_smtEngine
= smtEngine
;
2108 d_commandStatus
= CommandSuccess::instance();
2110 catch (exception
& e
)
2112 d_commandStatus
= new CommandFailure(e
.what());
2116 void GetSynthSolutionCommand::printResult(std::ostream
& out
,
2117 uint32_t verbosity
) const
2121 this->Command::printResult(out
, verbosity
);
2125 d_smtEngine
->printSynthSolution(out
);
2129 Command
* GetSynthSolutionCommand::exportTo(
2130 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2132 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2133 c
->d_smtEngine
= d_smtEngine
;
2137 Command
* GetSynthSolutionCommand::clone() const
2139 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2140 c
->d_smtEngine
= d_smtEngine
;
2144 std::string
GetSynthSolutionCommand::getCommandName() const
2146 return "get-instantiations";
2149 GetAbductCommand::GetAbductCommand() {}
2150 GetAbductCommand::GetAbductCommand(const std::string
& name
, Expr conj
)
2151 : d_name(name
), d_conj(conj
), d_resultStatus(false)
2154 GetAbductCommand::GetAbductCommand(const std::string
& name
,
2159 d_sygus_grammar_type(gtype
),
2160 d_resultStatus(false)
2164 Expr
GetAbductCommand::getConjecture() const { return d_conj
; }
2165 Type
GetAbductCommand::getGrammarType() const { return d_sygus_grammar_type
; }
2166 Expr
GetAbductCommand::getResult() const { return d_result
; }
2168 void GetAbductCommand::invoke(SmtEngine
* smtEngine
)
2172 if (d_sygus_grammar_type
.isNull())
2174 d_resultStatus
= smtEngine
->getAbduct(d_conj
, d_result
);
2179 smtEngine
->getAbduct(d_conj
, d_sygus_grammar_type
, d_result
);
2181 d_commandStatus
= CommandSuccess::instance();
2183 catch (exception
& e
)
2185 d_commandStatus
= new CommandFailure(e
.what());
2189 void GetAbductCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2193 this->Command::printResult(out
, verbosity
);
2197 expr::ExprDag::Scope
scope(out
, false);
2200 out
<< "(define-fun " << d_name
<< " () Bool " << d_result
<< ")"
2205 out
<< "none" << std::endl
;
2210 Command
* GetAbductCommand::exportTo(ExprManager
* exprManager
,
2211 ExprManagerMapCollection
& variableMap
)
2213 GetAbductCommand
* c
=
2214 new GetAbductCommand(d_name
, d_conj
.exportTo(exprManager
, variableMap
));
2215 c
->d_sygus_grammar_type
=
2216 d_sygus_grammar_type
.exportTo(exprManager
, variableMap
);
2217 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
2218 c
->d_resultStatus
= d_resultStatus
;
2222 Command
* GetAbductCommand::clone() const
2224 GetAbductCommand
* c
= new GetAbductCommand(d_name
, d_conj
);
2225 c
->d_sygus_grammar_type
= d_sygus_grammar_type
;
2226 c
->d_result
= d_result
;
2227 c
->d_resultStatus
= d_resultStatus
;
2231 std::string
GetAbductCommand::getCommandName() const { return "get-abduct"; }
2233 /* -------------------------------------------------------------------------- */
2234 /* class GetQuantifierEliminationCommand */
2235 /* -------------------------------------------------------------------------- */
2237 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand()
2238 : d_expr(), d_doFull(true)
2241 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
2242 const Expr
& expr
, bool doFull
)
2243 : d_expr(expr
), d_doFull(doFull
)
2247 Expr
GetQuantifierEliminationCommand::getExpr() const { return d_expr
; }
2248 bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull
; }
2249 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
)
2253 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
2254 d_commandStatus
= CommandSuccess::instance();
2256 catch (exception
& e
)
2258 d_commandStatus
= new CommandFailure(e
.what());
2262 Expr
GetQuantifierEliminationCommand::getResult() const { return d_result
; }
2263 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
,
2264 uint32_t verbosity
) const
2268 this->Command::printResult(out
, verbosity
);
2272 out
<< d_result
<< endl
;
2276 Command
* GetQuantifierEliminationCommand::exportTo(
2277 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2279 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(
2280 d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
2281 c
->d_result
= d_result
;
2285 Command
* GetQuantifierEliminationCommand::clone() const
2287 GetQuantifierEliminationCommand
* c
=
2288 new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
2289 c
->d_result
= d_result
;
2293 std::string
GetQuantifierEliminationCommand::getCommandName() const
2295 return d_doFull
? "get-qe" : "get-qe-disjunct";
2298 /* -------------------------------------------------------------------------- */
2299 /* class GetUnsatAssumptionsCommand */
2300 /* -------------------------------------------------------------------------- */
2302 GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
2304 void GetUnsatAssumptionsCommand::invoke(SmtEngine
* smtEngine
)
2308 d_result
= smtEngine
->getUnsatAssumptions();
2309 d_commandStatus
= CommandSuccess::instance();
2311 catch (RecoverableModalException
& e
)
2313 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2315 catch (exception
& e
)
2317 d_commandStatus
= new CommandFailure(e
.what());
2321 std::vector
<Expr
> GetUnsatAssumptionsCommand::getResult() const
2326 void GetUnsatAssumptionsCommand::printResult(std::ostream
& out
,
2327 uint32_t verbosity
) const
2331 this->Command::printResult(out
, verbosity
);
2335 container_to_stream(out
, d_result
, "(", ")\n", " ");
2339 Command
* GetUnsatAssumptionsCommand::exportTo(
2340 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2342 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2343 c
->d_result
= d_result
;
2347 Command
* GetUnsatAssumptionsCommand::clone() const
2349 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2350 c
->d_result
= d_result
;
2354 std::string
GetUnsatAssumptionsCommand::getCommandName() const
2356 return "get-unsat-assumptions";
2359 /* -------------------------------------------------------------------------- */
2360 /* class GetUnsatCoreCommand */
2361 /* -------------------------------------------------------------------------- */
2363 GetUnsatCoreCommand::GetUnsatCoreCommand() {}
2364 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
)
2368 d_result
= smtEngine
->getUnsatCore();
2369 d_commandStatus
= CommandSuccess::instance();
2371 catch (RecoverableModalException
& e
)
2373 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2375 catch (exception
& e
)
2377 d_commandStatus
= new CommandFailure(e
.what());
2381 void GetUnsatCoreCommand::printResult(std::ostream
& out
,
2382 uint32_t verbosity
) const
2386 this->Command::printResult(out
, verbosity
);
2390 d_result
.toStream(out
);
2394 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const
2396 // of course, this will be empty if the command hasn't been invoked yet
2400 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
,
2401 ExprManagerMapCollection
& variableMap
)
2403 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2404 c
->d_result
= d_result
;
2408 Command
* GetUnsatCoreCommand::clone() const
2410 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2411 c
->d_result
= d_result
;
2415 std::string
GetUnsatCoreCommand::getCommandName() const
2417 return "get-unsat-core";
2420 /* -------------------------------------------------------------------------- */
2421 /* class GetAssertionsCommand */
2422 /* -------------------------------------------------------------------------- */
2424 GetAssertionsCommand::GetAssertionsCommand() {}
2425 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
2430 const vector
<Expr
> v
= smtEngine
->getAssertions();
2432 copy(v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n"));
2434 d_result
= ss
.str();
2435 d_commandStatus
= CommandSuccess::instance();
2437 catch (exception
& e
)
2439 d_commandStatus
= new CommandFailure(e
.what());
2443 std::string
GetAssertionsCommand::getResult() const { return d_result
; }
2444 void GetAssertionsCommand::printResult(std::ostream
& out
,
2445 uint32_t verbosity
) const
2449 this->Command::printResult(out
, verbosity
);
2457 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
,
2458 ExprManagerMapCollection
& variableMap
)
2460 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2461 c
->d_result
= d_result
;
2465 Command
* GetAssertionsCommand::clone() const
2467 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2468 c
->d_result
= d_result
;
2472 std::string
GetAssertionsCommand::getCommandName() const
2474 return "get-assertions";
2477 /* -------------------------------------------------------------------------- */
2478 /* class SetBenchmarkStatusCommand */
2479 /* -------------------------------------------------------------------------- */
2481 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
)
2486 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const
2491 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
)
2497 SExpr status
= SExpr(ss
.str());
2498 smtEngine
->setInfo("status", status
);
2499 d_commandStatus
= CommandSuccess::instance();
2501 catch (exception
& e
)
2503 d_commandStatus
= new CommandFailure(e
.what());
2507 Command
* SetBenchmarkStatusCommand::exportTo(
2508 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2510 return new SetBenchmarkStatusCommand(d_status
);
2513 Command
* SetBenchmarkStatusCommand::clone() const
2515 return new SetBenchmarkStatusCommand(d_status
);
2518 std::string
SetBenchmarkStatusCommand::getCommandName() const
2523 /* -------------------------------------------------------------------------- */
2524 /* class SetBenchmarkLogicCommand */
2525 /* -------------------------------------------------------------------------- */
2527 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
)
2532 std::string
SetBenchmarkLogicCommand::getLogic() const { return d_logic
; }
2533 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
)
2537 smtEngine
->setLogic(d_logic
);
2538 d_commandStatus
= CommandSuccess::instance();
2540 catch (exception
& e
)
2542 d_commandStatus
= new CommandFailure(e
.what());
2546 Command
* SetBenchmarkLogicCommand::exportTo(
2547 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2549 return new SetBenchmarkLogicCommand(d_logic
);
2552 Command
* SetBenchmarkLogicCommand::clone() const
2554 return new SetBenchmarkLogicCommand(d_logic
);
2557 std::string
SetBenchmarkLogicCommand::getCommandName() const
2562 /* -------------------------------------------------------------------------- */
2563 /* class SetInfoCommand */
2564 /* -------------------------------------------------------------------------- */
2566 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
)
2567 : d_flag(flag
), d_sexpr(sexpr
)
2571 std::string
SetInfoCommand::getFlag() const { return d_flag
; }
2572 SExpr
SetInfoCommand::getSExpr() const { return d_sexpr
; }
2573 void SetInfoCommand::invoke(SmtEngine
* smtEngine
)
2577 smtEngine
->setInfo(d_flag
, d_sexpr
);
2578 d_commandStatus
= CommandSuccess::instance();
2580 catch (UnrecognizedOptionException
&)
2582 // As per SMT-LIB spec, silently accept unknown set-info keys
2583 d_commandStatus
= CommandSuccess::instance();
2585 catch (exception
& e
)
2587 d_commandStatus
= new CommandFailure(e
.what());
2591 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
,
2592 ExprManagerMapCollection
& variableMap
)
2594 return new SetInfoCommand(d_flag
, d_sexpr
);
2597 Command
* SetInfoCommand::clone() const
2599 return new SetInfoCommand(d_flag
, d_sexpr
);
2602 std::string
SetInfoCommand::getCommandName() const { return "set-info"; }
2604 /* -------------------------------------------------------------------------- */
2605 /* class GetInfoCommand */
2606 /* -------------------------------------------------------------------------- */
2608 GetInfoCommand::GetInfoCommand(std::string flag
) : d_flag(flag
) {}
2609 std::string
GetInfoCommand::getFlag() const { return d_flag
; }
2610 void GetInfoCommand::invoke(SmtEngine
* smtEngine
)
2615 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
2616 v
.push_back(smtEngine
->getInfo(d_flag
));
2618 if (d_flag
== "all-options" || d_flag
== "all-statistics")
2620 ss
<< PrettySExprs(true);
2623 d_result
= ss
.str();
2624 d_commandStatus
= CommandSuccess::instance();
2626 catch (UnrecognizedOptionException
&)
2628 d_commandStatus
= new CommandUnsupported();
2630 catch (RecoverableModalException
& e
)
2632 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2634 catch (exception
& e
)
2636 d_commandStatus
= new CommandFailure(e
.what());
2640 std::string
GetInfoCommand::getResult() const { return d_result
; }
2641 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2645 this->Command::printResult(out
, verbosity
);
2647 else if (d_result
!= "")
2649 out
<< d_result
<< endl
;
2653 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
,
2654 ExprManagerMapCollection
& variableMap
)
2656 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2657 c
->d_result
= d_result
;
2661 Command
* GetInfoCommand::clone() const
2663 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2664 c
->d_result
= d_result
;
2668 std::string
GetInfoCommand::getCommandName() const { return "get-info"; }
2670 /* -------------------------------------------------------------------------- */
2671 /* class SetOptionCommand */
2672 /* -------------------------------------------------------------------------- */
2674 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
)
2675 : d_flag(flag
), d_sexpr(sexpr
)
2679 std::string
SetOptionCommand::getFlag() const { return d_flag
; }
2680 SExpr
SetOptionCommand::getSExpr() const { return d_sexpr
; }
2681 void SetOptionCommand::invoke(SmtEngine
* smtEngine
)
2685 smtEngine
->setOption(d_flag
, d_sexpr
);
2686 d_commandStatus
= CommandSuccess::instance();
2688 catch (UnrecognizedOptionException
&)
2690 d_commandStatus
= new CommandUnsupported();
2692 catch (exception
& e
)
2694 d_commandStatus
= new CommandFailure(e
.what());
2698 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
,
2699 ExprManagerMapCollection
& variableMap
)
2701 return new SetOptionCommand(d_flag
, d_sexpr
);
2704 Command
* SetOptionCommand::clone() const
2706 return new SetOptionCommand(d_flag
, d_sexpr
);
2709 std::string
SetOptionCommand::getCommandName() const { return "set-option"; }
2711 /* -------------------------------------------------------------------------- */
2712 /* class GetOptionCommand */
2713 /* -------------------------------------------------------------------------- */
2715 GetOptionCommand::GetOptionCommand(std::string flag
) : d_flag(flag
) {}
2716 std::string
GetOptionCommand::getFlag() const { return d_flag
; }
2717 void GetOptionCommand::invoke(SmtEngine
* smtEngine
)
2721 SExpr res
= smtEngine
->getOption(d_flag
);
2722 d_result
= res
.toString();
2723 d_commandStatus
= CommandSuccess::instance();
2725 catch (UnrecognizedOptionException
&)
2727 d_commandStatus
= new CommandUnsupported();
2729 catch (exception
& e
)
2731 d_commandStatus
= new CommandFailure(e
.what());
2735 std::string
GetOptionCommand::getResult() const { return d_result
; }
2736 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2740 this->Command::printResult(out
, verbosity
);
2742 else if (d_result
!= "")
2744 out
<< d_result
<< endl
;
2748 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
,
2749 ExprManagerMapCollection
& variableMap
)
2751 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2752 c
->d_result
= d_result
;
2756 Command
* GetOptionCommand::clone() const
2758 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2759 c
->d_result
= d_result
;
2763 std::string
GetOptionCommand::getCommandName() const { return "get-option"; }
2765 /* -------------------------------------------------------------------------- */
2766 /* class SetExpressionNameCommand */
2767 /* -------------------------------------------------------------------------- */
2769 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
)
2770 : d_expr(expr
), d_name(name
)
2774 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
)
2776 smtEngine
->setExpressionName(d_expr
, d_name
);
2777 d_commandStatus
= CommandSuccess::instance();
2780 Command
* SetExpressionNameCommand::exportTo(
2781 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2783 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(
2784 d_expr
.exportTo(exprManager
, variableMap
), d_name
);
2788 Command
* SetExpressionNameCommand::clone() const
2790 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
2794 std::string
SetExpressionNameCommand::getCommandName() const
2796 return "set-expr-name";
2799 /* -------------------------------------------------------------------------- */
2800 /* class DatatypeDeclarationCommand */
2801 /* -------------------------------------------------------------------------- */
2803 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2804 const DatatypeType
& datatype
)
2807 d_datatypes
.push_back(datatype
);
2810 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2811 const std::vector
<DatatypeType
>& datatypes
)
2812 : d_datatypes(datatypes
)
2816 const std::vector
<DatatypeType
>& DatatypeDeclarationCommand::getDatatypes()
2822 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
)
2824 d_commandStatus
= CommandSuccess::instance();
2827 Command
* DatatypeDeclarationCommand::exportTo(
2828 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2830 throw ExportUnsupportedException(
2831 "export of DatatypeDeclarationCommand unsupported");
2834 Command
* DatatypeDeclarationCommand::clone() const
2836 return new DatatypeDeclarationCommand(d_datatypes
);
2839 std::string
DatatypeDeclarationCommand::getCommandName() const
2841 return "declare-datatypes";