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 "expr/type.h"
31 #include "options/options.h"
32 #include "options/smt_options.h"
33 #include "printer/printer.h"
35 #include "smt/model.h"
36 #include "smt/smt_engine.h"
37 #include "smt/smt_engine_scope.h"
38 #include "util/sexpr.h"
39 #include "util/utility.h"
45 const int CommandPrintSuccess::s_iosIndex
= std::ios_base::xalloc();
46 const CommandSuccess
* CommandSuccess::s_instance
= new CommandSuccess();
47 const CommandInterrupted
* CommandInterrupted::s_instance
=
48 new CommandInterrupted();
50 std::ostream
& operator<<(std::ostream
& out
, const Command
& c
)
53 Node::setdepth::getDepth(out
),
54 Node::printtypes::getPrintTypes(out
),
55 Node::dag::getDag(out
),
56 Node::setlanguage::getLanguage(out
));
60 ostream
& operator<<(ostream
& out
, const Command
* c
)
73 std::ostream
& operator<<(std::ostream
& out
, const CommandStatus
& s
)
75 s
.toStream(out
, Node::setlanguage::getLanguage(out
));
79 ostream
& operator<<(ostream
& out
, const CommandStatus
* s
)
93 /* output stream insertion operator for benchmark statuses */
94 std::ostream
& operator<<(std::ostream
& out
, BenchmarkStatus status
)
98 case SMT_SATISFIABLE
: return out
<< "sat";
100 case SMT_UNSATISFIABLE
: return out
<< "unsat";
102 case SMT_UNKNOWN
: return out
<< "unknown";
104 default: return out
<< "BenchmarkStatus::[UNKNOWNSTATUS!]";
108 /* -------------------------------------------------------------------------- */
109 /* class CommandPrintSuccess */
110 /* -------------------------------------------------------------------------- */
112 void CommandPrintSuccess::applyPrintSuccess(std::ostream
& out
)
114 out
.iword(s_iosIndex
) = d_printSuccess
;
117 bool CommandPrintSuccess::getPrintSuccess(std::ostream
& out
)
119 return out
.iword(s_iosIndex
);
122 void CommandPrintSuccess::setPrintSuccess(std::ostream
& out
, bool printSuccess
)
124 out
.iword(s_iosIndex
) = printSuccess
;
127 std::ostream
& operator<<(std::ostream
& out
, CommandPrintSuccess cps
)
129 cps
.applyPrintSuccess(out
);
133 /* -------------------------------------------------------------------------- */
135 /* -------------------------------------------------------------------------- */
137 Command::Command() : d_commandStatus(NULL
), d_muted(false) {}
138 Command::Command(const Command
& cmd
)
141 (cmd
.d_commandStatus
== NULL
) ? NULL
: &cmd
.d_commandStatus
->clone();
142 d_muted
= cmd
.d_muted
;
147 if (d_commandStatus
!= NULL
&& d_commandStatus
!= CommandSuccess::instance())
149 delete d_commandStatus
;
153 bool Command::ok() const
155 // either we haven't run the command yet, or it ran successfully
156 return d_commandStatus
== NULL
157 || dynamic_cast<const CommandSuccess
*>(d_commandStatus
) != NULL
;
160 bool Command::fail() const
162 return d_commandStatus
!= NULL
163 && dynamic_cast<const CommandFailure
*>(d_commandStatus
) != NULL
;
166 bool Command::interrupted() const
168 return d_commandStatus
!= NULL
169 && dynamic_cast<const CommandInterrupted
*>(d_commandStatus
) != NULL
;
172 void Command::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
175 if (!(isMuted() && ok()))
178 smtEngine
->getOption("command-verbosity:" + getCommandName())
184 std::string
Command::toString() const
186 std::stringstream ss
;
191 void Command::toStream(std::ostream
& out
,
195 OutputLanguage language
) const
197 Printer::getPrinter(language
)->toStream(out
, this, toDepth
, types
, dag
);
200 void CommandStatus::toStream(std::ostream
& out
, OutputLanguage language
) const
202 Printer::getPrinter(language
)->toStream(out
, this);
205 void Command::printResult(std::ostream
& out
, uint32_t verbosity
) const
207 if (d_commandStatus
!= NULL
)
209 if ((!ok() && verbosity
>= 1) || verbosity
>= 2)
211 out
<< *d_commandStatus
;
216 /* -------------------------------------------------------------------------- */
217 /* class EmptyCommand */
218 /* -------------------------------------------------------------------------- */
220 EmptyCommand::EmptyCommand(std::string name
) : d_name(name
) {}
221 std::string
EmptyCommand::getName() const { return d_name
; }
222 void EmptyCommand::invoke(SmtEngine
* smtEngine
)
224 /* empty commands have no implementation */
225 d_commandStatus
= CommandSuccess::instance();
228 Command
* EmptyCommand::exportTo(ExprManager
* exprManager
,
229 ExprManagerMapCollection
& variableMap
)
231 return new EmptyCommand(d_name
);
234 Command
* EmptyCommand::clone() const { return new EmptyCommand(d_name
); }
235 std::string
EmptyCommand::getCommandName() const { return "empty"; }
237 /* -------------------------------------------------------------------------- */
238 /* class EchoCommand */
239 /* -------------------------------------------------------------------------- */
241 EchoCommand::EchoCommand(std::string output
) : d_output(output
) {}
242 std::string
EchoCommand::getOutput() const { return d_output
; }
243 void EchoCommand::invoke(SmtEngine
* smtEngine
)
245 /* we don't have an output stream here, nothing to do */
246 d_commandStatus
= CommandSuccess::instance();
249 void EchoCommand::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
251 out
<< d_output
<< std::endl
;
252 Trace("dtview::command") << "* ~COMMAND: echo |" << d_output
<< "|~"
254 d_commandStatus
= CommandSuccess::instance();
256 smtEngine
->getOption("command-verbosity:" + getCommandName())
261 Command
* EchoCommand::exportTo(ExprManager
* exprManager
,
262 ExprManagerMapCollection
& variableMap
)
264 return new EchoCommand(d_output
);
267 Command
* EchoCommand::clone() const { return new EchoCommand(d_output
); }
268 std::string
EchoCommand::getCommandName() const { return "echo"; }
270 /* -------------------------------------------------------------------------- */
271 /* class AssertCommand */
272 /* -------------------------------------------------------------------------- */
274 AssertCommand::AssertCommand(const Expr
& e
, bool inUnsatCore
)
275 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
279 Expr
AssertCommand::getExpr() const { return d_expr
; }
280 void AssertCommand::invoke(SmtEngine
* smtEngine
)
284 smtEngine
->assertFormula(d_expr
, d_inUnsatCore
);
285 d_commandStatus
= CommandSuccess::instance();
287 catch (UnsafeInterruptException
& e
)
289 d_commandStatus
= new CommandInterrupted();
293 d_commandStatus
= new CommandFailure(e
.what());
297 Command
* AssertCommand::exportTo(ExprManager
* exprManager
,
298 ExprManagerMapCollection
& variableMap
)
300 return new AssertCommand(d_expr
.exportTo(exprManager
, variableMap
),
304 Command
* AssertCommand::clone() const
306 return new AssertCommand(d_expr
, d_inUnsatCore
);
309 std::string
AssertCommand::getCommandName() const { return "assert"; }
311 /* -------------------------------------------------------------------------- */
312 /* class PushCommand */
313 /* -------------------------------------------------------------------------- */
315 void PushCommand::invoke(SmtEngine
* smtEngine
)
320 d_commandStatus
= CommandSuccess::instance();
322 catch (UnsafeInterruptException
& e
)
324 d_commandStatus
= new CommandInterrupted();
328 d_commandStatus
= new CommandFailure(e
.what());
332 Command
* PushCommand::exportTo(ExprManager
* exprManager
,
333 ExprManagerMapCollection
& variableMap
)
335 return new PushCommand();
338 Command
* PushCommand::clone() const { return new PushCommand(); }
339 std::string
PushCommand::getCommandName() const { return "push"; }
341 /* -------------------------------------------------------------------------- */
342 /* class PopCommand */
343 /* -------------------------------------------------------------------------- */
345 void PopCommand::invoke(SmtEngine
* smtEngine
)
350 d_commandStatus
= CommandSuccess::instance();
352 catch (UnsafeInterruptException
& e
)
354 d_commandStatus
= new CommandInterrupted();
358 d_commandStatus
= new CommandFailure(e
.what());
362 Command
* PopCommand::exportTo(ExprManager
* exprManager
,
363 ExprManagerMapCollection
& variableMap
)
365 return new PopCommand();
368 Command
* PopCommand::clone() const { return new PopCommand(); }
369 std::string
PopCommand::getCommandName() const { return "pop"; }
371 /* -------------------------------------------------------------------------- */
372 /* class CheckSatCommand */
373 /* -------------------------------------------------------------------------- */
375 CheckSatCommand::CheckSatCommand() : d_expr() {}
377 CheckSatCommand::CheckSatCommand(const Expr
& expr
) : d_expr(expr
) {}
379 Expr
CheckSatCommand::getExpr() const { return d_expr
; }
380 void CheckSatCommand::invoke(SmtEngine
* smtEngine
)
382 Trace("dtview::command") << "* ~COMMAND: " << getCommandName() << "~"
386 d_result
= smtEngine
->checkSat(d_expr
);
387 d_commandStatus
= CommandSuccess::instance();
391 d_commandStatus
= new CommandFailure(e
.what());
395 Result
CheckSatCommand::getResult() const { return d_result
; }
396 void CheckSatCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
400 this->Command::printResult(out
, verbosity
);
404 Trace("dtview::command") << "* RESULT: " << d_result
<< std::endl
;
405 out
<< d_result
<< endl
;
409 Command
* CheckSatCommand::exportTo(ExprManager
* exprManager
,
410 ExprManagerMapCollection
& variableMap
)
413 new CheckSatCommand(d_expr
.exportTo(exprManager
, variableMap
));
414 c
->d_result
= d_result
;
418 Command
* CheckSatCommand::clone() const
420 CheckSatCommand
* c
= new CheckSatCommand(d_expr
);
421 c
->d_result
= d_result
;
425 std::string
CheckSatCommand::getCommandName() const { return "check-sat"; }
427 /* -------------------------------------------------------------------------- */
428 /* class CheckSatAssumingCommand */
429 /* -------------------------------------------------------------------------- */
431 CheckSatAssumingCommand::CheckSatAssumingCommand(Expr term
) : d_terms({term
}) {}
433 CheckSatAssumingCommand::CheckSatAssumingCommand(const std::vector
<Expr
>& terms
)
438 const std::vector
<Expr
>& CheckSatAssumingCommand::getTerms() const
443 void CheckSatAssumingCommand::invoke(SmtEngine
* smtEngine
)
445 Trace("dtview::command") << "* ~COMMAND: (check-sat-assuming ( " << d_terms
446 << " )~" << std::endl
;
449 d_result
= smtEngine
->checkSat(d_terms
);
450 d_commandStatus
= CommandSuccess::instance();
454 d_commandStatus
= new CommandFailure(e
.what());
458 Result
CheckSatAssumingCommand::getResult() const
460 Trace("dtview::command") << "* ~RESULT: " << d_result
<< "~" << std::endl
;
464 void CheckSatAssumingCommand::printResult(std::ostream
& out
,
465 uint32_t verbosity
) const
469 this->Command::printResult(out
, verbosity
);
473 out
<< d_result
<< endl
;
477 Command
* CheckSatAssumingCommand::exportTo(
478 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
480 vector
<Expr
> exportedTerms
;
481 for (const Expr
& e
: d_terms
)
483 exportedTerms
.push_back(e
.exportTo(exprManager
, variableMap
));
485 CheckSatAssumingCommand
* c
= new CheckSatAssumingCommand(exportedTerms
);
486 c
->d_result
= d_result
;
490 Command
* CheckSatAssumingCommand::clone() const
492 CheckSatAssumingCommand
* c
= new CheckSatAssumingCommand(d_terms
);
493 c
->d_result
= d_result
;
497 std::string
CheckSatAssumingCommand::getCommandName() const
499 return "check-sat-assuming";
502 /* -------------------------------------------------------------------------- */
503 /* class QueryCommand */
504 /* -------------------------------------------------------------------------- */
506 QueryCommand::QueryCommand(const Expr
& e
, bool inUnsatCore
)
507 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
511 Expr
QueryCommand::getExpr() const { return d_expr
; }
512 void QueryCommand::invoke(SmtEngine
* smtEngine
)
516 d_result
= smtEngine
->checkEntailed(d_expr
);
517 d_commandStatus
= CommandSuccess::instance();
521 d_commandStatus
= new CommandFailure(e
.what());
525 Result
QueryCommand::getResult() const { return d_result
; }
526 void QueryCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
530 this->Command::printResult(out
, verbosity
);
534 out
<< d_result
<< endl
;
538 Command
* QueryCommand::exportTo(ExprManager
* exprManager
,
539 ExprManagerMapCollection
& variableMap
)
541 QueryCommand
* c
= new QueryCommand(d_expr
.exportTo(exprManager
, variableMap
),
543 c
->d_result
= d_result
;
547 Command
* QueryCommand::clone() const
549 QueryCommand
* c
= new QueryCommand(d_expr
, d_inUnsatCore
);
550 c
->d_result
= d_result
;
554 std::string
QueryCommand::getCommandName() const { return "query"; }
556 /* -------------------------------------------------------------------------- */
557 /* class DeclareSygusVarCommand */
558 /* -------------------------------------------------------------------------- */
560 DeclareSygusVarCommand::DeclareSygusVarCommand(const std::string
& id
,
563 : DeclarationDefinitionCommand(id
), d_var(var
), d_type(t
)
567 Expr
DeclareSygusVarCommand::getVar() const { return d_var
; }
568 Type
DeclareSygusVarCommand::getType() const { return d_type
; }
570 void DeclareSygusVarCommand::invoke(SmtEngine
* smtEngine
)
574 smtEngine
->declareSygusVar(d_symbol
, d_var
, d_type
);
575 d_commandStatus
= CommandSuccess::instance();
579 d_commandStatus
= new CommandFailure(e
.what());
583 Command
* DeclareSygusVarCommand::exportTo(ExprManager
* exprManager
,
584 ExprManagerMapCollection
& variableMap
)
586 return new DeclareSygusVarCommand(d_symbol
,
587 d_var
.exportTo(exprManager
, variableMap
),
588 d_type
.exportTo(exprManager
, variableMap
));
591 Command
* DeclareSygusVarCommand::clone() const
593 return new DeclareSygusVarCommand(d_symbol
, d_var
, d_type
);
596 std::string
DeclareSygusVarCommand::getCommandName() const
598 return "declare-var";
601 /* -------------------------------------------------------------------------- */
602 /* class DeclareSygusPrimedVarCommand */
603 /* -------------------------------------------------------------------------- */
605 DeclareSygusPrimedVarCommand::DeclareSygusPrimedVarCommand(
606 const std::string
& id
, Type t
)
607 : DeclarationDefinitionCommand(id
), d_type(t
)
611 Type
DeclareSygusPrimedVarCommand::getType() const { return d_type
; }
613 void DeclareSygusPrimedVarCommand::invoke(SmtEngine
* smtEngine
)
617 smtEngine
->declareSygusPrimedVar(d_symbol
, d_type
);
618 d_commandStatus
= CommandSuccess::instance();
622 d_commandStatus
= new CommandFailure(e
.what());
626 Command
* DeclareSygusPrimedVarCommand::exportTo(
627 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
629 return new DeclareSygusPrimedVarCommand(
630 d_symbol
, d_type
.exportTo(exprManager
, variableMap
));
633 Command
* DeclareSygusPrimedVarCommand::clone() const
635 return new DeclareSygusPrimedVarCommand(d_symbol
, d_type
);
638 std::string
DeclareSygusPrimedVarCommand::getCommandName() const
640 return "declare-primed-var";
643 /* -------------------------------------------------------------------------- */
644 /* class DeclareSygusFunctionCommand */
645 /* -------------------------------------------------------------------------- */
647 DeclareSygusFunctionCommand::DeclareSygusFunctionCommand(const std::string
& id
,
650 : DeclarationDefinitionCommand(id
), d_func(func
), d_type(t
)
654 Expr
DeclareSygusFunctionCommand::getFunction() const { return d_func
; }
655 Type
DeclareSygusFunctionCommand::getType() const { return d_type
; }
657 void DeclareSygusFunctionCommand::invoke(SmtEngine
* smtEngine
)
661 smtEngine
->declareSygusFunctionVar(d_symbol
, d_func
, d_type
);
662 d_commandStatus
= CommandSuccess::instance();
666 d_commandStatus
= new CommandFailure(e
.what());
670 Command
* DeclareSygusFunctionCommand::exportTo(
671 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
673 return new DeclareSygusFunctionCommand(
675 d_func
.exportTo(exprManager
, variableMap
),
676 d_type
.exportTo(exprManager
, variableMap
));
679 Command
* DeclareSygusFunctionCommand::clone() const
681 return new DeclareSygusFunctionCommand(d_symbol
, d_func
, d_type
);
684 std::string
DeclareSygusFunctionCommand::getCommandName() const
686 return "declare-fun";
689 /* -------------------------------------------------------------------------- */
690 /* class SynthFunCommand */
691 /* -------------------------------------------------------------------------- */
693 SynthFunCommand::SynthFunCommand(const std::string
& id
,
697 const std::vector
<Expr
>& vars
)
698 : DeclarationDefinitionCommand(id
),
700 d_sygusType(sygusType
),
706 SynthFunCommand::SynthFunCommand(const std::string
& id
,
710 : SynthFunCommand(id
, func
, sygusType
, isInv
, {})
714 Expr
SynthFunCommand::getFunction() const { return d_func
; }
715 const std::vector
<Expr
>& SynthFunCommand::getVars() const { return d_vars
; }
716 Type
SynthFunCommand::getSygusType() const { return d_sygusType
; }
717 bool SynthFunCommand::isInv() const { return d_isInv
; }
719 void SynthFunCommand::invoke(SmtEngine
* smtEngine
)
723 smtEngine
->declareSynthFun(d_symbol
, d_func
, d_sygusType
, d_isInv
, d_vars
);
724 d_commandStatus
= CommandSuccess::instance();
728 d_commandStatus
= new CommandFailure(e
.what());
732 Command
* SynthFunCommand::exportTo(ExprManager
* exprManager
,
733 ExprManagerMapCollection
& variableMap
)
735 return new SynthFunCommand(d_symbol
,
736 d_func
.exportTo(exprManager
, variableMap
),
737 d_sygusType
.exportTo(exprManager
, variableMap
),
741 Command
* SynthFunCommand::clone() const
743 return new SynthFunCommand(d_symbol
, d_func
, d_sygusType
, d_isInv
, d_vars
);
746 std::string
SynthFunCommand::getCommandName() const
748 return d_isInv
? "synth-inv" : "synth-fun";
751 /* -------------------------------------------------------------------------- */
752 /* class SygusConstraintCommand */
753 /* -------------------------------------------------------------------------- */
755 SygusConstraintCommand::SygusConstraintCommand(const Expr
& e
) : d_expr(e
) {}
757 void SygusConstraintCommand::invoke(SmtEngine
* smtEngine
)
761 smtEngine
->assertSygusConstraint(d_expr
);
762 d_commandStatus
= CommandSuccess::instance();
766 d_commandStatus
= new CommandFailure(e
.what());
770 Expr
SygusConstraintCommand::getExpr() const { return d_expr
; }
772 Command
* SygusConstraintCommand::exportTo(ExprManager
* exprManager
,
773 ExprManagerMapCollection
& variableMap
)
775 return new SygusConstraintCommand(d_expr
.exportTo(exprManager
, variableMap
));
778 Command
* SygusConstraintCommand::clone() const
780 return new SygusConstraintCommand(d_expr
);
783 std::string
SygusConstraintCommand::getCommandName() const
788 /* -------------------------------------------------------------------------- */
789 /* class SygusInvConstraintCommand */
790 /* -------------------------------------------------------------------------- */
792 SygusInvConstraintCommand::SygusInvConstraintCommand(
793 const std::vector
<Expr
>& predicates
)
794 : d_predicates(predicates
)
798 SygusInvConstraintCommand::SygusInvConstraintCommand(const Expr
& inv
,
802 : SygusInvConstraintCommand(std::vector
<Expr
>{inv
, pre
, trans
, post
})
806 void SygusInvConstraintCommand::invoke(SmtEngine
* smtEngine
)
810 smtEngine
->assertSygusInvConstraint(
811 d_predicates
[0], d_predicates
[1], d_predicates
[2], d_predicates
[3]);
812 d_commandStatus
= CommandSuccess::instance();
816 d_commandStatus
= new CommandFailure(e
.what());
820 const std::vector
<Expr
>& SygusInvConstraintCommand::getPredicates() const
825 Command
* SygusInvConstraintCommand::exportTo(
826 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
828 return new SygusInvConstraintCommand(d_predicates
);
831 Command
* SygusInvConstraintCommand::clone() const
833 return new SygusInvConstraintCommand(d_predicates
);
836 std::string
SygusInvConstraintCommand::getCommandName() const
838 return "inv-constraint";
841 /* -------------------------------------------------------------------------- */
842 /* class CheckSynthCommand */
843 /* -------------------------------------------------------------------------- */
845 void CheckSynthCommand::invoke(SmtEngine
* smtEngine
)
849 d_result
= smtEngine
->checkSynth();
850 d_commandStatus
= CommandSuccess::instance();
851 smt::SmtScope
scope(smtEngine
);
853 // check whether we should print the status
854 if (d_result
.asSatisfiabilityResult() != Result::UNSAT
855 || options::sygusOut() == options::SygusSolutionOutMode::STATUS_AND_DEF
856 || options::sygusOut() == options::SygusSolutionOutMode::STATUS
)
858 if (options::sygusOut() == options::SygusSolutionOutMode::STANDARD
)
860 d_solution
<< "(fail)" << endl
;
864 d_solution
<< d_result
<< endl
;
867 // check whether we should print the solution
868 if (d_result
.asSatisfiabilityResult() == Result::UNSAT
869 && options::sygusOut() != options::SygusSolutionOutMode::STATUS
)
871 // printing a synthesis solution is a non-constant
872 // method, since it invokes a sophisticated algorithm
873 // (Figure 5 of Reynolds et al. CAV 2015).
874 // Hence, we must call here print solution here,
875 // instead of during printResult.
876 smtEngine
->printSynthSolution(d_solution
);
881 d_commandStatus
= new CommandFailure(e
.what());
885 Result
CheckSynthCommand::getResult() const { return d_result
; }
886 void CheckSynthCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
890 this->Command::printResult(out
, verbosity
);
894 out
<< d_solution
.str();
898 Command
* CheckSynthCommand::exportTo(ExprManager
* exprManager
,
899 ExprManagerMapCollection
& variableMap
)
901 return new CheckSynthCommand();
904 Command
* CheckSynthCommand::clone() const { return new CheckSynthCommand(); }
906 std::string
CheckSynthCommand::getCommandName() const { return "check-synth"; }
908 /* -------------------------------------------------------------------------- */
909 /* class ResetCommand */
910 /* -------------------------------------------------------------------------- */
912 void ResetCommand::invoke(SmtEngine
* smtEngine
)
917 d_commandStatus
= CommandSuccess::instance();
921 d_commandStatus
= new CommandFailure(e
.what());
925 Command
* ResetCommand::exportTo(ExprManager
* exprManager
,
926 ExprManagerMapCollection
& variableMap
)
928 return new ResetCommand();
931 Command
* ResetCommand::clone() const { return new ResetCommand(); }
932 std::string
ResetCommand::getCommandName() const { return "reset"; }
934 /* -------------------------------------------------------------------------- */
935 /* class ResetAssertionsCommand */
936 /* -------------------------------------------------------------------------- */
938 void ResetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
942 smtEngine
->resetAssertions();
943 d_commandStatus
= CommandSuccess::instance();
947 d_commandStatus
= new CommandFailure(e
.what());
951 Command
* ResetAssertionsCommand::exportTo(ExprManager
* exprManager
,
952 ExprManagerMapCollection
& variableMap
)
954 return new ResetAssertionsCommand();
957 Command
* ResetAssertionsCommand::clone() const
959 return new ResetAssertionsCommand();
962 std::string
ResetAssertionsCommand::getCommandName() const
964 return "reset-assertions";
967 /* -------------------------------------------------------------------------- */
968 /* class QuitCommand */
969 /* -------------------------------------------------------------------------- */
971 void QuitCommand::invoke(SmtEngine
* smtEngine
)
973 Dump("benchmark") << *this;
974 d_commandStatus
= CommandSuccess::instance();
977 Command
* QuitCommand::exportTo(ExprManager
* exprManager
,
978 ExprManagerMapCollection
& variableMap
)
980 return new QuitCommand();
983 Command
* QuitCommand::clone() const { return new QuitCommand(); }
984 std::string
QuitCommand::getCommandName() const { return "exit"; }
986 /* -------------------------------------------------------------------------- */
987 /* class CommentCommand */
988 /* -------------------------------------------------------------------------- */
990 CommentCommand::CommentCommand(std::string comment
) : d_comment(comment
) {}
991 std::string
CommentCommand::getComment() const { return d_comment
; }
992 void CommentCommand::invoke(SmtEngine
* smtEngine
)
994 Dump("benchmark") << *this;
995 d_commandStatus
= CommandSuccess::instance();
998 Command
* CommentCommand::exportTo(ExprManager
* exprManager
,
999 ExprManagerMapCollection
& variableMap
)
1001 return new CommentCommand(d_comment
);
1004 Command
* CommentCommand::clone() const { return new CommentCommand(d_comment
); }
1005 std::string
CommentCommand::getCommandName() const { return "comment"; }
1007 /* -------------------------------------------------------------------------- */
1008 /* class CommandSequence */
1009 /* -------------------------------------------------------------------------- */
1011 CommandSequence::CommandSequence() : d_index(0) {}
1012 CommandSequence::~CommandSequence()
1014 for (unsigned i
= d_index
; i
< d_commandSequence
.size(); ++i
)
1016 delete d_commandSequence
[i
];
1020 void CommandSequence::addCommand(Command
* cmd
)
1022 d_commandSequence
.push_back(cmd
);
1025 void CommandSequence::clear() { d_commandSequence
.clear(); }
1026 void CommandSequence::invoke(SmtEngine
* smtEngine
)
1028 for (; d_index
< d_commandSequence
.size(); ++d_index
)
1030 d_commandSequence
[d_index
]->invoke(smtEngine
);
1031 if (!d_commandSequence
[d_index
]->ok())
1034 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
1037 delete d_commandSequence
[d_index
];
1040 AlwaysAssert(d_commandStatus
== NULL
);
1041 d_commandStatus
= CommandSuccess::instance();
1044 void CommandSequence::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
1046 for (; d_index
< d_commandSequence
.size(); ++d_index
)
1048 d_commandSequence
[d_index
]->invoke(smtEngine
, out
);
1049 if (!d_commandSequence
[d_index
]->ok())
1052 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
1055 delete d_commandSequence
[d_index
];
1058 AlwaysAssert(d_commandStatus
== NULL
);
1059 d_commandStatus
= CommandSuccess::instance();
1062 Command
* CommandSequence::exportTo(ExprManager
* exprManager
,
1063 ExprManagerMapCollection
& variableMap
)
1065 CommandSequence
* seq
= new CommandSequence();
1066 for (iterator i
= begin(); i
!= end(); ++i
)
1068 Command
* cmd_to_export
= *i
;
1069 Command
* cmd
= cmd_to_export
->exportTo(exprManager
, variableMap
);
1070 seq
->addCommand(cmd
);
1071 Debug("export") << "[export] so far converted: " << seq
<< endl
;
1073 seq
->d_index
= d_index
;
1077 Command
* CommandSequence::clone() const
1079 CommandSequence
* seq
= new CommandSequence();
1080 for (const_iterator i
= begin(); i
!= end(); ++i
)
1082 seq
->addCommand((*i
)->clone());
1084 seq
->d_index
= d_index
;
1088 CommandSequence::const_iterator
CommandSequence::begin() const
1090 return d_commandSequence
.begin();
1093 CommandSequence::const_iterator
CommandSequence::end() const
1095 return d_commandSequence
.end();
1098 CommandSequence::iterator
CommandSequence::begin()
1100 return d_commandSequence
.begin();
1103 CommandSequence::iterator
CommandSequence::end()
1105 return d_commandSequence
.end();
1108 std::string
CommandSequence::getCommandName() const { return "sequence"; }
1110 /* -------------------------------------------------------------------------- */
1111 /* class DeclarationDefinitionCommand */
1112 /* -------------------------------------------------------------------------- */
1114 DeclarationDefinitionCommand::DeclarationDefinitionCommand(
1115 const std::string
& id
)
1120 std::string
DeclarationDefinitionCommand::getSymbol() const { return d_symbol
; }
1122 /* -------------------------------------------------------------------------- */
1123 /* class DeclareFunctionCommand */
1124 /* -------------------------------------------------------------------------- */
1126 DeclareFunctionCommand::DeclareFunctionCommand(const std::string
& id
,
1129 : DeclarationDefinitionCommand(id
),
1132 d_printInModel(true),
1133 d_printInModelSetByUser(false)
1137 Expr
DeclareFunctionCommand::getFunction() const { return d_func
; }
1138 Type
DeclareFunctionCommand::getType() const { return d_type
; }
1139 bool DeclareFunctionCommand::getPrintInModel() const { return d_printInModel
; }
1140 bool DeclareFunctionCommand::getPrintInModelSetByUser() const
1142 return d_printInModelSetByUser
;
1145 void DeclareFunctionCommand::setPrintInModel(bool p
)
1148 d_printInModelSetByUser
= true;
1151 void DeclareFunctionCommand::invoke(SmtEngine
* smtEngine
)
1153 d_commandStatus
= CommandSuccess::instance();
1156 Command
* DeclareFunctionCommand::exportTo(ExprManager
* exprManager
,
1157 ExprManagerMapCollection
& variableMap
)
1159 DeclareFunctionCommand
* dfc
=
1160 new DeclareFunctionCommand(d_symbol
,
1161 d_func
.exportTo(exprManager
, variableMap
),
1162 d_type
.exportTo(exprManager
, variableMap
));
1163 dfc
->d_printInModel
= d_printInModel
;
1164 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
1168 Command
* DeclareFunctionCommand::clone() const
1170 DeclareFunctionCommand
* dfc
=
1171 new DeclareFunctionCommand(d_symbol
, d_func
, d_type
);
1172 dfc
->d_printInModel
= d_printInModel
;
1173 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
1177 std::string
DeclareFunctionCommand::getCommandName() const
1179 return "declare-fun";
1182 /* -------------------------------------------------------------------------- */
1183 /* class DeclareTypeCommand */
1184 /* -------------------------------------------------------------------------- */
1186 DeclareTypeCommand::DeclareTypeCommand(const std::string
& id
,
1189 : DeclarationDefinitionCommand(id
), d_arity(arity
), d_type(t
)
1193 size_t DeclareTypeCommand::getArity() const { return d_arity
; }
1194 Type
DeclareTypeCommand::getType() const { return d_type
; }
1195 void DeclareTypeCommand::invoke(SmtEngine
* smtEngine
)
1197 d_commandStatus
= CommandSuccess::instance();
1200 Command
* DeclareTypeCommand::exportTo(ExprManager
* exprManager
,
1201 ExprManagerMapCollection
& variableMap
)
1203 return new DeclareTypeCommand(
1204 d_symbol
, d_arity
, d_type
.exportTo(exprManager
, variableMap
));
1207 Command
* DeclareTypeCommand::clone() const
1209 return new DeclareTypeCommand(d_symbol
, d_arity
, d_type
);
1212 std::string
DeclareTypeCommand::getCommandName() const
1214 return "declare-sort";
1217 /* -------------------------------------------------------------------------- */
1218 /* class DefineTypeCommand */
1219 /* -------------------------------------------------------------------------- */
1221 DefineTypeCommand::DefineTypeCommand(const std::string
& id
, Type t
)
1222 : DeclarationDefinitionCommand(id
), d_params(), d_type(t
)
1226 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
1227 const std::vector
<Type
>& params
,
1229 : DeclarationDefinitionCommand(id
), d_params(params
), d_type(t
)
1233 const std::vector
<Type
>& DefineTypeCommand::getParameters() const
1238 Type
DefineTypeCommand::getType() const { return d_type
; }
1239 void DefineTypeCommand::invoke(SmtEngine
* smtEngine
)
1241 d_commandStatus
= CommandSuccess::instance();
1244 Command
* DefineTypeCommand::exportTo(ExprManager
* exprManager
,
1245 ExprManagerMapCollection
& variableMap
)
1247 vector
<Type
> params
;
1248 transform(d_params
.begin(),
1250 back_inserter(params
),
1251 ExportTransformer(exprManager
, variableMap
));
1252 Type type
= d_type
.exportTo(exprManager
, variableMap
);
1253 return new DefineTypeCommand(d_symbol
, params
, type
);
1256 Command
* DefineTypeCommand::clone() const
1258 return new DefineTypeCommand(d_symbol
, d_params
, d_type
);
1261 std::string
DefineTypeCommand::getCommandName() const { return "define-sort"; }
1263 /* -------------------------------------------------------------------------- */
1264 /* class DefineFunctionCommand */
1265 /* -------------------------------------------------------------------------- */
1267 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1271 : DeclarationDefinitionCommand(id
),
1279 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1281 const std::vector
<Expr
>& formals
,
1284 : DeclarationDefinitionCommand(id
),
1293 Expr
DefineFunctionCommand::getFunction() const { return d_func
; }
1294 const std::vector
<Expr
>& DefineFunctionCommand::getFormals() const
1299 Expr
DefineFunctionCommand::getFormula() const { return d_formula
; }
1300 void DefineFunctionCommand::invoke(SmtEngine
* smtEngine
)
1304 if (!d_func
.isNull())
1306 smtEngine
->defineFunction(d_func
, d_formals
, d_formula
, d_global
);
1308 d_commandStatus
= CommandSuccess::instance();
1310 catch (exception
& e
)
1312 d_commandStatus
= new CommandFailure(e
.what());
1316 Command
* DefineFunctionCommand::exportTo(ExprManager
* exprManager
,
1317 ExprManagerMapCollection
& variableMap
)
1319 Expr func
= d_func
.exportTo(
1320 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1321 vector
<Expr
> formals
;
1322 transform(d_formals
.begin(),
1324 back_inserter(formals
),
1325 ExportTransformer(exprManager
, variableMap
));
1326 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1327 return new DefineFunctionCommand(d_symbol
, func
, formals
, formula
, d_global
);
1330 Command
* DefineFunctionCommand::clone() const
1332 return new DefineFunctionCommand(
1333 d_symbol
, d_func
, d_formals
, d_formula
, d_global
);
1336 std::string
DefineFunctionCommand::getCommandName() const
1338 return "define-fun";
1341 /* -------------------------------------------------------------------------- */
1342 /* class DefineNamedFunctionCommand */
1343 /* -------------------------------------------------------------------------- */
1345 DefineNamedFunctionCommand::DefineNamedFunctionCommand(
1346 const std::string
& id
,
1348 const std::vector
<Expr
>& formals
,
1351 : DefineFunctionCommand(id
, func
, formals
, formula
, global
)
1355 void DefineNamedFunctionCommand::invoke(SmtEngine
* smtEngine
)
1357 this->DefineFunctionCommand::invoke(smtEngine
);
1358 if (!d_func
.isNull() && d_func
.getType().isBoolean())
1360 smtEngine
->addToAssignment(d_func
);
1362 d_commandStatus
= CommandSuccess::instance();
1365 Command
* DefineNamedFunctionCommand::exportTo(
1366 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1368 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
1369 vector
<Expr
> formals
;
1370 transform(d_formals
.begin(),
1372 back_inserter(formals
),
1373 ExportTransformer(exprManager
, variableMap
));
1374 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1375 return new DefineNamedFunctionCommand(
1376 d_symbol
, func
, formals
, formula
, d_global
);
1379 Command
* DefineNamedFunctionCommand::clone() const
1381 return new DefineNamedFunctionCommand(
1382 d_symbol
, d_func
, d_formals
, d_formula
, d_global
);
1385 /* -------------------------------------------------------------------------- */
1386 /* class DefineFunctionRecCommand */
1387 /* -------------------------------------------------------------------------- */
1389 DefineFunctionRecCommand::DefineFunctionRecCommand(
1390 Expr func
, const std::vector
<Expr
>& formals
, Expr formula
, bool global
)
1393 d_funcs
.push_back(func
);
1394 d_formals
.push_back(formals
);
1395 d_formulas
.push_back(formula
);
1398 DefineFunctionRecCommand::DefineFunctionRecCommand(
1399 const std::vector
<Expr
>& funcs
,
1400 const std::vector
<std::vector
<Expr
>>& formals
,
1401 const std::vector
<Expr
>& formulas
,
1403 : d_funcs(funcs
), d_formals(formals
), d_formulas(formulas
), d_global(global
)
1407 const std::vector
<Expr
>& DefineFunctionRecCommand::getFunctions() const
1412 const std::vector
<std::vector
<Expr
>>& DefineFunctionRecCommand::getFormals()
1418 const std::vector
<Expr
>& DefineFunctionRecCommand::getFormulas() const
1423 void DefineFunctionRecCommand::invoke(SmtEngine
* smtEngine
)
1427 smtEngine
->defineFunctionsRec(d_funcs
, d_formals
, d_formulas
, d_global
);
1428 d_commandStatus
= CommandSuccess::instance();
1430 catch (exception
& e
)
1432 d_commandStatus
= new CommandFailure(e
.what());
1436 Command
* DefineFunctionRecCommand::exportTo(
1437 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1439 std::vector
<Expr
> funcs
;
1440 for (unsigned i
= 0, size
= d_funcs
.size(); i
< size
; i
++)
1442 Expr func
= d_funcs
[i
].exportTo(
1443 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1444 funcs
.push_back(func
);
1446 std::vector
<std::vector
<Expr
>> formals
;
1447 for (unsigned i
= 0, size
= d_formals
.size(); i
< size
; i
++)
1449 std::vector
<Expr
> formals_c
;
1450 transform(d_formals
[i
].begin(),
1452 back_inserter(formals_c
),
1453 ExportTransformer(exprManager
, variableMap
));
1454 formals
.push_back(formals_c
);
1456 std::vector
<Expr
> formulas
;
1457 for (unsigned i
= 0, size
= d_formulas
.size(); i
< size
; i
++)
1459 Expr formula
= d_formulas
[i
].exportTo(exprManager
, variableMap
);
1460 formulas
.push_back(formula
);
1462 return new DefineFunctionRecCommand(funcs
, formals
, formulas
, d_global
);
1465 Command
* DefineFunctionRecCommand::clone() const
1467 return new DefineFunctionRecCommand(d_funcs
, d_formals
, d_formulas
, d_global
);
1470 std::string
DefineFunctionRecCommand::getCommandName() const
1472 return "define-fun-rec";
1475 /* -------------------------------------------------------------------------- */
1476 /* class SetUserAttribute */
1477 /* -------------------------------------------------------------------------- */
1479 SetUserAttributeCommand::SetUserAttributeCommand(
1480 const std::string
& attr
,
1482 const std::vector
<Expr
>& expr_values
,
1483 const std::string
& str_value
)
1486 d_expr_values(expr_values
),
1487 d_str_value(str_value
)
1491 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1493 : SetUserAttributeCommand(attr
, expr
, {}, "")
1497 SetUserAttributeCommand::SetUserAttributeCommand(
1498 const std::string
& attr
, Expr expr
, const std::vector
<Expr
>& values
)
1499 : SetUserAttributeCommand(attr
, expr
, values
, "")
1503 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1505 const std::string
& value
)
1506 : SetUserAttributeCommand(attr
, expr
, {}, value
)
1510 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
)
1514 if (!d_expr
.isNull())
1516 smtEngine
->setUserAttribute(d_attr
, d_expr
, d_expr_values
, d_str_value
);
1518 d_commandStatus
= CommandSuccess::instance();
1520 catch (exception
& e
)
1522 d_commandStatus
= new CommandFailure(e
.what());
1526 Command
* SetUserAttributeCommand::exportTo(
1527 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1529 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
1530 return new SetUserAttributeCommand(d_attr
, expr
, d_expr_values
, d_str_value
);
1533 Command
* SetUserAttributeCommand::clone() const
1535 return new SetUserAttributeCommand(
1536 d_attr
, d_expr
, d_expr_values
, d_str_value
);
1539 std::string
SetUserAttributeCommand::getCommandName() const
1541 return "set-user-attribute";
1544 /* -------------------------------------------------------------------------- */
1545 /* class SimplifyCommand */
1546 /* -------------------------------------------------------------------------- */
1548 SimplifyCommand::SimplifyCommand(Expr term
) : d_term(term
) {}
1549 Expr
SimplifyCommand::getTerm() const { return d_term
; }
1550 void SimplifyCommand::invoke(SmtEngine
* smtEngine
)
1554 d_result
= smtEngine
->simplify(d_term
);
1555 d_commandStatus
= CommandSuccess::instance();
1557 catch (UnsafeInterruptException
& e
)
1559 d_commandStatus
= new CommandInterrupted();
1561 catch (exception
& e
)
1563 d_commandStatus
= new CommandFailure(e
.what());
1567 Expr
SimplifyCommand::getResult() const { return d_result
; }
1568 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1572 this->Command::printResult(out
, verbosity
);
1576 out
<< d_result
<< endl
;
1580 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
,
1581 ExprManagerMapCollection
& variableMap
)
1583 SimplifyCommand
* c
=
1584 new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
1585 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1589 Command
* SimplifyCommand::clone() const
1591 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
1592 c
->d_result
= d_result
;
1596 std::string
SimplifyCommand::getCommandName() const { return "simplify"; }
1598 /* -------------------------------------------------------------------------- */
1599 /* class ExpandDefinitionsCommand */
1600 /* -------------------------------------------------------------------------- */
1602 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) : d_term(term
) {}
1603 Expr
ExpandDefinitionsCommand::getTerm() const { return d_term
; }
1604 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
)
1606 d_result
= smtEngine
->expandDefinitions(d_term
);
1607 d_commandStatus
= CommandSuccess::instance();
1610 Expr
ExpandDefinitionsCommand::getResult() const { return d_result
; }
1611 void ExpandDefinitionsCommand::printResult(std::ostream
& out
,
1612 uint32_t verbosity
) const
1616 this->Command::printResult(out
, verbosity
);
1620 out
<< d_result
<< endl
;
1624 Command
* ExpandDefinitionsCommand::exportTo(
1625 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1627 ExpandDefinitionsCommand
* c
=
1628 new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
1629 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1633 Command
* ExpandDefinitionsCommand::clone() const
1635 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
1636 c
->d_result
= d_result
;
1640 std::string
ExpandDefinitionsCommand::getCommandName() const
1642 return "expand-definitions";
1645 /* -------------------------------------------------------------------------- */
1646 /* class GetValueCommand */
1647 /* -------------------------------------------------------------------------- */
1649 GetValueCommand::GetValueCommand(Expr term
) : d_terms()
1651 d_terms
.push_back(term
);
1654 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
)
1657 PrettyCheckArgument(
1658 terms
.size() >= 1, terms
, "cannot get-value of an empty set of terms");
1661 const std::vector
<Expr
>& GetValueCommand::getTerms() const { return d_terms
; }
1662 void GetValueCommand::invoke(SmtEngine
* smtEngine
)
1666 ExprManager
* em
= smtEngine
->getExprManager();
1667 NodeManager
* nm
= NodeManager::fromExprManager(em
);
1668 smt::SmtScope
scope(smtEngine
);
1669 vector
<Expr
> result
= smtEngine
->getValues(d_terms
);
1670 Assert(result
.size() == d_terms
.size());
1671 for (int i
= 0, size
= d_terms
.size(); i
< size
; i
++)
1673 Expr e
= d_terms
[i
];
1674 Assert(nm
== NodeManager::fromExprManager(e
.getExprManager()));
1675 Node request
= Node::fromExpr(
1676 options::expandDefinitions() ? smtEngine
->expandDefinitions(e
) : e
);
1677 Node value
= Node::fromExpr(result
[i
]);
1678 if (value
.getType().isInteger() && request
.getType() == nm
->realType())
1680 // Need to wrap in division-by-one so that output printers know this
1681 // is an integer-looking constant that really should be output as
1682 // a rational. Necessary for SMT-LIB standards compliance.
1683 value
= nm
->mkNode(kind::DIVISION
, value
, nm
->mkConst(Rational(1)));
1685 result
[i
] = nm
->mkNode(kind::SEXPR
, request
, value
).toExpr();
1687 d_result
= em
->mkExpr(kind::SEXPR
, result
);
1688 d_commandStatus
= CommandSuccess::instance();
1690 catch (RecoverableModalException
& e
)
1692 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1694 catch (UnsafeInterruptException
& e
)
1696 d_commandStatus
= new CommandInterrupted();
1698 catch (exception
& e
)
1700 d_commandStatus
= new CommandFailure(e
.what());
1704 Expr
GetValueCommand::getResult() const { return d_result
; }
1705 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1709 this->Command::printResult(out
, verbosity
);
1713 expr::ExprDag::Scope
scope(out
, false);
1714 out
<< d_result
<< endl
;
1718 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
,
1719 ExprManagerMapCollection
& variableMap
)
1721 vector
<Expr
> exportedTerms
;
1722 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1726 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1728 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1729 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1733 Command
* GetValueCommand::clone() const
1735 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1736 c
->d_result
= d_result
;
1740 std::string
GetValueCommand::getCommandName() const { return "get-value"; }
1742 /* -------------------------------------------------------------------------- */
1743 /* class GetAssignmentCommand */
1744 /* -------------------------------------------------------------------------- */
1746 GetAssignmentCommand::GetAssignmentCommand() {}
1747 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
)
1751 std::vector
<std::pair
<Expr
, Expr
>> assignments
= smtEngine
->getAssignment();
1752 vector
<SExpr
> sexprs
;
1753 for (const auto& p
: assignments
)
1756 v
.emplace_back(SExpr::Keyword(p
.first
.toString()));
1757 v
.emplace_back(SExpr::Keyword(p
.second
.toString()));
1758 sexprs
.emplace_back(v
);
1760 d_result
= SExpr(sexprs
);
1761 d_commandStatus
= CommandSuccess::instance();
1763 catch (RecoverableModalException
& e
)
1765 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1767 catch (UnsafeInterruptException
& e
)
1769 d_commandStatus
= new CommandInterrupted();
1771 catch (exception
& e
)
1773 d_commandStatus
= new CommandFailure(e
.what());
1777 SExpr
GetAssignmentCommand::getResult() const { return d_result
; }
1778 void GetAssignmentCommand::printResult(std::ostream
& out
,
1779 uint32_t verbosity
) const
1783 this->Command::printResult(out
, verbosity
);
1787 out
<< d_result
<< endl
;
1791 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
,
1792 ExprManagerMapCollection
& variableMap
)
1794 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1795 c
->d_result
= d_result
;
1799 Command
* GetAssignmentCommand::clone() const
1801 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1802 c
->d_result
= d_result
;
1806 std::string
GetAssignmentCommand::getCommandName() const
1808 return "get-assignment";
1811 /* -------------------------------------------------------------------------- */
1812 /* class GetModelCommand */
1813 /* -------------------------------------------------------------------------- */
1815 GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
1816 void GetModelCommand::invoke(SmtEngine
* smtEngine
)
1820 d_result
= smtEngine
->getModel();
1821 d_smtEngine
= smtEngine
;
1822 d_commandStatus
= CommandSuccess::instance();
1824 catch (RecoverableModalException
& e
)
1826 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1828 catch (UnsafeInterruptException
& e
)
1830 d_commandStatus
= new CommandInterrupted();
1832 catch (exception
& e
)
1834 d_commandStatus
= new CommandFailure(e
.what());
1838 /* Model is private to the library -- for now
1839 Model* GetModelCommand::getResult() const {
1844 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1848 this->Command::printResult(out
, verbosity
);
1856 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
,
1857 ExprManagerMapCollection
& variableMap
)
1859 GetModelCommand
* c
= new GetModelCommand();
1860 c
->d_result
= d_result
;
1861 c
->d_smtEngine
= d_smtEngine
;
1865 Command
* GetModelCommand::clone() const
1867 GetModelCommand
* c
= new GetModelCommand();
1868 c
->d_result
= d_result
;
1869 c
->d_smtEngine
= d_smtEngine
;
1873 std::string
GetModelCommand::getCommandName() const { return "get-model"; }
1875 /* -------------------------------------------------------------------------- */
1876 /* class BlockModelCommand */
1877 /* -------------------------------------------------------------------------- */
1879 BlockModelCommand::BlockModelCommand() {}
1880 void BlockModelCommand::invoke(SmtEngine
* smtEngine
)
1884 smtEngine
->blockModel();
1885 d_commandStatus
= CommandSuccess::instance();
1887 catch (RecoverableModalException
& e
)
1889 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1891 catch (UnsafeInterruptException
& e
)
1893 d_commandStatus
= new CommandInterrupted();
1895 catch (exception
& e
)
1897 d_commandStatus
= new CommandFailure(e
.what());
1901 Command
* BlockModelCommand::exportTo(ExprManager
* exprManager
,
1902 ExprManagerMapCollection
& variableMap
)
1904 BlockModelCommand
* c
= new BlockModelCommand();
1908 Command
* BlockModelCommand::clone() const
1910 BlockModelCommand
* c
= new BlockModelCommand();
1914 std::string
BlockModelCommand::getCommandName() const { return "block-model"; }
1916 /* -------------------------------------------------------------------------- */
1917 /* class BlockModelValuesCommand */
1918 /* -------------------------------------------------------------------------- */
1920 BlockModelValuesCommand::BlockModelValuesCommand(const std::vector
<Expr
>& terms
)
1923 PrettyCheckArgument(terms
.size() >= 1,
1925 "cannot block-model-values of an empty set of terms");
1928 const std::vector
<Expr
>& BlockModelValuesCommand::getTerms() const
1932 void BlockModelValuesCommand::invoke(SmtEngine
* smtEngine
)
1936 smtEngine
->blockModelValues(d_terms
);
1937 d_commandStatus
= CommandSuccess::instance();
1939 catch (RecoverableModalException
& e
)
1941 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1943 catch (UnsafeInterruptException
& e
)
1945 d_commandStatus
= new CommandInterrupted();
1947 catch (exception
& e
)
1949 d_commandStatus
= new CommandFailure(e
.what());
1953 Command
* BlockModelValuesCommand::exportTo(
1954 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1956 vector
<Expr
> exportedTerms
;
1957 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1961 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1963 BlockModelValuesCommand
* c
= new BlockModelValuesCommand(exportedTerms
);
1967 Command
* BlockModelValuesCommand::clone() const
1969 BlockModelValuesCommand
* c
= new BlockModelValuesCommand(d_terms
);
1973 std::string
BlockModelValuesCommand::getCommandName() const
1975 return "block-model-values";
1978 /* -------------------------------------------------------------------------- */
1979 /* class GetProofCommand */
1980 /* -------------------------------------------------------------------------- */
1982 GetProofCommand::GetProofCommand() : d_smtEngine(nullptr), d_result(nullptr) {}
1983 void GetProofCommand::invoke(SmtEngine
* smtEngine
)
1987 d_smtEngine
= smtEngine
;
1988 d_result
= &smtEngine
->getProof();
1989 d_commandStatus
= CommandSuccess::instance();
1991 catch (RecoverableModalException
& e
)
1993 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1995 catch (UnsafeInterruptException
& e
)
1997 d_commandStatus
= new CommandInterrupted();
1999 catch (exception
& e
)
2001 d_commandStatus
= new CommandFailure(e
.what());
2005 const Proof
& GetProofCommand::getResult() const { return *d_result
; }
2006 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2010 this->Command::printResult(out
, verbosity
);
2014 smt::SmtScope
scope(d_smtEngine
);
2015 d_result
->toStream(out
);
2019 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
,
2020 ExprManagerMapCollection
& variableMap
)
2022 GetProofCommand
* c
= new GetProofCommand();
2023 c
->d_result
= d_result
;
2024 c
->d_smtEngine
= d_smtEngine
;
2028 Command
* GetProofCommand::clone() const
2030 GetProofCommand
* c
= new GetProofCommand();
2031 c
->d_result
= d_result
;
2032 c
->d_smtEngine
= d_smtEngine
;
2036 std::string
GetProofCommand::getCommandName() const { return "get-proof"; }
2038 /* -------------------------------------------------------------------------- */
2039 /* class GetInstantiationsCommand */
2040 /* -------------------------------------------------------------------------- */
2042 GetInstantiationsCommand::GetInstantiationsCommand() : d_smtEngine(nullptr) {}
2043 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
)
2047 d_smtEngine
= smtEngine
;
2048 d_commandStatus
= CommandSuccess::instance();
2050 catch (exception
& e
)
2052 d_commandStatus
= new CommandFailure(e
.what());
2056 void GetInstantiationsCommand::printResult(std::ostream
& out
,
2057 uint32_t verbosity
) const
2061 this->Command::printResult(out
, verbosity
);
2065 d_smtEngine
->printInstantiations(out
);
2069 Command
* GetInstantiationsCommand::exportTo(
2070 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2072 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
2073 // c->d_result = d_result;
2074 c
->d_smtEngine
= d_smtEngine
;
2078 Command
* GetInstantiationsCommand::clone() const
2080 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
2081 // c->d_result = d_result;
2082 c
->d_smtEngine
= d_smtEngine
;
2086 std::string
GetInstantiationsCommand::getCommandName() const
2088 return "get-instantiations";
2091 /* -------------------------------------------------------------------------- */
2092 /* class GetSynthSolutionCommand */
2093 /* -------------------------------------------------------------------------- */
2095 GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
2096 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
)
2100 d_smtEngine
= smtEngine
;
2101 d_commandStatus
= CommandSuccess::instance();
2103 catch (exception
& e
)
2105 d_commandStatus
= new CommandFailure(e
.what());
2109 void GetSynthSolutionCommand::printResult(std::ostream
& out
,
2110 uint32_t verbosity
) const
2114 this->Command::printResult(out
, verbosity
);
2118 d_smtEngine
->printSynthSolution(out
);
2122 Command
* GetSynthSolutionCommand::exportTo(
2123 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2125 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2126 c
->d_smtEngine
= d_smtEngine
;
2130 Command
* GetSynthSolutionCommand::clone() const
2132 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2133 c
->d_smtEngine
= d_smtEngine
;
2137 std::string
GetSynthSolutionCommand::getCommandName() const
2139 return "get-instantiations";
2142 GetAbductCommand::GetAbductCommand() {}
2143 GetAbductCommand::GetAbductCommand(const std::string
& name
, Expr conj
)
2144 : d_name(name
), d_conj(conj
), d_resultStatus(false)
2147 GetAbductCommand::GetAbductCommand(const std::string
& name
,
2152 d_sygus_grammar_type(gtype
),
2153 d_resultStatus(false)
2157 Expr
GetAbductCommand::getConjecture() const { return d_conj
; }
2158 Type
GetAbductCommand::getGrammarType() const { return d_sygus_grammar_type
; }
2159 Expr
GetAbductCommand::getResult() const { return d_result
; }
2161 void GetAbductCommand::invoke(SmtEngine
* smtEngine
)
2165 if (d_sygus_grammar_type
.isNull())
2167 d_resultStatus
= smtEngine
->getAbduct(d_conj
, d_result
);
2172 smtEngine
->getAbduct(d_conj
, d_sygus_grammar_type
, d_result
);
2174 d_commandStatus
= CommandSuccess::instance();
2176 catch (exception
& e
)
2178 d_commandStatus
= new CommandFailure(e
.what());
2182 void GetAbductCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2186 this->Command::printResult(out
, verbosity
);
2190 expr::ExprDag::Scope
scope(out
, false);
2193 out
<< "(define-fun " << d_name
<< " () Bool " << d_result
<< ")"
2198 out
<< "none" << std::endl
;
2203 Command
* GetAbductCommand::exportTo(ExprManager
* exprManager
,
2204 ExprManagerMapCollection
& variableMap
)
2206 GetAbductCommand
* c
=
2207 new GetAbductCommand(d_name
, d_conj
.exportTo(exprManager
, variableMap
));
2208 c
->d_sygus_grammar_type
=
2209 d_sygus_grammar_type
.exportTo(exprManager
, variableMap
);
2210 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
2211 c
->d_resultStatus
= d_resultStatus
;
2215 Command
* GetAbductCommand::clone() const
2217 GetAbductCommand
* c
= new GetAbductCommand(d_name
, d_conj
);
2218 c
->d_sygus_grammar_type
= d_sygus_grammar_type
;
2219 c
->d_result
= d_result
;
2220 c
->d_resultStatus
= d_resultStatus
;
2224 std::string
GetAbductCommand::getCommandName() const { return "get-abduct"; }
2226 /* -------------------------------------------------------------------------- */
2227 /* class GetQuantifierEliminationCommand */
2228 /* -------------------------------------------------------------------------- */
2230 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand()
2231 : d_expr(), d_doFull(true)
2234 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
2235 const Expr
& expr
, bool doFull
)
2236 : d_expr(expr
), d_doFull(doFull
)
2240 Expr
GetQuantifierEliminationCommand::getExpr() const { return d_expr
; }
2241 bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull
; }
2242 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
)
2246 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
2247 d_commandStatus
= CommandSuccess::instance();
2249 catch (exception
& e
)
2251 d_commandStatus
= new CommandFailure(e
.what());
2255 Expr
GetQuantifierEliminationCommand::getResult() const { return d_result
; }
2256 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
,
2257 uint32_t verbosity
) const
2261 this->Command::printResult(out
, verbosity
);
2265 out
<< d_result
<< endl
;
2269 Command
* GetQuantifierEliminationCommand::exportTo(
2270 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2272 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(
2273 d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
2274 c
->d_result
= d_result
;
2278 Command
* GetQuantifierEliminationCommand::clone() const
2280 GetQuantifierEliminationCommand
* c
=
2281 new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
2282 c
->d_result
= d_result
;
2286 std::string
GetQuantifierEliminationCommand::getCommandName() const
2288 return d_doFull
? "get-qe" : "get-qe-disjunct";
2291 /* -------------------------------------------------------------------------- */
2292 /* class GetUnsatAssumptionsCommand */
2293 /* -------------------------------------------------------------------------- */
2295 GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
2297 void GetUnsatAssumptionsCommand::invoke(SmtEngine
* smtEngine
)
2301 d_result
= smtEngine
->getUnsatAssumptions();
2302 d_commandStatus
= CommandSuccess::instance();
2304 catch (RecoverableModalException
& e
)
2306 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2308 catch (exception
& e
)
2310 d_commandStatus
= new CommandFailure(e
.what());
2314 std::vector
<Expr
> GetUnsatAssumptionsCommand::getResult() const
2319 void GetUnsatAssumptionsCommand::printResult(std::ostream
& out
,
2320 uint32_t verbosity
) const
2324 this->Command::printResult(out
, verbosity
);
2328 container_to_stream(out
, d_result
, "(", ")\n", " ");
2332 Command
* GetUnsatAssumptionsCommand::exportTo(
2333 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2335 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2336 c
->d_result
= d_result
;
2340 Command
* GetUnsatAssumptionsCommand::clone() const
2342 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2343 c
->d_result
= d_result
;
2347 std::string
GetUnsatAssumptionsCommand::getCommandName() const
2349 return "get-unsat-assumptions";
2352 /* -------------------------------------------------------------------------- */
2353 /* class GetUnsatCoreCommand */
2354 /* -------------------------------------------------------------------------- */
2356 GetUnsatCoreCommand::GetUnsatCoreCommand() {}
2357 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
)
2361 d_result
= smtEngine
->getUnsatCore();
2362 d_commandStatus
= CommandSuccess::instance();
2364 catch (RecoverableModalException
& e
)
2366 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2368 catch (exception
& e
)
2370 d_commandStatus
= new CommandFailure(e
.what());
2374 void GetUnsatCoreCommand::printResult(std::ostream
& out
,
2375 uint32_t verbosity
) const
2379 this->Command::printResult(out
, verbosity
);
2383 d_result
.toStream(out
);
2387 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const
2389 // of course, this will be empty if the command hasn't been invoked yet
2393 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
,
2394 ExprManagerMapCollection
& variableMap
)
2396 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2397 c
->d_result
= d_result
;
2401 Command
* GetUnsatCoreCommand::clone() const
2403 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2404 c
->d_result
= d_result
;
2408 std::string
GetUnsatCoreCommand::getCommandName() const
2410 return "get-unsat-core";
2413 /* -------------------------------------------------------------------------- */
2414 /* class GetAssertionsCommand */
2415 /* -------------------------------------------------------------------------- */
2417 GetAssertionsCommand::GetAssertionsCommand() {}
2418 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
2423 const vector
<Expr
> v
= smtEngine
->getAssertions();
2425 copy(v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n"));
2427 d_result
= ss
.str();
2428 d_commandStatus
= CommandSuccess::instance();
2430 catch (exception
& e
)
2432 d_commandStatus
= new CommandFailure(e
.what());
2436 std::string
GetAssertionsCommand::getResult() const { return d_result
; }
2437 void GetAssertionsCommand::printResult(std::ostream
& out
,
2438 uint32_t verbosity
) const
2442 this->Command::printResult(out
, verbosity
);
2450 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
,
2451 ExprManagerMapCollection
& variableMap
)
2453 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2454 c
->d_result
= d_result
;
2458 Command
* GetAssertionsCommand::clone() const
2460 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2461 c
->d_result
= d_result
;
2465 std::string
GetAssertionsCommand::getCommandName() const
2467 return "get-assertions";
2470 /* -------------------------------------------------------------------------- */
2471 /* class SetBenchmarkStatusCommand */
2472 /* -------------------------------------------------------------------------- */
2474 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
)
2479 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const
2484 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
)
2490 SExpr status
= SExpr(ss
.str());
2491 smtEngine
->setInfo("status", status
);
2492 d_commandStatus
= CommandSuccess::instance();
2494 catch (exception
& e
)
2496 d_commandStatus
= new CommandFailure(e
.what());
2500 Command
* SetBenchmarkStatusCommand::exportTo(
2501 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2503 return new SetBenchmarkStatusCommand(d_status
);
2506 Command
* SetBenchmarkStatusCommand::clone() const
2508 return new SetBenchmarkStatusCommand(d_status
);
2511 std::string
SetBenchmarkStatusCommand::getCommandName() const
2516 /* -------------------------------------------------------------------------- */
2517 /* class SetBenchmarkLogicCommand */
2518 /* -------------------------------------------------------------------------- */
2520 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
)
2525 std::string
SetBenchmarkLogicCommand::getLogic() const { return d_logic
; }
2526 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
)
2530 smtEngine
->setLogic(d_logic
);
2531 d_commandStatus
= CommandSuccess::instance();
2533 catch (exception
& e
)
2535 d_commandStatus
= new CommandFailure(e
.what());
2539 Command
* SetBenchmarkLogicCommand::exportTo(
2540 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2542 return new SetBenchmarkLogicCommand(d_logic
);
2545 Command
* SetBenchmarkLogicCommand::clone() const
2547 return new SetBenchmarkLogicCommand(d_logic
);
2550 std::string
SetBenchmarkLogicCommand::getCommandName() const
2555 /* -------------------------------------------------------------------------- */
2556 /* class SetInfoCommand */
2557 /* -------------------------------------------------------------------------- */
2559 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
)
2560 : d_flag(flag
), d_sexpr(sexpr
)
2564 std::string
SetInfoCommand::getFlag() const { return d_flag
; }
2565 SExpr
SetInfoCommand::getSExpr() const { return d_sexpr
; }
2566 void SetInfoCommand::invoke(SmtEngine
* smtEngine
)
2570 smtEngine
->setInfo(d_flag
, d_sexpr
);
2571 d_commandStatus
= CommandSuccess::instance();
2573 catch (UnrecognizedOptionException
&)
2575 // As per SMT-LIB spec, silently accept unknown set-info keys
2576 d_commandStatus
= CommandSuccess::instance();
2578 catch (exception
& e
)
2580 d_commandStatus
= new CommandFailure(e
.what());
2584 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
,
2585 ExprManagerMapCollection
& variableMap
)
2587 return new SetInfoCommand(d_flag
, d_sexpr
);
2590 Command
* SetInfoCommand::clone() const
2592 return new SetInfoCommand(d_flag
, d_sexpr
);
2595 std::string
SetInfoCommand::getCommandName() const { return "set-info"; }
2597 /* -------------------------------------------------------------------------- */
2598 /* class GetInfoCommand */
2599 /* -------------------------------------------------------------------------- */
2601 GetInfoCommand::GetInfoCommand(std::string flag
) : d_flag(flag
) {}
2602 std::string
GetInfoCommand::getFlag() const { return d_flag
; }
2603 void GetInfoCommand::invoke(SmtEngine
* smtEngine
)
2608 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
2609 v
.push_back(smtEngine
->getInfo(d_flag
));
2611 if (d_flag
== "all-options" || d_flag
== "all-statistics")
2613 ss
<< PrettySExprs(true);
2616 d_result
= ss
.str();
2617 d_commandStatus
= CommandSuccess::instance();
2619 catch (UnrecognizedOptionException
&)
2621 d_commandStatus
= new CommandUnsupported();
2623 catch (RecoverableModalException
& e
)
2625 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2627 catch (exception
& e
)
2629 d_commandStatus
= new CommandFailure(e
.what());
2633 std::string
GetInfoCommand::getResult() const { return d_result
; }
2634 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2638 this->Command::printResult(out
, verbosity
);
2640 else if (d_result
!= "")
2642 out
<< d_result
<< endl
;
2646 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
,
2647 ExprManagerMapCollection
& variableMap
)
2649 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2650 c
->d_result
= d_result
;
2654 Command
* GetInfoCommand::clone() const
2656 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2657 c
->d_result
= d_result
;
2661 std::string
GetInfoCommand::getCommandName() const { return "get-info"; }
2663 /* -------------------------------------------------------------------------- */
2664 /* class SetOptionCommand */
2665 /* -------------------------------------------------------------------------- */
2667 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
)
2668 : d_flag(flag
), d_sexpr(sexpr
)
2672 std::string
SetOptionCommand::getFlag() const { return d_flag
; }
2673 SExpr
SetOptionCommand::getSExpr() const { return d_sexpr
; }
2674 void SetOptionCommand::invoke(SmtEngine
* smtEngine
)
2678 smtEngine
->setOption(d_flag
, d_sexpr
);
2679 d_commandStatus
= CommandSuccess::instance();
2681 catch (UnrecognizedOptionException
&)
2683 d_commandStatus
= new CommandUnsupported();
2685 catch (exception
& e
)
2687 d_commandStatus
= new CommandFailure(e
.what());
2691 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
,
2692 ExprManagerMapCollection
& variableMap
)
2694 return new SetOptionCommand(d_flag
, d_sexpr
);
2697 Command
* SetOptionCommand::clone() const
2699 return new SetOptionCommand(d_flag
, d_sexpr
);
2702 std::string
SetOptionCommand::getCommandName() const { return "set-option"; }
2704 /* -------------------------------------------------------------------------- */
2705 /* class GetOptionCommand */
2706 /* -------------------------------------------------------------------------- */
2708 GetOptionCommand::GetOptionCommand(std::string flag
) : d_flag(flag
) {}
2709 std::string
GetOptionCommand::getFlag() const { return d_flag
; }
2710 void GetOptionCommand::invoke(SmtEngine
* smtEngine
)
2714 SExpr res
= smtEngine
->getOption(d_flag
);
2715 d_result
= res
.toString();
2716 d_commandStatus
= CommandSuccess::instance();
2718 catch (UnrecognizedOptionException
&)
2720 d_commandStatus
= new CommandUnsupported();
2722 catch (exception
& e
)
2724 d_commandStatus
= new CommandFailure(e
.what());
2728 std::string
GetOptionCommand::getResult() const { return d_result
; }
2729 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2733 this->Command::printResult(out
, verbosity
);
2735 else if (d_result
!= "")
2737 out
<< d_result
<< endl
;
2741 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
,
2742 ExprManagerMapCollection
& variableMap
)
2744 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2745 c
->d_result
= d_result
;
2749 Command
* GetOptionCommand::clone() const
2751 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2752 c
->d_result
= d_result
;
2756 std::string
GetOptionCommand::getCommandName() const { return "get-option"; }
2758 /* -------------------------------------------------------------------------- */
2759 /* class SetExpressionNameCommand */
2760 /* -------------------------------------------------------------------------- */
2762 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
)
2763 : d_expr(expr
), d_name(name
)
2767 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
)
2769 smtEngine
->setExpressionName(d_expr
, d_name
);
2770 d_commandStatus
= CommandSuccess::instance();
2773 Command
* SetExpressionNameCommand::exportTo(
2774 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2776 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(
2777 d_expr
.exportTo(exprManager
, variableMap
), d_name
);
2781 Command
* SetExpressionNameCommand::clone() const
2783 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
2787 std::string
SetExpressionNameCommand::getCommandName() const
2789 return "set-expr-name";
2792 /* -------------------------------------------------------------------------- */
2793 /* class DatatypeDeclarationCommand */
2794 /* -------------------------------------------------------------------------- */
2796 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const Type
& datatype
)
2799 d_datatypes
.push_back(datatype
);
2802 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2803 const std::vector
<Type
>& datatypes
)
2804 : d_datatypes(datatypes
)
2808 const std::vector
<Type
>& DatatypeDeclarationCommand::getDatatypes() const
2813 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
)
2815 d_commandStatus
= CommandSuccess::instance();
2818 Command
* DatatypeDeclarationCommand::exportTo(
2819 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2821 throw ExportUnsupportedException(
2822 "export of DatatypeDeclarationCommand unsupported");
2825 Command
* DatatypeDeclarationCommand::clone() const
2827 return new DatatypeDeclarationCommand(d_datatypes
);
2830 std::string
DatatypeDeclarationCommand::getCommandName() const
2832 return "declare-datatypes";