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-2020 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 "api/cvc4cpp.h"
27 #include "base/check.h"
28 #include "base/output.h"
29 #include "expr/expr_iomanip.h"
30 #include "expr/node.h"
31 #include "expr/type.h"
32 #include "options/options.h"
33 #include "options/smt_options.h"
34 #include "printer/printer.h"
36 #include "smt/model.h"
37 #include "smt/smt_engine.h"
38 #include "smt/smt_engine_scope.h"
39 #include "util/sexpr.h"
40 #include "util/utility.h"
46 const int CommandPrintSuccess::s_iosIndex
= std::ios_base::xalloc();
47 const CommandSuccess
* CommandSuccess::s_instance
= new CommandSuccess();
48 const CommandInterrupted
* CommandInterrupted::s_instance
=
49 new CommandInterrupted();
51 std::ostream
& operator<<(std::ostream
& out
, const Command
& c
)
54 Node::setdepth::getDepth(out
),
55 Node::printtypes::getPrintTypes(out
),
56 Node::dag::getDag(out
),
57 Node::setlanguage::getLanguage(out
));
61 ostream
& operator<<(ostream
& out
, const Command
* c
)
74 std::ostream
& operator<<(std::ostream
& out
, const CommandStatus
& s
)
76 s
.toStream(out
, Node::setlanguage::getLanguage(out
));
80 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 // !!! Temporary until commands are migrated to the new API !!!
109 std::vector
<Node
> exprVectorToNodes(const std::vector
<Expr
>& exprs
)
111 std::vector
<Node
> nodes
;
112 nodes
.reserve(exprs
.size());
116 nodes
.push_back(Node::fromExpr(e
));
122 // !!! Temporary until commands are migrated to the new API !!!
123 std::vector
<TypeNode
> typeVectorToTypeNodes(const std::vector
<Type
>& types
)
125 std::vector
<TypeNode
> typeNodes
;
126 typeNodes
.reserve(types
.size());
130 typeNodes
.push_back(TypeNode::fromType(t
));
136 /* -------------------------------------------------------------------------- */
137 /* class CommandPrintSuccess */
138 /* -------------------------------------------------------------------------- */
140 void CommandPrintSuccess::applyPrintSuccess(std::ostream
& out
)
142 out
.iword(s_iosIndex
) = d_printSuccess
;
145 bool CommandPrintSuccess::getPrintSuccess(std::ostream
& out
)
147 return out
.iword(s_iosIndex
);
150 void CommandPrintSuccess::setPrintSuccess(std::ostream
& out
, bool printSuccess
)
152 out
.iword(s_iosIndex
) = printSuccess
;
155 std::ostream
& operator<<(std::ostream
& out
, CommandPrintSuccess cps
)
157 cps
.applyPrintSuccess(out
);
161 /* -------------------------------------------------------------------------- */
163 /* -------------------------------------------------------------------------- */
165 Command::Command() : d_commandStatus(nullptr), d_muted(false) {}
167 Command::Command(const api::Solver
* solver
)
168 : d_solver(solver
), d_commandStatus(nullptr), d_muted(false)
172 Command::Command(const Command
& cmd
)
175 (cmd
.d_commandStatus
== NULL
) ? NULL
: &cmd
.d_commandStatus
->clone();
176 d_muted
= cmd
.d_muted
;
181 if (d_commandStatus
!= NULL
&& d_commandStatus
!= CommandSuccess::instance())
183 delete d_commandStatus
;
187 bool Command::ok() const
189 // either we haven't run the command yet, or it ran successfully
190 return d_commandStatus
== NULL
191 || dynamic_cast<const CommandSuccess
*>(d_commandStatus
) != NULL
;
194 bool Command::fail() const
196 return d_commandStatus
!= NULL
197 && dynamic_cast<const CommandFailure
*>(d_commandStatus
) != NULL
;
200 bool Command::interrupted() const
202 return d_commandStatus
!= NULL
203 && dynamic_cast<const CommandInterrupted
*>(d_commandStatus
) != NULL
;
206 void Command::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
209 if (!(isMuted() && ok()))
212 smtEngine
->getOption("command-verbosity:" + getCommandName())
218 std::string
Command::toString() const
220 std::stringstream ss
;
225 void CommandStatus::toStream(std::ostream
& out
, OutputLanguage language
) const
227 Printer::getPrinter(language
)->toStream(out
, this);
230 void Command::printResult(std::ostream
& out
, uint32_t verbosity
) const
232 if (d_commandStatus
!= NULL
)
234 if ((!ok() && verbosity
>= 1) || verbosity
>= 2)
236 out
<< *d_commandStatus
;
241 /* -------------------------------------------------------------------------- */
242 /* class EmptyCommand */
243 /* -------------------------------------------------------------------------- */
245 EmptyCommand::EmptyCommand(std::string name
) : d_name(name
) {}
246 std::string
EmptyCommand::getName() const { return d_name
; }
247 void EmptyCommand::invoke(SmtEngine
* smtEngine
)
249 /* empty commands have no implementation */
250 d_commandStatus
= CommandSuccess::instance();
253 Command
* EmptyCommand::exportTo(ExprManager
* exprManager
,
254 ExprManagerMapCollection
& variableMap
)
256 return new EmptyCommand(d_name
);
259 Command
* EmptyCommand::clone() const { return new EmptyCommand(d_name
); }
260 std::string
EmptyCommand::getCommandName() const { return "empty"; }
262 void EmptyCommand::toStream(std::ostream
& out
,
266 OutputLanguage language
) const
268 Printer::getPrinter(language
)->toStreamCmdEmpty(out
, d_name
);
271 /* -------------------------------------------------------------------------- */
272 /* class EchoCommand */
273 /* -------------------------------------------------------------------------- */
275 EchoCommand::EchoCommand(std::string output
) : d_output(output
) {}
276 std::string
EchoCommand::getOutput() const { return d_output
; }
277 void EchoCommand::invoke(SmtEngine
* smtEngine
)
279 /* we don't have an output stream here, nothing to do */
280 d_commandStatus
= CommandSuccess::instance();
283 void EchoCommand::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
285 out
<< d_output
<< std::endl
;
286 Trace("dtview::command") << "* ~COMMAND: echo |" << d_output
<< "|~"
288 d_commandStatus
= CommandSuccess::instance();
290 smtEngine
->getOption("command-verbosity:" + getCommandName())
295 Command
* EchoCommand::exportTo(ExprManager
* exprManager
,
296 ExprManagerMapCollection
& variableMap
)
298 return new EchoCommand(d_output
);
301 Command
* EchoCommand::clone() const { return new EchoCommand(d_output
); }
302 std::string
EchoCommand::getCommandName() const { return "echo"; }
304 void EchoCommand::toStream(std::ostream
& out
,
308 OutputLanguage language
) const
310 Printer::getPrinter(language
)->toStreamCmdEcho(out
, d_output
);
313 /* -------------------------------------------------------------------------- */
314 /* class AssertCommand */
315 /* -------------------------------------------------------------------------- */
317 AssertCommand::AssertCommand(const Expr
& e
, bool inUnsatCore
)
318 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
322 Expr
AssertCommand::getExpr() const { return d_expr
; }
323 void AssertCommand::invoke(SmtEngine
* smtEngine
)
327 smtEngine
->assertFormula(d_expr
, d_inUnsatCore
);
328 d_commandStatus
= CommandSuccess::instance();
330 catch (UnsafeInterruptException
& e
)
332 d_commandStatus
= new CommandInterrupted();
336 d_commandStatus
= new CommandFailure(e
.what());
340 Command
* AssertCommand::exportTo(ExprManager
* exprManager
,
341 ExprManagerMapCollection
& variableMap
)
343 return new AssertCommand(d_expr
.exportTo(exprManager
, variableMap
),
347 Command
* AssertCommand::clone() const
349 return new AssertCommand(d_expr
, d_inUnsatCore
);
352 std::string
AssertCommand::getCommandName() const { return "assert"; }
354 void AssertCommand::toStream(std::ostream
& out
,
358 OutputLanguage language
) const
360 Printer::getPrinter(language
)->toStreamCmdAssert(out
, Node::fromExpr(d_expr
));
363 /* -------------------------------------------------------------------------- */
364 /* class PushCommand */
365 /* -------------------------------------------------------------------------- */
367 void PushCommand::invoke(SmtEngine
* smtEngine
)
372 d_commandStatus
= CommandSuccess::instance();
374 catch (UnsafeInterruptException
& e
)
376 d_commandStatus
= new CommandInterrupted();
380 d_commandStatus
= new CommandFailure(e
.what());
384 Command
* PushCommand::exportTo(ExprManager
* exprManager
,
385 ExprManagerMapCollection
& variableMap
)
387 return new PushCommand();
390 Command
* PushCommand::clone() const { return new PushCommand(); }
391 std::string
PushCommand::getCommandName() const { return "push"; }
393 void PushCommand::toStream(std::ostream
& out
,
397 OutputLanguage language
) const
399 Printer::getPrinter(language
)->toStreamCmdPush(out
);
402 /* -------------------------------------------------------------------------- */
403 /* class PopCommand */
404 /* -------------------------------------------------------------------------- */
406 void PopCommand::invoke(SmtEngine
* smtEngine
)
411 d_commandStatus
= CommandSuccess::instance();
413 catch (UnsafeInterruptException
& e
)
415 d_commandStatus
= new CommandInterrupted();
419 d_commandStatus
= new CommandFailure(e
.what());
423 Command
* PopCommand::exportTo(ExprManager
* exprManager
,
424 ExprManagerMapCollection
& variableMap
)
426 return new PopCommand();
429 Command
* PopCommand::clone() const { return new PopCommand(); }
430 std::string
PopCommand::getCommandName() const { return "pop"; }
432 void PopCommand::toStream(std::ostream
& out
,
436 OutputLanguage language
) const
438 Printer::getPrinter(language
)->toStreamCmdPop(out
);
441 /* -------------------------------------------------------------------------- */
442 /* class CheckSatCommand */
443 /* -------------------------------------------------------------------------- */
445 CheckSatCommand::CheckSatCommand() : d_expr() {}
447 CheckSatCommand::CheckSatCommand(const Expr
& expr
) : d_expr(expr
) {}
449 Expr
CheckSatCommand::getExpr() const { return d_expr
; }
450 void CheckSatCommand::invoke(SmtEngine
* smtEngine
)
452 Trace("dtview::command") << "* ~COMMAND: " << getCommandName() << "~"
456 d_result
= smtEngine
->checkSat(d_expr
);
457 d_commandStatus
= CommandSuccess::instance();
461 d_commandStatus
= new CommandFailure(e
.what());
465 Result
CheckSatCommand::getResult() const { return d_result
; }
466 void CheckSatCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
470 this->Command::printResult(out
, verbosity
);
474 Trace("dtview::command") << "* RESULT: " << d_result
<< std::endl
;
475 out
<< d_result
<< endl
;
479 Command
* CheckSatCommand::exportTo(ExprManager
* exprManager
,
480 ExprManagerMapCollection
& variableMap
)
483 new CheckSatCommand(d_expr
.exportTo(exprManager
, variableMap
));
484 c
->d_result
= d_result
;
488 Command
* CheckSatCommand::clone() const
490 CheckSatCommand
* c
= new CheckSatCommand(d_expr
);
491 c
->d_result
= d_result
;
495 std::string
CheckSatCommand::getCommandName() const { return "check-sat"; }
497 void CheckSatCommand::toStream(std::ostream
& out
,
501 OutputLanguage language
) const
503 Printer::getPrinter(language
)->toStreamCmdCheckSat(out
,
504 Node::fromExpr(d_expr
));
507 /* -------------------------------------------------------------------------- */
508 /* class CheckSatAssumingCommand */
509 /* -------------------------------------------------------------------------- */
511 CheckSatAssumingCommand::CheckSatAssumingCommand(Expr term
) : d_terms({term
}) {}
513 CheckSatAssumingCommand::CheckSatAssumingCommand(const std::vector
<Expr
>& terms
)
518 const std::vector
<Expr
>& CheckSatAssumingCommand::getTerms() const
523 void CheckSatAssumingCommand::invoke(SmtEngine
* smtEngine
)
525 Trace("dtview::command") << "* ~COMMAND: (check-sat-assuming ( " << d_terms
526 << " )~" << std::endl
;
529 d_result
= smtEngine
->checkSat(d_terms
);
530 d_commandStatus
= CommandSuccess::instance();
534 d_commandStatus
= new CommandFailure(e
.what());
538 Result
CheckSatAssumingCommand::getResult() const
540 Trace("dtview::command") << "* ~RESULT: " << d_result
<< "~" << std::endl
;
544 void CheckSatAssumingCommand::printResult(std::ostream
& out
,
545 uint32_t verbosity
) const
549 this->Command::printResult(out
, verbosity
);
553 out
<< d_result
<< endl
;
557 Command
* CheckSatAssumingCommand::exportTo(
558 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
560 vector
<Expr
> exportedTerms
;
561 for (const Expr
& e
: d_terms
)
563 exportedTerms
.push_back(e
.exportTo(exprManager
, variableMap
));
565 CheckSatAssumingCommand
* c
= new CheckSatAssumingCommand(exportedTerms
);
566 c
->d_result
= d_result
;
570 Command
* CheckSatAssumingCommand::clone() const
572 CheckSatAssumingCommand
* c
= new CheckSatAssumingCommand(d_terms
);
573 c
->d_result
= d_result
;
577 std::string
CheckSatAssumingCommand::getCommandName() const
579 return "check-sat-assuming";
582 void CheckSatAssumingCommand::toStream(std::ostream
& out
,
586 OutputLanguage language
) const
588 std::vector
<Node
> nodes
;
589 nodes
.reserve(d_terms
.size());
590 for (const Expr
& e
: d_terms
)
592 nodes
.push_back(Node::fromExpr(e
));
594 Printer::getPrinter(language
)->toStreamCmdCheckSatAssuming(out
, nodes
);
597 /* -------------------------------------------------------------------------- */
598 /* class QueryCommand */
599 /* -------------------------------------------------------------------------- */
601 QueryCommand::QueryCommand(const Expr
& e
, bool inUnsatCore
)
602 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
606 Expr
QueryCommand::getExpr() const { return d_expr
; }
607 void QueryCommand::invoke(SmtEngine
* smtEngine
)
611 d_result
= smtEngine
->checkEntailed(d_expr
);
612 d_commandStatus
= CommandSuccess::instance();
616 d_commandStatus
= new CommandFailure(e
.what());
620 Result
QueryCommand::getResult() const { return d_result
; }
621 void QueryCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
625 this->Command::printResult(out
, verbosity
);
629 out
<< d_result
<< endl
;
633 Command
* QueryCommand::exportTo(ExprManager
* exprManager
,
634 ExprManagerMapCollection
& variableMap
)
636 QueryCommand
* c
= new QueryCommand(d_expr
.exportTo(exprManager
, variableMap
),
638 c
->d_result
= d_result
;
642 Command
* QueryCommand::clone() const
644 QueryCommand
* c
= new QueryCommand(d_expr
, d_inUnsatCore
);
645 c
->d_result
= d_result
;
649 std::string
QueryCommand::getCommandName() const { return "query"; }
651 void QueryCommand::toStream(std::ostream
& out
,
655 OutputLanguage language
) const
657 Printer::getPrinter(language
)->toStreamCmdQuery(out
, d_expr
);
660 /* -------------------------------------------------------------------------- */
661 /* class DeclareSygusVarCommand */
662 /* -------------------------------------------------------------------------- */
664 DeclareSygusVarCommand::DeclareSygusVarCommand(const std::string
& id
,
667 : DeclarationDefinitionCommand(id
), d_var(var
), d_type(t
)
671 Expr
DeclareSygusVarCommand::getVar() const { return d_var
; }
672 Type
DeclareSygusVarCommand::getType() const { return d_type
; }
674 void DeclareSygusVarCommand::invoke(SmtEngine
* smtEngine
)
678 smtEngine
->declareSygusVar(
679 d_symbol
, Node::fromExpr(d_var
), TypeNode::fromType(d_type
));
680 d_commandStatus
= CommandSuccess::instance();
684 d_commandStatus
= new CommandFailure(e
.what());
688 Command
* DeclareSygusVarCommand::exportTo(ExprManager
* exprManager
,
689 ExprManagerMapCollection
& variableMap
)
691 return new DeclareSygusVarCommand(d_symbol
,
692 d_var
.exportTo(exprManager
, variableMap
),
693 d_type
.exportTo(exprManager
, variableMap
));
696 Command
* DeclareSygusVarCommand::clone() const
698 return new DeclareSygusVarCommand(d_symbol
, d_var
, d_type
);
701 std::string
DeclareSygusVarCommand::getCommandName() const
703 return "declare-var";
706 void DeclareSygusVarCommand::toStream(std::ostream
& out
,
710 OutputLanguage language
) const
712 Printer::getPrinter(language
)->toStreamCmdDeclareVar(
713 out
, Node::fromExpr(d_var
), TypeNode::fromType(d_type
));
716 /* -------------------------------------------------------------------------- */
717 /* class SynthFunCommand */
718 /* -------------------------------------------------------------------------- */
720 SynthFunCommand::SynthFunCommand(const api::Solver
* solver
,
721 const std::string
& id
,
723 const std::vector
<api::Term
>& vars
,
727 : DeclarationDefinitionCommand(id
),
737 api::Term
SynthFunCommand::getFunction() const { return d_fun
; }
739 const std::vector
<api::Term
>& SynthFunCommand::getVars() const
744 api::Sort
SynthFunCommand::getSort() const { return d_sort
; }
745 bool SynthFunCommand::isInv() const { return d_isInv
; }
747 const api::Grammar
* SynthFunCommand::getGrammar() const { return d_grammar
; }
749 void SynthFunCommand::invoke(SmtEngine
* smtEngine
)
753 std::vector
<Node
> vns
;
754 for (const api::Term
& t
: d_vars
)
756 vns
.push_back(Node::fromExpr(t
.getExpr()));
758 smtEngine
->declareSynthFun(
760 Node::fromExpr(d_fun
.getExpr()),
761 TypeNode::fromType(d_grammar
== nullptr
763 : d_grammar
->resolve().getType()),
766 d_commandStatus
= CommandSuccess::instance();
770 d_commandStatus
= new CommandFailure(e
.what());
774 Command
* SynthFunCommand::exportTo(ExprManager
* exprManager
,
775 ExprManagerMapCollection
& variableMap
)
780 Command
* SynthFunCommand::clone() const
782 return new SynthFunCommand(
783 d_solver
, d_symbol
, d_fun
, d_vars
, d_sort
, d_isInv
, d_grammar
);
786 std::string
SynthFunCommand::getCommandName() const
788 return d_isInv
? "synth-inv" : "synth-fun";
791 void SynthFunCommand::toStream(std::ostream
& out
,
795 OutputLanguage language
) const
797 std::vector
<Node
> nodeVars
= termVectorToNodes(d_vars
);
798 Printer::getPrinter(language
)->toStreamCmdSynthFun(
802 TypeNode::fromType(d_sort
.getType()),
804 TypeNode::fromType(d_grammar
->resolve().getType()));
807 /* -------------------------------------------------------------------------- */
808 /* class SygusConstraintCommand */
809 /* -------------------------------------------------------------------------- */
811 SygusConstraintCommand::SygusConstraintCommand(const Expr
& e
) : d_expr(e
) {}
813 void SygusConstraintCommand::invoke(SmtEngine
* smtEngine
)
817 smtEngine
->assertSygusConstraint(d_expr
);
818 d_commandStatus
= CommandSuccess::instance();
822 d_commandStatus
= new CommandFailure(e
.what());
826 Expr
SygusConstraintCommand::getExpr() const { return d_expr
; }
828 Command
* SygusConstraintCommand::exportTo(ExprManager
* exprManager
,
829 ExprManagerMapCollection
& variableMap
)
831 return new SygusConstraintCommand(d_expr
.exportTo(exprManager
, variableMap
));
834 Command
* SygusConstraintCommand::clone() const
836 return new SygusConstraintCommand(d_expr
);
839 std::string
SygusConstraintCommand::getCommandName() const
844 void SygusConstraintCommand::toStream(std::ostream
& out
,
848 OutputLanguage language
) const
850 Printer::getPrinter(language
)->toStreamCmdConstraint(out
,
851 Node::fromExpr(d_expr
));
854 /* -------------------------------------------------------------------------- */
855 /* class SygusInvConstraintCommand */
856 /* -------------------------------------------------------------------------- */
858 SygusInvConstraintCommand::SygusInvConstraintCommand(
859 const std::vector
<Expr
>& predicates
)
860 : d_predicates(predicates
)
864 SygusInvConstraintCommand::SygusInvConstraintCommand(const Expr
& inv
,
868 : SygusInvConstraintCommand(std::vector
<Expr
>{inv
, pre
, trans
, post
})
872 void SygusInvConstraintCommand::invoke(SmtEngine
* smtEngine
)
876 smtEngine
->assertSygusInvConstraint(
877 d_predicates
[0], d_predicates
[1], d_predicates
[2], d_predicates
[3]);
878 d_commandStatus
= CommandSuccess::instance();
882 d_commandStatus
= new CommandFailure(e
.what());
886 const std::vector
<Expr
>& SygusInvConstraintCommand::getPredicates() const
891 Command
* SygusInvConstraintCommand::exportTo(
892 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
894 return new SygusInvConstraintCommand(d_predicates
);
897 Command
* SygusInvConstraintCommand::clone() const
899 return new SygusInvConstraintCommand(d_predicates
);
902 std::string
SygusInvConstraintCommand::getCommandName() const
904 return "inv-constraint";
907 void SygusInvConstraintCommand::toStream(std::ostream
& out
,
911 OutputLanguage language
) const
913 Printer::getPrinter(language
)->toStreamCmdInvConstraint(
915 Node::fromExpr(d_predicates
[0]),
916 Node::fromExpr(d_predicates
[1]),
917 Node::fromExpr(d_predicates
[2]),
918 Node::fromExpr(d_predicates
[3]));
921 /* -------------------------------------------------------------------------- */
922 /* class CheckSynthCommand */
923 /* -------------------------------------------------------------------------- */
925 void CheckSynthCommand::invoke(SmtEngine
* smtEngine
)
929 d_result
= smtEngine
->checkSynth();
930 d_commandStatus
= CommandSuccess::instance();
931 smt::SmtScope
scope(smtEngine
);
933 // check whether we should print the status
934 if (d_result
.asSatisfiabilityResult() != Result::UNSAT
935 || options::sygusOut() == options::SygusSolutionOutMode::STATUS_AND_DEF
936 || options::sygusOut() == options::SygusSolutionOutMode::STATUS
)
938 if (options::sygusOut() == options::SygusSolutionOutMode::STANDARD
)
940 d_solution
<< "(fail)" << endl
;
944 d_solution
<< d_result
<< endl
;
947 // check whether we should print the solution
948 if (d_result
.asSatisfiabilityResult() == Result::UNSAT
949 && options::sygusOut() != options::SygusSolutionOutMode::STATUS
)
951 // printing a synthesis solution is a non-constant
952 // method, since it invokes a sophisticated algorithm
953 // (Figure 5 of Reynolds et al. CAV 2015).
954 // Hence, we must call here print solution here,
955 // instead of during printResult.
956 smtEngine
->printSynthSolution(d_solution
);
961 d_commandStatus
= new CommandFailure(e
.what());
965 Result
CheckSynthCommand::getResult() const { return d_result
; }
966 void CheckSynthCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
970 this->Command::printResult(out
, verbosity
);
974 out
<< d_solution
.str();
978 Command
* CheckSynthCommand::exportTo(ExprManager
* exprManager
,
979 ExprManagerMapCollection
& variableMap
)
981 return new CheckSynthCommand();
984 Command
* CheckSynthCommand::clone() const { return new CheckSynthCommand(); }
986 std::string
CheckSynthCommand::getCommandName() const { return "check-synth"; }
988 void CheckSynthCommand::toStream(std::ostream
& out
,
992 OutputLanguage language
) const
994 Printer::getPrinter(language
)->toStreamCmdCheckSynth(out
);
997 /* -------------------------------------------------------------------------- */
998 /* class ResetCommand */
999 /* -------------------------------------------------------------------------- */
1001 void ResetCommand::invoke(SmtEngine
* smtEngine
)
1006 d_commandStatus
= CommandSuccess::instance();
1008 catch (exception
& e
)
1010 d_commandStatus
= new CommandFailure(e
.what());
1014 Command
* ResetCommand::exportTo(ExprManager
* exprManager
,
1015 ExprManagerMapCollection
& variableMap
)
1017 return new ResetCommand();
1020 Command
* ResetCommand::clone() const { return new ResetCommand(); }
1021 std::string
ResetCommand::getCommandName() const { return "reset"; }
1023 void ResetCommand::toStream(std::ostream
& out
,
1027 OutputLanguage language
) const
1029 Printer::getPrinter(language
)->toStreamCmdReset(out
);
1032 /* -------------------------------------------------------------------------- */
1033 /* class ResetAssertionsCommand */
1034 /* -------------------------------------------------------------------------- */
1036 void ResetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
1040 smtEngine
->resetAssertions();
1041 d_commandStatus
= CommandSuccess::instance();
1043 catch (exception
& e
)
1045 d_commandStatus
= new CommandFailure(e
.what());
1049 Command
* ResetAssertionsCommand::exportTo(ExprManager
* exprManager
,
1050 ExprManagerMapCollection
& variableMap
)
1052 return new ResetAssertionsCommand();
1055 Command
* ResetAssertionsCommand::clone() const
1057 return new ResetAssertionsCommand();
1060 std::string
ResetAssertionsCommand::getCommandName() const
1062 return "reset-assertions";
1065 void ResetAssertionsCommand::toStream(std::ostream
& out
,
1069 OutputLanguage language
) const
1071 Printer::getPrinter(language
)->toStreamCmdResetAssertions(out
);
1074 /* -------------------------------------------------------------------------- */
1075 /* class QuitCommand */
1076 /* -------------------------------------------------------------------------- */
1078 void QuitCommand::invoke(SmtEngine
* smtEngine
)
1080 Dump("benchmark") << *this;
1081 d_commandStatus
= CommandSuccess::instance();
1084 Command
* QuitCommand::exportTo(ExprManager
* exprManager
,
1085 ExprManagerMapCollection
& variableMap
)
1087 return new QuitCommand();
1090 Command
* QuitCommand::clone() const { return new QuitCommand(); }
1091 std::string
QuitCommand::getCommandName() const { return "exit"; }
1093 void QuitCommand::toStream(std::ostream
& out
,
1097 OutputLanguage language
) const
1099 Printer::getPrinter(language
)->toStreamCmdQuit(out
);
1102 /* -------------------------------------------------------------------------- */
1103 /* class CommentCommand */
1104 /* -------------------------------------------------------------------------- */
1106 CommentCommand::CommentCommand(std::string comment
) : d_comment(comment
) {}
1107 std::string
CommentCommand::getComment() const { return d_comment
; }
1108 void CommentCommand::invoke(SmtEngine
* smtEngine
)
1110 Dump("benchmark") << *this;
1111 d_commandStatus
= CommandSuccess::instance();
1114 Command
* CommentCommand::exportTo(ExprManager
* exprManager
,
1115 ExprManagerMapCollection
& variableMap
)
1117 return new CommentCommand(d_comment
);
1120 Command
* CommentCommand::clone() const { return new CommentCommand(d_comment
); }
1121 std::string
CommentCommand::getCommandName() const { return "comment"; }
1123 void CommentCommand::toStream(std::ostream
& out
,
1127 OutputLanguage language
) const
1129 Printer::getPrinter(language
)->toStreamCmdComment(out
, d_comment
);
1132 /* -------------------------------------------------------------------------- */
1133 /* class CommandSequence */
1134 /* -------------------------------------------------------------------------- */
1136 CommandSequence::CommandSequence() : d_index(0) {}
1137 CommandSequence::~CommandSequence()
1139 for (unsigned i
= d_index
; i
< d_commandSequence
.size(); ++i
)
1141 delete d_commandSequence
[i
];
1145 void CommandSequence::addCommand(Command
* cmd
)
1147 d_commandSequence
.push_back(cmd
);
1150 void CommandSequence::clear() { d_commandSequence
.clear(); }
1151 void CommandSequence::invoke(SmtEngine
* smtEngine
)
1153 for (; d_index
< d_commandSequence
.size(); ++d_index
)
1155 d_commandSequence
[d_index
]->invoke(smtEngine
);
1156 if (!d_commandSequence
[d_index
]->ok())
1159 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
1162 delete d_commandSequence
[d_index
];
1165 AlwaysAssert(d_commandStatus
== NULL
);
1166 d_commandStatus
= CommandSuccess::instance();
1169 void CommandSequence::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
1171 for (; d_index
< d_commandSequence
.size(); ++d_index
)
1173 d_commandSequence
[d_index
]->invoke(smtEngine
, out
);
1174 if (!d_commandSequence
[d_index
]->ok())
1177 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
1180 delete d_commandSequence
[d_index
];
1183 AlwaysAssert(d_commandStatus
== NULL
);
1184 d_commandStatus
= CommandSuccess::instance();
1187 Command
* CommandSequence::exportTo(ExprManager
* exprManager
,
1188 ExprManagerMapCollection
& variableMap
)
1190 CommandSequence
* seq
= new CommandSequence();
1191 for (iterator i
= begin(); i
!= end(); ++i
)
1193 Command
* cmd_to_export
= *i
;
1194 Command
* cmd
= cmd_to_export
->exportTo(exprManager
, variableMap
);
1195 seq
->addCommand(cmd
);
1196 Debug("export") << "[export] so far converted: " << seq
<< endl
;
1198 seq
->d_index
= d_index
;
1202 Command
* CommandSequence::clone() const
1204 CommandSequence
* seq
= new CommandSequence();
1205 for (const_iterator i
= begin(); i
!= end(); ++i
)
1207 seq
->addCommand((*i
)->clone());
1209 seq
->d_index
= d_index
;
1213 CommandSequence::const_iterator
CommandSequence::begin() const
1215 return d_commandSequence
.begin();
1218 CommandSequence::const_iterator
CommandSequence::end() const
1220 return d_commandSequence
.end();
1223 CommandSequence::iterator
CommandSequence::begin()
1225 return d_commandSequence
.begin();
1228 CommandSequence::iterator
CommandSequence::end()
1230 return d_commandSequence
.end();
1233 std::string
CommandSequence::getCommandName() const { return "sequence"; }
1235 void CommandSequence::toStream(std::ostream
& out
,
1239 OutputLanguage language
) const
1241 Printer::getPrinter(language
)->toStreamCmdCommandSequence(out
,
1245 /* -------------------------------------------------------------------------- */
1246 /* class DeclarationSequence */
1247 /* -------------------------------------------------------------------------- */
1249 void DeclarationSequence::toStream(std::ostream
& out
,
1253 OutputLanguage language
) const
1255 Printer::getPrinter(language
)->toStreamCmdDeclarationSequence(
1256 out
, d_commandSequence
);
1259 /* -------------------------------------------------------------------------- */
1260 /* class DeclarationDefinitionCommand */
1261 /* -------------------------------------------------------------------------- */
1263 DeclarationDefinitionCommand::DeclarationDefinitionCommand(
1264 const std::string
& id
)
1269 std::string
DeclarationDefinitionCommand::getSymbol() const { return d_symbol
; }
1271 /* -------------------------------------------------------------------------- */
1272 /* class DeclareFunctionCommand */
1273 /* -------------------------------------------------------------------------- */
1275 DeclareFunctionCommand::DeclareFunctionCommand(const std::string
& id
,
1278 : DeclarationDefinitionCommand(id
),
1281 d_printInModel(true),
1282 d_printInModelSetByUser(false)
1286 Expr
DeclareFunctionCommand::getFunction() const { return d_func
; }
1287 Type
DeclareFunctionCommand::getType() const { return d_type
; }
1288 bool DeclareFunctionCommand::getPrintInModel() const { return d_printInModel
; }
1289 bool DeclareFunctionCommand::getPrintInModelSetByUser() const
1291 return d_printInModelSetByUser
;
1294 void DeclareFunctionCommand::setPrintInModel(bool p
)
1297 d_printInModelSetByUser
= true;
1300 void DeclareFunctionCommand::invoke(SmtEngine
* smtEngine
)
1302 d_commandStatus
= CommandSuccess::instance();
1305 Command
* DeclareFunctionCommand::exportTo(ExprManager
* exprManager
,
1306 ExprManagerMapCollection
& variableMap
)
1308 DeclareFunctionCommand
* dfc
=
1309 new DeclareFunctionCommand(d_symbol
,
1310 d_func
.exportTo(exprManager
, variableMap
),
1311 d_type
.exportTo(exprManager
, variableMap
));
1312 dfc
->d_printInModel
= d_printInModel
;
1313 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
1317 Command
* DeclareFunctionCommand::clone() const
1319 DeclareFunctionCommand
* dfc
=
1320 new DeclareFunctionCommand(d_symbol
, d_func
, d_type
);
1321 dfc
->d_printInModel
= d_printInModel
;
1322 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
1326 std::string
DeclareFunctionCommand::getCommandName() const
1328 return "declare-fun";
1331 void DeclareFunctionCommand::toStream(std::ostream
& out
,
1335 OutputLanguage language
) const
1337 Printer::getPrinter(language
)->toStreamCmdDeclareFunction(
1338 out
, d_func
.toString(), TypeNode::fromType(d_type
));
1341 /* -------------------------------------------------------------------------- */
1342 /* class DeclareTypeCommand */
1343 /* -------------------------------------------------------------------------- */
1345 DeclareTypeCommand::DeclareTypeCommand(const std::string
& id
,
1348 : DeclarationDefinitionCommand(id
), d_arity(arity
), d_type(t
)
1352 size_t DeclareTypeCommand::getArity() const { return d_arity
; }
1353 Type
DeclareTypeCommand::getType() const { return d_type
; }
1354 void DeclareTypeCommand::invoke(SmtEngine
* smtEngine
)
1356 d_commandStatus
= CommandSuccess::instance();
1359 Command
* DeclareTypeCommand::exportTo(ExprManager
* exprManager
,
1360 ExprManagerMapCollection
& variableMap
)
1362 return new DeclareTypeCommand(
1363 d_symbol
, d_arity
, d_type
.exportTo(exprManager
, variableMap
));
1366 Command
* DeclareTypeCommand::clone() const
1368 return new DeclareTypeCommand(d_symbol
, d_arity
, d_type
);
1371 std::string
DeclareTypeCommand::getCommandName() const
1373 return "declare-sort";
1376 void DeclareTypeCommand::toStream(std::ostream
& out
,
1380 OutputLanguage language
) const
1382 Printer::getPrinter(language
)->toStreamCmdDeclareType(
1383 out
, d_type
.toString(), d_arity
, TypeNode::fromType(d_type
));
1386 /* -------------------------------------------------------------------------- */
1387 /* class DefineTypeCommand */
1388 /* -------------------------------------------------------------------------- */
1390 DefineTypeCommand::DefineTypeCommand(const std::string
& id
, Type t
)
1391 : DeclarationDefinitionCommand(id
), d_params(), d_type(t
)
1395 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
1396 const std::vector
<Type
>& params
,
1398 : DeclarationDefinitionCommand(id
), d_params(params
), d_type(t
)
1402 const std::vector
<Type
>& DefineTypeCommand::getParameters() const
1407 Type
DefineTypeCommand::getType() const { return d_type
; }
1408 void DefineTypeCommand::invoke(SmtEngine
* smtEngine
)
1410 d_commandStatus
= CommandSuccess::instance();
1413 Command
* DefineTypeCommand::exportTo(ExprManager
* exprManager
,
1414 ExprManagerMapCollection
& variableMap
)
1416 vector
<Type
> params
;
1417 transform(d_params
.begin(),
1419 back_inserter(params
),
1420 ExportTransformer(exprManager
, variableMap
));
1421 Type type
= d_type
.exportTo(exprManager
, variableMap
);
1422 return new DefineTypeCommand(d_symbol
, params
, type
);
1425 Command
* DefineTypeCommand::clone() const
1427 return new DefineTypeCommand(d_symbol
, d_params
, d_type
);
1430 std::string
DefineTypeCommand::getCommandName() const { return "define-sort"; }
1432 void DefineTypeCommand::toStream(std::ostream
& out
,
1436 OutputLanguage language
) const
1438 Printer::getPrinter(language
)->toStreamCmdDefineType(
1441 typeVectorToTypeNodes(d_params
),
1442 TypeNode::fromType(d_type
));
1445 /* -------------------------------------------------------------------------- */
1446 /* class DefineFunctionCommand */
1447 /* -------------------------------------------------------------------------- */
1449 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1453 : DeclarationDefinitionCommand(id
),
1461 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1463 const std::vector
<Expr
>& formals
,
1466 : DeclarationDefinitionCommand(id
),
1475 Expr
DefineFunctionCommand::getFunction() const { return d_func
; }
1476 const std::vector
<Expr
>& DefineFunctionCommand::getFormals() const
1481 Expr
DefineFunctionCommand::getFormula() const { return d_formula
; }
1482 void DefineFunctionCommand::invoke(SmtEngine
* smtEngine
)
1486 if (!d_func
.isNull())
1488 smtEngine
->defineFunction(d_func
, d_formals
, d_formula
, d_global
);
1490 d_commandStatus
= CommandSuccess::instance();
1492 catch (exception
& e
)
1494 d_commandStatus
= new CommandFailure(e
.what());
1498 Command
* DefineFunctionCommand::exportTo(ExprManager
* exprManager
,
1499 ExprManagerMapCollection
& variableMap
)
1501 Expr func
= d_func
.exportTo(
1502 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1503 vector
<Expr
> formals
;
1504 transform(d_formals
.begin(),
1506 back_inserter(formals
),
1507 ExportTransformer(exprManager
, variableMap
));
1508 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1509 return new DefineFunctionCommand(d_symbol
, func
, formals
, formula
, d_global
);
1512 Command
* DefineFunctionCommand::clone() const
1514 return new DefineFunctionCommand(
1515 d_symbol
, d_func
, d_formals
, d_formula
, d_global
);
1518 std::string
DefineFunctionCommand::getCommandName() const
1520 return "define-fun";
1523 void DefineFunctionCommand::toStream(std::ostream
& out
,
1527 OutputLanguage language
) const
1529 Printer::getPrinter(language
)->toStreamCmdDefineFunction(
1532 exprVectorToNodes(d_formals
),
1533 Node::fromExpr(d_func
).getType().getRangeType(),
1534 Node::fromExpr(d_formula
));
1537 /* -------------------------------------------------------------------------- */
1538 /* class DefineNamedFunctionCommand */
1539 /* -------------------------------------------------------------------------- */
1541 DefineNamedFunctionCommand::DefineNamedFunctionCommand(
1542 const std::string
& id
,
1544 const std::vector
<Expr
>& formals
,
1547 : DefineFunctionCommand(id
, func
, formals
, formula
, global
)
1551 void DefineNamedFunctionCommand::invoke(SmtEngine
* smtEngine
)
1553 this->DefineFunctionCommand::invoke(smtEngine
);
1554 if (!d_func
.isNull() && d_func
.getType().isBoolean())
1556 smtEngine
->addToAssignment(d_func
);
1558 d_commandStatus
= CommandSuccess::instance();
1561 Command
* DefineNamedFunctionCommand::exportTo(
1562 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1564 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
1565 vector
<Expr
> formals
;
1566 transform(d_formals
.begin(),
1568 back_inserter(formals
),
1569 ExportTransformer(exprManager
, variableMap
));
1570 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1571 return new DefineNamedFunctionCommand(
1572 d_symbol
, func
, formals
, formula
, d_global
);
1575 Command
* DefineNamedFunctionCommand::clone() const
1577 return new DefineNamedFunctionCommand(
1578 d_symbol
, d_func
, d_formals
, d_formula
, d_global
);
1581 void DefineNamedFunctionCommand::toStream(std::ostream
& out
,
1585 OutputLanguage language
) const
1587 Printer::getPrinter(language
)->toStreamCmdDefineNamedFunction(
1590 exprVectorToNodes(d_formals
),
1591 Node::fromExpr(d_func
).getType().getRangeType(),
1592 Node::fromExpr(d_formula
));
1595 /* -------------------------------------------------------------------------- */
1596 /* class DefineFunctionRecCommand */
1597 /* -------------------------------------------------------------------------- */
1599 DefineFunctionRecCommand::DefineFunctionRecCommand(
1600 const api::Solver
* solver
,
1602 const std::vector
<api::Term
>& formals
,
1605 : Command(solver
), d_global(global
)
1607 d_funcs
.push_back(func
);
1608 d_formals
.push_back(formals
);
1609 d_formulas
.push_back(formula
);
1612 DefineFunctionRecCommand::DefineFunctionRecCommand(
1613 const api::Solver
* solver
,
1614 const std::vector
<api::Term
>& funcs
,
1615 const std::vector
<std::vector
<api::Term
>>& formals
,
1616 const std::vector
<api::Term
>& formulas
,
1621 d_formulas(formulas
),
1626 const std::vector
<api::Term
>& DefineFunctionRecCommand::getFunctions() const
1631 const std::vector
<std::vector
<api::Term
>>&
1632 DefineFunctionRecCommand::getFormals() const
1637 const std::vector
<api::Term
>& DefineFunctionRecCommand::getFormulas() const
1642 void DefineFunctionRecCommand::invoke(SmtEngine
* smtEngine
)
1646 d_solver
->defineFunsRec(d_funcs
, d_formals
, d_formulas
, d_global
);
1647 d_commandStatus
= CommandSuccess::instance();
1649 catch (exception
& e
)
1651 d_commandStatus
= new CommandFailure(e
.what());
1655 Command
* DefineFunctionRecCommand::exportTo(
1656 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1661 Command
* DefineFunctionRecCommand::clone() const
1663 return new DefineFunctionRecCommand(
1664 d_solver
, d_funcs
, d_formals
, d_formulas
, d_global
);
1667 std::string
DefineFunctionRecCommand::getCommandName() const
1669 return "define-fun-rec";
1672 void DefineFunctionRecCommand::toStream(std::ostream
& out
,
1676 OutputLanguage language
) const
1678 std::vector
<std::vector
<Node
>> formals
;
1679 formals
.reserve(d_formals
.size());
1680 for (const std::vector
<api::Term
>& formal
: d_formals
)
1682 formals
.push_back(api::termVectorToNodes(formal
));
1685 Printer::getPrinter(language
)->toStreamCmdDefineFunctionRec(
1687 api::termVectorToNodes(d_funcs
),
1689 api::termVectorToNodes(d_formulas
));
1692 /* -------------------------------------------------------------------------- */
1693 /* class SetUserAttribute */
1694 /* -------------------------------------------------------------------------- */
1696 SetUserAttributeCommand::SetUserAttributeCommand(
1697 const std::string
& attr
,
1699 const std::vector
<Expr
>& expr_values
,
1700 const std::string
& str_value
)
1703 d_expr_values(expr_values
),
1704 d_str_value(str_value
)
1708 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1710 : SetUserAttributeCommand(attr
, expr
, {}, "")
1714 SetUserAttributeCommand::SetUserAttributeCommand(
1715 const std::string
& attr
, Expr expr
, const std::vector
<Expr
>& values
)
1716 : SetUserAttributeCommand(attr
, expr
, values
, "")
1720 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1722 const std::string
& value
)
1723 : SetUserAttributeCommand(attr
, expr
, {}, value
)
1727 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
)
1731 if (!d_expr
.isNull())
1733 smtEngine
->setUserAttribute(d_attr
, d_expr
, d_expr_values
, d_str_value
);
1735 d_commandStatus
= CommandSuccess::instance();
1737 catch (exception
& e
)
1739 d_commandStatus
= new CommandFailure(e
.what());
1743 Command
* SetUserAttributeCommand::exportTo(
1744 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1746 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
1747 return new SetUserAttributeCommand(d_attr
, expr
, d_expr_values
, d_str_value
);
1750 Command
* SetUserAttributeCommand::clone() const
1752 return new SetUserAttributeCommand(
1753 d_attr
, d_expr
, d_expr_values
, d_str_value
);
1756 std::string
SetUserAttributeCommand::getCommandName() const
1758 return "set-user-attribute";
1761 void SetUserAttributeCommand::toStream(std::ostream
& out
,
1765 OutputLanguage language
) const
1767 Printer::getPrinter(language
)->toStreamCmdSetUserAttribute(
1768 out
, d_attr
, Node::fromExpr(d_expr
));
1771 /* -------------------------------------------------------------------------- */
1772 /* class SimplifyCommand */
1773 /* -------------------------------------------------------------------------- */
1775 SimplifyCommand::SimplifyCommand(Expr term
) : d_term(term
) {}
1776 Expr
SimplifyCommand::getTerm() const { return d_term
; }
1777 void SimplifyCommand::invoke(SmtEngine
* smtEngine
)
1781 d_result
= smtEngine
->simplify(Node::fromExpr(d_term
)).toExpr();
1782 d_commandStatus
= CommandSuccess::instance();
1784 catch (UnsafeInterruptException
& e
)
1786 d_commandStatus
= new CommandInterrupted();
1788 catch (exception
& e
)
1790 d_commandStatus
= new CommandFailure(e
.what());
1794 Expr
SimplifyCommand::getResult() const { return d_result
; }
1795 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1799 this->Command::printResult(out
, verbosity
);
1803 out
<< d_result
<< endl
;
1807 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
,
1808 ExprManagerMapCollection
& variableMap
)
1810 SimplifyCommand
* c
=
1811 new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
1812 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1816 Command
* SimplifyCommand::clone() const
1818 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
1819 c
->d_result
= d_result
;
1823 std::string
SimplifyCommand::getCommandName() const { return "simplify"; }
1825 void SimplifyCommand::toStream(std::ostream
& out
,
1829 OutputLanguage language
) const
1831 Printer::getPrinter(language
)->toStreamCmdSimplify(out
, d_term
);
1834 /* -------------------------------------------------------------------------- */
1835 /* class ExpandDefinitionsCommand */
1836 /* -------------------------------------------------------------------------- */
1838 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) : d_term(term
) {}
1839 Expr
ExpandDefinitionsCommand::getTerm() const { return d_term
; }
1840 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
)
1842 Node t
= Node::fromExpr(d_term
);
1843 d_result
= smtEngine
->expandDefinitions(t
).toExpr();
1844 d_commandStatus
= CommandSuccess::instance();
1847 Expr
ExpandDefinitionsCommand::getResult() const { return d_result
; }
1848 void ExpandDefinitionsCommand::printResult(std::ostream
& out
,
1849 uint32_t verbosity
) const
1853 this->Command::printResult(out
, verbosity
);
1857 out
<< d_result
<< endl
;
1861 Command
* ExpandDefinitionsCommand::exportTo(
1862 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1864 ExpandDefinitionsCommand
* c
=
1865 new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
1866 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1870 Command
* ExpandDefinitionsCommand::clone() const
1872 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
1873 c
->d_result
= d_result
;
1877 std::string
ExpandDefinitionsCommand::getCommandName() const
1879 return "expand-definitions";
1882 void ExpandDefinitionsCommand::toStream(std::ostream
& out
,
1886 OutputLanguage language
) const
1888 Printer::getPrinter(language
)->toStreamCmdExpandDefinitions(
1889 out
, Node::fromExpr(d_term
));
1892 /* -------------------------------------------------------------------------- */
1893 /* class GetValueCommand */
1894 /* -------------------------------------------------------------------------- */
1896 GetValueCommand::GetValueCommand(Expr term
) : d_terms()
1898 d_terms
.push_back(term
);
1901 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
)
1904 PrettyCheckArgument(
1905 terms
.size() >= 1, terms
, "cannot get-value of an empty set of terms");
1908 const std::vector
<Expr
>& GetValueCommand::getTerms() const { return d_terms
; }
1909 void GetValueCommand::invoke(SmtEngine
* smtEngine
)
1913 ExprManager
* em
= smtEngine
->getExprManager();
1914 NodeManager
* nm
= NodeManager::fromExprManager(em
);
1915 smt::SmtScope
scope(smtEngine
);
1916 vector
<Expr
> result
= smtEngine
->getValues(d_terms
);
1917 Assert(result
.size() == d_terms
.size());
1918 for (int i
= 0, size
= d_terms
.size(); i
< size
; i
++)
1920 Expr e
= d_terms
[i
];
1921 Node eNode
= Node::fromExpr(e
);
1922 Assert(nm
== NodeManager::fromExprManager(e
.getExprManager()));
1923 Node request
= options::expandDefinitions()
1924 ? smtEngine
->expandDefinitions(eNode
)
1926 Node value
= Node::fromExpr(result
[i
]);
1927 if (value
.getType().isInteger() && request
.getType() == nm
->realType())
1929 // Need to wrap in division-by-one so that output printers know this
1930 // is an integer-looking constant that really should be output as
1931 // a rational. Necessary for SMT-LIB standards compliance.
1932 value
= nm
->mkNode(kind::DIVISION
, value
, nm
->mkConst(Rational(1)));
1934 result
[i
] = nm
->mkNode(kind::SEXPR
, request
, value
).toExpr();
1936 d_result
= em
->mkExpr(kind::SEXPR
, result
);
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 Expr
GetValueCommand::getResult() const { return d_result
; }
1954 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1958 this->Command::printResult(out
, verbosity
);
1962 expr::ExprDag::Scope
scope(out
, false);
1963 out
<< d_result
<< endl
;
1967 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
,
1968 ExprManagerMapCollection
& variableMap
)
1970 vector
<Expr
> exportedTerms
;
1971 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1975 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1977 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1978 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1982 Command
* GetValueCommand::clone() const
1984 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1985 c
->d_result
= d_result
;
1989 std::string
GetValueCommand::getCommandName() const { return "get-value"; }
1991 void GetValueCommand::toStream(std::ostream
& out
,
1995 OutputLanguage language
) const
1997 Printer::getPrinter(language
)->toStreamCmdGetValue(
1998 out
, exprVectorToNodes(d_terms
));
2001 /* -------------------------------------------------------------------------- */
2002 /* class GetAssignmentCommand */
2003 /* -------------------------------------------------------------------------- */
2005 GetAssignmentCommand::GetAssignmentCommand() {}
2006 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
)
2010 std::vector
<std::pair
<Expr
, Expr
>> assignments
= smtEngine
->getAssignment();
2011 vector
<SExpr
> sexprs
;
2012 for (const auto& p
: assignments
)
2015 v
.emplace_back(SExpr::Keyword(p
.first
.toString()));
2016 v
.emplace_back(SExpr::Keyword(p
.second
.toString()));
2017 sexprs
.emplace_back(v
);
2019 d_result
= SExpr(sexprs
);
2020 d_commandStatus
= CommandSuccess::instance();
2022 catch (RecoverableModalException
& e
)
2024 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2026 catch (UnsafeInterruptException
& e
)
2028 d_commandStatus
= new CommandInterrupted();
2030 catch (exception
& e
)
2032 d_commandStatus
= new CommandFailure(e
.what());
2036 SExpr
GetAssignmentCommand::getResult() const { return d_result
; }
2037 void GetAssignmentCommand::printResult(std::ostream
& out
,
2038 uint32_t verbosity
) const
2042 this->Command::printResult(out
, verbosity
);
2046 out
<< d_result
<< endl
;
2050 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
,
2051 ExprManagerMapCollection
& variableMap
)
2053 GetAssignmentCommand
* c
= new GetAssignmentCommand();
2054 c
->d_result
= d_result
;
2058 Command
* GetAssignmentCommand::clone() const
2060 GetAssignmentCommand
* c
= new GetAssignmentCommand();
2061 c
->d_result
= d_result
;
2065 std::string
GetAssignmentCommand::getCommandName() const
2067 return "get-assignment";
2070 void GetAssignmentCommand::toStream(std::ostream
& out
,
2074 OutputLanguage language
) const
2076 Printer::getPrinter(language
)->toStreamCmdGetAssignment(out
);
2079 /* -------------------------------------------------------------------------- */
2080 /* class GetModelCommand */
2081 /* -------------------------------------------------------------------------- */
2083 GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
2084 void GetModelCommand::invoke(SmtEngine
* smtEngine
)
2088 d_result
= smtEngine
->getModel();
2089 d_smtEngine
= smtEngine
;
2090 d_commandStatus
= CommandSuccess::instance();
2092 catch (RecoverableModalException
& e
)
2094 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2096 catch (UnsafeInterruptException
& e
)
2098 d_commandStatus
= new CommandInterrupted();
2100 catch (exception
& e
)
2102 d_commandStatus
= new CommandFailure(e
.what());
2106 /* Model is private to the library -- for now
2107 Model* GetModelCommand::getResult() const {
2112 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2116 this->Command::printResult(out
, verbosity
);
2124 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
,
2125 ExprManagerMapCollection
& variableMap
)
2127 GetModelCommand
* c
= new GetModelCommand();
2128 c
->d_result
= d_result
;
2129 c
->d_smtEngine
= d_smtEngine
;
2133 Command
* GetModelCommand::clone() const
2135 GetModelCommand
* c
= new GetModelCommand();
2136 c
->d_result
= d_result
;
2137 c
->d_smtEngine
= d_smtEngine
;
2141 std::string
GetModelCommand::getCommandName() const { return "get-model"; }
2143 void GetModelCommand::toStream(std::ostream
& out
,
2147 OutputLanguage language
) const
2149 Printer::getPrinter(language
)->toStreamCmdGetModel(out
);
2152 /* -------------------------------------------------------------------------- */
2153 /* class BlockModelCommand */
2154 /* -------------------------------------------------------------------------- */
2156 BlockModelCommand::BlockModelCommand() {}
2157 void BlockModelCommand::invoke(SmtEngine
* smtEngine
)
2161 smtEngine
->blockModel();
2162 d_commandStatus
= CommandSuccess::instance();
2164 catch (RecoverableModalException
& e
)
2166 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2168 catch (UnsafeInterruptException
& e
)
2170 d_commandStatus
= new CommandInterrupted();
2172 catch (exception
& e
)
2174 d_commandStatus
= new CommandFailure(e
.what());
2178 Command
* BlockModelCommand::exportTo(ExprManager
* exprManager
,
2179 ExprManagerMapCollection
& variableMap
)
2181 BlockModelCommand
* c
= new BlockModelCommand();
2185 Command
* BlockModelCommand::clone() const
2187 BlockModelCommand
* c
= new BlockModelCommand();
2191 std::string
BlockModelCommand::getCommandName() const { return "block-model"; }
2193 void BlockModelCommand::toStream(std::ostream
& out
,
2197 OutputLanguage language
) const
2199 Printer::getPrinter(language
)->toStreamCmdBlockModel(out
);
2202 /* -------------------------------------------------------------------------- */
2203 /* class BlockModelValuesCommand */
2204 /* -------------------------------------------------------------------------- */
2206 BlockModelValuesCommand::BlockModelValuesCommand(const std::vector
<Expr
>& terms
)
2209 PrettyCheckArgument(terms
.size() >= 1,
2211 "cannot block-model-values of an empty set of terms");
2214 const std::vector
<Expr
>& BlockModelValuesCommand::getTerms() const
2218 void BlockModelValuesCommand::invoke(SmtEngine
* smtEngine
)
2222 smtEngine
->blockModelValues(d_terms
);
2223 d_commandStatus
= CommandSuccess::instance();
2225 catch (RecoverableModalException
& e
)
2227 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2229 catch (UnsafeInterruptException
& e
)
2231 d_commandStatus
= new CommandInterrupted();
2233 catch (exception
& e
)
2235 d_commandStatus
= new CommandFailure(e
.what());
2239 Command
* BlockModelValuesCommand::exportTo(
2240 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2242 vector
<Expr
> exportedTerms
;
2243 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
2247 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
2249 BlockModelValuesCommand
* c
= new BlockModelValuesCommand(exportedTerms
);
2253 Command
* BlockModelValuesCommand::clone() const
2255 BlockModelValuesCommand
* c
= new BlockModelValuesCommand(d_terms
);
2259 std::string
BlockModelValuesCommand::getCommandName() const
2261 return "block-model-values";
2264 void BlockModelValuesCommand::toStream(std::ostream
& out
,
2268 OutputLanguage language
) const
2270 Printer::getPrinter(language
)->toStreamCmdBlockModelValues(
2271 out
, exprVectorToNodes(d_terms
));
2274 /* -------------------------------------------------------------------------- */
2275 /* class GetProofCommand */
2276 /* -------------------------------------------------------------------------- */
2278 GetProofCommand::GetProofCommand() : d_smtEngine(nullptr), d_result(nullptr) {}
2279 void GetProofCommand::invoke(SmtEngine
* smtEngine
)
2283 d_smtEngine
= smtEngine
;
2284 d_result
= &smtEngine
->getProof();
2285 d_commandStatus
= CommandSuccess::instance();
2287 catch (RecoverableModalException
& e
)
2289 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2291 catch (UnsafeInterruptException
& e
)
2293 d_commandStatus
= new CommandInterrupted();
2295 catch (exception
& e
)
2297 d_commandStatus
= new CommandFailure(e
.what());
2301 const Proof
& GetProofCommand::getResult() const { return *d_result
; }
2302 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2306 this->Command::printResult(out
, verbosity
);
2310 smt::SmtScope
scope(d_smtEngine
);
2311 d_result
->toStream(out
);
2315 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
,
2316 ExprManagerMapCollection
& variableMap
)
2318 GetProofCommand
* c
= new GetProofCommand();
2319 c
->d_result
= d_result
;
2320 c
->d_smtEngine
= d_smtEngine
;
2324 Command
* GetProofCommand::clone() const
2326 GetProofCommand
* c
= new GetProofCommand();
2327 c
->d_result
= d_result
;
2328 c
->d_smtEngine
= d_smtEngine
;
2332 std::string
GetProofCommand::getCommandName() const { return "get-proof"; }
2334 void GetProofCommand::toStream(std::ostream
& out
,
2338 OutputLanguage language
) const
2340 Printer::getPrinter(language
)->toStreamCmdGetProof(out
);
2343 /* -------------------------------------------------------------------------- */
2344 /* class GetInstantiationsCommand */
2345 /* -------------------------------------------------------------------------- */
2347 GetInstantiationsCommand::GetInstantiationsCommand() : d_smtEngine(nullptr) {}
2348 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
)
2352 d_smtEngine
= smtEngine
;
2353 d_commandStatus
= CommandSuccess::instance();
2355 catch (exception
& e
)
2357 d_commandStatus
= new CommandFailure(e
.what());
2361 void GetInstantiationsCommand::printResult(std::ostream
& out
,
2362 uint32_t verbosity
) const
2366 this->Command::printResult(out
, verbosity
);
2370 d_smtEngine
->printInstantiations(out
);
2374 Command
* GetInstantiationsCommand::exportTo(
2375 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2377 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
2378 // c->d_result = d_result;
2379 c
->d_smtEngine
= d_smtEngine
;
2383 Command
* GetInstantiationsCommand::clone() const
2385 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
2386 // c->d_result = d_result;
2387 c
->d_smtEngine
= d_smtEngine
;
2391 std::string
GetInstantiationsCommand::getCommandName() const
2393 return "get-instantiations";
2396 void GetInstantiationsCommand::toStream(std::ostream
& out
,
2400 OutputLanguage language
) const
2402 Printer::getPrinter(language
)->toStreamCmdGetInstantiations(out
);
2405 /* -------------------------------------------------------------------------- */
2406 /* class GetSynthSolutionCommand */
2407 /* -------------------------------------------------------------------------- */
2409 GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
2410 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
)
2414 d_smtEngine
= smtEngine
;
2415 d_commandStatus
= CommandSuccess::instance();
2417 catch (exception
& e
)
2419 d_commandStatus
= new CommandFailure(e
.what());
2423 void GetSynthSolutionCommand::printResult(std::ostream
& out
,
2424 uint32_t verbosity
) const
2428 this->Command::printResult(out
, verbosity
);
2432 d_smtEngine
->printSynthSolution(out
);
2436 Command
* GetSynthSolutionCommand::exportTo(
2437 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2439 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2440 c
->d_smtEngine
= d_smtEngine
;
2444 Command
* GetSynthSolutionCommand::clone() const
2446 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2447 c
->d_smtEngine
= d_smtEngine
;
2451 std::string
GetSynthSolutionCommand::getCommandName() const
2453 return "get-synth-solution";
2456 void GetSynthSolutionCommand::toStream(std::ostream
& out
,
2460 OutputLanguage language
) const
2462 Printer::getPrinter(language
)->toStreamCmdGetSynthSolution(out
);
2465 /* -------------------------------------------------------------------------- */
2466 /* class GetInterpolCommand */
2467 /* -------------------------------------------------------------------------- */
2469 GetInterpolCommand::GetInterpolCommand(const api::Solver
* solver
,
2470 const std::string
& name
,
2472 : Command(solver
), d_name(name
), d_conj(conj
), d_resultStatus(false)
2475 GetInterpolCommand::GetInterpolCommand(const api::Solver
* solver
,
2476 const std::string
& name
,
2483 d_resultStatus(false)
2487 api::Term
GetInterpolCommand::getConjecture() const { return d_conj
; }
2489 const api::Grammar
* GetInterpolCommand::getGrammar() const
2491 return d_sygus_grammar
;
2494 api::Term
GetInterpolCommand::getResult() const { return d_result
; }
2496 void GetInterpolCommand::invoke(SmtEngine
* smtEngine
)
2500 if (!d_sygus_grammar
)
2502 d_resultStatus
= d_solver
->getInterpolant(d_conj
, d_result
);
2507 d_solver
->getInterpolant(d_conj
, *d_sygus_grammar
, d_result
);
2509 d_commandStatus
= CommandSuccess::instance();
2511 catch (exception
& e
)
2513 d_commandStatus
= new CommandFailure(e
.what());
2517 void GetInterpolCommand::printResult(std::ostream
& out
,
2518 uint32_t verbosity
) const
2522 this->Command::printResult(out
, verbosity
);
2526 expr::ExprDag::Scope
scope(out
, false);
2529 out
<< "(define-fun " << d_name
<< " () Bool " << d_result
<< ")"
2534 out
<< "none" << std::endl
;
2539 Command
* GetInterpolCommand::exportTo(ExprManager
* exprManager
,
2540 ExprManagerMapCollection
& variableMap
)
2545 Command
* GetInterpolCommand::clone() const
2547 GetInterpolCommand
* c
=
2548 new GetInterpolCommand(d_solver
, d_name
, d_conj
, d_sygus_grammar
);
2549 c
->d_result
= d_result
;
2550 c
->d_resultStatus
= d_resultStatus
;
2554 std::string
GetInterpolCommand::getCommandName() const
2556 return "get-interpol";
2559 void GetInterpolCommand::toStream(std::ostream
& out
,
2563 OutputLanguage language
) const
2565 Printer::getPrinter(language
)->toStreamCmdGetInterpol(
2569 TypeNode::fromType(d_sygus_grammar
->resolve().getType()));
2572 /* -------------------------------------------------------------------------- */
2573 /* class GetAbductCommand */
2574 /* -------------------------------------------------------------------------- */
2576 GetAbductCommand::GetAbductCommand(const api::Solver
* solver
,
2577 const std::string
& name
,
2579 : Command(solver
), d_name(name
), d_conj(conj
), d_resultStatus(false)
2582 GetAbductCommand::GetAbductCommand(const api::Solver
* solver
,
2583 const std::string
& name
,
2590 d_resultStatus(false)
2594 api::Term
GetAbductCommand::getConjecture() const { return d_conj
; }
2596 const api::Grammar
* GetAbductCommand::getGrammar() const
2598 return d_sygus_grammar
;
2601 std::string
GetAbductCommand::getAbductName() const { return d_name
; }
2602 api::Term
GetAbductCommand::getResult() const { return d_result
; }
2604 void GetAbductCommand::invoke(SmtEngine
* smtEngine
)
2608 if (!d_sygus_grammar
)
2610 d_resultStatus
= d_solver
->getAbduct(d_conj
, d_result
);
2614 d_resultStatus
= d_solver
->getAbduct(d_conj
, *d_sygus_grammar
, d_result
);
2616 d_commandStatus
= CommandSuccess::instance();
2618 catch (exception
& e
)
2620 d_commandStatus
= new CommandFailure(e
.what());
2624 void GetAbductCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2628 this->Command::printResult(out
, verbosity
);
2632 expr::ExprDag::Scope
scope(out
, false);
2635 out
<< "(define-fun " << d_name
<< " () Bool " << d_result
<< ")"
2640 out
<< "none" << std::endl
;
2645 Command
* GetAbductCommand::exportTo(ExprManager
* exprManager
,
2646 ExprManagerMapCollection
& variableMap
)
2651 Command
* GetAbductCommand::clone() const
2653 GetAbductCommand
* c
=
2654 new GetAbductCommand(d_solver
, d_name
, d_conj
, d_sygus_grammar
);
2655 c
->d_result
= d_result
;
2656 c
->d_resultStatus
= d_resultStatus
;
2660 std::string
GetAbductCommand::getCommandName() const { return "get-abduct"; }
2662 void GetAbductCommand::toStream(std::ostream
& out
,
2666 OutputLanguage language
) const
2668 Printer::getPrinter(language
)->toStreamCmdGetAbduct(
2672 TypeNode::fromType(d_sygus_grammar
->resolve().getType()));
2675 /* -------------------------------------------------------------------------- */
2676 /* class GetQuantifierEliminationCommand */
2677 /* -------------------------------------------------------------------------- */
2679 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand()
2680 : d_expr(), d_doFull(true)
2683 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
2684 const Expr
& expr
, bool doFull
)
2685 : d_expr(expr
), d_doFull(doFull
)
2689 Expr
GetQuantifierEliminationCommand::getExpr() const { return d_expr
; }
2690 bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull
; }
2691 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
)
2696 smtEngine
->getQuantifierElimination(Node::fromExpr(d_expr
), d_doFull
)
2698 d_commandStatus
= CommandSuccess::instance();
2700 catch (exception
& e
)
2702 d_commandStatus
= new CommandFailure(e
.what());
2706 Expr
GetQuantifierEliminationCommand::getResult() const { return d_result
; }
2707 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
,
2708 uint32_t verbosity
) const
2712 this->Command::printResult(out
, verbosity
);
2716 out
<< d_result
<< endl
;
2720 Command
* GetQuantifierEliminationCommand::exportTo(
2721 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2723 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(
2724 d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
2725 c
->d_result
= d_result
;
2729 Command
* GetQuantifierEliminationCommand::clone() const
2731 GetQuantifierEliminationCommand
* c
=
2732 new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
2733 c
->d_result
= d_result
;
2737 std::string
GetQuantifierEliminationCommand::getCommandName() const
2739 return d_doFull
? "get-qe" : "get-qe-disjunct";
2742 void GetQuantifierEliminationCommand::toStream(std::ostream
& out
,
2746 OutputLanguage language
) const
2748 Printer::getPrinter(language
)->toStreamCmdGetQuantifierElimination(
2749 out
, Node::fromExpr(d_expr
));
2752 /* -------------------------------------------------------------------------- */
2753 /* class GetUnsatAssumptionsCommand */
2754 /* -------------------------------------------------------------------------- */
2756 GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
2758 void GetUnsatAssumptionsCommand::invoke(SmtEngine
* smtEngine
)
2762 std::vector
<Node
> uassumps
= smtEngine
->getUnsatAssumptions();
2764 for (const Node
& n
: uassumps
)
2766 d_result
.push_back(n
.toExpr());
2768 d_commandStatus
= CommandSuccess::instance();
2770 catch (RecoverableModalException
& e
)
2772 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2774 catch (exception
& e
)
2776 d_commandStatus
= new CommandFailure(e
.what());
2780 std::vector
<Expr
> GetUnsatAssumptionsCommand::getResult() const
2785 void GetUnsatAssumptionsCommand::printResult(std::ostream
& out
,
2786 uint32_t verbosity
) const
2790 this->Command::printResult(out
, verbosity
);
2794 container_to_stream(out
, d_result
, "(", ")\n", " ");
2798 Command
* GetUnsatAssumptionsCommand::exportTo(
2799 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2801 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2802 c
->d_result
= d_result
;
2806 Command
* GetUnsatAssumptionsCommand::clone() const
2808 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2809 c
->d_result
= d_result
;
2813 std::string
GetUnsatAssumptionsCommand::getCommandName() const
2815 return "get-unsat-assumptions";
2818 void GetUnsatAssumptionsCommand::toStream(std::ostream
& out
,
2822 OutputLanguage language
) const
2824 Printer::getPrinter(language
)->toStreamCmdGetUnsatAssumptions(out
);
2827 /* -------------------------------------------------------------------------- */
2828 /* class GetUnsatCoreCommand */
2829 /* -------------------------------------------------------------------------- */
2831 GetUnsatCoreCommand::GetUnsatCoreCommand() {}
2832 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
)
2836 d_result
= smtEngine
->getUnsatCore();
2837 d_commandStatus
= CommandSuccess::instance();
2839 catch (RecoverableModalException
& e
)
2841 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2843 catch (exception
& e
)
2845 d_commandStatus
= new CommandFailure(e
.what());
2849 void GetUnsatCoreCommand::printResult(std::ostream
& out
,
2850 uint32_t verbosity
) const
2854 this->Command::printResult(out
, verbosity
);
2858 d_result
.toStream(out
);
2862 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const
2864 // of course, this will be empty if the command hasn't been invoked yet
2868 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
,
2869 ExprManagerMapCollection
& variableMap
)
2871 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2872 c
->d_result
= d_result
;
2876 Command
* GetUnsatCoreCommand::clone() const
2878 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2879 c
->d_result
= d_result
;
2883 std::string
GetUnsatCoreCommand::getCommandName() const
2885 return "get-unsat-core";
2888 void GetUnsatCoreCommand::toStream(std::ostream
& out
,
2892 OutputLanguage language
) const
2894 Printer::getPrinter(language
)->toStreamCmdGetUnsatCore(out
);
2897 /* -------------------------------------------------------------------------- */
2898 /* class GetAssertionsCommand */
2899 /* -------------------------------------------------------------------------- */
2901 GetAssertionsCommand::GetAssertionsCommand() {}
2902 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
2907 const vector
<Expr
> v
= smtEngine
->getAssertions();
2909 copy(v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n"));
2911 d_result
= ss
.str();
2912 d_commandStatus
= CommandSuccess::instance();
2914 catch (exception
& e
)
2916 d_commandStatus
= new CommandFailure(e
.what());
2920 std::string
GetAssertionsCommand::getResult() const { return d_result
; }
2921 void GetAssertionsCommand::printResult(std::ostream
& out
,
2922 uint32_t verbosity
) const
2926 this->Command::printResult(out
, verbosity
);
2934 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
,
2935 ExprManagerMapCollection
& variableMap
)
2937 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2938 c
->d_result
= d_result
;
2942 Command
* GetAssertionsCommand::clone() const
2944 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2945 c
->d_result
= d_result
;
2949 std::string
GetAssertionsCommand::getCommandName() const
2951 return "get-assertions";
2954 void GetAssertionsCommand::toStream(std::ostream
& out
,
2958 OutputLanguage language
) const
2960 Printer::getPrinter(language
)->toStreamCmdGetAssertions(out
);
2963 /* -------------------------------------------------------------------------- */
2964 /* class SetBenchmarkStatusCommand */
2965 /* -------------------------------------------------------------------------- */
2967 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
)
2972 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const
2977 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
)
2983 SExpr status
= SExpr(ss
.str());
2984 smtEngine
->setInfo("status", status
);
2985 d_commandStatus
= CommandSuccess::instance();
2987 catch (exception
& e
)
2989 d_commandStatus
= new CommandFailure(e
.what());
2993 Command
* SetBenchmarkStatusCommand::exportTo(
2994 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2996 return new SetBenchmarkStatusCommand(d_status
);
2999 Command
* SetBenchmarkStatusCommand::clone() const
3001 return new SetBenchmarkStatusCommand(d_status
);
3004 std::string
SetBenchmarkStatusCommand::getCommandName() const
3009 void SetBenchmarkStatusCommand::toStream(std::ostream
& out
,
3013 OutputLanguage language
) const
3015 Printer::getPrinter(language
)->toStreamCmdSetBenchmarkStatus(out
, d_status
);
3018 /* -------------------------------------------------------------------------- */
3019 /* class SetBenchmarkLogicCommand */
3020 /* -------------------------------------------------------------------------- */
3022 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
)
3027 std::string
SetBenchmarkLogicCommand::getLogic() const { return d_logic
; }
3028 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
)
3032 smtEngine
->setLogic(d_logic
);
3033 d_commandStatus
= CommandSuccess::instance();
3035 catch (exception
& e
)
3037 d_commandStatus
= new CommandFailure(e
.what());
3041 Command
* SetBenchmarkLogicCommand::exportTo(
3042 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
3044 return new SetBenchmarkLogicCommand(d_logic
);
3047 Command
* SetBenchmarkLogicCommand::clone() const
3049 return new SetBenchmarkLogicCommand(d_logic
);
3052 std::string
SetBenchmarkLogicCommand::getCommandName() const
3057 void SetBenchmarkLogicCommand::toStream(std::ostream
& out
,
3061 OutputLanguage language
) const
3063 Printer::getPrinter(language
)->toStreamCmdSetBenchmarkLogic(out
, d_logic
);
3066 /* -------------------------------------------------------------------------- */
3067 /* class SetInfoCommand */
3068 /* -------------------------------------------------------------------------- */
3070 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
)
3071 : d_flag(flag
), d_sexpr(sexpr
)
3075 std::string
SetInfoCommand::getFlag() const { return d_flag
; }
3076 SExpr
SetInfoCommand::getSExpr() const { return d_sexpr
; }
3077 void SetInfoCommand::invoke(SmtEngine
* smtEngine
)
3081 smtEngine
->setInfo(d_flag
, d_sexpr
);
3082 d_commandStatus
= CommandSuccess::instance();
3084 catch (UnrecognizedOptionException
&)
3086 // As per SMT-LIB spec, silently accept unknown set-info keys
3087 d_commandStatus
= CommandSuccess::instance();
3089 catch (exception
& e
)
3091 d_commandStatus
= new CommandFailure(e
.what());
3095 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
,
3096 ExprManagerMapCollection
& variableMap
)
3098 return new SetInfoCommand(d_flag
, d_sexpr
);
3101 Command
* SetInfoCommand::clone() const
3103 return new SetInfoCommand(d_flag
, d_sexpr
);
3106 std::string
SetInfoCommand::getCommandName() const { return "set-info"; }
3108 void SetInfoCommand::toStream(std::ostream
& out
,
3112 OutputLanguage language
) const
3114 Printer::getPrinter(language
)->toStreamCmdSetInfo(out
, d_flag
, d_sexpr
);
3117 /* -------------------------------------------------------------------------- */
3118 /* class GetInfoCommand */
3119 /* -------------------------------------------------------------------------- */
3121 GetInfoCommand::GetInfoCommand(std::string flag
) : d_flag(flag
) {}
3122 std::string
GetInfoCommand::getFlag() const { return d_flag
; }
3123 void GetInfoCommand::invoke(SmtEngine
* smtEngine
)
3128 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
3129 v
.push_back(smtEngine
->getInfo(d_flag
));
3131 if (d_flag
== "all-options" || d_flag
== "all-statistics")
3133 ss
<< PrettySExprs(true);
3136 d_result
= ss
.str();
3137 d_commandStatus
= CommandSuccess::instance();
3139 catch (UnrecognizedOptionException
&)
3141 d_commandStatus
= new CommandUnsupported();
3143 catch (RecoverableModalException
& e
)
3145 d_commandStatus
= new CommandRecoverableFailure(e
.what());
3147 catch (exception
& e
)
3149 d_commandStatus
= new CommandFailure(e
.what());
3153 std::string
GetInfoCommand::getResult() const { return d_result
; }
3154 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
3158 this->Command::printResult(out
, verbosity
);
3160 else if (d_result
!= "")
3162 out
<< d_result
<< endl
;
3166 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
,
3167 ExprManagerMapCollection
& variableMap
)
3169 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
3170 c
->d_result
= d_result
;
3174 Command
* GetInfoCommand::clone() const
3176 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
3177 c
->d_result
= d_result
;
3181 std::string
GetInfoCommand::getCommandName() const { return "get-info"; }
3183 void GetInfoCommand::toStream(std::ostream
& out
,
3187 OutputLanguage language
) const
3189 Printer::getPrinter(language
)->toStreamCmdGetInfo(out
, d_flag
);
3192 /* -------------------------------------------------------------------------- */
3193 /* class SetOptionCommand */
3194 /* -------------------------------------------------------------------------- */
3196 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
)
3197 : d_flag(flag
), d_sexpr(sexpr
)
3201 std::string
SetOptionCommand::getFlag() const { return d_flag
; }
3202 SExpr
SetOptionCommand::getSExpr() const { return d_sexpr
; }
3203 void SetOptionCommand::invoke(SmtEngine
* smtEngine
)
3207 smtEngine
->setOption(d_flag
, d_sexpr
);
3208 d_commandStatus
= CommandSuccess::instance();
3210 catch (UnrecognizedOptionException
&)
3212 d_commandStatus
= new CommandUnsupported();
3214 catch (exception
& e
)
3216 d_commandStatus
= new CommandFailure(e
.what());
3220 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
,
3221 ExprManagerMapCollection
& variableMap
)
3223 return new SetOptionCommand(d_flag
, d_sexpr
);
3226 Command
* SetOptionCommand::clone() const
3228 return new SetOptionCommand(d_flag
, d_sexpr
);
3231 std::string
SetOptionCommand::getCommandName() const { return "set-option"; }
3233 void SetOptionCommand::toStream(std::ostream
& out
,
3237 OutputLanguage language
) const
3239 Printer::getPrinter(language
)->toStreamCmdSetOption(out
, d_flag
, d_sexpr
);
3242 /* -------------------------------------------------------------------------- */
3243 /* class GetOptionCommand */
3244 /* -------------------------------------------------------------------------- */
3246 GetOptionCommand::GetOptionCommand(std::string flag
) : d_flag(flag
) {}
3247 std::string
GetOptionCommand::getFlag() const { return d_flag
; }
3248 void GetOptionCommand::invoke(SmtEngine
* smtEngine
)
3252 SExpr res
= smtEngine
->getOption(d_flag
);
3253 d_result
= res
.toString();
3254 d_commandStatus
= CommandSuccess::instance();
3256 catch (UnrecognizedOptionException
&)
3258 d_commandStatus
= new CommandUnsupported();
3260 catch (exception
& e
)
3262 d_commandStatus
= new CommandFailure(e
.what());
3266 std::string
GetOptionCommand::getResult() const { return d_result
; }
3267 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
3271 this->Command::printResult(out
, verbosity
);
3273 else if (d_result
!= "")
3275 out
<< d_result
<< endl
;
3279 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
,
3280 ExprManagerMapCollection
& variableMap
)
3282 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
3283 c
->d_result
= d_result
;
3287 Command
* GetOptionCommand::clone() const
3289 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
3290 c
->d_result
= d_result
;
3294 std::string
GetOptionCommand::getCommandName() const { return "get-option"; }
3296 void GetOptionCommand::toStream(std::ostream
& out
,
3300 OutputLanguage language
) const
3302 Printer::getPrinter(language
)->toStreamCmdGetOption(out
, d_flag
);
3305 /* -------------------------------------------------------------------------- */
3306 /* class SetExpressionNameCommand */
3307 /* -------------------------------------------------------------------------- */
3309 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
)
3310 : d_expr(expr
), d_name(name
)
3314 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
)
3316 smtEngine
->setExpressionName(d_expr
, d_name
);
3317 d_commandStatus
= CommandSuccess::instance();
3320 Command
* SetExpressionNameCommand::exportTo(
3321 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
3323 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(
3324 d_expr
.exportTo(exprManager
, variableMap
), d_name
);
3328 Command
* SetExpressionNameCommand::clone() const
3330 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
3334 std::string
SetExpressionNameCommand::getCommandName() const
3336 return "set-expr-name";
3339 void SetExpressionNameCommand::toStream(std::ostream
& out
,
3343 OutputLanguage language
) const
3345 Printer::getPrinter(language
)->toStreamCmdSetExpressionName(
3346 out
, Node::fromExpr(d_expr
), d_name
);
3349 /* -------------------------------------------------------------------------- */
3350 /* class DatatypeDeclarationCommand */
3351 /* -------------------------------------------------------------------------- */
3353 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const Type
& datatype
)
3356 d_datatypes
.push_back(datatype
);
3359 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
3360 const std::vector
<Type
>& datatypes
)
3361 : d_datatypes(datatypes
)
3365 const std::vector
<Type
>& DatatypeDeclarationCommand::getDatatypes() const
3370 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
)
3372 d_commandStatus
= CommandSuccess::instance();
3375 Command
* DatatypeDeclarationCommand::exportTo(
3376 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
3378 throw ExportUnsupportedException(
3379 "export of DatatypeDeclarationCommand unsupported");
3382 Command
* DatatypeDeclarationCommand::clone() const
3384 return new DatatypeDeclarationCommand(d_datatypes
);
3387 std::string
DatatypeDeclarationCommand::getCommandName() const
3389 return "declare-datatypes";
3392 void DatatypeDeclarationCommand::toStream(std::ostream
& out
,
3396 OutputLanguage language
) const
3398 Printer::getPrinter(language
)->toStreamCmdDatatypeDeclaration(
3399 out
, typeVectorToTypeNodes(d_datatypes
));