1 /********************* */
4 ** Top contributors (to current version):
5 ** Tim King, Morgan Deters, Aina Niemetz
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 special marker 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, but ugly.
1414 value
= nm
->mkNode(kind::APPLY_TYPE_ASCRIPTION
,
1415 nm
->mkConst(AscriptionType(em
->realType())),
1418 result
.push_back(nm
->mkNode(kind::SEXPR
, request
, value
).toExpr());
1420 d_result
= em
->mkExpr(kind::SEXPR
, result
);
1421 d_commandStatus
= CommandSuccess::instance();
1423 catch (RecoverableModalException
& e
)
1425 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1427 catch (UnsafeInterruptException
& e
)
1429 d_commandStatus
= new CommandInterrupted();
1431 catch (exception
& e
)
1433 d_commandStatus
= new CommandFailure(e
.what());
1437 Expr
GetValueCommand::getResult() const { return d_result
; }
1438 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1442 this->Command::printResult(out
, verbosity
);
1446 expr::ExprDag::Scope
scope(out
, false);
1447 out
<< d_result
<< endl
;
1451 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
,
1452 ExprManagerMapCollection
& variableMap
)
1454 vector
<Expr
> exportedTerms
;
1455 for (std::vector
<Expr
>::const_iterator i
= d_terms
.begin();
1459 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1461 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1462 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1466 Command
* GetValueCommand::clone() const
1468 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1469 c
->d_result
= d_result
;
1473 std::string
GetValueCommand::getCommandName() const { return "get-value"; }
1475 /* -------------------------------------------------------------------------- */
1476 /* class GetAssignmentCommand */
1477 /* -------------------------------------------------------------------------- */
1479 GetAssignmentCommand::GetAssignmentCommand() {}
1480 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
)
1484 std::vector
<std::pair
<Expr
, Expr
>> assignments
= smtEngine
->getAssignment();
1485 vector
<SExpr
> sexprs
;
1486 for (const auto& p
: assignments
)
1489 if (p
.first
.getKind() == kind::APPLY
)
1491 v
.emplace_back(SExpr::Keyword(p
.first
.getOperator().toString()));
1495 v
.emplace_back(SExpr::Keyword(p
.first
.toString()));
1497 v
.emplace_back(SExpr::Keyword(p
.second
.toString()));
1498 sexprs
.emplace_back(v
);
1500 d_result
= SExpr(sexprs
);
1501 d_commandStatus
= CommandSuccess::instance();
1503 catch (RecoverableModalException
& e
)
1505 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1507 catch (UnsafeInterruptException
& e
)
1509 d_commandStatus
= new CommandInterrupted();
1511 catch (exception
& e
)
1513 d_commandStatus
= new CommandFailure(e
.what());
1517 SExpr
GetAssignmentCommand::getResult() const { return d_result
; }
1518 void GetAssignmentCommand::printResult(std::ostream
& out
,
1519 uint32_t verbosity
) const
1523 this->Command::printResult(out
, verbosity
);
1527 out
<< d_result
<< endl
;
1531 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
,
1532 ExprManagerMapCollection
& variableMap
)
1534 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1535 c
->d_result
= d_result
;
1539 Command
* GetAssignmentCommand::clone() const
1541 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1542 c
->d_result
= d_result
;
1546 std::string
GetAssignmentCommand::getCommandName() const
1548 return "get-assignment";
1551 /* -------------------------------------------------------------------------- */
1552 /* class GetModelCommand */
1553 /* -------------------------------------------------------------------------- */
1555 GetModelCommand::GetModelCommand() : d_result(nullptr), d_smtEngine(nullptr) {}
1556 void GetModelCommand::invoke(SmtEngine
* smtEngine
)
1560 d_result
= smtEngine
->getModel();
1561 d_smtEngine
= smtEngine
;
1562 d_commandStatus
= CommandSuccess::instance();
1564 catch (RecoverableModalException
& e
)
1566 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1568 catch (UnsafeInterruptException
& e
)
1570 d_commandStatus
= new CommandInterrupted();
1572 catch (exception
& e
)
1574 d_commandStatus
= new CommandFailure(e
.what());
1578 /* Model is private to the library -- for now
1579 Model* GetModelCommand::getResult() const {
1584 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1588 this->Command::printResult(out
, verbosity
);
1596 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
,
1597 ExprManagerMapCollection
& variableMap
)
1599 GetModelCommand
* c
= new GetModelCommand();
1600 c
->d_result
= d_result
;
1601 c
->d_smtEngine
= d_smtEngine
;
1605 Command
* GetModelCommand::clone() const
1607 GetModelCommand
* c
= new GetModelCommand();
1608 c
->d_result
= d_result
;
1609 c
->d_smtEngine
= d_smtEngine
;
1613 std::string
GetModelCommand::getCommandName() const { return "get-model"; }
1615 /* -------------------------------------------------------------------------- */
1616 /* class GetProofCommand */
1617 /* -------------------------------------------------------------------------- */
1619 GetProofCommand::GetProofCommand() : d_smtEngine(nullptr), d_result(nullptr) {}
1620 void GetProofCommand::invoke(SmtEngine
* smtEngine
)
1624 d_smtEngine
= smtEngine
;
1625 d_result
= &smtEngine
->getProof();
1626 d_commandStatus
= CommandSuccess::instance();
1628 catch (RecoverableModalException
& e
)
1630 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1632 catch (UnsafeInterruptException
& e
)
1634 d_commandStatus
= new CommandInterrupted();
1636 catch (exception
& e
)
1638 d_commandStatus
= new CommandFailure(e
.what());
1642 const Proof
& GetProofCommand::getResult() const { return *d_result
; }
1643 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
1647 this->Command::printResult(out
, verbosity
);
1651 smt::SmtScope
scope(d_smtEngine
);
1652 d_result
->toStream(out
);
1656 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
,
1657 ExprManagerMapCollection
& variableMap
)
1659 GetProofCommand
* c
= new GetProofCommand();
1660 c
->d_result
= d_result
;
1661 c
->d_smtEngine
= d_smtEngine
;
1665 Command
* GetProofCommand::clone() const
1667 GetProofCommand
* c
= new GetProofCommand();
1668 c
->d_result
= d_result
;
1669 c
->d_smtEngine
= d_smtEngine
;
1673 std::string
GetProofCommand::getCommandName() const { return "get-proof"; }
1675 /* -------------------------------------------------------------------------- */
1676 /* class GetInstantiationsCommand */
1677 /* -------------------------------------------------------------------------- */
1679 GetInstantiationsCommand::GetInstantiationsCommand() : d_smtEngine(nullptr) {}
1680 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
)
1684 d_smtEngine
= smtEngine
;
1685 d_commandStatus
= CommandSuccess::instance();
1687 catch (exception
& e
)
1689 d_commandStatus
= new CommandFailure(e
.what());
1693 void GetInstantiationsCommand::printResult(std::ostream
& out
,
1694 uint32_t verbosity
) const
1698 this->Command::printResult(out
, verbosity
);
1702 d_smtEngine
->printInstantiations(out
);
1706 Command
* GetInstantiationsCommand::exportTo(
1707 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1709 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1710 // c->d_result = d_result;
1711 c
->d_smtEngine
= d_smtEngine
;
1715 Command
* GetInstantiationsCommand::clone() const
1717 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1718 // c->d_result = d_result;
1719 c
->d_smtEngine
= d_smtEngine
;
1723 std::string
GetInstantiationsCommand::getCommandName() const
1725 return "get-instantiations";
1728 /* -------------------------------------------------------------------------- */
1729 /* class GetSynthSolutionCommand */
1730 /* -------------------------------------------------------------------------- */
1732 GetSynthSolutionCommand::GetSynthSolutionCommand() : d_smtEngine(nullptr) {}
1733 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
)
1737 d_smtEngine
= smtEngine
;
1738 d_commandStatus
= CommandSuccess::instance();
1740 catch (exception
& e
)
1742 d_commandStatus
= new CommandFailure(e
.what());
1746 void GetSynthSolutionCommand::printResult(std::ostream
& out
,
1747 uint32_t verbosity
) const
1751 this->Command::printResult(out
, verbosity
);
1755 d_smtEngine
->printSynthSolution(out
);
1759 Command
* GetSynthSolutionCommand::exportTo(
1760 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1762 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1763 c
->d_smtEngine
= d_smtEngine
;
1767 Command
* GetSynthSolutionCommand::clone() const
1769 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1770 c
->d_smtEngine
= d_smtEngine
;
1774 std::string
GetSynthSolutionCommand::getCommandName() const
1776 return "get-instantiations";
1779 /* -------------------------------------------------------------------------- */
1780 /* class GetQuantifierEliminationCommand */
1781 /* -------------------------------------------------------------------------- */
1783 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand() : d_expr() {}
1784 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(
1785 const Expr
& expr
, bool doFull
)
1786 : d_expr(expr
), d_doFull(doFull
)
1790 Expr
GetQuantifierEliminationCommand::getExpr() const { return d_expr
; }
1791 bool GetQuantifierEliminationCommand::getDoFull() const { return d_doFull
; }
1792 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
)
1796 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
1797 d_commandStatus
= CommandSuccess::instance();
1799 catch (exception
& e
)
1801 d_commandStatus
= new CommandFailure(e
.what());
1805 Expr
GetQuantifierEliminationCommand::getResult() const { return d_result
; }
1806 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
,
1807 uint32_t verbosity
) const
1811 this->Command::printResult(out
, verbosity
);
1815 out
<< d_result
<< endl
;
1819 Command
* GetQuantifierEliminationCommand::exportTo(
1820 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1822 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(
1823 d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
1824 c
->d_result
= d_result
;
1828 Command
* GetQuantifierEliminationCommand::clone() const
1830 GetQuantifierEliminationCommand
* c
=
1831 new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
1832 c
->d_result
= d_result
;
1836 std::string
GetQuantifierEliminationCommand::getCommandName() const
1838 return d_doFull
? "get-qe" : "get-qe-disjunct";
1841 /* -------------------------------------------------------------------------- */
1842 /* class GetUnsatAssumptionsCommand */
1843 /* -------------------------------------------------------------------------- */
1845 GetUnsatAssumptionsCommand::GetUnsatAssumptionsCommand() {}
1847 void GetUnsatAssumptionsCommand::invoke(SmtEngine
* smtEngine
)
1851 d_result
= smtEngine
->getUnsatAssumptions();
1852 d_commandStatus
= CommandSuccess::instance();
1854 catch (RecoverableModalException
& e
)
1856 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1858 catch (exception
& e
)
1860 d_commandStatus
= new CommandFailure(e
.what());
1864 std::vector
<Expr
> GetUnsatAssumptionsCommand::getResult() const
1869 void GetUnsatAssumptionsCommand::printResult(std::ostream
& out
,
1870 uint32_t verbosity
) const
1874 this->Command::printResult(out
, verbosity
);
1878 out
<< d_result
<< endl
;
1882 Command
* GetUnsatAssumptionsCommand::exportTo(
1883 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
1885 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
1886 c
->d_result
= d_result
;
1890 Command
* GetUnsatAssumptionsCommand::clone() const
1892 GetUnsatAssumptionsCommand
* c
= new GetUnsatAssumptionsCommand
;
1893 c
->d_result
= d_result
;
1897 std::string
GetUnsatAssumptionsCommand::getCommandName() const
1899 return "get-unsat-assumptions";
1902 /* -------------------------------------------------------------------------- */
1903 /* class GetUnsatCoreCommand */
1904 /* -------------------------------------------------------------------------- */
1906 GetUnsatCoreCommand::GetUnsatCoreCommand() {}
1907 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
)
1911 d_result
= smtEngine
->getUnsatCore();
1912 d_commandStatus
= CommandSuccess::instance();
1914 catch (RecoverableModalException
& e
)
1916 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1918 catch (exception
& e
)
1920 d_commandStatus
= new CommandFailure(e
.what());
1924 void GetUnsatCoreCommand::printResult(std::ostream
& out
,
1925 uint32_t verbosity
) const
1929 this->Command::printResult(out
, verbosity
);
1933 d_result
.toStream(out
);
1937 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const
1939 // of course, this will be empty if the command hasn't been invoked yet
1943 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
,
1944 ExprManagerMapCollection
& variableMap
)
1946 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
1947 c
->d_result
= d_result
;
1951 Command
* GetUnsatCoreCommand::clone() const
1953 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
1954 c
->d_result
= d_result
;
1958 std::string
GetUnsatCoreCommand::getCommandName() const
1960 return "get-unsat-core";
1963 /* -------------------------------------------------------------------------- */
1964 /* class GetAssertionsCommand */
1965 /* -------------------------------------------------------------------------- */
1967 GetAssertionsCommand::GetAssertionsCommand() {}
1968 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
)
1973 const vector
<Expr
> v
= smtEngine
->getAssertions();
1975 copy(v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n"));
1977 d_result
= ss
.str();
1978 d_commandStatus
= CommandSuccess::instance();
1980 catch (exception
& e
)
1982 d_commandStatus
= new CommandFailure(e
.what());
1986 std::string
GetAssertionsCommand::getResult() const { return d_result
; }
1987 void GetAssertionsCommand::printResult(std::ostream
& out
,
1988 uint32_t verbosity
) const
1992 this->Command::printResult(out
, verbosity
);
2000 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
,
2001 ExprManagerMapCollection
& variableMap
)
2003 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2004 c
->d_result
= d_result
;
2008 Command
* GetAssertionsCommand::clone() const
2010 GetAssertionsCommand
* c
= new GetAssertionsCommand();
2011 c
->d_result
= d_result
;
2015 std::string
GetAssertionsCommand::getCommandName() const
2017 return "get-assertions";
2020 /* -------------------------------------------------------------------------- */
2021 /* class SetBenchmarkStatusCommand */
2022 /* -------------------------------------------------------------------------- */
2024 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
)
2029 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const
2034 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
)
2040 SExpr status
= SExpr(ss
.str());
2041 smtEngine
->setInfo("status", status
);
2042 d_commandStatus
= CommandSuccess::instance();
2044 catch (exception
& e
)
2046 d_commandStatus
= new CommandFailure(e
.what());
2050 Command
* SetBenchmarkStatusCommand::exportTo(
2051 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2053 return new SetBenchmarkStatusCommand(d_status
);
2056 Command
* SetBenchmarkStatusCommand::clone() const
2058 return new SetBenchmarkStatusCommand(d_status
);
2061 std::string
SetBenchmarkStatusCommand::getCommandName() const
2066 /* -------------------------------------------------------------------------- */
2067 /* class SetBenchmarkLogicCommand */
2068 /* -------------------------------------------------------------------------- */
2070 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
)
2075 std::string
SetBenchmarkLogicCommand::getLogic() const { return d_logic
; }
2076 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
)
2080 smtEngine
->setLogic(d_logic
);
2081 d_commandStatus
= CommandSuccess::instance();
2083 catch (exception
& e
)
2085 d_commandStatus
= new CommandFailure(e
.what());
2089 Command
* SetBenchmarkLogicCommand::exportTo(
2090 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2092 return new SetBenchmarkLogicCommand(d_logic
);
2095 Command
* SetBenchmarkLogicCommand::clone() const
2097 return new SetBenchmarkLogicCommand(d_logic
);
2100 std::string
SetBenchmarkLogicCommand::getCommandName() const
2105 /* -------------------------------------------------------------------------- */
2106 /* class SetInfoCommand */
2107 /* -------------------------------------------------------------------------- */
2109 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
)
2110 : d_flag(flag
), d_sexpr(sexpr
)
2114 std::string
SetInfoCommand::getFlag() const { return d_flag
; }
2115 SExpr
SetInfoCommand::getSExpr() const { return d_sexpr
; }
2116 void SetInfoCommand::invoke(SmtEngine
* smtEngine
)
2120 smtEngine
->setInfo(d_flag
, d_sexpr
);
2121 d_commandStatus
= CommandSuccess::instance();
2123 catch (UnrecognizedOptionException
&)
2125 // As per SMT-LIB spec, silently accept unknown set-info keys
2126 d_commandStatus
= CommandSuccess::instance();
2128 catch (exception
& e
)
2130 d_commandStatus
= new CommandFailure(e
.what());
2134 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
,
2135 ExprManagerMapCollection
& variableMap
)
2137 return new SetInfoCommand(d_flag
, d_sexpr
);
2140 Command
* SetInfoCommand::clone() const
2142 return new SetInfoCommand(d_flag
, d_sexpr
);
2145 std::string
SetInfoCommand::getCommandName() const { return "set-info"; }
2147 /* -------------------------------------------------------------------------- */
2148 /* class GetInfoCommand */
2149 /* -------------------------------------------------------------------------- */
2151 GetInfoCommand::GetInfoCommand(std::string flag
) : d_flag(flag
) {}
2152 std::string
GetInfoCommand::getFlag() const { return d_flag
; }
2153 void GetInfoCommand::invoke(SmtEngine
* smtEngine
)
2158 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
2159 v
.push_back(smtEngine
->getInfo(d_flag
));
2161 if (d_flag
== "all-options" || d_flag
== "all-statistics")
2163 ss
<< PrettySExprs(true);
2166 d_result
= ss
.str();
2167 d_commandStatus
= CommandSuccess::instance();
2169 catch (UnrecognizedOptionException
&)
2171 d_commandStatus
= new CommandUnsupported();
2173 catch (exception
& e
)
2175 d_commandStatus
= new CommandFailure(e
.what());
2179 std::string
GetInfoCommand::getResult() const { return d_result
; }
2180 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2184 this->Command::printResult(out
, verbosity
);
2186 else if (d_result
!= "")
2188 out
<< d_result
<< endl
;
2192 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
,
2193 ExprManagerMapCollection
& variableMap
)
2195 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2196 c
->d_result
= d_result
;
2200 Command
* GetInfoCommand::clone() const
2202 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
2203 c
->d_result
= d_result
;
2207 std::string
GetInfoCommand::getCommandName() const { return "get-info"; }
2209 /* -------------------------------------------------------------------------- */
2210 /* class SetOptionCommand */
2211 /* -------------------------------------------------------------------------- */
2213 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
)
2214 : d_flag(flag
), d_sexpr(sexpr
)
2218 std::string
SetOptionCommand::getFlag() const { return d_flag
; }
2219 SExpr
SetOptionCommand::getSExpr() const { return d_sexpr
; }
2220 void SetOptionCommand::invoke(SmtEngine
* smtEngine
)
2224 smtEngine
->setOption(d_flag
, d_sexpr
);
2225 d_commandStatus
= CommandSuccess::instance();
2227 catch (UnrecognizedOptionException
&)
2229 d_commandStatus
= new CommandUnsupported();
2231 catch (exception
& e
)
2233 d_commandStatus
= new CommandFailure(e
.what());
2237 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
,
2238 ExprManagerMapCollection
& variableMap
)
2240 return new SetOptionCommand(d_flag
, d_sexpr
);
2243 Command
* SetOptionCommand::clone() const
2245 return new SetOptionCommand(d_flag
, d_sexpr
);
2248 std::string
SetOptionCommand::getCommandName() const { return "set-option"; }
2250 /* -------------------------------------------------------------------------- */
2251 /* class GetOptionCommand */
2252 /* -------------------------------------------------------------------------- */
2254 GetOptionCommand::GetOptionCommand(std::string flag
) : d_flag(flag
) {}
2255 std::string
GetOptionCommand::getFlag() const { return d_flag
; }
2256 void GetOptionCommand::invoke(SmtEngine
* smtEngine
)
2260 SExpr res
= smtEngine
->getOption(d_flag
);
2261 d_result
= res
.toString();
2262 d_commandStatus
= CommandSuccess::instance();
2264 catch (UnrecognizedOptionException
&)
2266 d_commandStatus
= new CommandUnsupported();
2268 catch (exception
& e
)
2270 d_commandStatus
= new CommandFailure(e
.what());
2274 std::string
GetOptionCommand::getResult() const { return d_result
; }
2275 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const
2279 this->Command::printResult(out
, verbosity
);
2281 else if (d_result
!= "")
2283 out
<< d_result
<< endl
;
2287 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
,
2288 ExprManagerMapCollection
& variableMap
)
2290 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2291 c
->d_result
= d_result
;
2295 Command
* GetOptionCommand::clone() const
2297 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
2298 c
->d_result
= d_result
;
2302 std::string
GetOptionCommand::getCommandName() const { return "get-option"; }
2304 /* -------------------------------------------------------------------------- */
2305 /* class SetExpressionNameCommand */
2306 /* -------------------------------------------------------------------------- */
2308 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
)
2309 : d_expr(expr
), d_name(name
)
2313 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
)
2315 smtEngine
->setExpressionName(d_expr
, d_name
);
2316 d_commandStatus
= CommandSuccess::instance();
2319 Command
* SetExpressionNameCommand::exportTo(
2320 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2322 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(
2323 d_expr
.exportTo(exprManager
, variableMap
), d_name
);
2327 Command
* SetExpressionNameCommand::clone() const
2329 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
2333 std::string
SetExpressionNameCommand::getCommandName() const
2335 return "set-expr-name";
2338 /* -------------------------------------------------------------------------- */
2339 /* class DatatypeDeclarationCommand */
2340 /* -------------------------------------------------------------------------- */
2342 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2343 const DatatypeType
& datatype
)
2346 d_datatypes
.push_back(datatype
);
2349 DatatypeDeclarationCommand::DatatypeDeclarationCommand(
2350 const std::vector
<DatatypeType
>& datatypes
)
2351 : d_datatypes(datatypes
)
2355 const std::vector
<DatatypeType
>& DatatypeDeclarationCommand::getDatatypes()
2361 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
)
2363 d_commandStatus
= CommandSuccess::instance();
2366 Command
* DatatypeDeclarationCommand::exportTo(
2367 ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
)
2369 throw ExportUnsupportedException(
2370 "export of DatatypeDeclarationCommand unsupported");
2373 Command
* DatatypeDeclarationCommand::clone() const
2375 return new DatatypeDeclarationCommand(d_datatypes
);
2378 std::string
DatatypeDeclarationCommand::getCommandName() const
2380 return "declare-datatypes";
2383 /* -------------------------------------------------------------------------- */
2384 /* class RewriteRuleCommand */
2385 /* -------------------------------------------------------------------------- */
2387 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
2388 const std::vector
<Expr
>& guards
,
2391 const Triggers
& triggers
)
2396 d_triggers(triggers
)
2400 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
2403 : d_vars(vars
), d_head(head
), d_body(body
)
2407 const std::vector
<Expr
>& RewriteRuleCommand::getVars() const { return d_vars
; }
2408 const std::vector
<Expr
>& RewriteRuleCommand::getGuards() const
2413 Expr
RewriteRuleCommand::getHead() const { return d_head
; }
2414 Expr
RewriteRuleCommand::getBody() const { return d_body
; }
2415 const RewriteRuleCommand::Triggers
& RewriteRuleCommand::getTriggers() const
2420 void RewriteRuleCommand::invoke(SmtEngine
* smtEngine
)
2424 ExprManager
* em
= smtEngine
->getExprManager();
2425 /** build vars list */
2426 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
2427 /** build guards list */
2429 if (d_guards
.size() == 0)
2430 guards
= em
->mkConst
<bool>(true);
2431 else if (d_guards
.size() == 1)
2432 guards
= d_guards
[0];
2434 guards
= em
->mkExpr(kind::AND
, d_guards
);
2435 /** build expression */
2437 if (d_triggers
.empty())
2439 expr
= em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, d_head
, d_body
);
2443 /** build triggers list */
2444 std::vector
<Expr
> vtriggers
;
2445 vtriggers
.reserve(d_triggers
.size());
2446 for (Triggers::const_iterator i
= d_triggers
.begin(),
2447 end
= d_triggers
.end();
2451 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
, *i
));
2453 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
, vtriggers
);
2455 em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, d_head
, d_body
, triggers
);
2457 smtEngine
->assertFormula(expr
);
2458 d_commandStatus
= CommandSuccess::instance();
2460 catch (exception
& e
)
2462 d_commandStatus
= new CommandFailure(e
.what());
2466 Command
* RewriteRuleCommand::exportTo(ExprManager
* exprManager
,
2467 ExprManagerMapCollection
& variableMap
)
2469 /** Convert variables */
2470 VExpr vars
= ExportTo(exprManager
, variableMap
, d_vars
);
2471 /** Convert guards */
2472 VExpr guards
= ExportTo(exprManager
, variableMap
, d_guards
);
2473 /** Convert triggers */
2475 triggers
.reserve(d_triggers
.size());
2476 for (const std::vector
<Expr
>& trigger_list
: d_triggers
)
2478 triggers
.push_back(ExportTo(exprManager
, variableMap
, trigger_list
));
2480 /** Convert head and body */
2481 Expr head
= d_head
.exportTo(exprManager
, variableMap
);
2482 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
2483 /** Create the converted rules */
2484 return new RewriteRuleCommand(vars
, guards
, head
, body
, triggers
);
2487 Command
* RewriteRuleCommand::clone() const
2489 return new RewriteRuleCommand(d_vars
, d_guards
, d_head
, d_body
, d_triggers
);
2492 std::string
RewriteRuleCommand::getCommandName() const
2494 return "rewrite-rule";
2497 /* -------------------------------------------------------------------------- */
2498 /* class PropagateRuleCommand */
2499 /* -------------------------------------------------------------------------- */
2501 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
2502 const std::vector
<Expr
>& guards
,
2503 const std::vector
<Expr
>& heads
,
2505 const Triggers
& triggers
,
2511 d_triggers(triggers
),
2512 d_deduction(deduction
)
2516 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
2517 const std::vector
<Expr
>& heads
,
2520 : d_vars(vars
), d_heads(heads
), d_body(body
), d_deduction(deduction
)
2524 const std::vector
<Expr
>& PropagateRuleCommand::getVars() const
2529 const std::vector
<Expr
>& PropagateRuleCommand::getGuards() const
2534 const std::vector
<Expr
>& PropagateRuleCommand::getHeads() const
2539 Expr
PropagateRuleCommand::getBody() const { return d_body
; }
2540 const PropagateRuleCommand::Triggers
& PropagateRuleCommand::getTriggers() const
2545 bool PropagateRuleCommand::isDeduction() const { return d_deduction
; }
2546 void PropagateRuleCommand::invoke(SmtEngine
* smtEngine
)
2550 ExprManager
* em
= smtEngine
->getExprManager();
2551 /** build vars list */
2552 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
2553 /** build guards list */
2555 if (d_guards
.size() == 0)
2556 guards
= em
->mkConst
<bool>(true);
2557 else if (d_guards
.size() == 1)
2558 guards
= d_guards
[0];
2560 guards
= em
->mkExpr(kind::AND
, d_guards
);
2561 /** build heads list */
2563 if (d_heads
.size() == 1)
2566 heads
= em
->mkExpr(kind::AND
, d_heads
);
2567 /** build expression */
2569 if (d_triggers
.empty())
2571 expr
= em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, heads
, d_body
);
2575 /** build triggers list */
2576 std::vector
<Expr
> vtriggers
;
2577 vtriggers
.reserve(d_triggers
.size());
2578 for (Triggers::const_iterator i
= d_triggers
.begin(),
2579 end
= d_triggers
.end();
2583 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
, *i
));
2585 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
, vtriggers
);
2587 em
->mkExpr(kind::RR_REWRITE
, vars
, guards
, heads
, d_body
, triggers
);
2589 smtEngine
->assertFormula(expr
);
2590 d_commandStatus
= CommandSuccess::instance();
2592 catch (exception
& e
)
2594 d_commandStatus
= new CommandFailure(e
.what());
2598 Command
* PropagateRuleCommand::exportTo(ExprManager
* exprManager
,
2599 ExprManagerMapCollection
& variableMap
)
2601 /** Convert variables */
2602 VExpr vars
= ExportTo(exprManager
, variableMap
, d_vars
);
2603 /** Convert guards */
2604 VExpr guards
= ExportTo(exprManager
, variableMap
, d_guards
);
2605 /** Convert heads */
2606 VExpr heads
= ExportTo(exprManager
, variableMap
, d_heads
);
2607 /** Convert triggers */
2609 triggers
.reserve(d_triggers
.size());
2610 for (const std::vector
<Expr
>& trigger_list
: d_triggers
)
2612 triggers
.push_back(ExportTo(exprManager
, variableMap
, trigger_list
));
2614 /** Convert head and body */
2615 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
2616 /** Create the converted rules */
2617 return new PropagateRuleCommand(vars
, guards
, heads
, body
, triggers
);
2620 Command
* PropagateRuleCommand::clone() const
2622 return new PropagateRuleCommand(
2623 d_vars
, d_guards
, d_heads
, d_body
, d_triggers
);
2626 std::string
PropagateRuleCommand::getCommandName() const
2628 return "propagate-rule";