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-2016 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(UnsafeInterruptException
& e
) {
1027 d_commandStatus
= new CommandInterrupted();
1028 } catch(exception
& e
) {
1029 d_commandStatus
= new CommandFailure(e
.what());
1033 Expr
GetValueCommand::getResult() const throw() {
1037 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1039 this->Command::printResult(out
, verbosity
);
1041 expr::ExprDag::Scope
scope(out
, false);
1042 out
<< d_result
<< endl
;
1046 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1047 vector
<Expr
> exportedTerms
;
1048 for(std::vector
<Expr
>::const_iterator i
= d_terms
.begin(); i
!= d_terms
.end(); ++i
) {
1049 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
1051 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
1052 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1056 Command
* GetValueCommand::clone() const {
1057 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1058 c
->d_result
= d_result
;
1062 std::string
GetValueCommand::getCommandName() const throw() {
1066 /* class GetAssignmentCommand */
1068 GetAssignmentCommand::GetAssignmentCommand() throw() {
1071 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
) {
1073 d_result
= smtEngine
->getAssignment();
1074 d_commandStatus
= CommandSuccess::instance();
1075 } catch(UnsafeInterruptException
& e
) {
1076 d_commandStatus
= new CommandInterrupted();
1077 } catch(exception
& e
) {
1078 d_commandStatus
= new CommandFailure(e
.what());
1082 SExpr
GetAssignmentCommand::getResult() const throw() {
1086 void GetAssignmentCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1088 this->Command::printResult(out
, verbosity
);
1090 out
<< d_result
<< endl
;
1094 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1095 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1096 c
->d_result
= d_result
;
1100 Command
* GetAssignmentCommand::clone() const {
1101 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1102 c
->d_result
= d_result
;
1106 std::string
GetAssignmentCommand::getCommandName() const throw() {
1107 return "get-assignment";
1110 /* class GetModelCommand */
1112 GetModelCommand::GetModelCommand() throw() {
1115 void GetModelCommand::invoke(SmtEngine
* smtEngine
) {
1117 d_result
= smtEngine
->getModel();
1118 d_smtEngine
= smtEngine
;
1119 d_commandStatus
= CommandSuccess::instance();
1120 } catch(UnsafeInterruptException
& e
) {
1121 d_commandStatus
= new CommandInterrupted();
1122 } catch(exception
& e
) {
1123 d_commandStatus
= new CommandFailure(e
.what());
1127 /* Model is private to the library -- for now
1128 Model* GetModelCommand::getResult() const throw() {
1133 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1135 this->Command::printResult(out
, verbosity
);
1141 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1142 GetModelCommand
* c
= new GetModelCommand();
1143 c
->d_result
= d_result
;
1144 c
->d_smtEngine
= d_smtEngine
;
1148 Command
* GetModelCommand::clone() const {
1149 GetModelCommand
* c
= new GetModelCommand();
1150 c
->d_result
= d_result
;
1151 c
->d_smtEngine
= d_smtEngine
;
1155 std::string
GetModelCommand::getCommandName() const throw() {
1159 /* class GetProofCommand */
1161 GetProofCommand::GetProofCommand() throw() {
1164 void GetProofCommand::invoke(SmtEngine
* smtEngine
) {
1166 d_smtEngine
= smtEngine
;
1167 d_result
= smtEngine
->getProof();
1168 d_commandStatus
= CommandSuccess::instance();
1169 } catch(UnsafeInterruptException
& e
) {
1170 d_commandStatus
= new CommandInterrupted();
1171 } catch(exception
& e
) {
1172 d_commandStatus
= new CommandFailure(e
.what());
1176 Proof
* GetProofCommand::getResult() const throw() {
1180 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1182 this->Command::printResult(out
, verbosity
);
1184 smt::SmtScope
scope(d_smtEngine
);
1185 d_result
->toStream(out
);
1189 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1190 GetProofCommand
* c
= new GetProofCommand();
1191 c
->d_result
= d_result
;
1192 c
->d_smtEngine
= d_smtEngine
;
1196 Command
* GetProofCommand::clone() const {
1197 GetProofCommand
* c
= new GetProofCommand();
1198 c
->d_result
= d_result
;
1199 c
->d_smtEngine
= d_smtEngine
;
1203 std::string
GetProofCommand::getCommandName() const throw() {
1207 /* class GetInstantiationsCommand */
1209 GetInstantiationsCommand::GetInstantiationsCommand() throw() {
1212 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
) {
1214 d_smtEngine
= smtEngine
;
1215 d_commandStatus
= CommandSuccess::instance();
1216 } catch(exception
& e
) {
1217 d_commandStatus
= new CommandFailure(e
.what());
1221 //Instantiations* GetInstantiationsCommand::getResult() const throw() {
1225 void GetInstantiationsCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1227 this->Command::printResult(out
, verbosity
);
1229 d_smtEngine
->printInstantiations(out
);
1233 Command
* GetInstantiationsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1234 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1235 //c->d_result = d_result;
1236 c
->d_smtEngine
= d_smtEngine
;
1240 Command
* GetInstantiationsCommand::clone() const {
1241 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1242 //c->d_result = d_result;
1243 c
->d_smtEngine
= d_smtEngine
;
1247 std::string
GetInstantiationsCommand::getCommandName() const throw() {
1248 return "get-instantiations";
1251 /* class GetSynthSolutionCommand */
1253 GetSynthSolutionCommand::GetSynthSolutionCommand() throw() {
1256 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
) {
1258 d_smtEngine
= smtEngine
;
1259 d_commandStatus
= CommandSuccess::instance();
1260 } catch(exception
& e
) {
1261 d_commandStatus
= new CommandFailure(e
.what());
1265 void GetSynthSolutionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1267 this->Command::printResult(out
, verbosity
);
1269 d_smtEngine
->printSynthSolution(out
);
1273 Command
* GetSynthSolutionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1274 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1275 c
->d_smtEngine
= d_smtEngine
;
1279 Command
* GetSynthSolutionCommand::clone() const {
1280 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1281 c
->d_smtEngine
= d_smtEngine
;
1285 std::string
GetSynthSolutionCommand::getCommandName() const throw() {
1286 return "get-instantiations";
1289 /* class GetQuantifierEliminationCommand */
1291 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand() throw() :
1295 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(const Expr
& expr
, bool doFull
) throw() :
1296 d_expr(expr
), d_doFull(doFull
) {
1299 Expr
GetQuantifierEliminationCommand::getExpr() const throw() {
1302 bool GetQuantifierEliminationCommand::getDoFull() const throw() {
1306 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
) {
1308 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
1309 d_commandStatus
= CommandSuccess::instance();
1310 } catch(exception
& e
) {
1311 d_commandStatus
= new CommandFailure(e
.what());
1315 Expr
GetQuantifierEliminationCommand::getResult() const throw() {
1319 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1321 this->Command::printResult(out
, verbosity
);
1323 out
<< d_result
<< endl
;
1327 Command
* GetQuantifierEliminationCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1328 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
1329 c
->d_result
= d_result
;
1333 Command
* GetQuantifierEliminationCommand::clone() const {
1334 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
1335 c
->d_result
= d_result
;
1339 std::string
GetQuantifierEliminationCommand::getCommandName() const throw() {
1340 return d_doFull
? "get-qe" : "get-qe-disjunct";
1343 /* class GetUnsatCoreCommand */
1345 GetUnsatCoreCommand::GetUnsatCoreCommand() throw() {
1348 GetUnsatCoreCommand::GetUnsatCoreCommand(const std::map
<Expr
, std::string
>& names
) throw() : d_names(names
) {
1351 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
) {
1353 d_result
= smtEngine
->getUnsatCore();
1354 d_commandStatus
= CommandSuccess::instance();
1355 } catch(exception
& e
) {
1356 d_commandStatus
= new CommandFailure(e
.what());
1360 void GetUnsatCoreCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1362 this->Command::printResult(out
, verbosity
);
1364 d_result
.toStream(out
, d_names
);
1368 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const throw() {
1369 // of course, this will be empty if the command hasn't been invoked yet
1373 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1374 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand(d_names
);
1375 c
->d_result
= d_result
;
1379 Command
* GetUnsatCoreCommand::clone() const {
1380 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand(d_names
);
1381 c
->d_result
= d_result
;
1385 std::string
GetUnsatCoreCommand::getCommandName() const throw() {
1386 return "get-unsat-core";
1389 /* class GetAssertionsCommand */
1391 GetAssertionsCommand::GetAssertionsCommand() throw() {
1394 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
) {
1397 const vector
<Expr
> v
= smtEngine
->getAssertions();
1399 copy( v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n") );
1401 d_result
= ss
.str();
1402 d_commandStatus
= CommandSuccess::instance();
1403 } catch(exception
& e
) {
1404 d_commandStatus
= new CommandFailure(e
.what());
1408 std::string
GetAssertionsCommand::getResult() const throw() {
1412 void GetAssertionsCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1414 this->Command::printResult(out
, verbosity
);
1420 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1421 GetAssertionsCommand
* c
= new GetAssertionsCommand();
1422 c
->d_result
= d_result
;
1426 Command
* GetAssertionsCommand::clone() const {
1427 GetAssertionsCommand
* c
= new GetAssertionsCommand();
1428 c
->d_result
= d_result
;
1432 std::string
GetAssertionsCommand::getCommandName() const throw() {
1433 return "get-assertions";
1436 /* class SetBenchmarkStatusCommand */
1438 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
) throw() :
1442 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const throw() {
1446 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
) {
1450 SExpr status
= SExpr(ss
.str());
1451 smtEngine
->setInfo("status", status
);
1452 d_commandStatus
= CommandSuccess::instance();
1453 } catch(exception
& e
) {
1454 d_commandStatus
= new CommandFailure(e
.what());
1458 Command
* SetBenchmarkStatusCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1459 return new SetBenchmarkStatusCommand(d_status
);
1462 Command
* SetBenchmarkStatusCommand::clone() const {
1463 return new SetBenchmarkStatusCommand(d_status
);
1466 std::string
SetBenchmarkStatusCommand::getCommandName() const throw() {
1470 /* class SetBenchmarkLogicCommand */
1472 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
) throw() :
1476 std::string
SetBenchmarkLogicCommand::getLogic() const throw() {
1480 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
) {
1482 smtEngine
->setLogic(d_logic
);
1483 d_commandStatus
= CommandSuccess::instance();
1484 } catch(exception
& e
) {
1485 d_commandStatus
= new CommandFailure(e
.what());
1489 Command
* SetBenchmarkLogicCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1490 return new SetBenchmarkLogicCommand(d_logic
);
1493 Command
* SetBenchmarkLogicCommand::clone() const {
1494 return new SetBenchmarkLogicCommand(d_logic
);
1497 std::string
SetBenchmarkLogicCommand::getCommandName() const throw() {
1501 /* class SetInfoCommand */
1503 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
) throw() :
1508 std::string
SetInfoCommand::getFlag() const throw() {
1512 SExpr
SetInfoCommand::getSExpr() const throw() {
1516 void SetInfoCommand::invoke(SmtEngine
* smtEngine
) {
1518 smtEngine
->setInfo(d_flag
, d_sexpr
);
1519 d_commandStatus
= CommandSuccess::instance();
1520 } catch(UnrecognizedOptionException
&) {
1521 // As per SMT-LIB spec, silently accept unknown set-info keys
1522 d_commandStatus
= CommandSuccess::instance();
1523 } catch(exception
& e
) {
1524 d_commandStatus
= new CommandFailure(e
.what());
1528 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1529 return new SetInfoCommand(d_flag
, d_sexpr
);
1532 Command
* SetInfoCommand::clone() const {
1533 return new SetInfoCommand(d_flag
, d_sexpr
);
1536 std::string
SetInfoCommand::getCommandName() const throw() {
1540 /* class GetInfoCommand */
1542 GetInfoCommand::GetInfoCommand(std::string flag
) throw() :
1546 std::string
GetInfoCommand::getFlag() const throw() {
1550 void GetInfoCommand::invoke(SmtEngine
* smtEngine
) {
1553 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
1554 v
.push_back(smtEngine
->getInfo(d_flag
));
1556 if(d_flag
== "all-options" || d_flag
== "all-statistics") {
1557 ss
<< PrettySExprs(true);
1560 d_result
= ss
.str();
1561 d_commandStatus
= CommandSuccess::instance();
1562 } catch(UnrecognizedOptionException
&) {
1563 d_commandStatus
= new CommandUnsupported();
1564 } catch(exception
& e
) {
1565 d_commandStatus
= new CommandFailure(e
.what());
1569 std::string
GetInfoCommand::getResult() const throw() {
1573 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1575 this->Command::printResult(out
, verbosity
);
1576 } else if(d_result
!= "") {
1577 out
<< d_result
<< endl
;
1581 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1582 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
1583 c
->d_result
= d_result
;
1587 Command
* GetInfoCommand::clone() const {
1588 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
1589 c
->d_result
= d_result
;
1593 std::string
GetInfoCommand::getCommandName() const throw() {
1597 /* class SetOptionCommand */
1599 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
) throw() :
1604 std::string
SetOptionCommand::getFlag() const throw() {
1608 SExpr
SetOptionCommand::getSExpr() const throw() {
1612 void SetOptionCommand::invoke(SmtEngine
* smtEngine
) {
1614 smtEngine
->setOption(d_flag
, d_sexpr
);
1615 d_commandStatus
= CommandSuccess::instance();
1616 } catch(UnrecognizedOptionException
&) {
1617 d_commandStatus
= new CommandUnsupported();
1618 } catch(exception
& e
) {
1619 d_commandStatus
= new CommandFailure(e
.what());
1623 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1624 return new SetOptionCommand(d_flag
, d_sexpr
);
1627 Command
* SetOptionCommand::clone() const {
1628 return new SetOptionCommand(d_flag
, d_sexpr
);
1631 std::string
SetOptionCommand::getCommandName() const throw() {
1632 return "set-option";
1635 /* class GetOptionCommand */
1637 GetOptionCommand::GetOptionCommand(std::string flag
) throw() :
1641 std::string
GetOptionCommand::getFlag() const throw() {
1645 void GetOptionCommand::invoke(SmtEngine
* smtEngine
) {
1647 SExpr res
= smtEngine
->getOption(d_flag
);
1648 d_result
= res
.toString();
1649 d_commandStatus
= CommandSuccess::instance();
1650 } catch(UnrecognizedOptionException
&) {
1651 d_commandStatus
= new CommandUnsupported();
1652 } catch(exception
& e
) {
1653 d_commandStatus
= new CommandFailure(e
.what());
1657 std::string
GetOptionCommand::getResult() const throw() {
1661 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const {
1663 this->Command::printResult(out
, verbosity
);
1664 } else if(d_result
!= "") {
1665 out
<< d_result
<< endl
;
1669 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1670 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
1671 c
->d_result
= d_result
;
1675 Command
* GetOptionCommand::clone() const {
1676 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
1677 c
->d_result
= d_result
;
1681 std::string
GetOptionCommand::getCommandName() const throw() {
1682 return "get-option";
1685 /* class DatatypeDeclarationCommand */
1687 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const DatatypeType
& datatype
) throw() :
1689 d_datatypes
.push_back(datatype
);
1692 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const std::vector
<DatatypeType
>& datatypes
) throw() :
1693 d_datatypes(datatypes
) {
1696 const std::vector
<DatatypeType
>&
1697 DatatypeDeclarationCommand::getDatatypes() const throw() {
1701 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
) {
1702 d_commandStatus
= CommandSuccess::instance();
1705 Command
* DatatypeDeclarationCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1706 throw ExportUnsupportedException
1707 ("export of DatatypeDeclarationCommand unsupported");
1710 Command
* DatatypeDeclarationCommand::clone() const {
1711 return new DatatypeDeclarationCommand(d_datatypes
);
1714 std::string
DatatypeDeclarationCommand::getCommandName() const throw() {
1715 return "declare-datatypes";
1718 /* class RewriteRuleCommand */
1720 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
1721 const std::vector
<Expr
>& guards
,
1722 Expr head
, Expr body
,
1723 const Triggers
& triggers
) throw() :
1724 d_vars(vars
), d_guards(guards
), d_head(head
), d_body(body
), d_triggers(triggers
) {
1727 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
1728 Expr head
, Expr body
) throw() :
1729 d_vars(vars
), d_head(head
), d_body(body
) {
1732 const std::vector
<Expr
>& RewriteRuleCommand::getVars() const throw() {
1736 const std::vector
<Expr
>& RewriteRuleCommand::getGuards() const throw() {
1740 Expr
RewriteRuleCommand::getHead() const throw() {
1744 Expr
RewriteRuleCommand::getBody() const throw() {
1748 const RewriteRuleCommand::Triggers
& RewriteRuleCommand::getTriggers() const throw() {
1752 void RewriteRuleCommand::invoke(SmtEngine
* smtEngine
) {
1754 ExprManager
* em
= smtEngine
->getExprManager();
1755 /** build vars list */
1756 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
1757 /** build guards list */
1759 if(d_guards
.size() == 0) guards
= em
->mkConst
<bool>(true);
1760 else if(d_guards
.size() == 1) guards
= d_guards
[0];
1761 else guards
= em
->mkExpr(kind::AND
,d_guards
);
1762 /** build expression */
1764 if( d_triggers
.empty() ){
1765 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,d_head
,d_body
);
1767 /** build triggers list */
1768 std::vector
<Expr
> vtriggers
;
1769 vtriggers
.reserve(d_triggers
.size());
1770 for(Triggers::const_iterator i
= d_triggers
.begin(),
1771 end
= d_triggers
.end(); i
!= end
; ++i
){
1772 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
,*i
));
1774 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
,vtriggers
);
1775 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,d_head
,d_body
,triggers
);
1777 smtEngine
->assertFormula(expr
);
1778 d_commandStatus
= CommandSuccess::instance();
1779 } catch(exception
& e
) {
1780 d_commandStatus
= new CommandFailure(e
.what());
1784 Command
* RewriteRuleCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1785 /** Convert variables */
1786 VExpr vars
; vars
.reserve(d_vars
.size());
1787 for(VExpr::iterator i
= d_vars
.begin(), end
= d_vars
.end();
1789 vars
.push_back(i
->exportTo(exprManager
, variableMap
));
1791 /** Convert guards */
1792 VExpr guards
; guards
.reserve(d_guards
.size());
1793 for(VExpr::iterator i
= d_guards
.begin(), end
= d_guards
.end();
1795 guards
.push_back(i
->exportTo(exprManager
, variableMap
));
1797 /** Convert triggers */
1798 Triggers triggers
; triggers
.resize(d_triggers
.size());
1799 for(size_t i
= 0, end
= d_triggers
.size();
1801 triggers
[i
].reserve(d_triggers
[i
].size());
1802 for(VExpr::iterator j
= d_triggers
[i
].begin(), jend
= d_triggers
[i
].end();
1804 triggers
[i
].push_back(j
->exportTo(exprManager
, variableMap
));
1807 /** Convert head and body */
1808 Expr head
= d_head
.exportTo(exprManager
, variableMap
);
1809 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
1810 /** Create the converted rules */
1811 return new RewriteRuleCommand(vars
, guards
, head
, body
, triggers
);
1814 Command
* RewriteRuleCommand::clone() const {
1815 return new RewriteRuleCommand(d_vars
, d_guards
, d_head
, d_body
, d_triggers
);
1818 std::string
RewriteRuleCommand::getCommandName() const throw() {
1819 return "rewrite-rule";
1822 /* class PropagateRuleCommand */
1824 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
1825 const std::vector
<Expr
>& guards
,
1826 const std::vector
<Expr
>& heads
,
1828 const Triggers
& triggers
,
1829 bool deduction
) throw() :
1830 d_vars(vars
), d_guards(guards
), d_heads(heads
), d_body(body
), d_triggers(triggers
), d_deduction(deduction
) {
1833 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
1834 const std::vector
<Expr
>& heads
,
1836 bool deduction
) throw() :
1837 d_vars(vars
), d_heads(heads
), d_body(body
), d_deduction(deduction
) {
1840 const std::vector
<Expr
>& PropagateRuleCommand::getVars() const throw() {
1844 const std::vector
<Expr
>& PropagateRuleCommand::getGuards() const throw() {
1848 const std::vector
<Expr
>& PropagateRuleCommand::getHeads() const throw() {
1852 Expr
PropagateRuleCommand::getBody() const throw() {
1856 const PropagateRuleCommand::Triggers
& PropagateRuleCommand::getTriggers() const throw() {
1860 bool PropagateRuleCommand::isDeduction() const throw() {
1864 void PropagateRuleCommand::invoke(SmtEngine
* smtEngine
) {
1866 ExprManager
* em
= smtEngine
->getExprManager();
1867 /** build vars list */
1868 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
1869 /** build guards list */
1871 if(d_guards
.size() == 0) guards
= em
->mkConst
<bool>(true);
1872 else if(d_guards
.size() == 1) guards
= d_guards
[0];
1873 else guards
= em
->mkExpr(kind::AND
,d_guards
);
1874 /** build heads list */
1876 if(d_heads
.size() == 1) heads
= d_heads
[0];
1877 else heads
= em
->mkExpr(kind::AND
,d_heads
);
1878 /** build expression */
1880 if( d_triggers
.empty() ){
1881 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,heads
,d_body
);
1883 /** build triggers list */
1884 std::vector
<Expr
> vtriggers
;
1885 vtriggers
.reserve(d_triggers
.size());
1886 for(Triggers::const_iterator i
= d_triggers
.begin(),
1887 end
= d_triggers
.end(); i
!= end
; ++i
){
1888 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
,*i
));
1890 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
,vtriggers
);
1891 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,heads
,d_body
,triggers
);
1893 smtEngine
->assertFormula(expr
);
1894 d_commandStatus
= CommandSuccess::instance();
1895 } catch(exception
& e
) {
1896 d_commandStatus
= new CommandFailure(e
.what());
1900 Command
* PropagateRuleCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1901 /** Convert variables */
1902 VExpr vars
; vars
.reserve(d_vars
.size());
1903 for(VExpr::iterator i
= d_vars
.begin(), end
= d_vars
.end();
1905 vars
.push_back(i
->exportTo(exprManager
, variableMap
));
1907 /** Convert guards */
1908 VExpr guards
; guards
.reserve(d_guards
.size());
1909 for(VExpr::iterator i
= d_guards
.begin(), end
= d_guards
.end();
1911 guards
.push_back(i
->exportTo(exprManager
, variableMap
));
1913 /** Convert heads */
1914 VExpr heads
; heads
.reserve(d_heads
.size());
1915 for(VExpr::iterator i
= d_heads
.begin(), end
= d_heads
.end();
1917 heads
.push_back(i
->exportTo(exprManager
, variableMap
));
1919 /** Convert triggers */
1920 Triggers triggers
; triggers
.resize(d_triggers
.size());
1921 for(size_t i
= 0, end
= d_triggers
.size();
1923 triggers
[i
].reserve(d_triggers
[i
].size());
1924 for(VExpr::iterator j
= d_triggers
[i
].begin(), jend
= d_triggers
[i
].end();
1926 triggers
[i
].push_back(j
->exportTo(exprManager
, variableMap
));
1929 /** Convert head and body */
1930 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
1931 /** Create the converted rules */
1932 return new PropagateRuleCommand(vars
, guards
, heads
, body
, triggers
);
1935 Command
* PropagateRuleCommand::clone() const {
1936 return new PropagateRuleCommand(d_vars
, d_guards
, d_heads
, d_body
, d_triggers
);
1939 std::string
PropagateRuleCommand::getCommandName() const throw() {
1940 return "propagate-rule";
1943 /* output stream insertion operator for benchmark statuses */
1944 std::ostream
& operator<<(std::ostream
& out
,
1945 BenchmarkStatus status
) throw() {
1948 case SMT_SATISFIABLE
:
1949 return out
<< "sat";
1951 case SMT_UNSATISFIABLE
:
1952 return out
<< "unsat";
1955 return out
<< "unknown";
1958 return out
<< "BenchmarkStatus::[UNKNOWNSTATUS!]";
1962 }/* CVC4 namespace */