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
->query(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
,
1270 : DeclarationDefinitionCommand(id
),
1277 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1279 const std::vector
<Expr
>& formals
,
1281 : DeclarationDefinitionCommand(id
),
1288 Expr
DefineFunctionCommand::getFunction() const { return d_func
; }
1289 const std::vector
<Expr
>& DefineFunctionCommand::getFormals() const
1294 Expr
DefineFunctionCommand::getFormula() const { return d_formula
; }
1295 void DefineFunctionCommand::invoke(SmtEngine
* smtEngine
)
1299 if (!d_func
.isNull())
1301 smtEngine
->defineFunction(d_func
, d_formals
, d_formula
);
1303 d_commandStatus
= CommandSuccess::instance();
1305 catch (exception
& e
)
1307 d_commandStatus
= new CommandFailure(e
.what());
1311 Command
* DefineFunctionCommand::exportTo(ExprManager
* exprManager
,
1312 ExprManagerMapCollection
& variableMap
)
1314 Expr func
= d_func
.exportTo(
1315 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1316 vector
<Expr
> formals
;
1317 transform(d_formals
.begin(),
1319 back_inserter(formals
),
1320 ExportTransformer(exprManager
, variableMap
));
1321 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1322 return new DefineFunctionCommand(d_symbol
, func
, formals
, formula
);
1325 Command
* DefineFunctionCommand::clone() const
1327 return new DefineFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1330 std::string
DefineFunctionCommand::getCommandName() const
1332 return "define-fun";
1335 /* -------------------------------------------------------------------------- */
1336 /* class DefineNamedFunctionCommand */
1337 /* -------------------------------------------------------------------------- */
1339 DefineNamedFunctionCommand::DefineNamedFunctionCommand(
1340 const std::string
& id
,
1342 const std::vector
<Expr
>& formals
,
1344 : DefineFunctionCommand(id
, func
, formals
, formula
)
1348 void DefineNamedFunctionCommand::invoke(SmtEngine
* smtEngine
)
1350 this->DefineFunctionCommand::invoke(smtEngine
);
1351 if (!d_func
.isNull() && d_func
.getType().isBoolean())
1353 smtEngine
->addToAssignment(d_func
);
1355 d_commandStatus
= CommandSuccess::instance();
1358 Command
* DefineNamedFunctionCommand::exportTo(
1359 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1361 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
1362 vector
<Expr
> formals
;
1363 transform(d_formals
.begin(),
1365 back_inserter(formals
),
1366 ExportTransformer(exprManager
, variableMap
));
1367 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1368 return new DefineNamedFunctionCommand(d_symbol
, func
, formals
, formula
);
1371 Command
* DefineNamedFunctionCommand::clone() const
1373 return new DefineNamedFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1376 /* -------------------------------------------------------------------------- */
1377 /* class DefineFunctionRecCommand */
1378 /* -------------------------------------------------------------------------- */
1380 DefineFunctionRecCommand::DefineFunctionRecCommand(
1381 Expr func
, const std::vector
<Expr
>& formals
, Expr formula
)
1383 d_funcs
.push_back(func
);
1384 d_formals
.push_back(formals
);
1385 d_formulas
.push_back(formula
);
1388 DefineFunctionRecCommand::DefineFunctionRecCommand(
1389 const std::vector
<Expr
>& funcs
,
1390 const std::vector
<std::vector
<Expr
>>& formals
,
1391 const std::vector
<Expr
>& formulas
)
1393 d_funcs
.insert(d_funcs
.end(), funcs
.begin(), funcs
.end());
1394 d_formals
.insert(d_formals
.end(), formals
.begin(), formals
.end());
1395 d_formulas
.insert(d_formulas
.end(), formulas
.begin(), formulas
.end());
1398 const std::vector
<Expr
>& DefineFunctionRecCommand::getFunctions() const
1403 const std::vector
<std::vector
<Expr
>>& DefineFunctionRecCommand::getFormals()
1409 const std::vector
<Expr
>& DefineFunctionRecCommand::getFormulas() const
1414 void DefineFunctionRecCommand::invoke(SmtEngine
* smtEngine
)
1418 smtEngine
->defineFunctionsRec(d_funcs
, d_formals
, d_formulas
);
1419 d_commandStatus
= CommandSuccess::instance();
1421 catch (exception
& e
)
1423 d_commandStatus
= new CommandFailure(e
.what());
1427 Command
* DefineFunctionRecCommand::exportTo(
1428 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1430 std::vector
<Expr
> funcs
;
1431 for (unsigned i
= 0, size
= d_funcs
.size(); i
< size
; i
++)
1433 Expr func
= d_funcs
[i
].exportTo(
1434 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1435 funcs
.push_back(func
);
1437 std::vector
<std::vector
<Expr
>> formals
;
1438 for (unsigned i
= 0, size
= d_formals
.size(); i
< size
; i
++)
1440 std::vector
<Expr
> formals_c
;
1441 transform(d_formals
[i
].begin(),
1443 back_inserter(formals_c
),
1444 ExportTransformer(exprManager
, variableMap
));
1445 formals
.push_back(formals_c
);
1447 std::vector
<Expr
> formulas
;
1448 for (unsigned i
= 0, size
= d_formulas
.size(); i
< size
; i
++)
1450 Expr formula
= d_formulas
[i
].exportTo(exprManager
, variableMap
);
1451 formulas
.push_back(formula
);
1453 return new DefineFunctionRecCommand(funcs
, formals
, formulas
);
1456 Command
* DefineFunctionRecCommand::clone() const
1458 return new DefineFunctionRecCommand(d_funcs
, d_formals
, d_formulas
);
1461 std::string
DefineFunctionRecCommand::getCommandName() const
1463 return "define-fun-rec";
1466 /* -------------------------------------------------------------------------- */
1467 /* class SetUserAttribute */
1468 /* -------------------------------------------------------------------------- */
1470 SetUserAttributeCommand::SetUserAttributeCommand(
1471 const std::string
& attr
,
1473 const std::vector
<Expr
>& expr_values
,
1474 const std::string
& str_value
)
1477 d_expr_values(expr_values
),
1478 d_str_value(str_value
)
1482 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1484 : SetUserAttributeCommand(attr
, expr
, {}, "")
1488 SetUserAttributeCommand::SetUserAttributeCommand(
1489 const std::string
& attr
, Expr expr
, const std::vector
<Expr
>& values
)
1490 : SetUserAttributeCommand(attr
, expr
, values
, "")
1494 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1496 const std::string
& value
)
1497 : SetUserAttributeCommand(attr
, expr
, {}, value
)
1501 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
)
1505 if (!d_expr
.isNull())
1507 smtEngine
->setUserAttribute(d_attr
, d_expr
, d_expr_values
, d_str_value
);
1509 d_commandStatus
= CommandSuccess::instance();
1511 catch (exception
& e
)
1513 d_commandStatus
= new CommandFailure(e
.what());
1517 Command
* SetUserAttributeCommand::exportTo(
1518 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1520 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
1521 return new SetUserAttributeCommand(d_attr
, expr
, d_expr_values
, d_str_value
);
1524 Command
* SetUserAttributeCommand::clone() const
1526 return new SetUserAttributeCommand(
1527 d_attr
, d_expr
, d_expr_values
, d_str_value
);
1530 std::string
SetUserAttributeCommand::getCommandName() const
1532 return "set-user-attribute";
1535 /* -------------------------------------------------------------------------- */
1536 /* class SimplifyCommand */
1537 /* -------------------------------------------------------------------------- */
1539 SimplifyCommand::SimplifyCommand(Expr term
) : d_term(term
) {}
1540 Expr
SimplifyCommand::getTerm() const { return d_term
; }
1541 void SimplifyCommand::invoke(SmtEngine
* smtEngine
)
1545 d_result
= smtEngine
->simplify(d_term
);
1546 d_commandStatus
= CommandSuccess::instance();
1548 catch (UnsafeInterruptException
& e
)
1550 d_commandStatus
= new CommandInterrupted();
1552 catch (exception
& e
)
1554 d_commandStatus
= new CommandFailure(e
.what());
1558 Expr
SimplifyCommand::getResult() const { return d_result
; }
1559 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1563 this->Command::printResult(out
, verbosity
);
1567 out
<< d_result
<< endl
;
1571 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
,
1572 ExprManagerMapCollection
& variableMap
)
1574 SimplifyCommand
* c
=
1575 new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
1576 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1580 Command
* SimplifyCommand::clone() const
1582 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
1583 c
->d_result
= d_result
;
1587 std::string
SimplifyCommand::getCommandName() const { return "simplify"; }
1589 /* -------------------------------------------------------------------------- */
1590 /* class ExpandDefinitionsCommand */
1591 /* -------------------------------------------------------------------------- */
1593 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) : d_term(term
) {}
1594 Expr
ExpandDefinitionsCommand::getTerm() const { return d_term
; }
1595 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
)
1597 d_result
= smtEngine
->expandDefinitions(d_term
);
1598 d_commandStatus
= CommandSuccess::instance();
1601 Expr
ExpandDefinitionsCommand::getResult() const { return d_result
; }
1602 void ExpandDefinitionsCommand::printResult(std::ostream
& out
,
1603 uint32_t verbosity
) const
1607 this->Command::printResult(out
, verbosity
);
1611 out
<< d_result
<< endl
;
1615 Command
* ExpandDefinitionsCommand::exportTo(
1616 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1618 ExpandDefinitionsCommand
* c
=
1619 new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
1620 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1624 Command
* ExpandDefinitionsCommand::clone() const
1626 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
1627 c
->d_result
= d_result
;
1631 std::string
ExpandDefinitionsCommand::getCommandName() const
1633 return "expand-definitions";
1636 /* -------------------------------------------------------------------------- */
1637 /* class GetValueCommand */
1638 /* -------------------------------------------------------------------------- */
1640 GetValueCommand::GetValueCommand(Expr term
) : d_terms()
1642 d_terms
.push_back(term
);
1645 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
)
1648 PrettyCheckArgument(
1649 terms
.size() >= 1, terms
, "cannot get-value of an empty set of terms");
1652 const std::vector
<Expr
>& GetValueCommand::getTerms() const { return d_terms
; }
1653 void GetValueCommand::invoke(SmtEngine
* smtEngine
)
1657 ExprManager
* em
= smtEngine
->getExprManager();
1658 NodeManager
* nm
= NodeManager::fromExprManager(em
);
1659 smt::SmtScope
scope(smtEngine
);
1660 vector
<Expr
> result
= smtEngine
->getValues(d_terms
);
1661 Assert(result
.size() == d_terms
.size());
1662 for (int i
= 0, size
= d_terms
.size(); i
< size
; i
++)
1664 Expr e
= d_terms
[i
];
1665 Assert(nm
== NodeManager::fromExprManager(e
.getExprManager()));
1666 Node request
= Node::fromExpr(
1667 options::expandDefinitions() ? smtEngine
->expandDefinitions(e
) : e
);
1668 Node value
= Node::fromExpr(result
[i
]);
1669 if (value
.getType().isInteger() && request
.getType() == nm
->realType())
1671 // Need to wrap in division-by-one so that output printers know this
1672 // is an integer-looking constant that really should be output as
1673 // a rational. Necessary for SMT-LIB standards compliance.
1674 value
= nm
->mkNode(kind::DIVISION
, value
, nm
->mkConst(Rational(1)));
1676 result
[i
] = nm
->mkNode(kind::SEXPR
, request
, value
).toExpr();
1678 d_result
= em
->mkExpr(kind::SEXPR
, result
);
1679 d_commandStatus
= CommandSuccess::instance();
1681 catch (RecoverableModalException
& e
)
1683 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1685 catch (UnsafeInterruptException
& e
)
1687 d_commandStatus
= new CommandInterrupted();
1689 catch (exception
& e
)
1691 d_commandStatus
= new CommandFailure(e
.what());
1695 Expr
GetValueCommand::getResult() const { return d_result
; }
1696 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1700 this->Command::printResult(out
, verbosity
);
1704 expr::ExprDag::Scope
scope(out
, false);
1705 out
<< d_result
<< endl
;
1709 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
,
1710 ExprManagerMapCollection
& variableMap
)
1712 vector
<Expr
> exportedTerms
;
1713 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1717 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1719 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1720 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1724 Command
* GetValueCommand::clone() const
1726 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1727 c
->d_result
= d_result
;
1731 std::string
GetValueCommand::getCommandName() const { return "get-value"; }
1733 /* -------------------------------------------------------------------------- */
1734 /* class GetAssignmentCommand */
1735 /* -------------------------------------------------------------------------- */
1737 GetAssignmentCommand::GetAssignmentCommand() {}
1738 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
)
1742 std::vector
<std::pair
<Expr
, Expr
>> assignments
= smtEngine
->getAssignment();
1743 vector
<SExpr
> sexprs
;
1744 for (const auto& p
: assignments
)
1747 v
.emplace_back(SExpr::Keyword(p
.first
.toString()));
1748 v
.emplace_back(SExpr::Keyword(p
.second
.toString()));
1749 sexprs
.emplace_back(v
);
1751 d_result
= SExpr(sexprs
);
1752 d_commandStatus
= CommandSuccess::instance();
1754 catch (RecoverableModalException
& e
)
1756 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1758 catch (UnsafeInterruptException
& e
)
1760 d_commandStatus
= new CommandInterrupted();
1762 catch (exception
& e
)
1764 d_commandStatus
= new CommandFailure(e
.what());
1768 SExpr
GetAssignmentCommand::getResult() const { return d_result
; }
1769 void GetAssignmentCommand::printResult(std::ostream
& out
,
1770 uint32_t verbosity
) const
1774 this->Command::printResult(out
, verbosity
);
1778 out
<< d_result
<< endl
;
1782 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
,
1783 ExprManagerMapCollection
& variableMap
)
1785 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1786 c
->d_result
= d_result
;
1790 Command
* GetAssignmentCommand::clone() const
1792 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1793 c
->d_result
= d_result
;
1797 std::string
GetAssignmentCommand::getCommandName() const
1799 return "get-assignment";
1802 /* -------------------------------------------------------------------------- */
1803 /* class GetModelCommand */
1804 /* -------------------------------------------------------------------------- */
1806 GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
1807 void GetModelCommand::invoke(SmtEngine
* smtEngine
)
1811 d_result
= smtEngine
->getModel();
1812 d_smtEngine
= smtEngine
;
1813 d_commandStatus
= CommandSuccess::instance();
1815 catch (RecoverableModalException
& e
)
1817 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1819 catch (UnsafeInterruptException
& e
)
1821 d_commandStatus
= new CommandInterrupted();
1823 catch (exception
& e
)
1825 d_commandStatus
= new CommandFailure(e
.what());
1829 /* Model is private to the library -- for now
1830 Model* GetModelCommand::getResult() const {
1835 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1839 this->Command::printResult(out
, verbosity
);
1847 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
,
1848 ExprManagerMapCollection
& variableMap
)
1850 GetModelCommand
* c
= new GetModelCommand();
1851 c
->d_result
= d_result
;
1852 c
->d_smtEngine
= d_smtEngine
;
1856 Command
* GetModelCommand::clone() const
1858 GetModelCommand
* c
= new GetModelCommand();
1859 c
->d_result
= d_result
;
1860 c
->d_smtEngine
= d_smtEngine
;
1864 std::string
GetModelCommand::getCommandName() const { return "get-model"; }
1866 /* -------------------------------------------------------------------------- */
1867 /* class BlockModelCommand */
1868 /* -------------------------------------------------------------------------- */
1870 BlockModelCommand::BlockModelCommand() {}
1871 void BlockModelCommand::invoke(SmtEngine
* smtEngine
)
1875 smtEngine
->blockModel();
1876 d_commandStatus
= CommandSuccess::instance();
1878 catch (RecoverableModalException
& e
)
1880 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1882 catch (UnsafeInterruptException
& e
)
1884 d_commandStatus
= new CommandInterrupted();
1886 catch (exception
& e
)
1888 d_commandStatus
= new CommandFailure(e
.what());
1892 Command
* BlockModelCommand::exportTo(ExprManager
* exprManager
,
1893 ExprManagerMapCollection
& variableMap
)
1895 BlockModelCommand
* c
= new BlockModelCommand();
1899 Command
* BlockModelCommand::clone() const
1901 BlockModelCommand
* c
= new BlockModelCommand();
1905 std::string
BlockModelCommand::getCommandName() const { return "block-model"; }
1907 /* -------------------------------------------------------------------------- */
1908 /* class BlockModelValuesCommand */
1909 /* -------------------------------------------------------------------------- */
1911 BlockModelValuesCommand::BlockModelValuesCommand(const std::vector
<Expr
>& terms
)
1914 PrettyCheckArgument(terms
.size() >= 1,
1916 "cannot block-model-values of an empty set of terms");
1919 const std::vector
<Expr
>& BlockModelValuesCommand::getTerms() const
1923 void BlockModelValuesCommand::invoke(SmtEngine
* smtEngine
)
1927 smtEngine
->blockModelValues(d_terms
);
1928 d_commandStatus
= CommandSuccess::instance();
1930 catch (RecoverableModalException
& e
)
1932 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1934 catch (UnsafeInterruptException
& e
)
1936 d_commandStatus
= new CommandInterrupted();
1938 catch (exception
& e
)
1940 d_commandStatus
= new CommandFailure(e
.what());
1944 Command
* BlockModelValuesCommand::exportTo(
1945 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1947 vector
<Expr
> exportedTerms
;
1948 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1952 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1954 BlockModelValuesCommand
* c
= new BlockModelValuesCommand(exportedTerms
);
1958 Command
* BlockModelValuesCommand::clone() const
1960 BlockModelValuesCommand
* c
= new BlockModelValuesCommand(d_terms
);
1964 std::string
BlockModelValuesCommand::getCommandName() const
1966 return "block-model-values";
1969 /* -------------------------------------------------------------------------- */
1970 /* class GetProofCommand */
1971 /* -------------------------------------------------------------------------- */
1973 GetProofCommand::GetProofCommand() : d_smtEngine(nullptr), d_result(nullptr) {}
1974 void GetProofCommand::invoke(SmtEngine
* smtEngine
)
1978 d_smtEngine
= smtEngine
;
1979 d_result
= &smtEngine
->getProof();
1980 d_commandStatus
= CommandSuccess::instance();
1982 catch (RecoverableModalException
& e
)
1984 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1986 catch (UnsafeInterruptException
& e
)
1988 d_commandStatus
= new CommandInterrupted();
1990 catch (exception
& e
)
1992 d_commandStatus
= new CommandFailure(e
.what());
1996 const Proof
& GetProofCommand::getResult() const { return *d_result
; }
1997 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2001 this->Command::printResult(out
, verbosity
);
2005 smt::SmtScope
scope(d_smtEngine
);
2006 d_result
->toStream(out
);
2010 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
,
2011 ExprManagerMapCollection
& variableMap
)
2013 GetProofCommand
* c
= new GetProofCommand();
2014 c
->d_result
= d_result
;
2015 c
->d_smtEngine
= d_smtEngine
;
2019 Command
* GetProofCommand::clone() const
2021 GetProofCommand
* c
= new GetProofCommand();
2022 c
->d_result
= d_result
;
2023 c
->d_smtEngine
= d_smtEngine
;
2027 std::string
GetProofCommand::getCommandName() const { return "get-proof"; }
2029 /* -------------------------------------------------------------------------- */
2030 /* class GetInstantiationsCommand */
2031 /* -------------------------------------------------------------------------- */
2033 GetInstantiationsCommand::GetInstantiationsCommand() : d_smtEngine(nullptr) {}
2034 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
)
2038 d_smtEngine
= smtEngine
;
2039 d_commandStatus
= CommandSuccess::instance();
2041 catch (exception
& e
)
2043 d_commandStatus
= new CommandFailure(e
.what());
2047 void GetInstantiationsCommand::printResult(std::ostream
& out
,
2048 uint32_t verbosity
) const
2052 this->Command::printResult(out
, verbosity
);
2056 d_smtEngine
->printInstantiations(out
);
2060 Command
* GetInstantiationsCommand::exportTo(
2061 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2063 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
2064 // c->d_result = d_result;
2065 c
->d_smtEngine
= d_smtEngine
;
2069 Command
* GetInstantiationsCommand::clone() const
2071 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
2072 // c->d_result = d_result;
2073 c
->d_smtEngine
= d_smtEngine
;
2077 std::string
GetInstantiationsCommand::getCommandName() const
2079 return "get-instantiations";
2082 /* -------------------------------------------------------------------------- */
2083 /* class GetSynthSolutionCommand */
2084 /* -------------------------------------------------------------------------- */
2086 GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
2087 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
)
2091 d_smtEngine
= smtEngine
;
2092 d_commandStatus
= CommandSuccess::instance();
2094 catch (exception
& e
)
2096 d_commandStatus
= new CommandFailure(e
.what());
2100 void GetSynthSolutionCommand::printResult(std::ostream
& out
,
2101 uint32_t verbosity
) const
2105 this->Command::printResult(out
, verbosity
);
2109 d_smtEngine
->printSynthSolution(out
);
2113 Command
* GetSynthSolutionCommand::exportTo(
2114 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2116 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2117 c
->d_smtEngine
= d_smtEngine
;
2121 Command
* GetSynthSolutionCommand::clone() const
2123 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2124 c
->d_smtEngine
= d_smtEngine
;
2128 std::string
GetSynthSolutionCommand::getCommandName() const
2130 return "get-instantiations";
2133 GetAbductCommand::GetAbductCommand() {}
2134 GetAbductCommand::GetAbductCommand(const std::string
& name
, Expr conj
)
2135 : d_name(name
), d_conj(conj
), d_resultStatus(false)
2138 GetAbductCommand::GetAbductCommand(const std::string
& name
,
2143 d_sygus_grammar_type(gtype
),
2144 d_resultStatus(false)
2148 Expr
GetAbductCommand::getConjecture() const { return d_conj
; }
2149 Type
GetAbductCommand::getGrammarType() const { return d_sygus_grammar_type
; }
2150 Expr
GetAbductCommand::getResult() const { return d_result
; }
2152 void GetAbductCommand::invoke(SmtEngine
* smtEngine
)
2156 if (d_sygus_grammar_type
.isNull())
2158 d_resultStatus
= smtEngine
->getAbduct(d_conj
, d_result
);
2163 smtEngine
->getAbduct(d_conj
, d_sygus_grammar_type
, d_result
);
2165 d_commandStatus
= CommandSuccess::instance();
2167 catch (exception
& e
)
2169 d_commandStatus
= new CommandFailure(e
.what());
2173 void GetAbductCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2177 this->Command::printResult(out
, verbosity
);
2181 expr::ExprDag::Scope
scope(out
, false);
2184 out
<< "(define-fun " << d_name
<< " () Bool " << d_result
<< ")"
2189 out
<< "none" << std::endl
;
2194 Command
* GetAbductCommand::exportTo(ExprManager
* exprManager
,
2195 ExprManagerMapCollection
& variableMap
)
2197 GetAbductCommand
* c
=
2198 new GetAbductCommand(d_name
, d_conj
.exportTo(exprManager
, variableMap
));
2199 c
->d_sygus_grammar_type
=
2200 d_sygus_grammar_type
.exportTo(exprManager
, variableMap
);
2201 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
2202 c
->d_resultStatus
= d_resultStatus
;
2206 Command
* GetAbductCommand::clone() const
2208 GetAbductCommand
* c
= new GetAbductCommand(d_name
, d_conj
);
2209 c
->d_sygus_grammar_type
= d_sygus_grammar_type
;
2210 c
->d_result
= d_result
;
2211 c
->d_resultStatus
= d_resultStatus
;
2215 std::string
GetAbductCommand::getCommandName() const { return "get-abduct"; }
2217 /* -------------------------------------------------------------------------- */
2218 /* class GetQuantifierEliminationCommand */
2219 /* -------------------------------------------------------------------------- */
2221 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand()
2222 : d_expr(), d_doFull(true)
2225 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
2226 const Expr
& expr
, bool doFull
)
2227 : d_expr(expr
), d_doFull(doFull
)
2231 Expr
GetQuantifierEliminationCommand::getExpr() const { return d_expr
; }
2232 bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull
; }
2233 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
)
2237 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
2238 d_commandStatus
= CommandSuccess::instance();
2240 catch (exception
& e
)
2242 d_commandStatus
= new CommandFailure(e
.what());
2246 Expr
GetQuantifierEliminationCommand::getResult() const { return d_result
; }
2247 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
,
2248 uint32_t verbosity
) const
2252 this->Command::printResult(out
, verbosity
);
2256 out
<< d_result
<< endl
;
2260 Command
* GetQuantifierEliminationCommand::exportTo(
2261 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2263 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(
2264 d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
2265 c
->d_result
= d_result
;
2269 Command
* GetQuantifierEliminationCommand::clone() const
2271 GetQuantifierEliminationCommand
* c
=
2272 new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
2273 c
->d_result
= d_result
;
2277 std::string
GetQuantifierEliminationCommand::getCommandName() const
2279 return d_doFull
? "get-qe" : "get-qe-disjunct";
2282 /* -------------------------------------------------------------------------- */
2283 /* class GetUnsatAssumptionsCommand */
2284 /* -------------------------------------------------------------------------- */
2286 GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
2288 void GetUnsatAssumptionsCommand::invoke(SmtEngine
* smtEngine
)
2292 d_result
= smtEngine
->getUnsatAssumptions();
2293 d_commandStatus
= CommandSuccess::instance();
2295 catch (RecoverableModalException
& e
)
2297 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2299 catch (exception
& e
)
2301 d_commandStatus
= new CommandFailure(e
.what());
2305 std::vector
<Expr
> GetUnsatAssumptionsCommand::getResult() const
2310 void GetUnsatAssumptionsCommand::printResult(std::ostream
& out
,
2311 uint32_t verbosity
) const
2315 this->Command::printResult(out
, verbosity
);
2319 container_to_stream(out
, d_result
, "(", ")\n", " ");
2323 Command
* GetUnsatAssumptionsCommand::exportTo(
2324 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2326 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2327 c
->d_result
= d_result
;
2331 Command
* GetUnsatAssumptionsCommand::clone() const
2333 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2334 c
->d_result
= d_result
;
2338 std::string
GetUnsatAssumptionsCommand::getCommandName() const
2340 return "get-unsat-assumptions";
2343 /* -------------------------------------------------------------------------- */
2344 /* class GetUnsatCoreCommand */
2345 /* -------------------------------------------------------------------------- */
2347 GetUnsatCoreCommand::GetUnsatCoreCommand() {}
2348 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
)
2352 d_result
= smtEngine
->getUnsatCore();
2353 d_commandStatus
= CommandSuccess::instance();
2355 catch (RecoverableModalException
& e
)
2357 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2359 catch (exception
& e
)
2361 d_commandStatus
= new CommandFailure(e
.what());
2365 void GetUnsatCoreCommand::printResult(std::ostream
& out
,
2366 uint32_t verbosity
) const
2370 this->Command::printResult(out
, verbosity
);
2374 d_result
.toStream(out
);
2378 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const
2380 // of course, this will be empty if the command hasn't been invoked yet
2384 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
,
2385 ExprManagerMapCollection
& variableMap
)
2387 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2388 c
->d_result
= d_result
;
2392 Command
* GetUnsatCoreCommand::clone() const
2394 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2395 c
->d_result
= d_result
;
2399 std::string
GetUnsatCoreCommand::getCommandName() const
2401 return "get-unsat-core";
2404 /* -------------------------------------------------------------------------- */
2405 /* class GetAssertionsCommand */
2406 /* -------------------------------------------------------------------------- */
2408 GetAssertionsCommand::GetAssertionsCommand() {}
2409 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
2414 const vector
<Expr
> v
= smtEngine
->getAssertions();
2416 copy(v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n"));
2418 d_result
= ss
.str();
2419 d_commandStatus
= CommandSuccess::instance();
2421 catch (exception
& e
)
2423 d_commandStatus
= new CommandFailure(e
.what());
2427 std::string
GetAssertionsCommand::getResult() const { return d_result
; }
2428 void GetAssertionsCommand::printResult(std::ostream
& out
,
2429 uint32_t verbosity
) const
2433 this->Command::printResult(out
, verbosity
);
2441 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
,
2442 ExprManagerMapCollection
& variableMap
)
2444 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2445 c
->d_result
= d_result
;
2449 Command
* GetAssertionsCommand::clone() const
2451 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2452 c
->d_result
= d_result
;
2456 std::string
GetAssertionsCommand::getCommandName() const
2458 return "get-assertions";
2461 /* -------------------------------------------------------------------------- */
2462 /* class SetBenchmarkStatusCommand */
2463 /* -------------------------------------------------------------------------- */
2465 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
)
2470 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const
2475 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
)
2481 SExpr status
= SExpr(ss
.str());
2482 smtEngine
->setInfo("status", status
);
2483 d_commandStatus
= CommandSuccess::instance();
2485 catch (exception
& e
)
2487 d_commandStatus
= new CommandFailure(e
.what());
2491 Command
* SetBenchmarkStatusCommand::exportTo(
2492 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2494 return new SetBenchmarkStatusCommand(d_status
);
2497 Command
* SetBenchmarkStatusCommand::clone() const
2499 return new SetBenchmarkStatusCommand(d_status
);
2502 std::string
SetBenchmarkStatusCommand::getCommandName() const
2507 /* -------------------------------------------------------------------------- */
2508 /* class SetBenchmarkLogicCommand */
2509 /* -------------------------------------------------------------------------- */
2511 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
)
2516 std::string
SetBenchmarkLogicCommand::getLogic() const { return d_logic
; }
2517 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
)
2521 smtEngine
->setLogic(d_logic
);
2522 d_commandStatus
= CommandSuccess::instance();
2524 catch (exception
& e
)
2526 d_commandStatus
= new CommandFailure(e
.what());
2530 Command
* SetBenchmarkLogicCommand::exportTo(
2531 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2533 return new SetBenchmarkLogicCommand(d_logic
);
2536 Command
* SetBenchmarkLogicCommand::clone() const
2538 return new SetBenchmarkLogicCommand(d_logic
);
2541 std::string
SetBenchmarkLogicCommand::getCommandName() const
2546 /* -------------------------------------------------------------------------- */
2547 /* class SetInfoCommand */
2548 /* -------------------------------------------------------------------------- */
2550 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
)
2551 : d_flag(flag
), d_sexpr(sexpr
)
2555 std::string
SetInfoCommand::getFlag() const { return d_flag
; }
2556 SExpr
SetInfoCommand::getSExpr() const { return d_sexpr
; }
2557 void SetInfoCommand::invoke(SmtEngine
* smtEngine
)
2561 smtEngine
->setInfo(d_flag
, d_sexpr
);
2562 d_commandStatus
= CommandSuccess::instance();
2564 catch (UnrecognizedOptionException
&)
2566 // As per SMT-LIB spec, silently accept unknown set-info keys
2567 d_commandStatus
= CommandSuccess::instance();
2569 catch (exception
& e
)
2571 d_commandStatus
= new CommandFailure(e
.what());
2575 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
,
2576 ExprManagerMapCollection
& variableMap
)
2578 return new SetInfoCommand(d_flag
, d_sexpr
);
2581 Command
* SetInfoCommand::clone() const
2583 return new SetInfoCommand(d_flag
, d_sexpr
);
2586 std::string
SetInfoCommand::getCommandName() const { return "set-info"; }
2588 /* -------------------------------------------------------------------------- */
2589 /* class GetInfoCommand */
2590 /* -------------------------------------------------------------------------- */
2592 GetInfoCommand::GetInfoCommand(std::string flag
) : d_flag(flag
) {}
2593 std::string
GetInfoCommand::getFlag() const { return d_flag
; }
2594 void GetInfoCommand::invoke(SmtEngine
* smtEngine
)
2599 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
2600 v
.push_back(smtEngine
->getInfo(d_flag
));
2602 if (d_flag
== "all-options" || d_flag
== "all-statistics")
2604 ss
<< PrettySExprs(true);
2607 d_result
= ss
.str();
2608 d_commandStatus
= CommandSuccess::instance();
2610 catch (UnrecognizedOptionException
&)
2612 d_commandStatus
= new CommandUnsupported();
2614 catch (RecoverableModalException
& e
)
2616 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2618 catch (exception
& e
)
2620 d_commandStatus
= new CommandFailure(e
.what());
2624 std::string
GetInfoCommand::getResult() const { return d_result
; }
2625 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2629 this->Command::printResult(out
, verbosity
);
2631 else if (d_result
!= "")
2633 out
<< d_result
<< endl
;
2637 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
,
2638 ExprManagerMapCollection
& variableMap
)
2640 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2641 c
->d_result
= d_result
;
2645 Command
* GetInfoCommand::clone() const
2647 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2648 c
->d_result
= d_result
;
2652 std::string
GetInfoCommand::getCommandName() const { return "get-info"; }
2654 /* -------------------------------------------------------------------------- */
2655 /* class SetOptionCommand */
2656 /* -------------------------------------------------------------------------- */
2658 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
)
2659 : d_flag(flag
), d_sexpr(sexpr
)
2663 std::string
SetOptionCommand::getFlag() const { return d_flag
; }
2664 SExpr
SetOptionCommand::getSExpr() const { return d_sexpr
; }
2665 void SetOptionCommand::invoke(SmtEngine
* smtEngine
)
2669 smtEngine
->setOption(d_flag
, d_sexpr
);
2670 d_commandStatus
= CommandSuccess::instance();
2672 catch (UnrecognizedOptionException
&)
2674 d_commandStatus
= new CommandUnsupported();
2676 catch (exception
& e
)
2678 d_commandStatus
= new CommandFailure(e
.what());
2682 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
,
2683 ExprManagerMapCollection
& variableMap
)
2685 return new SetOptionCommand(d_flag
, d_sexpr
);
2688 Command
* SetOptionCommand::clone() const
2690 return new SetOptionCommand(d_flag
, d_sexpr
);
2693 std::string
SetOptionCommand::getCommandName() const { return "set-option"; }
2695 /* -------------------------------------------------------------------------- */
2696 /* class GetOptionCommand */
2697 /* -------------------------------------------------------------------------- */
2699 GetOptionCommand::GetOptionCommand(std::string flag
) : d_flag(flag
) {}
2700 std::string
GetOptionCommand::getFlag() const { return d_flag
; }
2701 void GetOptionCommand::invoke(SmtEngine
* smtEngine
)
2705 SExpr res
= smtEngine
->getOption(d_flag
);
2706 d_result
= res
.toString();
2707 d_commandStatus
= CommandSuccess::instance();
2709 catch (UnrecognizedOptionException
&)
2711 d_commandStatus
= new CommandUnsupported();
2713 catch (exception
& e
)
2715 d_commandStatus
= new CommandFailure(e
.what());
2719 std::string
GetOptionCommand::getResult() const { return d_result
; }
2720 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2724 this->Command::printResult(out
, verbosity
);
2726 else if (d_result
!= "")
2728 out
<< d_result
<< endl
;
2732 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
,
2733 ExprManagerMapCollection
& variableMap
)
2735 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2736 c
->d_result
= d_result
;
2740 Command
* GetOptionCommand::clone() const
2742 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2743 c
->d_result
= d_result
;
2747 std::string
GetOptionCommand::getCommandName() const { return "get-option"; }
2749 /* -------------------------------------------------------------------------- */
2750 /* class SetExpressionNameCommand */
2751 /* -------------------------------------------------------------------------- */
2753 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
)
2754 : d_expr(expr
), d_name(name
)
2758 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
)
2760 smtEngine
->setExpressionName(d_expr
, d_name
);
2761 d_commandStatus
= CommandSuccess::instance();
2764 Command
* SetExpressionNameCommand::exportTo(
2765 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2767 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(
2768 d_expr
.exportTo(exprManager
, variableMap
), d_name
);
2772 Command
* SetExpressionNameCommand::clone() const
2774 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
2778 std::string
SetExpressionNameCommand::getCommandName() const
2780 return "set-expr-name";
2783 /* -------------------------------------------------------------------------- */
2784 /* class DatatypeDeclarationCommand */
2785 /* -------------------------------------------------------------------------- */
2787 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const Type
& datatype
)
2790 d_datatypes
.push_back(datatype
);
2793 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2794 const std::vector
<Type
>& datatypes
)
2795 : d_datatypes(datatypes
)
2799 const std::vector
<Type
>& DatatypeDeclarationCommand::getDatatypes() const
2804 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
)
2806 d_commandStatus
= CommandSuccess::instance();
2809 Command
* DatatypeDeclarationCommand::exportTo(
2810 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2812 throw ExportUnsupportedException(
2813 "export of DatatypeDeclarationCommand unsupported");
2816 Command
* DatatypeDeclarationCommand::clone() const
2818 return new DatatypeDeclarationCommand(d_datatypes
);
2821 std::string
DatatypeDeclarationCommand::getCommandName() const
2823 return "declare-datatypes";