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/cvc4_assert.h"
27 #include "base/output.h"
28 #include "expr/expr_iomanip.h"
29 #include "expr/node.h"
30 #include "options/options.h"
31 #include "options/smt_options.h"
32 #include "printer/printer.h"
34 #include "smt/model.h"
35 #include "smt/smt_engine.h"
36 #include "smt/smt_engine_scope.h"
37 #include "util/sexpr.h"
38 #include "util/utility.h"
46 std::vector
<Expr
> ExportTo(ExprManager
* exprManager
,
47 ExprManagerMapCollection
& variableMap
,
48 const std::vector
<Expr
>& exprs
)
50 std::vector
<Expr
> exported
;
51 exported
.reserve(exprs
.size());
52 for (const Expr
& expr
: exprs
)
54 exported
.push_back(expr
.exportTo(exprManager
, variableMap
));
61 const int CommandPrintSuccess::s_iosIndex
= std::ios_base::xalloc();
62 const CommandSuccess
* CommandSuccess::s_instance
= new CommandSuccess();
63 const CommandInterrupted
* CommandInterrupted::s_instance
=
64 new CommandInterrupted();
66 std::ostream
& operator<<(std::ostream
& out
, const Command
& c
)
69 Node::setdepth::getDepth(out
),
70 Node::printtypes::getPrintTypes(out
),
71 Node::dag::getDag(out
),
72 Node::setlanguage::getLanguage(out
));
76 ostream
& operator<<(ostream
& out
, const Command
* c
)
89 std::ostream
& operator<<(std::ostream
& out
, const CommandStatus
& s
)
91 s
.toStream(out
, Node::setlanguage::getLanguage(out
));
95 ostream
& operator<<(ostream
& out
, const CommandStatus
* s
)
109 /* output stream insertion operator for benchmark statuses */
110 std::ostream
& operator<<(std::ostream
& out
, BenchmarkStatus status
)
114 case SMT_SATISFIABLE
: return out
<< "sat";
116 case SMT_UNSATISFIABLE
: return out
<< "unsat";
118 case SMT_UNKNOWN
: return out
<< "unknown";
120 default: return out
<< "BenchmarkStatus::[UNKNOWNSTATUS!]";
124 /* -------------------------------------------------------------------------- */
125 /* class CommandPrintSuccess */
126 /* -------------------------------------------------------------------------- */
128 void CommandPrintSuccess::applyPrintSuccess(std::ostream
& out
)
130 out
.iword(s_iosIndex
) = d_printSuccess
;
133 bool CommandPrintSuccess::getPrintSuccess(std::ostream
& out
)
135 return out
.iword(s_iosIndex
);
138 void CommandPrintSuccess::setPrintSuccess(std::ostream
& out
, bool printSuccess
)
140 out
.iword(s_iosIndex
) = printSuccess
;
143 std::ostream
& operator<<(std::ostream
& out
, CommandPrintSuccess cps
)
145 cps
.applyPrintSuccess(out
);
149 /* -------------------------------------------------------------------------- */
151 /* -------------------------------------------------------------------------- */
153 Command::Command() : d_commandStatus(NULL
), d_muted(false) {}
154 Command::Command(const Command
& cmd
)
157 (cmd
.d_commandStatus
== NULL
) ? NULL
: &cmd
.d_commandStatus
->clone();
158 d_muted
= cmd
.d_muted
;
163 if (d_commandStatus
!= NULL
&& d_commandStatus
!= CommandSuccess::instance())
165 delete d_commandStatus
;
169 bool Command::ok() const
171 // either we haven't run the command yet, or it ran successfully
172 return d_commandStatus
== NULL
173 || dynamic_cast<const CommandSuccess
*>(d_commandStatus
) != NULL
;
176 bool Command::fail() const
178 return d_commandStatus
!= NULL
179 && dynamic_cast<const CommandFailure
*>(d_commandStatus
) != NULL
;
182 bool Command::interrupted() const
184 return d_commandStatus
!= NULL
185 && dynamic_cast<const CommandInterrupted
*>(d_commandStatus
) != NULL
;
188 void Command::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
191 if (!(isMuted() && ok()))
194 smtEngine
->getOption("command-verbosity:" + getCommandName())
200 std::string
Command::toString() const
202 std::stringstream ss
;
207 void Command::toStream(std::ostream
& out
,
211 OutputLanguage language
) const
213 Printer::getPrinter(language
)->toStream(out
, this, toDepth
, types
, dag
);
216 void CommandStatus::toStream(std::ostream
& out
, OutputLanguage language
) const
218 Printer::getPrinter(language
)->toStream(out
, this);
221 void Command::printResult(std::ostream
& out
, uint32_t verbosity
) const
223 if (d_commandStatus
!= NULL
)
225 if ((!ok() && verbosity
>= 1) || verbosity
>= 2)
227 out
<< *d_commandStatus
;
232 /* -------------------------------------------------------------------------- */
233 /* class EmptyCommand */
234 /* -------------------------------------------------------------------------- */
236 EmptyCommand::EmptyCommand(std::string name
) : d_name(name
) {}
237 std::string
EmptyCommand::getName() const { return d_name
; }
238 void EmptyCommand::invoke(SmtEngine
* smtEngine
)
240 /* empty commands have no implementation */
241 d_commandStatus
= CommandSuccess::instance();
244 Command
* EmptyCommand::exportTo(ExprManager
* exprManager
,
245 ExprManagerMapCollection
& variableMap
)
247 return new EmptyCommand(d_name
);
250 Command
* EmptyCommand::clone() const { return new EmptyCommand(d_name
); }
251 std::string
EmptyCommand::getCommandName() const { return "empty"; }
253 /* -------------------------------------------------------------------------- */
254 /* class EchoCommand */
255 /* -------------------------------------------------------------------------- */
257 EchoCommand::EchoCommand(std::string output
) : d_output(output
) {}
258 std::string
EchoCommand::getOutput() const { return d_output
; }
259 void EchoCommand::invoke(SmtEngine
* smtEngine
)
261 /* we don't have an output stream here, nothing to do */
262 d_commandStatus
= CommandSuccess::instance();
265 void EchoCommand::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
267 out
<< d_output
<< std::endl
;
268 d_commandStatus
= CommandSuccess::instance();
270 smtEngine
->getOption("command-verbosity:" + getCommandName())
275 Command
* EchoCommand::exportTo(ExprManager
* exprManager
,
276 ExprManagerMapCollection
& variableMap
)
278 return new EchoCommand(d_output
);
281 Command
* EchoCommand::clone() const { return new EchoCommand(d_output
); }
282 std::string
EchoCommand::getCommandName() const { return "echo"; }
284 /* -------------------------------------------------------------------------- */
285 /* class AssertCommand */
286 /* -------------------------------------------------------------------------- */
288 AssertCommand::AssertCommand(const Expr
& e
, bool inUnsatCore
)
289 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
293 Expr
AssertCommand::getExpr() const { return d_expr
; }
294 void AssertCommand::invoke(SmtEngine
* smtEngine
)
298 smtEngine
->assertFormula(d_expr
, d_inUnsatCore
);
299 d_commandStatus
= CommandSuccess::instance();
301 catch (UnsafeInterruptException
& e
)
303 d_commandStatus
= new CommandInterrupted();
307 d_commandStatus
= new CommandFailure(e
.what());
311 Command
* AssertCommand::exportTo(ExprManager
* exprManager
,
312 ExprManagerMapCollection
& variableMap
)
314 return new AssertCommand(d_expr
.exportTo(exprManager
, variableMap
),
318 Command
* AssertCommand::clone() const
320 return new AssertCommand(d_expr
, d_inUnsatCore
);
323 std::string
AssertCommand::getCommandName() const { return "assert"; }
325 /* -------------------------------------------------------------------------- */
326 /* class PushCommand */
327 /* -------------------------------------------------------------------------- */
329 void PushCommand::invoke(SmtEngine
* smtEngine
)
334 d_commandStatus
= CommandSuccess::instance();
336 catch (UnsafeInterruptException
& e
)
338 d_commandStatus
= new CommandInterrupted();
342 d_commandStatus
= new CommandFailure(e
.what());
346 Command
* PushCommand::exportTo(ExprManager
* exprManager
,
347 ExprManagerMapCollection
& variableMap
)
349 return new PushCommand();
352 Command
* PushCommand::clone() const { return new PushCommand(); }
353 std::string
PushCommand::getCommandName() const { return "push"; }
355 /* -------------------------------------------------------------------------- */
356 /* class PopCommand */
357 /* -------------------------------------------------------------------------- */
359 void PopCommand::invoke(SmtEngine
* smtEngine
)
364 d_commandStatus
= CommandSuccess::instance();
366 catch (UnsafeInterruptException
& e
)
368 d_commandStatus
= new CommandInterrupted();
372 d_commandStatus
= new CommandFailure(e
.what());
376 Command
* PopCommand::exportTo(ExprManager
* exprManager
,
377 ExprManagerMapCollection
& variableMap
)
379 return new PopCommand();
382 Command
* PopCommand::clone() const { return new PopCommand(); }
383 std::string
PopCommand::getCommandName() const { return "pop"; }
385 /* -------------------------------------------------------------------------- */
386 /* class CheckSatCommand */
387 /* -------------------------------------------------------------------------- */
389 CheckSatCommand::CheckSatCommand() : d_expr() {}
391 CheckSatCommand::CheckSatCommand(const Expr
& expr
) : d_expr(expr
) {}
393 Expr
CheckSatCommand::getExpr() const { return d_expr
; }
394 void CheckSatCommand::invoke(SmtEngine
* smtEngine
)
398 d_result
= smtEngine
->checkSat(d_expr
);
399 d_commandStatus
= CommandSuccess::instance();
403 d_commandStatus
= new CommandFailure(e
.what());
407 Result
CheckSatCommand::getResult() const { return d_result
; }
408 void CheckSatCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
412 this->Command::printResult(out
, verbosity
);
416 out
<< d_result
<< endl
;
420 Command
* CheckSatCommand::exportTo(ExprManager
* exprManager
,
421 ExprManagerMapCollection
& variableMap
)
424 new CheckSatCommand(d_expr
.exportTo(exprManager
, variableMap
));
425 c
->d_result
= d_result
;
429 Command
* CheckSatCommand::clone() const
431 CheckSatCommand
* c
= new CheckSatCommand(d_expr
);
432 c
->d_result
= d_result
;
436 std::string
CheckSatCommand::getCommandName() const { return "check-sat"; }
438 /* -------------------------------------------------------------------------- */
439 /* class CheckSatAssumingCommand */
440 /* -------------------------------------------------------------------------- */
442 CheckSatAssumingCommand::CheckSatAssumingCommand(Expr term
) : d_terms({term
}) {}
444 CheckSatAssumingCommand::CheckSatAssumingCommand(const std::vector
<Expr
>& terms
)
449 const std::vector
<Expr
>& CheckSatAssumingCommand::getTerms() const
454 void CheckSatAssumingCommand::invoke(SmtEngine
* smtEngine
)
458 d_result
= smtEngine
->checkSat(d_terms
);
459 d_commandStatus
= CommandSuccess::instance();
463 d_commandStatus
= new CommandFailure(e
.what());
467 Result
CheckSatAssumingCommand::getResult() const
472 void CheckSatAssumingCommand::printResult(std::ostream
& out
,
473 uint32_t verbosity
) const
477 this->Command::printResult(out
, verbosity
);
481 out
<< d_result
<< endl
;
485 Command
* CheckSatAssumingCommand::exportTo(
486 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
488 vector
<Expr
> exportedTerms
;
489 for (const Expr
& e
: d_terms
)
491 exportedTerms
.push_back(e
.exportTo(exprManager
, variableMap
));
493 CheckSatAssumingCommand
* c
= new CheckSatAssumingCommand(exportedTerms
);
494 c
->d_result
= d_result
;
498 Command
* CheckSatAssumingCommand::clone() const
500 CheckSatAssumingCommand
* c
= new CheckSatAssumingCommand(d_terms
);
501 c
->d_result
= d_result
;
505 std::string
CheckSatAssumingCommand::getCommandName() const
507 return "check-sat-assuming";
510 /* -------------------------------------------------------------------------- */
511 /* class QueryCommand */
512 /* -------------------------------------------------------------------------- */
514 QueryCommand::QueryCommand(const Expr
& e
, bool inUnsatCore
)
515 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
519 Expr
QueryCommand::getExpr() const { return d_expr
; }
520 void QueryCommand::invoke(SmtEngine
* smtEngine
)
524 d_result
= smtEngine
->query(d_expr
);
525 d_commandStatus
= CommandSuccess::instance();
529 d_commandStatus
= new CommandFailure(e
.what());
533 Result
QueryCommand::getResult() const { return d_result
; }
534 void QueryCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
538 this->Command::printResult(out
, verbosity
);
542 out
<< d_result
<< endl
;
546 Command
* QueryCommand::exportTo(ExprManager
* exprManager
,
547 ExprManagerMapCollection
& variableMap
)
549 QueryCommand
* c
= new QueryCommand(d_expr
.exportTo(exprManager
, variableMap
),
551 c
->d_result
= d_result
;
555 Command
* QueryCommand::clone() const
557 QueryCommand
* c
= new QueryCommand(d_expr
, d_inUnsatCore
);
558 c
->d_result
= d_result
;
562 std::string
QueryCommand::getCommandName() const { return "query"; }
564 /* -------------------------------------------------------------------------- */
565 /* class DeclareSygusVarCommand */
566 /* -------------------------------------------------------------------------- */
568 DeclareSygusVarCommand::DeclareSygusVarCommand(const std::string
& id
,
571 : DeclarationDefinitionCommand(id
), d_var(var
), d_type(t
)
575 Expr
DeclareSygusVarCommand::getVar() const { return d_var
; }
576 Type
DeclareSygusVarCommand::getType() const { return d_type
; }
578 void DeclareSygusVarCommand::invoke(SmtEngine
* smtEngine
)
582 smtEngine
->declareSygusVar(d_symbol
, d_var
, d_type
);
583 d_commandStatus
= CommandSuccess::instance();
587 d_commandStatus
= new CommandFailure(e
.what());
591 Command
* DeclareSygusVarCommand::exportTo(ExprManager
* exprManager
,
592 ExprManagerMapCollection
& variableMap
)
594 return new DeclareSygusVarCommand(d_symbol
,
595 d_var
.exportTo(exprManager
, variableMap
),
596 d_type
.exportTo(exprManager
, variableMap
));
599 Command
* DeclareSygusVarCommand::clone() const
601 return new DeclareSygusVarCommand(d_symbol
, d_var
, d_type
);
604 std::string
DeclareSygusVarCommand::getCommandName() const
606 return "declare-var";
609 /* -------------------------------------------------------------------------- */
610 /* class DeclareSygusPrimedVarCommand */
611 /* -------------------------------------------------------------------------- */
613 DeclareSygusPrimedVarCommand::DeclareSygusPrimedVarCommand(
614 const std::string
& id
, Type t
)
615 : DeclarationDefinitionCommand(id
), d_type(t
)
619 Type
DeclareSygusPrimedVarCommand::getType() const { return d_type
; }
621 void DeclareSygusPrimedVarCommand::invoke(SmtEngine
* smtEngine
)
625 smtEngine
->declareSygusPrimedVar(d_symbol
, d_type
);
626 d_commandStatus
= CommandSuccess::instance();
630 d_commandStatus
= new CommandFailure(e
.what());
634 Command
* DeclareSygusPrimedVarCommand::exportTo(
635 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
637 return new DeclareSygusPrimedVarCommand(
638 d_symbol
, d_type
.exportTo(exprManager
, variableMap
));
641 Command
* DeclareSygusPrimedVarCommand::clone() const
643 return new DeclareSygusPrimedVarCommand(d_symbol
, d_type
);
646 std::string
DeclareSygusPrimedVarCommand::getCommandName() const
648 return "declare-primed-var";
651 /* -------------------------------------------------------------------------- */
652 /* class DeclareSygusFunctionCommand */
653 /* -------------------------------------------------------------------------- */
655 DeclareSygusFunctionCommand::DeclareSygusFunctionCommand(const std::string
& id
,
658 : DeclarationDefinitionCommand(id
), d_func(func
), d_type(t
)
662 Expr
DeclareSygusFunctionCommand::getFunction() const { return d_func
; }
663 Type
DeclareSygusFunctionCommand::getType() const { return d_type
; }
665 void DeclareSygusFunctionCommand::invoke(SmtEngine
* smtEngine
)
669 smtEngine
->declareSygusFunctionVar(d_symbol
, d_func
, d_type
);
670 d_commandStatus
= CommandSuccess::instance();
674 d_commandStatus
= new CommandFailure(e
.what());
678 Command
* DeclareSygusFunctionCommand::exportTo(
679 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
681 return new DeclareSygusFunctionCommand(
683 d_func
.exportTo(exprManager
, variableMap
),
684 d_type
.exportTo(exprManager
, variableMap
));
687 Command
* DeclareSygusFunctionCommand::clone() const
689 return new DeclareSygusFunctionCommand(d_symbol
, d_func
, d_type
);
692 std::string
DeclareSygusFunctionCommand::getCommandName() const
694 return "declare-fun";
697 /* -------------------------------------------------------------------------- */
698 /* class SynthFunCommand */
699 /* -------------------------------------------------------------------------- */
701 SynthFunCommand::SynthFunCommand(const std::string
& id
,
705 const std::vector
<Expr
>& vars
)
706 : DeclarationDefinitionCommand(id
),
708 d_sygusType(sygusType
),
714 SynthFunCommand::SynthFunCommand(const std::string
& id
,
718 : SynthFunCommand(id
, func
, sygusType
, isInv
, {})
722 Expr
SynthFunCommand::getFunction() const { return d_func
; }
723 const std::vector
<Expr
>& SynthFunCommand::getVars() const { return d_vars
; }
724 Type
SynthFunCommand::getSygusType() const { return d_sygusType
; }
725 bool SynthFunCommand::isInv() const { return d_isInv
; }
727 void SynthFunCommand::invoke(SmtEngine
* smtEngine
)
731 smtEngine
->declareSynthFun(d_symbol
, d_func
, d_sygusType
, d_isInv
, d_vars
);
732 d_commandStatus
= CommandSuccess::instance();
736 d_commandStatus
= new CommandFailure(e
.what());
740 Command
* SynthFunCommand::exportTo(ExprManager
* exprManager
,
741 ExprManagerMapCollection
& variableMap
)
743 return new SynthFunCommand(d_symbol
,
744 d_func
.exportTo(exprManager
, variableMap
),
745 d_sygusType
.exportTo(exprManager
, variableMap
),
749 Command
* SynthFunCommand::clone() const
751 return new SynthFunCommand(d_symbol
, d_func
, d_sygusType
, d_isInv
, d_vars
);
754 std::string
SynthFunCommand::getCommandName() const
756 return d_isInv
? "synth-inv" : "synth-fun";
759 /* -------------------------------------------------------------------------- */
760 /* class SygusConstraintCommand */
761 /* -------------------------------------------------------------------------- */
763 SygusConstraintCommand::SygusConstraintCommand(const Expr
& e
) : d_expr(e
) {}
765 void SygusConstraintCommand::invoke(SmtEngine
* smtEngine
)
769 smtEngine
->assertSygusConstraint(d_expr
);
770 d_commandStatus
= CommandSuccess::instance();
774 d_commandStatus
= new CommandFailure(e
.what());
778 Expr
SygusConstraintCommand::getExpr() const { return d_expr
; }
780 Command
* SygusConstraintCommand::exportTo(ExprManager
* exprManager
,
781 ExprManagerMapCollection
& variableMap
)
783 return new SygusConstraintCommand(d_expr
.exportTo(exprManager
, variableMap
));
786 Command
* SygusConstraintCommand::clone() const
788 return new SygusConstraintCommand(d_expr
);
791 std::string
SygusConstraintCommand::getCommandName() const
796 /* -------------------------------------------------------------------------- */
797 /* class SygusInvConstraintCommand */
798 /* -------------------------------------------------------------------------- */
800 SygusInvConstraintCommand::SygusInvConstraintCommand(
801 const std::vector
<Expr
>& predicates
)
802 : d_predicates(predicates
)
806 SygusInvConstraintCommand::SygusInvConstraintCommand(const Expr
& inv
,
810 : SygusInvConstraintCommand(std::vector
<Expr
>{inv
, pre
, trans
, post
})
814 void SygusInvConstraintCommand::invoke(SmtEngine
* smtEngine
)
818 smtEngine
->assertSygusInvConstraint(
819 d_predicates
[0], d_predicates
[1], d_predicates
[2], d_predicates
[3]);
820 d_commandStatus
= CommandSuccess::instance();
824 d_commandStatus
= new CommandFailure(e
.what());
828 const std::vector
<Expr
>& SygusInvConstraintCommand::getPredicates() const
833 Command
* SygusInvConstraintCommand::exportTo(
834 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
836 return new SygusInvConstraintCommand(d_predicates
);
839 Command
* SygusInvConstraintCommand::clone() const
841 return new SygusInvConstraintCommand(d_predicates
);
844 std::string
SygusInvConstraintCommand::getCommandName() const
846 return "inv-constraint";
849 /* -------------------------------------------------------------------------- */
850 /* class CheckSynthCommand */
851 /* -------------------------------------------------------------------------- */
853 void CheckSynthCommand::invoke(SmtEngine
* smtEngine
)
857 d_result
= smtEngine
->checkSynth();
858 d_commandStatus
= CommandSuccess::instance();
859 smt::SmtScope
scope(smtEngine
);
861 // check whether we should print the status
862 if (d_result
.asSatisfiabilityResult() != Result::UNSAT
863 || options::sygusOut() == SYGUS_SOL_OUT_STATUS_AND_DEF
864 || options::sygusOut() == SYGUS_SOL_OUT_STATUS
)
866 if (options::sygusOut() == SYGUS_SOL_OUT_STANDARD
)
868 d_solution
<< "(fail)" << endl
;
872 d_solution
<< d_result
<< endl
;
875 // check whether we should print the solution
876 if (d_result
.asSatisfiabilityResult() == Result::UNSAT
877 && options::sygusOut() != SYGUS_SOL_OUT_STATUS
)
879 // printing a synthesis solution is a non-constant
880 // method, since it invokes a sophisticated algorithm
881 // (Figure 5 of Reynolds et al. CAV 2015).
882 // Hence, we must call here print solution here,
883 // instead of during printResult.
884 smtEngine
->printSynthSolution(d_solution
);
889 d_commandStatus
= new CommandFailure(e
.what());
893 Result
CheckSynthCommand::getResult() const { return d_result
; }
894 void CheckSynthCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
898 this->Command::printResult(out
, verbosity
);
902 out
<< d_solution
.str();
906 Command
* CheckSynthCommand::exportTo(ExprManager
* exprManager
,
907 ExprManagerMapCollection
& variableMap
)
909 return new CheckSynthCommand();
912 Command
* CheckSynthCommand::clone() const { return new CheckSynthCommand(); }
914 std::string
CheckSynthCommand::getCommandName() const { return "check-synth"; }
916 /* -------------------------------------------------------------------------- */
917 /* class ResetCommand */
918 /* -------------------------------------------------------------------------- */
920 void ResetCommand::invoke(SmtEngine
* smtEngine
)
925 d_commandStatus
= CommandSuccess::instance();
929 d_commandStatus
= new CommandFailure(e
.what());
933 Command
* ResetCommand::exportTo(ExprManager
* exprManager
,
934 ExprManagerMapCollection
& variableMap
)
936 return new ResetCommand();
939 Command
* ResetCommand::clone() const { return new ResetCommand(); }
940 std::string
ResetCommand::getCommandName() const { return "reset"; }
942 /* -------------------------------------------------------------------------- */
943 /* class ResetAssertionsCommand */
944 /* -------------------------------------------------------------------------- */
946 void ResetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
950 smtEngine
->resetAssertions();
951 d_commandStatus
= CommandSuccess::instance();
955 d_commandStatus
= new CommandFailure(e
.what());
959 Command
* ResetAssertionsCommand::exportTo(ExprManager
* exprManager
,
960 ExprManagerMapCollection
& variableMap
)
962 return new ResetAssertionsCommand();
965 Command
* ResetAssertionsCommand::clone() const
967 return new ResetAssertionsCommand();
970 std::string
ResetAssertionsCommand::getCommandName() const
972 return "reset-assertions";
975 /* -------------------------------------------------------------------------- */
976 /* class QuitCommand */
977 /* -------------------------------------------------------------------------- */
979 void QuitCommand::invoke(SmtEngine
* smtEngine
)
981 Dump("benchmark") << *this;
982 d_commandStatus
= CommandSuccess::instance();
985 Command
* QuitCommand::exportTo(ExprManager
* exprManager
,
986 ExprManagerMapCollection
& variableMap
)
988 return new QuitCommand();
991 Command
* QuitCommand::clone() const { return new QuitCommand(); }
992 std::string
QuitCommand::getCommandName() const { return "exit"; }
994 /* -------------------------------------------------------------------------- */
995 /* class CommentCommand */
996 /* -------------------------------------------------------------------------- */
998 CommentCommand::CommentCommand(std::string comment
) : d_comment(comment
) {}
999 std::string
CommentCommand::getComment() const { return d_comment
; }
1000 void CommentCommand::invoke(SmtEngine
* smtEngine
)
1002 Dump("benchmark") << *this;
1003 d_commandStatus
= CommandSuccess::instance();
1006 Command
* CommentCommand::exportTo(ExprManager
* exprManager
,
1007 ExprManagerMapCollection
& variableMap
)
1009 return new CommentCommand(d_comment
);
1012 Command
* CommentCommand::clone() const { return new CommentCommand(d_comment
); }
1013 std::string
CommentCommand::getCommandName() const { return "comment"; }
1015 /* -------------------------------------------------------------------------- */
1016 /* class CommandSequence */
1017 /* -------------------------------------------------------------------------- */
1019 CommandSequence::CommandSequence() : d_index(0) {}
1020 CommandSequence::~CommandSequence()
1022 for (unsigned i
= d_index
; i
< d_commandSequence
.size(); ++i
)
1024 delete d_commandSequence
[i
];
1028 void CommandSequence::addCommand(Command
* cmd
)
1030 d_commandSequence
.push_back(cmd
);
1033 void CommandSequence::clear() { d_commandSequence
.clear(); }
1034 void CommandSequence::invoke(SmtEngine
* smtEngine
)
1036 for (; d_index
< d_commandSequence
.size(); ++d_index
)
1038 d_commandSequence
[d_index
]->invoke(smtEngine
);
1039 if (!d_commandSequence
[d_index
]->ok())
1042 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
1045 delete d_commandSequence
[d_index
];
1048 AlwaysAssert(d_commandStatus
== NULL
);
1049 d_commandStatus
= CommandSuccess::instance();
1052 void CommandSequence::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
1054 for (; d_index
< d_commandSequence
.size(); ++d_index
)
1056 d_commandSequence
[d_index
]->invoke(smtEngine
, out
);
1057 if (!d_commandSequence
[d_index
]->ok())
1060 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
1063 delete d_commandSequence
[d_index
];
1066 AlwaysAssert(d_commandStatus
== NULL
);
1067 d_commandStatus
= CommandSuccess::instance();
1070 Command
* CommandSequence::exportTo(ExprManager
* exprManager
,
1071 ExprManagerMapCollection
& variableMap
)
1073 CommandSequence
* seq
= new CommandSequence();
1074 for (iterator i
= begin(); i
!= end(); ++i
)
1076 Command
* cmd_to_export
= *i
;
1077 Command
* cmd
= cmd_to_export
->exportTo(exprManager
, variableMap
);
1078 seq
->addCommand(cmd
);
1079 Debug("export") << "[export] so far converted: " << seq
<< endl
;
1081 seq
->d_index
= d_index
;
1085 Command
* CommandSequence::clone() const
1087 CommandSequence
* seq
= new CommandSequence();
1088 for (const_iterator i
= begin(); i
!= end(); ++i
)
1090 seq
->addCommand((*i
)->clone());
1092 seq
->d_index
= d_index
;
1096 CommandSequence::const_iterator
CommandSequence::begin() const
1098 return d_commandSequence
.begin();
1101 CommandSequence::const_iterator
CommandSequence::end() const
1103 return d_commandSequence
.end();
1106 CommandSequence::iterator
CommandSequence::begin()
1108 return d_commandSequence
.begin();
1111 CommandSequence::iterator
CommandSequence::end()
1113 return d_commandSequence
.end();
1116 std::string
CommandSequence::getCommandName() const { return "sequence"; }
1118 /* -------------------------------------------------------------------------- */
1119 /* class DeclarationDefinitionCommand */
1120 /* -------------------------------------------------------------------------- */
1122 DeclarationDefinitionCommand::DeclarationDefinitionCommand(
1123 const std::string
& id
)
1128 std::string
DeclarationDefinitionCommand::getSymbol() const { return d_symbol
; }
1130 /* -------------------------------------------------------------------------- */
1131 /* class DeclareFunctionCommand */
1132 /* -------------------------------------------------------------------------- */
1134 DeclareFunctionCommand::DeclareFunctionCommand(const std::string
& id
,
1137 : DeclarationDefinitionCommand(id
),
1140 d_printInModel(true),
1141 d_printInModelSetByUser(false)
1145 Expr
DeclareFunctionCommand::getFunction() const { return d_func
; }
1146 Type
DeclareFunctionCommand::getType() const { return d_type
; }
1147 bool DeclareFunctionCommand::getPrintInModel() const { return d_printInModel
; }
1148 bool DeclareFunctionCommand::getPrintInModelSetByUser() const
1150 return d_printInModelSetByUser
;
1153 void DeclareFunctionCommand::setPrintInModel(bool p
)
1156 d_printInModelSetByUser
= true;
1159 void DeclareFunctionCommand::invoke(SmtEngine
* smtEngine
)
1161 d_commandStatus
= CommandSuccess::instance();
1164 Command
* DeclareFunctionCommand::exportTo(ExprManager
* exprManager
,
1165 ExprManagerMapCollection
& variableMap
)
1167 DeclareFunctionCommand
* dfc
=
1168 new DeclareFunctionCommand(d_symbol
,
1169 d_func
.exportTo(exprManager
, variableMap
),
1170 d_type
.exportTo(exprManager
, variableMap
));
1171 dfc
->d_printInModel
= d_printInModel
;
1172 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
1176 Command
* DeclareFunctionCommand::clone() const
1178 DeclareFunctionCommand
* dfc
=
1179 new DeclareFunctionCommand(d_symbol
, d_func
, d_type
);
1180 dfc
->d_printInModel
= d_printInModel
;
1181 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
1185 std::string
DeclareFunctionCommand::getCommandName() const
1187 return "declare-fun";
1190 /* -------------------------------------------------------------------------- */
1191 /* class DeclareTypeCommand */
1192 /* -------------------------------------------------------------------------- */
1194 DeclareTypeCommand::DeclareTypeCommand(const std::string
& id
,
1197 : DeclarationDefinitionCommand(id
), d_arity(arity
), d_type(t
)
1201 size_t DeclareTypeCommand::getArity() const { return d_arity
; }
1202 Type
DeclareTypeCommand::getType() const { return d_type
; }
1203 void DeclareTypeCommand::invoke(SmtEngine
* smtEngine
)
1205 d_commandStatus
= CommandSuccess::instance();
1208 Command
* DeclareTypeCommand::exportTo(ExprManager
* exprManager
,
1209 ExprManagerMapCollection
& variableMap
)
1211 return new DeclareTypeCommand(
1212 d_symbol
, d_arity
, d_type
.exportTo(exprManager
, variableMap
));
1215 Command
* DeclareTypeCommand::clone() const
1217 return new DeclareTypeCommand(d_symbol
, d_arity
, d_type
);
1220 std::string
DeclareTypeCommand::getCommandName() const
1222 return "declare-sort";
1225 /* -------------------------------------------------------------------------- */
1226 /* class DefineTypeCommand */
1227 /* -------------------------------------------------------------------------- */
1229 DefineTypeCommand::DefineTypeCommand(const std::string
& id
, Type t
)
1230 : DeclarationDefinitionCommand(id
), d_params(), d_type(t
)
1234 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
1235 const std::vector
<Type
>& params
,
1237 : DeclarationDefinitionCommand(id
), d_params(params
), d_type(t
)
1241 const std::vector
<Type
>& DefineTypeCommand::getParameters() const
1246 Type
DefineTypeCommand::getType() const { return d_type
; }
1247 void DefineTypeCommand::invoke(SmtEngine
* smtEngine
)
1249 d_commandStatus
= CommandSuccess::instance();
1252 Command
* DefineTypeCommand::exportTo(ExprManager
* exprManager
,
1253 ExprManagerMapCollection
& variableMap
)
1255 vector
<Type
> params
;
1256 transform(d_params
.begin(),
1258 back_inserter(params
),
1259 ExportTransformer(exprManager
, variableMap
));
1260 Type type
= d_type
.exportTo(exprManager
, variableMap
);
1261 return new DefineTypeCommand(d_symbol
, params
, type
);
1264 Command
* DefineTypeCommand::clone() const
1266 return new DefineTypeCommand(d_symbol
, d_params
, d_type
);
1269 std::string
DefineTypeCommand::getCommandName() const { return "define-sort"; }
1271 /* -------------------------------------------------------------------------- */
1272 /* class DefineFunctionCommand */
1273 /* -------------------------------------------------------------------------- */
1275 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1278 : DeclarationDefinitionCommand(id
),
1285 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1287 const std::vector
<Expr
>& formals
,
1289 : DeclarationDefinitionCommand(id
),
1296 Expr
DefineFunctionCommand::getFunction() const { return d_func
; }
1297 const std::vector
<Expr
>& DefineFunctionCommand::getFormals() const
1302 Expr
DefineFunctionCommand::getFormula() const { return d_formula
; }
1303 void DefineFunctionCommand::invoke(SmtEngine
* smtEngine
)
1307 if (!d_func
.isNull())
1309 smtEngine
->defineFunction(d_func
, d_formals
, d_formula
);
1311 d_commandStatus
= CommandSuccess::instance();
1313 catch (exception
& e
)
1315 d_commandStatus
= new CommandFailure(e
.what());
1319 Command
* DefineFunctionCommand::exportTo(ExprManager
* exprManager
,
1320 ExprManagerMapCollection
& variableMap
)
1322 Expr func
= d_func
.exportTo(
1323 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1324 vector
<Expr
> formals
;
1325 transform(d_formals
.begin(),
1327 back_inserter(formals
),
1328 ExportTransformer(exprManager
, variableMap
));
1329 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1330 return new DefineFunctionCommand(d_symbol
, func
, formals
, formula
);
1333 Command
* DefineFunctionCommand::clone() const
1335 return new DefineFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1338 std::string
DefineFunctionCommand::getCommandName() const
1340 return "define-fun";
1343 /* -------------------------------------------------------------------------- */
1344 /* class DefineNamedFunctionCommand */
1345 /* -------------------------------------------------------------------------- */
1347 DefineNamedFunctionCommand::DefineNamedFunctionCommand(
1348 const std::string
& id
,
1350 const std::vector
<Expr
>& formals
,
1352 : DefineFunctionCommand(id
, func
, formals
, formula
)
1356 void DefineNamedFunctionCommand::invoke(SmtEngine
* smtEngine
)
1358 this->DefineFunctionCommand::invoke(smtEngine
);
1359 if (!d_func
.isNull() && d_func
.getType().isBoolean())
1361 smtEngine
->addToAssignment(d_func
);
1363 d_commandStatus
= CommandSuccess::instance();
1366 Command
* DefineNamedFunctionCommand::exportTo(
1367 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1369 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
1370 vector
<Expr
> formals
;
1371 transform(d_formals
.begin(),
1373 back_inserter(formals
),
1374 ExportTransformer(exprManager
, variableMap
));
1375 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1376 return new DefineNamedFunctionCommand(d_symbol
, func
, formals
, formula
);
1379 Command
* DefineNamedFunctionCommand::clone() const
1381 return new DefineNamedFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1384 /* -------------------------------------------------------------------------- */
1385 /* class DefineFunctionRecCommand */
1386 /* -------------------------------------------------------------------------- */
1388 DefineFunctionRecCommand::DefineFunctionRecCommand(
1389 Expr func
, const std::vector
<Expr
>& formals
, Expr formula
)
1391 d_funcs
.push_back(func
);
1392 d_formals
.push_back(formals
);
1393 d_formulas
.push_back(formula
);
1396 DefineFunctionRecCommand::DefineFunctionRecCommand(
1397 const std::vector
<Expr
>& funcs
,
1398 const std::vector
<std::vector
<Expr
>>& formals
,
1399 const std::vector
<Expr
>& formulas
)
1401 d_funcs
.insert(d_funcs
.end(), funcs
.begin(), funcs
.end());
1402 d_formals
.insert(d_formals
.end(), formals
.begin(), formals
.end());
1403 d_formulas
.insert(d_formulas
.end(), formulas
.begin(), formulas
.end());
1406 const std::vector
<Expr
>& DefineFunctionRecCommand::getFunctions() const
1411 const std::vector
<std::vector
<Expr
>>& DefineFunctionRecCommand::getFormals()
1417 const std::vector
<Expr
>& DefineFunctionRecCommand::getFormulas() const
1422 void DefineFunctionRecCommand::invoke(SmtEngine
* smtEngine
)
1426 smtEngine
->defineFunctionsRec(d_funcs
, d_formals
, d_formulas
);
1427 d_commandStatus
= CommandSuccess::instance();
1429 catch (exception
& e
)
1431 d_commandStatus
= new CommandFailure(e
.what());
1435 Command
* DefineFunctionRecCommand::exportTo(
1436 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1438 std::vector
<Expr
> funcs
;
1439 for (unsigned i
= 0, size
= d_funcs
.size(); i
< size
; i
++)
1441 Expr func
= d_funcs
[i
].exportTo(
1442 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1443 funcs
.push_back(func
);
1445 std::vector
<std::vector
<Expr
>> formals
;
1446 for (unsigned i
= 0, size
= d_formals
.size(); i
< size
; i
++)
1448 std::vector
<Expr
> formals_c
;
1449 transform(d_formals
[i
].begin(),
1451 back_inserter(formals_c
),
1452 ExportTransformer(exprManager
, variableMap
));
1453 formals
.push_back(formals_c
);
1455 std::vector
<Expr
> formulas
;
1456 for (unsigned i
= 0, size
= d_formulas
.size(); i
< size
; i
++)
1458 Expr formula
= d_formulas
[i
].exportTo(exprManager
, variableMap
);
1459 formulas
.push_back(formula
);
1461 return new DefineFunctionRecCommand(funcs
, formals
, formulas
);
1464 Command
* DefineFunctionRecCommand::clone() const
1466 return new DefineFunctionRecCommand(d_funcs
, d_formals
, d_formulas
);
1469 std::string
DefineFunctionRecCommand::getCommandName() const
1471 return "define-fun-rec";
1474 /* -------------------------------------------------------------------------- */
1475 /* class SetUserAttribute */
1476 /* -------------------------------------------------------------------------- */
1478 SetUserAttributeCommand::SetUserAttributeCommand(
1479 const std::string
& attr
,
1481 const std::vector
<Expr
>& expr_values
,
1482 const std::string
& str_value
)
1485 d_expr_values(expr_values
),
1486 d_str_value(str_value
)
1490 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1492 : SetUserAttributeCommand(attr
, expr
, {}, "")
1496 SetUserAttributeCommand::SetUserAttributeCommand(
1497 const std::string
& attr
, Expr expr
, const std::vector
<Expr
>& values
)
1498 : SetUserAttributeCommand(attr
, expr
, values
, "")
1502 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1504 const std::string
& value
)
1505 : SetUserAttributeCommand(attr
, expr
, {}, value
)
1509 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
)
1513 if (!d_expr
.isNull())
1515 smtEngine
->setUserAttribute(d_attr
, d_expr
, d_expr_values
, d_str_value
);
1517 d_commandStatus
= CommandSuccess::instance();
1519 catch (exception
& e
)
1521 d_commandStatus
= new CommandFailure(e
.what());
1525 Command
* SetUserAttributeCommand::exportTo(
1526 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1528 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
1529 return new SetUserAttributeCommand(d_attr
, expr
, d_expr_values
, d_str_value
);
1532 Command
* SetUserAttributeCommand::clone() const
1534 return new SetUserAttributeCommand(
1535 d_attr
, d_expr
, d_expr_values
, d_str_value
);
1538 std::string
SetUserAttributeCommand::getCommandName() const
1540 return "set-user-attribute";
1543 /* -------------------------------------------------------------------------- */
1544 /* class SimplifyCommand */
1545 /* -------------------------------------------------------------------------- */
1547 SimplifyCommand::SimplifyCommand(Expr term
) : d_term(term
) {}
1548 Expr
SimplifyCommand::getTerm() const { return d_term
; }
1549 void SimplifyCommand::invoke(SmtEngine
* smtEngine
)
1553 d_result
= smtEngine
->simplify(d_term
);
1554 d_commandStatus
= CommandSuccess::instance();
1556 catch (UnsafeInterruptException
& e
)
1558 d_commandStatus
= new CommandInterrupted();
1560 catch (exception
& e
)
1562 d_commandStatus
= new CommandFailure(e
.what());
1566 Expr
SimplifyCommand::getResult() const { return d_result
; }
1567 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1571 this->Command::printResult(out
, verbosity
);
1575 out
<< d_result
<< endl
;
1579 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
,
1580 ExprManagerMapCollection
& variableMap
)
1582 SimplifyCommand
* c
=
1583 new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
1584 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1588 Command
* SimplifyCommand::clone() const
1590 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
1591 c
->d_result
= d_result
;
1595 std::string
SimplifyCommand::getCommandName() const { return "simplify"; }
1597 /* -------------------------------------------------------------------------- */
1598 /* class ExpandDefinitionsCommand */
1599 /* -------------------------------------------------------------------------- */
1601 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) : d_term(term
) {}
1602 Expr
ExpandDefinitionsCommand::getTerm() const { return d_term
; }
1603 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
)
1605 d_result
= smtEngine
->expandDefinitions(d_term
);
1606 d_commandStatus
= CommandSuccess::instance();
1609 Expr
ExpandDefinitionsCommand::getResult() const { return d_result
; }
1610 void ExpandDefinitionsCommand::printResult(std::ostream
& out
,
1611 uint32_t verbosity
) const
1615 this->Command::printResult(out
, verbosity
);
1619 out
<< d_result
<< endl
;
1623 Command
* ExpandDefinitionsCommand::exportTo(
1624 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1626 ExpandDefinitionsCommand
* c
=
1627 new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
1628 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1632 Command
* ExpandDefinitionsCommand::clone() const
1634 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
1635 c
->d_result
= d_result
;
1639 std::string
ExpandDefinitionsCommand::getCommandName() const
1641 return "expand-definitions";
1644 /* -------------------------------------------------------------------------- */
1645 /* class GetValueCommand */
1646 /* -------------------------------------------------------------------------- */
1648 GetValueCommand::GetValueCommand(Expr term
) : d_terms()
1650 d_terms
.push_back(term
);
1653 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
)
1656 PrettyCheckArgument(
1657 terms
.size() >= 1, terms
, "cannot get-value of an empty set of terms");
1660 const std::vector
<Expr
>& GetValueCommand::getTerms() const { return d_terms
; }
1661 void GetValueCommand::invoke(SmtEngine
* smtEngine
)
1665 vector
<Expr
> result
;
1666 ExprManager
* em
= smtEngine
->getExprManager();
1667 NodeManager
* nm
= NodeManager::fromExprManager(em
);
1668 for (const Expr
& e
: d_terms
)
1670 Assert(nm
== NodeManager::fromExprManager(e
.getExprManager()));
1671 smt::SmtScope
scope(smtEngine
);
1672 Node request
= Node::fromExpr(
1673 options::expandDefinitions() ? smtEngine
->expandDefinitions(e
) : e
);
1674 Node value
= Node::fromExpr(smtEngine
->getValue(e
));
1675 if (value
.getType().isInteger() && request
.getType() == nm
->realType())
1677 // Need to wrap in division-by-one so that output printers know this
1678 // is an integer-looking constant that really should be output as
1679 // a rational. Necessary for SMT-LIB standards compliance.
1680 value
= nm
->mkNode(kind::DIVISION
, value
, nm
->mkConst(Rational(1)));
1682 result
.push_back(nm
->mkNode(kind::SEXPR
, request
, value
).toExpr());
1684 d_result
= em
->mkExpr(kind::SEXPR
, result
);
1685 d_commandStatus
= CommandSuccess::instance();
1687 catch (RecoverableModalException
& e
)
1689 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1691 catch (UnsafeInterruptException
& e
)
1693 d_commandStatus
= new CommandInterrupted();
1695 catch (exception
& e
)
1697 d_commandStatus
= new CommandFailure(e
.what());
1701 Expr
GetValueCommand::getResult() const { return d_result
; }
1702 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1706 this->Command::printResult(out
, verbosity
);
1710 expr::ExprDag::Scope
scope(out
, false);
1711 out
<< d_result
<< endl
;
1715 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
,
1716 ExprManagerMapCollection
& variableMap
)
1718 vector
<Expr
> exportedTerms
;
1719 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1723 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1725 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1726 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1730 Command
* GetValueCommand::clone() const
1732 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1733 c
->d_result
= d_result
;
1737 std::string
GetValueCommand::getCommandName() const { return "get-value"; }
1739 /* -------------------------------------------------------------------------- */
1740 /* class GetAssignmentCommand */
1741 /* -------------------------------------------------------------------------- */
1743 GetAssignmentCommand::GetAssignmentCommand() {}
1744 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
)
1748 std::vector
<std::pair
<Expr
, Expr
>> assignments
= smtEngine
->getAssignment();
1749 vector
<SExpr
> sexprs
;
1750 for (const auto& p
: assignments
)
1753 v
.emplace_back(SExpr::Keyword(p
.first
.toString()));
1754 v
.emplace_back(SExpr::Keyword(p
.second
.toString()));
1755 sexprs
.emplace_back(v
);
1757 d_result
= SExpr(sexprs
);
1758 d_commandStatus
= CommandSuccess::instance();
1760 catch (RecoverableModalException
& e
)
1762 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1764 catch (UnsafeInterruptException
& e
)
1766 d_commandStatus
= new CommandInterrupted();
1768 catch (exception
& e
)
1770 d_commandStatus
= new CommandFailure(e
.what());
1774 SExpr
GetAssignmentCommand::getResult() const { return d_result
; }
1775 void GetAssignmentCommand::printResult(std::ostream
& out
,
1776 uint32_t verbosity
) const
1780 this->Command::printResult(out
, verbosity
);
1784 out
<< d_result
<< endl
;
1788 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
,
1789 ExprManagerMapCollection
& variableMap
)
1791 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1792 c
->d_result
= d_result
;
1796 Command
* GetAssignmentCommand::clone() const
1798 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1799 c
->d_result
= d_result
;
1803 std::string
GetAssignmentCommand::getCommandName() const
1805 return "get-assignment";
1808 /* -------------------------------------------------------------------------- */
1809 /* class GetModelCommand */
1810 /* -------------------------------------------------------------------------- */
1812 GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
1813 void GetModelCommand::invoke(SmtEngine
* smtEngine
)
1817 d_result
= smtEngine
->getModel();
1818 d_smtEngine
= smtEngine
;
1819 d_commandStatus
= CommandSuccess::instance();
1821 catch (RecoverableModalException
& e
)
1823 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1825 catch (UnsafeInterruptException
& e
)
1827 d_commandStatus
= new CommandInterrupted();
1829 catch (exception
& e
)
1831 d_commandStatus
= new CommandFailure(e
.what());
1835 /* Model is private to the library -- for now
1836 Model* GetModelCommand::getResult() const {
1841 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1845 this->Command::printResult(out
, verbosity
);
1853 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
,
1854 ExprManagerMapCollection
& variableMap
)
1856 GetModelCommand
* c
= new GetModelCommand();
1857 c
->d_result
= d_result
;
1858 c
->d_smtEngine
= d_smtEngine
;
1862 Command
* GetModelCommand::clone() const
1864 GetModelCommand
* c
= new GetModelCommand();
1865 c
->d_result
= d_result
;
1866 c
->d_smtEngine
= d_smtEngine
;
1870 std::string
GetModelCommand::getCommandName() const { return "get-model"; }
1872 /* -------------------------------------------------------------------------- */
1873 /* class GetProofCommand */
1874 /* -------------------------------------------------------------------------- */
1876 GetProofCommand::GetProofCommand() : d_smtEngine(nullptr), d_result(nullptr) {}
1877 void GetProofCommand::invoke(SmtEngine
* smtEngine
)
1881 d_smtEngine
= smtEngine
;
1882 d_result
= &smtEngine
->getProof();
1883 d_commandStatus
= CommandSuccess::instance();
1885 catch (RecoverableModalException
& e
)
1887 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1889 catch (UnsafeInterruptException
& e
)
1891 d_commandStatus
= new CommandInterrupted();
1893 catch (exception
& e
)
1895 d_commandStatus
= new CommandFailure(e
.what());
1899 const Proof
& GetProofCommand::getResult() const { return *d_result
; }
1900 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1904 this->Command::printResult(out
, verbosity
);
1908 smt::SmtScope
scope(d_smtEngine
);
1909 d_result
->toStream(out
);
1913 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
,
1914 ExprManagerMapCollection
& variableMap
)
1916 GetProofCommand
* c
= new GetProofCommand();
1917 c
->d_result
= d_result
;
1918 c
->d_smtEngine
= d_smtEngine
;
1922 Command
* GetProofCommand::clone() const
1924 GetProofCommand
* c
= new GetProofCommand();
1925 c
->d_result
= d_result
;
1926 c
->d_smtEngine
= d_smtEngine
;
1930 std::string
GetProofCommand::getCommandName() const { return "get-proof"; }
1932 /* -------------------------------------------------------------------------- */
1933 /* class GetInstantiationsCommand */
1934 /* -------------------------------------------------------------------------- */
1936 GetInstantiationsCommand::GetInstantiationsCommand() : d_smtEngine(nullptr) {}
1937 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
)
1941 d_smtEngine
= smtEngine
;
1942 d_commandStatus
= CommandSuccess::instance();
1944 catch (exception
& e
)
1946 d_commandStatus
= new CommandFailure(e
.what());
1950 void GetInstantiationsCommand::printResult(std::ostream
& out
,
1951 uint32_t verbosity
) const
1955 this->Command::printResult(out
, verbosity
);
1959 d_smtEngine
->printInstantiations(out
);
1963 Command
* GetInstantiationsCommand::exportTo(
1964 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1966 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1967 // c->d_result = d_result;
1968 c
->d_smtEngine
= d_smtEngine
;
1972 Command
* GetInstantiationsCommand::clone() const
1974 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1975 // c->d_result = d_result;
1976 c
->d_smtEngine
= d_smtEngine
;
1980 std::string
GetInstantiationsCommand::getCommandName() const
1982 return "get-instantiations";
1985 /* -------------------------------------------------------------------------- */
1986 /* class GetSynthSolutionCommand */
1987 /* -------------------------------------------------------------------------- */
1989 GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
1990 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
)
1994 d_smtEngine
= smtEngine
;
1995 d_commandStatus
= CommandSuccess::instance();
1997 catch (exception
& e
)
1999 d_commandStatus
= new CommandFailure(e
.what());
2003 void GetSynthSolutionCommand::printResult(std::ostream
& out
,
2004 uint32_t verbosity
) const
2008 this->Command::printResult(out
, verbosity
);
2012 d_smtEngine
->printSynthSolution(out
);
2016 Command
* GetSynthSolutionCommand::exportTo(
2017 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2019 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2020 c
->d_smtEngine
= d_smtEngine
;
2024 Command
* GetSynthSolutionCommand::clone() const
2026 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2027 c
->d_smtEngine
= d_smtEngine
;
2031 std::string
GetSynthSolutionCommand::getCommandName() const
2033 return "get-instantiations";
2036 GetAbductCommand::GetAbductCommand() {}
2037 GetAbductCommand::GetAbductCommand(const std::string
& name
, Expr conj
)
2038 : d_name(name
), d_conj(conj
), d_resultStatus(false)
2041 GetAbductCommand::GetAbductCommand(const std::string
& name
,
2046 d_sygus_grammar_type(gtype
),
2047 d_resultStatus(false)
2051 Expr
GetAbductCommand::getConjecture() const { return d_conj
; }
2052 Type
GetAbductCommand::getGrammarType() const { return d_sygus_grammar_type
; }
2053 Expr
GetAbductCommand::getResult() const { return d_result
; }
2055 void GetAbductCommand::invoke(SmtEngine
* smtEngine
)
2059 if (d_sygus_grammar_type
.isNull())
2061 d_resultStatus
= smtEngine
->getAbduct(d_conj
, d_result
);
2066 smtEngine
->getAbduct(d_conj
, d_sygus_grammar_type
, d_result
);
2068 d_commandStatus
= CommandSuccess::instance();
2070 catch (exception
& e
)
2072 d_commandStatus
= new CommandFailure(e
.what());
2076 void GetAbductCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2080 this->Command::printResult(out
, verbosity
);
2084 expr::ExprDag::Scope
scope(out
, false);
2087 out
<< "(define-fun " << d_name
<< " () Bool " << d_result
<< ")"
2092 out
<< "none" << std::endl
;
2097 Command
* GetAbductCommand::exportTo(ExprManager
* exprManager
,
2098 ExprManagerMapCollection
& variableMap
)
2100 GetAbductCommand
* c
=
2101 new GetAbductCommand(d_name
, d_conj
.exportTo(exprManager
, variableMap
));
2102 c
->d_sygus_grammar_type
=
2103 d_sygus_grammar_type
.exportTo(exprManager
, variableMap
);
2104 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
2105 c
->d_resultStatus
= d_resultStatus
;
2109 Command
* GetAbductCommand::clone() const
2111 GetAbductCommand
* c
= new GetAbductCommand(d_name
, d_conj
);
2112 c
->d_sygus_grammar_type
= d_sygus_grammar_type
;
2113 c
->d_result
= d_result
;
2114 c
->d_resultStatus
= d_resultStatus
;
2118 std::string
GetAbductCommand::getCommandName() const { return "get-abduct"; }
2120 /* -------------------------------------------------------------------------- */
2121 /* class GetQuantifierEliminationCommand */
2122 /* -------------------------------------------------------------------------- */
2124 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand()
2125 : d_expr(), d_doFull(true)
2128 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
2129 const Expr
& expr
, bool doFull
)
2130 : d_expr(expr
), d_doFull(doFull
)
2134 Expr
GetQuantifierEliminationCommand::getExpr() const { return d_expr
; }
2135 bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull
; }
2136 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
)
2140 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
2141 d_commandStatus
= CommandSuccess::instance();
2143 catch (exception
& e
)
2145 d_commandStatus
= new CommandFailure(e
.what());
2149 Expr
GetQuantifierEliminationCommand::getResult() const { return d_result
; }
2150 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
,
2151 uint32_t verbosity
) const
2155 this->Command::printResult(out
, verbosity
);
2159 out
<< d_result
<< endl
;
2163 Command
* GetQuantifierEliminationCommand::exportTo(
2164 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2166 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(
2167 d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
2168 c
->d_result
= d_result
;
2172 Command
* GetQuantifierEliminationCommand::clone() const
2174 GetQuantifierEliminationCommand
* c
=
2175 new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
2176 c
->d_result
= d_result
;
2180 std::string
GetQuantifierEliminationCommand::getCommandName() const
2182 return d_doFull
? "get-qe" : "get-qe-disjunct";
2185 /* -------------------------------------------------------------------------- */
2186 /* class GetUnsatAssumptionsCommand */
2187 /* -------------------------------------------------------------------------- */
2189 GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
2191 void GetUnsatAssumptionsCommand::invoke(SmtEngine
* smtEngine
)
2195 d_result
= smtEngine
->getUnsatAssumptions();
2196 d_commandStatus
= CommandSuccess::instance();
2198 catch (RecoverableModalException
& e
)
2200 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2202 catch (exception
& e
)
2204 d_commandStatus
= new CommandFailure(e
.what());
2208 std::vector
<Expr
> GetUnsatAssumptionsCommand::getResult() const
2213 void GetUnsatAssumptionsCommand::printResult(std::ostream
& out
,
2214 uint32_t verbosity
) const
2218 this->Command::printResult(out
, verbosity
);
2222 container_to_stream(out
, d_result
, "(", ")\n", " ");
2226 Command
* GetUnsatAssumptionsCommand::exportTo(
2227 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2229 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2230 c
->d_result
= d_result
;
2234 Command
* GetUnsatAssumptionsCommand::clone() const
2236 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2237 c
->d_result
= d_result
;
2241 std::string
GetUnsatAssumptionsCommand::getCommandName() const
2243 return "get-unsat-assumptions";
2246 /* -------------------------------------------------------------------------- */
2247 /* class GetUnsatCoreCommand */
2248 /* -------------------------------------------------------------------------- */
2250 GetUnsatCoreCommand::GetUnsatCoreCommand() {}
2251 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
)
2255 d_result
= smtEngine
->getUnsatCore();
2256 d_commandStatus
= CommandSuccess::instance();
2258 catch (RecoverableModalException
& e
)
2260 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2262 catch (exception
& e
)
2264 d_commandStatus
= new CommandFailure(e
.what());
2268 void GetUnsatCoreCommand::printResult(std::ostream
& out
,
2269 uint32_t verbosity
) const
2273 this->Command::printResult(out
, verbosity
);
2277 d_result
.toStream(out
);
2281 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const
2283 // of course, this will be empty if the command hasn't been invoked yet
2287 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
,
2288 ExprManagerMapCollection
& variableMap
)
2290 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2291 c
->d_result
= d_result
;
2295 Command
* GetUnsatCoreCommand::clone() const
2297 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2298 c
->d_result
= d_result
;
2302 std::string
GetUnsatCoreCommand::getCommandName() const
2304 return "get-unsat-core";
2307 /* -------------------------------------------------------------------------- */
2308 /* class GetAssertionsCommand */
2309 /* -------------------------------------------------------------------------- */
2311 GetAssertionsCommand::GetAssertionsCommand() {}
2312 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
2317 const vector
<Expr
> v
= smtEngine
->getAssertions();
2319 copy(v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n"));
2321 d_result
= ss
.str();
2322 d_commandStatus
= CommandSuccess::instance();
2324 catch (exception
& e
)
2326 d_commandStatus
= new CommandFailure(e
.what());
2330 std::string
GetAssertionsCommand::getResult() const { return d_result
; }
2331 void GetAssertionsCommand::printResult(std::ostream
& out
,
2332 uint32_t verbosity
) const
2336 this->Command::printResult(out
, verbosity
);
2344 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
,
2345 ExprManagerMapCollection
& variableMap
)
2347 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2348 c
->d_result
= d_result
;
2352 Command
* GetAssertionsCommand::clone() const
2354 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2355 c
->d_result
= d_result
;
2359 std::string
GetAssertionsCommand::getCommandName() const
2361 return "get-assertions";
2364 /* -------------------------------------------------------------------------- */
2365 /* class SetBenchmarkStatusCommand */
2366 /* -------------------------------------------------------------------------- */
2368 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
)
2373 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const
2378 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
)
2384 SExpr status
= SExpr(ss
.str());
2385 smtEngine
->setInfo("status", status
);
2386 d_commandStatus
= CommandSuccess::instance();
2388 catch (exception
& e
)
2390 d_commandStatus
= new CommandFailure(e
.what());
2394 Command
* SetBenchmarkStatusCommand::exportTo(
2395 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2397 return new SetBenchmarkStatusCommand(d_status
);
2400 Command
* SetBenchmarkStatusCommand::clone() const
2402 return new SetBenchmarkStatusCommand(d_status
);
2405 std::string
SetBenchmarkStatusCommand::getCommandName() const
2410 /* -------------------------------------------------------------------------- */
2411 /* class SetBenchmarkLogicCommand */
2412 /* -------------------------------------------------------------------------- */
2414 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
)
2419 std::string
SetBenchmarkLogicCommand::getLogic() const { return d_logic
; }
2420 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
)
2424 smtEngine
->setLogic(d_logic
);
2425 d_commandStatus
= CommandSuccess::instance();
2427 catch (exception
& e
)
2429 d_commandStatus
= new CommandFailure(e
.what());
2433 Command
* SetBenchmarkLogicCommand::exportTo(
2434 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2436 return new SetBenchmarkLogicCommand(d_logic
);
2439 Command
* SetBenchmarkLogicCommand::clone() const
2441 return new SetBenchmarkLogicCommand(d_logic
);
2444 std::string
SetBenchmarkLogicCommand::getCommandName() const
2449 /* -------------------------------------------------------------------------- */
2450 /* class SetInfoCommand */
2451 /* -------------------------------------------------------------------------- */
2453 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
)
2454 : d_flag(flag
), d_sexpr(sexpr
)
2458 std::string
SetInfoCommand::getFlag() const { return d_flag
; }
2459 SExpr
SetInfoCommand::getSExpr() const { return d_sexpr
; }
2460 void SetInfoCommand::invoke(SmtEngine
* smtEngine
)
2464 smtEngine
->setInfo(d_flag
, d_sexpr
);
2465 d_commandStatus
= CommandSuccess::instance();
2467 catch (UnrecognizedOptionException
&)
2469 // As per SMT-LIB spec, silently accept unknown set-info keys
2470 d_commandStatus
= CommandSuccess::instance();
2472 catch (exception
& e
)
2474 d_commandStatus
= new CommandFailure(e
.what());
2478 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
,
2479 ExprManagerMapCollection
& variableMap
)
2481 return new SetInfoCommand(d_flag
, d_sexpr
);
2484 Command
* SetInfoCommand::clone() const
2486 return new SetInfoCommand(d_flag
, d_sexpr
);
2489 std::string
SetInfoCommand::getCommandName() const { return "set-info"; }
2491 /* -------------------------------------------------------------------------- */
2492 /* class GetInfoCommand */
2493 /* -------------------------------------------------------------------------- */
2495 GetInfoCommand::GetInfoCommand(std::string flag
) : d_flag(flag
) {}
2496 std::string
GetInfoCommand::getFlag() const { return d_flag
; }
2497 void GetInfoCommand::invoke(SmtEngine
* smtEngine
)
2502 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
2503 v
.push_back(smtEngine
->getInfo(d_flag
));
2505 if (d_flag
== "all-options" || d_flag
== "all-statistics")
2507 ss
<< PrettySExprs(true);
2510 d_result
= ss
.str();
2511 d_commandStatus
= CommandSuccess::instance();
2513 catch (UnrecognizedOptionException
&)
2515 d_commandStatus
= new CommandUnsupported();
2517 catch (RecoverableModalException
& e
)
2519 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2521 catch (exception
& e
)
2523 d_commandStatus
= new CommandFailure(e
.what());
2527 std::string
GetInfoCommand::getResult() const { return d_result
; }
2528 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2532 this->Command::printResult(out
, verbosity
);
2534 else if (d_result
!= "")
2536 out
<< d_result
<< endl
;
2540 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
,
2541 ExprManagerMapCollection
& variableMap
)
2543 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2544 c
->d_result
= d_result
;
2548 Command
* GetInfoCommand::clone() const
2550 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2551 c
->d_result
= d_result
;
2555 std::string
GetInfoCommand::getCommandName() const { return "get-info"; }
2557 /* -------------------------------------------------------------------------- */
2558 /* class SetOptionCommand */
2559 /* -------------------------------------------------------------------------- */
2561 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
)
2562 : d_flag(flag
), d_sexpr(sexpr
)
2566 std::string
SetOptionCommand::getFlag() const { return d_flag
; }
2567 SExpr
SetOptionCommand::getSExpr() const { return d_sexpr
; }
2568 void SetOptionCommand::invoke(SmtEngine
* smtEngine
)
2572 smtEngine
->setOption(d_flag
, d_sexpr
);
2573 d_commandStatus
= CommandSuccess::instance();
2575 catch (UnrecognizedOptionException
&)
2577 d_commandStatus
= new CommandUnsupported();
2579 catch (exception
& e
)
2581 d_commandStatus
= new CommandFailure(e
.what());
2585 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
,
2586 ExprManagerMapCollection
& variableMap
)
2588 return new SetOptionCommand(d_flag
, d_sexpr
);
2591 Command
* SetOptionCommand::clone() const
2593 return new SetOptionCommand(d_flag
, d_sexpr
);
2596 std::string
SetOptionCommand::getCommandName() const { return "set-option"; }
2598 /* -------------------------------------------------------------------------- */
2599 /* class GetOptionCommand */
2600 /* -------------------------------------------------------------------------- */
2602 GetOptionCommand::GetOptionCommand(std::string flag
) : d_flag(flag
) {}
2603 std::string
GetOptionCommand::getFlag() const { return d_flag
; }
2604 void GetOptionCommand::invoke(SmtEngine
* smtEngine
)
2608 SExpr res
= smtEngine
->getOption(d_flag
);
2609 d_result
= res
.toString();
2610 d_commandStatus
= CommandSuccess::instance();
2612 catch (UnrecognizedOptionException
&)
2614 d_commandStatus
= new CommandUnsupported();
2616 catch (exception
& e
)
2618 d_commandStatus
= new CommandFailure(e
.what());
2622 std::string
GetOptionCommand::getResult() const { return d_result
; }
2623 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2627 this->Command::printResult(out
, verbosity
);
2629 else if (d_result
!= "")
2631 out
<< d_result
<< endl
;
2635 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
,
2636 ExprManagerMapCollection
& variableMap
)
2638 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2639 c
->d_result
= d_result
;
2643 Command
* GetOptionCommand::clone() const
2645 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2646 c
->d_result
= d_result
;
2650 std::string
GetOptionCommand::getCommandName() const { return "get-option"; }
2652 /* -------------------------------------------------------------------------- */
2653 /* class SetExpressionNameCommand */
2654 /* -------------------------------------------------------------------------- */
2656 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
)
2657 : d_expr(expr
), d_name(name
)
2661 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
)
2663 smtEngine
->setExpressionName(d_expr
, d_name
);
2664 d_commandStatus
= CommandSuccess::instance();
2667 Command
* SetExpressionNameCommand::exportTo(
2668 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2670 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(
2671 d_expr
.exportTo(exprManager
, variableMap
), d_name
);
2675 Command
* SetExpressionNameCommand::clone() const
2677 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
2681 std::string
SetExpressionNameCommand::getCommandName() const
2683 return "set-expr-name";
2686 /* -------------------------------------------------------------------------- */
2687 /* class DatatypeDeclarationCommand */
2688 /* -------------------------------------------------------------------------- */
2690 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2691 const DatatypeType
& datatype
)
2694 d_datatypes
.push_back(datatype
);
2697 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2698 const std::vector
<DatatypeType
>& datatypes
)
2699 : d_datatypes(datatypes
)
2703 const std::vector
<DatatypeType
>& DatatypeDeclarationCommand::getDatatypes()
2709 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
)
2711 d_commandStatus
= CommandSuccess::instance();
2714 Command
* DatatypeDeclarationCommand::exportTo(
2715 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2717 throw ExportUnsupportedException(
2718 "export of DatatypeDeclarationCommand unsupported");
2721 Command
* DatatypeDeclarationCommand::clone() const
2723 return new DatatypeDeclarationCommand(d_datatypes
);
2726 std::string
DatatypeDeclarationCommand::getCommandName() const
2728 return "declare-datatypes";
2731 /* -------------------------------------------------------------------------- */
2732 /* class RewriteRuleCommand */
2733 /* -------------------------------------------------------------------------- */
2735 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
2736 const std::vector
<Expr
>& guards
,
2739 const Triggers
& triggers
)
2744 d_triggers(triggers
)
2748 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
2751 : d_vars(vars
), d_head(head
), d_body(body
)
2755 const std::vector
<Expr
>& RewriteRuleCommand::getVars() const { return d_vars
; }
2756 const std::vector
<Expr
>& RewriteRuleCommand::getGuards() const
2761 Expr
RewriteRuleCommand::getHead() const { return d_head
; }
2762 Expr
RewriteRuleCommand::getBody() const { return d_body
; }
2763 const RewriteRuleCommand::Triggers
& RewriteRuleCommand::getTriggers() const
2768 void RewriteRuleCommand::invoke(SmtEngine
* smtEngine
)
2772 ExprManager
* em
= smtEngine
->getExprManager();
2773 /** build vars list */
2774 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
2775 /** build guards list */
2777 if (d_guards
.size() == 0)
2778 guards
= em
->mkConst
<bool>(true);
2779 else if (d_guards
.size() == 1)
2780 guards
= d_guards
[0];
2782 guards
= em
->mkExpr(kind::AND
, d_guards
);
2783 /** build expression */
2785 if (d_triggers
.empty())
2787 expr
= em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, d_head
, d_body
);
2791 /** build triggers list */
2792 std::vector
<Expr
> vtriggers
;
2793 vtriggers
.reserve(d_triggers
.size());
2794 for (Triggers::const_iterator i
= d_triggers
.begin(),
2795 end
= d_triggers
.end();
2799 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
, *i
));
2801 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
, vtriggers
);
2803 em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, d_head
, d_body
, triggers
);
2805 smtEngine
->assertFormula(expr
);
2806 d_commandStatus
= CommandSuccess::instance();
2808 catch (exception
& e
)
2810 d_commandStatus
= new CommandFailure(e
.what());
2814 Command
* RewriteRuleCommand::exportTo(ExprManager
* exprManager
,
2815 ExprManagerMapCollection
& variableMap
)
2817 /** Convert variables */
2818 VExpr vars
= ExportTo(exprManager
, variableMap
, d_vars
);
2819 /** Convert guards */
2820 VExpr guards
= ExportTo(exprManager
, variableMap
, d_guards
);
2821 /** Convert triggers */
2823 triggers
.reserve(d_triggers
.size());
2824 for (const std::vector
<Expr
>& trigger_list
: d_triggers
)
2826 triggers
.push_back(ExportTo(exprManager
, variableMap
, trigger_list
));
2828 /** Convert head and body */
2829 Expr head
= d_head
.exportTo(exprManager
, variableMap
);
2830 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
2831 /** Create the converted rules */
2832 return new RewriteRuleCommand(vars
, guards
, head
, body
, triggers
);
2835 Command
* RewriteRuleCommand::clone() const
2837 return new RewriteRuleCommand(d_vars
, d_guards
, d_head
, d_body
, d_triggers
);
2840 std::string
RewriteRuleCommand::getCommandName() const
2842 return "rewrite-rule";
2845 /* -------------------------------------------------------------------------- */
2846 /* class PropagateRuleCommand */
2847 /* -------------------------------------------------------------------------- */
2849 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
2850 const std::vector
<Expr
>& guards
,
2851 const std::vector
<Expr
>& heads
,
2853 const Triggers
& triggers
,
2859 d_triggers(triggers
),
2860 d_deduction(deduction
)
2864 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
2865 const std::vector
<Expr
>& heads
,
2868 : d_vars(vars
), d_heads(heads
), d_body(body
), d_deduction(deduction
)
2872 const std::vector
<Expr
>& PropagateRuleCommand::getVars() const
2877 const std::vector
<Expr
>& PropagateRuleCommand::getGuards() const
2882 const std::vector
<Expr
>& PropagateRuleCommand::getHeads() const
2887 Expr
PropagateRuleCommand::getBody() const { return d_body
; }
2888 const PropagateRuleCommand::Triggers
& PropagateRuleCommand::getTriggers() const
2893 bool PropagateRuleCommand::isDeduction() const { return d_deduction
; }
2894 void PropagateRuleCommand::invoke(SmtEngine
* smtEngine
)
2898 ExprManager
* em
= smtEngine
->getExprManager();
2899 /** build vars list */
2900 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
2901 /** build guards list */
2903 if (d_guards
.size() == 0)
2904 guards
= em
->mkConst
<bool>(true);
2905 else if (d_guards
.size() == 1)
2906 guards
= d_guards
[0];
2908 guards
= em
->mkExpr(kind::AND
, d_guards
);
2909 /** build heads list */
2911 if (d_heads
.size() == 1)
2914 heads
= em
->mkExpr(kind::AND
, d_heads
);
2915 /** build expression */
2917 if (d_triggers
.empty())
2919 expr
= em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, heads
, d_body
);
2923 /** build triggers list */
2924 std::vector
<Expr
> vtriggers
;
2925 vtriggers
.reserve(d_triggers
.size());
2926 for (Triggers::const_iterator i
= d_triggers
.begin(),
2927 end
= d_triggers
.end();
2931 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
, *i
));
2933 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
, vtriggers
);
2935 em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, heads
, d_body
, triggers
);
2937 smtEngine
->assertFormula(expr
);
2938 d_commandStatus
= CommandSuccess::instance();
2940 catch (exception
& e
)
2942 d_commandStatus
= new CommandFailure(e
.what());
2946 Command
* PropagateRuleCommand::exportTo(ExprManager
* exprManager
,
2947 ExprManagerMapCollection
& variableMap
)
2949 /** Convert variables */
2950 VExpr vars
= ExportTo(exprManager
, variableMap
, d_vars
);
2951 /** Convert guards */
2952 VExpr guards
= ExportTo(exprManager
, variableMap
, d_guards
);
2953 /** Convert heads */
2954 VExpr heads
= ExportTo(exprManager
, variableMap
, d_heads
);
2955 /** Convert triggers */
2957 triggers
.reserve(d_triggers
.size());
2958 for (const std::vector
<Expr
>& trigger_list
: d_triggers
)
2960 triggers
.push_back(ExportTo(exprManager
, variableMap
, trigger_list
));
2962 /** Convert head and body */
2963 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
2964 /** Create the converted rules */
2965 return new PropagateRuleCommand(vars
, guards
, heads
, body
, triggers
);
2968 Command
* PropagateRuleCommand::clone() const
2970 return new PropagateRuleCommand(
2971 d_vars
, d_guards
, d_heads
, d_body
, d_triggers
);
2974 std::string
PropagateRuleCommand::getCommandName() const
2976 return "propagate-rule";