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-2018 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(
1362 d_func
.getExprManager()->mkExpr(kind::APPLY
, d_func
));
1364 d_commandStatus
= CommandSuccess::instance();
1367 Command
* DefineNamedFunctionCommand::exportTo(
1368 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1370 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
1371 vector
<Expr
> formals
;
1372 transform(d_formals
.begin(),
1374 back_inserter(formals
),
1375 ExportTransformer(exprManager
, variableMap
));
1376 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1377 return new DefineNamedFunctionCommand(d_symbol
, func
, formals
, formula
);
1380 Command
* DefineNamedFunctionCommand::clone() const
1382 return new DefineNamedFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1385 /* -------------------------------------------------------------------------- */
1386 /* class DefineFunctionRecCommand */
1387 /* -------------------------------------------------------------------------- */
1389 DefineFunctionRecCommand::DefineFunctionRecCommand(
1390 Expr func
, const std::vector
<Expr
>& formals
, Expr formula
)
1392 d_funcs
.push_back(func
);
1393 d_formals
.push_back(formals
);
1394 d_formulas
.push_back(formula
);
1397 DefineFunctionRecCommand::DefineFunctionRecCommand(
1398 const std::vector
<Expr
>& funcs
,
1399 const std::vector
<std::vector
<Expr
>>& formals
,
1400 const std::vector
<Expr
>& formulas
)
1402 d_funcs
.insert(d_funcs
.end(), funcs
.begin(), funcs
.end());
1403 d_formals
.insert(d_formals
.end(), formals
.begin(), formals
.end());
1404 d_formulas
.insert(d_formulas
.end(), formulas
.begin(), formulas
.end());
1407 const std::vector
<Expr
>& DefineFunctionRecCommand::getFunctions() const
1412 const std::vector
<std::vector
<Expr
>>& DefineFunctionRecCommand::getFormals()
1418 const std::vector
<Expr
>& DefineFunctionRecCommand::getFormulas() const
1423 void DefineFunctionRecCommand::invoke(SmtEngine
* smtEngine
)
1427 smtEngine
->defineFunctionsRec(d_funcs
, d_formals
, d_formulas
);
1428 d_commandStatus
= CommandSuccess::instance();
1430 catch (exception
& e
)
1432 d_commandStatus
= new CommandFailure(e
.what());
1436 Command
* DefineFunctionRecCommand::exportTo(
1437 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1439 std::vector
<Expr
> funcs
;
1440 for (unsigned i
= 0, size
= d_funcs
.size(); i
< size
; i
++)
1442 Expr func
= d_funcs
[i
].exportTo(
1443 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1444 funcs
.push_back(func
);
1446 std::vector
<std::vector
<Expr
>> formals
;
1447 for (unsigned i
= 0, size
= d_formals
.size(); i
< size
; i
++)
1449 std::vector
<Expr
> formals_c
;
1450 transform(d_formals
[i
].begin(),
1452 back_inserter(formals_c
),
1453 ExportTransformer(exprManager
, variableMap
));
1454 formals
.push_back(formals_c
);
1456 std::vector
<Expr
> formulas
;
1457 for (unsigned i
= 0, size
= d_formulas
.size(); i
< size
; i
++)
1459 Expr formula
= d_formulas
[i
].exportTo(exprManager
, variableMap
);
1460 formulas
.push_back(formula
);
1462 return new DefineFunctionRecCommand(funcs
, formals
, formulas
);
1465 Command
* DefineFunctionRecCommand::clone() const
1467 return new DefineFunctionRecCommand(d_funcs
, d_formals
, d_formulas
);
1470 std::string
DefineFunctionRecCommand::getCommandName() const
1472 return "define-fun-rec";
1475 /* -------------------------------------------------------------------------- */
1476 /* class SetUserAttribute */
1477 /* -------------------------------------------------------------------------- */
1479 SetUserAttributeCommand::SetUserAttributeCommand(
1480 const std::string
& attr
,
1482 const std::vector
<Expr
>& expr_values
,
1483 const std::string
& str_value
)
1486 d_expr_values(expr_values
),
1487 d_str_value(str_value
)
1491 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1493 : SetUserAttributeCommand(attr
, expr
, {}, "")
1497 SetUserAttributeCommand::SetUserAttributeCommand(
1498 const std::string
& attr
, Expr expr
, const std::vector
<Expr
>& values
)
1499 : SetUserAttributeCommand(attr
, expr
, values
, "")
1503 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1505 const std::string
& value
)
1506 : SetUserAttributeCommand(attr
, expr
, {}, value
)
1510 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
)
1514 if (!d_expr
.isNull())
1516 smtEngine
->setUserAttribute(d_attr
, d_expr
, d_expr_values
, d_str_value
);
1518 d_commandStatus
= CommandSuccess::instance();
1520 catch (exception
& e
)
1522 d_commandStatus
= new CommandFailure(e
.what());
1526 Command
* SetUserAttributeCommand::exportTo(
1527 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1529 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
1530 return new SetUserAttributeCommand(d_attr
, expr
, d_expr_values
, d_str_value
);
1533 Command
* SetUserAttributeCommand::clone() const
1535 return new SetUserAttributeCommand(
1536 d_attr
, d_expr
, d_expr_values
, d_str_value
);
1539 std::string
SetUserAttributeCommand::getCommandName() const
1541 return "set-user-attribute";
1544 /* -------------------------------------------------------------------------- */
1545 /* class SimplifyCommand */
1546 /* -------------------------------------------------------------------------- */
1548 SimplifyCommand::SimplifyCommand(Expr term
) : d_term(term
) {}
1549 Expr
SimplifyCommand::getTerm() const { return d_term
; }
1550 void SimplifyCommand::invoke(SmtEngine
* smtEngine
)
1554 d_result
= smtEngine
->simplify(d_term
);
1555 d_commandStatus
= CommandSuccess::instance();
1557 catch (UnsafeInterruptException
& e
)
1559 d_commandStatus
= new CommandInterrupted();
1561 catch (exception
& e
)
1563 d_commandStatus
= new CommandFailure(e
.what());
1567 Expr
SimplifyCommand::getResult() const { return d_result
; }
1568 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1572 this->Command::printResult(out
, verbosity
);
1576 out
<< d_result
<< endl
;
1580 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
,
1581 ExprManagerMapCollection
& variableMap
)
1583 SimplifyCommand
* c
=
1584 new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
1585 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1589 Command
* SimplifyCommand::clone() const
1591 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
1592 c
->d_result
= d_result
;
1596 std::string
SimplifyCommand::getCommandName() const { return "simplify"; }
1598 /* -------------------------------------------------------------------------- */
1599 /* class ExpandDefinitionsCommand */
1600 /* -------------------------------------------------------------------------- */
1602 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) : d_term(term
) {}
1603 Expr
ExpandDefinitionsCommand::getTerm() const { return d_term
; }
1604 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
)
1606 d_result
= smtEngine
->expandDefinitions(d_term
);
1607 d_commandStatus
= CommandSuccess::instance();
1610 Expr
ExpandDefinitionsCommand::getResult() const { return d_result
; }
1611 void ExpandDefinitionsCommand::printResult(std::ostream
& out
,
1612 uint32_t verbosity
) const
1616 this->Command::printResult(out
, verbosity
);
1620 out
<< d_result
<< endl
;
1624 Command
* ExpandDefinitionsCommand::exportTo(
1625 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1627 ExpandDefinitionsCommand
* c
=
1628 new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
1629 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1633 Command
* ExpandDefinitionsCommand::clone() const
1635 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
1636 c
->d_result
= d_result
;
1640 std::string
ExpandDefinitionsCommand::getCommandName() const
1642 return "expand-definitions";
1645 /* -------------------------------------------------------------------------- */
1646 /* class GetValueCommand */
1647 /* -------------------------------------------------------------------------- */
1649 GetValueCommand::GetValueCommand(Expr term
) : d_terms()
1651 d_terms
.push_back(term
);
1654 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
)
1657 PrettyCheckArgument(
1658 terms
.size() >= 1, terms
, "cannot get-value of an empty set of terms");
1661 const std::vector
<Expr
>& GetValueCommand::getTerms() const { return d_terms
; }
1662 void GetValueCommand::invoke(SmtEngine
* smtEngine
)
1666 vector
<Expr
> result
;
1667 ExprManager
* em
= smtEngine
->getExprManager();
1668 NodeManager
* nm
= NodeManager::fromExprManager(em
);
1669 for (const Expr
& e
: d_terms
)
1671 Assert(nm
== NodeManager::fromExprManager(e
.getExprManager()));
1672 smt::SmtScope
scope(smtEngine
);
1673 Node request
= Node::fromExpr(
1674 options::expandDefinitions() ? smtEngine
->expandDefinitions(e
) : e
);
1675 Node value
= Node::fromExpr(smtEngine
->getValue(e
));
1676 if (value
.getType().isInteger() && request
.getType() == nm
->realType())
1678 // Need to wrap in division-by-one so that output printers know this
1679 // is an integer-looking constant that really should be output as
1680 // a rational. Necessary for SMT-LIB standards compliance.
1681 value
= nm
->mkNode(kind::DIVISION
, value
, nm
->mkConst(Rational(1)));
1683 result
.push_back(nm
->mkNode(kind::SEXPR
, request
, value
).toExpr());
1685 d_result
= em
->mkExpr(kind::SEXPR
, result
);
1686 d_commandStatus
= CommandSuccess::instance();
1688 catch (RecoverableModalException
& e
)
1690 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1692 catch (UnsafeInterruptException
& e
)
1694 d_commandStatus
= new CommandInterrupted();
1696 catch (exception
& e
)
1698 d_commandStatus
= new CommandFailure(e
.what());
1702 Expr
GetValueCommand::getResult() const { return d_result
; }
1703 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1707 this->Command::printResult(out
, verbosity
);
1711 expr::ExprDag::Scope
scope(out
, false);
1712 out
<< d_result
<< endl
;
1716 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
,
1717 ExprManagerMapCollection
& variableMap
)
1719 vector
<Expr
> exportedTerms
;
1720 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1724 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1726 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1727 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1731 Command
* GetValueCommand::clone() const
1733 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1734 c
->d_result
= d_result
;
1738 std::string
GetValueCommand::getCommandName() const { return "get-value"; }
1740 /* -------------------------------------------------------------------------- */
1741 /* class GetAssignmentCommand */
1742 /* -------------------------------------------------------------------------- */
1744 GetAssignmentCommand::GetAssignmentCommand() {}
1745 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
)
1749 std::vector
<std::pair
<Expr
, Expr
>> assignments
= smtEngine
->getAssignment();
1750 vector
<SExpr
> sexprs
;
1751 for (const auto& p
: assignments
)
1754 if (p
.first
.getKind() == kind::APPLY
)
1756 v
.emplace_back(SExpr::Keyword(p
.first
.getOperator().toString()));
1760 v
.emplace_back(SExpr::Keyword(p
.first
.toString()));
1762 v
.emplace_back(SExpr::Keyword(p
.second
.toString()));
1763 sexprs
.emplace_back(v
);
1765 d_result
= SExpr(sexprs
);
1766 d_commandStatus
= CommandSuccess::instance();
1768 catch (RecoverableModalException
& e
)
1770 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1772 catch (UnsafeInterruptException
& e
)
1774 d_commandStatus
= new CommandInterrupted();
1776 catch (exception
& e
)
1778 d_commandStatus
= new CommandFailure(e
.what());
1782 SExpr
GetAssignmentCommand::getResult() const { return d_result
; }
1783 void GetAssignmentCommand::printResult(std::ostream
& out
,
1784 uint32_t verbosity
) const
1788 this->Command::printResult(out
, verbosity
);
1792 out
<< d_result
<< endl
;
1796 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
,
1797 ExprManagerMapCollection
& variableMap
)
1799 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1800 c
->d_result
= d_result
;
1804 Command
* GetAssignmentCommand::clone() const
1806 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1807 c
->d_result
= d_result
;
1811 std::string
GetAssignmentCommand::getCommandName() const
1813 return "get-assignment";
1816 /* -------------------------------------------------------------------------- */
1817 /* class GetModelCommand */
1818 /* -------------------------------------------------------------------------- */
1820 GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
1821 void GetModelCommand::invoke(SmtEngine
* smtEngine
)
1825 d_result
= smtEngine
->getModel();
1826 d_smtEngine
= smtEngine
;
1827 d_commandStatus
= CommandSuccess::instance();
1829 catch (RecoverableModalException
& e
)
1831 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1833 catch (UnsafeInterruptException
& e
)
1835 d_commandStatus
= new CommandInterrupted();
1837 catch (exception
& e
)
1839 d_commandStatus
= new CommandFailure(e
.what());
1843 /* Model is private to the library -- for now
1844 Model* GetModelCommand::getResult() const {
1849 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1853 this->Command::printResult(out
, verbosity
);
1861 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
,
1862 ExprManagerMapCollection
& variableMap
)
1864 GetModelCommand
* c
= new GetModelCommand();
1865 c
->d_result
= d_result
;
1866 c
->d_smtEngine
= d_smtEngine
;
1870 Command
* GetModelCommand::clone() const
1872 GetModelCommand
* c
= new GetModelCommand();
1873 c
->d_result
= d_result
;
1874 c
->d_smtEngine
= d_smtEngine
;
1878 std::string
GetModelCommand::getCommandName() const { return "get-model"; }
1880 /* -------------------------------------------------------------------------- */
1881 /* class GetProofCommand */
1882 /* -------------------------------------------------------------------------- */
1884 GetProofCommand::GetProofCommand() : d_smtEngine(nullptr), d_result(nullptr) {}
1885 void GetProofCommand::invoke(SmtEngine
* smtEngine
)
1889 d_smtEngine
= smtEngine
;
1890 d_result
= &smtEngine
->getProof();
1891 d_commandStatus
= CommandSuccess::instance();
1893 catch (RecoverableModalException
& e
)
1895 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1897 catch (UnsafeInterruptException
& e
)
1899 d_commandStatus
= new CommandInterrupted();
1901 catch (exception
& e
)
1903 d_commandStatus
= new CommandFailure(e
.what());
1907 const Proof
& GetProofCommand::getResult() const { return *d_result
; }
1908 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1912 this->Command::printResult(out
, verbosity
);
1916 smt::SmtScope
scope(d_smtEngine
);
1917 d_result
->toStream(out
);
1921 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
,
1922 ExprManagerMapCollection
& variableMap
)
1924 GetProofCommand
* c
= new GetProofCommand();
1925 c
->d_result
= d_result
;
1926 c
->d_smtEngine
= d_smtEngine
;
1930 Command
* GetProofCommand::clone() const
1932 GetProofCommand
* c
= new GetProofCommand();
1933 c
->d_result
= d_result
;
1934 c
->d_smtEngine
= d_smtEngine
;
1938 std::string
GetProofCommand::getCommandName() const { return "get-proof"; }
1940 /* -------------------------------------------------------------------------- */
1941 /* class GetInstantiationsCommand */
1942 /* -------------------------------------------------------------------------- */
1944 GetInstantiationsCommand::GetInstantiationsCommand() : d_smtEngine(nullptr) {}
1945 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
)
1949 d_smtEngine
= smtEngine
;
1950 d_commandStatus
= CommandSuccess::instance();
1952 catch (exception
& e
)
1954 d_commandStatus
= new CommandFailure(e
.what());
1958 void GetInstantiationsCommand::printResult(std::ostream
& out
,
1959 uint32_t verbosity
) const
1963 this->Command::printResult(out
, verbosity
);
1967 d_smtEngine
->printInstantiations(out
);
1971 Command
* GetInstantiationsCommand::exportTo(
1972 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1974 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1975 // c->d_result = d_result;
1976 c
->d_smtEngine
= d_smtEngine
;
1980 Command
* GetInstantiationsCommand::clone() const
1982 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1983 // c->d_result = d_result;
1984 c
->d_smtEngine
= d_smtEngine
;
1988 std::string
GetInstantiationsCommand::getCommandName() const
1990 return "get-instantiations";
1993 /* -------------------------------------------------------------------------- */
1994 /* class GetSynthSolutionCommand */
1995 /* -------------------------------------------------------------------------- */
1997 GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
1998 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
)
2002 d_smtEngine
= smtEngine
;
2003 d_commandStatus
= CommandSuccess::instance();
2005 catch (exception
& e
)
2007 d_commandStatus
= new CommandFailure(e
.what());
2011 void GetSynthSolutionCommand::printResult(std::ostream
& out
,
2012 uint32_t verbosity
) const
2016 this->Command::printResult(out
, verbosity
);
2020 d_smtEngine
->printSynthSolution(out
);
2024 Command
* GetSynthSolutionCommand::exportTo(
2025 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2027 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2028 c
->d_smtEngine
= d_smtEngine
;
2032 Command
* GetSynthSolutionCommand::clone() const
2034 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
2035 c
->d_smtEngine
= d_smtEngine
;
2039 std::string
GetSynthSolutionCommand::getCommandName() const
2041 return "get-instantiations";
2044 /* -------------------------------------------------------------------------- */
2045 /* class GetQuantifierEliminationCommand */
2046 /* -------------------------------------------------------------------------- */
2048 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand()
2049 : d_expr(), d_doFull(true)
2052 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
2053 const Expr
& expr
, bool doFull
)
2054 : d_expr(expr
), d_doFull(doFull
)
2058 Expr
GetQuantifierEliminationCommand::getExpr() const { return d_expr
; }
2059 bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull
; }
2060 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
)
2064 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
2065 d_commandStatus
= CommandSuccess::instance();
2067 catch (exception
& e
)
2069 d_commandStatus
= new CommandFailure(e
.what());
2073 Expr
GetQuantifierEliminationCommand::getResult() const { return d_result
; }
2074 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
,
2075 uint32_t verbosity
) const
2079 this->Command::printResult(out
, verbosity
);
2083 out
<< d_result
<< endl
;
2087 Command
* GetQuantifierEliminationCommand::exportTo(
2088 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2090 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(
2091 d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
2092 c
->d_result
= d_result
;
2096 Command
* GetQuantifierEliminationCommand::clone() const
2098 GetQuantifierEliminationCommand
* c
=
2099 new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
2100 c
->d_result
= d_result
;
2104 std::string
GetQuantifierEliminationCommand::getCommandName() const
2106 return d_doFull
? "get-qe" : "get-qe-disjunct";
2109 /* -------------------------------------------------------------------------- */
2110 /* class GetUnsatAssumptionsCommand */
2111 /* -------------------------------------------------------------------------- */
2113 GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
2115 void GetUnsatAssumptionsCommand::invoke(SmtEngine
* smtEngine
)
2119 d_result
= smtEngine
->getUnsatAssumptions();
2120 d_commandStatus
= CommandSuccess::instance();
2122 catch (RecoverableModalException
& e
)
2124 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2126 catch (exception
& e
)
2128 d_commandStatus
= new CommandFailure(e
.what());
2132 std::vector
<Expr
> GetUnsatAssumptionsCommand::getResult() const
2137 void GetUnsatAssumptionsCommand::printResult(std::ostream
& out
,
2138 uint32_t verbosity
) const
2142 this->Command::printResult(out
, verbosity
);
2146 container_to_stream(out
, d_result
, "(", ")\n", " ");
2150 Command
* GetUnsatAssumptionsCommand::exportTo(
2151 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2153 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2154 c
->d_result
= d_result
;
2158 Command
* GetUnsatAssumptionsCommand::clone() const
2160 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
2161 c
->d_result
= d_result
;
2165 std::string
GetUnsatAssumptionsCommand::getCommandName() const
2167 return "get-unsat-assumptions";
2170 /* -------------------------------------------------------------------------- */
2171 /* class GetUnsatCoreCommand */
2172 /* -------------------------------------------------------------------------- */
2174 GetUnsatCoreCommand::GetUnsatCoreCommand() {}
2175 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
)
2179 d_result
= smtEngine
->getUnsatCore();
2180 d_commandStatus
= CommandSuccess::instance();
2182 catch (RecoverableModalException
& e
)
2184 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2186 catch (exception
& e
)
2188 d_commandStatus
= new CommandFailure(e
.what());
2192 void GetUnsatCoreCommand::printResult(std::ostream
& out
,
2193 uint32_t verbosity
) const
2197 this->Command::printResult(out
, verbosity
);
2201 d_result
.toStream(out
);
2205 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const
2207 // of course, this will be empty if the command hasn't been invoked yet
2211 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
,
2212 ExprManagerMapCollection
& variableMap
)
2214 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2215 c
->d_result
= d_result
;
2219 Command
* GetUnsatCoreCommand::clone() const
2221 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
2222 c
->d_result
= d_result
;
2226 std::string
GetUnsatCoreCommand::getCommandName() const
2228 return "get-unsat-core";
2231 /* -------------------------------------------------------------------------- */
2232 /* class GetAssertionsCommand */
2233 /* -------------------------------------------------------------------------- */
2235 GetAssertionsCommand::GetAssertionsCommand() {}
2236 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
2241 const vector
<Expr
> v
= smtEngine
->getAssertions();
2243 copy(v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n"));
2245 d_result
= ss
.str();
2246 d_commandStatus
= CommandSuccess::instance();
2248 catch (exception
& e
)
2250 d_commandStatus
= new CommandFailure(e
.what());
2254 std::string
GetAssertionsCommand::getResult() const { return d_result
; }
2255 void GetAssertionsCommand::printResult(std::ostream
& out
,
2256 uint32_t verbosity
) const
2260 this->Command::printResult(out
, verbosity
);
2268 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
,
2269 ExprManagerMapCollection
& variableMap
)
2271 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2272 c
->d_result
= d_result
;
2276 Command
* GetAssertionsCommand::clone() const
2278 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2279 c
->d_result
= d_result
;
2283 std::string
GetAssertionsCommand::getCommandName() const
2285 return "get-assertions";
2288 /* -------------------------------------------------------------------------- */
2289 /* class SetBenchmarkStatusCommand */
2290 /* -------------------------------------------------------------------------- */
2292 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
)
2297 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const
2302 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
)
2308 SExpr status
= SExpr(ss
.str());
2309 smtEngine
->setInfo("status", status
);
2310 d_commandStatus
= CommandSuccess::instance();
2312 catch (exception
& e
)
2314 d_commandStatus
= new CommandFailure(e
.what());
2318 Command
* SetBenchmarkStatusCommand::exportTo(
2319 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2321 return new SetBenchmarkStatusCommand(d_status
);
2324 Command
* SetBenchmarkStatusCommand::clone() const
2326 return new SetBenchmarkStatusCommand(d_status
);
2329 std::string
SetBenchmarkStatusCommand::getCommandName() const
2334 /* -------------------------------------------------------------------------- */
2335 /* class SetBenchmarkLogicCommand */
2336 /* -------------------------------------------------------------------------- */
2338 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
)
2343 std::string
SetBenchmarkLogicCommand::getLogic() const { return d_logic
; }
2344 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
)
2348 smtEngine
->setLogic(d_logic
);
2349 d_commandStatus
= CommandSuccess::instance();
2351 catch (exception
& e
)
2353 d_commandStatus
= new CommandFailure(e
.what());
2357 Command
* SetBenchmarkLogicCommand::exportTo(
2358 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2360 return new SetBenchmarkLogicCommand(d_logic
);
2363 Command
* SetBenchmarkLogicCommand::clone() const
2365 return new SetBenchmarkLogicCommand(d_logic
);
2368 std::string
SetBenchmarkLogicCommand::getCommandName() const
2373 /* -------------------------------------------------------------------------- */
2374 /* class SetInfoCommand */
2375 /* -------------------------------------------------------------------------- */
2377 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
)
2378 : d_flag(flag
), d_sexpr(sexpr
)
2382 std::string
SetInfoCommand::getFlag() const { return d_flag
; }
2383 SExpr
SetInfoCommand::getSExpr() const { return d_sexpr
; }
2384 void SetInfoCommand::invoke(SmtEngine
* smtEngine
)
2388 smtEngine
->setInfo(d_flag
, d_sexpr
);
2389 d_commandStatus
= CommandSuccess::instance();
2391 catch (UnrecognizedOptionException
&)
2393 // As per SMT-LIB spec, silently accept unknown set-info keys
2394 d_commandStatus
= CommandSuccess::instance();
2396 catch (exception
& e
)
2398 d_commandStatus
= new CommandFailure(e
.what());
2402 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
,
2403 ExprManagerMapCollection
& variableMap
)
2405 return new SetInfoCommand(d_flag
, d_sexpr
);
2408 Command
* SetInfoCommand::clone() const
2410 return new SetInfoCommand(d_flag
, d_sexpr
);
2413 std::string
SetInfoCommand::getCommandName() const { return "set-info"; }
2415 /* -------------------------------------------------------------------------- */
2416 /* class GetInfoCommand */
2417 /* -------------------------------------------------------------------------- */
2419 GetInfoCommand::GetInfoCommand(std::string flag
) : d_flag(flag
) {}
2420 std::string
GetInfoCommand::getFlag() const { return d_flag
; }
2421 void GetInfoCommand::invoke(SmtEngine
* smtEngine
)
2426 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
2427 v
.push_back(smtEngine
->getInfo(d_flag
));
2429 if (d_flag
== "all-options" || d_flag
== "all-statistics")
2431 ss
<< PrettySExprs(true);
2434 d_result
= ss
.str();
2435 d_commandStatus
= CommandSuccess::instance();
2437 catch (UnrecognizedOptionException
&)
2439 d_commandStatus
= new CommandUnsupported();
2441 catch (RecoverableModalException
& e
)
2443 d_commandStatus
= new CommandRecoverableFailure(e
.what());
2445 catch (exception
& e
)
2447 d_commandStatus
= new CommandFailure(e
.what());
2451 std::string
GetInfoCommand::getResult() const { return d_result
; }
2452 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2456 this->Command::printResult(out
, verbosity
);
2458 else if (d_result
!= "")
2460 out
<< d_result
<< endl
;
2464 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
,
2465 ExprManagerMapCollection
& variableMap
)
2467 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2468 c
->d_result
= d_result
;
2472 Command
* GetInfoCommand::clone() const
2474 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2475 c
->d_result
= d_result
;
2479 std::string
GetInfoCommand::getCommandName() const { return "get-info"; }
2481 /* -------------------------------------------------------------------------- */
2482 /* class SetOptionCommand */
2483 /* -------------------------------------------------------------------------- */
2485 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
)
2486 : d_flag(flag
), d_sexpr(sexpr
)
2490 std::string
SetOptionCommand::getFlag() const { return d_flag
; }
2491 SExpr
SetOptionCommand::getSExpr() const { return d_sexpr
; }
2492 void SetOptionCommand::invoke(SmtEngine
* smtEngine
)
2496 smtEngine
->setOption(d_flag
, d_sexpr
);
2497 d_commandStatus
= CommandSuccess::instance();
2499 catch (UnrecognizedOptionException
&)
2501 d_commandStatus
= new CommandUnsupported();
2503 catch (exception
& e
)
2505 d_commandStatus
= new CommandFailure(e
.what());
2509 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
,
2510 ExprManagerMapCollection
& variableMap
)
2512 return new SetOptionCommand(d_flag
, d_sexpr
);
2515 Command
* SetOptionCommand::clone() const
2517 return new SetOptionCommand(d_flag
, d_sexpr
);
2520 std::string
SetOptionCommand::getCommandName() const { return "set-option"; }
2522 /* -------------------------------------------------------------------------- */
2523 /* class GetOptionCommand */
2524 /* -------------------------------------------------------------------------- */
2526 GetOptionCommand::GetOptionCommand(std::string flag
) : d_flag(flag
) {}
2527 std::string
GetOptionCommand::getFlag() const { return d_flag
; }
2528 void GetOptionCommand::invoke(SmtEngine
* smtEngine
)
2532 SExpr res
= smtEngine
->getOption(d_flag
);
2533 d_result
= res
.toString();
2534 d_commandStatus
= CommandSuccess::instance();
2536 catch (UnrecognizedOptionException
&)
2538 d_commandStatus
= new CommandUnsupported();
2540 catch (exception
& e
)
2542 d_commandStatus
= new CommandFailure(e
.what());
2546 std::string
GetOptionCommand::getResult() const { return d_result
; }
2547 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2551 this->Command::printResult(out
, verbosity
);
2553 else if (d_result
!= "")
2555 out
<< d_result
<< endl
;
2559 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
,
2560 ExprManagerMapCollection
& variableMap
)
2562 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2563 c
->d_result
= d_result
;
2567 Command
* GetOptionCommand::clone() const
2569 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2570 c
->d_result
= d_result
;
2574 std::string
GetOptionCommand::getCommandName() const { return "get-option"; }
2576 /* -------------------------------------------------------------------------- */
2577 /* class SetExpressionNameCommand */
2578 /* -------------------------------------------------------------------------- */
2580 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
)
2581 : d_expr(expr
), d_name(name
)
2585 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
)
2587 smtEngine
->setExpressionName(d_expr
, d_name
);
2588 d_commandStatus
= CommandSuccess::instance();
2591 Command
* SetExpressionNameCommand::exportTo(
2592 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2594 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(
2595 d_expr
.exportTo(exprManager
, variableMap
), d_name
);
2599 Command
* SetExpressionNameCommand::clone() const
2601 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
2605 std::string
SetExpressionNameCommand::getCommandName() const
2607 return "set-expr-name";
2610 /* -------------------------------------------------------------------------- */
2611 /* class DatatypeDeclarationCommand */
2612 /* -------------------------------------------------------------------------- */
2614 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2615 const DatatypeType
& datatype
)
2618 d_datatypes
.push_back(datatype
);
2621 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2622 const std::vector
<DatatypeType
>& datatypes
)
2623 : d_datatypes(datatypes
)
2627 const std::vector
<DatatypeType
>& DatatypeDeclarationCommand::getDatatypes()
2633 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
)
2635 d_commandStatus
= CommandSuccess::instance();
2638 Command
* DatatypeDeclarationCommand::exportTo(
2639 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2641 throw ExportUnsupportedException(
2642 "export of DatatypeDeclarationCommand unsupported");
2645 Command
* DatatypeDeclarationCommand::clone() const
2647 return new DatatypeDeclarationCommand(d_datatypes
);
2650 std::string
DatatypeDeclarationCommand::getCommandName() const
2652 return "declare-datatypes";
2655 /* -------------------------------------------------------------------------- */
2656 /* class RewriteRuleCommand */
2657 /* -------------------------------------------------------------------------- */
2659 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
2660 const std::vector
<Expr
>& guards
,
2663 const Triggers
& triggers
)
2668 d_triggers(triggers
)
2672 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
2675 : d_vars(vars
), d_head(head
), d_body(body
)
2679 const std::vector
<Expr
>& RewriteRuleCommand::getVars() const { return d_vars
; }
2680 const std::vector
<Expr
>& RewriteRuleCommand::getGuards() const
2685 Expr
RewriteRuleCommand::getHead() const { return d_head
; }
2686 Expr
RewriteRuleCommand::getBody() const { return d_body
; }
2687 const RewriteRuleCommand::Triggers
& RewriteRuleCommand::getTriggers() const
2692 void RewriteRuleCommand::invoke(SmtEngine
* smtEngine
)
2696 ExprManager
* em
= smtEngine
->getExprManager();
2697 /** build vars list */
2698 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
2699 /** build guards list */
2701 if (d_guards
.size() == 0)
2702 guards
= em
->mkConst
<bool>(true);
2703 else if (d_guards
.size() == 1)
2704 guards
= d_guards
[0];
2706 guards
= em
->mkExpr(kind::AND
, d_guards
);
2707 /** build expression */
2709 if (d_triggers
.empty())
2711 expr
= em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, d_head
, d_body
);
2715 /** build triggers list */
2716 std::vector
<Expr
> vtriggers
;
2717 vtriggers
.reserve(d_triggers
.size());
2718 for (Triggers::const_iterator i
= d_triggers
.begin(),
2719 end
= d_triggers
.end();
2723 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
, *i
));
2725 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
, vtriggers
);
2727 em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, d_head
, d_body
, triggers
);
2729 smtEngine
->assertFormula(expr
);
2730 d_commandStatus
= CommandSuccess::instance();
2732 catch (exception
& e
)
2734 d_commandStatus
= new CommandFailure(e
.what());
2738 Command
* RewriteRuleCommand::exportTo(ExprManager
* exprManager
,
2739 ExprManagerMapCollection
& variableMap
)
2741 /** Convert variables */
2742 VExpr vars
= ExportTo(exprManager
, variableMap
, d_vars
);
2743 /** Convert guards */
2744 VExpr guards
= ExportTo(exprManager
, variableMap
, d_guards
);
2745 /** Convert triggers */
2747 triggers
.reserve(d_triggers
.size());
2748 for (const std::vector
<Expr
>& trigger_list
: d_triggers
)
2750 triggers
.push_back(ExportTo(exprManager
, variableMap
, trigger_list
));
2752 /** Convert head and body */
2753 Expr head
= d_head
.exportTo(exprManager
, variableMap
);
2754 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
2755 /** Create the converted rules */
2756 return new RewriteRuleCommand(vars
, guards
, head
, body
, triggers
);
2759 Command
* RewriteRuleCommand::clone() const
2761 return new RewriteRuleCommand(d_vars
, d_guards
, d_head
, d_body
, d_triggers
);
2764 std::string
RewriteRuleCommand::getCommandName() const
2766 return "rewrite-rule";
2769 /* -------------------------------------------------------------------------- */
2770 /* class PropagateRuleCommand */
2771 /* -------------------------------------------------------------------------- */
2773 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
2774 const std::vector
<Expr
>& guards
,
2775 const std::vector
<Expr
>& heads
,
2777 const Triggers
& triggers
,
2783 d_triggers(triggers
),
2784 d_deduction(deduction
)
2788 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
2789 const std::vector
<Expr
>& heads
,
2792 : d_vars(vars
), d_heads(heads
), d_body(body
), d_deduction(deduction
)
2796 const std::vector
<Expr
>& PropagateRuleCommand::getVars() const
2801 const std::vector
<Expr
>& PropagateRuleCommand::getGuards() const
2806 const std::vector
<Expr
>& PropagateRuleCommand::getHeads() const
2811 Expr
PropagateRuleCommand::getBody() const { return d_body
; }
2812 const PropagateRuleCommand::Triggers
& PropagateRuleCommand::getTriggers() const
2817 bool PropagateRuleCommand::isDeduction() const { return d_deduction
; }
2818 void PropagateRuleCommand::invoke(SmtEngine
* smtEngine
)
2822 ExprManager
* em
= smtEngine
->getExprManager();
2823 /** build vars list */
2824 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
2825 /** build guards list */
2827 if (d_guards
.size() == 0)
2828 guards
= em
->mkConst
<bool>(true);
2829 else if (d_guards
.size() == 1)
2830 guards
= d_guards
[0];
2832 guards
= em
->mkExpr(kind::AND
, d_guards
);
2833 /** build heads list */
2835 if (d_heads
.size() == 1)
2838 heads
= em
->mkExpr(kind::AND
, d_heads
);
2839 /** build expression */
2841 if (d_triggers
.empty())
2843 expr
= em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, heads
, d_body
);
2847 /** build triggers list */
2848 std::vector
<Expr
> vtriggers
;
2849 vtriggers
.reserve(d_triggers
.size());
2850 for (Triggers::const_iterator i
= d_triggers
.begin(),
2851 end
= d_triggers
.end();
2855 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
, *i
));
2857 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
, vtriggers
);
2859 em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, heads
, d_body
, triggers
);
2861 smtEngine
->assertFormula(expr
);
2862 d_commandStatus
= CommandSuccess::instance();
2864 catch (exception
& e
)
2866 d_commandStatus
= new CommandFailure(e
.what());
2870 Command
* PropagateRuleCommand::exportTo(ExprManager
* exprManager
,
2871 ExprManagerMapCollection
& variableMap
)
2873 /** Convert variables */
2874 VExpr vars
= ExportTo(exprManager
, variableMap
, d_vars
);
2875 /** Convert guards */
2876 VExpr guards
= ExportTo(exprManager
, variableMap
, d_guards
);
2877 /** Convert heads */
2878 VExpr heads
= ExportTo(exprManager
, variableMap
, d_heads
);
2879 /** Convert triggers */
2881 triggers
.reserve(d_triggers
.size());
2882 for (const std::vector
<Expr
>& trigger_list
: d_triggers
)
2884 triggers
.push_back(ExportTo(exprManager
, variableMap
, trigger_list
));
2886 /** Convert head and body */
2887 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
2888 /** Create the converted rules */
2889 return new PropagateRuleCommand(vars
, guards
, heads
, body
, triggers
);
2892 Command
* PropagateRuleCommand::clone() const
2894 return new PropagateRuleCommand(
2895 d_vars
, d_guards
, d_heads
, d_body
, d_triggers
);
2898 std::string
PropagateRuleCommand::getCommandName() const
2900 return "propagate-rule";