1 /********************* */
4 ** Original author: Morgan Deters
5 ** Major contributors: none
6 ** Minor contributors (to current version): Kshitij Bansal, Dejan Jovanovic, Andrew Reynolds, Francois Bobot
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** 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
) throw() {
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 throw() {
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
) throw() {
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
) throw() {
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
) throw() {
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
) throw() {
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
) throw() {
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
) throw() {
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
) throw() {
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 throw() {
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
) throw() {
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 throw() {
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() {
379 /* class ResetCommand */
381 void ResetCommand::invoke(SmtEngine
* smtEngine
) throw() {
384 d_commandStatus
= CommandSuccess::instance();
385 } catch(exception
& e
) {
386 d_commandStatus
= new CommandFailure(e
.what());
390 Command
* ResetCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
391 return new ResetCommand();
394 Command
* ResetCommand::clone() const {
395 return new ResetCommand();
398 std::string
ResetCommand::getCommandName() const throw() {
402 /* class ResetAssertionsCommand */
404 void ResetAssertionsCommand::invoke(SmtEngine
* smtEngine
) throw() {
406 smtEngine
->resetAssertions();
407 d_commandStatus
= CommandSuccess::instance();
408 } catch(exception
& e
) {
409 d_commandStatus
= new CommandFailure(e
.what());
413 Command
* ResetAssertionsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
414 return new ResetAssertionsCommand();
417 Command
* ResetAssertionsCommand::clone() const {
418 return new ResetAssertionsCommand();
421 std::string
ResetAssertionsCommand::getCommandName() const throw() {
422 return "reset-assertions";
425 /* class QuitCommand */
427 void QuitCommand::invoke(SmtEngine
* smtEngine
) throw() {
428 Dump("benchmark") << *this;
429 d_commandStatus
= CommandSuccess::instance();
432 Command
* QuitCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
433 return new QuitCommand();
436 Command
* QuitCommand::clone() const {
437 return new QuitCommand();
440 std::string
QuitCommand::getCommandName() const throw() {
444 /* class CommentCommand */
446 CommentCommand::CommentCommand(std::string comment
) throw() : d_comment(comment
) {
449 std::string
CommentCommand::getComment() const throw() {
453 void CommentCommand::invoke(SmtEngine
* smtEngine
) throw() {
454 Dump("benchmark") << *this;
455 d_commandStatus
= CommandSuccess::instance();
458 Command
* CommentCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
459 return new CommentCommand(d_comment
);
462 Command
* CommentCommand::clone() const {
463 return new CommentCommand(d_comment
);
466 std::string
CommentCommand::getCommandName() const throw() {
470 /* class CommandSequence */
472 CommandSequence::CommandSequence() throw() :
476 CommandSequence::~CommandSequence() throw() {
477 for(unsigned i
= d_index
; i
< d_commandSequence
.size(); ++i
) {
478 delete d_commandSequence
[i
];
482 void CommandSequence::addCommand(Command
* cmd
) throw() {
483 d_commandSequence
.push_back(cmd
);
486 void CommandSequence::clear() throw() {
487 d_commandSequence
.clear();
490 void CommandSequence::invoke(SmtEngine
* smtEngine
) throw() {
491 for(; d_index
< d_commandSequence
.size(); ++d_index
) {
492 d_commandSequence
[d_index
]->invoke(smtEngine
);
493 if(! d_commandSequence
[d_index
]->ok()) {
495 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
498 delete d_commandSequence
[d_index
];
501 AlwaysAssert(d_commandStatus
== NULL
);
502 d_commandStatus
= CommandSuccess::instance();
505 void CommandSequence::invoke(SmtEngine
* smtEngine
, std::ostream
& out
) throw() {
506 for(; d_index
< d_commandSequence
.size(); ++d_index
) {
507 d_commandSequence
[d_index
]->invoke(smtEngine
, out
);
508 if(! d_commandSequence
[d_index
]->ok()) {
510 d_commandStatus
= d_commandSequence
[d_index
]->getCommandStatus();
513 delete d_commandSequence
[d_index
];
516 AlwaysAssert(d_commandStatus
== NULL
);
517 d_commandStatus
= CommandSuccess::instance();
520 Command
* CommandSequence::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
521 CommandSequence
* seq
= new CommandSequence();
522 for(iterator i
= begin(); i
!= end(); ++i
) {
523 Command
* cmd_to_export
= *i
;
524 Command
* cmd
= cmd_to_export
->exportTo(exprManager
, variableMap
);
525 seq
->addCommand(cmd
);
526 Debug("export") << "[export] so far converted: " << seq
<< endl
;
528 seq
->d_index
= d_index
;
532 Command
* CommandSequence::clone() const {
533 CommandSequence
* seq
= new CommandSequence();
534 for(const_iterator i
= begin(); i
!= end(); ++i
) {
535 seq
->addCommand((*i
)->clone());
537 seq
->d_index
= d_index
;
541 CommandSequence::const_iterator
CommandSequence::begin() const throw() {
542 return d_commandSequence
.begin();
545 CommandSequence::const_iterator
CommandSequence::end() const throw() {
546 return d_commandSequence
.end();
549 CommandSequence::iterator
CommandSequence::begin() throw() {
550 return d_commandSequence
.begin();
553 CommandSequence::iterator
CommandSequence::end() throw() {
554 return d_commandSequence
.end();
557 std::string
CommandSequence::getCommandName() const throw() {
561 /* class DeclarationSequenceCommand */
563 /* class DeclarationDefinitionCommand */
565 DeclarationDefinitionCommand::DeclarationDefinitionCommand(const std::string
& id
) throw() :
569 std::string
DeclarationDefinitionCommand::getSymbol() const throw() {
573 /* class DeclareFunctionCommand */
575 DeclareFunctionCommand::DeclareFunctionCommand(const std::string
& id
, Expr func
, Type t
) throw() :
576 DeclarationDefinitionCommand(id
),
579 d_printInModel(true),
580 d_printInModelSetByUser(false){
583 Expr
DeclareFunctionCommand::getFunction() const throw() {
587 Type
DeclareFunctionCommand::getType() const throw() {
591 bool DeclareFunctionCommand::getPrintInModel() const throw() {
592 return d_printInModel
;
595 bool DeclareFunctionCommand::getPrintInModelSetByUser() const throw() {
596 return d_printInModelSetByUser
;
599 void DeclareFunctionCommand::setPrintInModel( bool p
) {
601 d_printInModelSetByUser
= true;
604 void DeclareFunctionCommand::invoke(SmtEngine
* smtEngine
) throw() {
605 d_commandStatus
= CommandSuccess::instance();
608 Command
* DeclareFunctionCommand::exportTo(ExprManager
* exprManager
,
609 ExprManagerMapCollection
& variableMap
) {
610 DeclareFunctionCommand
* dfc
= new DeclareFunctionCommand(d_symbol
, d_func
.exportTo(exprManager
, variableMap
),
611 d_type
.exportTo(exprManager
, variableMap
));
612 dfc
->d_printInModel
= d_printInModel
;
613 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
617 Command
* DeclareFunctionCommand::clone() const {
618 DeclareFunctionCommand
* dfc
= new DeclareFunctionCommand(d_symbol
, d_func
, d_type
);
619 dfc
->d_printInModel
= d_printInModel
;
620 dfc
->d_printInModelSetByUser
= d_printInModelSetByUser
;
624 std::string
DeclareFunctionCommand::getCommandName() const throw() {
625 return "declare-fun";
628 /* class DeclareTypeCommand */
630 DeclareTypeCommand::DeclareTypeCommand(const std::string
& id
, size_t arity
, Type t
) throw() :
631 DeclarationDefinitionCommand(id
),
636 size_t DeclareTypeCommand::getArity() const throw() {
640 Type
DeclareTypeCommand::getType() const throw() {
644 void DeclareTypeCommand::invoke(SmtEngine
* smtEngine
) throw() {
645 d_commandStatus
= CommandSuccess::instance();
648 Command
* DeclareTypeCommand::exportTo(ExprManager
* exprManager
,
649 ExprManagerMapCollection
& variableMap
) {
650 return new DeclareTypeCommand(d_symbol
, d_arity
,
651 d_type
.exportTo(exprManager
, variableMap
));
654 Command
* DeclareTypeCommand::clone() const {
655 return new DeclareTypeCommand(d_symbol
, d_arity
, d_type
);
658 std::string
DeclareTypeCommand::getCommandName() const throw() {
659 return "declare-sort";
662 /* class DefineTypeCommand */
664 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
666 DeclarationDefinitionCommand(id
),
671 DefineTypeCommand::DefineTypeCommand(const std::string
& id
,
672 const std::vector
<Type
>& params
,
674 DeclarationDefinitionCommand(id
),
679 const std::vector
<Type
>& DefineTypeCommand::getParameters() const throw() {
683 Type
DefineTypeCommand::getType() const throw() {
687 void DefineTypeCommand::invoke(SmtEngine
* smtEngine
) throw() {
688 d_commandStatus
= CommandSuccess::instance();
691 Command
* DefineTypeCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
693 transform(d_params
.begin(), d_params
.end(), back_inserter(params
),
694 ExportTransformer(exprManager
, variableMap
));
695 Type type
= d_type
.exportTo(exprManager
, variableMap
);
696 return new DefineTypeCommand(d_symbol
, params
, type
);
699 Command
* DefineTypeCommand::clone() const {
700 return new DefineTypeCommand(d_symbol
, d_params
, d_type
);
703 std::string
DefineTypeCommand::getCommandName() const throw() {
704 return "define-sort";
707 /* class DefineFunctionCommand */
709 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
711 Expr formula
) throw() :
712 DeclarationDefinitionCommand(id
),
718 DefineFunctionCommand::DefineFunctionCommand(const std::string
& id
,
720 const std::vector
<Expr
>& formals
,
721 Expr formula
) throw() :
722 DeclarationDefinitionCommand(id
),
728 Expr
DefineFunctionCommand::getFunction() const throw() {
732 const std::vector
<Expr
>& DefineFunctionCommand::getFormals() const throw() {
736 Expr
DefineFunctionCommand::getFormula() const throw() {
740 void DefineFunctionCommand::invoke(SmtEngine
* smtEngine
) throw() {
742 if(!d_func
.isNull()) {
743 smtEngine
->defineFunction(d_func
, d_formals
, d_formula
);
745 d_commandStatus
= CommandSuccess::instance();
746 } catch(exception
& e
) {
747 d_commandStatus
= new CommandFailure(e
.what());
751 Command
* DefineFunctionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
752 Expr func
= d_func
.exportTo(exprManager
, variableMap
, /* flags = */ ExprManager::VAR_FLAG_DEFINED
);
753 vector
<Expr
> formals
;
754 transform(d_formals
.begin(), d_formals
.end(), back_inserter(formals
),
755 ExportTransformer(exprManager
, variableMap
));
756 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
757 return new DefineFunctionCommand(d_symbol
, func
, formals
, formula
);
760 Command
* DefineFunctionCommand::clone() const {
761 return new DefineFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
764 std::string
DefineFunctionCommand::getCommandName() const throw() {
768 /* class DefineNamedFunctionCommand */
770 DefineNamedFunctionCommand::DefineNamedFunctionCommand(const std::string
& id
,
772 const std::vector
<Expr
>& formals
,
773 Expr formula
) throw() :
774 DefineFunctionCommand(id
, func
, formals
, formula
) {
777 void DefineNamedFunctionCommand::invoke(SmtEngine
* smtEngine
) throw() {
778 this->DefineFunctionCommand::invoke(smtEngine
);
779 if(!d_func
.isNull() && d_func
.getType().isBoolean()) {
780 smtEngine
->addToAssignment(d_func
.getExprManager()->mkExpr(kind::APPLY
, d_func
));
782 d_commandStatus
= CommandSuccess::instance();
785 Command
* DefineNamedFunctionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
786 Expr func
= d_func
.exportTo(exprManager
, variableMap
);
787 vector
<Expr
> formals
;
788 transform(d_formals
.begin(), d_formals
.end(), back_inserter(formals
),
789 ExportTransformer(exprManager
, variableMap
));
790 Expr formula
= d_formula
.exportTo(exprManager
, variableMap
);
791 return new DefineNamedFunctionCommand(d_symbol
, func
, formals
, formula
);
794 Command
* DefineNamedFunctionCommand::clone() const {
795 return new DefineNamedFunctionCommand(d_symbol
, d_func
, d_formals
, d_formula
);
798 /* class SetUserAttribute */
800 SetUserAttributeCommand::SetUserAttributeCommand( const std::string
& attr
, Expr expr
) throw() :
801 d_attr( attr
), d_expr( expr
){
804 SetUserAttributeCommand::SetUserAttributeCommand( const std::string
& attr
, Expr expr
,
805 std::vector
<Expr
>& values
) throw() :
806 d_attr( attr
), d_expr( expr
){
807 d_expr_values
.insert( d_expr_values
.begin(), values
.begin(), values
.end() );
810 SetUserAttributeCommand::SetUserAttributeCommand( const std::string
& attr
, Expr expr
,
811 const std::string
& value
) throw() :
812 d_attr( attr
), d_expr( expr
), d_str_value( value
){
815 void SetUserAttributeCommand::invoke(SmtEngine
* smtEngine
) throw(){
817 if(!d_expr
.isNull()) {
818 smtEngine
->setUserAttribute( d_attr
, d_expr
, d_expr_values
, d_str_value
);
820 d_commandStatus
= CommandSuccess::instance();
821 } catch(exception
& e
) {
822 d_commandStatus
= new CommandFailure(e
.what());
826 Command
* SetUserAttributeCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
){
827 Expr expr
= d_expr
.exportTo(exprManager
, variableMap
);
828 SetUserAttributeCommand
* c
= new SetUserAttributeCommand( d_attr
, expr
, d_str_value
);
829 c
->d_expr_values
.insert( c
->d_expr_values
.end(), d_expr_values
.begin(), d_expr_values
.end() );
833 Command
* SetUserAttributeCommand::clone() const{
834 SetUserAttributeCommand
* c
= new SetUserAttributeCommand( d_attr
, d_expr
, d_str_value
);
835 c
->d_expr_values
.insert( c
->d_expr_values
.end(), d_expr_values
.begin(), d_expr_values
.end() );
839 std::string
SetUserAttributeCommand::getCommandName() const throw() {
840 return "set-user-attribute";
843 /* class SimplifyCommand */
845 SimplifyCommand::SimplifyCommand(Expr term
) throw() :
849 Expr
SimplifyCommand::getTerm() const throw() {
853 void SimplifyCommand::invoke(SmtEngine
* smtEngine
) throw() {
855 d_result
= smtEngine
->simplify(d_term
);
856 d_commandStatus
= CommandSuccess::instance();
857 } catch(UnsafeInterruptException
& e
) {
858 d_commandStatus
= new CommandInterrupted();
859 } catch(exception
& e
) {
860 d_commandStatus
= new CommandFailure(e
.what());
864 Expr
SimplifyCommand::getResult() const throw() {
868 void SimplifyCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
870 this->Command::printResult(out
, verbosity
);
872 out
<< d_result
<< endl
;
876 Command
* SimplifyCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
877 SimplifyCommand
* c
= new SimplifyCommand(d_term
.exportTo(exprManager
, variableMap
));
878 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
882 Command
* SimplifyCommand::clone() const {
883 SimplifyCommand
* c
= new SimplifyCommand(d_term
);
884 c
->d_result
= d_result
;
888 std::string
SimplifyCommand::getCommandName() const throw() {
892 /* class ExpandDefinitionsCommand */
894 ExpandDefinitionsCommand::ExpandDefinitionsCommand(Expr term
) throw() :
898 Expr
ExpandDefinitionsCommand::getTerm() const throw() {
902 void ExpandDefinitionsCommand::invoke(SmtEngine
* smtEngine
) throw() {
903 d_result
= smtEngine
->expandDefinitions(d_term
);
904 d_commandStatus
= CommandSuccess::instance();
907 Expr
ExpandDefinitionsCommand::getResult() const throw() {
911 void ExpandDefinitionsCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
913 this->Command::printResult(out
, verbosity
);
915 out
<< d_result
<< endl
;
919 Command
* ExpandDefinitionsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
920 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
.exportTo(exprManager
, variableMap
));
921 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
925 Command
* ExpandDefinitionsCommand::clone() const {
926 ExpandDefinitionsCommand
* c
= new ExpandDefinitionsCommand(d_term
);
927 c
->d_result
= d_result
;
931 std::string
ExpandDefinitionsCommand::getCommandName() const throw() {
932 return "expand-definitions";
935 /* class GetValueCommand */
937 GetValueCommand::GetValueCommand(Expr term
) throw() :
939 d_terms
.push_back(term
);
942 GetValueCommand::GetValueCommand(const std::vector
<Expr
>& terms
) throw() :
944 PrettyCheckArgument(terms
.size() >= 1, terms
,
945 "cannot get-value of an empty set of terms");
948 const std::vector
<Expr
>& GetValueCommand::getTerms() const throw() {
952 void GetValueCommand::invoke(SmtEngine
* smtEngine
) throw() {
955 ExprManager
* em
= smtEngine
->getExprManager();
956 NodeManager
* nm
= NodeManager::fromExprManager(em
);
957 for(std::vector
<Expr
>::const_iterator i
= d_terms
.begin(); i
!= d_terms
.end(); ++i
) {
958 Assert(nm
== NodeManager::fromExprManager((*i
).getExprManager()));
959 smt::SmtScope
scope(smtEngine
);
960 Node request
= Node::fromExpr(options::expandDefinitions() ? smtEngine
->expandDefinitions(*i
) : *i
);
961 Node value
= Node::fromExpr(smtEngine
->getValue(*i
));
962 if(value
.getType().isInteger() && request
.getType() == nm
->realType()) {
963 // Need to wrap in special marker so that output printers know this
964 // is an integer-looking constant that really should be output as
965 // a rational. Necessary for SMT-LIB standards compliance, but ugly.
966 value
= nm
->mkNode(kind::APPLY_TYPE_ASCRIPTION
,
967 nm
->mkConst(AscriptionType(em
->realType())), value
);
969 result
.push_back(nm
->mkNode(kind::SEXPR
, request
, value
).toExpr());
971 d_result
= em
->mkExpr(kind::SEXPR
, result
);
972 d_commandStatus
= CommandSuccess::instance();
973 } catch(UnsafeInterruptException
& e
) {
974 d_commandStatus
= new CommandInterrupted();
975 } catch(exception
& e
) {
976 d_commandStatus
= new CommandFailure(e
.what());
980 Expr
GetValueCommand::getResult() const throw() {
984 void GetValueCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
986 this->Command::printResult(out
, verbosity
);
988 expr::ExprDag::Scope
scope(out
, false);
989 out
<< d_result
<< endl
;
993 Command
* GetValueCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
994 vector
<Expr
> exportedTerms
;
995 for(std::vector
<Expr
>::const_iterator i
= d_terms
.begin(); i
!= d_terms
.end(); ++i
) {
996 exportedTerms
.push_back((*i
).exportTo(exprManager
, variableMap
));
998 GetValueCommand
* c
= new GetValueCommand(exportedTerms
);
999 c
->d_result
= d_result
.exportTo(exprManager
, variableMap
);
1003 Command
* GetValueCommand::clone() const {
1004 GetValueCommand
* c
= new GetValueCommand(d_terms
);
1005 c
->d_result
= d_result
;
1009 std::string
GetValueCommand::getCommandName() const throw() {
1013 /* class GetAssignmentCommand */
1015 GetAssignmentCommand::GetAssignmentCommand() throw() {
1018 void GetAssignmentCommand::invoke(SmtEngine
* smtEngine
) throw() {
1020 d_result
= smtEngine
->getAssignment();
1021 d_commandStatus
= CommandSuccess::instance();
1022 } catch(UnsafeInterruptException
& e
) {
1023 d_commandStatus
= new CommandInterrupted();
1024 } catch(exception
& e
) {
1025 d_commandStatus
= new CommandFailure(e
.what());
1029 SExpr
GetAssignmentCommand::getResult() const throw() {
1033 void GetAssignmentCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1035 this->Command::printResult(out
, verbosity
);
1037 out
<< d_result
<< endl
;
1041 Command
* GetAssignmentCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1042 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1043 c
->d_result
= d_result
;
1047 Command
* GetAssignmentCommand::clone() const {
1048 GetAssignmentCommand
* c
= new GetAssignmentCommand();
1049 c
->d_result
= d_result
;
1053 std::string
GetAssignmentCommand::getCommandName() const throw() {
1054 return "get-assignment";
1057 /* class GetModelCommand */
1059 GetModelCommand::GetModelCommand() throw() {
1062 void GetModelCommand::invoke(SmtEngine
* smtEngine
) throw() {
1064 d_result
= smtEngine
->getModel();
1065 d_smtEngine
= smtEngine
;
1066 d_commandStatus
= CommandSuccess::instance();
1067 } catch(UnsafeInterruptException
& e
) {
1068 d_commandStatus
= new CommandInterrupted();
1069 } catch(exception
& e
) {
1070 d_commandStatus
= new CommandFailure(e
.what());
1074 /* Model is private to the library -- for now
1075 Model* GetModelCommand::getResult() const throw() {
1080 void GetModelCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1082 this->Command::printResult(out
, verbosity
);
1088 Command
* GetModelCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1089 GetModelCommand
* c
= new GetModelCommand();
1090 c
->d_result
= d_result
;
1091 c
->d_smtEngine
= d_smtEngine
;
1095 Command
* GetModelCommand::clone() const {
1096 GetModelCommand
* c
= new GetModelCommand();
1097 c
->d_result
= d_result
;
1098 c
->d_smtEngine
= d_smtEngine
;
1102 std::string
GetModelCommand::getCommandName() const throw() {
1106 /* class GetProofCommand */
1108 GetProofCommand::GetProofCommand() throw() {
1111 void GetProofCommand::invoke(SmtEngine
* smtEngine
) throw() {
1113 d_smtEngine
= smtEngine
;
1114 d_result
= smtEngine
->getProof();
1115 d_commandStatus
= CommandSuccess::instance();
1116 } catch(UnsafeInterruptException
& e
) {
1117 d_commandStatus
= new CommandInterrupted();
1118 } catch(exception
& e
) {
1119 d_commandStatus
= new CommandFailure(e
.what());
1123 Proof
* GetProofCommand::getResult() const throw() {
1127 void GetProofCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1129 this->Command::printResult(out
, verbosity
);
1131 smt::SmtScope
scope(d_smtEngine
);
1132 d_result
->toStream(out
);
1136 Command
* GetProofCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1137 GetProofCommand
* c
= new GetProofCommand();
1138 c
->d_result
= d_result
;
1139 c
->d_smtEngine
= d_smtEngine
;
1143 Command
* GetProofCommand::clone() const {
1144 GetProofCommand
* c
= new GetProofCommand();
1145 c
->d_result
= d_result
;
1146 c
->d_smtEngine
= d_smtEngine
;
1150 std::string
GetProofCommand::getCommandName() const throw() {
1154 /* class GetInstantiationsCommand */
1156 GetInstantiationsCommand::GetInstantiationsCommand() throw() {
1159 void GetInstantiationsCommand::invoke(SmtEngine
* smtEngine
) throw() {
1161 d_smtEngine
= smtEngine
;
1162 d_commandStatus
= CommandSuccess::instance();
1163 } catch(exception
& e
) {
1164 d_commandStatus
= new CommandFailure(e
.what());
1168 //Instantiations* GetInstantiationsCommand::getResult() const throw() {
1172 void GetInstantiationsCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1174 this->Command::printResult(out
, verbosity
);
1176 d_smtEngine
->printInstantiations(out
);
1180 Command
* GetInstantiationsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1181 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1182 //c->d_result = d_result;
1183 c
->d_smtEngine
= d_smtEngine
;
1187 Command
* GetInstantiationsCommand::clone() const {
1188 GetInstantiationsCommand
* c
= new GetInstantiationsCommand();
1189 //c->d_result = d_result;
1190 c
->d_smtEngine
= d_smtEngine
;
1194 std::string
GetInstantiationsCommand::getCommandName() const throw() {
1195 return "get-instantiations";
1198 /* class GetSynthSolutionCommand */
1200 GetSynthSolutionCommand::GetSynthSolutionCommand() throw() {
1203 void GetSynthSolutionCommand::invoke(SmtEngine
* smtEngine
) throw() {
1205 d_smtEngine
= smtEngine
;
1206 d_commandStatus
= CommandSuccess::instance();
1207 } catch(exception
& e
) {
1208 d_commandStatus
= new CommandFailure(e
.what());
1212 void GetSynthSolutionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1214 this->Command::printResult(out
, verbosity
);
1216 d_smtEngine
->printSynthSolution(out
);
1220 Command
* GetSynthSolutionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1221 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1222 c
->d_smtEngine
= d_smtEngine
;
1226 Command
* GetSynthSolutionCommand::clone() const {
1227 GetSynthSolutionCommand
* c
= new GetSynthSolutionCommand();
1228 c
->d_smtEngine
= d_smtEngine
;
1232 std::string
GetSynthSolutionCommand::getCommandName() const throw() {
1233 return "get-instantiations";
1236 /* class GetQuantifierEliminationCommand */
1238 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand() throw() :
1242 GetQuantifierEliminationCommand::GetQuantifierEliminationCommand(const Expr
& expr
, bool doFull
) throw() :
1243 d_expr(expr
), d_doFull(doFull
) {
1246 Expr
GetQuantifierEliminationCommand::getExpr() const throw() {
1249 bool GetQuantifierEliminationCommand::getDoFull() const throw() {
1253 void GetQuantifierEliminationCommand::invoke(SmtEngine
* smtEngine
) throw() {
1255 d_result
= smtEngine
->doQuantifierElimination(d_expr
, d_doFull
);
1256 d_commandStatus
= CommandSuccess::instance();
1257 } catch(exception
& e
) {
1258 d_commandStatus
= new CommandFailure(e
.what());
1262 Expr
GetQuantifierEliminationCommand::getResult() const throw() {
1266 void GetQuantifierEliminationCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1268 this->Command::printResult(out
, verbosity
);
1270 out
<< d_result
<< endl
;
1274 Command
* GetQuantifierEliminationCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1275 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(d_expr
.exportTo(exprManager
, variableMap
), d_doFull
);
1276 c
->d_result
= d_result
;
1280 Command
* GetQuantifierEliminationCommand::clone() const {
1281 GetQuantifierEliminationCommand
* c
= new GetQuantifierEliminationCommand(d_expr
, d_doFull
);
1282 c
->d_result
= d_result
;
1286 std::string
GetQuantifierEliminationCommand::getCommandName() const throw() {
1287 return d_doFull
? "get-qe" : "get-qe-disjunct";
1290 /* class GetUnsatCoreCommand */
1292 GetUnsatCoreCommand::GetUnsatCoreCommand() throw() {
1295 GetUnsatCoreCommand::GetUnsatCoreCommand(const std::map
<Expr
, std::string
>& names
) throw() : d_names(names
) {
1298 void GetUnsatCoreCommand::invoke(SmtEngine
* smtEngine
) throw() {
1300 d_result
= smtEngine
->getUnsatCore();
1301 d_commandStatus
= CommandSuccess::instance();
1302 } catch(exception
& e
) {
1303 d_commandStatus
= new CommandFailure(e
.what());
1307 void GetUnsatCoreCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1309 this->Command::printResult(out
, verbosity
);
1311 d_result
.toStream(out
, d_names
);
1315 const UnsatCore
& GetUnsatCoreCommand::getUnsatCore() const throw() {
1316 // of course, this will be empty if the command hasn't been invoked yet
1320 Command
* GetUnsatCoreCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1321 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand(d_names
);
1322 c
->d_result
= d_result
;
1326 Command
* GetUnsatCoreCommand::clone() const {
1327 GetUnsatCoreCommand
* c
= new GetUnsatCoreCommand(d_names
);
1328 c
->d_result
= d_result
;
1332 std::string
GetUnsatCoreCommand::getCommandName() const throw() {
1333 return "get-unsat-core";
1336 /* class GetAssertionsCommand */
1338 GetAssertionsCommand::GetAssertionsCommand() throw() {
1341 void GetAssertionsCommand::invoke(SmtEngine
* smtEngine
) throw() {
1344 const vector
<Expr
> v
= smtEngine
->getAssertions();
1346 copy( v
.begin(), v
.end(), ostream_iterator
<Expr
>(ss
, "\n") );
1348 d_result
= ss
.str();
1349 d_commandStatus
= CommandSuccess::instance();
1350 } catch(exception
& e
) {
1351 d_commandStatus
= new CommandFailure(e
.what());
1355 std::string
GetAssertionsCommand::getResult() const throw() {
1359 void GetAssertionsCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1361 this->Command::printResult(out
, verbosity
);
1367 Command
* GetAssertionsCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1368 GetAssertionsCommand
* c
= new GetAssertionsCommand();
1369 c
->d_result
= d_result
;
1373 Command
* GetAssertionsCommand::clone() const {
1374 GetAssertionsCommand
* c
= new GetAssertionsCommand();
1375 c
->d_result
= d_result
;
1379 std::string
GetAssertionsCommand::getCommandName() const throw() {
1380 return "get-assertions";
1383 /* class SetBenchmarkStatusCommand */
1385 SetBenchmarkStatusCommand::SetBenchmarkStatusCommand(BenchmarkStatus status
) throw() :
1389 BenchmarkStatus
SetBenchmarkStatusCommand::getStatus() const throw() {
1393 void SetBenchmarkStatusCommand::invoke(SmtEngine
* smtEngine
) throw() {
1397 SExpr status
= SExpr(ss
.str());
1398 smtEngine
->setInfo("status", status
);
1399 d_commandStatus
= CommandSuccess::instance();
1400 } catch(exception
& e
) {
1401 d_commandStatus
= new CommandFailure(e
.what());
1405 Command
* SetBenchmarkStatusCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1406 return new SetBenchmarkStatusCommand(d_status
);
1409 Command
* SetBenchmarkStatusCommand::clone() const {
1410 return new SetBenchmarkStatusCommand(d_status
);
1413 std::string
SetBenchmarkStatusCommand::getCommandName() const throw() {
1417 /* class SetBenchmarkLogicCommand */
1419 SetBenchmarkLogicCommand::SetBenchmarkLogicCommand(std::string logic
) throw() :
1423 std::string
SetBenchmarkLogicCommand::getLogic() const throw() {
1427 void SetBenchmarkLogicCommand::invoke(SmtEngine
* smtEngine
) throw() {
1429 smtEngine
->setLogic(d_logic
);
1430 d_commandStatus
= CommandSuccess::instance();
1431 } catch(exception
& e
) {
1432 d_commandStatus
= new CommandFailure(e
.what());
1436 Command
* SetBenchmarkLogicCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1437 return new SetBenchmarkLogicCommand(d_logic
);
1440 Command
* SetBenchmarkLogicCommand::clone() const {
1441 return new SetBenchmarkLogicCommand(d_logic
);
1444 std::string
SetBenchmarkLogicCommand::getCommandName() const throw() {
1448 /* class SetInfoCommand */
1450 SetInfoCommand::SetInfoCommand(std::string flag
, const SExpr
& sexpr
) throw() :
1455 std::string
SetInfoCommand::getFlag() const throw() {
1459 SExpr
SetInfoCommand::getSExpr() const throw() {
1463 void SetInfoCommand::invoke(SmtEngine
* smtEngine
) throw() {
1465 smtEngine
->setInfo(d_flag
, d_sexpr
);
1466 d_commandStatus
= CommandSuccess::instance();
1467 } catch(UnrecognizedOptionException
&) {
1468 // As per SMT-LIB spec, silently accept unknown set-info keys
1469 d_commandStatus
= CommandSuccess::instance();
1470 } catch(exception
& e
) {
1471 d_commandStatus
= new CommandFailure(e
.what());
1475 Command
* SetInfoCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1476 return new SetInfoCommand(d_flag
, d_sexpr
);
1479 Command
* SetInfoCommand::clone() const {
1480 return new SetInfoCommand(d_flag
, d_sexpr
);
1483 std::string
SetInfoCommand::getCommandName() const throw() {
1487 /* class GetInfoCommand */
1489 GetInfoCommand::GetInfoCommand(std::string flag
) throw() :
1493 std::string
GetInfoCommand::getFlag() const throw() {
1497 void GetInfoCommand::invoke(SmtEngine
* smtEngine
) throw() {
1500 v
.push_back(SExpr(SExpr::Keyword(string(":") + d_flag
)));
1501 v
.push_back(smtEngine
->getInfo(d_flag
));
1503 if(d_flag
== "all-options" || d_flag
== "all-statistics") {
1504 ss
<< PrettySExprs(true);
1507 d_result
= ss
.str();
1508 d_commandStatus
= CommandSuccess::instance();
1509 } catch(UnrecognizedOptionException
&) {
1510 d_commandStatus
= new CommandUnsupported();
1511 } catch(exception
& e
) {
1512 d_commandStatus
= new CommandFailure(e
.what());
1516 std::string
GetInfoCommand::getResult() const throw() {
1520 void GetInfoCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1522 this->Command::printResult(out
, verbosity
);
1523 } else if(d_result
!= "") {
1524 out
<< d_result
<< endl
;
1528 Command
* GetInfoCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1529 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
1530 c
->d_result
= d_result
;
1534 Command
* GetInfoCommand::clone() const {
1535 GetInfoCommand
* c
= new GetInfoCommand(d_flag
);
1536 c
->d_result
= d_result
;
1540 std::string
GetInfoCommand::getCommandName() const throw() {
1544 /* class SetOptionCommand */
1546 SetOptionCommand::SetOptionCommand(std::string flag
, const SExpr
& sexpr
) throw() :
1551 std::string
SetOptionCommand::getFlag() const throw() {
1555 SExpr
SetOptionCommand::getSExpr() const throw() {
1559 void SetOptionCommand::invoke(SmtEngine
* smtEngine
) throw() {
1561 smtEngine
->setOption(d_flag
, d_sexpr
);
1562 d_commandStatus
= CommandSuccess::instance();
1563 } catch(UnrecognizedOptionException
&) {
1564 d_commandStatus
= new CommandUnsupported();
1565 } catch(exception
& e
) {
1566 d_commandStatus
= new CommandFailure(e
.what());
1570 Command
* SetOptionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1571 return new SetOptionCommand(d_flag
, d_sexpr
);
1574 Command
* SetOptionCommand::clone() const {
1575 return new SetOptionCommand(d_flag
, d_sexpr
);
1578 std::string
SetOptionCommand::getCommandName() const throw() {
1579 return "set-option";
1582 /* class GetOptionCommand */
1584 GetOptionCommand::GetOptionCommand(std::string flag
) throw() :
1588 std::string
GetOptionCommand::getFlag() const throw() {
1592 void GetOptionCommand::invoke(SmtEngine
* smtEngine
) throw() {
1594 SExpr res
= smtEngine
->getOption(d_flag
);
1595 d_result
= res
.toString();
1596 d_commandStatus
= CommandSuccess::instance();
1597 } catch(UnrecognizedOptionException
&) {
1598 d_commandStatus
= new CommandUnsupported();
1599 } catch(exception
& e
) {
1600 d_commandStatus
= new CommandFailure(e
.what());
1604 std::string
GetOptionCommand::getResult() const throw() {
1608 void GetOptionCommand::printResult(std::ostream
& out
, uint32_t verbosity
) const throw() {
1610 this->Command::printResult(out
, verbosity
);
1611 } else if(d_result
!= "") {
1612 out
<< d_result
<< endl
;
1616 Command
* GetOptionCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1617 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
1618 c
->d_result
= d_result
;
1622 Command
* GetOptionCommand::clone() const {
1623 GetOptionCommand
* c
= new GetOptionCommand(d_flag
);
1624 c
->d_result
= d_result
;
1628 std::string
GetOptionCommand::getCommandName() const throw() {
1629 return "get-option";
1632 /* class DatatypeDeclarationCommand */
1634 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const DatatypeType
& datatype
) throw() :
1636 d_datatypes
.push_back(datatype
);
1639 DatatypeDeclarationCommand::DatatypeDeclarationCommand(const std::vector
<DatatypeType
>& datatypes
) throw() :
1640 d_datatypes(datatypes
) {
1643 const std::vector
<DatatypeType
>&
1644 DatatypeDeclarationCommand::getDatatypes() const throw() {
1648 void DatatypeDeclarationCommand::invoke(SmtEngine
* smtEngine
) throw() {
1649 d_commandStatus
= CommandSuccess::instance();
1652 Command
* DatatypeDeclarationCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1653 throw ExportUnsupportedException
1654 ("export of DatatypeDeclarationCommand unsupported");
1657 Command
* DatatypeDeclarationCommand::clone() const {
1658 return new DatatypeDeclarationCommand(d_datatypes
);
1661 std::string
DatatypeDeclarationCommand::getCommandName() const throw() {
1662 return "declare-datatypes";
1665 /* class RewriteRuleCommand */
1667 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
1668 const std::vector
<Expr
>& guards
,
1669 Expr head
, Expr body
,
1670 const Triggers
& triggers
) throw() :
1671 d_vars(vars
), d_guards(guards
), d_head(head
), d_body(body
), d_triggers(triggers
) {
1674 RewriteRuleCommand::RewriteRuleCommand(const std::vector
<Expr
>& vars
,
1675 Expr head
, Expr body
) throw() :
1676 d_vars(vars
), d_head(head
), d_body(body
) {
1679 const std::vector
<Expr
>& RewriteRuleCommand::getVars() const throw() {
1683 const std::vector
<Expr
>& RewriteRuleCommand::getGuards() const throw() {
1687 Expr
RewriteRuleCommand::getHead() const throw() {
1691 Expr
RewriteRuleCommand::getBody() const throw() {
1695 const RewriteRuleCommand::Triggers
& RewriteRuleCommand::getTriggers() const throw() {
1699 void RewriteRuleCommand::invoke(SmtEngine
* smtEngine
) throw() {
1701 ExprManager
* em
= smtEngine
->getExprManager();
1702 /** build vars list */
1703 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
1704 /** build guards list */
1706 if(d_guards
.size() == 0) guards
= em
->mkConst
<bool>(true);
1707 else if(d_guards
.size() == 1) guards
= d_guards
[0];
1708 else guards
= em
->mkExpr(kind::AND
,d_guards
);
1709 /** build expression */
1711 if( d_triggers
.empty() ){
1712 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,d_head
,d_body
);
1714 /** build triggers list */
1715 std::vector
<Expr
> vtriggers
;
1716 vtriggers
.reserve(d_triggers
.size());
1717 for(Triggers::const_iterator i
= d_triggers
.begin(),
1718 end
= d_triggers
.end(); i
!= end
; ++i
){
1719 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
,*i
));
1721 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
,vtriggers
);
1722 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,d_head
,d_body
,triggers
);
1724 smtEngine
->assertFormula(expr
);
1725 d_commandStatus
= CommandSuccess::instance();
1726 } catch(exception
& e
) {
1727 d_commandStatus
= new CommandFailure(e
.what());
1731 Command
* RewriteRuleCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1732 /** Convert variables */
1733 VExpr vars
; vars
.reserve(d_vars
.size());
1734 for(VExpr::iterator i
= d_vars
.begin(), end
= d_vars
.end();
1736 vars
.push_back(i
->exportTo(exprManager
, variableMap
));
1738 /** Convert guards */
1739 VExpr guards
; guards
.reserve(d_guards
.size());
1740 for(VExpr::iterator i
= d_guards
.begin(), end
= d_guards
.end();
1742 guards
.push_back(i
->exportTo(exprManager
, variableMap
));
1744 /** Convert triggers */
1745 Triggers triggers
; triggers
.resize(d_triggers
.size());
1746 for(size_t i
= 0, end
= d_triggers
.size();
1748 triggers
[i
].reserve(d_triggers
[i
].size());
1749 for(VExpr::iterator j
= d_triggers
[i
].begin(), jend
= d_triggers
[i
].end();
1751 triggers
[i
].push_back(j
->exportTo(exprManager
, variableMap
));
1754 /** Convert head and body */
1755 Expr head
= d_head
.exportTo(exprManager
, variableMap
);
1756 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
1757 /** Create the converted rules */
1758 return new RewriteRuleCommand(vars
, guards
, head
, body
, triggers
);
1761 Command
* RewriteRuleCommand::clone() const {
1762 return new RewriteRuleCommand(d_vars
, d_guards
, d_head
, d_body
, d_triggers
);
1765 std::string
RewriteRuleCommand::getCommandName() const throw() {
1766 return "rewrite-rule";
1769 /* class PropagateRuleCommand */
1771 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
1772 const std::vector
<Expr
>& guards
,
1773 const std::vector
<Expr
>& heads
,
1775 const Triggers
& triggers
,
1776 bool deduction
) throw() :
1777 d_vars(vars
), d_guards(guards
), d_heads(heads
), d_body(body
), d_triggers(triggers
), d_deduction(deduction
) {
1780 PropagateRuleCommand::PropagateRuleCommand(const std::vector
<Expr
>& vars
,
1781 const std::vector
<Expr
>& heads
,
1783 bool deduction
) throw() :
1784 d_vars(vars
), d_heads(heads
), d_body(body
), d_deduction(deduction
) {
1787 const std::vector
<Expr
>& PropagateRuleCommand::getVars() const throw() {
1791 const std::vector
<Expr
>& PropagateRuleCommand::getGuards() const throw() {
1795 const std::vector
<Expr
>& PropagateRuleCommand::getHeads() const throw() {
1799 Expr
PropagateRuleCommand::getBody() const throw() {
1803 const PropagateRuleCommand::Triggers
& PropagateRuleCommand::getTriggers() const throw() {
1807 bool PropagateRuleCommand::isDeduction() const throw() {
1811 void PropagateRuleCommand::invoke(SmtEngine
* smtEngine
) throw() {
1813 ExprManager
* em
= smtEngine
->getExprManager();
1814 /** build vars list */
1815 Expr vars
= em
->mkExpr(kind::BOUND_VAR_LIST
, d_vars
);
1816 /** build guards list */
1818 if(d_guards
.size() == 0) guards
= em
->mkConst
<bool>(true);
1819 else if(d_guards
.size() == 1) guards
= d_guards
[0];
1820 else guards
= em
->mkExpr(kind::AND
,d_guards
);
1821 /** build heads list */
1823 if(d_heads
.size() == 1) heads
= d_heads
[0];
1824 else heads
= em
->mkExpr(kind::AND
,d_heads
);
1825 /** build expression */
1827 if( d_triggers
.empty() ){
1828 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,heads
,d_body
);
1830 /** build triggers list */
1831 std::vector
<Expr
> vtriggers
;
1832 vtriggers
.reserve(d_triggers
.size());
1833 for(Triggers::const_iterator i
= d_triggers
.begin(),
1834 end
= d_triggers
.end(); i
!= end
; ++i
){
1835 vtriggers
.push_back(em
->mkExpr(kind::INST_PATTERN
,*i
));
1837 Expr triggers
= em
->mkExpr(kind::INST_PATTERN_LIST
,vtriggers
);
1838 expr
= em
->mkExpr(kind::RR_REWRITE
,vars
,guards
,heads
,d_body
,triggers
);
1840 smtEngine
->assertFormula(expr
);
1841 d_commandStatus
= CommandSuccess::instance();
1842 } catch(exception
& e
) {
1843 d_commandStatus
= new CommandFailure(e
.what());
1847 Command
* PropagateRuleCommand::exportTo(ExprManager
* exprManager
, ExprManagerMapCollection
& variableMap
) {
1848 /** Convert variables */
1849 VExpr vars
; vars
.reserve(d_vars
.size());
1850 for(VExpr::iterator i
= d_vars
.begin(), end
= d_vars
.end();
1852 vars
.push_back(i
->exportTo(exprManager
, variableMap
));
1854 /** Convert guards */
1855 VExpr guards
; guards
.reserve(d_guards
.size());
1856 for(VExpr::iterator i
= d_guards
.begin(), end
= d_guards
.end();
1858 guards
.push_back(i
->exportTo(exprManager
, variableMap
));
1860 /** Convert heads */
1861 VExpr heads
; heads
.reserve(d_heads
.size());
1862 for(VExpr::iterator i
= d_heads
.begin(), end
= d_heads
.end();
1864 heads
.push_back(i
->exportTo(exprManager
, variableMap
));
1866 /** Convert triggers */
1867 Triggers triggers
; triggers
.resize(d_triggers
.size());
1868 for(size_t i
= 0, end
= d_triggers
.size();
1870 triggers
[i
].reserve(d_triggers
[i
].size());
1871 for(VExpr::iterator j
= d_triggers
[i
].begin(), jend
= d_triggers
[i
].end();
1873 triggers
[i
].push_back(j
->exportTo(exprManager
, variableMap
));
1876 /** Convert head and body */
1877 Expr body
= d_body
.exportTo(exprManager
, variableMap
);
1878 /** Create the converted rules */
1879 return new PropagateRuleCommand(vars
, guards
, heads
, body
, triggers
);
1882 Command
* PropagateRuleCommand::clone() const {
1883 return new PropagateRuleCommand(d_vars
, d_guards
, d_heads
, d_body
, d_triggers
);
1886 std::string
PropagateRuleCommand::getCommandName() const throw() {
1887 return "propagate-rule";
1890 /* output stream insertion operator for benchmark statuses */
1891 std::ostream
& operator<<(std::ostream
& out
,
1892 BenchmarkStatus status
) throw() {
1895 case SMT_SATISFIABLE
:
1896 return out
<< "sat";
1898 case SMT_UNSATISFIABLE
:
1899 return out
<< "unsat";
1902 return out
<< "unknown";
1905 return out
<< "BenchmarkStatus::[UNKNOWNSTATUS!]";
1909 }/* CVC4 namespace */