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"
45 std::vector
<Expr
> ExportTo(ExprManager
* exprManager
,
46 ExprManagerMapCollection
& variableMap
,
47 const std::vector
<Expr
>& exprs
)
49 std::vector
<Expr
> exported
;
50 exported
.reserve(exprs
.size());
51 for (const Expr
& expr
: exprs
)
53 exported
.push_back(expr
.exportTo(exprManager
, variableMap
));
60 const int CommandPrintSuccess::s_iosIndex
= std::ios_base::xalloc();
61 const CommandSuccess
* CommandSuccess::s_instance
= new CommandSuccess();
62 const CommandInterrupted
* CommandInterrupted::s_instance
=
63 new CommandInterrupted();
65 std::ostream
& operator<<(std::ostream
& out
, const Command
& c
)
68 Node::setdepth::getDepth(out
),
69 Node::printtypes::getPrintTypes(out
),
70 Node::dag::getDag(out
),
71 Node::setlanguage::getLanguage(out
));
75 ostream
& operator<<(ostream
& out
, const Command
* c
)
88 std::ostream
& operator<<(std::ostream
& out
, const CommandStatus
& s
)
90 s
.toStream(out
, Node::setlanguage::getLanguage(out
));
94 ostream
& operator<<(ostream
& out
, const CommandStatus
* s
)
108 /* output stream insertion operator for benchmark statuses */
109 std::ostream
& operator<<(std::ostream
& out
, BenchmarkStatus status
)
113 case SMT_SATISFIABLE
: return out
<< "sat";
115 case SMT_UNSATISFIABLE
: return out
<< "unsat";
117 case SMT_UNKNOWN
: return out
<< "unknown";
119 default: return out
<< "BenchmarkStatus::[UNKNOWNSTATUS!]";
123 /* -------------------------------------------------------------------------- */
124 /* class CommandPrintSuccess */
125 /* -------------------------------------------------------------------------- */
127 void CommandPrintSuccess::applyPrintSuccess(std::ostream
& out
)
129 out
.iword(s_iosIndex
) = d_printSuccess
;
132 bool CommandPrintSuccess::getPrintSuccess(std::ostream
& out
)
134 return out
.iword(s_iosIndex
);
137 void CommandPrintSuccess::setPrintSuccess(std::ostream
& out
, bool printSuccess
)
139 out
.iword(s_iosIndex
) = printSuccess
;
142 std::ostream
& operator<<(std::ostream
& out
, CommandPrintSuccess cps
)
144 cps
.applyPrintSuccess(out
);
148 /* -------------------------------------------------------------------------- */
150 /* -------------------------------------------------------------------------- */
152 Command::Command() : d_commandStatus(NULL
), d_muted(false) {}
153 Command::Command(const Command
& cmd
)
156 (cmd
.d_commandStatus
== NULL
) ? NULL
: &cmd
.d_commandStatus
->clone();
157 d_muted
= cmd
.d_muted
;
162 if (d_commandStatus
!= NULL
&& d_commandStatus
!= CommandSuccess::instance())
164 delete d_commandStatus
;
168 bool Command::ok() const
170 // either we haven't run the command yet, or it ran successfully
171 return d_commandStatus
== NULL
172 || dynamic_cast<const CommandSuccess
*>(d_commandStatus
) != NULL
;
175 bool Command::fail() const
177 return d_commandStatus
!= NULL
178 && dynamic_cast<const CommandFailure
*>(d_commandStatus
) != NULL
;
181 bool Command::interrupted() const
183 return d_commandStatus
!= NULL
184 && dynamic_cast<const CommandInterrupted
*>(d_commandStatus
) != NULL
;
187 void Command::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
190 if (!(isMuted() && ok()))
193 smtEngine
->getOption("command-verbosity:" + getCommandName())
199 std::string
Command::toString() const
201 std::stringstream ss
;
206 void Command::toStream(std::ostream
& out
,
210 OutputLanguage language
) const
212 Printer::getPrinter(language
)->toStream(out
, this, toDepth
, types
, dag
);
215 void CommandStatus::toStream(std::ostream
& out
, OutputLanguage language
) const
217 Printer::getPrinter(language
)->toStream(out
, this);
220 void Command::printResult(std::ostream
& out
, uint32_t verbosity
) const
222 if (d_commandStatus
!= NULL
)
224 if ((!ok() && verbosity
>= 1) || verbosity
>= 2)
226 out
<< *d_commandStatus
;
231 /* -------------------------------------------------------------------------- */
232 /* class EmptyCommand */
233 /* -------------------------------------------------------------------------- */
235 EmptyCommand::EmptyCommand(std::string name
) : d_name(name
) {}
236 std::string
EmptyCommand::getName() const { return d_name
; }
237 void EmptyCommand::invoke(SmtEngine
* smtEngine
)
239 /* empty commands have no implementation */
240 d_commandStatus
= CommandSuccess::instance();
243 Command
* EmptyCommand::exportTo(ExprManager
* exprManager
,
244 ExprManagerMapCollection
& variableMap
)
246 return new EmptyCommand(d_name
);
249 Command
* EmptyCommand::clone() const { return new EmptyCommand(d_name
); }
250 std::string
EmptyCommand::getCommandName() const { return "empty"; }
252 /* -------------------------------------------------------------------------- */
253 /* class EchoCommand */
254 /* -------------------------------------------------------------------------- */
256 EchoCommand::EchoCommand(std::string output
) : d_output(output
) {}
257 std::string
EchoCommand::getOutput() const { return d_output
; }
258 void EchoCommand::invoke(SmtEngine
* smtEngine
)
260 /* we don't have an output stream here, nothing to do */
261 d_commandStatus
= CommandSuccess::instance();
264 void EchoCommand::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
266 out
<< d_output
<< std::endl
;
267 d_commandStatus
= CommandSuccess::instance();
269 smtEngine
->getOption("command-verbosity:" + getCommandName())
274 Command
* EchoCommand::exportTo(ExprManager
* exprManager
,
275 ExprManagerMapCollection
& variableMap
)
277 return new EchoCommand(d_output
);
280 Command
* EchoCommand::clone() const { return new EchoCommand(d_output
); }
281 std::string
EchoCommand::getCommandName() const { return "echo"; }
283 /* -------------------------------------------------------------------------- */
284 /* class AssertCommand */
285 /* -------------------------------------------------------------------------- */
287 AssertCommand::AssertCommand(const Expr
& e
, bool inUnsatCore
)
288 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
292 Expr
AssertCommand::getExpr() const { return d_expr
; }
293 void AssertCommand::invoke(SmtEngine
* smtEngine
)
297 smtEngine
->assertFormula(d_expr
, d_inUnsatCore
);
298 d_commandStatus
= CommandSuccess::instance();
300 catch (UnsafeInterruptException
& e
)
302 d_commandStatus
= new CommandInterrupted();
306 d_commandStatus
= new CommandFailure(e
.what());
310 Command
* AssertCommand::exportTo(ExprManager
* exprManager
,
311 ExprManagerMapCollection
& variableMap
)
313 return new AssertCommand(d_expr
.exportTo(exprManager
, variableMap
),
317 Command
* AssertCommand::clone() const
319 return new AssertCommand(d_expr
, d_inUnsatCore
);
322 std::string
AssertCommand::getCommandName() const { return "assert"; }
324 /* -------------------------------------------------------------------------- */
325 /* class PushCommand */
326 /* -------------------------------------------------------------------------- */
328 void PushCommand::invoke(SmtEngine
* smtEngine
)
333 d_commandStatus
= CommandSuccess::instance();
335 catch (UnsafeInterruptException
& e
)
337 d_commandStatus
= new CommandInterrupted();
341 d_commandStatus
= new CommandFailure(e
.what());
345 Command
* PushCommand::exportTo(ExprManager
* exprManager
,
346 ExprManagerMapCollection
& variableMap
)
348 return new PushCommand();
351 Command
* PushCommand::clone() const { return new PushCommand(); }
352 std::string
PushCommand::getCommandName() const { return "push"; }
354 /* -------------------------------------------------------------------------- */
355 /* class PopCommand */
356 /* -------------------------------------------------------------------------- */
358 void PopCommand::invoke(SmtEngine
* smtEngine
)
363 d_commandStatus
= CommandSuccess::instance();
365 catch (UnsafeInterruptException
& e
)
367 d_commandStatus
= new CommandInterrupted();
371 d_commandStatus
= new CommandFailure(e
.what());
375 Command
* PopCommand::exportTo(ExprManager
* exprManager
,
376 ExprManagerMapCollection
& variableMap
)
378 return new PopCommand();
381 Command
* PopCommand::clone() const { return new PopCommand(); }
382 std::string
PopCommand::getCommandName() const { return "pop"; }
384 /* -------------------------------------------------------------------------- */
385 /* class CheckSatCommand */
386 /* -------------------------------------------------------------------------- */
388 CheckSatCommand::CheckSatCommand() : d_expr() {}
389 CheckSatCommand::CheckSatCommand(const Expr
& expr
, bool inUnsatCore
)
390 : d_expr(expr
), d_inUnsatCore(inUnsatCore
)
394 Expr
CheckSatCommand::getExpr() const { return d_expr
; }
395 void CheckSatCommand::invoke(SmtEngine
* smtEngine
)
399 d_result
= smtEngine
->checkSat(d_expr
);
400 d_commandStatus
= CommandSuccess::instance();
404 d_commandStatus
= new CommandFailure(e
.what());
408 Result
CheckSatCommand::getResult() const { return d_result
; }
409 void CheckSatCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
413 this->Command::printResult(out
, verbosity
);
417 out
<< d_result
<< endl
;
421 Command
* CheckSatCommand::exportTo(ExprManager
* exprManager
,
422 ExprManagerMapCollection
& variableMap
)
424 CheckSatCommand
* c
= new CheckSatCommand(
425 d_expr
.exportTo(exprManager
, variableMap
), d_inUnsatCore
);
426 c
->d_result
= d_result
;
430 Command
* CheckSatCommand::clone() const
432 CheckSatCommand
* c
= new CheckSatCommand(d_expr
, d_inUnsatCore
);
433 c
->d_result
= d_result
;
437 std::string
CheckSatCommand::getCommandName() const { return "check-sat"; }
439 /* -------------------------------------------------------------------------- */
440 /* class CheckSatAssumingCommand */
441 /* -------------------------------------------------------------------------- */
443 CheckSatAssumingCommand::CheckSatAssumingCommand(Expr term
) : d_terms()
445 d_terms
.push_back(term
);
448 CheckSatAssumingCommand::CheckSatAssumingCommand(const std::vector
<Expr
>& terms
,
450 : d_terms(terms
), d_inUnsatCore(inUnsatCore
)
454 const std::vector
<Expr
>& CheckSatAssumingCommand::getTerms() const
459 void CheckSatAssumingCommand::invoke(SmtEngine
* smtEngine
)
463 d_result
= smtEngine
->checkSat(d_terms
);
464 d_commandStatus
= CommandSuccess::instance();
468 d_commandStatus
= new CommandFailure(e
.what());
472 Result
CheckSatAssumingCommand::getResult() const
477 void CheckSatAssumingCommand::printResult(std::ostream
& out
,
478 uint32_t verbosity
) const
482 this->Command::printResult(out
, verbosity
);
486 out
<< d_result
<< endl
;
490 Command
* CheckSatAssumingCommand::exportTo(
491 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
493 vector
<Expr
> exportedTerms
;
494 for (const Expr
& e
: d_terms
)
496 exportedTerms
.push_back(e
.exportTo(exprManager
, variableMap
));
498 CheckSatAssumingCommand
* c
=
499 new CheckSatAssumingCommand(exportedTerms
, d_inUnsatCore
);
500 c
->d_result
= d_result
;
504 Command
* CheckSatAssumingCommand::clone() const
506 CheckSatAssumingCommand
* c
=
507 new CheckSatAssumingCommand(d_terms
, d_inUnsatCore
);
508 c
->d_result
= d_result
;
512 std::string
CheckSatAssumingCommand::getCommandName() const
514 return "check-sat-assuming";
517 /* -------------------------------------------------------------------------- */
518 /* class QueryCommand */
519 /* -------------------------------------------------------------------------- */
521 QueryCommand::QueryCommand(const Expr
& e
, bool inUnsatCore
)
522 : d_expr(e
), d_inUnsatCore(inUnsatCore
)
526 Expr
QueryCommand::getExpr() const { return d_expr
; }
527 void QueryCommand::invoke(SmtEngine
* smtEngine
)
531 d_result
= smtEngine
->query(d_expr
);
532 d_commandStatus
= CommandSuccess::instance();
536 d_commandStatus
= new CommandFailure(e
.what());
540 Result
QueryCommand::getResult() const { return d_result
; }
541 void QueryCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
545 this->Command::printResult(out
, verbosity
);
549 out
<< d_result
<< endl
;
553 Command
* QueryCommand::exportTo(ExprManager
* exprManager
,
554 ExprManagerMapCollection
& variableMap
)
556 QueryCommand
* c
= new QueryCommand(d_expr
.exportTo(exprManager
, variableMap
),
558 c
->d_result
= d_result
;
562 Command
* QueryCommand::clone() const
564 QueryCommand
* c
= new QueryCommand(d_expr
, d_inUnsatCore
);
565 c
->d_result
= d_result
;
569 std::string
QueryCommand::getCommandName() const { return "query"; }
571 /* -------------------------------------------------------------------------- */
572 /* class CheckSynthCommand */
573 /* -------------------------------------------------------------------------- */
575 CheckSynthCommand::CheckSynthCommand() : d_expr() {}
576 CheckSynthCommand::CheckSynthCommand(const Expr
& expr
) : d_expr(expr
) {}
577 Expr
CheckSynthCommand::getExpr() const { return d_expr
; }
578 void CheckSynthCommand::invoke(SmtEngine
* smtEngine
)
582 d_result
= smtEngine
->checkSynth(d_expr
);
583 d_commandStatus
= CommandSuccess::instance();
584 smt::SmtScope
scope(smtEngine
);
586 // check whether we should print the status
587 if (d_result
.asSatisfiabilityResult() != Result::UNSAT
588 || options::sygusOut() == SYGUS_SOL_OUT_STATUS_AND_DEF
589 || options::sygusOut() == SYGUS_SOL_OUT_STATUS
)
591 if (options::sygusOut() == SYGUS_SOL_OUT_STANDARD
)
593 d_solution
<< "(fail)" << endl
;
597 d_solution
<< d_result
<< endl
;
600 // check whether we should print the solution
601 if (d_result
.asSatisfiabilityResult() == Result::UNSAT
602 && options::sygusOut() != SYGUS_SOL_OUT_STATUS
)
604 // printing a synthesis solution is a non-constant
605 // method, since it invokes a sophisticated algorithm
606 // (Figure 5 of Reynolds et al. CAV 2015).
607 // Hence, we must call here print solution here,
608 // instead of during printResult.
609 smtEngine
->printSynthSolution(d_solution
);
614 d_commandStatus
= new CommandFailure(e
.what());
618 Result
CheckSynthCommand::getResult() const { return d_result
; }
619 void CheckSynthCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
623 this->Command::printResult(out
, verbosity
);
627 out
<< d_solution
.str();
631 Command
* CheckSynthCommand::exportTo(ExprManager
* exprManager
,
632 ExprManagerMapCollection
& variableMap
)
634 CheckSynthCommand
* c
=
635 new CheckSynthCommand(d_expr
.exportTo(exprManager
, variableMap
));
636 c
->d_result
= d_result
;
640 Command
* CheckSynthCommand::clone() const
642 CheckSynthCommand
* c
= new CheckSynthCommand(d_expr
);
643 c
->d_result
= d_result
;
647 std::string
CheckSynthCommand::getCommandName() const { return "check-synth"; }
649 /* -------------------------------------------------------------------------- */
650 /* class ResetCommand */
651 /* -------------------------------------------------------------------------- */
653 void ResetCommand::invoke(SmtEngine
* smtEngine
)
658 d_commandStatus
= CommandSuccess::instance();
662 d_commandStatus
= new CommandFailure(e
.what());
666 Command
* ResetCommand::exportTo(ExprManager
* exprManager
,
667 ExprManagerMapCollection
& variableMap
)
669 return new ResetCommand();
672 Command
* ResetCommand::clone() const { return new ResetCommand(); }
673 std::string
ResetCommand::getCommandName() const { return "reset"; }
675 /* -------------------------------------------------------------------------- */
676 /* class ResetAssertionsCommand */
677 /* -------------------------------------------------------------------------- */
679 void ResetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
683 smtEngine
->resetAssertions();
684 d_commandStatus
= CommandSuccess::instance();
688 d_commandStatus
= new CommandFailure(e
.what());
692 Command
* ResetAssertionsCommand::exportTo(ExprManager
* exprManager
,
693 ExprManagerMapCollection
& variableMap
)
695 return new ResetAssertionsCommand();
698 Command
* ResetAssertionsCommand::clone() const
700 return new ResetAssertionsCommand();
703 std::string
ResetAssertionsCommand::getCommandName() const
705 return "reset-assertions";
708 /* -------------------------------------------------------------------------- */
709 /* class QuitCommand */
710 /* -------------------------------------------------------------------------- */
712 void QuitCommand::invoke(SmtEngine
* smtEngine
)
714 Dump("benchmark") << *this;
715 d_commandStatus
= CommandSuccess::instance();
718 Command
* QuitCommand::exportTo(ExprManager
* exprManager
,
719 ExprManagerMapCollection
& variableMap
)
721 return new QuitCommand();
724 Command
* QuitCommand::clone() const { return new QuitCommand(); }
725 std::string
QuitCommand::getCommandName() const { return "exit"; }
727 /* -------------------------------------------------------------------------- */
728 /* class CommentCommand */
729 /* -------------------------------------------------------------------------- */
731 CommentCommand::CommentCommand(std::string comment
) : d_comment(comment
) {}
732 std::string
CommentCommand::getComment() const { return d_comment
; }
733 void CommentCommand::invoke(SmtEngine
* smtEngine
)
735 Dump("benchmark") << *this;
736 d_commandStatus
= CommandSuccess::instance();
739 Command
* CommentCommand::exportTo(ExprManager
* exprManager
,
740 ExprManagerMapCollection
& variableMap
)
742 return new CommentCommand(d_comment
);
745 Command
* CommentCommand::clone() const { return new CommentCommand(d_comment
); }
746 std::string
CommentCommand::getCommandName() const { return "comment"; }
748 /* -------------------------------------------------------------------------- */
749 /* class CommandSequence */
750 /* -------------------------------------------------------------------------- */
752 CommandSequence::CommandSequence() : d_index(0) {}
753 CommandSequence::~CommandSequence()
755 for (unsigned i
= d_index
; i
< d_commandSequence
.size(); ++i
)
757 delete d_commandSequence
[i
];
761 void CommandSequence::addCommand(Command
* cmd
)
763 d_commandSequence
.push_back(cmd
);
766 void CommandSequence::clear() { d_commandSequence
.clear(); }
767 void CommandSequence::invoke(SmtEngine
* smtEngine
)
769 for (; d_index
< d_commandSequence
.size(); ++d_index
)
771 d_commandSequence
[d_index
]->invoke(smtEngine
);
772 if (!d_commandSequence
[d_index
]->ok())
775 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
778 delete d_commandSequence
[d_index
];
781 AlwaysAssert(d_commandStatus
== NULL
);
782 d_commandStatus
= CommandSuccess::instance();
785 void CommandSequence::invoke(SmtEngine
* smtEngine
, std::ostream
& out
)
787 for (; d_index
< d_commandSequence
.size(); ++d_index
)
789 d_commandSequence
[d_index
]->invoke(smtEngine
, out
);
790 if (!d_commandSequence
[d_index
]->ok())
793 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
796 delete d_commandSequence
[d_index
];
799 AlwaysAssert(d_commandStatus
== NULL
);
800 d_commandStatus
= CommandSuccess::instance();
803 Command
* CommandSequence::exportTo(ExprManager
* exprManager
,
804 ExprManagerMapCollection
& variableMap
)
806 CommandSequence
* seq
= new CommandSequence();
807 for (iterator i
= begin(); i
!= end(); ++i
)
809 Command
* cmd_to_export
= *i
;
810 Command
* cmd
= cmd_to_export
->exportTo(exprManager
, variableMap
);
811 seq
->addCommand(cmd
);
812 Debug("export") << "[export] so far converted: " << seq
<< endl
;
814 seq
->d_index
= d_index
;
818 Command
* CommandSequence::clone() const
820 CommandSequence
* seq
= new CommandSequence();
821 for (const_iterator i
= begin(); i
!= end(); ++i
)
823 seq
->addCommand((*i
)->clone());
825 seq
->d_index
= d_index
;
829 CommandSequence::const_iterator
CommandSequence::begin() const
831 return d_commandSequence
.begin();
834 CommandSequence::const_iterator
CommandSequence::end() const
836 return d_commandSequence
.end();
839 CommandSequence::iterator
CommandSequence::begin()
841 return d_commandSequence
.begin();
844 CommandSequence::iterator
CommandSequence::end()
846 return d_commandSequence
.end();
849 std::string
CommandSequence::getCommandName() const { return "sequence"; }
851 /* -------------------------------------------------------------------------- */
852 /* class DeclarationDefinitionCommand */
853 /* -------------------------------------------------------------------------- */
855 DeclarationDefinitionCommand::DeclarationDefinitionCommand(
856 const std::string
& id
)
861 std::string
DeclarationDefinitionCommand::getSymbol() const { return d_symbol
; }
863 /* -------------------------------------------------------------------------- */
864 /* class DeclareFunctionCommand */
865 /* -------------------------------------------------------------------------- */
867 DeclareFunctionCommand::DeclareFunctionCommand(const std::string
& id
,
870 : DeclarationDefinitionCommand(id
),
873 d_printInModel(true),
874 d_printInModelSetByUser(false)
878 Expr
DeclareFunctionCommand::getFunction() const { return d_func
; }
879 Type
DeclareFunctionCommand::getType() const { return d_type
; }
880 bool DeclareFunctionCommand::getPrintInModel() const { return d_printInModel
; }
881 bool DeclareFunctionCommand::getPrintInModelSetByUser() const
883 return d_printInModelSetByUser
;
886 void DeclareFunctionCommand::setPrintInModel(bool p
)
889 d_printInModelSetByUser
= true;
892 void DeclareFunctionCommand::invoke(SmtEngine
* smtEngine
)
894 d_commandStatus
= CommandSuccess::instance();
897 Command
* DeclareFunctionCommand::exportTo(ExprManager
* exprManager
,
898 ExprManagerMapCollection
& variableMap
)
900 DeclareFunctionCommand
* dfc
=
901 new DeclareFunctionCommand(d_symbol
,
902 d_func
.exportTo(exprManager
, variableMap
),
903 d_type
.exportTo(exprManager
, variableMap
));
904 dfc
->d_printInModel
= d_printInModel
;
905 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
909 Command
* DeclareFunctionCommand::clone() const
911 DeclareFunctionCommand
* dfc
=
912 new DeclareFunctionCommand(d_symbol
, d_func
, d_type
);
913 dfc
->d_printInModel
= d_printInModel
;
914 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
918 std::string
DeclareFunctionCommand::getCommandName() const
920 return "declare-fun";
923 /* -------------------------------------------------------------------------- */
924 /* class DeclareTypeCommand */
925 /* -------------------------------------------------------------------------- */
927 DeclareTypeCommand::DeclareTypeCommand(const std::string
& id
,
930 : DeclarationDefinitionCommand(id
), d_arity(arity
), d_type(t
)
934 size_t DeclareTypeCommand::getArity() const { return d_arity
; }
935 Type
DeclareTypeCommand::getType() const { return d_type
; }
936 void DeclareTypeCommand::invoke(SmtEngine
* smtEngine
)
938 d_commandStatus
= CommandSuccess::instance();
941 Command
* DeclareTypeCommand::exportTo(ExprManager
* exprManager
,
942 ExprManagerMapCollection
& variableMap
)
944 return new DeclareTypeCommand(
945 d_symbol
, d_arity
, d_type
.exportTo(exprManager
, variableMap
));
948 Command
* DeclareTypeCommand::clone() const
950 return new DeclareTypeCommand(d_symbol
, d_arity
, d_type
);
953 std::string
DeclareTypeCommand::getCommandName() const
955 return "declare-sort";
958 /* -------------------------------------------------------------------------- */
959 /* class DefineTypeCommand */
960 /* -------------------------------------------------------------------------- */
962 DefineTypeCommand::DefineTypeCommand(const std::string
& id
, Type t
)
963 : DeclarationDefinitionCommand(id
), d_params(), d_type(t
)
967 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
968 const std::vector
<Type
>& params
,
970 : DeclarationDefinitionCommand(id
), d_params(params
), d_type(t
)
974 const std::vector
<Type
>& DefineTypeCommand::getParameters() const
979 Type
DefineTypeCommand::getType() const { return d_type
; }
980 void DefineTypeCommand::invoke(SmtEngine
* smtEngine
)
982 d_commandStatus
= CommandSuccess::instance();
985 Command
* DefineTypeCommand::exportTo(ExprManager
* exprManager
,
986 ExprManagerMapCollection
& variableMap
)
989 transform(d_params
.begin(),
991 back_inserter(params
),
992 ExportTransformer(exprManager
, variableMap
));
993 Type type
= d_type
.exportTo(exprManager
, variableMap
);
994 return new DefineTypeCommand(d_symbol
, params
, type
);
997 Command
* DefineTypeCommand::clone() const
999 return new DefineTypeCommand(d_symbol
, d_params
, d_type
);
1002 std::string
DefineTypeCommand::getCommandName() const { return "define-sort"; }
1004 /* -------------------------------------------------------------------------- */
1005 /* class DefineFunctionCommand */
1006 /* -------------------------------------------------------------------------- */
1008 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1011 : DeclarationDefinitionCommand(id
),
1018 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
1020 const std::vector
<Expr
>& formals
,
1022 : DeclarationDefinitionCommand(id
),
1029 Expr
DefineFunctionCommand::getFunction() const { return d_func
; }
1030 const std::vector
<Expr
>& DefineFunctionCommand::getFormals() const
1035 Expr
DefineFunctionCommand::getFormula() const { return d_formula
; }
1036 void DefineFunctionCommand::invoke(SmtEngine
* smtEngine
)
1040 if (!d_func
.isNull())
1042 smtEngine
->defineFunction(d_func
, d_formals
, d_formula
);
1044 d_commandStatus
= CommandSuccess::instance();
1046 catch (exception
& e
)
1048 d_commandStatus
= new CommandFailure(e
.what());
1052 Command
* DefineFunctionCommand::exportTo(ExprManager
* exprManager
,
1053 ExprManagerMapCollection
& variableMap
)
1055 Expr func
= d_func
.exportTo(
1056 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1057 vector
<Expr
> formals
;
1058 transform(d_formals
.begin(),
1060 back_inserter(formals
),
1061 ExportTransformer(exprManager
, variableMap
));
1062 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1063 return new DefineFunctionCommand(d_symbol
, func
, formals
, formula
);
1066 Command
* DefineFunctionCommand::clone() const
1068 return new DefineFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1071 std::string
DefineFunctionCommand::getCommandName() const
1073 return "define-fun";
1076 /* -------------------------------------------------------------------------- */
1077 /* class DefineNamedFunctionCommand */
1078 /* -------------------------------------------------------------------------- */
1080 DefineNamedFunctionCommand::DefineNamedFunctionCommand(
1081 const std::string
& id
,
1083 const std::vector
<Expr
>& formals
,
1085 : DefineFunctionCommand(id
, func
, formals
, formula
)
1089 void DefineNamedFunctionCommand::invoke(SmtEngine
* smtEngine
)
1091 this->DefineFunctionCommand::invoke(smtEngine
);
1092 if (!d_func
.isNull() && d_func
.getType().isBoolean())
1094 smtEngine
->addToAssignment(
1095 d_func
.getExprManager()->mkExpr(kind::APPLY
, d_func
));
1097 d_commandStatus
= CommandSuccess::instance();
1100 Command
* DefineNamedFunctionCommand::exportTo(
1101 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1103 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
1104 vector
<Expr
> formals
;
1105 transform(d_formals
.begin(),
1107 back_inserter(formals
),
1108 ExportTransformer(exprManager
, variableMap
));
1109 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
1110 return new DefineNamedFunctionCommand(d_symbol
, func
, formals
, formula
);
1113 Command
* DefineNamedFunctionCommand::clone() const
1115 return new DefineNamedFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
1118 /* -------------------------------------------------------------------------- */
1119 /* class DefineFunctionRecCommand */
1120 /* -------------------------------------------------------------------------- */
1122 DefineFunctionRecCommand::DefineFunctionRecCommand(
1123 Expr func
, const std::vector
<Expr
>& formals
, Expr formula
)
1125 d_funcs
.push_back(func
);
1126 d_formals
.push_back(formals
);
1127 d_formulas
.push_back(formula
);
1130 DefineFunctionRecCommand::DefineFunctionRecCommand(
1131 const std::vector
<Expr
>& funcs
,
1132 const std::vector
<std::vector
<Expr
>>& formals
,
1133 const std::vector
<Expr
>& formulas
)
1135 d_funcs
.insert(d_funcs
.end(), funcs
.begin(), funcs
.end());
1136 d_formals
.insert(d_formals
.end(), formals
.begin(), formals
.end());
1137 d_formulas
.insert(d_formulas
.end(), formulas
.begin(), formulas
.end());
1140 const std::vector
<Expr
>& DefineFunctionRecCommand::getFunctions() const
1145 const std::vector
<std::vector
<Expr
>>& DefineFunctionRecCommand::getFormals()
1151 const std::vector
<Expr
>& DefineFunctionRecCommand::getFormulas() const
1156 void DefineFunctionRecCommand::invoke(SmtEngine
* smtEngine
)
1160 smtEngine
->defineFunctionsRec(d_funcs
, d_formals
, d_formulas
);
1161 d_commandStatus
= CommandSuccess::instance();
1163 catch (exception
& e
)
1165 d_commandStatus
= new CommandFailure(e
.what());
1169 Command
* DefineFunctionRecCommand::exportTo(
1170 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1172 std::vector
<Expr
> funcs
;
1173 for (unsigned i
= 0, size
= d_funcs
.size(); i
< size
; i
++)
1175 Expr func
= d_funcs
[i
].exportTo(
1176 exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
1177 funcs
.push_back(func
);
1179 std::vector
<std::vector
<Expr
>> formals
;
1180 for (unsigned i
= 0, size
= d_formals
.size(); i
< size
; i
++)
1182 std::vector
<Expr
> formals_c
;
1183 transform(d_formals
[i
].begin(),
1185 back_inserter(formals_c
),
1186 ExportTransformer(exprManager
, variableMap
));
1187 formals
.push_back(formals_c
);
1189 std::vector
<Expr
> formulas
;
1190 for (unsigned i
= 0, size
= d_formulas
.size(); i
< size
; i
++)
1192 Expr formula
= d_formulas
[i
].exportTo(exprManager
, variableMap
);
1193 formulas
.push_back(formula
);
1195 return new DefineFunctionRecCommand(funcs
, formals
, formulas
);
1198 Command
* DefineFunctionRecCommand::clone() const
1200 return new DefineFunctionRecCommand(d_funcs
, d_formals
, d_formulas
);
1203 std::string
DefineFunctionRecCommand::getCommandName() const
1205 return "define-fun-rec";
1208 /* -------------------------------------------------------------------------- */
1209 /* class SetUserAttribute */
1210 /* -------------------------------------------------------------------------- */
1212 SetUserAttributeCommand::SetUserAttributeCommand(
1213 const std::string
& attr
,
1215 const std::vector
<Expr
>& expr_values
,
1216 const std::string
& str_value
)
1219 d_expr_values(expr_values
),
1220 d_str_value(str_value
)
1224 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1226 : SetUserAttributeCommand(attr
, expr
, {}, "")
1230 SetUserAttributeCommand::SetUserAttributeCommand(
1231 const std::string
& attr
, Expr expr
, const std::vector
<Expr
>& values
)
1232 : SetUserAttributeCommand(attr
, expr
, values
, "")
1236 SetUserAttributeCommand::SetUserAttributeCommand(const std::string
& attr
,
1238 const std::string
& value
)
1239 : SetUserAttributeCommand(attr
, expr
, {}, value
)
1243 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
)
1247 if (!d_expr
.isNull())
1249 smtEngine
->setUserAttribute(d_attr
, d_expr
, d_expr_values
, d_str_value
);
1251 d_commandStatus
= CommandSuccess::instance();
1253 catch (exception
& e
)
1255 d_commandStatus
= new CommandFailure(e
.what());
1259 Command
* SetUserAttributeCommand::exportTo(
1260 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1262 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
1263 return new SetUserAttributeCommand(d_attr
, expr
, d_expr_values
, d_str_value
);
1266 Command
* SetUserAttributeCommand::clone() const
1268 return new SetUserAttributeCommand(
1269 d_attr
, d_expr
, d_expr_values
, d_str_value
);
1272 std::string
SetUserAttributeCommand::getCommandName() const
1274 return "set-user-attribute";
1277 /* -------------------------------------------------------------------------- */
1278 /* class SimplifyCommand */
1279 /* -------------------------------------------------------------------------- */
1281 SimplifyCommand::SimplifyCommand(Expr term
) : d_term(term
) {}
1282 Expr
SimplifyCommand::getTerm() const { return d_term
; }
1283 void SimplifyCommand::invoke(SmtEngine
* smtEngine
)
1287 d_result
= smtEngine
->simplify(d_term
);
1288 d_commandStatus
= CommandSuccess::instance();
1290 catch (UnsafeInterruptException
& e
)
1292 d_commandStatus
= new CommandInterrupted();
1294 catch (exception
& e
)
1296 d_commandStatus
= new CommandFailure(e
.what());
1300 Expr
SimplifyCommand::getResult() const { return d_result
; }
1301 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1305 this->Command::printResult(out
, verbosity
);
1309 out
<< d_result
<< endl
;
1313 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
,
1314 ExprManagerMapCollection
& variableMap
)
1316 SimplifyCommand
* c
=
1317 new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
1318 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1322 Command
* SimplifyCommand::clone() const
1324 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
1325 c
->d_result
= d_result
;
1329 std::string
SimplifyCommand::getCommandName() const { return "simplify"; }
1331 /* -------------------------------------------------------------------------- */
1332 /* class ExpandDefinitionsCommand */
1333 /* -------------------------------------------------------------------------- */
1335 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) : d_term(term
) {}
1336 Expr
ExpandDefinitionsCommand::getTerm() const { return d_term
; }
1337 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
)
1339 d_result
= smtEngine
->expandDefinitions(d_term
);
1340 d_commandStatus
= CommandSuccess::instance();
1343 Expr
ExpandDefinitionsCommand::getResult() const { return d_result
; }
1344 void ExpandDefinitionsCommand::printResult(std::ostream
& out
,
1345 uint32_t verbosity
) const
1349 this->Command::printResult(out
, verbosity
);
1353 out
<< d_result
<< endl
;
1357 Command
* ExpandDefinitionsCommand::exportTo(
1358 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1360 ExpandDefinitionsCommand
* c
=
1361 new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
1362 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1366 Command
* ExpandDefinitionsCommand::clone() const
1368 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
1369 c
->d_result
= d_result
;
1373 std::string
ExpandDefinitionsCommand::getCommandName() const
1375 return "expand-definitions";
1378 /* -------------------------------------------------------------------------- */
1379 /* class GetValueCommand */
1380 /* -------------------------------------------------------------------------- */
1382 GetValueCommand::GetValueCommand(Expr term
) : d_terms()
1384 d_terms
.push_back(term
);
1387 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
)
1390 PrettyCheckArgument(
1391 terms
.size() >= 1, terms
, "cannot get-value of an empty set of terms");
1394 const std::vector
<Expr
>& GetValueCommand::getTerms() const { return d_terms
; }
1395 void GetValueCommand::invoke(SmtEngine
* smtEngine
)
1399 vector
<Expr
> result
;
1400 ExprManager
* em
= smtEngine
->getExprManager();
1401 NodeManager
* nm
= NodeManager::fromExprManager(em
);
1402 for (const Expr
& e
: d_terms
)
1404 Assert(nm
== NodeManager::fromExprManager(e
.getExprManager()));
1405 smt::SmtScope
scope(smtEngine
);
1406 Node request
= Node::fromExpr(
1407 options::expandDefinitions() ? smtEngine
->expandDefinitions(e
) : e
);
1408 Node value
= Node::fromExpr(smtEngine
->getValue(e
));
1409 if (value
.getType().isInteger() && request
.getType() == nm
->realType())
1411 // Need to wrap in division-by-one so that output printers know this
1412 // is an integer-looking constant that really should be output as
1413 // a rational. Necessary for SMT-LIB standards compliance.
1414 value
= nm
->mkNode(kind::DIVISION
, value
, nm
->mkConst(Rational(1)));
1416 result
.push_back(nm
->mkNode(kind::SEXPR
, request
, value
).toExpr());
1418 d_result
= em
->mkExpr(kind::SEXPR
, result
);
1419 d_commandStatus
= CommandSuccess::instance();
1421 catch (RecoverableModalException
& e
)
1423 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1425 catch (UnsafeInterruptException
& e
)
1427 d_commandStatus
= new CommandInterrupted();
1429 catch (exception
& e
)
1431 d_commandStatus
= new CommandFailure(e
.what());
1435 Expr
GetValueCommand::getResult() const { return d_result
; }
1436 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1440 this->Command::printResult(out
, verbosity
);
1444 expr::ExprDag::Scope
scope(out
, false);
1445 out
<< d_result
<< endl
;
1449 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
,
1450 ExprManagerMapCollection
& variableMap
)
1452 vector
<Expr
> exportedTerms
;
1453 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1457 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1459 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1460 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1464 Command
* GetValueCommand::clone() const
1466 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1467 c
->d_result
= d_result
;
1471 std::string
GetValueCommand::getCommandName() const { return "get-value"; }
1473 /* -------------------------------------------------------------------------- */
1474 /* class GetAssignmentCommand */
1475 /* -------------------------------------------------------------------------- */
1477 GetAssignmentCommand::GetAssignmentCommand() {}
1478 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
)
1482 std::vector
<std::pair
<Expr
, Expr
>> assignments
= smtEngine
->getAssignment();
1483 vector
<SExpr
> sexprs
;
1484 for (const auto& p
: assignments
)
1487 if (p
.first
.getKind() == kind::APPLY
)
1489 v
.emplace_back(SExpr::Keyword(p
.first
.getOperator().toString()));
1493 v
.emplace_back(SExpr::Keyword(p
.first
.toString()));
1495 v
.emplace_back(SExpr::Keyword(p
.second
.toString()));
1496 sexprs
.emplace_back(v
);
1498 d_result
= SExpr(sexprs
);
1499 d_commandStatus
= CommandSuccess::instance();
1501 catch (RecoverableModalException
& e
)
1503 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1505 catch (UnsafeInterruptException
& e
)
1507 d_commandStatus
= new CommandInterrupted();
1509 catch (exception
& e
)
1511 d_commandStatus
= new CommandFailure(e
.what());
1515 SExpr
GetAssignmentCommand::getResult() const { return d_result
; }
1516 void GetAssignmentCommand::printResult(std::ostream
& out
,
1517 uint32_t verbosity
) const
1521 this->Command::printResult(out
, verbosity
);
1525 out
<< d_result
<< endl
;
1529 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
,
1530 ExprManagerMapCollection
& variableMap
)
1532 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1533 c
->d_result
= d_result
;
1537 Command
* GetAssignmentCommand::clone() const
1539 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1540 c
->d_result
= d_result
;
1544 std::string
GetAssignmentCommand::getCommandName() const
1546 return "get-assignment";
1549 /* -------------------------------------------------------------------------- */
1550 /* class GetModelCommand */
1551 /* -------------------------------------------------------------------------- */
1553 GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
1554 void GetModelCommand::invoke(SmtEngine
* smtEngine
)
1558 d_result
= smtEngine
->getModel();
1559 d_smtEngine
= smtEngine
;
1560 d_commandStatus
= CommandSuccess::instance();
1562 catch (RecoverableModalException
& e
)
1564 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1566 catch (UnsafeInterruptException
& e
)
1568 d_commandStatus
= new CommandInterrupted();
1570 catch (exception
& e
)
1572 d_commandStatus
= new CommandFailure(e
.what());
1576 /* Model is private to the library -- for now
1577 Model* GetModelCommand::getResult() const {
1582 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1586 this->Command::printResult(out
, verbosity
);
1594 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
,
1595 ExprManagerMapCollection
& variableMap
)
1597 GetModelCommand
* c
= new GetModelCommand();
1598 c
->d_result
= d_result
;
1599 c
->d_smtEngine
= d_smtEngine
;
1603 Command
* GetModelCommand::clone() const
1605 GetModelCommand
* c
= new GetModelCommand();
1606 c
->d_result
= d_result
;
1607 c
->d_smtEngine
= d_smtEngine
;
1611 std::string
GetModelCommand::getCommandName() const { return "get-model"; }
1613 /* -------------------------------------------------------------------------- */
1614 /* class GetProofCommand */
1615 /* -------------------------------------------------------------------------- */
1617 GetProofCommand::GetProofCommand() : d_smtEngine(nullptr), d_result(nullptr) {}
1618 void GetProofCommand::invoke(SmtEngine
* smtEngine
)
1622 d_smtEngine
= smtEngine
;
1623 d_result
= &smtEngine
->getProof();
1624 d_commandStatus
= CommandSuccess::instance();
1626 catch (RecoverableModalException
& e
)
1628 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1630 catch (UnsafeInterruptException
& e
)
1632 d_commandStatus
= new CommandInterrupted();
1634 catch (exception
& e
)
1636 d_commandStatus
= new CommandFailure(e
.what());
1640 const Proof
& GetProofCommand::getResult() const { return *d_result
; }
1641 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1645 this->Command::printResult(out
, verbosity
);
1649 smt::SmtScope
scope(d_smtEngine
);
1650 d_result
->toStream(out
);
1654 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
,
1655 ExprManagerMapCollection
& variableMap
)
1657 GetProofCommand
* c
= new GetProofCommand();
1658 c
->d_result
= d_result
;
1659 c
->d_smtEngine
= d_smtEngine
;
1663 Command
* GetProofCommand::clone() const
1665 GetProofCommand
* c
= new GetProofCommand();
1666 c
->d_result
= d_result
;
1667 c
->d_smtEngine
= d_smtEngine
;
1671 std::string
GetProofCommand::getCommandName() const { return "get-proof"; }
1673 /* -------------------------------------------------------------------------- */
1674 /* class GetInstantiationsCommand */
1675 /* -------------------------------------------------------------------------- */
1677 GetInstantiationsCommand::GetInstantiationsCommand() : d_smtEngine(nullptr) {}
1678 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
)
1682 d_smtEngine
= smtEngine
;
1683 d_commandStatus
= CommandSuccess::instance();
1685 catch (exception
& e
)
1687 d_commandStatus
= new CommandFailure(e
.what());
1691 void GetInstantiationsCommand::printResult(std::ostream
& out
,
1692 uint32_t verbosity
) const
1696 this->Command::printResult(out
, verbosity
);
1700 d_smtEngine
->printInstantiations(out
);
1704 Command
* GetInstantiationsCommand::exportTo(
1705 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1707 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1708 // c->d_result = d_result;
1709 c
->d_smtEngine
= d_smtEngine
;
1713 Command
* GetInstantiationsCommand::clone() const
1715 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1716 // c->d_result = d_result;
1717 c
->d_smtEngine
= d_smtEngine
;
1721 std::string
GetInstantiationsCommand::getCommandName() const
1723 return "get-instantiations";
1726 /* -------------------------------------------------------------------------- */
1727 /* class GetSynthSolutionCommand */
1728 /* -------------------------------------------------------------------------- */
1730 GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
1731 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
)
1735 d_smtEngine
= smtEngine
;
1736 d_commandStatus
= CommandSuccess::instance();
1738 catch (exception
& e
)
1740 d_commandStatus
= new CommandFailure(e
.what());
1744 void GetSynthSolutionCommand::printResult(std::ostream
& out
,
1745 uint32_t verbosity
) const
1749 this->Command::printResult(out
, verbosity
);
1753 d_smtEngine
->printSynthSolution(out
);
1757 Command
* GetSynthSolutionCommand::exportTo(
1758 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1760 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1761 c
->d_smtEngine
= d_smtEngine
;
1765 Command
* GetSynthSolutionCommand::clone() const
1767 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1768 c
->d_smtEngine
= d_smtEngine
;
1772 std::string
GetSynthSolutionCommand::getCommandName() const
1774 return "get-instantiations";
1777 /* -------------------------------------------------------------------------- */
1778 /* class GetQuantifierEliminationCommand */
1779 /* -------------------------------------------------------------------------- */
1781 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand() : d_expr() {}
1782 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
1783 const Expr
& expr
, bool doFull
)
1784 : d_expr(expr
), d_doFull(doFull
)
1788 Expr
GetQuantifierEliminationCommand::getExpr() const { return d_expr
; }
1789 bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull
; }
1790 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
)
1794 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
1795 d_commandStatus
= CommandSuccess::instance();
1797 catch (exception
& e
)
1799 d_commandStatus
= new CommandFailure(e
.what());
1803 Expr
GetQuantifierEliminationCommand::getResult() const { return d_result
; }
1804 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
,
1805 uint32_t verbosity
) const
1809 this->Command::printResult(out
, verbosity
);
1813 out
<< d_result
<< endl
;
1817 Command
* GetQuantifierEliminationCommand::exportTo(
1818 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1820 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(
1821 d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
1822 c
->d_result
= d_result
;
1826 Command
* GetQuantifierEliminationCommand::clone() const
1828 GetQuantifierEliminationCommand
* c
=
1829 new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
1830 c
->d_result
= d_result
;
1834 std::string
GetQuantifierEliminationCommand::getCommandName() const
1836 return d_doFull
? "get-qe" : "get-qe-disjunct";
1839 /* -------------------------------------------------------------------------- */
1840 /* class GetUnsatAssumptionsCommand */
1841 /* -------------------------------------------------------------------------- */
1843 GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
1845 void GetUnsatAssumptionsCommand::invoke(SmtEngine
* smtEngine
)
1849 d_result
= smtEngine
->getUnsatAssumptions();
1850 d_commandStatus
= CommandSuccess::instance();
1852 catch (RecoverableModalException
& e
)
1854 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1856 catch (exception
& e
)
1858 d_commandStatus
= new CommandFailure(e
.what());
1862 std::vector
<Expr
> GetUnsatAssumptionsCommand::getResult() const
1867 void GetUnsatAssumptionsCommand::printResult(std::ostream
& out
,
1868 uint32_t verbosity
) const
1872 this->Command::printResult(out
, verbosity
);
1876 out
<< d_result
<< endl
;
1880 Command
* GetUnsatAssumptionsCommand::exportTo(
1881 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1883 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
1884 c
->d_result
= d_result
;
1888 Command
* GetUnsatAssumptionsCommand::clone() const
1890 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
1891 c
->d_result
= d_result
;
1895 std::string
GetUnsatAssumptionsCommand::getCommandName() const
1897 return "get-unsat-assumptions";
1900 /* -------------------------------------------------------------------------- */
1901 /* class GetUnsatCoreCommand */
1902 /* -------------------------------------------------------------------------- */
1904 GetUnsatCoreCommand::GetUnsatCoreCommand() {}
1905 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
)
1909 d_result
= smtEngine
->getUnsatCore();
1910 d_commandStatus
= CommandSuccess::instance();
1912 catch (RecoverableModalException
& e
)
1914 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1916 catch (exception
& e
)
1918 d_commandStatus
= new CommandFailure(e
.what());
1922 void GetUnsatCoreCommand::printResult(std::ostream
& out
,
1923 uint32_t verbosity
) const
1927 this->Command::printResult(out
, verbosity
);
1931 d_result
.toStream(out
);
1935 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const
1937 // of course, this will be empty if the command hasn't been invoked yet
1941 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
,
1942 ExprManagerMapCollection
& variableMap
)
1944 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
1945 c
->d_result
= d_result
;
1949 Command
* GetUnsatCoreCommand::clone() const
1951 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
1952 c
->d_result
= d_result
;
1956 std::string
GetUnsatCoreCommand::getCommandName() const
1958 return "get-unsat-core";
1961 /* -------------------------------------------------------------------------- */
1962 /* class GetAssertionsCommand */
1963 /* -------------------------------------------------------------------------- */
1965 GetAssertionsCommand::GetAssertionsCommand() {}
1966 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
1971 const vector
<Expr
> v
= smtEngine
->getAssertions();
1973 copy(v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n"));
1975 d_result
= ss
.str();
1976 d_commandStatus
= CommandSuccess::instance();
1978 catch (exception
& e
)
1980 d_commandStatus
= new CommandFailure(e
.what());
1984 std::string
GetAssertionsCommand::getResult() const { return d_result
; }
1985 void GetAssertionsCommand::printResult(std::ostream
& out
,
1986 uint32_t verbosity
) const
1990 this->Command::printResult(out
, verbosity
);
1998 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
,
1999 ExprManagerMapCollection
& variableMap
)
2001 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2002 c
->d_result
= d_result
;
2006 Command
* GetAssertionsCommand::clone() const
2008 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2009 c
->d_result
= d_result
;
2013 std::string
GetAssertionsCommand::getCommandName() const
2015 return "get-assertions";
2018 /* -------------------------------------------------------------------------- */
2019 /* class SetBenchmarkStatusCommand */
2020 /* -------------------------------------------------------------------------- */
2022 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
)
2027 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const
2032 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
)
2038 SExpr status
= SExpr(ss
.str());
2039 smtEngine
->setInfo("status", status
);
2040 d_commandStatus
= CommandSuccess::instance();
2042 catch (exception
& e
)
2044 d_commandStatus
= new CommandFailure(e
.what());
2048 Command
* SetBenchmarkStatusCommand::exportTo(
2049 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2051 return new SetBenchmarkStatusCommand(d_status
);
2054 Command
* SetBenchmarkStatusCommand::clone() const
2056 return new SetBenchmarkStatusCommand(d_status
);
2059 std::string
SetBenchmarkStatusCommand::getCommandName() const
2064 /* -------------------------------------------------------------------------- */
2065 /* class SetBenchmarkLogicCommand */
2066 /* -------------------------------------------------------------------------- */
2068 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
)
2073 std::string
SetBenchmarkLogicCommand::getLogic() const { return d_logic
; }
2074 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
)
2078 smtEngine
->setLogic(d_logic
);
2079 d_commandStatus
= CommandSuccess::instance();
2081 catch (exception
& e
)
2083 d_commandStatus
= new CommandFailure(e
.what());
2087 Command
* SetBenchmarkLogicCommand::exportTo(
2088 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2090 return new SetBenchmarkLogicCommand(d_logic
);
2093 Command
* SetBenchmarkLogicCommand::clone() const
2095 return new SetBenchmarkLogicCommand(d_logic
);
2098 std::string
SetBenchmarkLogicCommand::getCommandName() const
2103 /* -------------------------------------------------------------------------- */
2104 /* class SetInfoCommand */
2105 /* -------------------------------------------------------------------------- */
2107 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
)
2108 : d_flag(flag
), d_sexpr(sexpr
)
2112 std::string
SetInfoCommand::getFlag() const { return d_flag
; }
2113 SExpr
SetInfoCommand::getSExpr() const { return d_sexpr
; }
2114 void SetInfoCommand::invoke(SmtEngine
* smtEngine
)
2118 smtEngine
->setInfo(d_flag
, d_sexpr
);
2119 d_commandStatus
= CommandSuccess::instance();
2121 catch (UnrecognizedOptionException
&)
2123 // As per SMT-LIB spec, silently accept unknown set-info keys
2124 d_commandStatus
= CommandSuccess::instance();
2126 catch (exception
& e
)
2128 d_commandStatus
= new CommandFailure(e
.what());
2132 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
,
2133 ExprManagerMapCollection
& variableMap
)
2135 return new SetInfoCommand(d_flag
, d_sexpr
);
2138 Command
* SetInfoCommand::clone() const
2140 return new SetInfoCommand(d_flag
, d_sexpr
);
2143 std::string
SetInfoCommand::getCommandName() const { return "set-info"; }
2145 /* -------------------------------------------------------------------------- */
2146 /* class GetInfoCommand */
2147 /* -------------------------------------------------------------------------- */
2149 GetInfoCommand::GetInfoCommand(std::string flag
) : d_flag(flag
) {}
2150 std::string
GetInfoCommand::getFlag() const { return d_flag
; }
2151 void GetInfoCommand::invoke(SmtEngine
* smtEngine
)
2156 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
2157 v
.push_back(smtEngine
->getInfo(d_flag
));
2159 if (d_flag
== "all-options" || d_flag
== "all-statistics")
2161 ss
<< PrettySExprs(true);
2164 d_result
= ss
.str();
2165 d_commandStatus
= CommandSuccess::instance();
2167 catch (UnrecognizedOptionException
&)
2169 d_commandStatus
= new CommandUnsupported();
2171 catch (exception
& e
)
2173 d_commandStatus
= new CommandFailure(e
.what());
2177 std::string
GetInfoCommand::getResult() const { return d_result
; }
2178 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2182 this->Command::printResult(out
, verbosity
);
2184 else if (d_result
!= "")
2186 out
<< d_result
<< endl
;
2190 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
,
2191 ExprManagerMapCollection
& variableMap
)
2193 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2194 c
->d_result
= d_result
;
2198 Command
* GetInfoCommand::clone() const
2200 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2201 c
->d_result
= d_result
;
2205 std::string
GetInfoCommand::getCommandName() const { return "get-info"; }
2207 /* -------------------------------------------------------------------------- */
2208 /* class SetOptionCommand */
2209 /* -------------------------------------------------------------------------- */
2211 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
)
2212 : d_flag(flag
), d_sexpr(sexpr
)
2216 std::string
SetOptionCommand::getFlag() const { return d_flag
; }
2217 SExpr
SetOptionCommand::getSExpr() const { return d_sexpr
; }
2218 void SetOptionCommand::invoke(SmtEngine
* smtEngine
)
2222 smtEngine
->setOption(d_flag
, d_sexpr
);
2223 d_commandStatus
= CommandSuccess::instance();
2225 catch (UnrecognizedOptionException
&)
2227 d_commandStatus
= new CommandUnsupported();
2229 catch (exception
& e
)
2231 d_commandStatus
= new CommandFailure(e
.what());
2235 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
,
2236 ExprManagerMapCollection
& variableMap
)
2238 return new SetOptionCommand(d_flag
, d_sexpr
);
2241 Command
* SetOptionCommand::clone() const
2243 return new SetOptionCommand(d_flag
, d_sexpr
);
2246 std::string
SetOptionCommand::getCommandName() const { return "set-option"; }
2248 /* -------------------------------------------------------------------------- */
2249 /* class GetOptionCommand */
2250 /* -------------------------------------------------------------------------- */
2252 GetOptionCommand::GetOptionCommand(std::string flag
) : d_flag(flag
) {}
2253 std::string
GetOptionCommand::getFlag() const { return d_flag
; }
2254 void GetOptionCommand::invoke(SmtEngine
* smtEngine
)
2258 SExpr res
= smtEngine
->getOption(d_flag
);
2259 d_result
= res
.toString();
2260 d_commandStatus
= CommandSuccess::instance();
2262 catch (UnrecognizedOptionException
&)
2264 d_commandStatus
= new CommandUnsupported();
2266 catch (exception
& e
)
2268 d_commandStatus
= new CommandFailure(e
.what());
2272 std::string
GetOptionCommand::getResult() const { return d_result
; }
2273 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2277 this->Command::printResult(out
, verbosity
);
2279 else if (d_result
!= "")
2281 out
<< d_result
<< endl
;
2285 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
,
2286 ExprManagerMapCollection
& variableMap
)
2288 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2289 c
->d_result
= d_result
;
2293 Command
* GetOptionCommand::clone() const
2295 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2296 c
->d_result
= d_result
;
2300 std::string
GetOptionCommand::getCommandName() const { return "get-option"; }
2302 /* -------------------------------------------------------------------------- */
2303 /* class SetExpressionNameCommand */
2304 /* -------------------------------------------------------------------------- */
2306 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
)
2307 : d_expr(expr
), d_name(name
)
2311 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
)
2313 smtEngine
->setExpressionName(d_expr
, d_name
);
2314 d_commandStatus
= CommandSuccess::instance();
2317 Command
* SetExpressionNameCommand::exportTo(
2318 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2320 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(
2321 d_expr
.exportTo(exprManager
, variableMap
), d_name
);
2325 Command
* SetExpressionNameCommand::clone() const
2327 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
2331 std::string
SetExpressionNameCommand::getCommandName() const
2333 return "set-expr-name";
2336 /* -------------------------------------------------------------------------- */
2337 /* class DatatypeDeclarationCommand */
2338 /* -------------------------------------------------------------------------- */
2340 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2341 const DatatypeType
& datatype
)
2344 d_datatypes
.push_back(datatype
);
2347 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2348 const std::vector
<DatatypeType
>& datatypes
)
2349 : d_datatypes(datatypes
)
2353 const std::vector
<DatatypeType
>& DatatypeDeclarationCommand::getDatatypes()
2359 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
)
2361 d_commandStatus
= CommandSuccess::instance();
2364 Command
* DatatypeDeclarationCommand::exportTo(
2365 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2367 throw ExportUnsupportedException(
2368 "export of DatatypeDeclarationCommand unsupported");
2371 Command
* DatatypeDeclarationCommand::clone() const
2373 return new DatatypeDeclarationCommand(d_datatypes
);
2376 std::string
DatatypeDeclarationCommand::getCommandName() const
2378 return "declare-datatypes";
2381 /* -------------------------------------------------------------------------- */
2382 /* class RewriteRuleCommand */
2383 /* -------------------------------------------------------------------------- */
2385 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
2386 const std::vector
<Expr
>& guards
,
2389 const Triggers
& triggers
)
2394 d_triggers(triggers
)
2398 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
2401 : d_vars(vars
), d_head(head
), d_body(body
)
2405 const std::vector
<Expr
>& RewriteRuleCommand::getVars() const { return d_vars
; }
2406 const std::vector
<Expr
>& RewriteRuleCommand::getGuards() const
2411 Expr
RewriteRuleCommand::getHead() const { return d_head
; }
2412 Expr
RewriteRuleCommand::getBody() const { return d_body
; }
2413 const RewriteRuleCommand::Triggers
& RewriteRuleCommand::getTriggers() const
2418 void RewriteRuleCommand::invoke(SmtEngine
* smtEngine
)
2422 ExprManager
* em
= smtEngine
->getExprManager();
2423 /** build vars list */
2424 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
2425 /** build guards list */
2427 if (d_guards
.size() == 0)
2428 guards
= em
->mkConst
<bool>(true);
2429 else if (d_guards
.size() == 1)
2430 guards
= d_guards
[0];
2432 guards
= em
->mkExpr(kind::AND
, d_guards
);
2433 /** build expression */
2435 if (d_triggers
.empty())
2437 expr
= em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, d_head
, d_body
);
2441 /** build triggers list */
2442 std::vector
<Expr
> vtriggers
;
2443 vtriggers
.reserve(d_triggers
.size());
2444 for (Triggers::const_iterator i
= d_triggers
.begin(),
2445 end
= d_triggers
.end();
2449 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
, *i
));
2451 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
, vtriggers
);
2453 em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, d_head
, d_body
, triggers
);
2455 smtEngine
->assertFormula(expr
);
2456 d_commandStatus
= CommandSuccess::instance();
2458 catch (exception
& e
)
2460 d_commandStatus
= new CommandFailure(e
.what());
2464 Command
* RewriteRuleCommand::exportTo(ExprManager
* exprManager
,
2465 ExprManagerMapCollection
& variableMap
)
2467 /** Convert variables */
2468 VExpr vars
= ExportTo(exprManager
, variableMap
, d_vars
);
2469 /** Convert guards */
2470 VExpr guards
= ExportTo(exprManager
, variableMap
, d_guards
);
2471 /** Convert triggers */
2473 triggers
.reserve(d_triggers
.size());
2474 for (const std::vector
<Expr
>& trigger_list
: d_triggers
)
2476 triggers
.push_back(ExportTo(exprManager
, variableMap
, trigger_list
));
2478 /** Convert head and body */
2479 Expr head
= d_head
.exportTo(exprManager
, variableMap
);
2480 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
2481 /** Create the converted rules */
2482 return new RewriteRuleCommand(vars
, guards
, head
, body
, triggers
);
2485 Command
* RewriteRuleCommand::clone() const
2487 return new RewriteRuleCommand(d_vars
, d_guards
, d_head
, d_body
, d_triggers
);
2490 std::string
RewriteRuleCommand::getCommandName() const
2492 return "rewrite-rule";
2495 /* -------------------------------------------------------------------------- */
2496 /* class PropagateRuleCommand */
2497 /* -------------------------------------------------------------------------- */
2499 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
2500 const std::vector
<Expr
>& guards
,
2501 const std::vector
<Expr
>& heads
,
2503 const Triggers
& triggers
,
2509 d_triggers(triggers
),
2510 d_deduction(deduction
)
2514 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
2515 const std::vector
<Expr
>& heads
,
2518 : d_vars(vars
), d_heads(heads
), d_body(body
), d_deduction(deduction
)
2522 const std::vector
<Expr
>& PropagateRuleCommand::getVars() const
2527 const std::vector
<Expr
>& PropagateRuleCommand::getGuards() const
2532 const std::vector
<Expr
>& PropagateRuleCommand::getHeads() const
2537 Expr
PropagateRuleCommand::getBody() const { return d_body
; }
2538 const PropagateRuleCommand::Triggers
& PropagateRuleCommand::getTriggers() const
2543 bool PropagateRuleCommand::isDeduction() const { return d_deduction
; }
2544 void PropagateRuleCommand::invoke(SmtEngine
* smtEngine
)
2548 ExprManager
* em
= smtEngine
->getExprManager();
2549 /** build vars list */
2550 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
2551 /** build guards list */
2553 if (d_guards
.size() == 0)
2554 guards
= em
->mkConst
<bool>(true);
2555 else if (d_guards
.size() == 1)
2556 guards
= d_guards
[0];
2558 guards
= em
->mkExpr(kind::AND
, d_guards
);
2559 /** build heads list */
2561 if (d_heads
.size() == 1)
2564 heads
= em
->mkExpr(kind::AND
, d_heads
);
2565 /** build expression */
2567 if (d_triggers
.empty())
2569 expr
= em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, heads
, d_body
);
2573 /** build triggers list */
2574 std::vector
<Expr
> vtriggers
;
2575 vtriggers
.reserve(d_triggers
.size());
2576 for (Triggers::const_iterator i
= d_triggers
.begin(),
2577 end
= d_triggers
.end();
2581 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
, *i
));
2583 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
, vtriggers
);
2585 em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, heads
, d_body
, triggers
);
2587 smtEngine
->assertFormula(expr
);
2588 d_commandStatus
= CommandSuccess::instance();
2590 catch (exception
& e
)
2592 d_commandStatus
= new CommandFailure(e
.what());
2596 Command
* PropagateRuleCommand::exportTo(ExprManager
* exprManager
,
2597 ExprManagerMapCollection
& variableMap
)
2599 /** Convert variables */
2600 VExpr vars
= ExportTo(exprManager
, variableMap
, d_vars
);
2601 /** Convert guards */
2602 VExpr guards
= ExportTo(exprManager
, variableMap
, d_guards
);
2603 /** Convert heads */
2604 VExpr heads
= ExportTo(exprManager
, variableMap
, d_heads
);
2605 /** Convert triggers */
2607 triggers
.reserve(d_triggers
.size());
2608 for (const std::vector
<Expr
>& trigger_list
: d_triggers
)
2610 triggers
.push_back(ExportTo(exprManager
, variableMap
, trigger_list
));
2612 /** Convert head and body */
2613 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
2614 /** Create the converted rules */
2615 return new PropagateRuleCommand(vars
, guards
, heads
, body
, triggers
);
2618 Command
* PropagateRuleCommand::clone() const
2620 return new PropagateRuleCommand(
2621 d_vars
, d_guards
, d_heads
, d_body
, d_triggers
);
2624 std::string
PropagateRuleCommand::getCommandName() const
2626 return "propagate-rule";