1 /********************* */
4 ** Top contributors (to current version):
5 ** Morgan Deters, Andrew Reynolds, Francois Bobot
6 ** This file is part of the CVC4 project.
7 ** Copyright (c) 2009-2017 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"
43 const int CommandPrintSuccess::s_iosIndex
= std::ios_base::xalloc();
44 const CommandSuccess
* CommandSuccess::s_instance
= new CommandSuccess();
45 const CommandInterrupted
* CommandInterrupted::s_instance
= new CommandInterrupted();
47 std::ostream
& operator<<(std::ostream
& out
, const Command
& c
) throw() {
49 Node::setdepth::getDepth(out
),
50 Node::printtypes::getPrintTypes(out
),
51 Node::dag::getDag(out
),
52 Node::setlanguage::getLanguage(out
));
56 ostream
& operator<<(ostream
& out
, const Command
* c
) throw() {
65 std::ostream
& operator<<(std::ostream
& out
, const CommandStatus
& s
) throw() {
66 s
.toStream(out
, Node::setlanguage::getLanguage(out
));
70 ostream
& operator<<(ostream
& out
, const CommandStatus
* s
) throw() {
81 Command::Command() throw() : d_commandStatus(NULL
), d_muted(false) {
84 Command::Command(const Command
& cmd
) {
85 d_commandStatus
= (cmd
.d_commandStatus
== NULL
) ? NULL
: &cmd
.d_commandStatus
->clone();
86 d_muted
= cmd
.d_muted
;
89 Command::~Command() throw() {
90 if(d_commandStatus
!= NULL
&& d_commandStatus
!= CommandSuccess::instance()) {
91 delete d_commandStatus
;
95 bool Command::ok() const throw() {
96 // either we haven't run the command yet, or it ran successfully
97 return d_commandStatus
== NULL
|| dynamic_cast<const CommandSuccess
*>(d_commandStatus
) != NULL
;
100 bool Command::fail() const throw() {
101 return d_commandStatus
!= NULL
&& dynamic_cast<const CommandFailure
*>(d_commandStatus
) != NULL
;
104 bool Command::interrupted() const throw() {
105 return d_commandStatus
!= NULL
&& dynamic_cast<const CommandInterrupted
*>(d_commandStatus
) != NULL
;
108 void Command::invoke(SmtEngine
* smtEngine
, std::ostream
& out
) {
110 if(!(isMuted() && ok())) {
111 printResult(out
, smtEngine
->getOption("command-verbosity:" + getCommandName()).getIntegerValue().toUnsignedInt());
115 std::string
Command::toString() const throw() {
116 std::stringstream ss
;
121 void Command::toStream(std::ostream
& out
, int toDepth
, bool types
, size_t dag
,
122 OutputLanguage language
) const throw() {
123 Printer::getPrinter(language
)->toStream(out
, this, toDepth
, types
, dag
);
126 void CommandStatus::toStream(std::ostream
& out
, OutputLanguage language
) const throw() {
127 Printer::getPrinter(language
)->toStream(out
, this);
130 void Command::printResult(std::ostream
& out
, uint32_t verbosity
) const {
131 if(d_commandStatus
!= NULL
) {
132 if((!ok() && verbosity
>= 1) || verbosity
>= 2) {
133 out
<< *d_commandStatus
;
138 /* class EmptyCommand */
140 EmptyCommand::EmptyCommand(std::string name
) throw() :
144 std::string
EmptyCommand::getName() const throw() {
148 void EmptyCommand::invoke(SmtEngine
* smtEngine
) {
149 /* empty commands have no implementation */
150 d_commandStatus
= CommandSuccess::instance();
153 Command
* EmptyCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
154 return new EmptyCommand(d_name
);
157 Command
* EmptyCommand::clone() const {
158 return new EmptyCommand(d_name
);
161 std::string
EmptyCommand::getCommandName() const throw() {
165 /* class EchoCommand */
167 EchoCommand::EchoCommand(std::string output
) throw() :
171 std::string
EchoCommand::getOutput() const throw() {
175 void EchoCommand::invoke(SmtEngine
* smtEngine
) {
176 /* we don't have an output stream here, nothing to do */
177 d_commandStatus
= CommandSuccess::instance();
180 void EchoCommand::invoke(SmtEngine
* smtEngine
, std::ostream
& out
) {
181 out
<< d_output
<< std::endl
;
182 d_commandStatus
= CommandSuccess::instance();
183 printResult(out
, smtEngine
->getOption("command-verbosity:" + getCommandName()).getIntegerValue().toUnsignedInt());
186 Command
* EchoCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
187 return new EchoCommand(d_output
);
190 Command
* EchoCommand::clone() const {
191 return new EchoCommand(d_output
);
194 std::string
EchoCommand::getCommandName() const throw() {
198 /* class AssertCommand */
200 AssertCommand::AssertCommand(const Expr
& e
, bool inUnsatCore
) throw() :
201 d_expr(e
), d_inUnsatCore(inUnsatCore
) {
204 Expr
AssertCommand::getExpr() const throw() {
208 void AssertCommand::invoke(SmtEngine
* smtEngine
) {
210 smtEngine
->assertFormula(d_expr
, d_inUnsatCore
);
211 d_commandStatus
= CommandSuccess::instance();
212 } catch(UnsafeInterruptException
& e
) {
213 d_commandStatus
= new CommandInterrupted();
214 } catch(exception
& e
) {
215 d_commandStatus
= new CommandFailure(e
.what());
219 Command
* AssertCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
220 return new AssertCommand(d_expr
.exportTo(exprManager
, variableMap
), d_inUnsatCore
);
223 Command
* AssertCommand::clone() const {
224 return new AssertCommand(d_expr
, d_inUnsatCore
);
227 std::string
AssertCommand::getCommandName() const throw() {
231 /* class PushCommand */
233 void PushCommand::invoke(SmtEngine
* smtEngine
) {
236 d_commandStatus
= CommandSuccess::instance();
237 } catch(UnsafeInterruptException
& e
) {
238 d_commandStatus
= new CommandInterrupted();
239 } catch(exception
& e
) {
240 d_commandStatus
= new CommandFailure(e
.what());
244 Command
* PushCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
245 return new PushCommand();
248 Command
* PushCommand::clone() const {
249 return new PushCommand();
252 std::string
PushCommand::getCommandName() const throw() {
256 /* class PopCommand */
258 void PopCommand::invoke(SmtEngine
* smtEngine
) {
261 d_commandStatus
= CommandSuccess::instance();
262 } catch(UnsafeInterruptException
& e
) {
263 d_commandStatus
= new CommandInterrupted();
264 } catch(exception
& e
) {
265 d_commandStatus
= new CommandFailure(e
.what());
269 Command
* PopCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
270 return new PopCommand();
273 Command
* PopCommand::clone() const {
274 return new PopCommand();
277 std::string
PopCommand::getCommandName() const throw() {
281 /* class CheckSatCommand */
283 CheckSatCommand::CheckSatCommand() throw() :
287 CheckSatCommand::CheckSatCommand(const Expr
& expr
, bool inUnsatCore
) throw() :
288 d_expr(expr
), d_inUnsatCore(inUnsatCore
) {
291 Expr
CheckSatCommand::getExpr() const throw() {
295 void CheckSatCommand::invoke(SmtEngine
* smtEngine
) {
297 d_result
= smtEngine
->checkSat(d_expr
);
298 d_commandStatus
= CommandSuccess::instance();
299 } catch(exception
& e
) {
300 d_commandStatus
= new CommandFailure(e
.what());
304 Result
CheckSatCommand::getResult() const throw() {
308 void CheckSatCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
310 this->Command::printResult(out
, verbosity
);
312 out
<< d_result
<< endl
;
316 Command
* CheckSatCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
317 CheckSatCommand
* c
= new CheckSatCommand(d_expr
.exportTo(exprManager
, variableMap
), d_inUnsatCore
);
318 c
->d_result
= d_result
;
322 Command
* CheckSatCommand::clone() const {
323 CheckSatCommand
* c
= new CheckSatCommand(d_expr
, d_inUnsatCore
);
324 c
->d_result
= d_result
;
328 std::string
CheckSatCommand::getCommandName() const throw() {
332 /* class QueryCommand */
334 QueryCommand::QueryCommand(const Expr
& e
, bool inUnsatCore
) throw() :
335 d_expr(e
), d_inUnsatCore(inUnsatCore
) {
338 Expr
QueryCommand::getExpr() const throw() {
342 void QueryCommand::invoke(SmtEngine
* smtEngine
) {
344 d_result
= smtEngine
->query(d_expr
);
345 d_commandStatus
= CommandSuccess::instance();
346 } catch(exception
& e
) {
347 d_commandStatus
= new CommandFailure(e
.what());
351 Result
QueryCommand::getResult() const throw() {
355 void QueryCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
357 this->Command::printResult(out
, verbosity
);
359 out
<< d_result
<< endl
;
363 Command
* QueryCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
364 QueryCommand
* c
= new QueryCommand(d_expr
.exportTo(exprManager
, variableMap
), d_inUnsatCore
);
365 c
->d_result
= d_result
;
369 Command
* QueryCommand::clone() const {
370 QueryCommand
* c
= new QueryCommand(d_expr
, d_inUnsatCore
);
371 c
->d_result
= d_result
;
375 std::string
QueryCommand::getCommandName() const throw() {
380 /* class CheckSynthCommand */
382 CheckSynthCommand::CheckSynthCommand() throw() :
386 CheckSynthCommand::CheckSynthCommand(const Expr
& expr
, bool inUnsatCore
) throw() :
387 d_expr(expr
), d_inUnsatCore(inUnsatCore
) {
390 Expr
CheckSynthCommand::getExpr() const throw() {
394 void CheckSynthCommand::invoke(SmtEngine
* smtEngine
) {
396 d_result
= smtEngine
->checkSynth(d_expr
);
397 d_commandStatus
= CommandSuccess::instance();
398 } catch(exception
& e
) {
399 d_commandStatus
= new CommandFailure(e
.what());
403 Result
CheckSynthCommand::getResult() const throw() {
407 void CheckSynthCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
409 this->Command::printResult(out
, verbosity
);
411 out
<< d_result
<< endl
;
415 Command
* CheckSynthCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
416 CheckSynthCommand
* c
= new CheckSynthCommand(d_expr
.exportTo(exprManager
, variableMap
), d_inUnsatCore
);
417 c
->d_result
= d_result
;
421 Command
* CheckSynthCommand::clone() const {
422 CheckSynthCommand
* c
= new CheckSynthCommand(d_expr
, d_inUnsatCore
);
423 c
->d_result
= d_result
;
427 std::string
CheckSynthCommand::getCommandName() const throw() {
428 return "check-synth";
432 /* class ResetCommand */
434 void ResetCommand::invoke(SmtEngine
* smtEngine
) {
437 d_commandStatus
= CommandSuccess::instance();
438 } catch(exception
& e
) {
439 d_commandStatus
= new CommandFailure(e
.what());
443 Command
* ResetCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
444 return new ResetCommand();
447 Command
* ResetCommand::clone() const {
448 return new ResetCommand();
451 std::string
ResetCommand::getCommandName() const throw() {
455 /* class ResetAssertionsCommand */
457 void ResetAssertionsCommand::invoke(SmtEngine
* smtEngine
) {
459 smtEngine
->resetAssertions();
460 d_commandStatus
= CommandSuccess::instance();
461 } catch(exception
& e
) {
462 d_commandStatus
= new CommandFailure(e
.what());
466 Command
* ResetAssertionsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
467 return new ResetAssertionsCommand();
470 Command
* ResetAssertionsCommand::clone() const {
471 return new ResetAssertionsCommand();
474 std::string
ResetAssertionsCommand::getCommandName() const throw() {
475 return "reset-assertions";
478 /* class QuitCommand */
480 void QuitCommand::invoke(SmtEngine
* smtEngine
) {
481 Dump("benchmark") << *this;
482 d_commandStatus
= CommandSuccess::instance();
485 Command
* QuitCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
486 return new QuitCommand();
489 Command
* QuitCommand::clone() const {
490 return new QuitCommand();
493 std::string
QuitCommand::getCommandName() const throw() {
497 /* class CommentCommand */
499 CommentCommand::CommentCommand(std::string comment
) throw() : d_comment(comment
) {
502 std::string
CommentCommand::getComment() const throw() {
506 void CommentCommand::invoke(SmtEngine
* smtEngine
) {
507 Dump("benchmark") << *this;
508 d_commandStatus
= CommandSuccess::instance();
511 Command
* CommentCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
512 return new CommentCommand(d_comment
);
515 Command
* CommentCommand::clone() const {
516 return new CommentCommand(d_comment
);
519 std::string
CommentCommand::getCommandName() const throw() {
523 /* class CommandSequence */
525 CommandSequence::CommandSequence() throw() :
529 CommandSequence::~CommandSequence() throw() {
530 for(unsigned i
= d_index
; i
< d_commandSequence
.size(); ++i
) {
531 delete d_commandSequence
[i
];
535 void CommandSequence::addCommand(Command
* cmd
) throw() {
536 d_commandSequence
.push_back(cmd
);
539 void CommandSequence::clear() throw() {
540 d_commandSequence
.clear();
543 void CommandSequence::invoke(SmtEngine
* smtEngine
) {
544 for(; d_index
< d_commandSequence
.size(); ++d_index
) {
545 d_commandSequence
[d_index
]->invoke(smtEngine
);
546 if(! d_commandSequence
[d_index
]->ok()) {
548 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
551 delete d_commandSequence
[d_index
];
554 AlwaysAssert(d_commandStatus
== NULL
);
555 d_commandStatus
= CommandSuccess::instance();
558 void CommandSequence::invoke(SmtEngine
* smtEngine
, std::ostream
& out
) {
559 for(; d_index
< d_commandSequence
.size(); ++d_index
) {
560 d_commandSequence
[d_index
]->invoke(smtEngine
, out
);
561 if(! d_commandSequence
[d_index
]->ok()) {
563 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
566 delete d_commandSequence
[d_index
];
569 AlwaysAssert(d_commandStatus
== NULL
);
570 d_commandStatus
= CommandSuccess::instance();
573 Command
* CommandSequence::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
574 CommandSequence
* seq
= new CommandSequence();
575 for(iterator i
= begin(); i
!= end(); ++i
) {
576 Command
* cmd_to_export
= *i
;
577 Command
* cmd
= cmd_to_export
->exportTo(exprManager
, variableMap
);
578 seq
->addCommand(cmd
);
579 Debug("export") << "[export] so far converted: " << seq
<< endl
;
581 seq
->d_index
= d_index
;
585 Command
* CommandSequence::clone() const {
586 CommandSequence
* seq
= new CommandSequence();
587 for(const_iterator i
= begin(); i
!= end(); ++i
) {
588 seq
->addCommand((*i
)->clone());
590 seq
->d_index
= d_index
;
594 CommandSequence::const_iterator
CommandSequence::begin() const throw() {
595 return d_commandSequence
.begin();
598 CommandSequence::const_iterator
CommandSequence::end() const throw() {
599 return d_commandSequence
.end();
602 CommandSequence::iterator
CommandSequence::begin() throw() {
603 return d_commandSequence
.begin();
606 CommandSequence::iterator
CommandSequence::end() throw() {
607 return d_commandSequence
.end();
610 std::string
CommandSequence::getCommandName() const throw() {
614 /* class DeclarationSequenceCommand */
616 /* class DeclarationDefinitionCommand */
618 DeclarationDefinitionCommand::DeclarationDefinitionCommand(const std::string
& id
) throw() :
622 std::string
DeclarationDefinitionCommand::getSymbol() const throw() {
626 /* class DeclareFunctionCommand */
628 DeclareFunctionCommand::DeclareFunctionCommand(const std::string
& id
, Expr func
, Type t
) throw() :
629 DeclarationDefinitionCommand(id
),
632 d_printInModel(true),
633 d_printInModelSetByUser(false){
636 Expr
DeclareFunctionCommand::getFunction() const throw() {
640 Type
DeclareFunctionCommand::getType() const throw() {
644 bool DeclareFunctionCommand::getPrintInModel() const throw() {
645 return d_printInModel
;
648 bool DeclareFunctionCommand::getPrintInModelSetByUser() const throw() {
649 return d_printInModelSetByUser
;
652 void DeclareFunctionCommand::setPrintInModel( bool p
) {
654 d_printInModelSetByUser
= true;
657 void DeclareFunctionCommand::invoke(SmtEngine
* smtEngine
) {
658 d_commandStatus
= CommandSuccess::instance();
661 Command
* DeclareFunctionCommand::exportTo(ExprManager
* exprManager
,
662 ExprManagerMapCollection
& variableMap
) {
663 DeclareFunctionCommand
* dfc
= new DeclareFunctionCommand(d_symbol
, d_func
.exportTo(exprManager
, variableMap
),
664 d_type
.exportTo(exprManager
, variableMap
));
665 dfc
->d_printInModel
= d_printInModel
;
666 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
670 Command
* DeclareFunctionCommand::clone() const {
671 DeclareFunctionCommand
* dfc
= new DeclareFunctionCommand(d_symbol
, d_func
, d_type
);
672 dfc
->d_printInModel
= d_printInModel
;
673 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
677 std::string
DeclareFunctionCommand::getCommandName() const throw() {
678 return "declare-fun";
681 /* class DeclareTypeCommand */
683 DeclareTypeCommand::DeclareTypeCommand(const std::string
& id
, size_t arity
, Type t
) throw() :
684 DeclarationDefinitionCommand(id
),
689 size_t DeclareTypeCommand::getArity() const throw() {
693 Type
DeclareTypeCommand::getType() const throw() {
697 void DeclareTypeCommand::invoke(SmtEngine
* smtEngine
) {
698 d_commandStatus
= CommandSuccess::instance();
701 Command
* DeclareTypeCommand::exportTo(ExprManager
* exprManager
,
702 ExprManagerMapCollection
& variableMap
) {
703 return new DeclareTypeCommand(d_symbol
, d_arity
,
704 d_type
.exportTo(exprManager
, variableMap
));
707 Command
* DeclareTypeCommand::clone() const {
708 return new DeclareTypeCommand(d_symbol
, d_arity
, d_type
);
711 std::string
DeclareTypeCommand::getCommandName() const throw() {
712 return "declare-sort";
715 /* class DefineTypeCommand */
717 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
719 DeclarationDefinitionCommand(id
),
724 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
725 const std::vector
<Type
>& params
,
727 DeclarationDefinitionCommand(id
),
732 const std::vector
<Type
>& DefineTypeCommand::getParameters() const throw() {
736 Type
DefineTypeCommand::getType() const throw() {
740 void DefineTypeCommand::invoke(SmtEngine
* smtEngine
) {
741 d_commandStatus
= CommandSuccess::instance();
744 Command
* DefineTypeCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
746 transform(d_params
.begin(), d_params
.end(), back_inserter(params
),
747 ExportTransformer(exprManager
, variableMap
));
748 Type type
= d_type
.exportTo(exprManager
, variableMap
);
749 return new DefineTypeCommand(d_symbol
, params
, type
);
752 Command
* DefineTypeCommand::clone() const {
753 return new DefineTypeCommand(d_symbol
, d_params
, d_type
);
756 std::string
DefineTypeCommand::getCommandName() const throw() {
757 return "define-sort";
760 /* class DefineFunctionCommand */
762 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
764 Expr formula
) throw() :
765 DeclarationDefinitionCommand(id
),
771 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
773 const std::vector
<Expr
>& formals
,
774 Expr formula
) throw() :
775 DeclarationDefinitionCommand(id
),
781 Expr
DefineFunctionCommand::getFunction() const throw() {
785 const std::vector
<Expr
>& DefineFunctionCommand::getFormals() const throw() {
789 Expr
DefineFunctionCommand::getFormula() const throw() {
793 void DefineFunctionCommand::invoke(SmtEngine
* smtEngine
) {
795 if(!d_func
.isNull()) {
796 smtEngine
->defineFunction(d_func
, d_formals
, d_formula
);
798 d_commandStatus
= CommandSuccess::instance();
799 } catch(exception
& e
) {
800 d_commandStatus
= new CommandFailure(e
.what());
804 Command
* DefineFunctionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
805 Expr func
= d_func
.exportTo(exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
806 vector
<Expr
> formals
;
807 transform(d_formals
.begin(), d_formals
.end(), back_inserter(formals
),
808 ExportTransformer(exprManager
, variableMap
));
809 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
810 return new DefineFunctionCommand(d_symbol
, func
, formals
, formula
);
813 Command
* DefineFunctionCommand::clone() const {
814 return new DefineFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
817 std::string
DefineFunctionCommand::getCommandName() const throw() {
821 /* class DefineNamedFunctionCommand */
823 DefineNamedFunctionCommand::DefineNamedFunctionCommand(const std::string
& id
,
825 const std::vector
<Expr
>& formals
,
826 Expr formula
) throw() :
827 DefineFunctionCommand(id
, func
, formals
, formula
) {
830 void DefineNamedFunctionCommand::invoke(SmtEngine
* smtEngine
) {
831 this->DefineFunctionCommand::invoke(smtEngine
);
832 if(!d_func
.isNull() && d_func
.getType().isBoolean()) {
833 smtEngine
->addToAssignment(d_func
.getExprManager()->mkExpr(kind::APPLY
, d_func
));
835 d_commandStatus
= CommandSuccess::instance();
838 Command
* DefineNamedFunctionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
839 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
840 vector
<Expr
> formals
;
841 transform(d_formals
.begin(), d_formals
.end(), back_inserter(formals
),
842 ExportTransformer(exprManager
, variableMap
));
843 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
844 return new DefineNamedFunctionCommand(d_symbol
, func
, formals
, formula
);
847 Command
* DefineNamedFunctionCommand::clone() const {
848 return new DefineNamedFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
851 /* class SetUserAttribute */
853 SetUserAttributeCommand::SetUserAttributeCommand( const std::string
& attr
, Expr expr
) throw() :
854 d_attr( attr
), d_expr( expr
){
857 SetUserAttributeCommand::SetUserAttributeCommand( const std::string
& attr
, Expr expr
,
858 std::vector
<Expr
>& values
) throw() :
859 d_attr( attr
), d_expr( expr
){
860 d_expr_values
.insert( d_expr_values
.begin(), values
.begin(), values
.end() );
863 SetUserAttributeCommand::SetUserAttributeCommand( const std::string
& attr
, Expr expr
,
864 const std::string
& value
) throw() :
865 d_attr( attr
), d_expr( expr
), d_str_value( value
){
868 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
) {
870 if(!d_expr
.isNull()) {
871 smtEngine
->setUserAttribute( d_attr
, d_expr
, d_expr_values
, d_str_value
);
873 d_commandStatus
= CommandSuccess::instance();
874 } catch(exception
& e
) {
875 d_commandStatus
= new CommandFailure(e
.what());
879 Command
* SetUserAttributeCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
){
880 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
881 SetUserAttributeCommand
* c
= new SetUserAttributeCommand( d_attr
, expr
, d_str_value
);
882 c
->d_expr_values
.insert( c
->d_expr_values
.end(), d_expr_values
.begin(), d_expr_values
.end() );
886 Command
* SetUserAttributeCommand::clone() const{
887 SetUserAttributeCommand
* c
= new SetUserAttributeCommand( d_attr
, d_expr
, d_str_value
);
888 c
->d_expr_values
.insert( c
->d_expr_values
.end(), d_expr_values
.begin(), d_expr_values
.end() );
892 std::string
SetUserAttributeCommand::getCommandName() const throw() {
893 return "set-user-attribute";
896 /* class SimplifyCommand */
898 SimplifyCommand::SimplifyCommand(Expr term
) throw() :
902 Expr
SimplifyCommand::getTerm() const throw() {
906 void SimplifyCommand::invoke(SmtEngine
* smtEngine
) {
908 d_result
= smtEngine
->simplify(d_term
);
909 d_commandStatus
= CommandSuccess::instance();
910 } catch(UnsafeInterruptException
& e
) {
911 d_commandStatus
= new CommandInterrupted();
912 } catch(exception
& e
) {
913 d_commandStatus
= new CommandFailure(e
.what());
917 Expr
SimplifyCommand::getResult() const throw() {
921 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
923 this->Command::printResult(out
, verbosity
);
925 out
<< d_result
<< endl
;
929 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
930 SimplifyCommand
* c
= new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
931 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
935 Command
* SimplifyCommand::clone() const {
936 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
937 c
->d_result
= d_result
;
941 std::string
SimplifyCommand::getCommandName() const throw() {
945 /* class ExpandDefinitionsCommand */
947 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) throw() :
951 Expr
ExpandDefinitionsCommand::getTerm() const throw() {
955 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
) {
956 d_result
= smtEngine
->expandDefinitions(d_term
);
957 d_commandStatus
= CommandSuccess::instance();
960 Expr
ExpandDefinitionsCommand::getResult() const throw() {
964 void ExpandDefinitionsCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
966 this->Command::printResult(out
, verbosity
);
968 out
<< d_result
<< endl
;
972 Command
* ExpandDefinitionsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
973 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
974 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
978 Command
* ExpandDefinitionsCommand::clone() const {
979 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
980 c
->d_result
= d_result
;
984 std::string
ExpandDefinitionsCommand::getCommandName() const throw() {
985 return "expand-definitions";
988 /* class GetValueCommand */
990 GetValueCommand::GetValueCommand(Expr term
) throw() :
992 d_terms
.push_back(term
);
995 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
) throw() :
997 PrettyCheckArgument(terms
.size() >= 1, terms
,
998 "cannot get-value of an empty set of terms");
1001 const std::vector
<Expr
>& GetValueCommand::getTerms() const throw() {
1005 void GetValueCommand::invoke(SmtEngine
* smtEngine
) {
1007 vector
<Expr
> result
;
1008 ExprManager
* em
= smtEngine
->getExprManager();
1009 NodeManager
* nm
= NodeManager::fromExprManager(em
);
1010 for(std::vector
<Expr
>::const_iterator i
= d_terms
.begin(); i
!= d_terms
.end(); ++i
) {
1011 Assert(nm
== NodeManager::fromExprManager((*i
).getExprManager()));
1012 smt::SmtScope
scope(smtEngine
);
1013 Node request
= Node::fromExpr(options::expandDefinitions() ? smtEngine
->expandDefinitions(*i
) : *i
);
1014 Node value
= Node::fromExpr(smtEngine
->getValue(*i
));
1015 if(value
.getType().isInteger() && request
.getType() == nm
->realType()) {
1016 // Need to wrap in special marker so that output printers know this
1017 // is an integer-looking constant that really should be output as
1018 // a rational. Necessary for SMT-LIB standards compliance, but ugly.
1019 value
= nm
->mkNode(kind::APPLY_TYPE_ASCRIPTION
,
1020 nm
->mkConst(AscriptionType(em
->realType())), value
);
1022 result
.push_back(nm
->mkNode(kind::SEXPR
, request
, value
).toExpr());
1024 d_result
= em
->mkExpr(kind::SEXPR
, result
);
1025 d_commandStatus
= CommandSuccess::instance();
1026 } catch (RecoverableModalException
& e
) {
1027 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1028 } catch(UnsafeInterruptException
& e
) {
1029 d_commandStatus
= new CommandInterrupted();
1030 } catch(exception
& e
) {
1031 d_commandStatus
= new CommandFailure(e
.what());
1035 Expr
GetValueCommand::getResult() const throw() {
1039 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1041 this->Command::printResult(out
, verbosity
);
1043 expr::ExprDag::Scope
scope(out
, false);
1044 out
<< d_result
<< endl
;
1048 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1049 vector
<Expr
> exportedTerms
;
1050 for(std::vector
<Expr
>::const_iterator i
= d_terms
.begin(); i
!= d_terms
.end(); ++i
) {
1051 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1053 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1054 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1058 Command
* GetValueCommand::clone() const {
1059 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1060 c
->d_result
= d_result
;
1064 std::string
GetValueCommand::getCommandName() const throw() {
1068 /* class GetAssignmentCommand */
1070 GetAssignmentCommand::GetAssignmentCommand() throw() {
1073 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
) {
1075 d_result
= smtEngine
->getAssignment();
1076 d_commandStatus
= CommandSuccess::instance();
1077 } catch (RecoverableModalException
& e
) {
1078 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1079 } catch(UnsafeInterruptException
& e
) {
1080 d_commandStatus
= new CommandInterrupted();
1081 } catch(exception
& e
) {
1082 d_commandStatus
= new CommandFailure(e
.what());
1086 SExpr
GetAssignmentCommand::getResult() const throw() {
1090 void GetAssignmentCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1092 this->Command::printResult(out
, verbosity
);
1094 out
<< d_result
<< endl
;
1098 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1099 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1100 c
->d_result
= d_result
;
1104 Command
* GetAssignmentCommand::clone() const {
1105 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1106 c
->d_result
= d_result
;
1110 std::string
GetAssignmentCommand::getCommandName() const throw() {
1111 return "get-assignment";
1114 /* class GetModelCommand */
1116 GetModelCommand::GetModelCommand() throw()
1117 : d_result(nullptr), d_smtEngine(nullptr) {}
1119 void GetModelCommand::invoke(SmtEngine
* smtEngine
) {
1121 d_result
= smtEngine
->getModel();
1122 d_smtEngine
= smtEngine
;
1123 d_commandStatus
= CommandSuccess::instance();
1124 } catch (RecoverableModalException
& e
) {
1125 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1126 } catch(UnsafeInterruptException
& e
) {
1127 d_commandStatus
= new CommandInterrupted();
1128 } catch(exception
& e
) {
1129 d_commandStatus
= new CommandFailure(e
.what());
1133 /* Model is private to the library -- for now
1134 Model* GetModelCommand::getResult() const throw() {
1139 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1141 this->Command::printResult(out
, verbosity
);
1147 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1148 GetModelCommand
* c
= new GetModelCommand();
1149 c
->d_result
= d_result
;
1150 c
->d_smtEngine
= d_smtEngine
;
1154 Command
* GetModelCommand::clone() const {
1155 GetModelCommand
* c
= new GetModelCommand();
1156 c
->d_result
= d_result
;
1157 c
->d_smtEngine
= d_smtEngine
;
1161 std::string
GetModelCommand::getCommandName() const throw() {
1165 /* class GetProofCommand */
1167 GetProofCommand::GetProofCommand() throw()
1168 : d_result(nullptr), d_smtEngine(nullptr) {}
1170 void GetProofCommand::invoke(SmtEngine
* smtEngine
) {
1172 d_smtEngine
= smtEngine
;
1173 d_result
= smtEngine
->getProof();
1174 d_commandStatus
= CommandSuccess::instance();
1175 } catch (RecoverableModalException
& e
) {
1176 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1177 } catch(UnsafeInterruptException
& e
) {
1178 d_commandStatus
= new CommandInterrupted();
1179 } catch(exception
& e
) {
1180 d_commandStatus
= new CommandFailure(e
.what());
1184 Proof
* GetProofCommand::getResult() const throw() {
1188 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1190 this->Command::printResult(out
, verbosity
);
1192 smt::SmtScope
scope(d_smtEngine
);
1193 d_result
->toStream(out
);
1197 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1198 GetProofCommand
* c
= new GetProofCommand();
1199 c
->d_result
= d_result
;
1200 c
->d_smtEngine
= d_smtEngine
;
1204 Command
* GetProofCommand::clone() const {
1205 GetProofCommand
* c
= new GetProofCommand();
1206 c
->d_result
= d_result
;
1207 c
->d_smtEngine
= d_smtEngine
;
1211 std::string
GetProofCommand::getCommandName() const throw() {
1215 /* class GetInstantiationsCommand */
1217 GetInstantiationsCommand::GetInstantiationsCommand() throw()
1218 : d_smtEngine(nullptr) {}
1220 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
) {
1222 d_smtEngine
= smtEngine
;
1223 d_commandStatus
= CommandSuccess::instance();
1224 } catch(exception
& e
) {
1225 d_commandStatus
= new CommandFailure(e
.what());
1229 //Instantiations* GetInstantiationsCommand::getResult() const throw() {
1233 void GetInstantiationsCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1235 this->Command::printResult(out
, verbosity
);
1237 d_smtEngine
->printInstantiations(out
);
1241 Command
* GetInstantiationsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1242 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1243 //c->d_result = d_result;
1244 c
->d_smtEngine
= d_smtEngine
;
1248 Command
* GetInstantiationsCommand::clone() const {
1249 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1250 //c->d_result = d_result;
1251 c
->d_smtEngine
= d_smtEngine
;
1255 std::string
GetInstantiationsCommand::getCommandName() const throw() {
1256 return "get-instantiations";
1259 /* class GetSynthSolutionCommand */
1261 GetSynthSolutionCommand::GetSynthSolutionCommand() throw()
1262 : d_smtEngine(nullptr) {}
1264 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
) {
1266 d_smtEngine
= smtEngine
;
1267 d_commandStatus
= CommandSuccess::instance();
1268 } catch(exception
& e
) {
1269 d_commandStatus
= new CommandFailure(e
.what());
1273 void GetSynthSolutionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1275 this->Command::printResult(out
, verbosity
);
1277 d_smtEngine
->printSynthSolution(out
);
1281 Command
* GetSynthSolutionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1282 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1283 c
->d_smtEngine
= d_smtEngine
;
1287 Command
* GetSynthSolutionCommand::clone() const {
1288 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1289 c
->d_smtEngine
= d_smtEngine
;
1293 std::string
GetSynthSolutionCommand::getCommandName() const throw() {
1294 return "get-instantiations";
1297 /* class GetQuantifierEliminationCommand */
1299 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand() throw() :
1303 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(const Expr
& expr
, bool doFull
) throw() :
1304 d_expr(expr
), d_doFull(doFull
) {
1307 Expr
GetQuantifierEliminationCommand::getExpr() const throw() {
1310 bool GetQuantifierEliminationCommand::getDoFull() const throw() {
1314 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
) {
1316 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
1317 d_commandStatus
= CommandSuccess::instance();
1318 } catch(exception
& e
) {
1319 d_commandStatus
= new CommandFailure(e
.what());
1323 Expr
GetQuantifierEliminationCommand::getResult() const throw() {
1327 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1329 this->Command::printResult(out
, verbosity
);
1331 out
<< d_result
<< endl
;
1335 Command
* GetQuantifierEliminationCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1336 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
1337 c
->d_result
= d_result
;
1341 Command
* GetQuantifierEliminationCommand::clone() const {
1342 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
1343 c
->d_result
= d_result
;
1347 std::string
GetQuantifierEliminationCommand::getCommandName() const throw() {
1348 return d_doFull
? "get-qe" : "get-qe-disjunct";
1351 /* class GetUnsatCoreCommand */
1353 GetUnsatCoreCommand::GetUnsatCoreCommand() throw() {
1356 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
) {
1358 d_result
= smtEngine
->getUnsatCore();
1359 d_commandStatus
= CommandSuccess::instance();
1360 } catch (RecoverableModalException
& e
) {
1361 d_commandStatus
= new CommandRecoverableFailure(e
.what());
1362 } catch(exception
& e
) {
1363 d_commandStatus
= new CommandFailure(e
.what());
1367 void GetUnsatCoreCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1369 this->Command::printResult(out
, verbosity
);
1371 d_result
.toStream(out
);
1375 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const throw() {
1376 // of course, this will be empty if the command hasn't been invoked yet
1380 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1381 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
1382 c
->d_result
= d_result
;
1386 Command
* GetUnsatCoreCommand::clone() const {
1387 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand
;
1388 c
->d_result
= d_result
;
1392 std::string
GetUnsatCoreCommand::getCommandName() const throw() {
1393 return "get-unsat-core";
1396 /* class GetAssertionsCommand */
1398 GetAssertionsCommand::GetAssertionsCommand() throw() {
1401 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
) {
1404 const vector
<Expr
> v
= smtEngine
->getAssertions();
1406 copy( v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n") );
1408 d_result
= ss
.str();
1409 d_commandStatus
= CommandSuccess::instance();
1410 } catch(exception
& e
) {
1411 d_commandStatus
= new CommandFailure(e
.what());
1415 std::string
GetAssertionsCommand::getResult() const throw() {
1419 void GetAssertionsCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1421 this->Command::printResult(out
, verbosity
);
1427 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1428 GetAssertionsCommand
* c
= new GetAssertionsCommand();
1429 c
->d_result
= d_result
;
1433 Command
* GetAssertionsCommand::clone() const {
1434 GetAssertionsCommand
* c
= new GetAssertionsCommand();
1435 c
->d_result
= d_result
;
1439 std::string
GetAssertionsCommand::getCommandName() const throw() {
1440 return "get-assertions";
1443 /* class SetBenchmarkStatusCommand */
1445 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
) throw() :
1449 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const throw() {
1453 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
) {
1457 SExpr status
= SExpr(ss
.str());
1458 smtEngine
->setInfo("status", status
);
1459 d_commandStatus
= CommandSuccess::instance();
1460 } catch(exception
& e
) {
1461 d_commandStatus
= new CommandFailure(e
.what());
1465 Command
* SetBenchmarkStatusCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1466 return new SetBenchmarkStatusCommand(d_status
);
1469 Command
* SetBenchmarkStatusCommand::clone() const {
1470 return new SetBenchmarkStatusCommand(d_status
);
1473 std::string
SetBenchmarkStatusCommand::getCommandName() const throw() {
1477 /* class SetBenchmarkLogicCommand */
1479 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
) throw() :
1483 std::string
SetBenchmarkLogicCommand::getLogic() const throw() {
1487 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
) {
1489 smtEngine
->setLogic(d_logic
);
1490 d_commandStatus
= CommandSuccess::instance();
1491 } catch(exception
& e
) {
1492 d_commandStatus
= new CommandFailure(e
.what());
1496 Command
* SetBenchmarkLogicCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1497 return new SetBenchmarkLogicCommand(d_logic
);
1500 Command
* SetBenchmarkLogicCommand::clone() const {
1501 return new SetBenchmarkLogicCommand(d_logic
);
1504 std::string
SetBenchmarkLogicCommand::getCommandName() const throw() {
1508 /* class SetInfoCommand */
1510 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
) throw() :
1515 std::string
SetInfoCommand::getFlag() const throw() {
1519 SExpr
SetInfoCommand::getSExpr() const throw() {
1523 void SetInfoCommand::invoke(SmtEngine
* smtEngine
) {
1525 smtEngine
->setInfo(d_flag
, d_sexpr
);
1526 d_commandStatus
= CommandSuccess::instance();
1527 } catch(UnrecognizedOptionException
&) {
1528 // As per SMT-LIB spec, silently accept unknown set-info keys
1529 d_commandStatus
= CommandSuccess::instance();
1530 } catch(exception
& e
) {
1531 d_commandStatus
= new CommandFailure(e
.what());
1535 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1536 return new SetInfoCommand(d_flag
, d_sexpr
);
1539 Command
* SetInfoCommand::clone() const {
1540 return new SetInfoCommand(d_flag
, d_sexpr
);
1543 std::string
SetInfoCommand::getCommandName() const throw() {
1547 /* class GetInfoCommand */
1549 GetInfoCommand::GetInfoCommand(std::string flag
) throw() :
1553 std::string
GetInfoCommand::getFlag() const throw() {
1557 void GetInfoCommand::invoke(SmtEngine
* smtEngine
) {
1560 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
1561 v
.push_back(smtEngine
->getInfo(d_flag
));
1563 if(d_flag
== "all-options" || d_flag
== "all-statistics") {
1564 ss
<< PrettySExprs(true);
1567 d_result
= ss
.str();
1568 d_commandStatus
= CommandSuccess::instance();
1569 } catch(UnrecognizedOptionException
&) {
1570 d_commandStatus
= new CommandUnsupported();
1571 } catch(exception
& e
) {
1572 d_commandStatus
= new CommandFailure(e
.what());
1576 std::string
GetInfoCommand::getResult() const throw() {
1580 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1582 this->Command::printResult(out
, verbosity
);
1583 } else if(d_result
!= "") {
1584 out
<< d_result
<< endl
;
1588 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1589 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
1590 c
->d_result
= d_result
;
1594 Command
* GetInfoCommand::clone() const {
1595 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
1596 c
->d_result
= d_result
;
1600 std::string
GetInfoCommand::getCommandName() const throw() {
1604 /* class SetOptionCommand */
1606 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
) throw() :
1611 std::string
SetOptionCommand::getFlag() const throw() {
1615 SExpr
SetOptionCommand::getSExpr() const throw() {
1619 void SetOptionCommand::invoke(SmtEngine
* smtEngine
) {
1621 smtEngine
->setOption(d_flag
, d_sexpr
);
1622 d_commandStatus
= CommandSuccess::instance();
1623 } catch(UnrecognizedOptionException
&) {
1624 d_commandStatus
= new CommandUnsupported();
1625 } catch(exception
& e
) {
1626 d_commandStatus
= new CommandFailure(e
.what());
1630 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1631 return new SetOptionCommand(d_flag
, d_sexpr
);
1634 Command
* SetOptionCommand::clone() const {
1635 return new SetOptionCommand(d_flag
, d_sexpr
);
1638 std::string
SetOptionCommand::getCommandName() const throw() {
1639 return "set-option";
1642 /* class GetOptionCommand */
1644 GetOptionCommand::GetOptionCommand(std::string flag
) throw() :
1648 std::string
GetOptionCommand::getFlag() const throw() {
1652 void GetOptionCommand::invoke(SmtEngine
* smtEngine
) {
1654 SExpr res
= smtEngine
->getOption(d_flag
);
1655 d_result
= res
.toString();
1656 d_commandStatus
= CommandSuccess::instance();
1657 } catch(UnrecognizedOptionException
&) {
1658 d_commandStatus
= new CommandUnsupported();
1659 } catch(exception
& e
) {
1660 d_commandStatus
= new CommandFailure(e
.what());
1664 std::string
GetOptionCommand::getResult() const throw() {
1668 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1670 this->Command::printResult(out
, verbosity
);
1671 } else if(d_result
!= "") {
1672 out
<< d_result
<< endl
;
1676 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1677 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
1678 c
->d_result
= d_result
;
1682 Command
* GetOptionCommand::clone() const {
1683 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
1684 c
->d_result
= d_result
;
1688 std::string
GetOptionCommand::getCommandName() const throw() {
1689 return "get-option";
1693 /* class SetExpressionNameCommand */
1695 SetExpressionNameCommand::SetExpressionNameCommand(Expr expr
, std::string name
) throw() :
1696 d_expr(expr
), d_name(name
) {
1700 void SetExpressionNameCommand::invoke(SmtEngine
* smtEngine
) {
1701 smtEngine
->setExpressionName(d_expr
, d_name
);
1702 d_commandStatus
= CommandSuccess::instance();
1705 Command
* SetExpressionNameCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1706 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
.exportTo(exprManager
, variableMap
), d_name
);
1710 Command
* SetExpressionNameCommand::clone() const {
1711 SetExpressionNameCommand
* c
= new SetExpressionNameCommand(d_expr
, d_name
);
1715 std::string
SetExpressionNameCommand::getCommandName() const throw() {
1716 return "set-expr-name";
1719 /* class DatatypeDeclarationCommand */
1721 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const DatatypeType
& datatype
) throw() :
1723 d_datatypes
.push_back(datatype
);
1726 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const std::vector
<DatatypeType
>& datatypes
) throw() :
1727 d_datatypes(datatypes
) {
1730 const std::vector
<DatatypeType
>&
1731 DatatypeDeclarationCommand::getDatatypes() const throw() {
1735 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
) {
1736 d_commandStatus
= CommandSuccess::instance();
1739 Command
* DatatypeDeclarationCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1740 throw ExportUnsupportedException
1741 ("export of DatatypeDeclarationCommand unsupported");
1744 Command
* DatatypeDeclarationCommand::clone() const {
1745 return new DatatypeDeclarationCommand(d_datatypes
);
1748 std::string
DatatypeDeclarationCommand::getCommandName() const throw() {
1749 return "declare-datatypes";
1752 /* class RewriteRuleCommand */
1754 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
1755 const std::vector
<Expr
>& guards
,
1756 Expr head
, Expr body
,
1757 const Triggers
& triggers
) throw() :
1758 d_vars(vars
), d_guards(guards
), d_head(head
), d_body(body
), d_triggers(triggers
) {
1761 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
1762 Expr head
, Expr body
) throw() :
1763 d_vars(vars
), d_head(head
), d_body(body
) {
1766 const std::vector
<Expr
>& RewriteRuleCommand::getVars() const throw() {
1770 const std::vector
<Expr
>& RewriteRuleCommand::getGuards() const throw() {
1774 Expr
RewriteRuleCommand::getHead() const throw() {
1778 Expr
RewriteRuleCommand::getBody() const throw() {
1782 const RewriteRuleCommand::Triggers
& RewriteRuleCommand::getTriggers() const throw() {
1786 void RewriteRuleCommand::invoke(SmtEngine
* smtEngine
) {
1788 ExprManager
* em
= smtEngine
->getExprManager();
1789 /** build vars list */
1790 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
1791 /** build guards list */
1793 if(d_guards
.size() == 0) guards
= em
->mkConst
<bool>(true);
1794 else if(d_guards
.size() == 1) guards
= d_guards
[0];
1795 else guards
= em
->mkExpr(kind::AND
,d_guards
);
1796 /** build expression */
1798 if( d_triggers
.empty() ){
1799 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,d_head
,d_body
);
1801 /** build triggers list */
1802 std::vector
<Expr
> vtriggers
;
1803 vtriggers
.reserve(d_triggers
.size());
1804 for(Triggers::const_iterator i
= d_triggers
.begin(),
1805 end
= d_triggers
.end(); i
!= end
; ++i
){
1806 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
,*i
));
1808 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
,vtriggers
);
1809 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,d_head
,d_body
,triggers
);
1811 smtEngine
->assertFormula(expr
);
1812 d_commandStatus
= CommandSuccess::instance();
1813 } catch(exception
& e
) {
1814 d_commandStatus
= new CommandFailure(e
.what());
1818 Command
* RewriteRuleCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1819 /** Convert variables */
1820 VExpr vars
; vars
.reserve(d_vars
.size());
1821 for(VExpr::iterator i
= d_vars
.begin(), end
= d_vars
.end();
1823 vars
.push_back(i
->exportTo(exprManager
, variableMap
));
1825 /** Convert guards */
1826 VExpr guards
; guards
.reserve(d_guards
.size());
1827 for(VExpr::iterator i
= d_guards
.begin(), end
= d_guards
.end();
1829 guards
.push_back(i
->exportTo(exprManager
, variableMap
));
1831 /** Convert triggers */
1832 Triggers triggers
; triggers
.resize(d_triggers
.size());
1833 for(size_t i
= 0, end
= d_triggers
.size();
1835 triggers
[i
].reserve(d_triggers
[i
].size());
1836 for(VExpr::iterator j
= d_triggers
[i
].begin(), jend
= d_triggers
[i
].end();
1838 triggers
[i
].push_back(j
->exportTo(exprManager
, variableMap
));
1841 /** Convert head and body */
1842 Expr head
= d_head
.exportTo(exprManager
, variableMap
);
1843 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
1844 /** Create the converted rules */
1845 return new RewriteRuleCommand(vars
, guards
, head
, body
, triggers
);
1848 Command
* RewriteRuleCommand::clone() const {
1849 return new RewriteRuleCommand(d_vars
, d_guards
, d_head
, d_body
, d_triggers
);
1852 std::string
RewriteRuleCommand::getCommandName() const throw() {
1853 return "rewrite-rule";
1856 /* class PropagateRuleCommand */
1858 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
1859 const std::vector
<Expr
>& guards
,
1860 const std::vector
<Expr
>& heads
,
1862 const Triggers
& triggers
,
1863 bool deduction
) throw() :
1864 d_vars(vars
), d_guards(guards
), d_heads(heads
), d_body(body
), d_triggers(triggers
), d_deduction(deduction
) {
1867 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
1868 const std::vector
<Expr
>& heads
,
1870 bool deduction
) throw() :
1871 d_vars(vars
), d_heads(heads
), d_body(body
), d_deduction(deduction
) {
1874 const std::vector
<Expr
>& PropagateRuleCommand::getVars() const throw() {
1878 const std::vector
<Expr
>& PropagateRuleCommand::getGuards() const throw() {
1882 const std::vector
<Expr
>& PropagateRuleCommand::getHeads() const throw() {
1886 Expr
PropagateRuleCommand::getBody() const throw() {
1890 const PropagateRuleCommand::Triggers
& PropagateRuleCommand::getTriggers() const throw() {
1894 bool PropagateRuleCommand::isDeduction() const throw() {
1898 void PropagateRuleCommand::invoke(SmtEngine
* smtEngine
) {
1900 ExprManager
* em
= smtEngine
->getExprManager();
1901 /** build vars list */
1902 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
1903 /** build guards list */
1905 if(d_guards
.size() == 0) guards
= em
->mkConst
<bool>(true);
1906 else if(d_guards
.size() == 1) guards
= d_guards
[0];
1907 else guards
= em
->mkExpr(kind::AND
,d_guards
);
1908 /** build heads list */
1910 if(d_heads
.size() == 1) heads
= d_heads
[0];
1911 else heads
= em
->mkExpr(kind::AND
,d_heads
);
1912 /** build expression */
1914 if( d_triggers
.empty() ){
1915 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,heads
,d_body
);
1917 /** build triggers list */
1918 std::vector
<Expr
> vtriggers
;
1919 vtriggers
.reserve(d_triggers
.size());
1920 for(Triggers::const_iterator i
= d_triggers
.begin(),
1921 end
= d_triggers
.end(); i
!= end
; ++i
){
1922 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
,*i
));
1924 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
,vtriggers
);
1925 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,heads
,d_body
,triggers
);
1927 smtEngine
->assertFormula(expr
);
1928 d_commandStatus
= CommandSuccess::instance();
1929 } catch(exception
& e
) {
1930 d_commandStatus
= new CommandFailure(e
.what());
1934 Command
* PropagateRuleCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1935 /** Convert variables */
1936 VExpr vars
; vars
.reserve(d_vars
.size());
1937 for(VExpr::iterator i
= d_vars
.begin(), end
= d_vars
.end();
1939 vars
.push_back(i
->exportTo(exprManager
, variableMap
));
1941 /** Convert guards */
1942 VExpr guards
; guards
.reserve(d_guards
.size());
1943 for(VExpr::iterator i
= d_guards
.begin(), end
= d_guards
.end();
1945 guards
.push_back(i
->exportTo(exprManager
, variableMap
));
1947 /** Convert heads */
1948 VExpr heads
; heads
.reserve(d_heads
.size());
1949 for(VExpr::iterator i
= d_heads
.begin(), end
= d_heads
.end();
1951 heads
.push_back(i
->exportTo(exprManager
, variableMap
));
1953 /** Convert triggers */
1954 Triggers triggers
; triggers
.resize(d_triggers
.size());
1955 for(size_t i
= 0, end
= d_triggers
.size();
1957 triggers
[i
].reserve(d_triggers
[i
].size());
1958 for(VExpr::iterator j
= d_triggers
[i
].begin(), jend
= d_triggers
[i
].end();
1960 triggers
[i
].push_back(j
->exportTo(exprManager
, variableMap
));
1963 /** Convert head and body */
1964 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
1965 /** Create the converted rules */
1966 return new PropagateRuleCommand(vars
, guards
, heads
, body
, triggers
);
1969 Command
* PropagateRuleCommand::clone() const {
1970 return new PropagateRuleCommand(d_vars
, d_guards
, d_heads
, d_body
, d_triggers
);
1973 std::string
PropagateRuleCommand::getCommandName() const throw() {
1974 return "propagate-rule";
1977 /* output stream insertion operator for benchmark statuses */
1978 std::ostream
& operator<<(std::ostream
& out
,
1979 BenchmarkStatus status
) throw() {
1982 case SMT_SATISFIABLE
:
1983 return out
<< "sat";
1985 case SMT_UNSATISFIABLE
:
1986 return out
<< "unsat";
1989 return out
<< "unknown";
1992 return out
<< "BenchmarkStatus::[UNKNOWNSTATUS!]";
1996 }/* CVC4 namespace */