From 2ba8bb701ce289ba60afec01b653b0930cc59298 Mon Sep 17 00:00:00 2001 From: Tim King Date: Thu, 28 Jan 2016 12:35:45 -0800 Subject: [PATCH] Adding listeners to Options. - Options -- Added the new option attribute :notify. One can get a notify() call on the Listener after a the option's value is updated. This is the new preferred way to achieve dynamic dispatch for options. -- Removed SmtOptionsHandler and pushed its functionality into OptionsHandler and Listeners. -- Added functions to Options for registering listeners of the notify calls. -- Changed a number of options to use the new listener infrastructure. -- Fixed a number of warnings in options. -- Added the ArgumentExtender class to better capture how arguments are inserted while parsing options and ease memory management. Previously this was the "preemptGetopt" procedure. -- Moved options/options_handler_interface.{cpp,h} to options/options_handler.{cpp,h}. - Theories -- Reimplemented alternative theories to use a datastructure stored on TheoryEngine instead of on Options. - Ostream Handling: -- Added new functionality that generalized how ostreams are opened, options/open_stream.h. -- Simplified the memory management for different ostreams, smt/managed_ostreams.h. -- Had the SmtEnginePrivate manage the memory for the ostreams set by options. -- Simplified how the setting of ostreams are updated, smt/update_ostream.h. - Configuration and Tags: -- Configuration can now be used during predicates and handlers for options. -- Moved configuration.{cpp,h,i} and configuration_private.h from util/ into base/. -- Moved {Debug,Trace}_tags.* from being generated in options/ into base/. - cvc4_private.h -- Upgraded #warning's in cvc4_private.h and cvc4_private_library.h to #error's. -- Added public first-order (non-templatized) member functions for options get and set the value of options outside of libcvc4. Fixed all of the use locations. -- Made lib/lib/clock_gettime.h a cvc4_private_library.h header. - Antlr -- Fixed antlr and cvc4 macro definition conflicts that caused warnings. - SmtGlobals -- Refactored replayStream and replayLog out of SmtGlobals. -- Renamed SmtGlobals to LemmaChannels and moved the implementation into smt_util/lemma_channels.{h,cpp}. --- contrib/alttheoryskel/theory_DIR.cpp | 5 +- contrib/alttheoryskel/theory_DIR.h | 3 +- contrib/theoryskel/theory_DIR.cpp | 5 +- contrib/theoryskel/theory_DIR.h | 3 +- examples/hashsmt/word.cpp | 9 +- examples/nra-translate/normalize.cpp | 4 +- examples/nra-translate/smt2info.cpp | 7 +- examples/nra-translate/smt2todreal.cpp | 13 +- examples/nra-translate/smt2toisat.cpp | 3 +- examples/nra-translate/smt2tomathematica.cpp | 13 +- examples/nra-translate/smt2toqepcad.cpp | 101 +-- examples/nra-translate/smt2toredlog.cpp | 24 +- examples/sets-translate/sets_translate.cpp | 3 +- examples/translator.cpp | 4 +- src/Makefile.am | 31 +- src/base/Makefile.am | 44 + src/{util => base}/configuration.cpp | 8 +- src/{util => base}/configuration.h | 0 src/{util => base}/configuration.i | 4 +- src/{util => base}/configuration_private.h | 3 +- src/base/exception.cpp | 2 +- src/base/exception.h | 6 +- src/base/listener.cpp | 39 +- src/base/listener.h | 112 ++- src/{options => base}/mktagheaders | 0 src/{options => base}/mktags | 0 src/base/output.h | 24 +- src/compat/cvc3_compat.cpp | 25 +- src/cvc4.i | 2 +- src/expr/Makefile.am | 3 +- src/expr/expr_template.h | 4 +- src/expr/node.h | 2 +- src/expr/node_manager.cpp | 22 +- src/expr/node_manager.h | 9 + src/expr/node_manager_listeners.cpp | 44 + src/expr/node_manager_listeners.h | 63 ++ src/include/cvc4.h | 2 +- src/include/cvc4_private.h | 5 +- src/include/cvc4_private_library.h | 2 +- src/include/cvc4parser_private.h | 6 +- src/lib/clock_gettime.c | 2 +- src/lib/clock_gettime.h | 2 +- src/main/command_executor.cpp | 116 ++- src/main/command_executor.h | 12 +- src/main/command_executor_portfolio.cpp | 158 ++-- src/main/command_executor_portfolio.h | 4 +- src/main/driver_unified.cpp | 251 +++--- src/main/interactive_shell.cpp | 44 +- src/main/main.cpp | 21 +- src/main/portfolio_util.cpp | 81 +- src/main/portfolio_util.h | 22 +- src/main/util.cpp | 26 +- src/options/Makefile.am | 83 +- src/options/argument_extender.cpp | 74 ++ src/options/argument_extender.h | 79 ++ src/options/arith_options | 11 +- src/options/base_handlers.h | 4 +- src/options/base_options | 126 ++- src/options/booleans_options | 2 +- src/options/bv_options | 16 +- src/options/decision_options | 4 +- src/options/expr_options | 8 +- src/options/logic_info_forward.h | 26 - src/options/main_options | 18 +- src/options/mkoptions | 72 +- src/options/open_ostream.cpp | 102 +++ src/options/open_ostream.h | 63 ++ src/options/options.h | 383 +++++++- ...te.cpp => options_get_option_template.cpp} | 11 +- .../options_handler.cpp} | 820 ++++++------------ src/options/options_handler.h | 224 +++++ src/options/options_handler_interface.cpp | 358 -------- src/options/options_handler_interface.h | 272 ------ src/options/options_handler_interface.i | 5 - src/options/options_public_functions.cpp | 322 +++++++ ...te.cpp => options_set_option_template.cpp} | 17 +- src/options/options_template.cpp | 329 +++++-- src/options/parser_options | 27 +- src/options/printer_modes.h | 8 +- src/options/printer_options | 4 +- src/options/prop_options | 8 +- src/options/quantifiers_options | 26 +- src/options/smt_options | 51 +- src/options/strings_options | 4 +- src/options/theory_options | 7 +- src/options/uf_options | 4 +- src/options/ufss_mode.h | 3 +- src/parser/Makefile.am | 21 +- src/parser/antlr_input.cpp | 8 +- src/parser/antlr_input.h | 23 +- src/parser/antlr_input_imports.cpp | 6 + src/parser/antlr_line_buffered_input.cpp | 16 +- src/parser/antlr_line_buffered_input.h | 7 +- src/parser/antlr_undefines.h | 69 ++ src/parser/cvc/Cvc.g | 8 + src/parser/cvc/cvc_input.cpp | 6 +- src/parser/input.cpp | 10 +- src/parser/input.h | 4 +- src/parser/parser.cpp | 10 +- src/parser/parser_builder.cpp | 25 +- src/parser/smt1/Smt1.g | 9 + src/parser/smt1/smt1_input.cpp | 4 + src/parser/smt2/Smt2.g | 9 + src/parser/smt2/smt2.cpp | 5 + src/parser/smt2/smt2.h | 15 +- src/parser/smt2/smt2_input.cpp | 5 + src/parser/smt2/smt2_input.h | 2 +- src/parser/smt2/sygus_input.cpp | 5 + src/parser/tptp/Tptp.g | 9 + src/parser/tptp/tptp.cpp | 5 +- src/parser/tptp/tptp.h | 4 +- src/parser/tptp/tptp_input.cpp | 4 + src/printer/printer.h | 4 +- src/proof/proof.h | 4 +- src/proof/proof_manager.cpp | 9 +- src/proof/proof_manager.h | 10 +- src/proof/theory_proof.cpp | 5 +- src/proof/theory_proof.h | 86 +- src/prop/bvminisat/bvminisat.h | 2 +- src/prop/cnf_stream.cpp | 21 +- src/prop/cnf_stream.h | 10 +- src/prop/prop_engine.cpp | 24 +- src/prop/prop_engine.h | 12 +- src/prop/theory_proxy.cpp | 28 +- src/prop/theory_proxy.h | 25 +- src/smt/managed_ostreams.cpp | 192 ++++ src/smt/managed_ostreams.h | 181 ++++ src/smt/smt_engine.cpp | 409 +++++++-- src/smt/smt_engine.h | 29 +- src/smt/smt_engine_check_proof.cpp | 2 +- src/smt/smt_engine_scope.h | 2 +- src/smt/smt_globals.cpp | 111 --- src/smt/smt_globals.h | 106 --- src/smt/smt_options_handler.h | 198 ----- src/smt/update_ostream.h | 122 +++ src/smt_util/Makefile.am | 8 +- src/smt_util/boolean_simplification.h | 4 +- src/smt_util/dump.cpp | 197 +++++ src/smt_util/dump.h | 10 +- src/smt_util/lemma_channels.cpp | 54 ++ src/smt_util/lemma_channels.h | 77 ++ src/theory/arith/constraint.h | 25 +- src/theory/arith/cut_log.h | 2 +- src/theory/arith/theory_arith.cpp | 4 +- src/theory/arith/theory_arith.h | 3 +- src/theory/arrays/theory_arrays.cpp | 5 +- src/theory/arrays/theory_arrays.h | 8 +- src/theory/booleans/theory_bool.h | 5 +- src/theory/builtin/theory_builtin.h | 4 +- src/theory/bv/bitblaster_template.h | 1 - src/theory/bv/eager_bitblaster.cpp | 17 +- src/theory/bv/lazy_bitblaster.cpp | 9 +- src/theory/bv/theory_bv.cpp | 4 +- src/theory/bv/theory_bv.h | 4 +- src/theory/datatypes/theory_datatypes.cpp | 6 +- src/theory/datatypes/theory_datatypes.h | 2 +- src/theory/fp/theory_fp.cpp | 54 +- src/theory/fp/theory_fp.h | 3 +- src/theory/idl/theory_idl.cpp | 4 +- src/theory/idl/theory_idl.h | 3 +- src/theory/logic_info.cpp | 2 - src/theory/logic_info.h | 1 - src/theory/mktheorytraits | 2 +- src/theory/quantifiers/theory_quantifiers.cpp | 4 +- src/theory/quantifiers/theory_quantifiers.h | 2 +- src/theory/sets/theory_sets.cpp | 5 +- src/theory/sets/theory_sets.h | 3 +- src/theory/strings/theory_strings.cpp | 4 +- src/theory/strings/theory_strings.h | 2 +- src/theory/theory.cpp | 37 +- src/theory/theory.h | 43 +- src/theory/theory_engine.cpp | 28 +- src/theory/theory_engine.h | 20 +- src/theory/uf/theory_uf.cpp | 9 +- src/theory/uf/theory_uf.h | 2 +- src/util/Makefile.am | 4 - src/util/cache.h | 4 +- src/util/resource_manager.cpp | 18 +- src/util/resource_manager.h | 32 +- src/util/sexpr.cpp | 13 +- test/system/smt2_compliance.cpp | 10 +- test/unit/expr/attribute_black.h | 7 +- test/unit/expr/expr_public.h | 7 +- test/unit/expr/node_black.h | 8 +- test/unit/prop/cnf_stream_white.h | 2 +- test/unit/theory/theory_arith_white.h | 2 +- test/unit/theory/theory_engine_white.h | 4 +- test/unit/theory/theory_white.h | 6 +- test/unit/util/configuration_black.h | 2 +- test/unit/util/listener_black.h | 24 +- test/unit/util/output_black.h | 12 +- 191 files changed, 4667 insertions(+), 3015 deletions(-) rename src/{util => base}/configuration.cpp (97%) rename src/{util => base}/configuration.h (100%) rename src/{util => base}/configuration.i (56%) rename src/{util => base}/configuration_private.h (99%) rename src/{options => base}/mktagheaders (100%) rename src/{options => base}/mktags (100%) create mode 100644 src/expr/node_manager_listeners.cpp create mode 100644 src/expr/node_manager_listeners.h create mode 100644 src/options/argument_extender.cpp create mode 100644 src/options/argument_extender.h delete mode 100644 src/options/logic_info_forward.h create mode 100644 src/options/open_ostream.cpp create mode 100644 src/options/open_ostream.h rename src/options/{options_handler_get_option_template.cpp => options_get_option_template.cpp} (86%) rename src/{smt/smt_options_handler.cpp => options/options_handler.cpp} (59%) create mode 100644 src/options/options_handler.h delete mode 100644 src/options/options_handler_interface.cpp delete mode 100644 src/options/options_handler_interface.h delete mode 100644 src/options/options_handler_interface.i create mode 100644 src/options/options_public_functions.cpp rename src/options/{options_handler_set_option_template.cpp => options_set_option_template.cpp} (83%) create mode 100644 src/parser/antlr_undefines.h create mode 100644 src/smt/managed_ostreams.cpp create mode 100644 src/smt/managed_ostreams.h delete mode 100644 src/smt/smt_globals.cpp delete mode 100644 src/smt/smt_globals.h delete mode 100644 src/smt/smt_options_handler.h create mode 100644 src/smt/update_ostream.h create mode 100644 src/smt_util/lemma_channels.cpp create mode 100644 src/smt_util/lemma_channels.h diff --git a/contrib/alttheoryskel/theory_DIR.cpp b/contrib/alttheoryskel/theory_DIR.cpp index 3f89abbab..b1cd27c89 100644 --- a/contrib/alttheoryskel/theory_DIR.cpp +++ b/contrib/alttheoryskel/theory_DIR.cpp @@ -11,9 +11,8 @@ Theory$camel::Theory$camel(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, - SmtGlobals* globals) : - Theory(THEORY_$alt_id, c, u, out, valuation, logicInfo, globals) { + const LogicInfo& logicInfo) : + Theory(THEORY_$alt_id, c, u, out, valuation, logicInfo) { }/* Theory$camel::Theory$camel() */ void Theory$camel::check(Effort level) { diff --git a/contrib/alttheoryskel/theory_DIR.h b/contrib/alttheoryskel/theory_DIR.h index a26d76ad5..d8e652b7c 100644 --- a/contrib/alttheoryskel/theory_DIR.h +++ b/contrib/alttheoryskel/theory_DIR.h @@ -17,8 +17,7 @@ public: context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, - SmtGlobals* globals); + const LogicInfo& logicInfo); void check(Effort); diff --git a/contrib/theoryskel/theory_DIR.cpp b/contrib/theoryskel/theory_DIR.cpp index 2b48114af..06307f4e7 100644 --- a/contrib/theoryskel/theory_DIR.cpp +++ b/contrib/theoryskel/theory_DIR.cpp @@ -11,9 +11,8 @@ Theory$camel::Theory$camel(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, - SmtGlobals* globals) : - Theory(THEORY_$id, c, u, out, valuation, logicInfo, globals) { + const LogicInfo& logicInfo) : + Theory(THEORY_$id, c, u, out, valuation, logicInfo) { }/* Theory$camel::Theory$camel() */ void Theory$camel::check(Effort level) { diff --git a/contrib/theoryskel/theory_DIR.h b/contrib/theoryskel/theory_DIR.h index a26d76ad5..d8e652b7c 100644 --- a/contrib/theoryskel/theory_DIR.h +++ b/contrib/theoryskel/theory_DIR.h @@ -17,8 +17,7 @@ public: context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, - SmtGlobals* globals); + const LogicInfo& logicInfo); void check(Effort); diff --git a/examples/hashsmt/word.cpp b/examples/hashsmt/word.cpp index 7aa37e91b..a2c5907f0 100644 --- a/examples/hashsmt/word.cpp +++ b/examples/hashsmt/word.cpp @@ -28,7 +28,6 @@ #include "expr/expr.h" #include "expr/expr_iomanip.h" -#include "options/base_options.h" #include "options/language.h" #include "options/options.h" @@ -43,7 +42,7 @@ Expr Word::extendToSize(unsigned newSize) const { } else { // 0-extend to size Expr extendOp = em()->mkConst(BitVectorZeroExtend(newSize - size())); - return em()->mkExpr(extendOp, d_expr); + return em()->mkExpr(extendOp, d_expr); } } @@ -52,8 +51,8 @@ ExprManager* Word::s_manager = 0; ExprManager* Word::em() { if (s_manager == 0) { CVC4::Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); - options.set(outputLanguage, language::output::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); + options.setOutputLanguage(language::output::LANG_SMTLIB_V2); s_manager = new CVC4::ExprManager(options); } return s_manager; @@ -173,5 +172,3 @@ cvc4_uchar8::cvc4_uchar8(const Word& b) { d_expr = b.getExpr(); } } - - diff --git a/examples/nra-translate/normalize.cpp b/examples/nra-translate/normalize.cpp index 56f326216..38329fba6 100644 --- a/examples/nra-translate/normalize.cpp +++ b/examples/nra-translate/normalize.cpp @@ -25,7 +25,6 @@ #include "expr/expr.h" #include "expr/expr_iomanip.h" #include "options/language.h" -#include "options/base_options.h" #include "options/options.h" #include "options/set_language.h" #include "parser/parser.h" @@ -36,7 +35,6 @@ using namespace std; using namespace CVC4; using namespace CVC4::parser; -using namespace CVC4::options; using namespace CVC4::theory; int main(int argc, char* argv[]) @@ -47,7 +45,7 @@ int main(int argc, char* argv[]) // Create the expression manager Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); ExprManager exprManager(options); cout << language::SetLanguage(language::output::LANG_SMTLIB_V2) diff --git a/examples/nra-translate/smt2info.cpp b/examples/nra-translate/smt2info.cpp index c541a23fe..7efb5c855 100644 --- a/examples/nra-translate/smt2info.cpp +++ b/examples/nra-translate/smt2info.cpp @@ -22,7 +22,6 @@ #include #include "expr/expr.h" -#include "options/base_options.h" #include "options/options.h" #include "parser/parser.h" #include "parser/parser_builder.h" @@ -78,13 +77,13 @@ int main(int argc, char* argv[]) // Create the expression manager Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); ExprManager exprManager(options); - + // Create the parser ParserBuilder parserBuilder(&exprManager, input, options); Parser* parser = parserBuilder.build(); - + // Variables and assertions vector variables; vector info_tags; diff --git a/examples/nra-translate/smt2todreal.cpp b/examples/nra-translate/smt2todreal.cpp index 56f323812..331cf894f 100644 --- a/examples/nra-translate/smt2todreal.cpp +++ b/examples/nra-translate/smt2todreal.cpp @@ -24,7 +24,6 @@ #include "expr/expr.h" #include "expr/expr_iomanip.h" -#include "options/base_options.h" #include "options/options.h" #include "parser/parser.h" #include "parser/parser_builder.h" @@ -36,20 +35,20 @@ using namespace CVC4; using namespace CVC4::parser; using namespace CVC4::options; -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) { - // Get the filename + // Get the filename string input(argv[1]); // Create the expression manager Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); - options.set(outputLanguage, language::output::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); + options.setOutputLanguage(language::output::LANG_SMTLIB_V2); ExprManager exprManager(options); cout << expr::ExprDag(0) << expr::ExprSetDepth(-1); - + // Create the parser ParserBuilder parserBuilder(&exprManager, input, options); Parser* parser = parserBuilder.build(); @@ -82,5 +81,3 @@ int main(int argc, char* argv[]) // Get rid of the parser delete parser; } - - diff --git a/examples/nra-translate/smt2toisat.cpp b/examples/nra-translate/smt2toisat.cpp index 076d37077..bcfb4a180 100644 --- a/examples/nra-translate/smt2toisat.cpp +++ b/examples/nra-translate/smt2toisat.cpp @@ -23,7 +23,6 @@ #include #include "expr/expr.h" -#include "options/base_options.h" #include "options/options.h" #include "parser/parser.h" #include "parser/parser_builder.h" @@ -50,7 +49,7 @@ int main(int argc, char* argv[]) // Create the expression manager Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); ExprManager exprManager(options); // Create the parser diff --git a/examples/nra-translate/smt2tomathematica.cpp b/examples/nra-translate/smt2tomathematica.cpp index 0ad5bbab5..ec1da2d7c 100644 --- a/examples/nra-translate/smt2tomathematica.cpp +++ b/examples/nra-translate/smt2tomathematica.cpp @@ -23,7 +23,6 @@ #include #include "expr/expr.h" -#include "options/base_options.h" #include "options/options.h" #include "parser/parser.h" #include "parser/parser_builder.h" @@ -32,26 +31,25 @@ using namespace std; using namespace CVC4; using namespace CVC4::parser; -using namespace CVC4::options; void translate_to_mathematica( string input, const vector& info_tags, const vector& info_data, - const map& variables, + const map& variables, const vector& assertions); -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) { - // Get the filename + // Get the filename string input(argv[1]); // Create the expression manager Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); ExprManager exprManager(options); - + // Create the parser ParserBuilder parserBuilder(&exprManager, input, options); Parser* parser = parserBuilder.build(); @@ -325,4 +323,3 @@ void translate_to_mathematica( // End resolve cout << ", Reals]" << endl; } - diff --git a/examples/nra-translate/smt2toqepcad.cpp b/examples/nra-translate/smt2toqepcad.cpp index c74b0a110..ea9f2a4e6 100644 --- a/examples/nra-translate/smt2toqepcad.cpp +++ b/examples/nra-translate/smt2toqepcad.cpp @@ -23,7 +23,6 @@ #include #include "expr/expr.h" -#include "options/base_options.h" #include "options/options.h" #include "parser/parser.h" #include "parser/parser_builder.h" @@ -32,28 +31,26 @@ using namespace std; using namespace CVC4; using namespace CVC4::parser; -using namespace CVC4::options; - void translate_to_qepcad( string input, const vector& info_tags, const vector& info_data, - const map& variables, + const map& variables, const vector& assertions); -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) { std::map vars2id; - // Get the filename + // Get the filename string input(argv[1]); // Create the expression manager Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); ExprManager exprManager(options); - + // Create the parser ParserBuilder parserBuilder(&exprManager, input, options); Parser* parser = parserBuilder.build(); @@ -75,7 +72,8 @@ int main(int argc, char* argv[]) continue; } - DeclareFunctionCommand* declare = dynamic_cast(cmd); + DeclareFunctionCommand* declare = + dynamic_cast(cmd); if (declare) { string name = declare->getSymbol(); Expr var = parser->getVariable(name); @@ -84,7 +82,7 @@ int main(int argc, char* argv[]) delete cmd; continue; } - + AssertCommand* assert = dynamic_cast(cmd); if (assert) { assertions.push_back(assert->getExpr()); @@ -92,30 +90,32 @@ int main(int argc, char* argv[]) continue; } - delete cmd; + delete cmd; } // Do the translation translate_to_qepcad(input, info_tags, info_data, variables, assertions); - + // Get rid of the parser delete parser; } -void translate_to_qepcad_term(const std::map& variables, const Expr& term) { +void translate_to_qepcad_term(const std::map& variables, + const Expr& term) +{ bool first; unsigned n = term.getNumChildren(); - + if (n == 0) { if (term.getKind() == kind::CONST_RATIONAL) { cout << term.getConst(); - } else { + } else { assert(variables.find(term) != variables.end()); cout << "x" << variables.find(term)->second; } } else { - + switch (term.getKind()) { case kind::PLUS: cout << "("; @@ -140,12 +140,12 @@ void translate_to_qepcad_term(const std::map& variables, const E translate_to_qepcad_term(variables, term[i]); } cout << ")"; - break; + break; case kind::MINUS: cout << "("; translate_to_qepcad_term(variables, term[0]); cout << " - "; - translate_to_qepcad_term(variables, term[1]); + translate_to_qepcad_term(variables, term[1]); cout << ")"; break; case kind::UMINUS: @@ -167,25 +167,27 @@ void translate_to_qepcad_term(const std::map& variables, const E assert(false); break; } - } + } } -void translate_to_qepcad(const std::map& variables, const Expr& assertion) { +void translate_to_qepcad(const std::map& variables, + const Expr& assertion) +{ bool first; - + unsigned n = assertion.getNumChildren(); - + if (n == 0) { assert(false); } else { - + std::string op; bool theory = false; bool binary = false; - + switch (assertion.getKind()) { - case kind::NOT: - cout << "[~"; + case kind::NOT: + cout << "[~"; translate_to_qepcad(variables, assertion[0]); cout << "]"; break; @@ -212,7 +214,7 @@ void translate_to_qepcad(const std::map& variables, const Expr& translate_to_qepcad(variables, assertion[i]); } cout << "]"; - break; + break; case kind::IMPLIES: op = "==>"; binary = true; @@ -220,7 +222,7 @@ void translate_to_qepcad(const std::map& variables, const Expr& case kind::IFF: op = "<==>"; binary = true; - break; + break; case kind::EQUAL: op = "="; theory = true; @@ -252,7 +254,7 @@ void translate_to_qepcad(const std::map& variables, const Expr& cout << " " << op << " "; translate_to_qepcad_term(variables, assertion[1]); cout << "]"; - } + } if (binary) { cout << "["; @@ -260,15 +262,15 @@ void translate_to_qepcad(const std::map& variables, const Expr& cout << " " << op << " "; translate_to_qepcad(variables, assertion[1]); cout << "]"; - } - } + } + } } void translate_to_qepcad( string input, const vector& info_tags, const vector& info_data, - const std::map& variables, + const std::map& variables, const vector& assertions) { bool first; @@ -277,22 +279,22 @@ void translate_to_qepcad( cout << "[ translated from " << input << " "; bool dump_tags = false; - if (dump_tags) { - first = true; + if (dump_tags) { + first = true; for (unsigned i = 0; i < info_tags.size(); ++ i) { if (!first) { - cout << ", "; + cout << ", "; } first = false; cout << info_tags[i] << " = " << info_data[i]; } } - - cout << "]" << endl; + + cout << "]" << endl; // Declare the variables cout << "("; - + first = true; for (unsigned i = 0; i < variables.size(); ++ i) { if (!first) { @@ -301,17 +303,17 @@ void translate_to_qepcad( first = false; cout << "x" << i;; } - + cout << ")" << endl; - // Number of free variables + // Number of free variables cout << "0" << endl; - // The quantifiers first + // The quantifiers first for (unsigned i = 0; i < variables.size(); ++ i) { cout << "(Ex" << i << ")"; } - + // Now the formula cout << "["; if (assertions.size() > 1) { @@ -319,35 +321,34 @@ void translate_to_qepcad( for (unsigned i = 0; i < assertions.size(); ++ i) { if (!first) { cout << " /\\ "; - } + } first = false; translate_to_qepcad(variables, assertions[i]); } } else { translate_to_qepcad(variables, assertions[0]); } - cout << "]." << endl; + cout << "]." << endl; // Before normalization cout << "go" << endl; - + // Before projection if (variables.size() > 3) { cout << "proj-op (m,m"; for (unsigned i = 3; i < variables.size(); ++ i) { cout << ",h"; - } + } cout << ")" << endl; } cout << "go" << endl; - + // Before choice cout << "d-stat" << endl; - + // Before solution - cout << "go" << endl; + cout << "go" << endl; // Finish up cout << "finish" << endl; } - diff --git a/examples/nra-translate/smt2toredlog.cpp b/examples/nra-translate/smt2toredlog.cpp index 7a6f87122..934906b74 100644 --- a/examples/nra-translate/smt2toredlog.cpp +++ b/examples/nra-translate/smt2toredlog.cpp @@ -23,7 +23,6 @@ #include #include "expr/expr.h" -#include "options/base_options.h" #include "options/options.h" #include "parser/parser.h" #include "parser/parser_builder.h" @@ -40,22 +39,22 @@ void translate_to_redlog( string command, const vector& info_tags, const vector& info_data, - const map& variables, + const map& variables, const vector& assertions); -int main(int argc, char* argv[]) +int main(int argc, char* argv[]) { - // Get the filename + // Get the filename string input(argv[1]); // Get the redlog command string command(argv[2]); // Create the expression manager Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); ExprManager exprManager(options); - + // Create the parser ParserBuilder parserBuilder(&exprManager, input, options); Parser* parser = parserBuilder.build(); @@ -169,14 +168,14 @@ void translate_to_redlog_term(const map& variables, const Expr& assert(false); break; } - } + } } void translate_to_redlog(const map& variables, const Expr& assertion) { bool first; - + unsigned n = assertion.getNumChildren(); - + if (n == 0) { if (assertion.isConst()) { if (assertion.getConst()) { @@ -188,13 +187,13 @@ void translate_to_redlog(const map& variables, const Expr& asser assert(false); } } else { - + std::string op; bool binary = false; bool theory = false; - + switch (assertion.getKind()) { - case kind::NOT: + case kind::NOT: cout << "(not "; translate_to_redlog(variables, assertion[0]); cout << ")"; @@ -326,4 +325,3 @@ void translate_to_redlog( cout << "quit;" << endl; } - diff --git a/examples/sets-translate/sets_translate.cpp b/examples/sets-translate/sets_translate.cpp index a310a2e6b..c07369661 100644 --- a/examples/sets-translate/sets_translate.cpp +++ b/examples/sets-translate/sets_translate.cpp @@ -24,7 +24,6 @@ #include "expr/expr.h" #include "options/language.h" -#include "options/base_options.h" #include "options/options.h" #include "options/set_language.h" #include "parser/parser.h" @@ -265,7 +264,7 @@ int main(int argc, char* argv[]) // Create the expression manager Options options; - options.set(inputLanguage, language::input::LANG_SMTLIB_V2); + options.setInputLanguage(language::input::LANG_SMTLIB_V2); cout << language::SetLanguage(language::output::LANG_SMTLIB_V2); // cout << Expr::dag(0); ExprManager exprManager(options); diff --git a/examples/translator.cpp b/examples/translator.cpp index 248dadd5f..94f5ad1b8 100644 --- a/examples/translator.cpp +++ b/examples/translator.cpp @@ -24,8 +24,8 @@ #include "expr/expr.h" #include "expr/expr_iomanip.h" -#include "options/base_options.h" #include "options/language.h" +#include "options/options.h" #include "options/set_language.h" #include "parser/parser.h" #include "parser/parser_builder.h" @@ -103,7 +103,7 @@ static void readFile(const char* filename, InputLanguage fromLang, OutputLanguag *out << language::SetLanguage(toLang); Options opts; - opts.set(options::inputLanguage, fromLang); + opts.setInputLanguage(fromLang); ExprManager exprMgr(opts); ParserBuilder parserBuilder(&exprMgr, filename, opts); if(!strcmp(filename, "-")) { diff --git a/src/Makefile.am b/src/Makefile.am index c71caea51..3f573f55e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -105,26 +105,25 @@ libcvc4_la_SOURCES = \ prop/sat_solver_types.h \ prop/sat_solver_factory.h \ prop/sat_solver_factory.cpp \ - smt/smt_engine.cpp \ - smt/smt_engine_check_proof.cpp \ - smt/smt_engine.h \ - smt/smt_globals.cpp \ - smt/smt_globals.h \ + smt/boolean_terms.cpp \ + smt/boolean_terms.h \ + smt/command_list.cpp \ + smt/command_list.h \ + smt/logic_exception.h \ + smt/logic_request.cpp \ + smt/logic_request.h \ + smt/managed_ostreams.cpp \ + smt/managed_ostreams.h \ smt/model_postprocessor.cpp \ smt/model_postprocessor.h \ + smt/smt_engine.cpp \ + smt/smt_engine.h \ + smt/smt_engine_check_proof.cpp \ smt/smt_engine_scope.cpp \ smt/smt_engine_scope.h \ - smt/smt_options_handler.cpp \ - smt/smt_options_handler.h \ smt/smt_statistics_registry.cpp \ smt/smt_statistics_registry.h \ - smt/command_list.cpp \ - smt/command_list.h \ - smt/boolean_terms.h \ - smt/boolean_terms.cpp \ - smt/logic_exception.h \ - smt/logic_request.h \ - smt/logic_request.cpp \ + smt/update_ostream.h \ theory/logic_info.h \ theory/logic_info.cpp \ theory/output_channel.h \ @@ -520,7 +519,7 @@ svn_versioninfo.cpp: svninfo rev=0; \ mods=false; \ fi; \ - echo "#include \"util/configuration.h\""; \ + echo "#include \"base/configuration.h\""; \ echo "const bool ::CVC4::Configuration::IS_SUBVERSION_BUILD = $$issvn;"; \ echo "const char* const ::CVC4::Configuration::SUBVERSION_BRANCH_NAME = \"$$branch\";"; \ echo "const unsigned ::CVC4::Configuration::SUBVERSION_REVISION = $$rev;"; \ @@ -548,7 +547,7 @@ git_versioninfo.cpp: gitinfo rev=unknown; \ mods=false; \ fi; \ - echo "#include \"util/configuration.h\""; \ + echo "#include \"base/configuration.h\""; \ echo "const bool ::CVC4::Configuration::IS_GIT_BUILD = $$isgit;"; \ echo "const char* const ::CVC4::Configuration::GIT_BRANCH_NAME = \"$$branch\";"; \ echo "const char* const ::CVC4::Configuration::GIT_COMMIT = \"$$rev\";"; \ diff --git a/src/base/Makefile.am b/src/base/Makefile.am index f2fe3f306..bda063176 100644 --- a/src/base/Makefile.am +++ b/src/base/Makefile.am @@ -15,6 +15,9 @@ noinst_LTLIBRARIES = libbase.la libbase_la_SOURCES = \ Makefile.am \ Makefile.in \ + configuration.cpp \ + configuration.h \ + configuration_private.h \ cvc4_assert.cpp \ cvc4_assert.h \ exception.cpp \ @@ -30,11 +33,52 @@ libbase_la_SOURCES = \ BUILT_SOURCES = \ tls.h +# listing {Debug,Trace}_tags too ensures that make doesn't auto-remove it +# after building (if it does, we don't get the "cached" effect with +# the .tmp files below, and we have to re-compile and re-link each +# time, even when there are no changes). +BUILT_SOURCES += \ + Debug_tags.h \ + Debug_tags \ + Trace_tags.h \ + Trace_tags + +MOSTLYCLEANFILES = \ + Debug_tags \ + Trace_tags \ + Debug_tags.tmp \ + Trace_tags.tmp \ + Debug_tags.h \ + Trace_tags.h + EXTRA_DIST = \ + configuration.i \ exception.i \ + mktagheaders \ + mktags \ modal_exception.i \ tls.h.in DISTCLEANFILES = \ tls.h.tmp \ tls.h + +%_tags.h: %_tags mktagheaders + $(AM_V_at)chmod +x @srcdir@/mktagheaders + $(AM_V_GEN)( @srcdir@/mktagheaders "$<" "$<" ) >"$@" + +# This .tmp business is to keep from having to re-compile options.cpp +# (and then re-link the libraries) if nothing has changed. +%_tags: %_tags.tmp + $(AM_V_GEN)\ + diff -q "$^" "$@" &>/dev/null || mv "$^" "$@" || true +# .PHONY ensures the .tmp version is always rebuilt (to check for any changes) +.PHONY: Debug_tags.tmp Trace_tags.tmp +# The "sed" invocation below is particularly obnoxious, but it works around +# inconsistencies in REs on different platforms, using only a basic regular +# expression (no |, no \<, ...). +Debug_tags.tmp Trace_tags.tmp: mktags + $(AM_V_at)chmod +x @srcdir@/mktags + $(AM_V_GEN)(@srcdir@/mktags \ + '$(@:_tags.tmp=)' \ + "$$(find @srcdir@/../ -name '*.cpp' -o -name '*.h' -o -name '*.cc' -o -name '*.g')") >"$@" diff --git a/src/util/configuration.cpp b/src/base/configuration.cpp similarity index 97% rename from src/util/configuration.cpp rename to src/base/configuration.cpp index bbde7193f..c3ba39075 100644 --- a/src/util/configuration.cpp +++ b/src/base/configuration.cpp @@ -15,7 +15,7 @@ ** Implementation of Configuration class, which provides compile-time ** configuration information about the CVC4 library. **/ -#include "util/configuration.h" +#include "base/configuration.h" #include #include @@ -24,14 +24,14 @@ #include #include "cvc4autoconfig.h" -#include "util/configuration_private.h" +#include "base/configuration_private.h" #if defined(CVC4_DEBUG) && defined(CVC4_TRACING) -# include "options/Debug_tags.h" +# include "base/Debug_tags.h" #endif /* CVC4_DEBUG && CVC4_TRACING */ #ifdef CVC4_TRACING -# include "options/Trace_tags.h" +# include "base/Trace_tags.h" #endif /* CVC4_TRACING */ using namespace std; diff --git a/src/util/configuration.h b/src/base/configuration.h similarity index 100% rename from src/util/configuration.h rename to src/base/configuration.h diff --git a/src/util/configuration.i b/src/base/configuration.i similarity index 56% rename from src/util/configuration.i rename to src/base/configuration.i index 240131592..3b92e2438 100644 --- a/src/util/configuration.i +++ b/src/base/configuration.i @@ -1,7 +1,7 @@ %{ -#include "util/configuration.h" +#include "base/configuration.h" %} %apply char **STRING_ARRAY { char const* const* } -%include "util/configuration.h" +%include "base/configuration.h" %clear char const* const*; diff --git a/src/util/configuration_private.h b/src/base/configuration_private.h similarity index 99% rename from src/util/configuration_private.h rename to src/base/configuration_private.h index 631a323d3..902fdad09 100644 --- a/src/util/configuration_private.h +++ b/src/base/configuration_private.h @@ -19,7 +19,8 @@ #define __CVC4__CONFIGURATION_PRIVATE_H #include -#include "util/configuration.h" + +#include "base/configuration.h" namespace CVC4 { diff --git a/src/base/exception.cpp b/src/base/exception.cpp index e1486e5bc..cdad92d5d 100644 --- a/src/base/exception.cpp +++ b/src/base/exception.cpp @@ -50,7 +50,7 @@ void LastExceptionBuffer::setContents(const char* string) { } } -char* IllegalArgumentException::s_header = "Illegal argument detected"; +const char* IllegalArgumentException::s_header = "Illegal argument detected"; std::string IllegalArgumentException::formatVariadic() { return std::string(); diff --git a/src/base/exception.h b/src/base/exception.h index 02384b6cb..38bbe47a4 100644 --- a/src/base/exception.h +++ b/src/base/exception.h @@ -90,7 +90,7 @@ protected: static std::string format_extra(const char* condStr, const char* argDesc); - static char* s_header; + static const char* s_header; public: @@ -155,8 +155,8 @@ public: private: /* Disallow copies */ - LastExceptionBuffer(const LastExceptionBuffer&) CVC4_UNUSED; - LastExceptionBuffer& operator=(const LastExceptionBuffer&) CVC4_UNUSED; + LastExceptionBuffer(const LastExceptionBuffer&) CVC4_UNDEFINED; + LastExceptionBuffer& operator=(const LastExceptionBuffer&) CVC4_UNDEFINED; char* d_contents; diff --git a/src/base/listener.cpp b/src/base/listener.cpp index 62bec5990..2daced1f5 100644 --- a/src/base/listener.cpp +++ b/src/base/listener.cpp @@ -49,8 +49,8 @@ void ListenerCollection::notify() { bool ListenerCollection::empty() const { return d_listeners.empty(); } -RegisterListener::RegisterListener(ListenerCollection* collection, - Listener* listener) +ListenerCollection::Registration::Registration( + ListenerCollection* collection, Listener* listener) : d_listener(listener) , d_position() , d_collection(collection) @@ -58,9 +58,42 @@ RegisterListener::RegisterListener(ListenerCollection* collection, d_position = d_collection->addListener(d_listener); } -RegisterListener::~RegisterListener() { +ListenerCollection::Registration::~Registration() { d_collection->removeListener(d_position); delete d_listener; } + ListenerCollection::Registration* ListenerCollection::registerListener( + Listener* listener) +{ + return new Registration(this, listener); +} + + +ListenerRegistrationList::ListenerRegistrationList() + : d_registrations() +{} + +ListenerRegistrationList::~ListenerRegistrationList() { + clear(); +} + +void ListenerRegistrationList::add( + ListenerCollection::Registration* registration) +{ + d_registrations.push_back(registration); +} + +void ListenerRegistrationList::clear(){ + typedef std::list::iterator iterator; + for(iterator i = d_registrations.begin(), iend = d_registrations.end(); + i != iend; ++i) + { + ListenerCollection::Registration* current = *i; + delete current; + } + d_registrations.clear(); +} + + }/* CVC4 namespace */ diff --git a/src/base/listener.h b/src/base/listener.h index d6828818c..8094c634d 100644 --- a/src/base/listener.h +++ b/src/base/listener.h @@ -14,8 +14,8 @@ ** Utilities for the development of a Listener interface class. This class ** provides a single notification that must be overwritten. This file also ** provides a utility class for a collection of listeners and an RAII style - ** RegisterListener class for managing the relationship between Listeners - ** and the manager. + ** Registration class for managing the relationship between Listeners + ** and the collection. **/ #include "cvc4_public.h" @@ -54,45 +54,111 @@ public: typedef std::list ListenerList; typedef ListenerList::iterator iterator; + /** Creates an empty listener collection. */ ListenerCollection(); + /** + * Destroys an iterator collection. + * If assertions are on, this throws an AssertionException if the collection + * is not empty(). + */ ~ListenerCollection(); + /** + * This adds a listener to the current collection and returns + * an iterator to the listener in the collection. + * The user of the collection must call removeListener() using + * this iterator. + * The collection does not take over the memory for the listener. + */ iterator addListener(Listener* listener); + /** + * Remove an listener using the iterator distributed when adding the + * listener. + */ void removeListener(iterator position); + /** Calls notify() on all listeners in the collection. */ void notify(); + /** Returns true if the collection contains no listeners. */ bool empty() const; + /** + * Registration is an RAII utility function for using Listener + * with ListenerCollection. + * + * On construction, the Registration takes a ListenerCollection, + * collection, + * and a Listener*, listener. It takes over the memory for listener. It then + * adds listener to collection. On destruction it removes listener and calls + * delete on listener. + * + * Because of this usage, a Registration must be destroyed before the + * ListenerCollection it is attached to. + */ + class CVC4_PUBLIC Registration { + public: + Registration(ListenerCollection* collection, Listener* listener); + ~Registration(); + + private: + Listener* d_listener; + ListenerCollection::iterator d_position; + ListenerCollection* d_collection; + };/* class CVC4::ListenerCollection::Registration */ + + + /** + * Returns a new Registration given a Listener that is attached to this + * ListenerCollection. Management of the memory is handed to the user of + * this function. To remove the listener, call the destructor for the + * Registration. + */ + Registration* registerListener(Listener* listener); + private: + + /** + * Disabling the copy-constructor. + * The user of the class must be know to remove listeners on the collection. + * Allowing copies will only cause confusion. + */ + ListenerCollection(const ListenerCollection& copy) CVC4_UNDEFINED; + + /** + * Disabling the assignment operator. + * The user of the class must be know to remove listeners on the collection. + * Allowing copies will only cause confusion. + */ + ListenerCollection& operator=(const ListenerCollection& copy) CVC4_UNDEFINED; + + /** A list of the listeners in the collection.*/ ListenerList d_listeners; -}; +};/* class CVC4::ListenerCollection */ /** - * RegisterListener is an RAII utility function for using Listener - * with ListenerCollection. + * A list of ListenerCollection::Registration* pointers. * - * On construction, the RegisterListener takes a ListenerCollection, collection, - * and a Listener*, listener. It takes over the memory for listener. It then - * add listener to collection. On destruction it removes listener and calls - * delete on listener. - * - * Because of this usage, a RegisterListener must be destroyed before - * collection. + * This list assumes it has control over all of the memory of the registrations. */ -class CVC4_PUBLIC RegisterListener { -public: - RegisterListener(ListenerCollection* collection, Listener* listener); - ~RegisterListener(); - -private: - Listener* d_listener; - ListenerCollection::iterator d_position; - ListenerCollection* d_collection; -}; - +class ListenerRegistrationList { + public: + ListenerRegistrationList(); + ~ListenerRegistrationList(); + + void add(ListenerCollection::Registration* registration); + void clear(); + + private: + /** Disallow copying.*/ + ListenerRegistrationList(const ListenerRegistrationList&) CVC4_UNDEFINED; + /** Disallow assignment.*/ + ListenerRegistrationList operator=(const ListenerRegistrationList&) + CVC4_UNDEFINED; + std::list d_registrations; +};/* class CVC4::ListenerRegistrationList */ }/* CVC4 namespace */ diff --git a/src/options/mktagheaders b/src/base/mktagheaders similarity index 100% rename from src/options/mktagheaders rename to src/base/mktagheaders diff --git a/src/options/mktags b/src/base/mktags similarity index 100% rename from src/options/mktags rename to src/base/mktags diff --git a/src/base/output.h b/src/base/output.h index 0974591db..4bffad85f 100644 --- a/src/base/output.h +++ b/src/base/output.h @@ -212,11 +212,12 @@ public: bool off(std::string tag) { d_tags.erase (tag); return false; } bool off() { d_tags.clear(); return false; } - bool isOn(const char* tag) { return d_tags.find(std::string(tag)) != d_tags.end(); } + bool isOn(const char* tag) { return d_tags.find(std::string(tag)) != d_tags.end(); } bool isOn(std::string tag) { return d_tags.find(tag) != d_tags.end(); } - std::ostream& setStream(std::ostream& os) { d_os = &os; return os; } + std::ostream& setStream(std::ostream* os) { d_os = os; return *os; } std::ostream& getStream() { return *d_os; } + std::ostream* getStreamPointer() { return d_os; } };/* class DebugC */ /** The warning output class */ @@ -231,8 +232,9 @@ public: CVC4ostream operator()() { return CVC4ostream(d_os); } - std::ostream& setStream(std::ostream& os) { d_os = &os; return os; } + std::ostream& setStream(std::ostream* os) { d_os = os; return *d_os; } std::ostream& getStream() { return *d_os; } + std::ostream* getStreamPointer() { return d_os; } bool isOn() const { return d_os != &null_os; } @@ -264,8 +266,9 @@ public: CVC4ostream operator()() { return CVC4ostream(d_os); } - std::ostream& setStream(std::ostream& os) { d_os = &os; return os; } + std::ostream& setStream(std::ostream* os) { d_os = os; return *d_os; } std::ostream& getStream() { return *d_os; } + std::ostream* getStreamPointer() { return d_os; } bool isOn() const { return d_os != &null_os; } };/* class MessageC */ @@ -281,8 +284,9 @@ public: CVC4ostream operator()() { return CVC4ostream(d_os); } - std::ostream& setStream(std::ostream& os) { d_os = &os; return os; } + std::ostream& setStream(std::ostream* os) { d_os = os; return *d_os; } std::ostream& getStream() { return *d_os; } + std::ostream* getStreamPointer() { return d_os; } bool isOn() const { return d_os != &null_os; } };/* class NoticeC */ @@ -298,8 +302,9 @@ public: CVC4ostream operator()() { return CVC4ostream(d_os); } - std::ostream& setStream(std::ostream& os) { d_os = &os; return os; } + std::ostream& setStream(std::ostream* os) { d_os = os; return *d_os; } std::ostream& getStream() { return *d_os; } + std::ostream* getStreamPointer() { return d_os; } bool isOn() const { return d_os != &null_os; } };/* class ChatC */ @@ -340,8 +345,10 @@ public: bool isOn(const char* tag) { return d_tags.find(std::string(tag)) != d_tags.end(); } bool isOn(std::string tag) { return d_tags.find(tag) != d_tags.end(); } - std::ostream& setStream(std::ostream& os) { d_os = &os; return os; } + std::ostream& setStream(std::ostream* os) { d_os = os; return *d_os; } std::ostream& getStream() { return *d_os; } + std::ostream* getStreamPointer() { return d_os; } + };/* class TraceC */ /** The dump output class */ @@ -385,8 +392,9 @@ public: bool isOn(const char* tag) { return d_tags.find(std::string(tag)) != d_tags.end(); } bool isOn(std::string tag) { return d_tags.find(tag) != d_tags.end(); } - std::ostream& setStream(std::ostream& os) { d_os = &os; return os; } + std::ostream& setStream(std::ostream* os) { d_os = os; return *d_os; } std::ostream& getStream() { return *d_os; } + std::ostream* getStreamPointer() { return d_os; } };/* class DumpOutC */ /** The debug output singleton */ diff --git a/src/compat/cvc3_compat.cpp b/src/compat/cvc3_compat.cpp index 9ae394b97..a62776c80 100644 --- a/src/compat/cvc3_compat.cpp +++ b/src/compat/cvc3_compat.cpp @@ -28,11 +28,8 @@ #include "expr/expr_iomanip.h" #include "expr/kind.h" #include "expr/predicate.h" -#include "options/base_options.h" -#include "options/expr_options.h" -#include "options/parser_options.h" +#include "options/options.h" #include "options/set_language.h" -#include "options/smt_options.h" #include "parser/parser.h" #include "parser/parser_builder.h" #include "smt_util/command.h" @@ -655,11 +652,11 @@ std::string ExprManager::getKindName(int kind) { } InputLanguage ExprManager::getInputLang() const { - return getOptions()[CVC4::options::inputLanguage]; + return getOptions().getInputLanguage(); } InputLanguage ExprManager::getOutputLang() const { - return CVC4::language::toInputLanguage(getOptions()[CVC4::options::outputLanguage]); + return CVC4::language::toInputLanguage(getOptions().getOutputLanguage()); } Expr Expr::operator[](int i) const { @@ -927,7 +924,7 @@ void ValidityChecker::setUpOptions(CVC4::Options& options, const CLFlags& clflag d_smt->setOption("input-language", clflags["lang"].getString()); if(clflags["output-lang"].getString() == "") { stringstream langss; - langss << CVC4::language::toOutputLanguage(options[CVC4::options::inputLanguage]); + langss << CVC4::language::toOutputLanguage(options.getInputLanguage()); d_smt->setOption("output-language", langss.str()); } else { d_smt->setOption("output-language", clflags["output-lang"].getString()); @@ -1563,7 +1560,8 @@ void ValidityChecker::printExpr(const Expr& e) { void ValidityChecker::printExpr(const Expr& e, std::ostream& os) { CVC4::expr::ExprSetDepth::Scope sd(os, -1); CVC4::expr::ExprPrintTypes::Scope pt(os, false); - CVC4::language::SetLanguage::Scope sl(os, d_em->getOptions()[CVC4::options::outputLanguage]); + CVC4::language::SetLanguage::Scope sl( + os, d_em->getOptions().getOutputLanguage()); os << e; } @@ -2561,8 +2559,8 @@ void ValidityChecker::logAnnotation(const Expr& annot) { static void doCommands(CVC4::parser::Parser* parser, CVC4::SmtEngine* smt, CVC4::Options& opts) { while(CVC4::Command* cmd = parser->nextCommand()) { - if(opts[CVC4::options::verbosity] >= 0) { - cmd->invoke(smt, *opts[CVC4::options::out]); + if(opts.getVerbosity() >= 0) { + cmd->invoke(smt, *opts.getOut()); } else { cmd->invoke(smt); } @@ -2574,7 +2572,8 @@ void ValidityChecker::loadFile(const std::string& fileName, InputLanguage lang, bool interactive, bool calledFromParser) { - CVC4::Options opts = d_em->getOptions(); + CVC4::Options opts; + opts.copyValues(d_em->getOptions()); stringstream langss; langss << lang; d_smt->setOption("input-language", CVC4::SExpr(langss.str())); @@ -2589,7 +2588,9 @@ void ValidityChecker::loadFile(const std::string& fileName, void ValidityChecker::loadFile(std::istream& is, InputLanguage lang, bool interactive) { - CVC4::Options opts = d_em->getOptions(); + CVC4::Options opts; + opts.copyValues(d_em->getOptions()); + stringstream langss; langss << lang; d_smt->setOption("input-language", CVC4::SExpr(langss.str())); diff --git a/src/cvc4.i b/src/cvc4.i index 4b954489c..f4525203e 100644 --- a/src/cvc4.i +++ b/src/cvc4.i @@ -305,6 +305,7 @@ std::set CVC4::JavaInputStreamAdapter::s_adapters; // TIM: // At the moment, the header includes seem to need to follow a special order. // I don't know why. I am following the build order +%include "base/configuration.i" %include "base/exception.i" %include "base/modal_exception.i" @@ -318,7 +319,6 @@ std::set CVC4::JavaInputStreamAdapter::s_adapters; // Tim: The remainder of util/. %include "util/bool.i" %include "util/cardinality.i" -%include "util/configuration.i" %include "util/hash.i" %include "util/proof.i" %include "util/regexp.i" diff --git a/src/expr/Makefile.am b/src/expr/Makefile.am index b3fb13253..c04de4421 100644 --- a/src/expr/Makefile.am +++ b/src/expr/Makefile.am @@ -31,7 +31,8 @@ libexpr_la_SOURCES = \ node_manager.cpp \ node_manager.h \ node_manager_attributes.h \ - node_self_iterator.h \ + node_manager_listeners.cpp \ + node_manager_listeners.h \ node_self_iterator.h \ node_value.cpp \ node_value.h \ diff --git a/src/expr/expr_template.h b/src/expr/expr_template.h index 7d82cb222..d037a6bb9 100644 --- a/src/expr/expr_template.h +++ b/src/expr/expr_template.h @@ -40,7 +40,7 @@ ${includes} // compiler directs the user to the template file instead of the // generated one. We don't want the user to modify the generated one, // since it'll get overwritten on a later build. -#line 45 "${template}" +#line 44 "${template}" namespace CVC4 { @@ -553,7 +553,7 @@ private: ${getConst_instantiations} -#line 939 "${template}" +#line 557 "${template}" inline size_t ExprHashFunction::operator()(CVC4::Expr e) const { return (size_t) e.getId(); diff --git a/src/expr/node.h b/src/expr/node.h index c0e2a5542..a51de6d66 100644 --- a/src/expr/node.h +++ b/src/expr/node.h @@ -30,6 +30,7 @@ #include #include +#include "base/configuration.h" #include "base/cvc4_assert.h" #include "base/exception.h" #include "base/output.h" @@ -40,7 +41,6 @@ #include "expr/expr_iomanip.h" #include "options/language.h" #include "options/set_language.h" -#include "util/configuration.h" #include "util/utility.h" #include "util/hash.h" diff --git a/src/expr/node_manager.cpp b/src/expr/node_manager.cpp index 13960b717..e52776fce 100644 --- a/src/expr/node_manager.cpp +++ b/src/expr/node_manager.cpp @@ -23,9 +23,11 @@ #include #include "base/cvc4_assert.h" +#include "base/listener.h" #include "base/tls.h" #include "expr/attribute.h" #include "expr/node_manager_attributes.h" +#include "expr/node_manager_listeners.h" #include "expr/type_checker.h" #include "options/options.h" #include "options/smt_options.h" @@ -84,6 +86,7 @@ NodeManager::NodeManager(ExprManager* exprManager) : d_options(new Options()), d_statisticsRegistry(new StatisticsRegistry()), d_resourceManager(new ResourceManager()), + d_registrations(new ListenerRegistrationList()), next_id(0), d_attrManager(new expr::attr::AttributeManager()), d_exprManager(exprManager), @@ -96,16 +99,19 @@ NodeManager::NodeManager(ExprManager* exprManager) : NodeManager::NodeManager(ExprManager* exprManager, const Options& options) : - d_options(new Options(options)), + d_options(new Options()), d_statisticsRegistry(new StatisticsRegistry()), d_resourceManager(new ResourceManager()), + d_registrations(new ListenerRegistrationList()), next_id(0), d_attrManager(new expr::attr::AttributeManager()), d_exprManager(exprManager), d_nodeUnderDeletion(NULL), d_inReclaimZombies(false), d_abstractValueCount(0), - d_skolemCounter(0) { + d_skolemCounter(0) +{ + d_options->copyValues(options); init(); } @@ -135,6 +141,16 @@ void NodeManager::init() { if((*d_options)[options::cpuTime]) { d_resourceManager->useCPUTime(true); } + + // Do not notify() upon registration as these were handled manually above. + d_registrations->add(d_options->registerTlimitListener( + new TlimitListener(d_resourceManager), false)); + d_registrations->add(d_options->registerTlimitPerListener( + new TlimitPerListener(d_resourceManager), false)); + d_registrations->add(d_options->registerRlimitListener( + new RlimitListener(d_resourceManager), false)); + d_registrations->add(d_options->registerRlimitPerListener( + new RlimitPerListener(d_resourceManager), false)); } NodeManager::~NodeManager() { @@ -180,6 +196,8 @@ NodeManager::~NodeManager() { // defensive coding, in case destruction-order issues pop up (they often do) delete d_statisticsRegistry; d_statisticsRegistry = NULL; + delete d_registrations; + d_registrations = NULL; delete d_resourceManager; d_resourceManager = NULL; delete d_attrManager; diff --git a/src/expr/node_manager.h b/src/expr/node_manager.h index 870408939..1ae9f1e8e 100644 --- a/src/expr/node_manager.h +++ b/src/expr/node_manager.h @@ -102,8 +102,15 @@ class NodeManager { Options* d_options; StatisticsRegistry* d_statisticsRegistry; + ResourceManager* d_resourceManager; + /** + * A list of registrations on d_options to that call into d_resourceManager. + * These must be garbage collected before d_options and d_resourceManager. + */ + ListenerRegistrationList* d_registrations; + NodeValuePool d_nodeValuePool; size_t next_id; @@ -295,6 +302,8 @@ class NodeManager { // undefined private copy constructor (disallow copy) NodeManager(const NodeManager&) CVC4_UNDEFINED; + NodeManager& operator=(const NodeManager&) CVC4_UNDEFINED; + void init(); /** diff --git a/src/expr/node_manager_listeners.cpp b/src/expr/node_manager_listeners.cpp new file mode 100644 index 000000000..ec2de105a --- /dev/null +++ b/src/expr/node_manager_listeners.cpp @@ -0,0 +1,44 @@ +/********************* */ +/*! \file node_manager_listeners.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2014 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Listeners that NodeManager registers to its Options object. + ** + ** Listeners that NodeManager registers to its Options object. + **/ + +#include "node_manager_listeners.h" + +#include "base/listener.h" +#include "options/smt_options.h" +#include "util/resource_manager.h" + +namespace CVC4 { +namespace expr { + + +void TlimitListener::notify() { + d_rm->setTimeLimit(options::cumulativeMillisecondLimit(), true); +} + +void TlimitPerListener::notify() { + d_rm->setTimeLimit(options::perCallMillisecondLimit(), false); +} + +void RlimitListener::notify() { + d_rm->setTimeLimit(options::cumulativeResourceLimit(), true); +} + +void RlimitPerListener::notify() { + d_rm->setTimeLimit(options::perCallResourceLimit(), false); +} + +}/* CVC4::expr namespace */ +}/* CVC4 namespace */ diff --git a/src/expr/node_manager_listeners.h b/src/expr/node_manager_listeners.h new file mode 100644 index 000000000..fc7c2f65f --- /dev/null +++ b/src/expr/node_manager_listeners.h @@ -0,0 +1,63 @@ +/********************* */ +/*! \file node_manager_listeners.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2014 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Listeners that NodeManager registers to its Options object. + ** + ** Listeners that NodeManager registers to its Options object. + **/ + +#include "cvc4_private.h" + +#ifndef __CVC4__EXPR__NODE_MANAGER_LISTENERS_H +#define __CVC4__EXPR__NODE_MANAGER_LISTENERS_H + +#include "base/listener.h" +#include "util/resource_manager.h" + +namespace CVC4 { +namespace expr { + +class TlimitListener : public Listener { + public: + TlimitListener(ResourceManager* rm) : d_rm(rm) {} + virtual void notify(); + private: + ResourceManager* d_rm; +}; + +class TlimitPerListener : public Listener { + public: + TlimitPerListener(ResourceManager* rm) : d_rm(rm) {} + virtual void notify(); + private: + ResourceManager* d_rm; +}; + +class RlimitListener : public Listener { + public: + RlimitListener(ResourceManager* rm) : d_rm(rm) {} + virtual void notify(); + private: + ResourceManager* d_rm; +}; + +class RlimitPerListener : public Listener { + public: + RlimitPerListener(ResourceManager* rm) : d_rm(rm) {} + virtual void notify(); + private: + ResourceManager* d_rm; +}; + +}/* CVC4::expr namespace */ +}/* CVC4 namespace */ + +#endif /* __CVC4__EXPR__NODE_MANAGER_LISTENERS_H */ diff --git a/src/include/cvc4.h b/src/include/cvc4.h index d41fce056..09be6ff4c 100644 --- a/src/include/cvc4.h +++ b/src/include/cvc4.h @@ -18,6 +18,7 @@ #ifndef __CVC4__CVC4_H #define __CVC4__CVC4_H +#include #include #include #include @@ -27,7 +28,6 @@ #include #include #include -#include #include #include diff --git a/src/include/cvc4_private.h b/src/include/cvc4_private.h index 3cdb993f1..ccc850787 100644 --- a/src/include/cvc4_private.h +++ b/src/include/cvc4_private.h @@ -20,12 +20,9 @@ #define __CVC4_PRIVATE_H #if ! (defined(__BUILDING_CVC4LIB) || defined(__BUILDING_CVC4LIB_UNIT_TEST)) -# warning A private CVC4 header was included when not building the library or private unit test code. +# error A private CVC4 header was included when not building the library or private unit test code. #endif /* ! (__BUILDING_CVC4LIB || __BUILDING_CVC4LIB_UNIT_TEST) */ -#ifdef __BUILDING_STATISTICS_FOR_EXPORT -# warning A private CVC4 header was included when building a library for export. -#endif /* __BUILDING_STATISTICS_FOR_EXPORT */ #include "cvc4_public.h" #include "cvc4autoconfig.h" diff --git a/src/include/cvc4_private_library.h b/src/include/cvc4_private_library.h index 05bd3d820..e0127946d 100644 --- a/src/include/cvc4_private_library.h +++ b/src/include/cvc4_private_library.h @@ -20,7 +20,7 @@ #define __CVC4_PRIVATE_LIBRARY_H #if ! (defined(__BUILDING_CVC4LIB) || defined(__BUILDING_CVC4LIB_UNIT_TEST) || defined(__BUILDING_CVC4PARSERLIB) || defined(__BUILDING_CVC4PARSERLIB_UNIT_TEST) || defined(__BUILDING_CVC4COMPATLIB) || defined(__BUILDING_CVC4DRIVER)) -# warning A "private library" CVC4 header was included when not building the library, driver, or private unit test code. +# error A "private library" CVC4 header was included when not building the library, driver, or private unit test code. #endif /* ! (__BUILDING_CVC4LIB || __BUILDING_CVC4LIB_UNIT_TEST || __BUILDING_CVC4PARSERLIB || __BUILDING_CVC4PARSERLIB_UNIT_TEST || __BUILDING_CVC4DRIVER) */ #include "cvc4_public.h" diff --git a/src/include/cvc4parser_private.h b/src/include/cvc4parser_private.h index dd56c4e1d..c107c4f56 100644 --- a/src/include/cvc4parser_private.h +++ b/src/include/cvc4parser_private.h @@ -20,12 +20,12 @@ #define __CVC4PARSER_PRIVATE_H #if ! (defined(__BUILDING_CVC4PARSERLIB) || defined(__BUILDING_CVC4PARSERLIB_UNIT_TEST)) -# warning A private CVC4 parser header was included when not building the parser library or private unit test code. +# error A private CVC4 parser header was included when not building the parser library or private unit test code. #endif /* ! (__BUILDING_CVC4PARSERLIB || __BUILDING_CVC4PARSERLIB_UNIT_TEST) */ #include "cvc4parser_public.h" -// It would be nice to #include this here, but there are conflicts with -// antlr3's autoheader stuff, which they export :( +// It would be nice to #include "cvc4autoconfig.h" here, but there are conflicts +// with antlr3's autoheader stuff, which they export :( // // #include "cvc4autoconfig.h" diff --git a/src/lib/clock_gettime.c b/src/lib/clock_gettime.c index 0187cbb7d..01426dc51 100644 --- a/src/lib/clock_gettime.c +++ b/src/lib/clock_gettime.c @@ -16,7 +16,7 @@ ** OS X). **/ -#include "cvc4_private.h" +#warning "TODO: make lib/clock_gettime.h cvc4_private.h again." #include "lib/clock_gettime.h" diff --git a/src/lib/clock_gettime.h b/src/lib/clock_gettime.h index daae9aabf..3a181bef5 100644 --- a/src/lib/clock_gettime.h +++ b/src/lib/clock_gettime.h @@ -14,7 +14,7 @@ ** Replacement for clock_gettime() for systems without it (like Mac OS X). **/ -#include "cvc4_private.h" +#include "cvc4_private_library.h" #ifndef __CVC4__LIB__CLOCK_GETTIME_H #define __CVC4__LIB__CLOCK_GETTIME_H diff --git a/src/main/command_executor.cpp b/src/main/command_executor.cpp index aa43cff0f..b2dbaf39b 100644 --- a/src/main/command_executor.cpp +++ b/src/main/command_executor.cpp @@ -22,10 +22,6 @@ #include #include "main/main.h" -#include "options/base_options.h" -#include "options/main_options.h" -#include "options/printer_options.h" -#include "options/smt_options.h" #include "smt_util/command.h" @@ -55,12 +51,19 @@ CommandExecutor::CommandExecutor(ExprManager &exprMgr, Options &options) : d_smtEngine(new SmtEngine(&exprMgr)), d_options(options), d_stats("driver"), - d_result() { + d_result(), + d_replayStream(NULL) +{} + +void CommandExecutor::setReplayStream(ExprStream* replayStream) { + assert(d_replayStream == NULL); + d_replayStream = replayStream; + d_smtEngine->setReplayStream(d_replayStream); } bool CommandExecutor::doCommand(Command* cmd) { - if( d_options[options::parseOnly] ) { + if( d_options.getParseOnly() ) { return true; } @@ -70,15 +73,15 @@ bool CommandExecutor::doCommand(Command* cmd) bool status = true; for(CommandSequence::iterator subcmd = seq->begin(); - (status || d_options[options::continuedExecution]) && subcmd != seq->end(); + (status || d_options.getContinuedExecution()) && subcmd != seq->end(); ++subcmd) { status = doCommand(*subcmd); } return status; } else { - if(d_options[options::verbosity] > 2) { - *d_options[options::out] << "Invoking: " << *cmd << std::endl; + if(d_options.getVerbosity() > 2) { + *d_options.getOut() << "Invoking: " << *cmd << std::endl; } return doCommandSingleton(cmd); @@ -87,8 +90,8 @@ bool CommandExecutor::doCommand(Command* cmd) void CommandExecutor::reset() { - if(d_options[options::statistics]) { - flushStatistics(*d_options[options::err]); + if(d_options.getStatistics()) { + flushStatistics(*d_options.getErr()); } delete d_smtEngine; d_smtEngine = new SmtEngine(&d_exprMgr); @@ -97,8 +100,8 @@ void CommandExecutor::reset() bool CommandExecutor::doCommandSingleton(Command* cmd) { bool status = true; - if(d_options[options::verbosity] >= -1) { - status = smtEngineInvoke(d_smtEngine, cmd, d_options[options::out]); + if(d_options.getVerbosity() >= -1) { + status = smtEngineInvoke(d_smtEngine, cmd, d_options.getOut()); } else { status = smtEngineInvoke(d_smtEngine, cmd, NULL); } @@ -113,42 +116,53 @@ bool CommandExecutor::doCommandSingleton(Command* cmd) d_result = res = q->getResult(); } - if((cs != NULL || q != NULL) && d_options[options::statsEveryQuery]) { + if((cs != NULL || q != NULL) && d_options.getStatsEveryQuery()) { std::ostringstream ossCurStats; flushStatistics(ossCurStats); - printStatsIncremental(*d_options[options::err], d_lastStatistics, ossCurStats.str()); + std::ostream& err = *d_options.getErr(); + printStatsIncremental(err, d_lastStatistics, ossCurStats.str()); d_lastStatistics = ossCurStats.str(); } // dump the model/proof/unsat core if option is set if(status) { Command* g = NULL; - if( d_options[options::produceModels] && - d_options[options::dumpModels] && + if( d_options.getProduceModels() && + d_options.getDumpModels() && ( res.asSatisfiabilityResult() == Result::SAT || (res.isUnknown() && res.whyUnknown() == Result::INCOMPLETE) ) ) { g = new GetModelCommand(); } - if( d_options[options::proof] && - d_options[options::dumpProofs] && + if( d_options.getProof() && + d_options.getDumpProofs() && res.asSatisfiabilityResult() == Result::UNSAT ) { g = new GetProofCommand(); } - if( d_options[options::dumpInstantiations] && - ( ( d_options[options::instFormatMode] != INST_FORMAT_MODE_SZS && - ( res.asSatisfiabilityResult() == Result::SAT || (res.isUnknown() && res.whyUnknown() == Result::INCOMPLETE) ) ) || - res.asSatisfiabilityResult() == Result::UNSAT ) ) { + + if( d_options.getDumpInstantiations() && + ( ( d_options.getInstFormatMode() != INST_FORMAT_MODE_SZS && + ( res.asSatisfiabilityResult() == Result::SAT || + (res.isUnknown() && res.whyUnknown() == Result::INCOMPLETE) ) ) || + res.asSatisfiabilityResult() == Result::UNSAT ) ) + { g = new GetInstantiationsCommand(); } - if( d_options[options::dumpSynth] && res.asSatisfiabilityResult() == Result::UNSAT ){ + + if( d_options.getDumpSynth() && + res.asSatisfiabilityResult() == Result::UNSAT ) + { g = new GetSynthSolutionCommand(); } - if( d_options[options::dumpUnsatCores] && res.asSatisfiabilityResult() == Result::UNSAT ) { + + if( d_options.getDumpUnsatCores() && + res.asSatisfiabilityResult() == Result::UNSAT ) + { g = new GetUnsatCoreCommand(); } + if(g != NULL) { // set no time limit during dumping if applicable - if( d_options[options::forceNoLimitCpuWhileDump] ){ + if( d_options.getForceNoLimitCpuWhileDump() ){ setNoLimitCPU(); } status = doCommandSingleton(g); @@ -165,7 +179,9 @@ bool smtEngineInvoke(SmtEngine* smt, Command* cmd, std::ostream *out) cmd->invoke(smt, *out); } // ignore the error if the command-verbosity is 0 for this command - if(smt->getOption(std::string("command-verbosity:") + cmd->getCommandName()).getIntegerValue() == 0) { + std::string commandName = + std::string("command-verbosity:") + cmd->getCommandName(); + if(smt->getOption(commandName).getIntegerValue() == 0) { return true; } return !cmd->fail(); @@ -223,5 +239,51 @@ void printStatsIncremental(std::ostream& out, const std::string& prvsStatsString } } +void CommandExecutor::printStatsFilterZeros(std::ostream& out, + const std::string& statsString) { + // read each line, if a number, check zero and skip if so + // Stat are assumed to one-per line: ", " + + std::istringstream iss(statsString); + std::string statName, statValue; + + std::getline(iss, statName, ','); + + while( !iss.eof() ) { + + std::getline(iss, statValue, '\n'); + + double curFloat; + bool isFloat = (std::istringstream(statValue) >> curFloat); + + if( (isFloat && curFloat == 0) || + statValue == " \"0\"" || + statValue == " \"[]\"") { + // skip + } else { + out << statName << "," << statValue << std::endl; + } + + std::getline(iss, statName, ','); + } + +} + +void CommandExecutor::flushOutputStreams() { + if(d_options.getStatistics()) { + if(d_options.getStatsHideZeros() == false) { + flushStatistics(*(d_options.getErr())); + } else { + std::ostringstream ossStats; + flushStatistics(ossStats); + printStatsFilterZeros(*(d_options.getErr()), ossStats.str()); + } + } + + // make sure out and err streams are flushed too + d_options.flushOut(); + d_options.flushErr(); +} + }/* CVC4::main namespace */ }/* CVC4 namespace */ diff --git a/src/main/command_executor.h b/src/main/command_executor.h index 7b6c2fab5..03bbe661b 100644 --- a/src/main/command_executor.h +++ b/src/main/command_executor.h @@ -37,12 +37,16 @@ protected: Options& d_options; StatisticsRegistry d_stats; Result d_result; + ExprStream* d_replayStream; public: CommandExecutor(ExprManager &exprMgr, Options &options); virtual ~CommandExecutor() { delete d_smtEngine; + if(d_replayStream != NULL){ + delete d_replayStream; + } } /** @@ -65,7 +69,13 @@ public: d_stats.flushInformation(out); } - SmtGlobals* globals() { return d_smtEngine->globals(); } + static void printStatsFilterZeros(std::ostream& out, + const std::string& statsString); + + LemmaChannels* channels() { return d_smtEngine->channels(); } + void flushOutputStreams(); + + void setReplayStream(ExprStream* replayStream); protected: /** Executes treating cmd as a singleton */ diff --git a/src/main/command_executor_portfolio.cpp b/src/main/command_executor_portfolio.cpp index 9d0042694..bf1143647 100644 --- a/src/main/command_executor_portfolio.cpp +++ b/src/main/command_executor_portfolio.cpp @@ -31,12 +31,8 @@ #include "expr/pickler.h" #include "main/main.h" #include "main/portfolio.h" -#include "options/base_options.h" -#include "options/main_options.h" #include "options/options.h" -#include "options/printer_options.h" #include "options/set_language.h" -#include "options/smt_options.h" #include "smt_util/command.h" @@ -45,25 +41,26 @@ using namespace std; namespace CVC4 { namespace main { -CommandExecutorPortfolio::CommandExecutorPortfolio -(ExprManager &exprMgr, Options &options, vector& tOpts): - CommandExecutor(exprMgr, options), - d_numThreads(options[options::threads]), - d_smts(), - d_seq(new CommandSequence()), - d_threadOptions(tOpts), - d_vmaps(), - d_lastWinner(0), - d_channelsOut(), - d_channelsIn(), - d_ostringstreams(), - d_statLastWinner("portfolio::lastWinner"), - d_statWaitTime("portfolio::waitTime") +CommandExecutorPortfolio::CommandExecutorPortfolio( + ExprManager &exprMgr, Options &options, OptionsList& tOpts) + : CommandExecutor(exprMgr, options), + d_numThreads(options.getThreads()), + d_smts(), + d_seq(new CommandSequence()), + d_threadOptions(tOpts), + d_vmaps(), + d_lastWinner(0), + d_channelsOut(), + d_channelsIn(), + d_ostringstreams(), + d_statLastWinner("portfolio::lastWinner"), + d_statWaitTime("portfolio::waitTime") { assert(d_threadOptions.size() == d_numThreads); d_statLastWinner.setData(d_lastWinner); d_stats.registerStat(&d_statLastWinner); + d_stats.registerStat(&d_statWaitTime); /* Duplication, individualization */ @@ -111,7 +108,7 @@ void CommandExecutorPortfolio::lemmaSharingInit() if(d_numThreads == 1) { // Disable sharing - d_threadOptions[0].set(options::sharingFilterByLength, 0); + d_threadOptions[0].setSharingFilterByLength(0); } else { // Setup sharing channels const unsigned int sharingChannelSize = 1000000; @@ -125,34 +122,34 @@ void CommandExecutorPortfolio::lemmaSharingInit() /* Lemma I/O channels */ for(unsigned i = 0; i < d_numThreads; ++i) { - string tag = "thread #" + - boost::lexical_cast(d_threadOptions[i][options::thread_id]); + int thread_id = d_threadOptions[i].getThreadId(); + string tag = "thread #" + boost::lexical_cast(thread_id); LemmaOutputChannel* outputChannel = new PortfolioLemmaOutputChannel(tag, d_channelsOut[i], d_exprMgrs[i], d_vmaps[i]->d_from, d_vmaps[i]->d_to); LemmaInputChannel* inputChannel = new PortfolioLemmaInputChannel(tag, d_channelsIn[i], d_exprMgrs[i], d_vmaps[i]->d_from, d_vmaps[i]->d_to); - d_smts[i]->globals()->setLemmaInputChannel(inputChannel); - d_smts[i]->globals()->setLemmaOutputChannel(outputChannel); + d_smts[i]->channels()->setLemmaInputChannel(inputChannel); + d_smts[i]->channels()->setLemmaOutputChannel(outputChannel); } /* Output to string stream */ assert(d_ostringstreams.size() == 0); for(unsigned i = 0; i < d_numThreads; ++i) { d_ostringstreams.push_back(new ostringstream); - d_threadOptions[i].set(options::out, d_ostringstreams[i]); + d_threadOptions[i].setOut(d_ostringstreams[i]); + OutputLanguage outputLanguage = d_threadOptions[i].getOutputLanguage(); // important even for muzzled builds (to get result output right) - *d_threadOptions[i][options::out] - << language::SetLanguage(d_threadOptions[i][options::outputLanguage]); + *(d_threadOptions[i].getOut()) << language::SetLanguage(outputLanguage); } } }/* CommandExecutorPortfolio::lemmaSharingInit() */ void CommandExecutorPortfolio::lemmaSharingCleanup() { - assert(d_numThreads == d_options[options::threads]); + assert(d_numThreads == d_options.getThreads()); if(d_numThreads == 1) return; @@ -163,10 +160,10 @@ void CommandExecutorPortfolio::lemmaSharingCleanup() for(unsigned i = 0; i < d_numThreads; ++i) { delete d_channelsIn[i]; delete d_channelsOut[i]; - delete d_smts[i]->globals()->getLemmaInputChannel(); - d_smts[i]->globals()->setLemmaInputChannel(NULL); - delete d_smts[i]->globals()->getLemmaOutputChannel(); - d_smts[i]->globals()->setLemmaOutputChannel(NULL); + delete d_smts[i]->channels()->getLemmaInputChannel(); + d_smts[i]->channels()->setLemmaInputChannel(NULL); + delete d_smts[i]->channels()->getLemmaOutputChannel(); + d_smts[i]->channels()->setLemmaOutputChannel(NULL); } d_channelsIn.clear(); d_channelsOut.clear(); @@ -175,7 +172,7 @@ void CommandExecutorPortfolio::lemmaSharingCleanup() if(d_ostringstreams.size() != 0) { assert(d_ostringstreams.size() == d_numThreads); for(unsigned i = 0; i < d_numThreads; ++i) { - d_threadOptions[i].set(options::out, d_options[options::out]); + d_threadOptions[i].setOut(d_options.getOut()); delete d_ostringstreams[i]; } d_ostringstreams.clear(); @@ -225,9 +222,9 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd) Command* cmdExported = d_lastWinner == 0 ? cmd : cmd->exportTo(d_exprMgrs[d_lastWinner], *(d_vmaps[d_lastWinner]) ); - bool ret = smtEngineInvoke(d_smts[d_lastWinner], - cmdExported, - d_options[options::verbosity] >= -1 ? d_threadOptions[d_lastWinner][options::out] : NULL); + std::ostream* winnersOut = d_options.getVerbosity() >= -1 ? + (d_threadOptions[d_lastWinner]).getOut() : NULL; + bool ret = smtEngineInvoke(d_smts[d_lastWinner], cmdExported, winnersOut); if(d_lastWinner != 0) delete cmdExported; return ret; } else if(mode == 1) { // portfolio @@ -260,13 +257,15 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd) cmd->exportTo(d_exprMgrs[i], *(d_vmaps[i])) : d_seq->exportTo(d_exprMgrs[i], *(d_vmaps[i]) ); } catch(ExportUnsupportedException& e) { - if(d_options[options::fallbackSequential]) { - Notice() << "Unsupported theory encountered, switching to sequential mode."; + if(d_options.getFallbackSequential()) { + Notice() << "Unsupported theory encountered." + << "Switching to sequential mode."; return CommandExecutor::doCommandSingleton(cmd); } else - throw Exception("Certain theories (e.g., datatypes) are (currently) unsupported in portfolio\n" - "mode. Please see option --fallback-sequential to make this a soft error."); + throw Exception("Certain theories (e.g., datatypes) are (currently)" + " unsupported in portfolio\n mode. Please see option" + " --fallback-sequential to make this a soft error."); } } @@ -289,11 +288,11 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd) /* Portfolio */ boost::function* fns = new boost::function[d_numThreads]; for(unsigned i = 0; i < d_numThreads; ++i) { - fns[i] = boost::bind(smtEngineInvoke, - d_smts[i], - seqs[i], - d_options[options::verbosity] >= -1 ? d_threadOptions[i][options::out] : NULL - ); + std::ostream* current_out_or_null = d_options.getVerbosity() >= -1 ? + d_threadOptions[i].getOut() : NULL; + + fns[i] = boost::bind(smtEngineInvoke, d_smts[i], seqs[i], + current_out_or_null); } assert(d_channelsIn.size() == d_numThreads @@ -311,12 +310,12 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd) &d_channelsIn[0], &d_smts[0]); - size_t threadStackSize = d_options[options::threadStackSize]; + size_t threadStackSize = d_options.getThreadStackSize(); threadStackSize *= 1024 * 1024; pair portfolioReturn = runPortfolio(d_numThreads, smFn, fns, threadStackSize, - d_options[options::waitToJoin], d_statWaitTime); + d_options.getWaitToJoin(), d_statWaitTime); #ifdef CVC4_STATISTICS_ON assert( d_statWaitTime.running() ); @@ -327,25 +326,24 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd) d_result = d_smts[d_lastWinner]->getStatusOfLastCommand(); if(d_ostringstreams.size() != 0) { - assert(d_numThreads == d_options[options::threads]); + assert(d_numThreads == d_options.getThreads()); assert(portfolioReturn.first >= 0); assert(unsigned(portfolioReturn.first) < d_numThreads); + std::ostream& out = *d_options.getOut(); if(Debug.isOn("treat-unknown-error")) { if(d_ostringstreams[portfolioReturn.first]->str() == "unknown\n") { - *d_options[options::out] - << "portfolioReturn = (" << portfolioReturn.first << ", " << portfolioReturn.second - << ")\n"; + out << "portfolioReturn = (" << portfolioReturn.first << ", " + << portfolioReturn.second << ")\n"; for(unsigned i = 0; i < d_numThreads; ++i) - *d_options[options::out] - << "thread " << i << ": " << d_ostringstreams[i]->str() << std::endl; + out << "thread " << i << ": " << d_ostringstreams[i]->str() + << std::endl; throw Exception("unknown encountered"); } } - *d_options[options::out] - << d_ostringstreams[portfolioReturn.first]->str() - << std::flush; + out << d_ostringstreams[portfolioReturn.first]->str() + << std::flush; #ifdef CVC4_COMPETITION_MODE // We use CVC4 in competition with --no-wait-to-join. If @@ -366,27 +364,32 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd) // dump the model/proof/unsat core if option is set if(status) { - if( d_options[options::produceModels] && - d_options[options::dumpModels] && + if( d_options.getProduceModels() && + d_options.getDumpModels() && ( d_result.asSatisfiabilityResult() == Result::SAT || - (d_result.isUnknown() && d_result.whyUnknown() == Result::INCOMPLETE) ) ) { + (d_result.isUnknown() && + d_result.whyUnknown() == Result::INCOMPLETE) ) ) + { Command* gm = new GetModelCommand(); status = doCommandSingleton(gm); - } else if( d_options[options::proof] && - d_options[options::dumpProofs] && + } else if( d_options.getProof() && + d_options.getDumpProofs() && d_result.asSatisfiabilityResult() == Result::UNSAT ) { Command* gp = new GetProofCommand(); status = doCommandSingleton(gp); - } else if( d_options[options::dumpInstantiations] && - ( ( d_options[options::instFormatMode]!=INST_FORMAT_MODE_SZS && - ( d_result.asSatisfiabilityResult() == Result::SAT || (d_result.isUnknown() && d_result.whyUnknown() == Result::INCOMPLETE) ) ) || - d_result.asSatisfiabilityResult() == Result::UNSAT ) ) { + } else if( d_options.getDumpInstantiations() && + ( ( d_options.getInstFormatMode() != INST_FORMAT_MODE_SZS && + ( d_result.asSatisfiabilityResult() == Result::SAT || + (d_result.isUnknown() && + d_result.whyUnknown() == Result::INCOMPLETE) ) ) || + d_result.asSatisfiabilityResult() == Result::UNSAT ) ) { Command* gi = new GetInstantiationsCommand(); status = doCommandSingleton(gi); - } else if( d_options[options::dumpSynth] && d_result.asSatisfiabilityResult() == Result::UNSAT ){ + } else if( d_options.getDumpSynth() && + d_result.asSatisfiabilityResult() == Result::UNSAT ){ Command* gi = new GetSynthSolutionCommand(); status = doCommandSingleton(gi); - } else if( d_options[options::dumpUnsatCores] && + } else if( d_options.getDumpUnsatCores() && d_result.asSatisfiabilityResult() == Result::UNSAT ) { Command* guc = new GetUnsatCoreCommand(); status = doCommandSingleton(guc); @@ -395,13 +398,15 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd) return status; } else if(mode == 2) { - Command* cmdExported = - d_lastWinner == 0 ? - cmd : cmd->exportTo(d_exprMgrs[d_lastWinner], *(d_vmaps[d_lastWinner]) ); - bool ret = smtEngineInvoke(d_smts[d_lastWinner], - cmdExported, - d_options[options::verbosity] >= -1 ? d_threadOptions[d_lastWinner][options::out] : NULL); - if(d_lastWinner != 0) delete cmdExported; + Command* cmdExported = d_lastWinner == 0 ? + cmd : cmd->exportTo(d_exprMgrs[d_lastWinner], *(d_vmaps[d_lastWinner])); + std::ostream* winner_out_if_verbose = d_options.getVerbosity() >= -1 ? + d_threadOptions[d_lastWinner].getOut() : NULL; + bool ret = smtEngineInvoke(d_smts[d_lastWinner], cmdExported, + winner_out_if_verbose); + if(d_lastWinner != 0){ + delete cmdExported; + } return ret; } else { // Unreachable(); @@ -412,16 +417,17 @@ bool CommandExecutorPortfolio::doCommandSingleton(Command* cmd) }/* CommandExecutorPortfolio::doCommandSingleton() */ void CommandExecutorPortfolio::flushStatistics(std::ostream& out) const { - assert(d_numThreads == d_exprMgrs.size() && d_exprMgrs.size() == d_smts.size()); + assert(d_numThreads == d_exprMgrs.size() && + d_exprMgrs.size() == d_smts.size()); for(size_t i = 0; i < d_numThreads; ++i) { string emTag = "thread#" - + boost::lexical_cast(d_threadOptions[i][options::thread_id]); + + boost::lexical_cast(d_threadOptions[i].getThreadId()); Statistics stats = d_exprMgrs[i]->getStatistics(); stats.setPrefix(emTag); stats.flushInformation(out); string smtTag = "thread#" - + boost::lexical_cast(d_threadOptions[i][options::thread_id]); + + boost::lexical_cast(d_threadOptions[i].getThreadId()); stats = d_smts[i]->getStatistics(); stats.setPrefix(smtTag); stats.flushInformation(out); diff --git a/src/main/command_executor_portfolio.h b/src/main/command_executor_portfolio.h index ee2b270fb..ce9a80a4e 100644 --- a/src/main/command_executor_portfolio.h +++ b/src/main/command_executor_portfolio.h @@ -40,7 +40,7 @@ class CommandExecutorPortfolio : public CommandExecutor { // not too hard to support this changing std::vector d_smts; CommandSequence* d_seq; - std::vector& d_threadOptions; + OptionsList& d_threadOptions; std::vector d_vmaps; int d_lastWinner; @@ -57,7 +57,7 @@ class CommandExecutorPortfolio : public CommandExecutor { public: CommandExecutorPortfolio(ExprManager &exprMgr, Options &options, - std::vector& tOpts); + OptionsList& tOpts); ~CommandExecutorPortfolio(); diff --git a/src/main/driver_unified.cpp b/src/main/driver_unified.cpp index 71f47906d..83b85c170 100644 --- a/src/main/driver_unified.cpp +++ b/src/main/driver_unified.cpp @@ -25,6 +25,7 @@ // This must come before PORTFOLIO_BUILD. #include "cvc4autoconfig.h" +#include "base/configuration.h" #include "base/output.h" #include "expr/expr_iomanip.h" #include "expr/expr_manager.h" @@ -36,18 +37,12 @@ #include "main/interactive_shell.h" #include "main/main.h" -#include "options/base_options.h" -#include "options/main_options.h" #include "options/options.h" -#include "options/quantifiers_options.h" #include "options/set_language.h" -#include "options/smt_options.h" #include "parser/parser.h" #include "parser/parser_builder.h" #include "parser/parser_exception.h" -#include "smt/smt_options_handler.h" #include "smt_util/command.h" -#include "util/configuration.h" #include "util/result.h" #include "util/statistics_registry.h" @@ -79,47 +74,18 @@ namespace CVC4 { void printUsage(Options& opts, bool full) { stringstream ss; - ss << "usage: " << opts[options::binary_name] << " [options] [input-file]" << endl - << endl - << "Without an input file, or with `-', CVC4 reads from standard input." << endl - << endl - << "CVC4 options:" << endl; + ss << "usage: " << opts.getBinaryName() << " [options] [input-file]" + << endl << endl + << "Without an input file, or with `-', CVC4 reads from standard input." + << endl << endl + << "CVC4 options:" << endl; if(full) { - Options::printUsage( ss.str(), *opts[options::out] ); + Options::printUsage( ss.str(), *(opts.getOut()) ); } else { - Options::printShortUsage( ss.str(), *opts[options::out] ); + Options::printShortUsage( ss.str(), *(opts.getOut()) ); } } -void printStatsFilterZeros(std::ostream& out, const std::string& statsString) { - // read each line, if a number, check zero and skip if so - // Stat are assumed to one-per line: ", " - - std::istringstream iss(statsString); - std::string statName, statValue; - - std::getline(iss, statName, ','); - - while( !iss.eof() ) { - - std::getline(iss, statValue, '\n'); - - double curFloat; - bool isFloat = (std::istringstream(statValue) >> curFloat); - - if( (isFloat && curFloat == 0) || - statValue == " \"0\"" || - statValue == " \"[]\"") { - // skip - } else { - out << statName << "," << statValue << std::endl; - } - - std::getline(iss, statName, ','); - } - -} - int runCvc4(int argc, char* argv[], Options& opts) { // Timer statistic @@ -134,38 +100,35 @@ int runCvc4(int argc, char* argv[], Options& opts) { progPath = argv[0]; -#warning "TODO: Check that the SmtEngine pointer should be NULL with Kshitij." - smt::SmtOptionsHandler optionsHandler(NULL); - // Parse the options - vector filenames = opts.parseOptions(argc, argv, &optionsHandler); + vector filenames = opts.parseOptions(argc, argv); # ifndef PORTFOLIO_BUILD - if( opts.wasSetByUser(options::threads) || - opts.wasSetByUser(options::threadStackSize) || - ! opts[options::threadArgv].empty() ) { + if( opts.wasSetByUserThreads() || + opts.wasSetByUserThreadStackSize() || + (! opts.getThreadArgv().empty()) ) { throw OptionException("Thread options cannot be used with sequential CVC4. Please build and use the portfolio binary `pcvc4'."); } # endif - progName = opts[options::binary_name].c_str(); + progName = opts.getBinaryName().c_str(); - if( opts[options::help] ) { + if( opts.getHelp() ) { printUsage(opts, true); exit(1); - } else if( opts[options::languageHelp] ) { - Options::printLanguageHelp(*opts[options::out]); + } else if( opts.getLanguageHelp() ) { + Options::printLanguageHelp(*(opts.getOut())); exit(1); - } else if( opts[options::version] ) { - *opts[options::out] << Configuration::about().c_str() << flush; + } else if( opts.getVersion() ) { + *(opts.getOut()) << Configuration::about().c_str() << flush; exit(0); } - segvSpin = opts[options::segvSpin]; + segvSpin = opts.getSegvSpin(); // If in competition mode, set output stream option to flush immediately #ifdef CVC4_COMPETITION_MODE - *opts[options::out] << unitbuf; + *(opts.getOut()) << unitbuf; #endif /* CVC4_COMPETITION_MODE */ // We only accept one input file @@ -177,66 +140,66 @@ int runCvc4(int argc, char* argv[], Options& opts) { const bool inputFromStdin = filenames.empty() || filenames[0] == "-"; // if we're reading from stdin on a TTY, default to interactive mode - if(!opts.wasSetByUser(options::interactive)) { - opts.set(options::interactive, inputFromStdin && isatty(fileno(stdin))); + if(!opts.wasSetByUserInteractive()) { + opts.setInteractive(inputFromStdin && isatty(fileno(stdin))); } // Auto-detect input language by filename extension const char* filename = inputFromStdin ? "" : filenames[0].c_str(); - if(opts[options::inputLanguage] == language::input::LANG_AUTO) { + if(opts.getInputLanguage() == language::input::LANG_AUTO) { if( inputFromStdin ) { // We can't do any fancy detection on stdin - opts.set(options::inputLanguage, language::input::LANG_CVC4); + opts.setInputLanguage(language::input::LANG_CVC4); } else { unsigned len = strlen(filename); if(len >= 5 && !strcmp(".smt2", filename + len - 5)) { - opts.set(options::inputLanguage, language::input::LANG_SMTLIB_V2_0); + opts.setInputLanguage(language::input::LANG_SMTLIB_V2_0); } else if(len >= 4 && !strcmp(".smt", filename + len - 4)) { - opts.set(options::inputLanguage, language::input::LANG_SMTLIB_V1); + opts.setInputLanguage(language::input::LANG_SMTLIB_V1); } else if(len >= 5 && !strcmp(".smt1", filename + len - 5)) { - opts.set(options::inputLanguage, language::input::LANG_SMTLIB_V1); + opts.setInputLanguage(language::input::LANG_SMTLIB_V1); } else if((len >= 2 && !strcmp(".p", filename + len - 2)) || (len >= 5 && !strcmp(".tptp", filename + len - 5))) { - opts.set(options::inputLanguage, language::input::LANG_TPTP); + opts.setInputLanguage(language::input::LANG_TPTP); } else if(( len >= 4 && !strcmp(".cvc", filename + len - 4) ) || ( len >= 5 && !strcmp(".cvc4", filename + len - 5) )) { - opts.set(options::inputLanguage, language::input::LANG_CVC4); + opts.setInputLanguage(language::input::LANG_CVC4); } else if((len >= 3 && !strcmp(".sy", filename + len - 3)) || (len >= 3 && !strcmp(".sl", filename + len - 3))) { - opts.set(options::inputLanguage, language::input::LANG_SYGUS); + opts.setInputLanguage(language::input::LANG_SYGUS); //since there is no sygus output language, set this to SMT lib 2 - //opts.set(options::outputLanguage, language::output::LANG_SMTLIB_V2_0); + //opts.setOutputLanguage(language::output::LANG_SMTLIB_V2_0); } } } - if(opts[options::outputLanguage] == language::output::LANG_AUTO) { - opts.set(options::outputLanguage, language::toOutputLanguage(opts[options::inputLanguage])); + if(opts.getOutputLanguage() == language::output::LANG_AUTO) { + opts.setOutputLanguage(language::toOutputLanguage(opts.getInputLanguage())); } // if doing sygus, turn on CEGQI by default - if(opts[options::inputLanguage] == language::input::LANG_SYGUS ){ - if( !opts.wasSetByUser(options::ceGuidedInst)) { - opts.set(options::ceGuidedInst, true); + if(opts.getInputLanguage() == language::input::LANG_SYGUS ){ + if( !opts.wasSetByUserCeGuidedInst()) { + opts.setCeGuidedInst(true); } - if( !opts.wasSetByUser(options::dumpSynth)) { - opts.set(options::dumpSynth, true); + if( !opts.wasSetByUserDumpSynth()) { + opts.setDumpSynth(true); } } // Determine which messages to show based on smtcomp_mode and verbosity if(Configuration::isMuzzledBuild()) { - DebugChannel.setStream(CVC4::null_os); - TraceChannel.setStream(CVC4::null_os); - NoticeChannel.setStream(CVC4::null_os); - ChatChannel.setStream(CVC4::null_os); - MessageChannel.setStream(CVC4::null_os); - WarningChannel.setStream(CVC4::null_os); + DebugChannel.setStream(&CVC4::null_os); + TraceChannel.setStream(&CVC4::null_os); + NoticeChannel.setStream(&CVC4::null_os); + ChatChannel.setStream(&CVC4::null_os); + MessageChannel.setStream(&CVC4::null_os); + WarningChannel.setStream(&CVC4::null_os); } // important even for muzzled builds (to get result output right) - *opts[options::out] << language::SetLanguage(opts[options::outputLanguage]); + (*(opts.getOut())) << language::SetLanguage(opts.getOutputLanguage()); // Create the expression manager using appropriate options ExprManager* exprMgr; @@ -244,20 +207,24 @@ int runCvc4(int argc, char* argv[], Options& opts) { exprMgr = new ExprManager(opts); pExecutor = new CommandExecutor(*exprMgr, opts); # else - vector threadOpts = parseThreadSpecificOptions(opts); + OptionsList threadOpts; + parseThreadSpecificOptions(threadOpts, opts); + bool useParallelExecutor = true; // incremental? - if(opts.wasSetByUser(options::incrementalSolving) && - opts[options::incrementalSolving] && - !opts[options::incrementalParallel]) { - Notice() << "Notice: In --incremental mode, using the sequential solver unless forced by...\n" + if(opts.wasSetByUserIncrementalSolving() && + opts.getIncrementalSolving() && + (! opts.getIncrementalParallel()) ) { + Notice() << "Notice: In --incremental mode, using the sequential solver" + << " unless forced by...\n" << "Notice: ...the experimental --incremental-parallel option.\n"; useParallelExecutor = false; } // proofs? - if(opts[options::checkProofs]) { - if(opts[options::fallbackSequential]) { - Warning() << "Warning: Falling back to sequential mode, as cannot run portfolio in check-proofs mode.\n"; + if(opts.getCheckProofs()) { + if(opts.getFallbackSequential()) { + Warning() << "Warning: Falling back to sequential mode, as cannot run" + << " portfolio in check-proofs mode.\n"; useParallelExecutor = false; } else { @@ -275,41 +242,41 @@ int runCvc4(int argc, char* argv[], Options& opts) { # endif Parser* replayParser = NULL; - if( opts[options::replayFilename] != "" ) { - ParserBuilder replayParserBuilder(exprMgr, opts[options::replayFilename], opts); + if( opts.getReplayInputFilename() != "" ) { + std::string replayFilename = opts.getReplayInputFilename(); + ParserBuilder replayParserBuilder(exprMgr, replayFilename, opts); - if( opts[options::replayFilename] == "-") { + if( replayFilename == "-") { if( inputFromStdin ) { throw OptionException("Replay file and input file can't both be stdin."); } replayParserBuilder.withStreamInput(cin); } replayParser = replayParserBuilder.build(); - pExecutor->globals()->setReplayStream(new Parser::ExprStream(replayParser)); - } - if( pExecutor->globals()->getReplayLog() != NULL ) { - *(pExecutor->globals()->getReplayLog()) << - language::SetLanguage(opts[options::outputLanguage]) << expr::ExprSetDepth(-1); + pExecutor->setReplayStream(new Parser::ExprStream(replayParser)); } int returnValue = 0; { // Timer statistic - RegisterStatistic statTotalTime(&pExecutor->getStatisticsRegistry(), pTotalTime); + RegisterStatistic statTotalTime(&pExecutor->getStatisticsRegistry(), + pTotalTime); // Filename statistics ReferenceStat< const char* > s_statFilename("filename", filename); - RegisterStatistic statFilenameReg(&pExecutor->getStatisticsRegistry(), &s_statFilename); + RegisterStatistic statFilenameReg(&pExecutor->getStatisticsRegistry(), + &s_statFilename); // Parse and execute commands until we are done Command* cmd; bool status = true; - if(opts[options::interactive] && inputFromStdin) { - if(opts[options::tearDownIncremental] > 0) { - throw OptionException("--tear-down-incremental doesn't work in interactive mode"); + if(opts.getInteractive() && inputFromStdin) { + if(opts.getTearDownIncremental() > 0) { + throw OptionException( + "--tear-down-incremental doesn't work in interactive mode"); } #ifndef PORTFOLIO_BUILD - if(!opts.wasSetByUser(options::incrementalSolving)) { + if(!opts.wasSetByUserIncrementalSolving()) { cmd = new SetOptionCommand("incremental", SExpr(true)); cmd->setMuted(true); pExecutor->doCommand(cmd); @@ -317,7 +284,7 @@ int runCvc4(int argc, char* argv[], Options& opts) { } #endif /* PORTFOLIO_BUILD */ InteractiveShell shell(*exprMgr, opts); - if(opts[options::interactivePrompt]) { + if(opts.getInteractivePrompt()) { Message() << Configuration::getPackageName() << " " << Configuration::getVersionString(); if(Configuration::isGitBuild()) { @@ -339,7 +306,7 @@ int runCvc4(int argc, char* argv[], Options& opts) { try { cmd = shell.readCommand(); } catch(UnsafeInterruptException& e) { - *opts[options::out] << CommandInterrupted(); + (*opts.getOut()) << CommandInterrupted(); break; } if (cmd == NULL) @@ -351,14 +318,15 @@ int runCvc4(int argc, char* argv[], Options& opts) { } delete cmd; } - } else if(opts[options::tearDownIncremental] > 0) { - if(!opts[options::incrementalSolving]) { + } else if( opts.getTearDownIncremental() > 0) { + if(!opts.getIncrementalSolving()) { cmd = new SetOptionCommand("incremental", SExpr(true)); cmd->setMuted(true); pExecutor->doCommand(cmd); delete cmd; - // if(opts.wasSetByUser(options::incrementalSolving)) { - // throw OptionException("--tear-down-incremental incompatible with --incremental"); + // if(opts.wasSetByUserIncrementalSolving()) { + // throw OptionException( + // "--tear-down-incremental incompatible with --incremental"); // } // cmd = new SetOptionCommand("incremental", SExpr(false)); @@ -387,9 +355,9 @@ int runCvc4(int argc, char* argv[], Options& opts) { int needReset = 0; // true if one of the commands was interrupted bool interrupted = false; - while (status || opts[options::continuedExecution]) { + while (status || opts.getContinuedExecution()) { if (interrupted) { - *opts[options::out] << CommandInterrupted(); + (*opts.getOut()) << CommandInterrupted(); break; } @@ -402,11 +370,12 @@ int runCvc4(int argc, char* argv[], Options& opts) { } if(dynamic_cast(cmd) != NULL) { - if(needReset >= opts[options::tearDownIncremental]) { + if(needReset >= opts.getTearDownIncremental()) { pExecutor->reset(); for(size_t i = 0; i < allCommands.size() && !interrupted; ++i) { if (interrupted) break; - for(size_t j = 0; j < allCommands[i].size() && !interrupted; ++j) { + for(size_t j = 0; j < allCommands[i].size() && !interrupted; ++j) + { Command* cmd = allCommands[i][j]->clone(); cmd->setMuted(true); pExecutor->doCommand(cmd); @@ -428,10 +397,11 @@ int runCvc4(int argc, char* argv[], Options& opts) { } } else if(dynamic_cast(cmd) != NULL) { allCommands.pop_back(); // fixme leaks cmds here - if (needReset >= opts[options::tearDownIncremental]) { + if (needReset >= opts.getTearDownIncremental()) { pExecutor->reset(); for(size_t i = 0; i < allCommands.size() && !interrupted; ++i) { - for(size_t j = 0; j < allCommands[i].size() && !interrupted; ++j) { + for(size_t j = 0; j < allCommands[i].size() && !interrupted; ++j) + { Command* cmd = allCommands[i][j]->clone(); cmd->setMuted(true); pExecutor->doCommand(cmd); @@ -442,7 +412,7 @@ int runCvc4(int argc, char* argv[], Options& opts) { } } if (interrupted) continue; - *opts[options::out] << CommandSuccess(); + (*opts.getOut()) << CommandSuccess(); needReset = 0; } else { status = pExecutor->doCommand(cmd); @@ -453,10 +423,11 @@ int runCvc4(int argc, char* argv[], Options& opts) { } } else if(dynamic_cast(cmd) != NULL || dynamic_cast(cmd) != NULL) { - if(needReset >= opts[options::tearDownIncremental]) { + if(needReset >= opts.getTearDownIncremental()) { pExecutor->reset(); for(size_t i = 0; i < allCommands.size() && !interrupted; ++i) { - for(size_t j = 0; j < allCommands[i].size() && !interrupted; ++j) { + for(size_t j = 0; j < allCommands[i].size() && !interrupted; ++j) + { Command* cmd = allCommands[i][j]->clone(); cmd->setMuted(true); pExecutor->doCommand(cmd); @@ -516,7 +487,7 @@ int runCvc4(int argc, char* argv[], Options& opts) { // Remove the parser delete parser; } else { - if(!opts.wasSetByUser(options::incrementalSolving)) { + if(!opts.wasSetByUserIncrementalSolving()) { cmd = new SetOptionCommand("incremental", SExpr(false)); cmd->setMuted(true); pExecutor->doCommand(cmd); @@ -539,9 +510,9 @@ int runCvc4(int argc, char* argv[], Options& opts) { replayParser->useDeclarationsFrom(parser); } bool interrupted = false; - while(status || opts[options::continuedExecution]) { + while(status || opts.getContinuedExecution()) { if (interrupted) { - *opts[options::out] << CommandInterrupted(); + (*opts.getOut()) << CommandInterrupted(); pExecutor->reset(); break; } @@ -569,13 +540,6 @@ int runCvc4(int argc, char* argv[], Options& opts) { delete parser; } - if( pExecutor->globals()->getReplayStream() != NULL ) { - ExprStream* replayStream = pExecutor->globals()->getReplayStream(); - pExecutor->globals()->setReplayStream(NULL); - // this deletes the expression parser too - delete replayStream; - } - Result result; if(status) { result = pExecutor->getResult(); @@ -586,7 +550,7 @@ int runCvc4(int argc, char* argv[], Options& opts) { } #ifdef CVC4_COMPETITION_MODE - *opts[options::out] << flush; + opts.flushOut(); // exit, don't return (don't want destructors to run) // _exit() from unistd.h doesn't run global destructors // or other on_exit/atexit stuff. @@ -594,37 +558,22 @@ int runCvc4(int argc, char* argv[], Options& opts) { #endif /* CVC4_COMPETITION_MODE */ ReferenceStat< Result > s_statSatResult("sat/unsat", result); - RegisterStatistic statSatResultReg(&pExecutor->getStatisticsRegistry(), &s_statSatResult); + RegisterStatistic statSatResultReg(&pExecutor->getStatisticsRegistry(), + &s_statSatResult); pTotalTime->stop(); + // Tim: I think that following comment is out of date? // Set the global executor pointer to NULL first. If we get a // signal while dumping statistics, we don't want to try again. - if(opts[options::statistics]) { - if(opts[options::statsHideZeros] == false) { - pExecutor->flushStatistics(*opts[options::err]); - } else { - std::ostringstream ossStats; - pExecutor->flushStatistics(ossStats); - printStatsFilterZeros(*opts[options::err], ossStats.str()); - } - } - - // make sure to flush replay output log before early-exit - if( pExecutor->globals()->getReplayLog() != NULL ) { - *(pExecutor->globals()->getReplayLog()) << flush; - } - - // make sure out and err streams are flushed too - *opts[options::out] << flush; - *opts[options::err] << flush; + pExecutor->flushOutputStreams(); #ifdef CVC4_DEBUG - if(opts[options::earlyExit] && opts.wasSetByUser(options::earlyExit)) { + if(opts.getEarlyExit() && opts.wasSetByUserEarlyExit()) { _exit(returnValue); } #else /* CVC4_DEBUG */ - if(opts[options::earlyExit]) { + if(opts.getEarlyExit()) { _exit(returnValue); } #endif /* CVC4_DEBUG */ diff --git a/src/main/interactive_shell.cpp b/src/main/interactive_shell.cpp index 6888d3af5..19e4859b0 100644 --- a/src/main/interactive_shell.cpp +++ b/src/main/interactive_shell.cpp @@ -40,10 +40,7 @@ #include "base/output.h" #include "options/language.h" -#include "options/base_options.h" -#include "options/main_options.h" #include "options/options.h" -#include "options/smt_options.h" #include "parser/input.h" #include "parser/parser.h" #include "parser/parser_builder.h" @@ -92,16 +89,18 @@ static set s_declarations; #endif /* HAVE_LIBREADLINE */ InteractiveShell::InteractiveShell(ExprManager& exprManager, - const Options& options) : - d_in(*options[options::in]), - d_out(*options[options::out]), - d_options(options), - d_quit(false) { + const Options& options) + : d_in(*options.getIn()), + d_out(*options.getOutConst()), + d_options(options), + d_quit(false) +{ ParserBuilder parserBuilder(&exprManager, INPUT_FILENAME, options); /* Create parser with bogus input. */ d_parser = parserBuilder.withStringInput("").build(); - if(d_options.wasSetByUser(options::forceLogic)) { - d_parser->forceLogic(d_options[options::forceLogic]->getLogicString()); + if(d_options.wasSetByUserForceLogicString()) { + LogicInfo tmp(d_options.getForceLogicString()); + d_parser->forceLogic(tmp.getLogicString()); } #if HAVE_LIBREADLINE @@ -114,7 +113,8 @@ InteractiveShell::InteractiveShell(ExprManager& exprManager, #endif /* READLINE_COMPENTRY_FUNC_RETURNS_CHARP */ ::using_history(); - switch(OutputLanguage lang = toOutputLanguage(d_options[options::inputLanguage])) { + OutputLanguage lang = toOutputLanguage(d_options.getInputLanguage()); + switch(lang) { case output::LANG_CVC4: d_historyFilename = string(getenv("HOME")) + "/.cvc4_history"; commandsBegin = cvc_commands; @@ -195,7 +195,8 @@ restart: /* Prompt the user for input. */ if(d_usingReadline) { #if HAVE_LIBREADLINE - lineBuf = ::readline(d_options[options::interactivePrompt] ? (line == "" ? "CVC4> " : "... > ") : ""); + lineBuf = ::readline(d_options.getInteractivePrompt() + ? (line == "" ? "CVC4> " : "... > ") : ""); if(lineBuf != NULL && lineBuf[0] != '\0') { ::add_history(lineBuf); } @@ -203,7 +204,7 @@ restart: free(lineBuf); #endif /* HAVE_LIBREADLINE */ } else { - if(d_options[options::interactivePrompt]) { + if(d_options.getInteractivePrompt()) { if(line == "") { d_out << "CVC4> " << flush; } else { @@ -219,7 +220,8 @@ restart: string input = ""; while(true) { - Debug("interactive") << "Input now '" << input << line << "'" << endl << flush; + Debug("interactive") << "Input now '" << input << line << "'" << endl + << flush; assert( !(d_in.fail() && !d_in.eof()) || line.empty() ); @@ -260,7 +262,8 @@ restart: /* Extract the newline delimiter from the stream too */ int c CVC4_UNUSED = d_in.get(); assert(c == '\n'); - Debug("interactive") << "Next char is '" << (char)c << "'" << endl << flush; + Debug("interactive") << "Next char is '" << (char)c << "'" << endl + << flush; } input += line; @@ -271,7 +274,7 @@ restart: input[n] = '\n'; if(d_usingReadline) { #if HAVE_LIBREADLINE - lineBuf = ::readline(d_options[options::interactivePrompt] ? "... > " : ""); + lineBuf = ::readline(d_options.getInteractivePrompt() ? "... > " : ""); if(lineBuf != NULL && lineBuf[0] != '\0') { ::add_history(lineBuf); } @@ -279,7 +282,7 @@ restart: free(lineBuf); #endif /* HAVE_LIBREADLINE */ } else { - if(d_options[options::interactivePrompt]) { + if(d_options.getInteractivePrompt()) { d_out << "... > " << flush; } @@ -295,7 +298,8 @@ restart: } } - d_parser->setInput(Input::newStringInput(d_options[options::inputLanguage], input, INPUT_FILENAME)); + d_parser->setInput(Input::newStringInput(d_options.getInputLanguage(), + input, INPUT_FILENAME)); /* There may be more than one command in the input. Build up a sequence. */ @@ -326,8 +330,8 @@ restart: line += "\n"; goto restart; } catch(ParserException& pe) { - if(d_options[options::outputLanguage] == output::LANG_SMTLIB_V2_0 || - d_options[options::outputLanguage] == output::LANG_SMTLIB_V2_5) { + if(d_options.getOutputLanguage() == output::LANG_SMTLIB_V2_0 || + d_options.getOutputLanguage() == output::LANG_SMTLIB_V2_5) { d_out << "(error \"" << pe << "\")" << endl; } else { d_out << pe << endl; diff --git a/src/main/main.cpp b/src/main/main.cpp index 92902ac11..9151d8bf7 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -22,19 +22,18 @@ #include #include +#include "base/configuration.h" #include "base/output.h" #include "expr/expr_manager.h" #include "main/command_executor.h" #include "main/interactive_shell.h" -#include "options/base_options.h" #include "options/language.h" -#include "options/main_options.h" +#include "options/options.h" #include "parser/parser.h" #include "parser/parser_builder.h" #include "parser/parser_exception.h" #include "smt/smt_engine.h" #include "smt_util/command.h" -#include "util/configuration.h" #include "util/result.h" #include "util/statistics.h" @@ -56,24 +55,24 @@ int main(int argc, char* argv[]) { return runCvc4(argc, argv, opts); } catch(OptionException& e) { #ifdef CVC4_COMPETITION_MODE - *opts[options::out] << "unknown" << endl; + *opts.getOut() << "unknown" << endl; #endif cerr << "CVC4 Error:" << endl << e << endl << endl << "Please use --help to get help on command-line options." << endl; } catch(Exception& e) { #ifdef CVC4_COMPETITION_MODE - *opts[options::out] << "unknown" << endl; + *opts.getOut() << "unknown" << endl; #endif - if(opts[options::outputLanguage] == output::LANG_SMTLIB_V2_0 || - opts[options::outputLanguage] == output::LANG_SMTLIB_V2_5) { - *opts[options::out] << "(error \"" << e << "\")" << endl; + if(opts.getOutputLanguage() == output::LANG_SMTLIB_V2_0 || + opts.getOutputLanguage() == output::LANG_SMTLIB_V2_5) { + *opts.getOut() << "(error \"" << e << "\")" << endl; } else { - *opts[options::err] << "CVC4 Error:" << endl << e << endl; + *opts.getErr() << "CVC4 Error:" << endl << e << endl; } - if(opts[options::statistics] && pExecutor != NULL) { + if(opts.getStatistics() && pExecutor != NULL) { pTotalTime->stop(); - pExecutor->flushStatistics(*opts[options::err]); + pExecutor->flushStatistics(*opts.getErr()); } } exit(1); diff --git a/src/main/portfolio_util.cpp b/src/main/portfolio_util.cpp index 1ec0b961c..e42787fea 100644 --- a/src/main/portfolio_util.cpp +++ b/src/main/portfolio_util.cpp @@ -19,45 +19,68 @@ #include #include -#include "options/base_options.h" -#include "options/main_options.h" #include "options/options.h" -#include "options/prop_options.h" -#include "options/smt_options.h" -#include "smt/smt_options_handler.h" using namespace std; namespace CVC4 { -vector parseThreadSpecificOptions(Options opts) -{ - vector threadOptions; +OptionsList::OptionsList() : d_options() {} + +OptionsList::~OptionsList(){ + for(std::vector::iterator i = d_options.begin(), + iend = d_options.end(); i != iend; ++i) + { + Options* current = *i; + delete current; + } + d_options.clear(); +} + +void OptionsList::push_back_copy(const Options& opts) { + Options* copy = new Options; + copy->copyValues(opts); + d_options.push_back(copy); +} + +Options& OptionsList::operator[](size_t position){ + return *(d_options[position]); +} + +const Options& OptionsList::operator[](size_t position) const { + return *(d_options[position]); +} -#warning "TODO: Check that the SmtEngine pointer should be NULL with Kshitij." - smt::SmtOptionsHandler optionsHandler(NULL); +Options& OptionsList::back() { + return *(d_options.back()); +} - unsigned numThreads = opts[options::threads]; +size_t OptionsList::size() const { + return d_options.size(); +} + +void parseThreadSpecificOptions(OptionsList& threadOptions, const Options& opts) +{ + + unsigned numThreads = opts.getThreads(); for(unsigned i = 0; i < numThreads; ++i) { - threadOptions.push_back(opts); + threadOptions.push_back_copy(opts); Options& tOpts = threadOptions.back(); // Set thread identifier - tOpts.set(options::thread_id, i); - - if(i < opts[options::threadArgv].size() && - !opts[options::threadArgv][i].empty()) { - + tOpts.setThreadId(i); + const std::vector& optThreadArgvs = opts.getThreadArgv(); + if(i < optThreadArgvs.size() && (! optThreadArgvs[i].empty())) { // separate out the thread's individual configuration string stringstream optidss; optidss << "--thread" << i; string optid = optidss.str(); int targc = 1; - char* tbuf = strdup(opts[options::threadArgv][i].c_str()); + char* tbuf = strdup(optThreadArgvs[i].c_str()); char* p = tbuf; // string length is certainly an upper bound on size needed - char** targv = new char*[opts[options::threadArgv][i].size()]; + char** targv = new char*[optThreadArgvs[i].size()]; char** vp = targv; *vp++ = strdup(optid.c_str()); p = strtok(p, " "); @@ -69,7 +92,7 @@ vector parseThreadSpecificOptions(Options opts) *vp++ = NULL; if(targc > 1) { // this is necessary in case you do e.g. --thread0=" " try { - tOpts.parseOptions(targc, targv, &optionsHandler); + tOpts.parseOptions(targc, targv); } catch(OptionException& e) { stringstream ss; ss << optid << ": " << e.getMessage(); @@ -81,8 +104,8 @@ vector parseThreadSpecificOptions(Options opts) << "' in thread configuration " << optid << " !"; throw OptionException(ss.str()); } - if(tOpts[options::threads] != numThreads - || tOpts[options::threadArgv] != opts[options::threadArgv]) { + if(tOpts.getThreads() != numThreads || + tOpts.getThreadArgv() != opts.getThreadArgv()) { stringstream ss; ss << "not allowed to set thread options in " << optid << " !"; throw OptionException(ss.str()); @@ -95,12 +118,10 @@ vector parseThreadSpecificOptions(Options opts) } assert(numThreads >= 1); //do we need this? - - return threadOptions; } void PortfolioLemmaOutputChannel::notifyNewLemma(Expr lemma) { - if(int(lemma.getNumChildren()) > options::sharingFilterByLength()) { + if(int(lemma.getNumChildren()) > Options::currentGetSharingFilterByLength()) { return; } ++cnt; @@ -109,9 +130,9 @@ void PortfolioLemmaOutputChannel::notifyNewLemma(Expr lemma) { try { d_pickler.toPickle(lemma, pkl); d_sharedChannel->push(pkl); - if(Trace.isOn("showSharing") && options::thread_id() == 0) { - *options::out() << "thread #0: notifyNewLemma: " << lemma - << std::endl; + if(Trace.isOn("showSharing") && Options::currentGetThreadId() == 0) { + (*(Options::currentGetOut())) + << "thread #0: notifyNewLemma: " << lemma << std::endl; } } catch(expr::pickle::PicklingException& p){ Trace("sharing::blocked") << lemma << std::endl; @@ -137,8 +158,8 @@ Expr PortfolioLemmaInputChannel::getNewLemma() { expr::pickle::Pickle pkl = d_sharedChannel->pop(); Expr e = d_pickler.fromPickle(pkl); - if(Trace.isOn("showSharing") && options::thread_id() == 0) { - *options::out() << "thread #0: getNewLemma: " << e << std::endl; + if(Trace.isOn("showSharing") && Options::currentGetThreadId() == 0) { + (*Options::currentGetOut()) << "thread #0: getNewLemma: " << e << std::endl; } return e; } diff --git a/src/main/portfolio_util.h b/src/main/portfolio_util.h index 2b1e22754..50cf0060a 100644 --- a/src/main/portfolio_util.h +++ b/src/main/portfolio_util.h @@ -19,7 +19,6 @@ #include "base/output.h" #include "expr/pickler.h" -#include "options/main_options.h" #include "smt/smt_engine.h" #include "smt_util/lemma_input_channel.h" #include "smt_util/lemma_output_channel.h" @@ -73,7 +72,26 @@ public: };/* class PortfolioLemmaInputChannel */ -std::vector parseThreadSpecificOptions(Options opts); +class OptionsList { + public: + OptionsList(); + ~OptionsList(); + + void push_back_copy(const Options& options); + + Options& operator[](size_t position); + const Options& operator[](size_t position) const; + + Options& back(); + + size_t size() const; + private: + OptionsList(const OptionsList&) CVC4_UNDEFINED; + OptionsList& operator=(const OptionsList&) CVC4_UNDEFINED; + std::vector d_options; +}; + +void parseThreadSpecificOptions(OptionsList& list, const Options& opts); template void sharingManager(unsigned numThreads, diff --git a/src/main/util.cpp b/src/main/util.cpp index abcdcc7c5..71b46e67a 100644 --- a/src/main/util.cpp +++ b/src/main/util.cpp @@ -33,7 +33,6 @@ #include "cvc4autoconfig.h" #include "main/command_executor.h" #include "main/main.h" -#include "options/base_options.h" #include "options/options.h" #include "smt/smt_engine.h" #include "util/statistics.h" @@ -42,11 +41,6 @@ using CVC4::Exception; using namespace std; namespace CVC4 { - -#ifdef CVC4_DEBUG -//extern CVC4_THREADLOCAL(const char*) s_debugLastException; -#endif /* CVC4_DEBUG */ - namespace main { /** @@ -64,7 +58,7 @@ void* cvc4StackBase; /** Handler for SIGXCPU, i.e., timeout. */ void timeout_handler(int sig, siginfo_t* info, void*) { fprintf(stderr, "CVC4 interrupted by timeout.\n"); - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -74,7 +68,7 @@ void timeout_handler(int sig, siginfo_t* info, void*) { /** Handler for SIGINT, i.e., when the user hits control C. */ void sigint_handler(int sig, siginfo_t* info, void*) { fprintf(stderr, "CVC4 interrupted by user.\n"); - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -99,7 +93,7 @@ void segv_handler(int sig, siginfo_t* info, void* c) { } if(!segvSpin) { - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -121,7 +115,7 @@ void segv_handler(int sig, siginfo_t* info, void* c) { } else if(addr < 10*1024) { cerr << "Looks like a NULL pointer was dereferenced." << endl; } - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -134,7 +128,7 @@ void ill_handler(int sig, siginfo_t* info, void*) { #ifdef CVC4_DEBUG fprintf(stderr, "CVC4 executed an illegal instruction in DEBUG mode.\n"); if(!segvSpin) { - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -149,7 +143,7 @@ void ill_handler(int sig, siginfo_t* info, void*) { } #else /* CVC4_DEBUG */ fprintf(stderr, "CVC4 executed an illegal instruction.\n"); - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -177,7 +171,7 @@ void cvc4unexpected() { fprintf(stderr, "The exception is:\n%s\n\n", lastContents); } if(!segvSpin) { - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -192,7 +186,7 @@ void cvc4unexpected() { } #else /* CVC4_DEBUG */ fprintf(stderr, "CVC4 threw an \"unexpected\" exception.\n"); - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -211,7 +205,7 @@ void cvc4terminate() { "CVC4 was terminated by the C++ runtime.\n" "Perhaps an exception was thrown during stack unwinding. " "(Don't do that.)\n"); - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } @@ -220,7 +214,7 @@ void cvc4terminate() { fprintf(stderr, "CVC4 was terminated by the C++ runtime.\n" "Perhaps an exception was thrown during stack unwinding.\n"); - if((*pOptions)[options::statistics] && pExecutor != NULL) { + if(pOptions->getStatistics() && pExecutor != NULL) { pTotalTime->stop(); pExecutor->flushStatistics(cerr); } diff --git a/src/options/Makefile.am b/src/options/Makefile.am index cf38708e1..8a465c522 100644 --- a/src/options/Makefile.am +++ b/src/options/Makefile.am @@ -162,16 +162,16 @@ CPP_TEMPLATE_FILES = \ base_options_template.cpp \ options_holder_template.h \ options_template.cpp \ - options_handler_get_option_template.cpp \ - options_handler_set_option_template.cpp + options_get_option_template.cpp \ + options_set_option_template.cpp CPP_TEMPLATE_SEDS = \ base_options_template.h.sed \ base_options_template.cpp.sed \ options_holder_template.h.sed \ options_template.cpp.sed \ - options_handler_get_option_template.cpp.sed \ - options_handler_set_option_template.cpp.sed + options_get_option_template.cpp.sed \ + options_set_option_template.cpp.sed DOCUMENTATION_FILES = \ @@ -206,6 +206,8 @@ liboptions_la_SOURCES = \ arith_propagation_mode.h \ arith_unate_lemma_mode.cpp \ arith_unate_lemma_mode.h \ + argument_extender.cpp \ + argument_extender.h \ base_handlers.h \ boolean_term_conversion_mode.cpp \ boolean_term_conversion_mode.h \ @@ -218,11 +220,13 @@ liboptions_la_SOURCES = \ didyoumean.h \ language.cpp \ language.h \ - logic_info_forward.h \ + open_ostream.cpp \ + open_ostream.h \ option_exception.h \ options.h \ - options_handler_interface.cpp \ - options_handler_interface.h \ + options_handler.cpp \ + options_handler.h \ + options_public_functions.cpp \ printer_modes.cpp \ printer_modes.h \ quantifiers_modes.cpp \ @@ -241,8 +245,8 @@ nodist_liboptions_la_SOURCES = \ options_holder.h \ $(OPTIONS_HEADS) \ $(OPTIONS_CPPS) \ - options_handler_get_option.cpp \ - options_handler_set_option.cpp + options_get_option.cpp \ + options_set_option.cpp BUILT_SOURCES = \ @@ -254,20 +258,11 @@ BUILT_SOURCES = \ $(OPTIONS_OPTIONS_FILES) \ $(OPTIONS_SEDS) \ options.cpp \ - options_handler_get_option.cpp \ - options_handler_set_option.cpp \ + options_get_option.cpp \ + options_set_option.cpp \ options_holder.h \ summary.sed -# listing {Debug,Trace}_tags too ensures that make doesn't auto-remove it -# after building (if it does, we don't get the "cached" effect with -# the .tmp files below, and we have to re-compile and re-link each -# time, even when there are no changes). -BUILT_SOURCES += \ - Debug_tags.h \ - Debug_tags \ - Trace_tags.h \ - Trace_tags CLEANFILES = \ $(BUILT_SOURCES) \ @@ -283,47 +278,19 @@ EXTRA_DIST = \ base_options_template.h \ language.i \ mkoptions \ - mktagheaders \ - mktags \ option_exception.i \ options.i \ - options_handler_get_option_template.cpp \ - options_handler_interface.i \ - options_handler_set_option_template.cpp \ + options_get_option_template.cpp \ options_holder_template.h \ + options_set_option_template.cpp \ options_template.cpp -%_tags.h: %_tags mktagheaders - $(AM_V_at)chmod +x @srcdir@/mktagheaders - $(AM_V_GEN)( @srcdir@/mktagheaders "$<" "$<" ) >"$@" -# This .tmp business is to keep from having to re-compile options.cpp -# (and then re-link the libraries) if nothing has changed. -%_tags: %_tags.tmp - $(AM_V_GEN)\ - diff -q "$^" "$@" &>/dev/null || mv "$^" "$@" || true -# .PHONY ensures the .tmp version is always rebuilt (to check for any changes) -.PHONY: Debug_tags.tmp Trace_tags.tmp -# The "sed" invocation below is particularly obnoxious, but it works around -# inconsistencies in REs on different platforms, using only a basic regular -# expression (no |, no \<, ...). -Debug_tags.tmp Trace_tags.tmp: mktags - $(AM_V_at)chmod +x @srcdir@/mktags - $(AM_V_GEN)(@srcdir@/mktags \ - '$(@:_tags.tmp=)' \ - "$$(find @srcdir@/../ -name '*.cpp' -o -name '*.h' -o -name '*.cc' -o -name '*.g')") >"$@" - -MOSTLYCLEANFILES = \ - Debug_tags \ - Trace_tags \ - Debug_tags.tmp \ - Trace_tags.tmp \ - Debug_tags.h \ - Trace_tags.h + # Make sure the implicit rules never mistake a _template.cpp or _template.h file for source file. -options_holder_template.h options_template.cpp options_handler_get_option_template.cpp options_handler_set_option_template.cpp base_options_template.h base_options_template.cpp :; +options_holder_template.h options_template.cpp options_get_option_template.cpp options_set_option_template.cpp base_options_template.h base_options_template.cpp :; # Make sure the implicit rules never mistake X_options for the -o file for a # CPP file. @@ -418,19 +385,19 @@ options.cpp : options_template.cpp options_template.cpp.sed mkoptions summary.se # mkoptions apply-sed-to-template sed-file template-file -options_handler_get_option.cpp : options_handler_get_option_template.cpp options_handler_get_option_template.cpp.sed mkoptions summary.sed $(OPTIONS_HEADS) +options_get_option.cpp : options_get_option_template.cpp options_get_option_template.cpp.sed mkoptions summary.sed $(OPTIONS_HEADS) $(AM_V_at)chmod +x @srcdir@/mkoptions $(AM_V_GEN)(@srcdir@/mkoptions apply-sed-files-to-template \ - @srcdir@/options_handler_get_option_template.cpp \ - @builddir@/options_handler_get_option_template.cpp.sed \ + @srcdir@/options_get_option_template.cpp \ + @builddir@/options_get_option_template.cpp.sed \ summary.sed \ ) > "$@" -options_handler_set_option.cpp : options_handler_set_option_template.cpp options_handler_set_option_template.cpp.sed mkoptions summary.sed $(OPTIONS_HEADS) +options_set_option.cpp : options_set_option_template.cpp options_set_option_template.cpp.sed mkoptions summary.sed $(OPTIONS_HEADS) $(AM_V_at)chmod +x @srcdir@/mkoptions $(AM_V_GEN)(@srcdir@/mkoptions apply-sed-files-to-template \ - @srcdir@/options_handler_set_option_template.cpp \ - @builddir@/options_handler_set_option_template.cpp.sed \ + @srcdir@/options_set_option_template.cpp \ + @builddir@/options_set_option_template.cpp.sed \ summary.sed \ ) > "$@" diff --git a/src/options/argument_extender.cpp b/src/options/argument_extender.cpp new file mode 100644 index 000000000..d55610590 --- /dev/null +++ b/src/options/argument_extender.cpp @@ -0,0 +1,74 @@ +/********************* */ +/*! \file preempt_get_option.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2014 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Utility function for parsing commandline options. + ** + ** Utility function for parsing commandline options. + **/ + +#include "options/argument_extender.h" + +#include +#include +#include + +#include "base/cvc4_assert.h" +#include "base/output.h" + +namespace CVC4 { +namespace options { + +ArgumentExtender::ArgumentExtender(unsigned additional, size_t length) + : d_additional(additional) + , d_length(length) +{ + AlwaysAssert(d_additional >= 1); + AlwaysAssert(d_length >= 1); +} + +ArgumentExtender::~ArgumentExtender(){} + +unsigned ArgumentExtender::getIncrease() const { return d_additional; } +size_t ArgumentExtender::getLength() const { return d_length; } + +void ArgumentExtender::extend(int& argc, char**& argv, const char* opt, + std::vector& allocated) +{ + + Debug("preemptGetopt") << "preempting getopt() with " << opt << std::endl; + + AlwaysAssert(opt != NULL && *opt != '\0'); + AlwaysAssert(strlen(opt) <= getLength()); + + ++argc; + unsigned i = 1; + while(argv[i] != NULL && argv[i][0] != '\0') { + ++i; + } + + if(argv[i] == NULL) { + unsigned newSize = i + getIncrease(); + argv = (char**) realloc(argv, newSize * sizeof(char*)); + for(unsigned j = i; j < newSize-1; ++j) { + char* newString = (char*) malloc(sizeof(char) * getLength()); + newString[0] = '\0'; + argv[j] = newString; + allocated.push_back(newString); + } + argv[newSize - 1] = NULL; + } + + strncpy(argv[i], opt, getLength() - 1); + argv[i][getLength() - 1] = '\0'; // ensure NULL-termination even on overflow +} + +}/* CVC4::options namespace */ +}/* CVC4 namespace */ diff --git a/src/options/argument_extender.h b/src/options/argument_extender.h new file mode 100644 index 000000000..1f7e3c1dd --- /dev/null +++ b/src/options/argument_extender.h @@ -0,0 +1,79 @@ +/********************* */ +/*! \file preempt_get_option.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2014 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Utility function for extending commandline options. + ** + ** Utility function for extending commandline options. + **/ + +#include "cvc4_private.h" + +#ifndef __CVC4__OPTIONS__PREMPT_GET_OPTION_H +#define __CVC4__OPTIONS__PREMPT_GET_OPTION_H + +#include +#include + +namespace CVC4 { +namespace options { + + +class ArgumentExtender { + public: + /** + * Preconditions: + * additional >= 1 + * length >= 1 + */ + ArgumentExtender(unsigned additional, size_t length); + ~ArgumentExtender(); + + /** + * This purpose of this function is to massage argc and argv upon the event + * of parsing during Options::parseOptions of an option with the :link or + * :link-alternative attributes. The purpose of the function is to extend argv + * with another commandline argument. + * + * Preconditions: + * opt is '\0' terminated, non-null and non-empty c-string. + * strlen(opt) <= getLength() + * + * Let P be the first position in argv that is >= 1 and is either NULL or + * empty: + * argv[P] == NULL || argv[P] == '\0' + * + * This has a very specific set of side effects: + * - argc is incremented by one. + * - If argv[P] == NULL, this reallocates argv to have (P+additional) + * elements. + * - The 0 through P-1 elements of argv are the same. + * - The P element of argv is a copy of the first len-1 characters of opt. + * This is a newly allocated '\0' terminated c string of length len. + * - The P+1 through (P+additional-2) elements of argv are newly allocated + * empty '\0' terminated c strings of size len. + * - The last element at (P+additional-1) of argv is NULL. + * - All allocations are pushed back onto allocated. + */ + void extend(int& argc, char**& argv, const char* opt, + std::vector& allocated); + + unsigned getIncrease() const; + size_t getLength() const; + + private: + unsigned d_additional; + size_t d_length; +}; + +}/* CVC4::options namespace */ +}/* CVC4 namespace */ + +#endif /* __CVC4__OPTIONS__PREMPT_GET_OPTION_H */ diff --git a/src/options/arith_options b/src/options/arith_options index 9737d5382..9f4003004 100644 --- a/src/options/arith_options +++ b/src/options/arith_options @@ -5,10 +5,10 @@ module ARITH "options/arith_options.h" Arithmetic theory -option arithUnateLemmaMode --unate-lemmas=MODE ArithUnateLemmaMode :handler CVC4::options::stringToArithUnateLemmaMode :default ALL_PRESOLVE_LEMMAS :handler-include "options/options_handler_interface.h" :include "options/arith_unate_lemma_mode.h" +option arithUnateLemmaMode --unate-lemmas=MODE ArithUnateLemmaMode :handler stringToArithUnateLemmaMode :default ALL_PRESOLVE_LEMMAS :include "options/arith_unate_lemma_mode.h" determines which lemmas to add before solving (default is 'all', see --unate-lemmas=help) -option arithPropagationMode --arith-prop=MODE ArithPropagationMode :handler CVC4::options::stringToArithPropagationMode :default BOTH_PROP :handler-include "options/options_handler_interface.h" :include "options/arith_propagation_mode.h" +option arithPropagationMode --arith-prop=MODE ArithPropagationMode :handler stringToArithPropagationMode :default BOTH_PROP :include "options/arith_propagation_mode.h" turns on arithmetic propagation (default is 'old', see --arith-prop=help) # The maximum number of difference pivots to do per invocation of simplex. @@ -25,7 +25,7 @@ option arithHeuristicPivots --heuristic-pivots=N int16_t :default 0 :read-write expert-option arithStandardCheckVarOrderPivots --standard-effort-variable-order-pivots=N int16_t :default -1 :read-write limits the number of pivots in a single invocation of check() at a non-full effort level using Bland's pivot rule -option arithErrorSelectionRule --error-selection-rule=RULE ErrorSelectionRule :handler CVC4::options::stringToErrorSelectionRule :default MINIMUM_AMOUNT :handler-include "options/options_handler_interface.h" :include "options/arith_heuristic_pivot_rule.h" +option arithErrorSelectionRule --error-selection-rule=RULE ErrorSelectionRule :handler stringToErrorSelectionRule :default MINIMUM_AMOUNT :include "options/arith_heuristic_pivot_rule.h" change the pivot rule for the basic variable (default is 'min', see --pivot-rule help) # The number of pivots before simplex rechecks every basic variable for a conflict @@ -42,8 +42,9 @@ option arithPivotThreshold --pivot-threshold=N uint16_t :default 2 :read-write option arithPropagateMaxLength --prop-row-length=N uint16_t :default 16 sets the maximum row length to be used in propagation -option arithDioSolver /--disable-dio-solver bool :default true - turns off Linear Diophantine Equation solver (Griggio, JSAT 2012) +option arithDioSolver --enable-dio-solver/--disable-dio-solver bool :default true + turns on Linear Diophantine Equation solver (Griggio, JSAT 2012) +/turns off Linear Diophantine Equation solver (Griggio, JSAT 2012) # Whether to split (= x y) into (and (<= x y) (>= x y)) in # arithmetic preprocessing. diff --git a/src/options/base_handlers.h b/src/options/base_handlers.h index b37dde5c6..d4137255e 100644 --- a/src/options/base_handlers.h +++ b/src/options/base_handlers.h @@ -24,6 +24,8 @@ #include #include +#include "options/option_exception.h" + namespace CVC4 { namespace options { @@ -39,7 +41,7 @@ public: comparator(double d) throw() : d_lbound(0), d_dbound(d), d_hasLbound(false) {} template - void operator()(std::string option, const T& value, OptionsHandler* handler) { + void operator()(std::string option, const T& value) { if((d_hasLbound && !(Cmp()(value, T(d_lbound)))) || (!d_hasLbound && !(Cmp()(value, T(d_dbound))))) { std::stringstream ss; diff --git a/src/options/base_options b/src/options/base_options index edbef801d..7346641c7 100644 --- a/src/options/base_options +++ b/src/options/base_options @@ -3,31 +3,34 @@ # # This is essentially a shell script interpreted with special commands. # -# Lines starting with whitespace are special. They are passed in their entirety (minus -# the first whitespace char) to the "doc" command. Lines starting with a single slash -# are stripped of this initial character and interpreted by the "doc-alt" command. A period -# "." in the first column of a line, followed optionally by whitespace but without any other -# content on the line, is interpreted as an empty string passed to doc. (This allows -# multi-paragraph documentation for options.) Lines may be continued with a backslash (\) -# at the end of a line. +# Lines starting with whitespace are special. They are passed in their entirety +# (minus the first whitespace char) to the "doc" command. Lines starting with a +# single slash are stripped of this initial character and interpreted by the +# "doc-alt" command. A period "." in the first column of a line, followed +# optionally by whitespace but without any other content on the line, is +# interpreted as an empty string passed to doc. (This allows multi-paragraph +# documentation for options.) Lines may be continued with a backslash (\) at the +# end of a line. # # commands are: # # module ID "include-file" name # -# Identifies the module. Must be the first command in the file. ID is a suitable -# identifier for a preprocessor definition, and should be unique; name is a "pretty" -# name used for the benefit of the end CVC4 user in, e.g., option listings. +# Identifies the module. Must be the first command in the file. ID is a +# suitable identifier for a preprocessor definition, and should be unique; +# name is a "pretty" name used for the benefit of the end CVC4 user in, e.g., +# option listings. # # common-option SPECIFICATION # option SPECIFICATION # expert-option SPECIFICATION # undocumented-option SPECIFICATION # -# These commands declare (respectively) common options presented first to the user, -# standard options that the user might want to see with "--help" documentation, -# expert options that should be marked as expert-only, and options that should not -# appear in normal option documentation (even if documentation is included here). +# These commands declare (respectively) common options presented first to the +# user, standard options that the user might want to see with "--help" +# documentation, expert options that should be marked as expert-only, and +# options that should not appear in normal option documentation (even if +# documentation is included here). # # SPECIFICATIONs take this form: # @@ -36,9 +39,13 @@ # | :default C++-expression # | :handler custom-option-handlers.. # | :handler-include include-files.. +# | :predicate custom-option-handlers.. +# | :predicate-include include-files.. +# | :notify custom-option-notifications.. # | :read-only # | :read-write # | :link linked-options.. +# | :link-smt linked-option [value] # # common-alias ALIAS_SPECIFICATION # alias ALIAS_SPECIFICATION @@ -74,7 +81,76 @@ # # endmodule # -# This file should end with the "endmodule" command, and nothing should follow it. +# This file should end with the "endmodule" command, and nothing should +# follow it. +# +# +# The options/ package supports a wide range of operations for responding to +# an option being set. Roughly the three major concepts are: +# - :handler is to parse an option before setting its value. +# - :predicate is to reject bad values for the option. +# - :notify is used for dynamic dispatch after an option is assigned. +# +# More details on each class of custom handlers. +# :handler custom-option-handler +# Handlers provide support for parsing custom types and parsing for options. +# The signature for a handler call is: +# T custom-option-handler(std::string option, std::string optarg, +# OptionsHandler* handler); +# where T is the type of the option. The suggested implementation is to +# implement custom-handler as a dispatch into a function on handler with the +# signature: +# T OptionsHandler::custom-option-handler(std::string option, +# std::string optarg); +# The handlers are run before predicates and notifications. +# Having multiple handlers is considered bad practice and is unsupported. +# Handlers may have arbitrary side effects, but should call no code +# inaccessible to liboptions. For side effects that are not required in order +# to parse the option, using :predicate is recommended. Use :notify to +# achieve dynamic dispatch outside of base/, lib/, and options/. Memory +# management done by a handler needs to either be encapsulated by the type +# and the destructor for the type or should *always* be owned by handler. More +# elaborate memory management schemes are not currently supported. +# +# :predicate custom-predicate +# Predicates provide support for checking whether or not the value of an +# is acceptable. Predicates are run after handlers and before notifications. +# The signature for a predicate call is: +# void custom-predicate(std::string option, T value, +# OptionsHandler* handler); +# where T is the type of the option. The suggested implementation is to +# implement custom-predicate as a dispatch into a function on handler with the +# signature: +# void OptionsHandler::custom-predicate(std::string option, T value); +# The predicates are run after handlers and before notifications. Multiple +# predicates may be defined for the same option, but the order they are run +# is not guaranteed. Predicates may have arbitrary side effects, but should +# call no code inaccessible to liboptions. Use :notify to +# achieve dynamic dispatch outside of base/, lib/, and options/. +# Predicates are expected to reject bad value for the option by throwing an +# OptionsException. +# +# :notify custom-notification +# This allows for the installation of custom post-processing callbacks using +# the Listener infrastructure. custom-option-notification is a C++ function +# that is called after the assignment of the option is updated. +# The normal usage of an notify is to call a Listener that is registered for +# this specific option. This is how dynamic dispatch outside of the +# liboptions package should always be done. +# The signature of custom-option-notification should take an option name as +# well as an OptionsHandler*. +# void custom-notification( +# const std::string& option, CVC4::options::OptionsHandler* handler); +# The name is provided so multiple options can use the same notification +# implementation. +# This is called after all handlers and predicates have been run. +# Formally, this is always placed at the end of either the generated +# Options::assign or Options::assignBool function for the option. +# Because of this :notify cannot be used with void type options. +# Users of this feature should *always* check the code generated in +# builds/src/options/options.cpp for the correctness of the placement of the +# generated code. The Listener notify() function is allowed to throw +# an arbitrary std::exception. # module BASE "options/base_options.h" Base @@ -85,9 +161,9 @@ option in std::istream* :default &std::cin :include option out std::ostream* :default &std::cout :include option err std::ostream* :default &std::cerr :include -common-option inputLanguage input-language -L --lang=LANG InputLanguage :handler CVC4::options::stringToInputLanguage :include "options/language.h" :default language::input::LANG_AUTO :read-write +common-option inputLanguage input-language -L --lang=LANG InputLanguage :handler stringToInputLanguage :include "options/language.h" :default language::input::LANG_AUTO :read-write force input language (default is "auto"; see --lang help) -common-option outputLanguage output-language --output-lang=LANG OutputLanguage :handler CVC4::options::stringToOutputLanguage :include "options/language.h" :default language::output::LANG_AUTO :read-write +common-option outputLanguage output-language --output-lang=LANG OutputLanguage :handler stringToOutputLanguage :include "options/language.h" :default language::output::LANG_AUTO :read-write force output language (default is "auto"; see --output-lang help) option languageHelp bool @@ -96,18 +172,18 @@ option languageHelp bool undocumented-alias --language=L = --lang=L undocumented-alias --output-language=L = --output-lang=L -option verbosity verbosity int :read-write :default 0 :predicate CVC4::options::setVerbosity :predicate-include "options/base_handlers.h" +option verbosity verbosity int :read-write :default 0 :predicate setVerbosity the verbosity level of CVC4 -common-option - -v --verbose void :handler CVC4::options::increaseVerbosity +common-option - -v --verbose void :handler increaseVerbosity increase verbosity (may be repeated) -common-option - -q --quiet void :handler CVC4::options::decreaseVerbosity +common-option - -q --quiet void :handler decreaseVerbosity decrease verbosity (may be repeated) -common-option statistics statistics --stats bool :predicate CVC4::options::statsEnabledBuild :predicate-include "options/options_handler_interface.h" +common-option statistics statistics --stats bool :predicate statsEnabledBuild give statistics on exit undocumented-alias --statistics = --stats undocumented-alias --no-statistics = --no-stats -option statsEveryQuery --stats-every-query bool :default false :link --stats +option statsEveryQuery --stats-every-query bool :default false :link --stats :link-smt statistics in incremental mode, print stats after every satisfiability or validity query undocumented-alias --statistics-every-query = --stats-every-query undocumented-alias --no-statistics-every-query = --no-stats-every-query @@ -123,12 +199,12 @@ option parseOnly parse-only --parse-only bool :read-write option preprocessOnly preprocess-only --preprocess-only bool exit after preprocessing input -option - trace -t --trace=TAG argument :handler CVC4::options::addTraceTag +option - trace -t --trace=TAG argument :handler addTraceTag trace something (e.g. -t pushpop), can repeat -option - debug -d --debug=TAG argument :handler CVC4::options::addDebugTag +option - debug -d --debug=TAG argument :handler addDebugTag debug something (e.g. -d arith), can repeat -option printSuccess print-success --print-success bool :predicate CVC4::options::setPrintSuccess :predicate-include "options/options_handler_interface.h" +option printSuccess print-success --print-success bool :notify notifyPrintSuccess print the "success" output required of SMT-LIBv2 alias --smtlib-strict = --lang=smt2 --output-lang=smt2 --strict-parsing --default-expr-depth=-1 --print-success --incremental --abstract-values diff --git a/src/options/booleans_options b/src/options/booleans_options index 2e2cbee1f..a150c1d83 100644 --- a/src/options/booleans_options +++ b/src/options/booleans_options @@ -5,7 +5,7 @@ module BOOLEANS "options/booleans_options.h" Boolean theory -option booleanTermConversionMode boolean-term-conversion-mode --boolean-term-conversion-mode=MODE CVC4::theory::booleans::BooleanTermConversionMode :default CVC4::theory::booleans::BOOLEAN_TERM_CONVERT_TO_BITVECTORS :include "options/boolean_term_conversion_mode.h" :handler CVC4::options::stringToBooleanTermConversionMode :handler-include "options/options_handler_interface.h" +option booleanTermConversionMode boolean-term-conversion-mode --boolean-term-conversion-mode=MODE CVC4::theory::booleans::BooleanTermConversionMode :default CVC4::theory::booleans::BOOLEAN_TERM_CONVERT_TO_BITVECTORS :include "options/boolean_term_conversion_mode.h" :handler stringToBooleanTermConversionMode policy for converting Boolean terms endmodule diff --git a/src/options/bv_options b/src/options/bv_options index 245c56b51..c1180dba3 100644 --- a/src/options/bv_options +++ b/src/options/bv_options @@ -7,34 +7,34 @@ module BV "options/bv_options.h" Bitvector theory # Option to set the bit-blasting mode (lazy, eager) -option bitblastMode bitblast --bitblast=MODE CVC4::theory::bv::BitblastMode :handler CVC4::options::stringToBitblastMode :default CVC4::theory::bv::BITBLAST_MODE_LAZY :read-write :include "options/bv_bitblast_mode.h" :handler-include "options/options_handler_interface.h" +option bitblastMode bitblast --bitblast=MODE CVC4::theory::bv::BitblastMode :handler stringToBitblastMode :default CVC4::theory::bv::BITBLAST_MODE_LAZY :read-write :include "options/bv_bitblast_mode.h" choose bitblasting mode, see --bitblast=help # Options for eager bit-blasting -option bitvectorAig --bitblast-aig bool :default false :predicate CVC4::options::abcEnabledBuild CVC4::options::setBitblastAig :predicate-include "options/options_handler_interface.h" :read-write +option bitvectorAig --bitblast-aig bool :default false :predicate abcEnabledBuild setBitblastAig :read-write bitblast by first converting to AIG (implies --bitblast=eager) -expert-option bitvectorAigSimplifications --bv-aig-simp=COMMAND std::string :default "" :predicate CVC4::options::abcEnabledBuild :read-write :link --bitblast-aig :link-smt bitblast-aig +expert-option bitvectorAigSimplifications --bv-aig-simp=COMMAND std::string :default "" :predicate abcEnabledBuild :read-write :link --bitblast-aig :link-smt bitblast-aig abc command to run AIG simplifications (implies --bitblast-aig, default is "balance;drw") # Options for lazy bit-blasting - option bitvectorPropagate --bv-propagate bool :default true :read-write use bit-vector propagation in the bit-blaster -option bitvectorEqualitySolver --bv-eq-solver bool :default true :read-write +option bitvectorEqualitySolver --bv-eq-solver bool :default true :read-write use the equality engine for the bit-vector theory (only if --bitblast=lazy) -option bitvectorEqualitySlicer --bv-eq-slicer=MODE CVC4::theory::bv::BvSlicerMode :handler CVC4::options::stringToBvSlicerMode :default CVC4::theory::bv::BITVECTOR_SLICER_OFF :read-write :include "options/bv_bitblast_mode.h" :handler-include "options/options_handler_interface.h" :read-write :link --bv-eq-solver +option bitvectorEqualitySlicer --bv-eq-slicer=MODE CVC4::theory::bv::BvSlicerMode :handler stringToBvSlicerMode :default CVC4::theory::bv::BITVECTOR_SLICER_OFF :read-write :include "options/bv_bitblast_mode.h" :read-write :link --bv-eq-solver :link-smt bv-eq-solver turn on the slicing equality solver for the bit-vector theory (only if --bitblast=lazy) + option bitvectorInequalitySolver --bv-inequality-solver bool :default true :read-write turn on the inequality solver for the bit-vector theory (only if --bitblast=lazy) -option bitvectorAlgebraicSolver --bv-algebraic-solver bool :default true :read-write +option bitvectorAlgebraicSolver --bv-algebraic-solver bool :default true :read-write turn on the algebraic solver for the bit-vector theory (only if --bitblast=lazy) -expert-option bitvectorAlgebraicBudget --bv-algebraic-budget unsigned :default 1500 :read-write :link --bv-algebraic-solver +expert-option bitvectorAlgebraicBudget --bv-algebraic-budget unsigned :default 1500 :read-write :link --bv-algebraic-solver :link-smt bv-algebraic-solver the budget allowed for the algebraic solver in number of SAT conflicts # General options diff --git a/src/options/decision_options b/src/options/decision_options index 35a1de1e9..2490d2808 100644 --- a/src/options/decision_options +++ b/src/options/decision_options @@ -6,7 +6,7 @@ module DECISION "options/decision_options.h" Decision heuristics # When/whether to use any decision strategies -option decisionMode decision-mode --decision=MODE decision::DecisionMode :handler CVC4::options::stringToDecisionMode :default decision::DECISION_STRATEGY_INTERNAL :read-write :include "options/decision_mode.h" :handler-include "options/options_handler_interface.h" +option decisionMode decision-mode --decision=MODE decision::DecisionMode :handler stringToDecisionMode :default decision::DECISION_STRATEGY_INTERNAL :read-write :include "options/decision_mode.h" choose decision mode, see --decision=help # only use DE to determine when to stop, not to make decisions @@ -21,7 +21,7 @@ expert-option decisionUseWeight --decision-use-weight bool :default false expert-option decisionRandomWeight --decision-random-weight=N int :default 0 assign random weights to nodes between 0 and N-1 (0: disable) -expert-option decisionWeightInternal --decision-weight-internal=HOW decision::DecisionWeightInternal :handler CVC4::options::stringToDecisionWeightInternal :default decision::DECISION_WEIGHT_INTERNAL_OFF :handler-include "options/options_handler_interface.h" +expert-option decisionWeightInternal --decision-weight-internal=HOW decision::DecisionWeightInternal :handler stringToDecisionWeightInternal :default decision::DECISION_WEIGHT_INTERNAL_OFF computer weights of internal nodes using children: off, max, sum, usr1 (meaning evolving) endmodule diff --git a/src/options/expr_options b/src/options/expr_options index fc92c75a6..75354a010 100644 --- a/src/options/expr_options +++ b/src/options/expr_options @@ -5,16 +5,16 @@ module EXPR "options/expr_options.h" Expression package -option defaultExprDepth --default-expr-depth=N int :default 0 :predicate CVC4::options::setDefaultExprDepth :predicate-include "options/options_handler_interface.h" +option defaultExprDepth --default-expr-depth=N int :default 0 :predicate setDefaultExprDepthPredicate :notify notifySetDefaultExprDepth print exprs to depth N (0 == default, -1 == no limit) undocumented-alias --expr-depth=N = --default-expr-depth=N -option defaultDagThresh default-dag-thresh --default-dag-thresh=N int :default 1 :predicate CVC4::options::setDefaultDagThresh :predicate-include "options/options_handler_interface.h" +option defaultDagThresh default-dag-thresh --default-dag-thresh=N int :default 1 :predicate setDefaultDagThreshPredicate :notify notifySetDefaultDagThresh dagify common subexprs appearing > N times (1 == default, 0 == don't dagify) undocumented-alias --dag-thresh=N = --default-dag-thresh=N undocumented-alias --dag-threshold=N = --default-dag-thresh=N -option - --print-expr-types void :handler CVC4::options::setPrintExprTypes :handler-include "options/options_handler_interface.h" +option printExprTypes --print-expr-types bool :default false :notify notifySetPrintExprTypes print types with variables when printing exprs option earlyTypeChecking --eager-type-checking/--lazy-type-checking bool :default USE_EARLY_TYPE_CHECKING_BY_DEFAULT @@ -23,7 +23,7 @@ option earlyTypeChecking --eager-type-checking/--lazy-type-checking bool :defaul # --no-type-checking will override any --early-type-checking or --lazy-type-checking option # --lazy-type-checking is linked because earlyTypeChecking should be set false too -option typeChecking /--no-type-checking bool :default DO_SEMANTIC_CHECKS_BY_DEFAULT :link /--lazy-type-checking +option typeChecking type-checking /--no-type-checking bool :default DO_SEMANTIC_CHECKS_BY_DEFAULT :link /--lazy-type-checking never type check expressions option biasedITERemoval --biased-ites bool :default false diff --git a/src/options/logic_info_forward.h b/src/options/logic_info_forward.h deleted file mode 100644 index b60e56034..000000000 --- a/src/options/logic_info_forward.h +++ /dev/null @@ -1,26 +0,0 @@ -/*! \file logic_info_forward.h - ** \verbatim - ** Original author: Tim King - ** Major contributors: none - ** Minor contributors (to current version): none - ** This file is part of the CVC4 project. - ** Copyright (c) 2009-2014 New York University and The University of Iowa - ** See the file COPYING in the top-level source directory for licensing - ** information.\endverbatim - ** - ** \brief A temporary forward delcaration file for LogicInfo. - ** - ** A temporary forward delcaration file for LogicInfo. - **/ - - -#include "cvc4_public.h" - -#ifndef __CVC4__OPTIONS_LOGIC_INFO_FORWARD_H -#define __CVC4__OPTIONS_LOGIC_INFO_FORWARD_H - -namespace CVC4 { -class LogicInfo; -}/* CVC4 namespace */ - -#endif /* __CVC4__OPTIONS_LOGIC_INFO_FORWARD_H */ diff --git a/src/options/main_options b/src/options/main_options index 8b161e5df..7ec4fedb3 100644 --- a/src/options/main_options +++ b/src/options/main_options @@ -12,21 +12,21 @@ undocumented-alias --license = --version common-option help -h --help/ bool full command line reference -common-option - --show-config void :handler CVC4::options::showConfiguration :handler-include "options/options_handler_interface.h" +common-option - --show-config void :handler showConfiguration show CVC4 static configuration -option - --show-debug-tags void :handler CVC4::options::showDebugTags :handler-include "options/options_handler_interface.h" +option - --show-debug-tags void :handler showDebugTags show all available tags for debugging -option - --show-trace-tags void :handler CVC4::options::showTraceTags :handler-include "options/options_handler_interface.h" +option - --show-trace-tags void :handler showTraceTags show all available tags for tracing expert-option earlyExit --early-exit bool :default true do not run destructors at exit; default on except in debug builds # portfolio options -option threads --threads=N unsigned :default 2 :predicate options::greater(0) +option threads --threads=N unsigned :default 2 :predicate unsignedGreater0 Total number of threads for portfolio -option - --threadN=string void :handler CVC4::options::threadN :handler-include "options/options_handler_interface.h" +option - --threadN=string void :handler threadN configures portfolio thread N (0..#threads-1) option threadStackSize --thread-stack=N unsigned :default 0 stack size for worker threads in MB (0 means use Boost/thread lib default) @@ -38,16 +38,16 @@ option sharingFilterByLength --filter-lemma-length=N int :default -1 :read-write don't share (among portfolio threads) lemmas strictly longer than N option fallbackSequential --fallback-sequential bool :default false Switch to sequential mode (instead of printing an error) if it can't be solved in portfolio mode -option incrementalParallel --incremental-parallel bool :default false :link --incremental +option incrementalParallel --incremental-parallel bool :default false :link --incremental :link-smt incremental Use parallel solver even in incremental mode (may print 'unknown's at times) option interactive : --interactive bool :read-write force interactive/non-interactive mode -undocumented-option interactivePrompt /--no-interactive-prompt bool :default true - turn off interactive prompting while in interactive mode +undocumented-option interactivePrompt --interactive-prompt bool :default true + interactive prompting while in interactive mode # error behaviors (--immediate-exit is default in cases we support, thus no options) -option continuedExecution --continued-execution/ bool :default false :link "--interactive --no-interactive-prompt"/ +option continuedExecution --continued-execution/ bool :default false :link "--interactive --no-interactive-prompt"/ :link-smt interactive :link-smt interactivePrompt \"false\" continue executing commands, even on error option segvSpin --segv-spin bool :default false diff --git a/src/options/mkoptions b/src/options/mkoptions index 05280baa8..ad8d7033f 100755 --- a/src/options/mkoptions +++ b/src/options/mkoptions @@ -115,6 +115,7 @@ long_option_alternate= long_option_alternate_set= type= predicates= +notifications= # just for duplicates-checking all_declared_internal_options= @@ -247,6 +248,7 @@ function handle_option { default_value= handlers= predicates= + notifications= links= links_alternate= smt_links= @@ -425,6 +427,12 @@ function handle_option { predicates="${predicates} ${args[$i]}" done ;; + :notify) + while [ $(($i+1)) -lt ${#args[@]} ] && ! expr "${args[$(($i+1))]}" : '\:' &>/dev/null; do + let ++i + notifications="${notifications} ${args[$i]}" + done + ;; :link) while [ $(($i+1)) -lt ${#args[@]} ] && ! expr "${args[$(($i+1))]}" : '\:' &>/dev/null; do let ++i @@ -535,11 +543,11 @@ template <> bool Options::wasSetByUser(options::${internal}__option_t) const;" if [ "$type" = bool ]; then module_specializations="${module_specializations} #line $lineno \"$kf\" -template <> void Options::assignBool(options::${internal}__option_t, std::string option, bool value, options::OptionsHandler* handler);" +template <> void Options::assignBool(options::${internal}__option_t, std::string option, bool value);" elif [ "$internal" != - ]; then module_specializations="${module_specializations} #line $lineno \"$kf\" -template <> void Options::assign(options::${internal}__option_t, std::string option, std::string value, options::OptionsHandler* handler);" +template <> void Options::assign(options::${internal}__option_t, std::string option, std::string value);" fi module_accessors="${module_accessors} @@ -585,6 +593,7 @@ template <> bool Options::wasSetByUser(options::${internal}__option_t) const { r run_links= run_links_alternate= run_smt_links= + run_notifications= if [ -n "$links" -a -z "$smt_links" -a -n "$smtname" ]; then WARN "$smtname has no :link-smt, but equivalent command-line has :link" elif [ -n "$smt_links" -a -z "$links" ] && [ -n "$short_option" -o -n "$short_option_alternate" -o -n "$long_option" -o "$long_option_alternate" ]; then @@ -595,7 +604,7 @@ template <> bool Options::wasSetByUser(options::${internal}__option_t) const { r for link in $links; do run_links="$run_links #line $lineno \"$kf\" - preemptGetopt(extra_argc, extra_argv, \"$link\");" + argumentExtender.extend(extra_argc, extra_argv, \"$link\", allocated);" done fi if [ -n "$smt_links" ]; then @@ -605,7 +614,7 @@ template <> bool Options::wasSetByUser(options::${internal}__option_t) const { r while [ $i -lt ${#smt_links[@]} ]; do run_smt_links="$run_smt_links #line $lineno \"$kf\" - handler->setOption(std::string(\"${smt_links[$i]}\"), (${smt_links[$(($i+1))]}));" + setOption(std::string(\"${smt_links[$i]}\"), (${smt_links[$(($i+1))]}));" i=$((i+2)) done fi @@ -614,7 +623,14 @@ template <> bool Options::wasSetByUser(options::${internal}__option_t) const { r for link in $links_alternate; do run_links_alternate="$run_links_alternate #line $lineno \"$kf\" - preemptGetopt(extra_argc, extra_argv, \"$link\");" + argumentExtender.extend(extra_argc, extra_argv, \"$link\", allocated);" + done + fi + if [ -n "$notifications" ]; then + for notification in $notifications; do + run_notifications="$run_notifications +#line $lineno \"$kf\" + d_handler->$notification(option);" done fi if [ "$type" = bool ] && [ -n "$cases" -o -n "$cases_alternate" -o -n "$smtname" ]; then @@ -626,7 +642,7 @@ template <> bool Options::wasSetByUser(options::${internal}__option_t) const { r for predicate in $predicates; do run_handlers="$run_handlers #line $lineno \"$kf\" - $predicate(option, b, handler);" + handler->$predicate(option, b);" done fi if [ -n "$run_handlers" ]; then @@ -641,7 +657,7 @@ template <> void runBoolPredicates(options::${internal}__option_t, std::string o if [ "$type" = bool ]; then all_modules_option_handlers="${all_modules_option_handlers}${cases} #line $lineno \"$kf\" - assignBool(options::$internal, option, true, handler);$run_links + assignBool(options::$internal, option, true);$run_links break; " elif [ -n "$expect_arg" -a "$internal" != - ]; then @@ -650,7 +666,7 @@ template <> void runBoolPredicates(options::${internal}__option_t, std::string o for handler in $handlers; do run_handlers="$run_handlers #line $lineno \"$kf\" - $handler(option, optionarg, handler);" + handler->$handler(option, optionarg);" done else run_handlers=" @@ -661,7 +677,7 @@ template <> void runBoolPredicates(options::${internal}__option_t, std::string o for predicate in $predicates; do run_handlers="$run_handlers #line $lineno \"$kf\" - $predicate(option, retval, handler);" + handler->$predicate(option, retval);" done fi all_custom_handlers="${all_custom_handlers} @@ -674,7 +690,7 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options }" all_modules_option_handlers="${all_modules_option_handlers}${cases} #line $lineno \"$kf\" - assign(options::$internal, option, optionarg, handler);$run_links + assign(options::$internal, option, optionarg);$run_links break; " elif [ -n "$expect_arg" ]; then @@ -686,7 +702,7 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options for handler in $handlers; do run_handlers="$run_handlers #line $lineno \"$kf\" - $handler(option, optionarg, handler);" + handler->$handler(option, optionarg);" done fi all_modules_option_handlers="${all_modules_option_handlers}${cases} @@ -703,7 +719,7 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options for handler in $handlers; do run_handlers="$run_handlers #line $lineno \"$kf\" - $handler(option, handler);" + handler->$handler(option);" done fi all_modules_option_handlers="${all_modules_option_handlers}${cases} @@ -712,12 +728,12 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options break; " fi - fi + fi # ends if [ -n "$cases" ]; if [ -n "$cases_alternate" ]; then if [ "$type" = bool ]; then all_modules_option_handlers="${all_modules_option_handlers}${cases_alternate} #line $lineno \"$kf\" - assignBool(options::$internal, option, false, handler);$run_links_alternate + assignBool(options::$internal, option, false);$run_links_alternate break; " else @@ -770,7 +786,7 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options #line $lineno \"$kf\" if(key == \"$smtname\") { #line $lineno \"$kf\" - Options::current()->assignBool(options::$internal, \"$smtname\", optionarg == \"true\", handler);$run_smt_links + Options::current()->assignBool(options::$internal, \"$smtname\", optionarg == \"true\");$run_smt_links return; }" elif [ -n "$expect_arg" -a "$internal" != - ]; then @@ -779,7 +795,7 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options for handler in $handlers; do run_handlers="$run_handlers #line $lineno \"$kf\" - $handler(\"$smtname\", optionarg, handler); + handler->$handler(\"$smtname\", optionarg); " done fi @@ -787,7 +803,7 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options #line $lineno \"$kf\" if(key == \"$smtname\") { #line $lineno \"$kf\" - Options::current()->assign(options::$internal, \"$smtname\", optionarg, handler);$run_smt_links + Options::current()->assign(options::$internal, \"$smtname\", optionarg);$run_smt_links return; }" elif [ -n "$expect_arg" ]; then @@ -795,7 +811,7 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options for handler in $handlers; do run_handlers="$run_handlers #line $lineno \"$kf\" - $handler(\"$smtname\", optionarg, handler); + handler->$handler(\"$smtname\", optionarg); " done smt_setoption_handlers="${smt_setoption_handlers} @@ -810,7 +826,7 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options for handler in $handlers; do run_handlers="$run_handlers #line $lineno \"$kf\" - $handler(\"$smtname\", handler); + handler->$handler(\"$smtname\"); " done smt_setoption_handlers="${smt_setoption_handlers} @@ -849,26 +865,26 @@ template <> options::${internal}__option_t::type runHandlerAndPredicates(options # emit assignBool/assign all_custom_handlers="${all_custom_handlers} #line $lineno \"$kf\" -template <> void Options::assignBool(options::${internal}__option_t, std::string option, bool value, options::OptionsHandler* handler) { +template <> void Options::assignBool(options::${internal}__option_t, std::string option, bool value) { #line $lineno \"$kf\" - runBoolPredicates(options::$internal, option, value, handler); + runBoolPredicates(options::$internal, option, value, d_handler); #line $lineno \"$kf\" d_holder->$internal = value; #line $lineno \"$kf\" d_holder->${internal}__setByUser__ = true; #line $lineno \"$kf\" - Trace(\"options\") << \"user assigned option $internal\" << std::endl; + Trace(\"options\") << \"user assigned option $internal\" << std::endl;$run_notifications }" elif [ -n "$expect_arg" -a "$internal" != - ] && [ -n "$cases" -o -n "$cases_alternate" -o -n "$smtname" ]; then all_custom_handlers="${all_custom_handlers} #line $lineno \"$kf\" -template <> void Options::assign(options::${internal}__option_t, std::string option, std::string value, options::OptionsHandler* handler) { +template <> void Options::assign(options::${internal}__option_t, std::string option, std::string value) { #line $lineno \"$kf\" - d_holder->$internal = runHandlerAndPredicates(options::$internal, option, value, handler); + d_holder->$internal = runHandlerAndPredicates(options::$internal, option, value, d_handler); #line $lineno \"$kf\" d_holder->${internal}__setByUser__ = true; #line $lineno \"$kf\" - Trace(\"options\") << \"user assigned option $internal\" << std::endl; + Trace(\"options\") << \"user assigned option $internal\" << std::endl;$run_notifications }" fi } @@ -912,8 +928,6 @@ function handle_alias { readOnly=true required_argument=false default_value= - handlers= - predicates= links= links_alternate= @@ -999,12 +1013,12 @@ function handle_alias { fi links="$links #line $lineno \"$kf\" - preemptGetopt(extra_argc, extra_argv, \"$linkopt\");" + argumentExtender.extend(extra_argc, extra_argv, \"$linkopt\", allocated);" if [ "$linkarg" ]; then # include also the arg links="$links #line $lineno \"$kf\" - preemptGetopt(extra_argc, extra_argv, optionarg.c_str());" + argumentExtender.extend(extra_argc, extra_argv, optionarg.c_str(), allocated);" fi shift done diff --git a/src/options/open_ostream.cpp b/src/options/open_ostream.cpp new file mode 100644 index 000000000..4c92d056b --- /dev/null +++ b/src/options/open_ostream.cpp @@ -0,0 +1,102 @@ +/********************* */ +/*! \file open_ostream.cpp + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2014 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief [[ Add one-line brief description here ]] + ** + ** [[ Add lengthier description here ]] + ** \todo document this file + **/ + +#include "options/open_ostream.h" + + +#include +#include +#include +#include +#include +#include + +#include "lib/strtok_r.h" +#include "options/parser_options.h" + +namespace CVC4 { + +OstreamOpener::OstreamOpener(const char* channelName) + : d_channelName(channelName) + , d_specialCases() +{} + +void OstreamOpener::addSpecialCase(const std::string& name, std::ostream* out){ + d_specialCases[name] = out; +} + + + +std::pair< bool, std::ostream* > OstreamOpener::open(const std::string& optarg) const + throw(OptionException) +{ + if(optarg == "") { + std::stringstream ss; + ss << "Bad file name setting for " << d_channelName; + throw OptionException(ss.str()); + } + if(d_specialCases.find(optarg) != d_specialCases.end()){ + return std::make_pair(false, (*d_specialCases.find(optarg)).second); + } else if(!options::filesystemAccess()) { + throw OptionException(std::string("Filesystem access not permitted")); + } else { + errno = 0; + std::ostream* outStream; + outStream = new std::ofstream(optarg.c_str(), + std::ofstream::out | std::ofstream::trunc); + if(outStream == NULL || !*outStream) { + std::stringstream ss; + ss << "Cannot open " << d_channelName << " file: `" + << optarg << "': " << cvc4_errno_failreason(); + throw OptionException(ss.str()); + } + return make_pair(true, outStream); + } +} + +std::string cvc4_errno_failreason() { +#if HAVE_STRERROR_R +#if STRERROR_R_CHAR_P + if(errno != 0) { + // GNU version of strerror_r: *might* use the given buffer, + // or might not. It returns a pointer to buf, or not. + char buf[80]; + return std::string(strerror_r(errno, buf, sizeof buf)); + } else { + return "unknown reason"; + } +#else /* STRERROR_R_CHAR_P */ + if(errno != 0) { + // XSI version of strerror_r: always uses the given buffer. + // Returns an error code. + char buf[80]; + if(strerror_r(errno, buf, sizeof buf) == 0) { + return std::string(buf); + } else { + // some error occurred while getting the error string + return "unknown reason"; + } + } else { + return "unknown reason"; + } +#endif /* STRERROR_R_CHAR_P */ +#else /* HAVE_STRERROR_R */ + return "unknown reason"; +#endif /* HAVE_STRERROR_R */ +} + +}/* CVC4 namespace */ diff --git a/src/options/open_ostream.h b/src/options/open_ostream.h new file mode 100644 index 000000000..ab83427a9 --- /dev/null +++ b/src/options/open_ostream.h @@ -0,0 +1,63 @@ +/********************* */ +/*! \file open_stream.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2016 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief [[ Add one-line brief description here ]] + ** + ** [[ Add lengthier description here ]] + ** \todo document this file + **/ + +#include "cvc4_private.h" + +#ifndef __CVC4__OPEN_OSTREAM_H +#define __CVC4__OPEN_OSTREAM_H + +#include +#include +#include +#include + +#include "options/option_exception.h" + +namespace CVC4 { + +class OstreamOpener { + public: + OstreamOpener(const char* channelName); + + void addSpecialCase(const std::string& name, std::ostream* out); + + /** + * If name == "", this throws OptionException with the message, messageIfEmpty. + * If name is a special case, this return where out is the + * special case that was added. + * If name == "std::cerr", this return . + * If none of the previous conditions hold and !options::filesystemAccess(), + * this throws an OptionException. + * Otherwise, this attempts to open a ofstream using the filename, name. + * If this fails, this throws and OptionException. If this succeeds, this + * returns where stream is a ostream allocated by new. + * The caller is in this case the owner of the allocated memory. + */ + std::pair open(const std::string& name) const + throw(OptionException); + + private: + const char* d_channelName; + std::map< std::string, std::ostream* > d_specialCases; + +}; /* class OstreamOpener */ + +std::string cvc4_errno_failreason(); + +}/* CVC4 namespace */ + +#endif /* __CVC4__OPEN_OSTREAM_H */ diff --git a/src/options/options.h b/src/options/options.h index 8e1ca2b65..8fb52146f 100644 --- a/src/options/options.h +++ b/src/options/options.h @@ -19,12 +19,16 @@ #ifndef __CVC4__OPTIONS__OPTIONS_H #define __CVC4__OPTIONS__OPTIONS_H -#include #include +#include #include #include +#include "base/listener.h" +#include "base/modal_exception.h" #include "base/tls.h" +#include "options/language.h" +#include "options/printer_modes.h" #include "options/option_exception.h" namespace CVC4 { @@ -38,18 +42,90 @@ class CVC4_PUBLIC Options { /** The struct that holds all option values. */ options::OptionsHolder* d_holder; + /** The handler for the options of the theory. */ + options::OptionsHandler* d_handler; + /** The current Options in effect */ static CVC4_THREADLOCAL(Options*) s_current; + /** Listeners for options::forceLogicString being set. */ + ListenerCollection d_forceLogicListeners; + + /** Listeners for notifyBeforeSearch. */ + ListenerCollection d_beforeSearchListeners; + + /** Listeners for options::tlimit. */ + ListenerCollection d_tlimitListeners; + + /** Listeners for options::tlimit-per. */ + ListenerCollection d_tlimitPerListeners; + + /** Listeners for options::rlimit. */ + ListenerCollection d_rlimitListeners; + + /** Listeners for options::tlimit-per. */ + ListenerCollection d_rlimitPerListeners; + + /** Listeners for options::useTheoryList. */ + ListenerCollection d_useTheoryListListeners; + + /** Listeners for options::defaultExprDepth. */ + ListenerCollection d_setDefaultExprDepthListeners; + + /** Listeners for options::defaultDagThresh. */ + ListenerCollection d_setDefaultDagThreshListeners; + + /** Listeners for options::printExprTypes. */ + ListenerCollection d_setPrintExprTypesListeners; + + /** Listeners for options::dumpModeString. */ + ListenerCollection d_setDumpModeListeners; + + /** Listeners for options::printSuccess. */ + ListenerCollection d_setPrintSuccessListeners; + + /** Listeners for options::dumpToFileName. */ + ListenerCollection d_dumpToFileListeners; + + /** Listeners for options::regularChannelName. */ + ListenerCollection d_setRegularChannelListeners; + + /** Listeners for options::diagnosticChannelName. */ + ListenerCollection d_setDiagnosticChannelListeners; + + /** Listeners for options::replayFilename. */ + ListenerCollection d_setReplayFilenameListeners; + + + static ListenerCollection::Registration* registerAndNotify( + ListenerCollection& collection, Listener* listener, bool notify); + /** Low-level assignment function for options */ template - void assign(T, std::string option, std::string value, options::OptionsHandler* handler); + void assign(T, std::string option, std::string value); /** Low-level assignment function for bool-valued options */ template - void assignBool(T, std::string option, bool value, options::OptionsHandler* handler); + void assignBool(T, std::string option, bool value); friend class options::OptionsHandler; + /** + * Options cannot be copied as they are given an explicit list of + * Listeners to respond to. + */ + Options(const Options& options) CVC4_UNDEFINED; + + /** + * Options cannot be assigned as they are given an explicit list of + * Listeners to respond to. + */ + Options& operator=(const Options& options) CVC4_UNDEFINED; + + static std::string formatThreadOptionException(const std::string& option); + + static const size_t s_maxoptlen = 128; + static const unsigned s_preemptAdditional = 6; + public: class CVC4_PUBLIC OptionsScope { private: @@ -76,10 +152,14 @@ public: } Options(); - Options(const Options& options); ~Options(); - Options& operator=(const Options& options); + /** + * Copies the value of the options stored in OptionsHolder into the current + * Options object. + * This does not copy the listeners in the Options object. + */ + void copyValues(const Options& options); /** * Set the value of the given option. Use of this default @@ -93,10 +173,98 @@ public: T::you_are_trying_to_assign_to_a_read_only_option; } + /** + * Set the value of the given option by key. + */ + void setOption(const std::string& key, const std::string& optionarg) + throw(OptionException, ModalException); + + /** Get the value of the given option. Const access only. */ template const typename T::type& operator[](T) const; + /** + * Gets the value of the given option by key and returns value as a string. + */ + std::string getOption(const std::string& key) const + throw(OptionException); + + // Get accessor functions. + InputLanguage getInputLanguage() const; + InstFormatMode getInstFormatMode() const; + OutputLanguage getOutputLanguage() const; + bool getCheckProofs() const; + bool getContinuedExecution() const; + bool getDumpInstantiations() const; + bool getDumpModels() const; + bool getDumpProofs() const; + bool getDumpSynth() const; + bool getDumpUnsatCores() const; + bool getEarlyExit() const; + bool getFallbackSequential() const; + bool getFilesystemAccess() const; + bool getForceNoLimitCpuWhileDump() const; + bool getHelp() const; + bool getIncrementalParallel() const; + bool getIncrementalSolving() const; + bool getInteractive() const; + bool getInteractivePrompt() const; + bool getLanguageHelp() const; + bool getMemoryMap() const; + bool getParseOnly() const; + bool getProduceModels() const; + bool getProof() const; + bool getSegvSpin() const; + bool getSemanticChecks() const; + bool getStatistics() const; + bool getStatsEveryQuery() const; + bool getStatsHideZeros() const; + bool getStrictParsing() const; + bool getTearDownIncremental() const; + bool getVersion() const; + bool getWaitToJoin() const; + const std::string& getForceLogicString() const; + const std::vector& getThreadArgv() const; + int getSharingFilterByLength() const; + int getThreadId() const; + int getVerbosity() const; + std::istream* getIn() const; + std::ostream* getErr(); + std::ostream* getOut(); + std::ostream* getOutConst() const; // TODO: Remove this. + std::string getBinaryName() const; + std::string getReplayInputFilename() const; + unsigned getParseStep() const; + unsigned getThreadStackSize() const; + unsigned getThreads() const; + + + // TODO: Document these. + void setCeGuidedInst(bool); + void setDumpSynth(bool); + void setInputLanguage(InputLanguage); + void setInteractive(bool); + void setOut(std::ostream*); + void setOutputLanguage(OutputLanguage); + void setSharingFilterByLength(int length); + void setThreadId(int); + + bool wasSetByUserCeGuidedInst() const; + bool wasSetByUserDumpSynth() const; + bool wasSetByUserEarlyExit() const; + bool wasSetByUserForceLogicString() const; + bool wasSetByUserIncrementalSolving() const; + bool wasSetByUserInteractive() const; + bool wasSetByUserThreadStackSize() const; + bool wasSetByUserThreads() const; + + // Static accessor functions. + // TODO: Document these. + static int currentGetSharingFilterByLength(); + static int currentGetThreadId(); + static std::ostream* currentGetOut(); + /** * Returns true iff the value of the given option was set * by the user via a command-line option or SmtEngine::setOption(). @@ -150,13 +318,216 @@ public: * The return value is what's left of the command line (that is, the * non-option arguments). */ - std::vector parseOptions(int argc, char* argv[], options::OptionsHandler* handler) throw(OptionException); + std::vector parseOptions(int argc, char* argv[]) + throw(OptionException); /** * Get the setting for all options. */ std::vector< std::vector > getOptions() const throw(); + + /** + * Registers a listener for the notification, notifyBeforeSearch. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + * + * This has multiple usages so having a notifyIfSet flag does not add + * clarity. Users should check the relevant flags before registering this. + */ + ListenerCollection::Registration* registerBeforeSearchListener( + Listener* listener); + + + /** + * Registers a listener for options::forceLogic being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerForceLogicListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::tlimit being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerTlimitListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::tlimit-per being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerTlimitPerListener( + Listener* listener, bool notifyIfSet); + + + /** + * Registers a listener for options::rlimit being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerRlimitListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::rlimit-per being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerRlimitPerListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::useTheoryList being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerUseTheoryListListener( + Listener* listener, bool notifyIfSet); + + + /** + * Registers a listener for options::defaultExprDepth being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerSetDefaultExprDepthListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::defaultDagThresh being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerSetDefaultExprDagListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::printExprTypes being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerSetPrintExprTypesListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::dumpModeString being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerSetDumpModeListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::printSuccess being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerSetPrintSuccessListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::dumpToFileName being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerDumpToFileNameListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::regularChannelName being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerSetRegularOutputChannelListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::diagnosticChannelName being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerSetDiagnosticOutputChannelListener( + Listener* listener, bool notifyIfSet); + + /** + * Registers a listener for options::replayLogFilename being set. + * + * If notifyIfSet is true, this calls notify on the listener + * if the option was set by the user. + * + * The memory for the Registration is controlled by the user and must + * be destroyed before the Options object is. + */ + ListenerCollection::Registration* registerSetReplayLogFilename( + Listener* listener, bool notifyIfSet); + + /** Sends a std::flush to getErr(). */ + void flushErr(); + + /** Sends a std::flush to getOut(). */ + void flushOut(); + };/* class Options */ }/* CVC4 namespace */ diff --git a/src/options/options_handler_get_option_template.cpp b/src/options/options_get_option_template.cpp similarity index 86% rename from src/options/options_handler_get_option_template.cpp rename to src/options/options_get_option_template.cpp index b5da8c68d..b7e5433ee 100644 --- a/src/options/options_handler_get_option_template.cpp +++ b/src/options/options_get_option_template.cpp @@ -26,29 +26,28 @@ #include "base/output.h" #include "base/modal_exception.h" #include "options/option_exception.h" -#include "options/options_handler_interface.h" +#include "options/options.h" +#include "options/options_handler.h" ${include_all_option_headers} ${option_handler_includes} -#line 31 "${template}" +#line 37 "${template}" using namespace std; namespace CVC4 { -namespace options { -std::string OptionsHandler::getOption(const std::string& key) const +std::string Options::getOption(const std::string& key) const throw(OptionException) { Trace("options") << "SMT getOption(" << key << ")" << endl; ${smt_getoption_handlers} -#line 57 "${template}" +#line 49 "${template}" throw UnrecognizedOptionException(key); } -}/* options namespace */ }/* CVC4 namespace */ diff --git a/src/smt/smt_options_handler.cpp b/src/options/options_handler.cpp similarity index 59% rename from src/smt/smt_options_handler.cpp rename to src/options/options_handler.cpp index 758ffaec8..1c48f4bb1 100644 --- a/src/smt/smt_options_handler.cpp +++ b/src/options/options_handler.cpp @@ -1,5 +1,5 @@ /********************* */ -/*! \file options_handler_interface.cpp +/*! \file options_handler.cpp ** \verbatim ** Original author: Tim King ** Major contributors: none @@ -14,20 +14,19 @@ ** Interface for custom handlers and predicates options. **/ -#include "smt/smt_options_handler.h" +#include "options/options_handler.h" -#include -#include #include -#include #include +#include + +#include "cvc4autoconfig.h" +#include "base/configuration.h" +#include "base/cvc4_assert.h" +#include "base/exception.h" #include "base/modal_exception.h" #include "base/output.h" -#include "cvc4autoconfig.h" -#include "expr/expr_iomanip.h" -#include "expr/metakind.h" -#include "expr/node_manager.h" #include "lib/strtok_r.h" #include "options/arith_heuristic_pivot_rule.h" #include "options/arith_propagation_mode.h" @@ -40,40 +39,104 @@ #include "options/decision_options.h" #include "options/didyoumean.h" #include "options/language.h" -#include "options/main_options.h" #include "options/option_exception.h" -#include "options/options_handler_interface.h" -#include "options/parser_options.h" #include "options/printer_modes.h" #include "options/quantifiers_modes.h" -#include "options/set_language.h" #include "options/simplification_mode.h" #include "options/smt_options.h" #include "options/theory_options.h" #include "options/theoryof_mode.h" #include "options/ufss_mode.h" -#include "smt/smt_engine.h" -#include "smt_util/command.h" -#include "smt_util/dump.h" -#include "theory/logic_info.h" -#include "util/configuration.h" -#include "util/configuration_private.h" -#include "util/resource_manager.h" +namespace CVC4 { +namespace options { -#warning "TODO: Make SmtOptionsHandler non-public and refactor driver unified." +OptionsHandler::OptionsHandler(Options* options) : d_options(options) { } -namespace CVC4 { -namespace smt { +void OptionsHandler::notifyForceLogic(const std::string& option){ + d_options->d_forceLogicListeners.notify(); +} + +void OptionsHandler::notifyBeforeSearch(const std::string& option) + throw(ModalException) +{ + try{ + d_options->d_beforeSearchListeners.notify(); + } catch (ModalException&){ + std::stringstream ss; + ss << "cannot change option `" << option + << "' after final initialization (i.e., after logic has been set)"; + throw ModalException(ss.str()); + } +} + + +void OptionsHandler::notifyTlimit(const std::string& option) { + d_options->d_tlimitListeners.notify(); +} + +void OptionsHandler::notifyTlimitPer(const std::string& option) { + d_options->d_tlimitPerListeners.notify(); +} + +void OptionsHandler::notifyRlimit(const std::string& option) { + d_options->d_rlimitListeners.notify(); +} + +void OptionsHandler::notifyRlimitPer(const std::string& option) { + d_options->d_rlimitPerListeners.notify(); +} + + +unsigned long OptionsHandler::tlimitHandler(std::string option, std::string optarg) throw(OptionException) { + unsigned long ms; + std::istringstream convert(optarg); + if (!(convert >> ms)) { + throw OptionException("option `"+option+"` requires a number as an argument"); + } + return ms; +} + +unsigned long OptionsHandler::tlimitPerHandler(std::string option, std::string optarg) throw(OptionException) { + unsigned long ms; + + std::istringstream convert(optarg); + if (!(convert >> ms)) { + throw OptionException("option `"+option+"` requires a number as an argument"); + } + return ms; +} + +unsigned long OptionsHandler::rlimitHandler(std::string option, std::string optarg) throw(OptionException) { + unsigned long ms; + + std::istringstream convert(optarg); + if (!(convert >> ms)) { + throw OptionException("option `"+option+"` requires a number as an argument"); + } + return ms; +} -SmtOptionsHandler::SmtOptionsHandler(SmtEngine* smt) - : d_smtEngine(smt) -{} -SmtOptionsHandler::~SmtOptionsHandler(){} +unsigned long OptionsHandler::rlimitPerHandler(std::string option, std::string optarg) throw(OptionException) { + unsigned long ms; + + std::istringstream convert(optarg); + if (!(convert >> ms)) { + throw OptionException("option `"+option+"` requires a number as an argument"); + } + + return ms; +} + + +/* options/base_options_handlers.h */ +void OptionsHandler::notifyPrintSuccess(std::string option) { + d_options->d_setPrintSuccessListeners.notify(); +} // theory/arith/options_handlers.h -const std::string SmtOptionsHandler::s_arithUnateLemmasHelp = "\ +const std::string OptionsHandler::s_arithUnateLemmasHelp = "\ Unate lemmas are generated before SAT search begins using the relationship\n\ of constant terms and polynomials.\n\ Modes currently supported by the --unate-lemmas option:\n\ @@ -88,7 +151,7 @@ Modes currently supported by the --unate-lemmas option:\n\ A combination of inequalities and equalities.\n\ "; -const std::string SmtOptionsHandler::s_arithPropagationModeHelp = "\ +const std::string OptionsHandler::s_arithPropagationModeHelp = "\ This decides on kind of propagation arithmetic attempts to do during the search.\n\ + none\n\ + unate\n\ @@ -99,7 +162,7 @@ This decides on kind of propagation arithmetic attempts to do during the search. +both\n\ "; -const std::string SmtOptionsHandler::s_errorSelectionRulesHelp = "\ +const std::string OptionsHandler::s_errorSelectionRulesHelp = "\ This decides on the rule used by simplex during heuristic rounds\n\ for deciding the next basic variable to select.\n\ Heuristic pivot rules available:\n\ @@ -111,7 +174,7 @@ Heuristic pivot rules available:\n\ The variable order\n\ "; -ArithUnateLemmaMode SmtOptionsHandler::stringToArithUnateLemmaMode(std::string option, std::string optarg) throw(OptionException) { +ArithUnateLemmaMode OptionsHandler::stringToArithUnateLemmaMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "all") { return ALL_PRESOLVE_LEMMAS; } else if(optarg == "none") { @@ -129,7 +192,7 @@ ArithUnateLemmaMode SmtOptionsHandler::stringToArithUnateLemmaMode(std::string o } } -ArithPropagationMode SmtOptionsHandler::stringToArithPropagationMode(std::string option, std::string optarg) throw(OptionException) { +ArithPropagationMode OptionsHandler::stringToArithPropagationMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "none") { return NO_PROP; } else if(optarg == "unate") { @@ -147,7 +210,7 @@ ArithPropagationMode SmtOptionsHandler::stringToArithPropagationMode(std::string } } -ErrorSelectionRule SmtOptionsHandler::stringToErrorSelectionRule(std::string option, std::string optarg) throw(OptionException) { +ErrorSelectionRule OptionsHandler::stringToErrorSelectionRule(std::string option, std::string optarg) throw(OptionException) { if(optarg == "min") { return MINIMUM_AMOUNT; } else if(optarg == "varord") { @@ -162,10 +225,9 @@ ErrorSelectionRule SmtOptionsHandler::stringToErrorSelectionRule(std::string opt optarg + "'. Try --heuristic-pivot-rule help."); } } - // theory/quantifiers/options_handlers.h -const std::string SmtOptionsHandler::s_instWhenHelp = "\ +const std::string OptionsHandler::s_instWhenHelp = "\ Modes currently supported by the --inst-when option:\n\ \n\ full-last-call (default)\n\ @@ -189,7 +251,7 @@ last-call\n\ \n\ "; -const std::string SmtOptionsHandler::s_literalMatchHelp = "\ +const std::string OptionsHandler::s_literalMatchHelp = "\ Literal match modes currently supported by the --literal-match option:\n\ \n\ none (default)\n\ @@ -204,7 +266,7 @@ predicate\n\ \n\ "; -const std::string SmtOptionsHandler::s_mbqiModeHelp = "\ +const std::string OptionsHandler::s_mbqiModeHelp = "\ Model-based quantifier instantiation modes currently supported by the --mbqi option:\n\ \n\ default \n\ @@ -226,7 +288,7 @@ abs \n\ \n\ "; -const std::string SmtOptionsHandler::s_qcfWhenModeHelp = "\ +const std::string OptionsHandler::s_qcfWhenModeHelp = "\ Quantifier conflict find modes currently supported by the --quant-cf-when option:\n\ \n\ default \n\ @@ -244,7 +306,7 @@ std-h \n\ \n\ "; -const std::string SmtOptionsHandler::s_qcfModeHelp = "\ +const std::string OptionsHandler::s_qcfModeHelp = "\ Quantifier conflict find modes currently supported by the --quant-cf option:\n\ \n\ prop-eq \n\ @@ -261,7 +323,7 @@ mc \n\ \n\ "; -const std::string SmtOptionsHandler::s_userPatModeHelp = "\ +const std::string OptionsHandler::s_userPatModeHelp = "\ User pattern modes currently supported by the --user-pat option:\n\ \n\ trust \n\ @@ -282,7 +344,7 @@ interleave \n\ \n\ "; -const std::string SmtOptionsHandler::s_triggerSelModeHelp = "\ +const std::string OptionsHandler::s_triggerSelModeHelp = "\ Trigger selection modes currently supported by the --trigger-sel option:\n\ \n\ default \n\ @@ -295,7 +357,7 @@ max \n\ + Consider only maximal subterms that meet criteria for triggers. \n\ \n\ "; -const std::string SmtOptionsHandler::s_prenexQuantModeHelp = "\ +const std::string OptionsHandler::s_prenexQuantModeHelp = "\ Prenex quantifiers modes currently supported by the --prenex-quant option:\n\ \n\ default \n\ @@ -309,7 +371,7 @@ none \n\ \n\ "; -const std::string SmtOptionsHandler::s_cegqiFairModeHelp = "\ +const std::string OptionsHandler::s_cegqiFairModeHelp = "\ Modes for enforcing fairness for counterexample guided quantifier instantion, supported by --cegqi-fair:\n\ \n\ uf-dt-size \n\ @@ -326,7 +388,7 @@ none \n\ \n\ "; -const std::string SmtOptionsHandler::s_termDbModeHelp = "\ +const std::string OptionsHandler::s_termDbModeHelp = "\ Modes for term database, supported by --term-db-mode:\n\ \n\ all \n\ @@ -337,7 +399,7 @@ relevant \n\ \n\ "; -const std::string SmtOptionsHandler::s_iteLiftQuantHelp = "\ +const std::string OptionsHandler::s_iteLiftQuantHelp = "\ Modes for term database, supported by --ite-lift-quant:\n\ \n\ none \n\ @@ -351,7 +413,7 @@ all \n\ \n\ "; -const std::string SmtOptionsHandler::s_sygusInvTemplHelp = "\ +const std::string OptionsHandler::s_sygusInvTemplHelp = "\ Template modes for sygus invariant synthesis, supported by --sygus-inv-templ:\n\ \n\ none \n\ @@ -365,7 +427,7 @@ post \n\ \n\ "; -const std::string SmtOptionsHandler::s_macrosQuantHelp = "\ +const std::string OptionsHandler::s_macrosQuantHelp = "\ Template modes for quantifiers macro expansion, supported by --macros-quant-mode:\n\ \n\ all \n\ @@ -379,7 +441,7 @@ ground-uf \n\ \n\ "; -theory::quantifiers::InstWhenMode SmtOptionsHandler::stringToInstWhenMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::InstWhenMode OptionsHandler::stringToInstWhenMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "pre-full") { return theory::quantifiers::INST_WHEN_PRE_FULL; } else if(optarg == "full") { @@ -401,13 +463,13 @@ theory::quantifiers::InstWhenMode SmtOptionsHandler::stringToInstWhenMode(std::s } } -void SmtOptionsHandler::checkInstWhenMode(std::string option, theory::quantifiers::InstWhenMode mode) throw(OptionException) { +void OptionsHandler::checkInstWhenMode(std::string option, theory::quantifiers::InstWhenMode mode) throw(OptionException) { if(mode == theory::quantifiers::INST_WHEN_PRE_FULL) { throw OptionException(std::string("Mode pre-full for ") + option + " is not supported in this release."); } } -theory::quantifiers::LiteralMatchMode SmtOptionsHandler::stringToLiteralMatchMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::LiteralMatchMode OptionsHandler::stringToLiteralMatchMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "none") { return theory::quantifiers::LITERAL_MATCH_NONE; } else if(optarg == "predicate") { @@ -423,13 +485,13 @@ theory::quantifiers::LiteralMatchMode SmtOptionsHandler::stringToLiteralMatchMod } } -void SmtOptionsHandler::checkLiteralMatchMode(std::string option, theory::quantifiers::LiteralMatchMode mode) throw(OptionException) { +void OptionsHandler::checkLiteralMatchMode(std::string option, theory::quantifiers::LiteralMatchMode mode) throw(OptionException) { if(mode == theory::quantifiers::LITERAL_MATCH_EQUALITY) { throw OptionException(std::string("Mode equality for ") + option + " is not supported in this release."); } } -theory::quantifiers::MbqiMode SmtOptionsHandler::stringToMbqiMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::MbqiMode OptionsHandler::stringToMbqiMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "gen-ev") { return theory::quantifiers::MBQI_GEN_EVAL; } else if(optarg == "none") { @@ -452,10 +514,10 @@ theory::quantifiers::MbqiMode SmtOptionsHandler::stringToMbqiMode(std::string op } -void SmtOptionsHandler::checkMbqiMode(std::string option, theory::quantifiers::MbqiMode mode) throw(OptionException) {} +void OptionsHandler::checkMbqiMode(std::string option, theory::quantifiers::MbqiMode mode) throw(OptionException) {} -theory::quantifiers::QcfWhenMode SmtOptionsHandler::stringToQcfWhenMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::QcfWhenMode OptionsHandler::stringToQcfWhenMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "default") { return theory::quantifiers::QCF_WHEN_MODE_DEFAULT; } else if(optarg == "last-call") { @@ -473,7 +535,7 @@ theory::quantifiers::QcfWhenMode SmtOptionsHandler::stringToQcfWhenMode(std::str } } -theory::quantifiers::QcfMode SmtOptionsHandler::stringToQcfMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::QcfMode OptionsHandler::stringToQcfMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "conflict") { return theory::quantifiers::QCF_CONFLICT_ONLY; } else if(optarg == "default" || optarg == "prop-eq") { @@ -491,7 +553,7 @@ theory::quantifiers::QcfMode SmtOptionsHandler::stringToQcfMode(std::string opti } } -theory::quantifiers::UserPatMode SmtOptionsHandler::stringToUserPatMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::UserPatMode OptionsHandler::stringToUserPatMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "use") { return theory::quantifiers::USER_PAT_MODE_USE; } else if(optarg == "default" || optarg == "trust") { @@ -511,7 +573,7 @@ theory::quantifiers::UserPatMode SmtOptionsHandler::stringToUserPatMode(std::str } } -theory::quantifiers::TriggerSelMode SmtOptionsHandler::stringToTriggerSelMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::TriggerSelMode OptionsHandler::stringToTriggerSelMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "default" || optarg == "all" ) { return theory::quantifiers::TRIGGER_SEL_DEFAULT; } else if(optarg == "min") { @@ -528,7 +590,7 @@ theory::quantifiers::TriggerSelMode SmtOptionsHandler::stringToTriggerSelMode(st } -theory::quantifiers::PrenexQuantMode SmtOptionsHandler::stringToPrenexQuantMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::PrenexQuantMode OptionsHandler::stringToPrenexQuantMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "default" ) { return theory::quantifiers::PRENEX_NO_USER_PAT; } else if(optarg == "all") { @@ -544,7 +606,7 @@ theory::quantifiers::PrenexQuantMode SmtOptionsHandler::stringToPrenexQuantMode( } } -theory::quantifiers::CegqiFairMode SmtOptionsHandler::stringToCegqiFairMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::CegqiFairMode OptionsHandler::stringToCegqiFairMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "uf-dt-size" ) { return theory::quantifiers::CEGQI_FAIR_UF_DT_SIZE; } else if(optarg == "default" || optarg == "dt-size") { @@ -562,7 +624,7 @@ theory::quantifiers::CegqiFairMode SmtOptionsHandler::stringToCegqiFairMode(std: } } -theory::quantifiers::TermDbMode SmtOptionsHandler::stringToTermDbMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::TermDbMode OptionsHandler::stringToTermDbMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "all" ) { return theory::quantifiers::TERM_DB_ALL; } else if(optarg == "relevant") { @@ -576,7 +638,7 @@ theory::quantifiers::TermDbMode SmtOptionsHandler::stringToTermDbMode(std::strin } } -theory::quantifiers::IteLiftQuantMode SmtOptionsHandler::stringToIteLiftQuantMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::IteLiftQuantMode OptionsHandler::stringToIteLiftQuantMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "all" ) { return theory::quantifiers::ITE_LIFT_QUANT_MODE_ALL; } else if(optarg == "simple") { @@ -592,7 +654,7 @@ theory::quantifiers::IteLiftQuantMode SmtOptionsHandler::stringToIteLiftQuantMod } } -theory::quantifiers::SygusInvTemplMode SmtOptionsHandler::stringToSygusInvTemplMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::SygusInvTemplMode OptionsHandler::stringToSygusInvTemplMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "none" ) { return theory::quantifiers::SYGUS_INV_TEMPL_MODE_NONE; } else if(optarg == "pre") { @@ -608,7 +670,7 @@ theory::quantifiers::SygusInvTemplMode SmtOptionsHandler::stringToSygusInvTemplM } } -theory::quantifiers::MacrosQuantMode SmtOptionsHandler::stringToMacrosQuantMode(std::string option, std::string optarg) throw(OptionException) { +theory::quantifiers::MacrosQuantMode OptionsHandler::stringToMacrosQuantMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "all" ) { return theory::quantifiers::MACROS_QUANT_MODE_ALL; } else if(optarg == "ground") { @@ -625,9 +687,8 @@ theory::quantifiers::MacrosQuantMode SmtOptionsHandler::stringToMacrosQuantMode( } - // theory/bv/options_handlers.h -void SmtOptionsHandler::abcEnabledBuild(std::string option, bool value) throw(OptionException) { +void OptionsHandler::abcEnabledBuild(std::string option, bool value) throw(OptionException) { #ifndef CVC4_USE_ABC if(value) { std::stringstream ss; @@ -637,7 +698,7 @@ void SmtOptionsHandler::abcEnabledBuild(std::string option, bool value) throw(Op #endif /* CVC4_USE_ABC */ } -void SmtOptionsHandler::abcEnabledBuild(std::string option, std::string value) throw(OptionException) { +void OptionsHandler::abcEnabledBuild(std::string option, std::string value) throw(OptionException) { #ifndef CVC4_USE_ABC if(!value.empty()) { std::stringstream ss; @@ -647,7 +708,7 @@ void SmtOptionsHandler::abcEnabledBuild(std::string option, std::string value) t #endif /* CVC4_USE_ABC */ } -const std::string SmtOptionsHandler::s_bitblastingModeHelp = "\ +const std::string OptionsHandler::s_bitblastingModeHelp = "\ Bit-blasting modes currently supported by the --bitblast option:\n\ \n\ lazy (default)\n\ @@ -658,7 +719,7 @@ eager\n\ + Bitblast eagerly to bv SAT solver\n\ "; -theory::bv::BitblastMode SmtOptionsHandler::stringToBitblastMode(std::string option, std::string optarg) throw(OptionException) { +theory::bv::BitblastMode OptionsHandler::stringToBitblastMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "lazy") { if (!options::bitvectorPropagate.wasSetByUser()) { options::bitvectorPropagate.set(true); @@ -708,7 +769,7 @@ theory::bv::BitblastMode SmtOptionsHandler::stringToBitblastMode(std::string opt } } -const std::string SmtOptionsHandler::s_bvSlicerModeHelp = "\ +const std::string OptionsHandler::s_bvSlicerModeHelp = "\ Bit-vector equality slicer modes supported by the --bv-eq-slicer option:\n\ \n\ auto (default)\n\ @@ -721,7 +782,7 @@ off\n\ + Turn slicer off\n\ "; -theory::bv::BvSlicerMode SmtOptionsHandler::stringToBvSlicerMode(std::string option, std::string optarg) throw(OptionException) { +theory::bv::BvSlicerMode OptionsHandler::stringToBvSlicerMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "auto") { return theory::bv::BITVECTOR_SLICER_AUTO; } else if(optarg == "on") { @@ -737,7 +798,7 @@ theory::bv::BvSlicerMode SmtOptionsHandler::stringToBvSlicerMode(std::string opt } } -void SmtOptionsHandler::setBitblastAig(std::string option, bool arg) throw(OptionException) { +void OptionsHandler::setBitblastAig(std::string option, bool arg) throw(OptionException) { if(arg) { if(options::bitblastMode.wasSetByUser()) { if(options::bitblastMode() != theory::bv::BITBLAST_MODE_EAGER) { @@ -755,7 +816,7 @@ void SmtOptionsHandler::setBitblastAig(std::string option, bool arg) throw(Optio // theory/booleans/options_handlers.h -const std::string SmtOptionsHandler::s_booleanTermConversionModeHelp = "\ +const std::string OptionsHandler::s_booleanTermConversionModeHelp = "\ Boolean term conversion modes currently supported by the\n\ --boolean-term-conversion-mode option:\n\ \n\ @@ -771,7 +832,7 @@ native\n\ Elsewhere, they are converted to a bitvector of size 1.\n\ "; -theory::booleans::BooleanTermConversionMode SmtOptionsHandler::stringToBooleanTermConversionMode(std::string option, std::string optarg) throw(OptionException){ +theory::booleans::BooleanTermConversionMode OptionsHandler::stringToBooleanTermConversionMode(std::string option, std::string optarg) throw(OptionException){ if(optarg == "bitvectors") { return theory::booleans::BOOLEAN_TERM_CONVERT_TO_BITVECTORS; } else if(optarg == "datatypes") { @@ -787,8 +848,9 @@ theory::booleans::BooleanTermConversionMode SmtOptionsHandler::stringToBooleanTe } } + // theory/uf/options_handlers.h -const std::string SmtOptionsHandler::s_ufssModeHelp = "\ +const std::string OptionsHandler::s_ufssModeHelp = "\ UF strong solver options currently supported by the --uf-ss option:\n\ \n\ full \n\ @@ -802,7 +864,7 @@ none \n\ \n\ "; -theory::uf::UfssMode SmtOptionsHandler::stringToUfssMode(std::string option, std::string optarg) throw(OptionException) { +theory::uf::UfssMode OptionsHandler::stringToUfssMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "default" || optarg == "full" ) { return theory::uf::UF_SS_FULL; } else if(optarg == "no-minimal") { @@ -821,7 +883,7 @@ theory::uf::UfssMode SmtOptionsHandler::stringToUfssMode(std::string option, std // theory/options_handlers.h -const std::string SmtOptionsHandler::s_theoryOfModeHelp = "\ +const std::string OptionsHandler::s_theoryOfModeHelp = "\ TheoryOf modes currently supported by the --theoryof-mode option:\n\ \n\ type (default) \n\ @@ -831,7 +893,7 @@ term \n\ + type variables as uninterpreted, equalities by the parametric theory\n\ "; -theory::TheoryOfMode SmtOptionsHandler::stringToTheoryOfMode(std::string option, std::string optarg) { +theory::TheoryOfMode OptionsHandler::stringToTheoryOfMode(std::string option, std::string optarg) { if(optarg == "type") { return theory::THEORY_OF_TYPE_BASED; } else if(optarg == "term") { @@ -845,25 +907,24 @@ theory::TheoryOfMode SmtOptionsHandler::stringToTheoryOfMode(std::string option, } } -void SmtOptionsHandler::useTheory(std::string option, std::string optarg) { - if(optarg == "help") { - puts(theory::useTheoryHelp); - exit(1); - } - if(theory::useTheoryValidate(optarg)) { - std::map m = options::theoryAlternates(); - m[optarg] = true; - options::theoryAlternates.set(m); +// theory/options_handlers.h +std::string OptionsHandler::handleUseTheoryList(std::string option, std::string optarg) { + std::string currentList = options::useTheoryList(); + if(currentList.empty()){ + return optarg; } else { - throw OptionException(std::string("unknown option for ") + option + ": `" + - optarg + "'. Try --use-theory help."); + return currentList +','+ optarg; } } +void OptionsHandler::notifyUseTheoryList(std::string option) { + d_options->d_useTheoryListListeners.notify(); +} + // printer/options_handlers.h -const std::string SmtOptionsHandler::s_modelFormatHelp = "\ +const std::string OptionsHandler::s_modelFormatHelp = "\ Model format modes currently supported by the --model-format option:\n\ \n\ default \n\ @@ -873,7 +934,7 @@ table\n\ + Print functional expressions over finite domains in a table format.\n\ "; -const std::string SmtOptionsHandler::s_instFormatHelp = "\ +const std::string OptionsHandler::s_instFormatHelp = "\ Inst format modes currently supported by the --model-format option:\n\ \n\ default \n\ @@ -883,7 +944,7 @@ szs\n\ + Print instantiations as SZS compliant proof.\n\ "; -ModelFormatMode SmtOptionsHandler::stringToModelFormatMode(std::string option, std::string optarg) throw(OptionException) { +ModelFormatMode OptionsHandler::stringToModelFormatMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "default") { return MODEL_FORMAT_MODE_DEFAULT; } else if(optarg == "table") { @@ -897,7 +958,7 @@ ModelFormatMode SmtOptionsHandler::stringToModelFormatMode(std::string option, s } } -InstFormatMode SmtOptionsHandler::stringToInstFormatMode(std::string option, std::string optarg) throw(OptionException) { +InstFormatMode OptionsHandler::stringToInstFormatMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "default") { return INST_FORMAT_MODE_DEFAULT; } else if(optarg == "szs") { @@ -912,9 +973,8 @@ InstFormatMode SmtOptionsHandler::stringToInstFormatMode(std::string option, std } - // decision/options_handlers.h -const std::string SmtOptionsHandler::s_decisionModeHelp = "\ +const std::string OptionsHandler::s_decisionModeHelp = "\ Decision modes currently supported by the --decision option:\n\ \n\ internal (default)\n\ @@ -927,7 +987,7 @@ justification-stoponly\n\ + Use the justification heuristic only to stop early, not for decisions\n\ "; -decision::DecisionMode SmtOptionsHandler::stringToDecisionMode(std::string option, std::string optarg) throw(OptionException) { +decision::DecisionMode OptionsHandler::stringToDecisionMode(std::string option, std::string optarg) throw(OptionException) { options::decisionStopOnly.set(false); if(optarg == "internal") { @@ -946,7 +1006,7 @@ decision::DecisionMode SmtOptionsHandler::stringToDecisionMode(std::string optio } } -decision::DecisionWeightInternal SmtOptionsHandler::stringToDecisionWeightInternal(std::string option, std::string optarg) throw(OptionException) { +decision::DecisionWeightInternal OptionsHandler::stringToDecisionWeightInternal(std::string option, std::string optarg) throw(OptionException) { if(optarg == "off") return decision::DECISION_WEIGHT_INTERNAL_OFF; else if(optarg == "max") @@ -960,91 +1020,8 @@ decision::DecisionWeightInternal SmtOptionsHandler::stringToDecisionWeightIntern } - // smt/options_handlers.h -const std::string SmtOptionsHandler::SmtOptionsHandler::s_dumpHelp = "\ -Dump modes currently supported by the --dump option:\n\ -\n\ -benchmark\n\ -+ Dump the benchmark structure (set-logic, push/pop, queries, etc.), but\n\ - does not include any declarations or assertions. Implied by all following\n\ - modes.\n\ -\n\ -declarations\n\ -+ Dump user declarations. Implied by all following modes.\n\ -\n\ -skolems\n\ -+ Dump internally-created skolem variable declarations. These can\n\ - arise from preprocessing simplifications, existential elimination,\n\ - and a number of other things. Implied by all following modes.\n\ -\n\ -assertions\n\ -+ Output the assertions after preprocessing and before clausification.\n\ - Can also specify \"assertions:pre-PASS\" or \"assertions:post-PASS\",\n\ - where PASS is one of the preprocessing passes: definition-expansion\n\ - boolean-terms constrain-subtypes substitution strings-pp skolem-quant\n\ - simplify static-learning ite-removal repeat-simplify\n\ - rewrite-apply-to-const theory-preprocessing.\n\ - PASS can also be the special value \"everything\", in which case the\n\ - assertions are printed before any preprocessing (with\n\ - \"assertions:pre-everything\") or after all preprocessing completes\n\ - (with \"assertions:post-everything\").\n\ -\n\ -clauses\n\ -+ Do all the preprocessing outlined above, and dump the CNF-converted\n\ - output\n\ -\n\ -state\n\ -+ Dump all contextual assertions (e.g., SAT decisions, propagations..).\n\ - Implied by all \"stateful\" modes below and conflicts with all\n\ - non-stateful modes below.\n\ -\n\ -t-conflicts [non-stateful]\n\ -+ Output correctness queries for all theory conflicts\n\ -\n\ -missed-t-conflicts [stateful]\n\ -+ Output completeness queries for theory conflicts\n\ -\n\ -t-propagations [stateful]\n\ -+ Output correctness queries for all theory propagations\n\ -\n\ -missed-t-propagations [stateful]\n\ -+ Output completeness queries for theory propagations (LARGE and EXPENSIVE)\n\ -\n\ -t-lemmas [non-stateful]\n\ -+ Output correctness queries for all theory lemmas\n\ -\n\ -t-explanations [non-stateful]\n\ -+ Output correctness queries for all theory explanations\n\ -\n\ -bv-rewrites [non-stateful]\n\ -+ Output correctness queries for all bitvector rewrites\n\ -\n\ -bv-abstraction [non-stateful]\n\ -+ Output correctness queries for all bv abstraction \n\ -\n\ -bv-algebraic [non-stateful]\n\ -+ Output correctness queries for bv algebraic solver. \n\ -\n\ -theory::fullcheck [non-stateful]\n \ -+ Output completeness queries for all full-check effort-level theory checks\n\ -\n\ -Dump modes can be combined with multiple uses of --dump. Generally you want\n\ -one from the assertions category (either assertions or clauses), and\n\ -perhaps one or more stateful or non-stateful modes for checking correctness\n\ -and completeness of decision procedure implementations. Stateful modes dump\n\ -the contextual assertions made by the core solver (all decisions and\n\ -propagations as assertions; that affects the validity of the resulting\n\ -correctness and completeness queries, so of course stateful and non-stateful\n\ -modes cannot be mixed in the same run.\n\ -\n\ -The --output-language option controls the language used for dumping, and\n\ -this allows you to connect CVC4 to another solver implementation via a UNIX\n\ -pipe to perform on-line checking. The --dump-to option can be used to dump\n\ -to a file.\n\ -"; - -const std::string SmtOptionsHandler::s_simplificationHelp = "\ +const std::string OptionsHandler::s_simplificationHelp = "\ Simplification modes currently supported by the --simplification option:\n\ \n\ batch (default) \n\ @@ -1056,127 +1033,9 @@ none\n\ + do not perform nonclausal simplification\n\ "; -void SmtOptionsHandler::dumpMode(std::string option, std::string optarg) { -#ifdef CVC4_DUMPING - char* optargPtr = strdup(optarg.c_str()); - char* tokstr = optargPtr; - char* toksave; - while((optargPtr = strtok_r(tokstr, ",", &toksave)) != NULL) { - tokstr = NULL; - if(!strcmp(optargPtr, "benchmark")) { - } else if(!strcmp(optargPtr, "declarations")) { - } else if(!strcmp(optargPtr, "assertions")) { - Dump.on("assertions:post-everything"); - } else if(!strncmp(optargPtr, "assertions:", 11)) { - const char* p = optargPtr + 11; - if(!strncmp(p, "pre-", 4)) { - p += 4; - } else if(!strncmp(p, "post-", 5)) { - p += 5; - } else { - throw OptionException(std::string("don't know how to dump `") + - optargPtr + "'. Please consult --dump help."); - } - if(!strcmp(p, "everything")) { - } else if(!strcmp(p, "definition-expansion")) { - } else if(!strcmp(p, "boolean-terms")) { - } else if(!strcmp(p, "constrain-subtypes")) { - } else if(!strcmp(p, "substitution")) { - } else if(!strcmp(p, "strings-pp")) { - } else if(!strcmp(p, "skolem-quant")) { - } else if(!strcmp(p, "simplify")) { - } else if(!strcmp(p, "static-learning")) { - } else if(!strcmp(p, "ite-removal")) { - } else if(!strcmp(p, "repeat-simplify")) { - } else if(!strcmp(p, "rewrite-apply-to-const")) { - } else if(!strcmp(p, "theory-preprocessing")) { - } else if(!strcmp(p, "nonclausal")) { - } else if(!strcmp(p, "theorypp")) { - } else if(!strcmp(p, "itesimp")) { - } else if(!strcmp(p, "unconstrained")) { - } else if(!strcmp(p, "repeatsimp")) { - } else { - throw OptionException(std::string("don't know how to dump `") + - optargPtr + "'. Please consult --dump help."); - } - Dump.on("assertions"); - } else if(!strcmp(optargPtr, "skolems")) { - } else if(!strcmp(optargPtr, "clauses")) { - } else if(!strcmp(optargPtr, "t-conflicts") || - !strcmp(optargPtr, "t-lemmas") || - !strcmp(optargPtr, "t-explanations") || - !strcmp(optargPtr, "bv-rewrites") || - !strcmp(optargPtr, "theory::fullcheck")) { - // These are "non-state-dumping" modes. If state (SAT decisions, - // propagations, etc.) is dumped, it will interfere with the validity - // of these generated queries. - if(Dump.isOn("state")) { - throw OptionException(std::string("dump option `") + optargPtr + - "' conflicts with a previous, " - "state-dumping dump option. You cannot " - "mix stateful and non-stateful dumping modes; " - "see --dump help."); - } else { - Dump.on("no-permit-state"); - } - } else if(!strcmp(optargPtr, "state") || - !strcmp(optargPtr, "missed-t-conflicts") || - !strcmp(optargPtr, "t-propagations") || - !strcmp(optargPtr, "missed-t-propagations")) { - // These are "state-dumping" modes. If state (SAT decisions, - // propagations, etc.) is not dumped, it will interfere with the - // validity of these generated queries. - if(Dump.isOn("no-permit-state")) { - throw OptionException(std::string("dump option `") + optargPtr + - "' conflicts with a previous, " - "non-state-dumping dump option. You cannot " - "mix stateful and non-stateful dumping modes; " - "see --dump help."); - } else { - Dump.on("state"); - } - } else if(!strcmp(optargPtr, "help")) { - puts(s_dumpHelp.c_str()); - exit(1); - } else if(!strcmp(optargPtr, "bv-abstraction")) { - Dump.on("bv-abstraction"); - } else if(!strcmp(optargPtr, "bv-algebraic")) { - Dump.on("bv-algebraic"); - } else { - throw OptionException(std::string("unknown option for --dump: `") + - optargPtr + "'. Try --dump help."); - } - - Dump.on(optargPtr); - Dump.on("benchmark"); - if(strcmp(optargPtr, "benchmark")) { - Dump.on("declarations"); - if(strcmp(optargPtr, "declarations")) { - Dump.on("skolems"); - } - } - } - free(optargPtr); -#else /* CVC4_DUMPING */ - throw OptionException("The dumping feature was disabled in this build of CVC4."); -#endif /* CVC4_DUMPING */ -} -LogicInfo* SmtOptionsHandler::stringToLogicInfo(std::string option, std::string optarg) throw(OptionException) { - try { -#warning "TODO: Fix the blatant memory leak here." - LogicInfo* logic = new LogicInfo(optarg); - if(d_smtEngine != NULL) { - d_smtEngine->setLogic(*logic); - } - return logic; - } catch(IllegalArgumentException& e) { - throw OptionException(std::string("invalid logic specification for --force-logic: `") + - optarg + "':\n" + e.what()); - } -} -SimplificationMode SmtOptionsHandler::stringToSimplificationMode(std::string option, std::string optarg) throw(OptionException) { +SimplificationMode OptionsHandler::stringToSimplificationMode(std::string option, std::string optarg) throw(OptionException) { if(optarg == "batch") { return SIMPLIFICATION_MODE_BATCH; } else if(optarg == "none") { @@ -1191,121 +1050,37 @@ SimplificationMode SmtOptionsHandler::stringToSimplificationMode(std::string opt } -void SmtOptionsHandler::beforeSearch(std::string option, bool value) throw(ModalException) { - SmtEngine::beforeSearch(d_smtEngine, option); -} - -void SmtOptionsHandler::setProduceAssertions(std::string option, bool value) throw() { +void OptionsHandler::setProduceAssertions(std::string option, bool value) throw() { options::produceAssertions.set(value); options::interactiveMode.set(value); } -void SmtOptionsHandler::proofEnabledBuild(std::string option, bool value) throw(OptionException) { -#if !(IS_PROOFS_BUILD) +void OptionsHandler::proofEnabledBuild(std::string option, bool value) throw(OptionException) { +#ifndef CVC4_PROOF if(value) { std::stringstream ss; ss << "option `" << option << "' requires a proofs-enabled build of CVC4; this binary was not built with proof support"; throw OptionException(ss.str()); } -#endif /* IS_PROOFS_BUILD */ -} - - -// This macro is used for setting :regular-output-channel and :diagnostic-output-channel -// to redirect a stream. It maintains all attributes set on the stream. -#define __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(__channel_get, __channel_set) \ - { \ - int dagSetting = expr::ExprDag::getDag(__channel_get); \ - size_t exprDepthSetting = expr::ExprSetDepth::getDepth(__channel_get); \ - bool printtypesSetting = expr::ExprPrintTypes::getPrintTypes(__channel_get); \ - OutputLanguage languageSetting = language::SetLanguage::getLanguage(__channel_get); \ - __channel_set; \ - __channel_get << expr::ExprDag(dagSetting); \ - __channel_get << expr::ExprSetDepth(exprDepthSetting); \ - __channel_get << expr::ExprPrintTypes(printtypesSetting); \ - __channel_get << language::SetLanguage(languageSetting); \ - } - -void SmtOptionsHandler::dumpToFile(std::string option, std::string optarg) { -#ifdef CVC4_DUMPING - std::ostream* outStream = NULL; - if(optarg == "") { - throw OptionException(std::string("Bad file name for --dump-to")); - } else if(optarg == "-") { - outStream = &DumpOutC::dump_cout; - } else if(!options::filesystemAccess()) { - throw OptionException(std::string("Filesystem access not permitted")); - } else { - errno = 0; - outStream = new std::ofstream(optarg.c_str(), std::ofstream::out | std::ofstream::trunc); - if(outStream == NULL || !*outStream) { - std::stringstream ss; - ss << "Cannot open dump-to file: `" << optarg << "': " << __cvc4_errno_failreason(); - throw OptionException(ss.str()); - } - } - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(Dump.getStream(), Dump.setStream(*outStream)); -#else /* CVC4_DUMPING */ - throw OptionException("The dumping feature was disabled in this build of CVC4."); -#endif /* CVC4_DUMPING */ +#endif /* CVC4_PROOF */ } -void SmtOptionsHandler::setRegularOutputChannel(std::string option, std::string optarg) { - std::ostream* outStream = NULL; - if(optarg == "") { - throw OptionException(std::string("Bad file name setting for regular output channel")); - } else if(optarg == "stdout") { - outStream = &std::cout; - } else if(optarg == "stderr") { - outStream = &std::cerr; - } else if(!options::filesystemAccess()) { - throw OptionException(std::string("Filesystem access not permitted")); - } else { - errno = 0; - outStream = new std::ofstream(optarg.c_str(), std::ofstream::out | std::ofstream::trunc); - if(outStream == NULL || !*outStream) { - std::stringstream ss; - ss << "Cannot open regular-output-channel file: `" << optarg << "': " << __cvc4_errno_failreason(); - throw OptionException(ss.str()); - } - } - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(*options::err(), options::err.set(outStream)); +void OptionsHandler::notifyDumpToFile(std::string option) { + d_options->d_dumpToFileListeners.notify(); } -void SmtOptionsHandler::setDiagnosticOutputChannel(std::string option, std::string optarg) { - std::ostream* outStream = NULL; - if(optarg == "") { - throw OptionException(std::string("Bad file name setting for diagnostic output channel")); - } else if(optarg == "stdout") { - outStream = &std::cout; - } else if(optarg == "stderr") { - outStream = &std::cerr; - } else if(!options::filesystemAccess()) { - throw OptionException(std::string("Filesystem access not permitted")); - } else { - errno = 0; - outStream = new std::ofstream(optarg.c_str(), std::ofstream::out | std::ofstream::trunc); - if(outStream == NULL || !*outStream) { - std::stringstream ss; - ss << "Cannot open diagnostic-output-channel file: `" << optarg << "': " << __cvc4_errno_failreason(); - throw OptionException(ss.str()); - } - } - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(Debug.getStream(), Debug.setStream(*outStream)); - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(Warning.getStream(), Warning.setStream(*outStream)); - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(Message.getStream(), Message.setStream(*outStream)); - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(Notice.getStream(), Notice.setStream(*outStream)); - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(Chat.getStream(), Chat.setStream(*outStream)); - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(Trace.getStream(), Trace.setStream(*outStream)); - __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM__(*options::err(), options::err.set(outStream)); -} -#undef __CVC4__SMT__OUTPUTCHANNELS__SETSTREAM +void OptionsHandler::notifySetRegularOutputChannel(std::string option) { + d_options->d_setRegularChannelListeners.notify(); +} +void OptionsHandler::notifySetDiagnosticOutputChannel(std::string option) { + d_options->d_setDiagnosticChannelListeners.notify(); +} -std::string SmtOptionsHandler::checkReplayFilename(std::string option, std::string optarg) { +std::string OptionsHandler::checkReplayFilename(std::string option, std::string optarg) { #ifdef CVC4_REPLAY if(optarg == "") { throw OptionException (std::string("Bad file name for --replay")); @@ -1317,8 +1092,11 @@ std::string SmtOptionsHandler::checkReplayFilename(std::string option, std::stri #endif /* CVC4_REPLAY */ } +void OptionsHandler::notifySetReplayLogFilename(std::string option) { + d_options->d_setReplayFilenameListeners.notify(); +} -void SmtOptionsHandler::statsEnabledBuild(std::string option, bool value) throw(OptionException) { +void OptionsHandler::statsEnabledBuild(std::string option, bool value) throw(OptionException) { #ifndef CVC4_STATISTICS_ON if(value) { std::stringstream ss; @@ -1328,112 +1106,43 @@ void SmtOptionsHandler::statsEnabledBuild(std::string option, bool value) throw( #endif /* CVC4_STATISTICS_ON */ } -unsigned long SmtOptionsHandler::tlimitHandler(std::string option, std::string optarg) throw(OptionException) { - unsigned long ms; - std::istringstream convert(optarg); - if (!(convert >> ms)) { - throw OptionException("option `"+option+"` requires a number as an argument"); - } - - // make sure the resource is set if the option is updated - // if the smt engine is null the resource will be set in the - if (d_smtEngine != NULL) { - ResourceManager* rm = NodeManager::fromExprManager(d_smtEngine->getExprManager())->getResourceManager(); - rm->setTimeLimit(ms, true); - } - return ms; -} - -unsigned long SmtOptionsHandler::tlimitPerHandler(std::string option, std::string optarg) throw(OptionException) { - unsigned long ms; - - std::istringstream convert(optarg); - if (!(convert >> ms)) { - throw OptionException("option `"+option+"` requires a number as an argument"); - } - - if (d_smtEngine != NULL) { - ResourceManager* rm = NodeManager::fromExprManager(d_smtEngine->getExprManager())->getResourceManager(); - rm->setTimeLimit(ms, false); - } - return ms; -} - -unsigned long SmtOptionsHandler::rlimitHandler(std::string option, std::string optarg) throw(OptionException) { - unsigned long ms; - - std::istringstream convert(optarg); - if (!(convert >> ms)) { - throw OptionException("option `"+option+"` requires a number as an argument"); - } - - if (d_smtEngine != NULL) { - ResourceManager* rm = NodeManager::fromExprManager(d_smtEngine->getExprManager())->getResourceManager(); - rm->setResourceLimit(ms, true); - } - return ms; +void OptionsHandler::threadN(std::string option) { + throw OptionException(option + " is not a real option by itself. Use e.g. --thread0=\"--random-seed=10 --random-freq=0.02\" --thread1=\"--random-seed=20 --random-freq=0.05\""); } -unsigned long SmtOptionsHandler::rlimitPerHandler(std::string option, std::string optarg) throw(OptionException) { - unsigned long ms; - - std::istringstream convert(optarg); - if (!(convert >> ms)) { - throw OptionException("option `"+option+"` requires a number as an argument"); - } - - // TODO: Remove check? - if (d_smtEngine != NULL) { - ResourceManager* rm = NodeManager::fromExprManager(d_smtEngine->getExprManager())->getResourceManager(); - rm->setResourceLimit(ms, false); - } - return ms; +void OptionsHandler::notifyDumpMode(std::string option) throw(OptionException) { + d_options->d_setDumpModeListeners.notify(); } - // expr/options_handlers.h -void SmtOptionsHandler::setDefaultExprDepth(std::string option, int depth) { +void OptionsHandler::setDefaultExprDepthPredicate(std::string option, int depth) { if(depth < -1) { throw OptionException("--default-expr-depth requires a positive argument, or -1."); } - - Debug.getStream() << expr::ExprSetDepth(depth); - Trace.getStream() << expr::ExprSetDepth(depth); - Notice.getStream() << expr::ExprSetDepth(depth); - Chat.getStream() << expr::ExprSetDepth(depth); - Message.getStream() << expr::ExprSetDepth(depth); - Warning.getStream() << expr::ExprSetDepth(depth); - // intentionally exclude Dump stream from this list } -void SmtOptionsHandler::setDefaultDagThresh(std::string option, int dag) { +void OptionsHandler::setDefaultDagThreshPredicate(std::string option, int dag) { if(dag < 0) { throw OptionException("--default-dag-thresh requires a nonnegative argument."); } +} + +void OptionsHandler::notifySetDefaultExprDepth(std::string option) { + d_options->d_setDefaultExprDepthListeners.notify(); +} - Debug.getStream() << expr::ExprDag(dag); - Trace.getStream() << expr::ExprDag(dag); - Notice.getStream() << expr::ExprDag(dag); - Chat.getStream() << expr::ExprDag(dag); - Message.getStream() << expr::ExprDag(dag); - Warning.getStream() << expr::ExprDag(dag); - Dump.getStream() << expr::ExprDag(dag); +void OptionsHandler::notifySetDefaultDagThresh(std::string option) { + d_options->d_setDefaultDagThreshListeners.notify(); } -void SmtOptionsHandler::setPrintExprTypes(std::string option) { - Debug.getStream() << expr::ExprPrintTypes(true); - Trace.getStream() << expr::ExprPrintTypes(true); - Notice.getStream() << expr::ExprPrintTypes(true); - Chat.getStream() << expr::ExprPrintTypes(true); - Message.getStream() << expr::ExprPrintTypes(true); - Warning.getStream() << expr::ExprPrintTypes(true); - // intentionally exclude Dump stream from this list +void OptionsHandler::notifySetPrintExprTypes(std::string option) { + d_options->d_setPrintExprTypesListeners.notify(); } // main/options_handlers.h -void SmtOptionsHandler::showConfiguration(std::string option) { +void OptionsHandler::showConfiguration(std::string option) { fputs(Configuration::about().c_str(), stdout); printf("\n"); printf("version : %s\n", Configuration::getVersionString().c_str()); @@ -1484,7 +1193,7 @@ void SmtOptionsHandler::showConfiguration(std::string option) { exit(0); } -void SmtOptionsHandler::showDebugTags(std::string option) { +void OptionsHandler::showDebugTags(std::string option) { if(Configuration::isDebugBuild() && Configuration::isTracingBuild()) { printf("available tags:"); unsigned ntags = Configuration::getNumDebugTags(); @@ -1501,7 +1210,7 @@ void SmtOptionsHandler::showDebugTags(std::string option) { exit(0); } -void SmtOptionsHandler::showTraceTags(std::string option) { +void OptionsHandler::showTraceTags(std::string option) { if(Configuration::isTracingBuild()) { printf("available tags:"); unsigned ntags = Configuration::getNumTraceTags(); @@ -1516,53 +1225,8 @@ void SmtOptionsHandler::showTraceTags(std::string option) { exit(0); } -void SmtOptionsHandler::threadN(std::string option) { - throw OptionException(option + " is not a real option by itself. Use e.g. --thread0=\"--random-seed=10 --random-freq=0.02\" --thread1=\"--random-seed=20 --random-freq=0.05\""); -} - - -/* options/base_options_handlers.h */ -void SmtOptionsHandler::setVerbosity(std::string option, int value) throw(OptionException) { - if(Configuration::isMuzzledBuild()) { - DebugChannel.setStream(CVC4::null_os); - TraceChannel.setStream(CVC4::null_os); - NoticeChannel.setStream(CVC4::null_os); - ChatChannel.setStream(CVC4::null_os); - MessageChannel.setStream(CVC4::null_os); - WarningChannel.setStream(CVC4::null_os); - } else { - if(value < 2) { - ChatChannel.setStream(CVC4::null_os); - } else { - ChatChannel.setStream(std::cout); - } - if(value < 1) { - NoticeChannel.setStream(CVC4::null_os); - } else { - NoticeChannel.setStream(std::cout); - } - if(value < 0) { - MessageChannel.setStream(CVC4::null_os); - WarningChannel.setStream(CVC4::null_os); - } else { - MessageChannel.setStream(std::cout); - WarningChannel.setStream(std::cerr); - } - } -} - -void SmtOptionsHandler::increaseVerbosity(std::string option) { - options::verbosity.set(options::verbosity() + 1); - setVerbosity(option, options::verbosity()); -} - -void SmtOptionsHandler::decreaseVerbosity(std::string option) { - options::verbosity.set(options::verbosity() - 1); - setVerbosity(option, options::verbosity()); -} - -OutputLanguage SmtOptionsHandler::stringToOutputLanguage(std::string option, std::string optarg) throw(OptionException) { +OutputLanguage OptionsHandler::stringToOutputLanguage(std::string option, std::string optarg) throw(OptionException) { if(optarg == "help") { options::languageHelp.set(true); return language::output::LANG_AUTO; @@ -1571,13 +1235,14 @@ OutputLanguage SmtOptionsHandler::stringToOutputLanguage(std::string option, std try { return language::toOutputLanguage(optarg); } catch(OptionException& oe) { - throw OptionException("Error in " + option + ": " + oe.getMessage() + "\nTry --output-language help"); + throw OptionException("Error in " + option + ": " + oe.getMessage() + + "\nTry --output-language help"); } Unreachable(); } -InputLanguage SmtOptionsHandler::stringToInputLanguage(std::string option, std::string optarg) throw(OptionException) { +InputLanguage OptionsHandler::stringToInputLanguage(std::string option, std::string optarg) throw(OptionException) { if(optarg == "help") { options::languageHelp.set(true); return language::input::LANG_AUTO; @@ -1592,7 +1257,48 @@ InputLanguage SmtOptionsHandler::stringToInputLanguage(std::string option, std:: Unreachable(); } -void SmtOptionsHandler::addTraceTag(std::string option, std::string optarg) { +/* options/base_options_handlers.h */ +void OptionsHandler::setVerbosity(std::string option, int value) throw(OptionException) { + if(Configuration::isMuzzledBuild()) { + DebugChannel.setStream(&CVC4::null_os); + TraceChannel.setStream(&CVC4::null_os); + NoticeChannel.setStream(&CVC4::null_os); + ChatChannel.setStream(&CVC4::null_os); + MessageChannel.setStream(&CVC4::null_os); + WarningChannel.setStream(&CVC4::null_os); + } else { + if(value < 2) { + ChatChannel.setStream(&CVC4::null_os); + } else { + ChatChannel.setStream(&std::cout); + } + if(value < 1) { + NoticeChannel.setStream(&CVC4::null_os); + } else { + NoticeChannel.setStream(&std::cout); + } + if(value < 0) { + MessageChannel.setStream(&CVC4::null_os); + WarningChannel.setStream(&CVC4::null_os); + } else { + MessageChannel.setStream(&std::cout); + WarningChannel.setStream(&std::cerr); + } + } +} + +void OptionsHandler::increaseVerbosity(std::string option) { + options::verbosity.set(options::verbosity() + 1); + setVerbosity(option, options::verbosity()); +} + +void OptionsHandler::decreaseVerbosity(std::string option) { + options::verbosity.set(options::verbosity() - 1); + setVerbosity(option, options::verbosity()); +} + + +void OptionsHandler::addTraceTag(std::string option, std::string optarg) { if(Configuration::isTracingBuild()) { if(!Configuration::isTraceTag(optarg.c_str())) { @@ -1617,7 +1323,7 @@ void SmtOptionsHandler::addTraceTag(std::string option, std::string optarg) { Trace.on(optarg); } -void SmtOptionsHandler::addDebugTag(std::string option, std::string optarg) { +void OptionsHandler::addDebugTag(std::string option, std::string optarg) { if(Configuration::isDebugBuild() && Configuration::isTracingBuild()) { if(!Configuration::isDebugTag(optarg.c_str()) && !Configuration::isTraceTag(optarg.c_str())) { @@ -1646,18 +1352,10 @@ void SmtOptionsHandler::addDebugTag(std::string option, std::string optarg) { Trace.on(optarg); } -void SmtOptionsHandler::setPrintSuccess(std::string option, bool value) { - Debug.getStream() << Command::printsuccess(value); - Trace.getStream() << Command::printsuccess(value); - Notice.getStream() << Command::printsuccess(value); - Chat.getStream() << Command::printsuccess(value); - Message.getStream() << Command::printsuccess(value); - Warning.getStream() << Command::printsuccess(value); - *options::out() << Command::printsuccess(value); -} -std::string SmtOptionsHandler::suggestTags(char const* const* validTags, std::string inputTag, + +std::string OptionsHandler::suggestTags(char const* const* validTags, std::string inputTag, char const* const* additionalTags) { DidYouMean didYouMean; @@ -1675,36 +1373,8 @@ std::string SmtOptionsHandler::suggestTags(char const* const* validTags, std::st return didYouMean.getMatchAsString(inputTag); } -std::string SmtOptionsHandler::__cvc4_errno_failreason() { -#if HAVE_STRERROR_R -#if STRERROR_R_CHAR_P - if(errno != 0) { - // GNU version of strerror_r: *might* use the given buffer, - // or might not. It returns a pointer to buf, or not. - char buf[80]; - return std::string(strerror_r(errno, buf, sizeof buf)); - } else { - return "unknown reason"; - } -#else /* STRERROR_R_CHAR_P */ - if(errno != 0) { - // XSI version of strerror_r: always uses the given buffer. - // Returns an error code. - char buf[80]; - if(strerror_r(errno, buf, sizeof buf) == 0) { - return std::string(buf); - } else { - // some error occurred while getting the error string - return "unknown reason"; - } - } else { - return "unknown reason"; - } -#endif /* STRERROR_R_CHAR_P */ -#else /* HAVE_STRERROR_R */ - return "unknown reason"; -#endif /* HAVE_STRERROR_R */ -} -}/* CVC4::smt namespace */ + + +}/* CVC4::options namespace */ }/* CVC4 namespace */ diff --git a/src/options/options_handler.h b/src/options/options_handler.h new file mode 100644 index 000000000..9aa037004 --- /dev/null +++ b/src/options/options_handler.h @@ -0,0 +1,224 @@ +/********************* */ +/*! \file options_handler.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2014 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Interface for custom handlers and predicates options. + ** + ** Interface for custom handlers and predicates options. + **/ + +#include "cvc4_private.h" + +#ifndef __CVC4__OPTIONS__OPTIONS_HANDLER_H +#define __CVC4__OPTIONS__OPTIONS_HANDLER_H + +#include +#include + +#include "base/modal_exception.h" +#include "options/arith_heuristic_pivot_rule.h" +#include "options/arith_propagation_mode.h" +#include "options/arith_unate_lemma_mode.h" +#include "options/base_handlers.h" +#include "options/boolean_term_conversion_mode.h" +#include "options/bv_bitblast_mode.h" +#include "options/decision_mode.h" +#include "options/language.h" +#include "options/option_exception.h" +#include "options/options.h" +#include "options/printer_modes.h" +#include "options/quantifiers_modes.h" +#include "options/simplification_mode.h" +#include "options/theoryof_mode.h" +#include "options/ufss_mode.h" + +namespace CVC4 { +namespace options { + +class OptionsHandler { +public: + OptionsHandler(Options* options); + virtual ~OptionsHandler() {} + + void unsignedGreater0(const std::string& option, unsigned value) { + options::greater(0)(option, value); + } + + void unsignedLessEqual2(const std::string& option, unsigned value) { + options::less_equal(2)(option, value); + } + + void doubleGreaterOrEqual0(const std::string& option, double value) { + options::greater_equal(0.0)(option, value); + } + + void doubleLessOrEqual1(const std::string& option, double value) { + options::less_equal(1.0)(option, value); + } + + // DONE + // decision/options_handlers.h + // expr/options_handlers.h + // main/options_handlers.h + // options/base_options_handlers.h + // printer/options_handlers.h + // smt/options_handlers.h + // theory/options_handlers.h + // theory/booleans/options_handlers.h + // theory/uf/options_handlers.h + // theory/bv/options_handlers.h + // theory/quantifiers/options_handlers.h + // theory/arith/options_handlers.h + + + // theory/arith/options_handlers.h + ArithUnateLemmaMode stringToArithUnateLemmaMode(std::string option, std::string optarg) throw(OptionException); + ArithPropagationMode stringToArithPropagationMode(std::string option, std::string optarg) throw(OptionException); + ErrorSelectionRule stringToErrorSelectionRule(std::string option, std::string optarg) throw(OptionException); + + // theory/quantifiers/options_handlers.h + theory::quantifiers::InstWhenMode stringToInstWhenMode(std::string option, std::string optarg) throw(OptionException); + void checkInstWhenMode(std::string option, theory::quantifiers::InstWhenMode mode) throw(OptionException); + theory::quantifiers::LiteralMatchMode stringToLiteralMatchMode(std::string option, std::string optarg) throw(OptionException); + void checkLiteralMatchMode(std::string option, theory::quantifiers::LiteralMatchMode mode) throw(OptionException); + theory::quantifiers::MbqiMode stringToMbqiMode(std::string option, std::string optarg) throw(OptionException); + void checkMbqiMode(std::string option, theory::quantifiers::MbqiMode mode) throw(OptionException); + theory::quantifiers::QcfWhenMode stringToQcfWhenMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::QcfMode stringToQcfMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::UserPatMode stringToUserPatMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::TriggerSelMode stringToTriggerSelMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::PrenexQuantMode stringToPrenexQuantMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::CegqiFairMode stringToCegqiFairMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::TermDbMode stringToTermDbMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::IteLiftQuantMode stringToIteLiftQuantMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::SygusInvTemplMode stringToSygusInvTemplMode(std::string option, std::string optarg) throw(OptionException); + theory::quantifiers::MacrosQuantMode stringToMacrosQuantMode(std::string option, std::string optarg) throw(OptionException); + + // theory/bv/options_handlers.h + void abcEnabledBuild(std::string option, bool value) throw(OptionException); + void abcEnabledBuild(std::string option, std::string value) throw(OptionException); + theory::bv::BitblastMode stringToBitblastMode(std::string option, std::string optarg) throw(OptionException); + theory::bv::BvSlicerMode stringToBvSlicerMode(std::string option, std::string optarg) throw(OptionException); + void setBitblastAig(std::string option, bool arg) throw(OptionException); + + + // theory/booleans/options_handlers.h + theory::booleans::BooleanTermConversionMode stringToBooleanTermConversionMode(std::string option, std::string optarg) throw(OptionException); + + // theory/uf/options_handlers.h + theory::uf::UfssMode stringToUfssMode(std::string option, std::string optarg) throw(OptionException); + + // theory/options_handlers.h + theory::TheoryOfMode stringToTheoryOfMode(std::string option, std::string optarg); + void notifyUseTheoryList(std::string option); + std::string handleUseTheoryList(std::string option, std::string optarg); + + + // printer/options_handlers.h + ModelFormatMode stringToModelFormatMode(std::string option, std::string optarg) throw(OptionException); + InstFormatMode stringToInstFormatMode(std::string option, std::string optarg) throw(OptionException); + + // decision/options_handlers.h + decision::DecisionMode stringToDecisionMode(std::string option, std::string optarg) throw(OptionException); + decision::DecisionWeightInternal stringToDecisionWeightInternal(std::string option, std::string optarg) throw(OptionException); + + + /* smt/options_handlers.h */ + void notifyForceLogic(const std::string& option); + void notifyBeforeSearch(const std::string& option) throw(ModalException); + void notifyDumpMode(std::string option) throw(OptionException); + SimplificationMode stringToSimplificationMode(std::string option, std::string optarg) throw(OptionException); + void setProduceAssertions(std::string option, bool value) throw(); + void proofEnabledBuild(std::string option, bool value) throw(OptionException); + void notifyDumpToFile(std::string option); + void notifySetRegularOutputChannel(std::string option); + void notifySetDiagnosticOutputChannel(std::string option); + std::string checkReplayFilename(std::string option, std::string optarg); + void notifySetReplayLogFilename(std::string option); + + void statsEnabledBuild(std::string option, bool value) throw(OptionException); + + unsigned long tlimitHandler(std::string option, std::string optarg) throw(OptionException); + unsigned long tlimitPerHandler(std::string option, std::string optarg) throw(OptionException); + unsigned long rlimitHandler(std::string option, std::string optarg) throw(OptionException); + unsigned long rlimitPerHandler(std::string option, std::string optarg) throw(OptionException); + + void notifyTlimit(const std::string& option); + void notifyTlimitPer(const std::string& option); + void notifyRlimit(const std::string& option); + void notifyRlimitPer(const std::string& option); + + + /* expr/options_handlers.h */ + void setDefaultExprDepthPredicate(std::string option, int depth); + void setDefaultDagThreshPredicate(std::string option, int dag); + void notifySetDefaultExprDepth(std::string option); + void notifySetDefaultDagThresh(std::string option); + void notifySetPrintExprTypes(std::string option); + + /* main/options_handlers.h */ + void showConfiguration(std::string option); + void showDebugTags(std::string option); + void showTraceTags(std::string option); + void threadN(std::string option); + + /* options/base_options_handlers.h */ + void setVerbosity(std::string option, int value) throw(OptionException); + void increaseVerbosity(std::string option); + void decreaseVerbosity(std::string option); + OutputLanguage stringToOutputLanguage(std::string option, std::string optarg) throw(OptionException); + InputLanguage stringToInputLanguage(std::string option, std::string optarg) throw(OptionException); + void addTraceTag(std::string option, std::string optarg); + void addDebugTag(std::string option, std::string optarg); + void notifyPrintSuccess(std::string option); + + private: + + /* Helper utilities */ + static std::string suggestTags(char const* const* validTags, std::string inputTag, + char const* const* additionalTags = NULL); + + /** Pointer to the containing Options object.*/ + Options* d_options; + + /* Help strings */ + static const std::string s_bitblastingModeHelp; + static const std::string s_booleanTermConversionModeHelp; + static const std::string s_bvSlicerModeHelp; + static const std::string s_cegqiFairModeHelp; + static const std::string s_decisionModeHelp; + static const std::string s_instFormatHelp ; + static const std::string s_instWhenHelp; + static const std::string s_iteLiftQuantHelp; + static const std::string s_literalMatchHelp; + static const std::string s_macrosQuantHelp; + static const std::string s_mbqiModeHelp; + static const std::string s_modelFormatHelp; + static const std::string s_prenexQuantModeHelp; + static const std::string s_qcfModeHelp; + static const std::string s_qcfWhenModeHelp; + static const std::string s_simplificationHelp; + static const std::string s_sygusInvTemplHelp; + static const std::string s_termDbModeHelp; + static const std::string s_theoryOfModeHelp; + static const std::string s_triggerSelModeHelp; + static const std::string s_ufssModeHelp; + static const std::string s_userPatModeHelp; + static const std::string s_errorSelectionRulesHelp; + static const std::string s_arithPropagationModeHelp; + static const std::string s_arithUnateLemmasHelp; + +}; /* class OptionHandler */ + + +}/* CVC4::options namespace */ +}/* CVC4 namespace */ + +#endif /* __CVC4__OPTIONS__OPTIONS_HANDLER_H */ diff --git a/src/options/options_handler_interface.cpp b/src/options/options_handler_interface.cpp deleted file mode 100644 index 2cf19a611..000000000 --- a/src/options/options_handler_interface.cpp +++ /dev/null @@ -1,358 +0,0 @@ -/********************* */ -/*! \file options_handler_interface.cpp - ** \verbatim - ** Original author: Tim King - ** Major contributors: none - ** Minor contributors (to current version): none - ** This file is part of the CVC4 project. - ** Copyright (c) 2009-2014 New York University and The University of Iowa - ** See the file COPYING in the top-level source directory for licensing - ** information.\endverbatim - ** - ** \brief Interface for custom handlers and predicates options. - ** - ** Interface for custom handlers and predicates options. - **/ - -#include "options/options_handler_interface.h" - -#include -#include - -#include "base/cvc4_assert.h" -#include "base/exception.h" -#include "base/modal_exception.h" -#include "options/arith_heuristic_pivot_rule.h" -#include "options/arith_propagation_mode.h" -#include "options/arith_unate_lemma_mode.h" -#include "options/boolean_term_conversion_mode.h" -#include "options/bv_bitblast_mode.h" -#include "options/decision_mode.h" -#include "options/language.h" -#include "options/option_exception.h" -#include "options/printer_modes.h" -#include "options/quantifiers_modes.h" -#include "options/simplification_mode.h" -#include "options/theoryof_mode.h" -#include "options/ufss_mode.h" - -namespace CVC4 { -namespace options { - -static const char* s_third_argument_warning = - "We no longer support passing the third argument to the setting an option as NULL."; - -// theory/arith/options_handlers.h -ArithUnateLemmaMode stringToArithUnateLemmaMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToArithUnateLemmaMode(option, optarg); -} -ArithPropagationMode stringToArithPropagationMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToArithPropagationMode(option, optarg); -} -ErrorSelectionRule stringToErrorSelectionRule(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToErrorSelectionRule(option, optarg); -} - -// theory/quantifiers/options_handlers.h -theory::quantifiers::InstWhenMode stringToInstWhenMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToInstWhenMode(option, optarg); -} -void checkInstWhenMode(std::string option, theory::quantifiers::InstWhenMode mode, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->checkInstWhenMode(option, mode); -} -theory::quantifiers::LiteralMatchMode stringToLiteralMatchMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToLiteralMatchMode(option, optarg); -} -void checkLiteralMatchMode(std::string option, theory::quantifiers::LiteralMatchMode mode, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->checkLiteralMatchMode(option, mode); -} -theory::quantifiers::MbqiMode stringToMbqiMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToMbqiMode(option, optarg); -} -void checkMbqiMode(std::string option, theory::quantifiers::MbqiMode mode, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->checkMbqiMode(option, mode); -} -theory::quantifiers::QcfWhenMode stringToQcfWhenMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToQcfWhenMode(option, optarg); -} -theory::quantifiers::QcfMode stringToQcfMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToQcfMode(option, optarg); -} -theory::quantifiers::UserPatMode stringToUserPatMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToUserPatMode(option, optarg); -} -theory::quantifiers::TriggerSelMode stringToTriggerSelMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToTriggerSelMode(option, optarg); -} -theory::quantifiers::PrenexQuantMode stringToPrenexQuantMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToPrenexQuantMode(option, optarg); -} -theory::quantifiers::CegqiFairMode stringToCegqiFairMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToCegqiFairMode(option, optarg); -} -theory::quantifiers::TermDbMode stringToTermDbMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler-> stringToTermDbMode(option, optarg); -} -theory::quantifiers::IteLiftQuantMode stringToIteLiftQuantMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToIteLiftQuantMode(option, optarg); -} -theory::quantifiers::SygusInvTemplMode stringToSygusInvTemplMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToSygusInvTemplMode(option, optarg); -} -theory::quantifiers::MacrosQuantMode stringToMacrosQuantMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToMacrosQuantMode(option, optarg); -} - - -// theory/bv/options_handlers.h -void abcEnabledBuild(std::string option, bool value, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->abcEnabledBuild(option, value); -} -void abcEnabledBuild(std::string option, std::string value, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->abcEnabledBuild(option, value); -} -theory::bv::BitblastMode stringToBitblastMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToBitblastMode(option, optarg); -} -theory::bv::BvSlicerMode stringToBvSlicerMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToBvSlicerMode(option, optarg); -} -void setBitblastAig(std::string option, bool arg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setBitblastAig(option, arg); -} - - -// theory/booleans/options_handlers.h -theory::booleans::BooleanTermConversionMode stringToBooleanTermConversionMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToBooleanTermConversionMode( option, optarg); -} - -// theory/uf/options_handlers.h -theory::uf::UfssMode stringToUfssMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToUfssMode(option, optarg); -} - -// theory/options_handlers.h -theory::TheoryOfMode stringToTheoryOfMode(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToTheoryOfMode(option, optarg); -} -void useTheory(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->useTheory(option, optarg); -} - -// printer/options_handlers.h -ModelFormatMode stringToModelFormatMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToModelFormatMode(option, optarg); -} - -InstFormatMode stringToInstFormatMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToInstFormatMode(option, optarg); -} - - -// decision/options_handlers.h -decision::DecisionMode stringToDecisionMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToDecisionMode(option, optarg); -} - -decision::DecisionWeightInternal stringToDecisionWeightInternal(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToDecisionWeightInternal(option, optarg); -} - - -/* options/base_options_handlers.h */ -void setVerbosity(std::string option, int value, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setVerbosity(option, value); -} -void increaseVerbosity(std::string option, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->increaseVerbosity(option); -} -void decreaseVerbosity(std::string option, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->decreaseVerbosity(option); -} - -OutputLanguage stringToOutputLanguage(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToOutputLanguage(option, optarg); -} - -InputLanguage stringToInputLanguage(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToInputLanguage(option, optarg); -} - -void addTraceTag(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->addTraceTag(option, optarg); -} - -void addDebugTag(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->addDebugTag(option, optarg); -} - -void setPrintSuccess(std::string option, bool value, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setPrintSuccess(option, value); -} - - -/* main/options_handlers.h */ -void showConfiguration(std::string option, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->showConfiguration(option); -} - -void showDebugTags(std::string option, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->showDebugTags(option); -} - -void showTraceTags(std::string option, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->showTraceTags(option); -} - -void threadN(std::string option, OptionsHandler* handler){ - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->threadN(option); -} - -/* expr/options_handlers.h */ -void setDefaultExprDepth(std::string option, int depth, OptionsHandler* handler){ - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setDefaultExprDepth(option, depth); -} - -void setDefaultDagThresh(std::string option, int dag, OptionsHandler* handler){ - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setDefaultDagThresh(option, dag); -} - -void setPrintExprTypes(std::string option, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setPrintExprTypes(option); -} - - -/* smt/options_handlers.h */ -void dumpMode(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->dumpMode(option, optarg); -} - -LogicInfo* stringToLogicInfo(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException){ - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToLogicInfo(option, optarg); -} - -SimplificationMode stringToSimplificationMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException){ - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->stringToSimplificationMode(option, optarg); -} - -// ensure we haven't started search yet -void beforeSearch(std::string option, bool value, OptionsHandler* handler) throw(ModalException){ - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->beforeSearch(option, value); -} - -void setProduceAssertions(std::string option, bool value, OptionsHandler* handler) throw() { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setProduceAssertions(option, value); -} - -// ensure we are a proof-enabled build of CVC4 -void proofEnabledBuild(std::string option, bool value, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->proofEnabledBuild(option, value); -} - -void dumpToFile(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->dumpToFile(option, optarg); -} - -void setRegularOutputChannel(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setRegularOutputChannel(option, optarg); -} - -void setDiagnosticOutputChannel(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - handler->setDiagnosticOutputChannel(option, optarg); -} - -std::string checkReplayFilename(std::string option, std::string optarg, OptionsHandler* handler) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->checkReplayFilename(option, optarg); -} - - -// ensure we are a stats-enabled build of CVC4 -void statsEnabledBuild(std::string option, bool value, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->statsEnabledBuild(option, value); -} - -unsigned long tlimitHandler(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->tlimitHandler(option, optarg); -} - -unsigned long tlimitPerHandler(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler-> tlimitPerHandler(option, optarg); -} - -unsigned long rlimitHandler(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->rlimitHandler(option, optarg); -} - -unsigned long rlimitPerHandler(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException) { - PrettyCheckArgument(handler != NULL, handler, s_third_argument_warning); - return handler->rlimitPerHandler(option, optarg); -} - - - -OptionsHandler::OptionsHandler() { } - -}/* CVC4::options namespace */ -}/* CVC4 namespace */ diff --git a/src/options/options_handler_interface.h b/src/options/options_handler_interface.h deleted file mode 100644 index e9e91ef0b..000000000 --- a/src/options/options_handler_interface.h +++ /dev/null @@ -1,272 +0,0 @@ -/********************* */ -/*! \file options_handler_interface.h - ** \verbatim - ** Original author: Tim King - ** Major contributors: none - ** Minor contributors (to current version): none - ** This file is part of the CVC4 project. - ** Copyright (c) 2009-2014 New York University and The University of Iowa - ** See the file COPYING in the top-level source directory for licensing - ** information.\endverbatim - ** - ** \brief Interface for custom handlers and predicates options. - ** - ** Interface for custom handlers and predicates options. - **/ - -#include "cvc4_private.h" - -#ifndef __CVC4__OPTIONS__OPTIONS_HANDLER_INTERFACE_H -#define __CVC4__OPTIONS__OPTIONS_HANDLER_INTERFACE_H - -#include -#include - -#include "base/modal_exception.h" -#include "options/arith_heuristic_pivot_rule.h" -#include "options/arith_propagation_mode.h" -#include "options/arith_unate_lemma_mode.h" -#include "options/boolean_term_conversion_mode.h" -#include "options/bv_bitblast_mode.h" -#include "options/decision_mode.h" -#include "options/language.h" -#include "options/option_exception.h" -#include "options/printer_modes.h" -#include "options/quantifiers_modes.h" -#include "options/simplification_mode.h" -#include "options/theoryof_mode.h" -#include "options/ufss_mode.h" - -namespace CVC4 { -class LogicInfo; -}/* CVC4 namespace */ - -namespace CVC4 { -namespace options { - -class OptionsHandler { -public: - OptionsHandler(); - virtual ~OptionsHandler() {} - - void setOption(const std::string& key, const std::string& optionarg) throw(OptionException, ModalException); - - std::string getOption(const std::string& key) const throw(OptionException); - - // DONE - // decision/options_handlers.h - // expr/options_handlers.h - // main/options_handlers.h - // options/base_options_handlers.h - // printer/options_handlers.h - // smt/options_handlers.h - // theory/options_handlers.h - // theory/booleans/options_handlers.h - // theory/uf/options_handlers.h - // theory/bv/options_handlers.h - // theory/quantifiers/options_handlers.h - // theory/arith/options_handlers.h - - - // theory/arith/options_handlers.h - virtual ArithUnateLemmaMode stringToArithUnateLemmaMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual ArithPropagationMode stringToArithPropagationMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual ErrorSelectionRule stringToErrorSelectionRule(std::string option, std::string optarg) throw(OptionException) = 0; - - // theory/quantifiers/options_handlers.h - virtual theory::quantifiers::InstWhenMode stringToInstWhenMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual void checkInstWhenMode(std::string option, theory::quantifiers::InstWhenMode mode) throw(OptionException) = 0; - virtual theory::quantifiers::LiteralMatchMode stringToLiteralMatchMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual void checkLiteralMatchMode(std::string option, theory::quantifiers::LiteralMatchMode mode) throw(OptionException) = 0; - virtual theory::quantifiers::MbqiMode stringToMbqiMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual void checkMbqiMode(std::string option, theory::quantifiers::MbqiMode mode) throw(OptionException) = 0; - virtual theory::quantifiers::QcfWhenMode stringToQcfWhenMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::QcfMode stringToQcfMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::UserPatMode stringToUserPatMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::TriggerSelMode stringToTriggerSelMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::PrenexQuantMode stringToPrenexQuantMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::CegqiFairMode stringToCegqiFairMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::TermDbMode stringToTermDbMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::IteLiftQuantMode stringToIteLiftQuantMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::SygusInvTemplMode stringToSygusInvTemplMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::quantifiers::MacrosQuantMode stringToMacrosQuantMode(std::string option, std::string optarg) throw(OptionException) = 0; - - // theory/bv/options_handlers.h - virtual void abcEnabledBuild(std::string option, bool value) throw(OptionException) = 0; - virtual void abcEnabledBuild(std::string option, std::string value) throw(OptionException) = 0; - virtual theory::bv::BitblastMode stringToBitblastMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual theory::bv::BvSlicerMode stringToBvSlicerMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual void setBitblastAig(std::string option, bool arg) throw(OptionException) = 0; - - - // theory/booleans/options_handlers.h - virtual theory::booleans::BooleanTermConversionMode stringToBooleanTermConversionMode(std::string option, std::string optarg) throw(OptionException) = 0; - - // theory/uf/options_handlers.h - virtual theory::uf::UfssMode stringToUfssMode(std::string option, std::string optarg) throw(OptionException) = 0; - - // theory/options_handlers.h - virtual theory::TheoryOfMode stringToTheoryOfMode(std::string option, std::string optarg) = 0; - virtual void useTheory(std::string option, std::string optarg) = 0; - - - // printer/options_handlers.h - virtual ModelFormatMode stringToModelFormatMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual InstFormatMode stringToInstFormatMode(std::string option, std::string optarg) throw(OptionException) = 0; - - // decision/options_handlers.h - virtual decision::DecisionMode stringToDecisionMode(std::string option, std::string optarg) throw(OptionException) = 0; - virtual decision::DecisionWeightInternal stringToDecisionWeightInternal(std::string option, std::string optarg) throw(OptionException) = 0; - - - /* smt/options_handlers.h */ - virtual void dumpMode(std::string option, std::string optarg) = 0; - virtual LogicInfo* stringToLogicInfo(std::string option, std::string optarg) throw(OptionException) = 0; - virtual SimplificationMode stringToSimplificationMode(std::string option, std::string optarg) throw(OptionException) = 0; - - virtual void beforeSearch(std::string option, bool value) throw(ModalException) = 0; - virtual void setProduceAssertions(std::string option, bool value) throw() = 0; - virtual void proofEnabledBuild(std::string option, bool value) throw(OptionException) = 0; - virtual void dumpToFile(std::string option, std::string optarg) = 0; - virtual void setRegularOutputChannel(std::string option, std::string optarg) = 0; - virtual void setDiagnosticOutputChannel(std::string option, std::string optarg) = 0; - virtual std::string checkReplayFilename(std::string option, std::string optarg) = 0; - virtual void statsEnabledBuild(std::string option, bool value) throw(OptionException) = 0; - virtual unsigned long tlimitHandler(std::string option, std::string optarg) throw(OptionException) = 0; - virtual unsigned long tlimitPerHandler(std::string option, std::string optarg) throw(OptionException) = 0; - virtual unsigned long rlimitHandler(std::string option, std::string optarg) throw(OptionException) = 0; - virtual unsigned long rlimitPerHandler(std::string option, std::string optarg) throw(OptionException) = 0; - - /* expr/options_handlers.h */ - virtual void setDefaultExprDepth(std::string option, int depth) = 0; - virtual void setDefaultDagThresh(std::string option, int dag) = 0; - virtual void setPrintExprTypes(std::string option) = 0; - - /* main/options_handlers.h */ - virtual void showConfiguration(std::string option) = 0; - virtual void showDebugTags(std::string option) = 0; - virtual void showTraceTags(std::string option) = 0; - virtual void threadN(std::string option) = 0; - - /* options/base_options_handlers.h */ - virtual void setVerbosity(std::string option, int value) throw(OptionException) = 0; - virtual void increaseVerbosity(std::string option) = 0; - virtual void decreaseVerbosity(std::string option) = 0; - virtual OutputLanguage stringToOutputLanguage(std::string option, std::string optarg) throw(OptionException) = 0; - virtual InputLanguage stringToInputLanguage(std::string option, std::string optarg) throw(OptionException) = 0; - virtual void addTraceTag(std::string option, std::string optarg) = 0; - virtual void addDebugTag(std::string option, std::string optarg) = 0; - virtual void setPrintSuccess(std::string option, bool value) = 0; -}; /* class OptionHandler */ - -// theory/arith/options_handlers.h -ArithUnateLemmaMode stringToArithUnateLemmaMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -ArithPropagationMode stringToArithPropagationMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -ErrorSelectionRule stringToErrorSelectionRule(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - -// theory/quantifiers/options_handlers.h -theory::quantifiers::InstWhenMode stringToInstWhenMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -void checkInstWhenMode(std::string option, theory::quantifiers::InstWhenMode mode, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::LiteralMatchMode stringToLiteralMatchMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -void checkLiteralMatchMode(std::string option, theory::quantifiers::LiteralMatchMode mode, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::MbqiMode stringToMbqiMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -void checkMbqiMode(std::string option, theory::quantifiers::MbqiMode mode, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::QcfWhenMode stringToQcfWhenMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::QcfMode stringToQcfMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::UserPatMode stringToUserPatMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::TriggerSelMode stringToTriggerSelMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::PrenexQuantMode stringToPrenexQuantMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::CegqiFairMode stringToCegqiFairMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::TermDbMode stringToTermDbMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::IteLiftQuantMode stringToIteLiftQuantMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::SygusInvTemplMode stringToSygusInvTemplMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::quantifiers::MacrosQuantMode stringToMacrosQuantMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - - -// theory/bv/options_handlers.h -void abcEnabledBuild(std::string option, bool value, OptionsHandler* handler) throw(OptionException); -void abcEnabledBuild(std::string option, std::string value, OptionsHandler* handler) throw(OptionException); -theory::bv::BitblastMode stringToBitblastMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -theory::bv::BvSlicerMode stringToBvSlicerMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -void setBitblastAig(std::string option, bool arg, OptionsHandler* handler) throw(OptionException); - -// theory/booleans/options_handlers.h -theory::booleans::BooleanTermConversionMode stringToBooleanTermConversionMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - -// theory/uf/options_handlers.h -theory::uf::UfssMode stringToUfssMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - - -// theory/options_handlers.h -theory::TheoryOfMode stringToTheoryOfMode(std::string option, std::string optarg, OptionsHandler* handler); -void useTheory(std::string option, std::string optarg, OptionsHandler* handler); - -// printer/options_handlers.h -ModelFormatMode stringToModelFormatMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -InstFormatMode stringToInstFormatMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - -// decision/options_handlers.h -decision::DecisionMode stringToDecisionMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -decision::DecisionWeightInternal stringToDecisionWeightInternal(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - - -/* options/base_options_handlers.h */ -void setVerbosity(std::string option, int value, OptionsHandler* handler) throw(OptionException); -void increaseVerbosity(std::string option, OptionsHandler* handler); -void decreaseVerbosity(std::string option, OptionsHandler* handler); -OutputLanguage stringToOutputLanguage(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -InputLanguage stringToInputLanguage(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); -void addTraceTag(std::string option, std::string optarg, OptionsHandler* handler); -void addDebugTag(std::string option, std::string optarg, OptionsHandler* handler); -void setPrintSuccess(std::string option, bool value, OptionsHandler* handler); - -/* main/options_handlers.h */ -void showConfiguration(std::string option, OptionsHandler* handler); -void showDebugTags(std::string option, OptionsHandler* handler); -void showTraceTags(std::string option, OptionsHandler* handler); -void threadN(std::string option, OptionsHandler* handler); - -/* expr/options_handlers.h */ -void setDefaultExprDepth(std::string option, int depth, OptionsHandler* handler); -void setDefaultDagThresh(std::string option, int dag, OptionsHandler* handler); -void setPrintExprTypes(std::string option, OptionsHandler* handler); - -/* smt/options_handlers.h */ -void dumpMode(std::string option, std::string optarg, OptionsHandler* handler); - -LogicInfo* stringToLogicInfo(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - -SimplificationMode stringToSimplificationMode(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - -// ensure we haven't started search yet -void beforeSearch(std::string option, bool value, OptionsHandler* handler) throw(ModalException); - -void setProduceAssertions(std::string option, bool value, OptionsHandler* handler) throw(); - -// ensure we are a proof-enabled build of CVC4 -void proofEnabledBuild(std::string option, bool value, OptionsHandler* handler) throw(OptionException); - -void dumpToFile(std::string option, std::string optarg, OptionsHandler* handler); - -void setRegularOutputChannel(std::string option, std::string optarg, OptionsHandler* handler); - -void setDiagnosticOutputChannel(std::string option, std::string optarg, OptionsHandler* handler); - -std::string checkReplayFilename(std::string option, std::string optarg, OptionsHandler* handler); - -// ensure we are a stats-enabled build of CVC4 -void statsEnabledBuild(std::string option, bool value, OptionsHandler* handler) throw(OptionException); - -unsigned long tlimitHandler(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - -unsigned long tlimitPerHandler(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - -unsigned long rlimitHandler(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - -unsigned long rlimitPerHandler(std::string option, std::string optarg, OptionsHandler* handler) throw(OptionException); - - -}/* CVC4::options namespace */ -}/* CVC4 namespace */ - -#endif /* __CVC4__OPTIONS__OPTIONS_HANDLER_INTERFACE_H */ diff --git a/src/options/options_handler_interface.i b/src/options/options_handler_interface.i deleted file mode 100644 index b7076a0b8..000000000 --- a/src/options/options_handler_interface.i +++ /dev/null @@ -1,5 +0,0 @@ -%{ -#include "options/options_handler_interface.h" -%} - -%include "options/options_handler_interface.h" diff --git a/src/options/options_public_functions.cpp b/src/options/options_public_functions.cpp new file mode 100644 index 000000000..2e86c732e --- /dev/null +++ b/src/options/options_public_functions.cpp @@ -0,0 +1,322 @@ +/********************* */ +/*! \file options_public_functions.cpp + ** \verbatim + ** Original author: Morgan Deters + ** Major contributors: none + ** Minor contributors (to current version): Kshitij Bansal + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2014 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Definitions of public facing interface functions for Options. + ** + ** Definitions of public facing interface functions for Options. These are + ** all 1 line wrappers for Options::get, Options::set, and + ** Options::wasSetByUser for different option types T. + **/ + +#include "options.h" + +#include +#include +#include +#include + +#include "base/listener.h" +#include "base/modal_exception.h" +#include "base/tls.h" +#include "options/base_options.h" +#include "options/language.h" +#include "options/main_options.h" +#include "options/parser_options.h" +#include "options/printer_modes.h" +#include "options/printer_options.h" +#include "options/option_exception.h" +#include "options/smt_options.h" +#include "options/quantifiers_options.h" + +namespace CVC4 { + +// Get accessor functions. +InputLanguage Options::getInputLanguage() const { + return (*this)[options::inputLanguage]; +} + +InstFormatMode Options::getInstFormatMode() const { + return (*this)[options::instFormatMode]; +} + +OutputLanguage Options::getOutputLanguage() const { + return (*this)[options::outputLanguage]; +} + +bool Options::getCheckProofs() const{ + return (*this)[options::checkProofs]; +} + +bool Options::getContinuedExecution() const{ + return (*this)[options::continuedExecution]; +} + +bool Options::getDumpInstantiations() const{ + return (*this)[options::dumpInstantiations]; +} + +bool Options::getDumpModels() const{ + return (*this)[options::dumpModels]; +} + +bool Options::getDumpProofs() const{ + return (*this)[options::dumpProofs]; +} + +bool Options::getDumpSynth() const{ + return (*this)[options::dumpSynth]; +} + +bool Options::getDumpUnsatCores() const{ + return (*this)[options::dumpUnsatCores]; +} + +bool Options::getEarlyExit() const{ + return (*this)[options::earlyExit]; +} + +bool Options::getFallbackSequential() const{ + return (*this)[options::fallbackSequential]; +} + +bool Options::getFilesystemAccess() const{ + return (*this)[options::filesystemAccess]; +} + +bool Options::getForceNoLimitCpuWhileDump() const{ + return (*this)[options::forceNoLimitCpuWhileDump]; +} + +bool Options::getHelp() const{ + return (*this)[options::help]; +} + +bool Options::getIncrementalParallel() const{ + return (*this)[options::incrementalParallel]; +} + +bool Options::getIncrementalSolving() const{ + return (*this)[options::incrementalSolving]; +} + +bool Options::getInteractive() const{ + return (*this)[options::interactive]; +} + +bool Options::getInteractivePrompt() const{ + return (*this)[options::interactivePrompt]; +} + +bool Options::getLanguageHelp() const{ + return (*this)[options::languageHelp]; +} + +bool Options::getMemoryMap() const{ + return (*this)[options::memoryMap]; +} + +bool Options::getParseOnly() const{ + return (*this)[options::parseOnly]; +} + +bool Options::getProduceModels() const{ + return (*this)[options::produceModels]; +} + +bool Options::getProof() const{ + return (*this)[options::proof]; +} + +bool Options::getSegvSpin() const{ + return (*this)[options::segvSpin]; +} + +bool Options::getSemanticChecks() const{ + return (*this)[options::semanticChecks]; +} + +bool Options::getStatistics() const{ + return (*this)[options::statistics]; +} + +bool Options::getStatsEveryQuery() const{ + return (*this)[options::statsEveryQuery]; +} + +bool Options::getStatsHideZeros() const{ + return (*this)[options::statsHideZeros]; +} + +bool Options::getStrictParsing() const{ + return (*this)[options::strictParsing]; +} + +bool Options::getTearDownIncremental() const{ + return (*this)[options::tearDownIncremental]; +} + +bool Options::getVersion() const{ + return (*this)[options::version]; +} + +bool Options::getWaitToJoin() const{ + return (*this)[options::waitToJoin]; +} + +const std::string& Options::getForceLogicString() const{ + return (*this)[options::forceLogicString]; +} + +const std::vector& Options::getThreadArgv() const{ + return (*this)[options::threadArgv]; +} + +int Options::getSharingFilterByLength() const{ + return (*this)[options::sharingFilterByLength]; +} + +int Options::getThreadId() const{ + return (*this)[options::thread_id]; +} + +int Options::getVerbosity() const{ + return (*this)[options::verbosity]; +} + +std::istream* Options::getIn() const{ + return (*this)[options::in]; +} + +std::ostream* Options::getErr(){ + return (*this)[options::err]; +} + +std::ostream* Options::getOut(){ + return (*this)[options::out]; +} + +std::ostream* Options::getOutConst() const{ +#warning "Remove Options::getOutConst" + return (*this)[options::out]; +} + +std::string Options::getBinaryName() const{ + return (*this)[options::binary_name]; +} + +std::string Options::getReplayInputFilename() const{ + return (*this)[options::replayInputFilename]; +} + +unsigned Options::getParseStep() const{ + return (*this)[options::parseStep]; +} + +unsigned Options::getThreadStackSize() const{ + return (*this)[options::threadStackSize]; +} + +unsigned Options::getThreads() const{ + return (*this)[options::threads]; +} + +int Options::currentGetSharingFilterByLength() { + return current()->getSharingFilterByLength(); +} + +int Options::currentGetThreadId() { + return current()->getThreadId(); +} + +std::ostream* Options::currentGetOut() { + return current()->getOut(); +} + + +// TODO: Document these. +void Options::setCeGuidedInst(bool value) { + set(options::ceGuidedInst, value); +} + +void Options::setDumpSynth(bool value) { + set(options::dumpSynth, value); +} + +void Options::setInputLanguage(InputLanguage value) { + set(options::inputLanguage, value); +} + +void Options::setInteractive(bool value) { + set(options::interactive, value); +} + +void Options::setOut(std::ostream* value) { + set(options::out, value); +} + +void Options::setOutputLanguage(OutputLanguage value) { + set(options::outputLanguage, value); +} + +void Options::setSharingFilterByLength(int length) { + set(options::sharingFilterByLength, length); +} + +void Options::setThreadId(int value) { + set(options::thread_id, value); +} + +bool Options::wasSetByUserCeGuidedInst() const { + return wasSetByUser(options::ceGuidedInst); +} + +bool Options::wasSetByUserDumpSynth() const { + return wasSetByUser(options::dumpSynth); +} + +bool Options::wasSetByUserEarlyExit() const { + return wasSetByUser(options::earlyExit); +} + +bool Options::wasSetByUserForceLogicString() const { + return wasSetByUser(options::forceLogicString); +} + +bool Options::wasSetByUserIncrementalSolving() const { + return wasSetByUser(options::incrementalSolving); +} + +bool Options::wasSetByUserInteractive() const { + return wasSetByUser(options::interactive); +} + +bool Options::wasSetByUserThreadStackSize() const { + return wasSetByUser(options::threadStackSize); +} + +bool Options::wasSetByUserThreads() const { + return wasSetByUser(options::threads); +} + + +void Options::flushErr() { + if(getErr() != NULL) { + *(getErr()) << std::flush; + } +} + +void Options::flushOut() { + if(getOut() != NULL) { + *(getOut()) << std::flush; + } +} + +}/* CVC4 namespace */ diff --git a/src/options/options_handler_set_option_template.cpp b/src/options/options_set_option_template.cpp similarity index 83% rename from src/options/options_handler_set_option_template.cpp rename to src/options/options_set_option_template.cpp index 86821bc0a..04f3800f7 100644 --- a/src/options/options_handler_set_option_template.cpp +++ b/src/options/options_set_option_template.cpp @@ -18,36 +18,35 @@ ** first generate options/summary.sed. **/ + #include #include -#include "base/output.h" #include "base/modal_exception.h" +#include "base/output.h" #include "options/option_exception.h" -#include "options/options_handler_interface.h" - +#include "options/options.h" +#include "options/options_handler.h" ${include_all_option_headers} ${option_handler_includes} -#line 31 "${template}" +#line 35 "${template}" using namespace std; namespace CVC4 { -namespace options { -void OptionsHandler::setOption(const std::string& key, const std::string& optionarg) +void Options::setOption(const std::string& key, const std::string& optionarg) throw(OptionException, ModalException) { - options::OptionsHandler* const handler = this; + options::OptionsHandler* handler = d_handler; Trace("options") << "SMT setOption(" << key << ", " << optionarg << ")" << endl; ${smt_setoption_handlers} -#line 44 "${template}" +#line 48 "${template}" throw UnrecognizedOptionException(key); } -}/* options namespace */ }/* CVC4 namespace */ diff --git a/src/options/options_template.cpp b/src/options/options_template.cpp index 231e5de90..51b2bea5e 100644 --- a/src/options/options_template.cpp +++ b/src/options/options_template.cpp @@ -52,13 +52,14 @@ extern int optreset; #include "base/exception.h" #include "base/output.h" #include "base/tls.h" +#include "options/argument_extender.h" #include "options/didyoumean.h" #include "options/language.h" -#include "options/options_handler_interface.h" +#include "options/options_handler.h" ${include_all_option_headers} -#line 58 "${template}" +#line 63 "${template}" #include "options/options_holder.h" #include "cvc4autoconfig.h" @@ -66,7 +67,7 @@ ${include_all_option_headers} ${option_handler_includes} -#line 67 "${template}" +#line 71 "${template}" using namespace CVC4; using namespace CVC4::options; @@ -75,6 +76,8 @@ namespace CVC4 { CVC4_THREADLOCAL(Options*) Options::s_current = NULL; + + /** * This is a default handler for options of built-in C++ type. This * template is really just a helper for the handleOption() template, @@ -110,7 +113,8 @@ struct OptionHandler { bool success = stringToInt(i, optionarg); if(!success){ - throw OptionException(option + ": failed to parse "+ optionarg +" as an integer of the appropraite type."); + throw OptionException(option + ": failed to parse "+ optionarg + + " as an integer of the appropraite type."); } // Depending in the platform unsigned numbers with '-' signs may parse. @@ -121,12 +125,14 @@ struct OptionHandler { } else if(i < std::numeric_limits::min()) { // negative overflow for type std::stringstream ss; - ss << option << " requires an argument >= " << std::numeric_limits::min(); + ss << option << " requires an argument >= " + << std::numeric_limits::min(); throw OptionException(ss.str()); } else if(i > std::numeric_limits::max()) { // positive overflow for type std::stringstream ss; - ss << option << " requires an argument <= " << std::numeric_limits::max(); + ss << option << " requires an argument <= " + << std::numeric_limits::max(); throw OptionException(ss.str()); } @@ -162,12 +168,14 @@ struct OptionHandler { } else if(r < -std::numeric_limits::max()) { // negative overflow for type std::stringstream ss; - ss << option << " requires an argument >= " << -std::numeric_limits::max(); + ss << option << " requires an argument >= " + << -std::numeric_limits::max(); throw OptionException(ss.str()); } else if(r > std::numeric_limits::max()) { // positive overflow for type std::stringstream ss; - ss << option << " requires an argument <= " << std::numeric_limits::max(); + ss << option << " requires an argument <= " + << std::numeric_limits::max(); throw OptionException(ss.str()); } @@ -221,9 +229,167 @@ void runBoolPredicates(T, std::string option, bool b, options::OptionsHandler* h // that can throw exceptions. } + +Options::Options() + : d_holder(new options::OptionsHolder()) + , d_handler(new options::OptionsHandler(this)) + , d_forceLogicListeners() + , d_beforeSearchListeners() + , d_tlimitListeners() + , d_tlimitPerListeners() + , d_rlimitListeners() + , d_rlimitPerListeners() +{} + +Options::~Options() { + delete d_handler; + delete d_holder; +} + +void Options::copyValues(const Options& options){ + if(this != &options) { + delete d_holder; + d_holder = new options::OptionsHolder(*options.d_holder); + } +} + +std::string Options::formatThreadOptionException(const std::string& option) { + std::stringstream ss; + ss << "can't understand option `" << option + << "': expected something like --threadN=\"--option1 --option2\"," + << " where N is a nonnegative integer"; + return ss.str(); +} + +ListenerCollection::Registration* Options::registerAndNotify( + ListenerCollection& collection, Listener* listener, bool notify) +{ + ListenerCollection::Registration* registration = + collection.registerListener(listener); + if(notify) { + listener->notify(); + } + return registration; +} + +ListenerCollection::Registration* Options::registerForceLogicListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::forceLogicString); + return registerAndNotify(d_forceLogicListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerBeforeSearchListener( + Listener* listener) +{ + return d_beforeSearchListeners.registerListener(listener); +} + +ListenerCollection::Registration* Options::registerTlimitListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && + wasSetByUser(options::cumulativeMillisecondLimit); + return registerAndNotify(d_tlimitListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerTlimitPerListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::perCallMillisecondLimit); + return registerAndNotify(d_tlimitPerListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerRlimitListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::cumulativeResourceLimit); + return registerAndNotify(d_rlimitListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerRlimitPerListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::perCallResourceLimit); + return registerAndNotify(d_rlimitPerListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerUseTheoryListListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::useTheoryList); + return registerAndNotify(d_useTheoryListListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerSetDefaultExprDepthListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::defaultExprDepth); + return registerAndNotify(d_setDefaultExprDepthListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerSetDefaultExprDagListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::defaultDagThresh); + return registerAndNotify(d_setDefaultDagThreshListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerSetPrintExprTypesListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::printExprTypes); + return registerAndNotify(d_setPrintExprTypesListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerSetDumpModeListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::dumpModeString); + return registerAndNotify(d_setDumpModeListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerSetPrintSuccessListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::printSuccess); + return registerAndNotify(d_setPrintSuccessListeners, listener, notify); +} + +ListenerCollection::Registration* Options::registerDumpToFileNameListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::dumpToFileName); + return registerAndNotify(d_dumpToFileListeners, listener, notify); +} + +ListenerCollection::Registration* +Options::registerSetRegularOutputChannelListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::regularChannelName); + return registerAndNotify(d_setRegularChannelListeners, listener, notify); +} + +ListenerCollection::Registration* +Options::registerSetDiagnosticOutputChannelListener( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::diagnosticChannelName); + return registerAndNotify(d_setDiagnosticChannelListeners, listener, notify); +} + +ListenerCollection::Registration* +Options::registerSetReplayLogFilename( + Listener* listener, bool notifyIfSet) +{ + bool notify = notifyIfSet && wasSetByUser(options::replayLogFilename); + return registerAndNotify(d_setReplayFilenameListeners, listener, notify); +} + ${all_custom_handlers} -#line 204 "${template}" +#line 393 "${template}" #ifdef CVC4_DEBUG # define USE_EARLY_TYPE_CHECKING_BY_DEFAULT true @@ -237,42 +403,22 @@ ${all_custom_handlers} # define DO_SEMANTIC_CHECKS_BY_DEFAULT true #endif /* CVC4_MUZZLED || CVC4_COMPETITION_MODE */ -Options::Options() : - d_holder(new options::OptionsHolder()) { -} - -Options::Options(const Options& options) : - d_holder(new options::OptionsHolder(*options.d_holder)) { -} - -Options::~Options() { - delete d_holder; -} - -Options& Options::operator=(const Options& options) { - if(this != &options) { - delete d_holder; - d_holder = new options::OptionsHolder(*options.d_holder); - } - return *this; -} - options::OptionsHolder::OptionsHolder() : ${all_modules_defaults} { } -#line 242 "${template}" +#line 411 "${template}" static const std::string mostCommonOptionsDescription = "\ Most commonly-used CVC4 options:${common_documentation}"; -#line 247 "${template}" +#line 416 "${template}" static const std::string optionsDescription = mostCommonOptionsDescription + "\n\ \n\ Additional CVC4 options:${remaining_documentation}"; -#line 253 "${template}" +#line 422 "${template}" static const std::string optionsFootnote = "\n\ [*] Each of these options has a --no-OPTIONNAME variant, which reverses the\n\ @@ -315,7 +461,8 @@ void Options::printUsage(const std::string msg, std::ostream& out) { void Options::printShortUsage(const std::string msg, std::ostream& out) { out << msg << mostCommonOptionsDescription << std::endl << optionsFootnote << std::endl - << "For full usage, please use --help." << std::endl << std::endl << std::flush; + << "For full usage, please use --help." + << std::endl << std::endl << std::flush; } void Options::printLanguageHelp(std::ostream& out) { @@ -350,34 +497,33 @@ static struct option cmdlineOptions[] = {${all_modules_long_options} { NULL, no_argument, NULL, '\0' } };/* cmdlineOptions */ -#line 330 "${template}" +#line 501 "${template}" -static void preemptGetopt(int& argc, char**& argv, const char* opt) { - const size_t maxoptlen = 128; +// static void preemptGetopt(int& argc, char**& argv, const char* opt) { - Debug("preemptGetopt") << "preempting getopt() with " << opt << std::endl; +// Debug("preemptGetopt") << "preempting getopt() with " << opt << std::endl; - AlwaysAssert(opt != NULL && *opt != '\0'); - AlwaysAssert(strlen(opt) <= maxoptlen); +// AlwaysAssert(opt != NULL && *opt != '\0'); +// AlwaysAssert(strlen(opt) <= maxoptlen); - ++argc; - unsigned i = 1; - while(argv[i] != NULL && argv[i][0] != '\0') { - ++i; - } +// ++argc; +// unsigned i = 1; +// while(argv[i] != NULL && argv[i][0] != '\0') { +// ++i; +// } - if(argv[i] == NULL) { - argv = (char**) realloc(argv, (i + 6) * sizeof(char*)); - for(unsigned j = i; j < i + 5; ++j) { - argv[j] = (char*) malloc(sizeof(char) * maxoptlen); - argv[j][0] = '\0'; - } - argv[i + 5] = NULL; - } +// if(argv[i] == NULL) { +// argv = (char**) realloc(argv, (i + 6) * sizeof(char*)); +// for(unsigned j = i; j < i + 5; ++j) { +// argv[j] = (char*) malloc(sizeof(char) * maxoptlen); +// argv[j][0] = '\0'; +// } +// argv[i + 5] = NULL; +// } - strncpy(argv[i], opt, maxoptlen - 1); - argv[i][maxoptlen - 1] = '\0'; // ensure NUL-termination even on overflow -} +// strncpy(argv[i], opt, maxoptlen - 1); +// argv[i][maxoptlen - 1] = '\0'; // ensure NUL-termination even on overflow +// } namespace options { @@ -403,11 +549,17 @@ public: * The return value is what's left of the command line (that is, the * non-option arguments). */ -std::vector Options::parseOptions(int argc, char* main_argv[], options::OptionsHandler* const handler) throw(OptionException) { +std::vector Options::parseOptions(int argc, char* main_argv[]) throw(OptionException) { options::OptionsGuard guard(&s_current, this); + // Having this synonym simplifies the generation code in mkoptions. + options::OptionsHandler* handler = d_handler; + const char *progName = main_argv[0]; + ArgumentExtender argumentExtender(s_preemptAdditional, s_maxoptlen); + std::vector allocated; + Debug("options") << "main_argv == " << main_argv << std::endl; // Reset getopt(), in the case of multiple calls to parseOptions(). @@ -441,7 +593,8 @@ std::vector Options::parseOptions(int argc, char* main_argv[], opti int c = -1; optopt = 0; std::string option, optionarg; - Debug("preemptGetopt") << "top of loop, extra_optind == " << extra_optind << ", extra_argc == " << extra_argc << std::endl; + Debug("preemptGetopt") << "top of loop, extra_optind == " << extra_optind + << ", extra_argc == " << extra_argc << std::endl; if((extra_optind == 0 ? 1 : extra_optind) < extra_argc) { #if HAVE_DECL_OPTRESET if(optind_ref != &extra_optind) { @@ -451,14 +604,20 @@ std::vector Options::parseOptions(int argc, char* main_argv[], opti old_optind = optind = extra_optind; optind_ref = &extra_optind; argv = extra_argv; - Debug("preemptGetopt") << "in preempt code, next arg is " << extra_argv[optind == 0 ? 1 : optind] << std::endl; + Debug("preemptGetopt") << "in preempt code, next arg is " + << extra_argv[optind == 0 ? 1 : optind] + << std::endl; if(extra_argv[extra_optind == 0 ? 1 : extra_optind][0] != '-') { - InternalError("preempted args cannot give non-options command-line args (found `%s')", extra_argv[extra_optind == 0 ? 1 : extra_optind]); + InternalError( + "preempted args cannot give non-options command-line args (found `%s')", + extra_argv[extra_optind == 0 ? 1 : extra_optind]); } c = getopt_long(extra_argc, extra_argv, "+:${all_modules_short_options}", cmdlineOptions, NULL); - Debug("preemptGetopt") << "in preempt code, c == " << c << " (`" << char(c) << "') optind == " << optind << std::endl; + Debug("preemptGetopt") << "in preempt code" + << ", c == " << c << " (`" << char(c) << "')" + << " optind == " << optind << std::endl; if(optopt == 0 || ( optopt >= ${long_option_value_begin} && optopt <= ${long_option_value_end} )) { // long option @@ -522,13 +681,16 @@ std::vector Options::parseOptions(int argc, char* main_argv[], opti Debug("options") << "I restored optind to " << optind << std::endl;*/ } #endif /* __MINGW32__ || __MINGW64__ */ - Debug("options") << "[ argc == " << argc << ", main_argv == " << main_argv << " ]" << std::endl; + Debug("options") << "[ argc == " << argc + << ", main_argv == " << main_argv << " ]" << std::endl; c = getopt_long(argc, main_argv, "+:${all_modules_short_options}", cmdlineOptions, NULL); main_optind = optind; - Debug("options") << "[ got " << int(c) << " (" << char(c) << ") ]" << std::endl; - Debug("options") << "[ next option will be at pos: " << optind << " ]" << std::endl; + Debug("options") << "[ got " << int(c) << " (" << char(c) << ") ]" + << std::endl; + Debug("options") << "[ next option will be at pos: " << optind << " ]" + << std::endl; if(c == -1) { Debug("options") << "done with option parsing" << std::endl; break; @@ -537,12 +699,13 @@ std::vector Options::parseOptions(int argc, char* main_argv[], opti optionarg = (optarg == NULL) ? "" : optarg; } - Debug("preemptGetopt") << "processing option " << c << " (`" << char(c) << "'), " << option << std::endl; + Debug("preemptGetopt") << "processing option " << c + << " (`" << char(c) << "'), " << option << std::endl; switch(c) { ${all_modules_option_handlers} -#line 523 "${template}" +#line 709 "${template}" case ':': // This can be a long or short option, and the way to get at the @@ -555,13 +718,13 @@ ${all_modules_option_handlers} !strncmp(argv[optind - 1], "--thread", 8) && strlen(argv[optind - 1]) > 8 ) { if(! isdigit(argv[optind - 1][8])) { - throw OptionException(std::string("can't understand option `") + option + "': expected something like --threadN=\"--option1 --option2\", where N is a nonnegative integer"); + throw OptionException(formatThreadOptionException(option)); } std::vector& threadArgv = d_holder->threadArgv; char *end; long tnum = strtol(argv[optind - 1] + 8, &end, 10); if(tnum < 0 || (*end != '\0' && *end != '=')) { - throw OptionException(std::string("can't understand option `") + option + "': expected something like --threadN=\"--option1 --option2\", where N is a nonnegative integer"); + throw OptionException(formatThreadOptionException(option)); } if(threadArgv.size() <= size_t(tnum)) { threadArgv.resize(tnum + 1); @@ -571,29 +734,42 @@ ${all_modules_option_handlers} } if(*end == '\0') { // e.g., we have --thread0 "foo" if(argc <= optind) { - throw OptionException(std::string("option `") + option + "' missing its required argument"); + throw OptionException(std::string("option `") + option + + "' missing its required argument"); } - Debug("options") << "thread " << tnum << " gets option " << argv[optind] << std::endl; + Debug("options") << "thread " << tnum << " gets option " + << argv[optind] << std::endl; threadArgv[tnum] += argv[(*optind_ref)++]; } else { // e.g., we have --thread0="foo" if(end[1] == '\0') { - throw OptionException(std::string("option `") + option + "' missing its required argument"); + throw OptionException(std::string("option `") + option + + "' missing its required argument"); } - Debug("options") << "thread " << tnum << " gets option " << (end + 1) << std::endl; + Debug("options") << "thread " << tnum << " gets option " << (end + 1) + << std::endl; threadArgv[tnum] += end + 1; } - Debug("options") << "thread " << tnum << " now has " << threadArgv[tnum] << std::endl; + Debug("options") << "thread " << tnum << " now has " << threadArgv[tnum] + << std::endl; break; } - throw OptionException(std::string("can't understand option `") + option + "'" - + suggestCommandLineOptions(option)); + throw OptionException(std::string("can't understand option `") + option + + "'" + suggestCommandLineOptions(option)); } } Debug("options") << "returning " << nonOptions.size() << " non-option arguments." << std::endl; free(extra_argv); + for(std::vector::iterator i = allocated.begin(), iend = allocated.end(); + i != iend; ++i) + { + char* current = *i; + #warning "TODO: Unit tests fail if garbage collection is done here." + //free(current); + } + allocated.clear(); return nonOptions; } @@ -611,7 +787,7 @@ std::string Options::suggestCommandLineOptions(const std::string& optionName) th static const char* smtOptions[] = { ${all_modules_smt_options}, -#line 592 "${template}" +#line 790 "${template}" NULL };/* smtOptions[] */ @@ -633,11 +809,12 @@ std::vector< std::vector > Options::getOptions() const throw() { ${all_modules_get_options} -#line 614 "${template}" +#line 813 "${template}" return opts; } + #undef USE_EARLY_TYPE_CHECKING_BY_DEFAULT #undef DO_SEMANTIC_CHECKS_BY_DEFAULT diff --git a/src/options/parser_options b/src/options/parser_options index e91c735fe..d1e9aa142 100644 --- a/src/options/parser_options +++ b/src/options/parser_options @@ -11,24 +11,25 @@ common-option strictParsing --strict-parsing bool option memoryMap --mmap bool memory map file input -option semanticChecks /--no-checking bool :default DO_SEMANTIC_CHECKS_BY_DEFAULT :link /--no-type-checking +option semanticChecks semantic-checks /--no-checking bool :default DO_SEMANTIC_CHECKS_BY_DEFAULT :link /--no-type-checking disable ALL semantic checks, including type checks option globalDeclarations global-declarations bool :default false force all declarations and definitions to be global -# this is to support security in the online version, and in other similar contexts -# (--no-include-file disables filesystem access in TPTP and SMT2 parsers) -# the name --no-include-file is legacy: it also now limits any filesystem access -# (read or write) for example by using --dump-to (or the equivalent set-option) or -# set-option :regular-output-channel/:diagnostic-output-channel. However, the main -# driver is still permitted to read the input file given on the command-line if any. -# creation/use of temp files are still permitted (but the paths aren't given by the -# user). Also note this is only safe for the version invoked through the main driver, -# there are ways via the API to get the CVC4 library to open a file for reading or -# writing and thus leak information from an existing file, or overwrite an existing -# file with malicious content. -undocumented-option filesystemAccess /--no-filesystem-access bool :default true +# this is to support security in the online version, and in other similar +# contexts (--no-include-file disables filesystem access in TPTP and SMT2 +# parsers) the name --no-include-file is legacy: it also now limits any +# filesystem access (read or write) for example by using --dump-to (or the +# equivalent set-option) or set-option +# :regular-output-channel/:diagnostic-output-channel. However, the main driver +# is still permitted to read the input file given on the command-line if any. +# creation/use of temp files are still permitted (but the paths aren't given by +# the user). Also note this is only safe for the version invoked through the +# main driver, there are ways via the API to get the CVC4 library to open a file +# for reading or writing and thus leak information from an existing file, or +# overwrite an existing file with malicious content. +undocumented-option filesystemAccess filesystem-access /--no-filesystem-access bool :default true undocumented-alias --no-include-file = --no-filesystem-access endmodule diff --git a/src/options/printer_modes.h b/src/options/printer_modes.h index f18799aaa..8ccceb13f 100644 --- a/src/options/printer_modes.h +++ b/src/options/printer_modes.h @@ -25,20 +25,20 @@ namespace CVC4 { /** Enumeration of model_format modes (how to print models from get-model command). */ -typedef enum { +enum CVC4_PUBLIC ModelFormatMode { /** default mode (print expressions in the output language format) */ MODEL_FORMAT_MODE_DEFAULT, /** print functional values in a table format */ MODEL_FORMAT_MODE_TABLE, -} ModelFormatMode; +}; /** Enumeration of inst_format modes (how to print models from get-model command). */ -typedef enum { +enum CVC4_PUBLIC InstFormatMode { /** default mode (print expressions in the output language format) */ INST_FORMAT_MODE_DEFAULT, /** print as SZS proof */ INST_FORMAT_MODE_SZS, -} InstFormatMode; +}; std::ostream& operator<<(std::ostream& out, ModelFormatMode mode) CVC4_PUBLIC; std::ostream& operator<<(std::ostream& out, InstFormatMode mode) CVC4_PUBLIC; diff --git a/src/options/printer_options b/src/options/printer_options index 7491570c6..c276c0dd5 100644 --- a/src/options/printer_options +++ b/src/options/printer_options @@ -5,10 +5,10 @@ module PRINTER "options/printer_options.h" Printing -option modelFormatMode --model-format=MODE ModelFormatMode :handler CVC4::options::stringToModelFormatMode :default MODEL_FORMAT_MODE_DEFAULT :read-write :include "options/printer_modes.h" :handler-include "options/options_handler_interface.h" +option modelFormatMode --model-format=MODE ModelFormatMode :handler stringToModelFormatMode :default MODEL_FORMAT_MODE_DEFAULT :read-write :include "options/printer_modes.h" print format mode for models, see --model-format=help -option instFormatMode --inst-format=MODE InstFormatMode :handler CVC4::options::stringToInstFormatMode :default INST_FORMAT_MODE_DEFAULT :read-write :include "options/printer_modes.h" :handler-include "options/options_handler_interface.h" +option instFormatMode --inst-format=MODE InstFormatMode :handler stringToInstFormatMode :default INST_FORMAT_MODE_DEFAULT :read-write :include "options/printer_modes.h" print format mode for instantiations, see --inst-format=help endmodule diff --git a/src/options/prop_options b/src/options/prop_options index 3c3198147..87112197c 100644 --- a/src/options/prop_options +++ b/src/options/prop_options @@ -5,18 +5,18 @@ module PROP "options/prop_options.h" SAT layer -option satRandomFreq random-frequency --random-freq=P double :default 0.0 :predicate options::greater_equal(0.0) options::less_equal(1.0) +option satRandomFreq random-frequency --random-freq=P double :default 0.0 :predicate doubleGreaterOrEqual0 doubleLessOrEqual1 sets the frequency of random decisions in the sat solver (P=0.0 by default) option satRandomSeed random-seed --random-seed=S uint32_t :default 0 :read-write sets the random seed for the sat solver -option satVarDecay double :default 0.95 :predicate options::less_equal(1.0) options::greater_equal(0.0) +option satVarDecay double :default 0.95 :predicate doubleGreaterOrEqual0 doubleLessOrEqual1 variable activity decay factor for Minisat -option satClauseDecay double :default 0.999 :predicate options::less_equal(1.0) options::greater_equal(0.0) +option satClauseDecay double :default 0.999 :predicate doubleGreaterOrEqual0 doubleLessOrEqual1 clause activity decay factor for Minisat option satRestartFirst --restart-int-base=N unsigned :default 25 sets the base restart interval for the sat solver (N=25 by default) -option satRestartInc --restart-int-inc=F double :default 3.0 :predicate options::greater_equal(0.0) +option satRestartInc --restart-int-inc=F double :default 3.0 :predicate doubleGreaterOrEqual0 sets the restart interval increase factor for the sat solver (F=3.0 by default) option sat_refine_conflicts --refine-conflicts bool :default false diff --git a/src/options/quantifiers_options b/src/options/quantifiers_options index 5bc20f9a8..f5a6ee843 100644 --- a/src/options/quantifiers_options +++ b/src/options/quantifiers_options @@ -19,7 +19,7 @@ option miniscopeQuantFreeVar --miniscope-quant-fv bool :default true :read-write miniscope quantifiers for ground subformulas option quantSplit --quant-split bool :default true apply splitting to quantified formulas based on variable disjoint disjuncts -option prenexQuant --prenex-quant=MODE CVC4::theory::quantifiers::PrenexQuantMode :default CVC4::theory::quantifiers::PRENEX_NO_USER_PAT :include "options/quantifiers_modes.h" :read-write :handler CVC4::options::stringToPrenexQuantMode :handler-include "options/options_handler_interface.h" +option prenexQuant --prenex-quant=MODE CVC4::theory::quantifiers::PrenexQuantMode :default CVC4::theory::quantifiers::PRENEX_NO_USER_PAT :include "options/quantifiers_modes.h" :read-write :handler stringToPrenexQuantMode prenex mode for quantified formulas # Whether to variable-eliminate quantifiers. # For example, forall x y. ( P( x, y ) V x != c ) will be rewritten to @@ -29,7 +29,7 @@ option varElimQuant --var-elim-quant bool :default true option dtVarExpandQuant --dt-var-exp-quant bool :default true expand datatype variables bound to one constructor in quantifiers #ite lift mode for quantified formulas -option iteLiftQuant --ite-lift-quant=MODE CVC4::theory::quantifiers::IteLiftQuantMode :default CVC4::theory::quantifiers::ITE_LIFT_QUANT_MODE_SIMPLE :include "options/quantifiers_modes.h" :read-write :handler CVC4::options::stringToIteLiftQuantMode :handler-include "options/options_handler_interface.h" +option iteLiftQuant --ite-lift-quant=MODE CVC4::theory::quantifiers::IteLiftQuantMode :default CVC4::theory::quantifiers::ITE_LIFT_QUANT_MODE_SIMPLE :include "options/quantifiers_modes.h" :read-write :handler stringToIteLiftQuantMode ite lifting mode for quantified formulas option condVarSplitQuant --cond-var-split-quant bool :default true split quantified formulas that lead to variable eliminations @@ -63,7 +63,7 @@ option purifyQuant --purify-quant bool :default false option eMatching --e-matching bool :read-write :default true whether to do heuristic E-matching -option termDbMode --term-db-mode CVC4::theory::quantifiers::TermDbMode :default CVC4::theory::quantifiers::TERM_DB_ALL :read-write :include "options/quantifiers_modes.h" :handler CVC4::options::stringToTermDbMode :handler-include "options/options_handler_interface.h" +option termDbMode --term-db-mode CVC4::theory::quantifiers::TermDbMode :default CVC4::theory::quantifiers::TERM_DB_ALL :read-write :include "options/quantifiers_modes.h" :handler stringToTermDbMode which ground terms to consider for instantiation option registerQuantBodyTerms --register-quant-body-terms bool :default false consider ground terms within bodies of quantified formulas for matching @@ -86,14 +86,14 @@ option multiTriggerWhenSingle --multi-trigger-when-single bool :default false select multi triggers when single triggers exist option multiTriggerPriority --multi-trigger-priority bool :default false only try multi triggers if single triggers give no instantiations -option triggerSelMode --trigger-sel CVC4::theory::quantifiers::TriggerSelMode :default CVC4::theory::quantifiers::TRIGGER_SEL_DEFAULT :read-write :include "options/quantifiers_modes.h" :handler CVC4::options::stringToTriggerSelMode :handler-include "options/options_handler_interface.h" +option triggerSelMode --trigger-sel CVC4::theory::quantifiers::TriggerSelMode :default CVC4::theory::quantifiers::TRIGGER_SEL_DEFAULT :read-write :include "options/quantifiers_modes.h" :handler stringToTriggerSelMode selection mode for triggers -option userPatternsQuant --user-pat=MODE CVC4::theory::quantifiers::UserPatMode :default CVC4::theory::quantifiers::USER_PAT_MODE_TRUST :include "options/quantifiers_modes.h" :handler CVC4::options::stringToUserPatMode :handler-include "options/options_handler_interface.h" +option userPatternsQuant --user-pat=MODE CVC4::theory::quantifiers::UserPatMode :default CVC4::theory::quantifiers::USER_PAT_MODE_TRUST :include "options/quantifiers_modes.h" :handler stringToUserPatMode policy for handling user-provided patterns for quantifier instantiation option incrementTriggers --increment-triggers bool :default true generate additional triggers as needed during search -option instWhenMode --inst-when=MODE CVC4::theory::quantifiers::InstWhenMode :default CVC4::theory::quantifiers::INST_WHEN_FULL_LAST_CALL :read-write :include "options/quantifiers_modes.h" :handler CVC4::options::stringToInstWhenMode :handler-include "options/options_handler_interface.h" :predicate CVC4::options::checkInstWhenMode :predicate-include "options/options_handler_interface.h" +option instWhenMode --inst-when=MODE CVC4::theory::quantifiers::InstWhenMode :default CVC4::theory::quantifiers::INST_WHEN_FULL_LAST_CALL :read-write :include "options/quantifiers_modes.h" :handler stringToInstWhenMode :predicate checkInstWhenMode when to apply instantiation option instMaxLevel --inst-max-level=N int :read-write :default -1 @@ -113,7 +113,7 @@ option fullSaturateQuantRd --full-saturate-quant-rd bool :default true option fullSaturateInst --fs-inst bool :default false interleave full saturate instantiation with other techniques -option literalMatchMode --literal-matching=MODE CVC4::theory::quantifiers::LiteralMatchMode :default CVC4::theory::quantifiers::LITERAL_MATCH_NONE :include "options/quantifiers_modes.h" :handler CVC4::options::stringToLiteralMatchMode :handler-include "options/options_handler_interface.h" :predicate CVC4::options::checkLiteralMatchMode :predicate-include "options/options_handler_interface.h" +option literalMatchMode --literal-matching=MODE CVC4::theory::quantifiers::LiteralMatchMode :default CVC4::theory::quantifiers::LITERAL_MATCH_NONE :include "options/quantifiers_modes.h" :handler stringToLiteralMatchMode :predicate checkLiteralMatchMode choose literal matching mode ### finite model finding options @@ -130,7 +130,7 @@ option fmfFunWellDefinedRelevant --fmf-fun-rlv bool :default false option fmfEmptySorts --fmf-empty-sorts bool :default false allow finite model finding to assume sorts that do not occur in ground assertions are empty -option mbqiMode --mbqi=MODE CVC4::theory::quantifiers::MbqiMode :read-write :default CVC4::theory::quantifiers::MBQI_FMC :include "options/quantifiers_modes.h" :handler CVC4::options::stringToMbqiMode :handler-include "options/options_handler_interface.h" :predicate CVC4::options::checkMbqiMode :predicate-include "options/options_handler_interface.h" +option mbqiMode --mbqi=MODE CVC4::theory::quantifiers::MbqiMode :read-write :default CVC4::theory::quantifiers::MBQI_FMC :include "options/quantifiers_modes.h" :handler stringToMbqiMode :predicate checkMbqiMode choose mode for model-based quantifier instantiation option fmfOneInstPerRound --mbqi-one-inst-per-round bool :read-write :default false only add one instantiation per quantifier per round for mbqi @@ -156,9 +156,9 @@ option fmfBoundIntLazy --fmf-bound-int-lazy bool :default false :read-write option quantConflictFind --quant-cf bool :read-write :default true enable conflict find mechanism for quantifiers -option qcfMode --quant-cf-mode=MODE CVC4::theory::quantifiers::QcfMode :default CVC4::theory::quantifiers::QCF_PROP_EQ :include "options/quantifiers_modes.h" :handler CVC4::options::stringToQcfMode :handler-include "options/options_handler_interface.h" +option qcfMode --quant-cf-mode=MODE CVC4::theory::quantifiers::QcfMode :default CVC4::theory::quantifiers::QCF_PROP_EQ :include "options/quantifiers_modes.h" :handler stringToQcfMode what effort to apply conflict find mechanism -option qcfWhenMode --quant-cf-when=MODE CVC4::theory::quantifiers::QcfWhenMode :default CVC4::theory::quantifiers::QCF_WHEN_MODE_DEFAULT :include "options/quantifiers_modes.h" :handler CVC4::options::stringToQcfWhenMode :handler-include "options/options_handler_interface.h" +option qcfWhenMode --quant-cf-when=MODE CVC4::theory::quantifiers::QcfWhenMode :default CVC4::theory::quantifiers::QCF_WHEN_MODE_DEFAULT :include "options/quantifiers_modes.h" :handler stringToQcfWhenMode when to invoke conflict find mechanism for quantifiers option qcfTConstraint --qcf-tconstraint bool :read-write :default false enable entailment checks for t-constraints in qcf algorithm @@ -205,7 +205,7 @@ option conjectureUeeIntro --conjecture-gen-uee-intro bool :default false option ceGuidedInst --cegqi bool :default false :read-write counterexample-guided quantifier instantiation -option ceGuidedInstFair --cegqi-fair=MODE CVC4::theory::quantifiers::CegqiFairMode :default CVC4::theory::quantifiers::CEGQI_FAIR_DT_SIZE :include "options/quantifiers_modes.h" :handler CVC4::options::stringToCegqiFairMode :handler-include "options/options_handler_interface.h" +option ceGuidedInstFair --cegqi-fair=MODE CVC4::theory::quantifiers::CegqiFairMode :default CVC4::theory::quantifiers::CEGQI_FAIR_DT_SIZE :include "options/quantifiers_modes.h" :handler stringToCegqiFairMode if and how to apply fairness for cegqi option cegqiSingleInv --cegqi-si bool :default false :read-write process single invocation synthesis conjectures @@ -233,7 +233,7 @@ option sygusNormalFormGlobalArg --sygus-nf-sym-arg bool :default true option sygusNormalFormGlobalContent --sygus-nf-sym-content bool :default true generalize based on content in global search space narrowing -option sygusInvTemplMode --sygus-inv-templ=MODE CVC4::theory::quantifiers::SygusInvTemplMode :default CVC4::theory::quantifiers::SYGUS_INV_TEMPL_MODE_NONE :include "options/quantifiers_modes.h" :handler CVC4::options::stringToSygusInvTemplMode :handler-include "options/options_handler_interface.h" +option sygusInvTemplMode --sygus-inv-templ=MODE CVC4::theory::quantifiers::SygusInvTemplMode :default CVC4::theory::quantifiers::SYGUS_INV_TEMPL_MODE_NONE :include "options/quantifiers_modes.h" :handler stringToSygusInvTemplMode template mode for sygus invariant synthesis # approach applied to general quantified formulas @@ -281,7 +281,7 @@ option quantAlphaEquiv --quant-alpha-equiv bool :default true infer alpha equivalence between quantified formulas option macrosQuant --macros-quant bool :read-write :default false perform quantifiers macro expansion -option macrosQuantMode --macros-quant-mode=MODE CVC4::theory::quantifiers::MacrosQuantMode :default CVC4::theory::quantifiers::MACROS_QUANT_MODE_GROUND_UF :include "options/quantifiers_modes.h" :handler CVC4::options::stringToMacrosQuantMode :handler-include "options/options_handler_interface.h" +option macrosQuantMode --macros-quant-mode=MODE CVC4::theory::quantifiers::MacrosQuantMode :default CVC4::theory::quantifiers::MACROS_QUANT_MODE_GROUND_UF :include "options/quantifiers_modes.h" :handler stringToMacrosQuantMode mode for quantifiers macro expansion ### recursive function options diff --git a/src/options/smt_options b/src/options/smt_options index b99a8a83b..bc2586fe0 100644 --- a/src/options/smt_options +++ b/src/options/smt_options @@ -5,15 +5,15 @@ module SMT "options/smt_options.h" SMT layer -common-option - dump --dump=MODE argument :handler CVC4::options::dumpMode :handler-include "options/options_handler_interface.h" +common-option dumpModeString dump --dump=MODE std::string :default "" :notify notifyDumpMode dump preprocessed assertions, etc., see --dump=help -common-option - dump-to --dump-to=FILE argument :handler CVC4::options::dumpToFile :handler-include "options/options_handler_interface.h" +common-option dumpToFileName dump-to --dump-to=FILE std::string :notify notifyDumpToFile all dumping goes to FILE (instead of stdout) -expert-option forceLogic force-logic --force-logic=LOGIC LogicInfo* :include "options/logic_info_forward.h" :handler CVC4::options::stringToLogicInfo :handler-include "options/options_handler_interface.h" :default NULL +expert-option forceLogicString force-logic --force-logic=LOGIC std::string :default "" :notify notifyForceLogic set the logic, and override all further user attempts to change it -option simplificationMode simplification-mode --simplification=MODE SimplificationMode :handler CVC4::options::stringToSimplificationMode :default SIMPLIFICATION_MODE_BATCH :read-write :include "options/simplification_mode.h" :handler-include "options/options_handler_interface.h" +option simplificationMode simplification-mode --simplification=MODE SimplificationMode :handler stringToSimplificationMode :default SIMPLIFICATION_MODE_BATCH :read-write :include "options/simplification_mode.h" choose simplification mode, see --simplification=help alias --no-simplification = --simplification=none turn off all simplification (same as --simplification=none) @@ -23,35 +23,35 @@ option doStaticLearning static-learning --static-learning bool :default true option expandDefinitions expand-definitions bool :default false always expand symbol definitions in output -common-option produceModels produce-models -m --produce-models bool :default false :predicate CVC4::options::beforeSearch :predicate-include "options/options_handler_interface.h" +common-option produceModels produce-models -m --produce-models bool :default false :notify notifyBeforeSearch support the get-value and get-model commands -option checkModels check-models --check-models bool :link --produce-models --produce-assertions :link-smt produce-models :link-smt produce-assertions :predicate CVC4::options::beforeSearch :predicate-include "options/options_handler_interface.h" +option checkModels check-models --check-models bool :link --produce-models --produce-assertions :link-smt produce-models :link-smt produce-assertions :notify notifyBeforeSearch after SAT/INVALID/UNKNOWN, check that the generated model satisfies user assertions -option dumpModels --dump-models bool :default false :link --produce-models +option dumpModels --dump-models bool :default false :link --produce-models :link-smt produce-models output models after every SAT/INVALID/UNKNOWN response -option proof produce-proofs --proof bool :default false :predicate CVC4::options::proofEnabledBuild CVC4::options::beforeSearch :predicate-include "options/options_handler_interface.h" +option proof produce-proofs --proof bool :default false :predicate proofEnabledBuild :notify notifyBeforeSearch turn on proof generation -option checkProofs check-proofs --check-proofs bool :link --proof :link-smt produce-proofs :predicate CVC4::options::beforeSearch :predicate-include "options/options_handler_interface.h" :read-write +option checkProofs check-proofs --check-proofs bool :link --proof :link-smt produce-proofs :notify notifyBeforeSearch :read-write after UNSAT/VALID, machine-check the generated proof -option dumpProofs --dump-proofs bool :default false :link --proof +option dumpProofs --dump-proofs bool :default false :link --proof :link-smt produce-proofs output proofs after every UNSAT/VALID response option dumpInstantiations --dump-instantiations bool :default false output instantiations of quantified formulas after every UNSAT/VALID response option dumpSynth --dump-synth bool :read-write :default false output solution for synthesis conjectures after every UNSAT/VALID response -option unsatCores produce-unsat-cores --produce-unsat-cores bool :predicate CVC4::options::proofEnabledBuild CVC4::options::beforeSearch :predicate-include "options/options_handler_interface.h" +option unsatCores produce-unsat-cores --produce-unsat-cores bool :predicate proofEnabledBuild :notify :notify notifyBeforeSearch turn on unsat core generation option checkUnsatCores check-unsat-cores --check-unsat-cores bool :link --produce-unsat-cores :link-smt produce-unsat-cores :read-write after UNSAT/VALID, produce and check an unsat core (expensive) -option dumpUnsatCores --dump-unsat-cores bool :default false :link --produce-unsat-cores :link-smt produce-unsat-cores :predicate CVC4::options::beforeSearch :predicate-include "options/options_handler_interface.h" +option dumpUnsatCores --dump-unsat-cores bool :default false :link --produce-unsat-cores :link-smt produce-unsat-cores :notify notifyBeforeSearch output unsat cores after every UNSAT/VALID response -option produceAssignments produce-assignments --produce-assignments bool :default false :predicate CVC4::options::beforeSearch :predicate-include "options/options_handler_interface.h" +option produceAssignments produce-assignments --produce-assignments bool :default false :notify notifyBeforeSearch support the get-assignment command -undocumented-option interactiveMode interactive-mode bool :predicate CVC4::options::beforeSearch CVC4::options::setProduceAssertions :predicate-include "options/options_handler_interface.h" :read-write +undocumented-option interactiveMode interactive-mode bool :predicate setProduceAssertions :read-write :notify notifyBeforeSearch deprecated name for produce-assertions -common-option produceAssertions produce-assertions --produce-assertions bool :predicate CVC4::options::beforeSearch CVC4::options::setProduceAssertions :predicate-include "options/options_handler_interface.h" :read-write +common-option produceAssertions produce-assertions --produce-assertions bool :predicate setProduceAssertions :read-write :notify notifyBeforeSearch keep an assertions list (enables get-assertions command) option doITESimp --ite-simp bool :read-write @@ -86,18 +86,18 @@ option abstractValues abstract-values --abstract-values bool :default false option modelUninterpDtEnum --model-u-dt-enum bool :default false in models, output uninterpreted sorts as datatype enumerations -option - regular-output-channel argument :handler CVC4::options::setRegularOutputChannel :handler-include "options/options_handler_interface.h" +option regularChannelName regular-output-channel std::string :notify notifySetRegularOutputChannel set the regular output channel of the solver -option - diagnostic-output-channel argument :handler CVC4::options::setDiagnosticOutputChannel :handler-include "options/options_handler_interface.h" +option diagnosticChannelName diagnostic-output-channel std::string :notify notifySetDiagnosticOutputChannel set the diagnostic output channel of the solver -common-option cumulativeMillisecondLimit tlimit --tlimit=MS "unsigned long" :handler CVC4::options::tlimitHandler :handler-include "options/options_handler_interface.h" +common-option cumulativeMillisecondLimit tlimit --tlimit=MS "unsigned long" :handler tlimitHandler :notify notifyTlimit enable time limiting (give milliseconds) -common-option perCallMillisecondLimit tlimit-per --tlimit-per=MS "unsigned long" :handler CVC4::options::tlimitPerHandler :handler-include "options/options_handler_interface.h" +common-option perCallMillisecondLimit tlimit-per --tlimit-per=MS "unsigned long" :handler tlimitPerHandler :notify notifyTlimitPer enable time limiting per query (give milliseconds) -common-option cumulativeResourceLimit rlimit --rlimit=N "unsigned long" :handler CVC4::options::rlimitHandler :handler-include "options/options_handler_interface.h" +common-option cumulativeResourceLimit rlimit --rlimit=N "unsigned long" :handler rlimitHandler :notify notifyRlimit enable resource limiting (currently, roughly the number of SAT conflicts) -common-option perCallResourceLimit reproducible-resource-limit --rlimit-per=N "unsigned long" :handler CVC4::options::rlimitPerHandler :handler-include "options/options_handler_interface.h" +common-option perCallResourceLimit reproducible-resource-limit --rlimit-per=N "unsigned long" :handler rlimitPerHandler :notify notifyRlimitPer enable resource limiting per query common-option hardLimit hard-limit --hard-limit bool :default false the resource limit is hard potentially leaving the smtEngine in an unsafe state (should be destroyed and rebuild after resourcing out) @@ -145,14 +145,19 @@ expert-option bvSatConflictStep bv-sat-conflict-step --bv-sat-conflict-step unsi expert-option rewriteApplyToConst rewrite-apply-to-const --rewrite-apply-to-const bool :default false eliminate function applications, rewriting e.g. f(5) to a new symbol f_5 + # --replay is currently broken; don't document it for 1.0 -undocumented-option replayFilename --replay=FILE std::string :handler CVC4::options::checkReplayFilename :handler-include "options/options_handler_interface.h" +undocumented-option replayInputFilename --replay=FILE std::string :handler checkReplayFilename replay decisions from file +# --replay is currently broken; don't document it for 1.0 +undocumented-option replayLogFilename --replay-log=FILE std::string :handler checkReplayFilename :notify notifySetReplayLogFilename :notify notifyBeforeSearch + replay decisions from file option forceNoLimitCpuWhileDump --force-no-limit-cpu-while-dump bool :default false Force no CPU limit when dumping models and proofs -option solveIntAsBV --solve-int-as-bv uint32_t :default 0 +undocumented-option solveIntAsBV --solve-int-as-bv uint32_t :default 0 + attempt to solve a pure integer satisfiable problem by bitblasting in sufficient bitwidth (experimental) endmodule diff --git a/src/options/strings_options b/src/options/strings_options index 6247ad3a1..65c293dbc 100644 --- a/src/options/strings_options +++ b/src/options/strings_options @@ -9,11 +9,11 @@ option stringExp strings-exp --strings-exp bool :default false :read-write experimental features in the theory of strings # :predicate-include "smt/smt_engine.h" -option stringLB strings-lb --strings-lb=N unsigned :default 0 :predicate options::less_equal(2) :predicate-include "options/base_handlers.h" +option stringLB strings-lb --strings-lb=N unsigned :default 0 :predicate unsignedLessEqual2 the strategy of LB rule application: 0-lazy, 1-eager, 2-no # :predicate-include "smt/smt_engine.h" -option stdASCII strings-std-ascii --strings-std-ascii bool :default true :predicate options::less_equal(2) :predicate-include "options/base_handlers.h" +option stdASCII strings-std-ascii --strings-std-ascii bool :default true :predicate unsignedLessEqual2 the alphabet contains only characters from the standard ASCII or the extended one option stringFMF strings-fmf --strings-fmf bool :default false :read-write diff --git a/src/options/theory_options b/src/options/theory_options index f6d6d0f84..131b5fb80 100644 --- a/src/options/theory_options +++ b/src/options/theory_options @@ -5,11 +5,10 @@ module THEORY "options/theory_options.h" Theory layer -expert-option theoryOfMode theoryof-mode --theoryof-mode=MODE CVC4::theory::TheoryOfMode :handler CVC4::options::stringToTheoryOfMode :handler-include "options/options_handler_interface.h" :default CVC4::theory::THEORY_OF_TYPE_BASED :include "options/theoryof_mode.h" :read-write +expert-option theoryOfMode theoryof-mode --theoryof-mode=MODE CVC4::theory::TheoryOfMode :handler stringToTheoryOfMode :default CVC4::theory::THEORY_OF_TYPE_BASED :include "options/theoryof_mode.h" :read-write mode for Theory::theoryof() -option - use-theory --use-theory=NAME argument :handler CVC4::options::useTheory :handler-include "options/options_handler_interface.h" - use alternate theory implementation NAME (--use-theory=help for a list) -option theoryAlternates ::std::map :include :read-write +option useTheoryList use-theory --use-theory=NAME std::string :handler handleUseTheoryList :notify notifyUseTheoryList + use alternate theory implementation NAME (--use-theory=help for a list). This option may be repeated or a comma separated list. endmodule diff --git a/src/options/uf_options b/src/options/uf_options index e7df9a2db..cbac04b18 100644 --- a/src/options/uf_options +++ b/src/options/uf_options @@ -11,7 +11,7 @@ option ufSymmetryBreaker uf-symmetry-breaker --symmetry-breaker bool :read-write option condenseFunctionValues condense-function-values --condense-function-values bool :default true condense models for functions rather than explicitly representing them -option ufssRegions /--disable-uf-ss-regions bool :default true +option ufssRegions --uf-ss-regions bool :default true disable region-based method for discovering cliques and splits in uf strong solver option ufssEagerSplits --uf-ss-eager-split bool :default false add splits eagerly for uf strong solver @@ -29,7 +29,7 @@ option ufssSimpleCliques --uf-ss-simple-cliques bool :default true always use simple clique lemmas for uf strong solver option ufssDiseqPropagation --uf-ss-deq-prop bool :default false eagerly propagate disequalities for uf strong solver -option ufssMode --uf-ss=MODE CVC4::theory::uf::UfssMode :default CVC4::theory::uf::UF_SS_FULL :include "options/options_handler_interface.h" :handler CVC4::options::stringToUfssMode :handler-include "options/options_handler_interface.h" +option ufssMode --uf-ss=MODE CVC4::theory::uf::UfssMode :default CVC4::theory::uf::UF_SS_FULL :include "options/ufss_mode.h" :handler stringToUfssMode mode of operation for uf strong solver. option ufssCliqueSplits --uf-ss-clique-splits bool :default false use cliques instead of splitting on demand to shrink model diff --git a/src/options/ufss_mode.h b/src/options/ufss_mode.h index 25eb1d2d7..6ce05d46a 100644 --- a/src/options/ufss_mode.h +++ b/src/options/ufss_mode.h @@ -22,7 +22,7 @@ namespace CVC4 { namespace theory { namespace uf { - + enum UfssMode{ /** default, use uf strong solver to find minimal models for uninterpreted sorts */ UF_SS_FULL, @@ -37,4 +37,3 @@ enum UfssMode{ }/* CVC4 namespace */ #endif /* __CVC4__BASE__UFSS_MODE_H */ - diff --git a/src/parser/Makefile.am b/src/parser/Makefile.am index c8a8cc941..18e77fab3 100644 --- a/src/parser/Makefile.am +++ b/src/parser/Makefile.am @@ -37,25 +37,26 @@ libcvc4parser_la_LIBADD += \ endif libcvc4parser_la_SOURCES = \ - antlr_input.h \ antlr_input.cpp \ + antlr_input.h \ antlr_input_imports.cpp \ - antlr_line_buffered_input.h \ antlr_line_buffered_input.cpp \ - bounded_token_buffer.h \ + antlr_line_buffered_input.h \ + antlr_tracing.h \ + antlr_undefines.h \ bounded_token_buffer.cpp \ - bounded_token_factory.h \ + bounded_token_buffer.h \ bounded_token_factory.cpp \ - input.h \ + bounded_token_factory.h \ input.cpp \ - memory_mapped_input_buffer.h \ + input.h \ memory_mapped_input_buffer.cpp \ - parser.h \ + memory_mapped_input_buffer.h \ parser.cpp \ - parser_builder.h \ + parser.h \ parser_builder.cpp \ - parser_exception.h \ - antlr_tracing.h + parser_builder.h \ + parser_exception.h EXTRA_DIST = \ Makefile.antlr_tracing \ diff --git a/src/parser/antlr_input.cpp b/src/parser/antlr_input.cpp index 21e48b19e..6428017f5 100644 --- a/src/parser/antlr_input.cpp +++ b/src/parser/antlr_input.cpp @@ -14,13 +14,17 @@ ** A super-class for ANTLR-generated input language parsers **/ +#include "parser/antlr_input.h" +// We rely on the inclusion of #include in "parser/antlr_input.h". +// This is avoid having to undefine the symbols in . +// See the documentation in "parser/antlr_undefines.h" for more +// details. + #include -#include #include #include "base/output.h" #include "expr/type.h" -#include "parser/antlr_input.h" #include "parser/antlr_line_buffered_input.h" #include "parser/bounded_token_buffer.h" #include "parser/bounded_token_factory.h" diff --git a/src/parser/antlr_input.h b/src/parser/antlr_input.h index baec46e6f..241d1bc83 100644 --- a/src/parser/antlr_input.h +++ b/src/parser/antlr_input.h @@ -14,21 +14,17 @@ ** Base for ANTLR parser classes. **/ -#include +#ifndef __CVC4__PARSER__ANTLR_INPUT_H +#define __CVC4__PARSER__ANTLR_INPUT_H -// ANTLR3 headers define these in our space :( -// undef them so that we don't get multiple-definition warnings -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION +// These headers must be included first. See the documentation +// in parser/antlr_undefines.h for an explanation. +// Also while unusual this must also be within the #ifdef guard. +#include +#include "parser/antlr_undefines.h" #include "cvc4parser_private.h" -#ifndef __CVC4__PARSER__ANTLR_INPUT_H -#define __CVC4__PARSER__ANTLR_INPUT_H - #include #include #include @@ -72,10 +68,11 @@ private: pANTLR3_UINT8 inputString); /* This is private and unimplemented, because you should never use it. */ - AntlrInputStream(const AntlrInputStream& inputStream) CVC4_UNUSED; + AntlrInputStream(const AntlrInputStream& inputStream) CVC4_UNDEFINED; /* This is private and unimplemented, because you should never use it. */ - AntlrInputStream& operator=(const AntlrInputStream& inputStream) CVC4_UNUSED; + AntlrInputStream& operator=(const AntlrInputStream& inputStream) + CVC4_UNDEFINED; public: diff --git a/src/parser/antlr_input_imports.cpp b/src/parser/antlr_input_imports.cpp index f50dd5879..e74d83882 100644 --- a/src/parser/antlr_input_imports.cpp +++ b/src/parser/antlr_input_imports.cpp @@ -51,7 +51,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +// These headers must be the first two included. +// See the documentation in "parser/antlr_undefines.h" for more details. #include +#include "parser/antlr_undefines.h" + #include #include "parser/antlr_input.h" diff --git a/src/parser/antlr_line_buffered_input.cpp b/src/parser/antlr_line_buffered_input.cpp index cc1d499fb..99b4a3068 100644 --- a/src/parser/antlr_line_buffered_input.cpp +++ b/src/parser/antlr_line_buffered_input.cpp @@ -15,22 +15,19 @@ ** \todo document this file **/ -#include +// We rely on the inclusion of #include in +// "parser/antlr_line_buffered_input.h". +// This is avoid having to undefine the symbols in . +// See the documentation in "parser/antlr_undefines.h" for more +// details. -// ANTLR3 headers define these in our space :( -// undef them so that we don't get multiple-definition warnings -#undef PACKAGE_BUGREPORT -#undef PACKAGE_NAME -#undef PACKAGE_STRING -#undef PACKAGE_TARNAME -#undef PACKAGE_VERSION +#include "parser/antlr_line_buffered_input.h" #include #include #include #include "base/output.h" -#include "parser/antlr_line_buffered_input.h" namespace CVC4 { namespace parser { @@ -380,4 +377,3 @@ antlr3CreateLineBufferedStream(std::istream& in) }/* CVC4::parser namespace */ }/* CVC4 namespace */ - diff --git a/src/parser/antlr_line_buffered_input.h b/src/parser/antlr_line_buffered_input.h index 13a6486cd..c47ab324f 100644 --- a/src/parser/antlr_line_buffered_input.h +++ b/src/parser/antlr_line_buffered_input.h @@ -15,12 +15,17 @@ ** \todo document this file **/ +// These headers should be the first two included. +// See the documentation in "parser/antlr_undefines.h" for more details. +#include +#include "parser/antlr_undefines.h" + #include "cvc4parser_private.h" #ifndef __CVC4__PARSER__ANTLR_LINE_BUFFERED_INPUT_H #define __CVC4__PARSER__ANTLR_LINE_BUFFERED_INPUT_H -#include +#include namespace CVC4 { namespace parser { diff --git a/src/parser/antlr_undefines.h b/src/parser/antlr_undefines.h new file mode 100644 index 000000000..35a6c7e12 --- /dev/null +++ b/src/parser/antlr_undefines.h @@ -0,0 +1,69 @@ +/********************* */ +/*! \file antlr_undefines.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2016 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Every usage undefines standard autotools macro names. + ** + ** This header is very sensitive and it should be understood *in full* before + ** it is used or *moved* in position relative to other headers. + ** + ** Including this header runs #undef on the following identifiers: + ** - PACKAGE_BUGREPORT, + ** - PACKAGE_NAME + ** - PACKAGE_STRING + ** - PACKAGE_TARNAME + ** - PACKAGE_VERSION + ** + ** This is to solves a problem caused by antlr and cvc4 both defining these + ** symbols. This has to do with both packages using autotools in a slightly + ** dicey way. This was reported by us a long time ago, but most versions + ** of libantlr are quite old (3.2). + ** http://www.antlr3.org/pipermail/antlr-interest/2010-March/037859.html + ** + ** The source of both of these two definitions are given below. + ** + ** From antlr, the autogenerated antlr lexers and parsers include antlr3.h. + ** The chain of inclusions is: + ** Lang{Lexer,Parser}.h -> -> -> + ** + ** where Lang is in {Smt1,Smt2,Tptp,Cvc}. + ** + ** From CVC4, the parsers use Debug("...") and other features from + ** "base/output.h". This is a cvc4_private_library.h header file. This means + ** the files is usable while building the driver and parsers, but is otherwise + ** conceptually the same as a cvc4_private.h header. (If that sounds sketchy, + ** it is sure is! [See src/DESIGN.txt for more details].) + ** The include chain is then + ** "base/output.h" -> "cvc4_private_library.h" -> "cvc4_private.h" -> + ** "cvc4autoconfig.h". + ** The file cvc4autoconfig.h is autogenerated by autotools and can be found in + ** builds///cvc4autoconfig.h + ** + ** Thus a working solution is to include this header immediately after all + ** locations of #include . This includes all autogenerated files. + ** This potentially has to be repeated so this header should not be guarded. + ** + ** To ensure that we do not remove cvc4's versions and use antlr's by mistake + ** #include needs to proceed any other includes like + ** #include "cvc4parser_private.h". + ** + ** It is worth noting that future version of antlr can both not define these + ** macros and may generate different code. This is at best a stop gap + ** solution. + ** + ** Every location this header is included needs to be documented. + ** When in doubt do not move this header! + **/ + +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION diff --git a/src/parser/cvc/Cvc.g b/src/parser/cvc/Cvc.g index 21e01e7ed..08fba893e 100644 --- a/src/parser/cvc/Cvc.g +++ b/src/parser/cvc/Cvc.g @@ -463,6 +463,10 @@ Expr addNots(ExprManager* em, size_t n, Expr e) { @lexer::includes { +// This should come immediately after #include in the generated +// files. See the documentation in "parser/antlr_undefines.h" for more details. +#include "parser/antlr_undefines.h" + /** This suppresses warnings about the redefinition of token symbols between different * parsers. The redefinitions should be harmless as long as no client: (a) #include's * the lexer headers for two grammars AND (b) uses the token symbol definitions. */ @@ -487,6 +491,10 @@ Expr addNots(ExprManager* em, size_t n, Expr e) { @parser::includes { +// This should come immediately after #include in the generated +// files. See the documentation in "parser/antlr_undefines.h" for more details. +#include "parser/antlr_undefines.h" + #include #include #include "options/set_language.h" diff --git a/src/parser/cvc/cvc_input.cpp b/src/parser/cvc/cvc_input.cpp index 69920403f..2370109ef 100644 --- a/src/parser/cvc/cvc_input.cpp +++ b/src/parser/cvc/cvc_input.cpp @@ -14,12 +14,16 @@ ** [[ Add file-specific comments here ]] **/ +// These headers should be the first two included. +// See the documentation in "parser/antlr_undefines.h" for more details. #include +#include "parser/antlr_undefines.h" + +#include "parser/cvc/cvc_input.h" #include "expr/expr_manager.h" #include "parser/antlr_input.h" #include "parser/parser_exception.h" -#include "parser/cvc/cvc_input.h" #include "parser/cvc/CvcLexer.h" #include "parser/cvc/CvcParser.h" diff --git a/src/parser/input.cpp b/src/parser/input.cpp index 82b6dd32f..7cc5ac0ca 100644 --- a/src/parser/input.cpp +++ b/src/parser/input.cpp @@ -14,14 +14,16 @@ ** A super-class for input language parsers **/ +// This must be included first. +#include "parser/antlr_input.h" + #include "parser/input.h" -#include "parser/parser_exception.h" -#include "parser/parser.h" #include "base/output.h" -#include "smt_util/command.h" #include "expr/type.h" -#include "parser/antlr_input.h" +#include "parser/parser.h" +#include "parser/parser_exception.h" +#include "smt_util/command.h" using namespace std; diff --git a/src/parser/input.h b/src/parser/input.h index dcb54d256..4ff37409c 100644 --- a/src/parser/input.h +++ b/src/parser/input.h @@ -94,8 +94,8 @@ class CVC4_PUBLIC Input { * copy construction and assignment. Mark them private and do not define * them. */ - Input(const Input& input) CVC4_UNUSED; - Input& operator=(const Input& input) CVC4_UNUSED; + Input(const Input& input) CVC4_UNDEFINED; + Input& operator=(const Input& input) CVC4_UNDEFINED; public: diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index adbeaabd3..3cfe78145 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -30,7 +30,6 @@ #include "expr/kind.h" #include "expr/type.h" #include "options/options.h" -#include "options/smt_options.h" #include "parser/input.h" #include "parser/parser_exception.h" #include "smt_util/command.h" @@ -500,17 +499,20 @@ Command* Parser::nextCommand() throw(ParserException, UnsafeInterruptException) Debug("parser") << "nextCommand() => " << cmd << std::endl; if (cmd != NULL && dynamic_cast(cmd) == NULL && - dynamic_cast(cmd) == NULL) { + dynamic_cast(cmd) == NULL) + { // don't count set-option commands as to not get stuck in an infinite // loop of resourcing out - d_resourceManager->spendResource(d_exprManager->getOptions()[options::parseStep]); + const Options& options = d_exprManager->getOptions(); + d_resourceManager->spendResource(options.getParseStep()); } return cmd; } Expr Parser::nextExpression() throw(ParserException, UnsafeInterruptException) { Debug("parser") << "nextExpression()" << std::endl; - d_resourceManager->spendResource(d_exprManager->getOptions()[options::parseStep]); + const Options& options = d_exprManager->getOptions(); + d_resourceManager->spendResource(options.getParseStep()); Expr result; if(!done()) { try { diff --git a/src/parser/parser_builder.cpp b/src/parser/parser_builder.cpp index f473ae178..e095d208b 100644 --- a/src/parser/parser_builder.cpp +++ b/src/parser/parser_builder.cpp @@ -13,16 +13,18 @@ ** ** A builder for parsers. **/ + +// This must be included first. +#include "parser/antlr_input.h" + #include "parser/parser_builder.h" #include #include "expr/expr_manager.h" -#include "options/base_options.h" -#include "options/parser_options.h" -#include "options/smt_options.h" #include "parser/input.h" #include "parser/parser.h" +#include "options/options.h" #include "smt1/smt1.h" #include "smt2/smt2.h" #include "tptp/tptp.h" @@ -161,14 +163,15 @@ ParserBuilder& ParserBuilder::withParseOnly(bool flag) { ParserBuilder& ParserBuilder::withOptions(const Options& options) { ParserBuilder& retval = *this; retval = - retval.withInputLanguage(options[options::inputLanguage]) - .withMmap(options[options::memoryMap]) - .withChecks(options[options::semanticChecks]) - .withStrictMode(options[options::strictParsing]) - .withParseOnly(options[options::parseOnly]) - .withIncludeFile(options[options::filesystemAccess]); - if(options.wasSetByUser(options::forceLogic)) { - retval = retval.withForcedLogic(options[options::forceLogic]->getLogicString()); + retval.withInputLanguage(options.getInputLanguage()) + .withMmap(options.getMemoryMap()) + .withChecks(options.getSemanticChecks()) + .withStrictMode(options.getStrictParsing()) + .withParseOnly(options.getParseOnly()) + .withIncludeFile(options.getFilesystemAccess()); + if(options.wasSetByUserForceLogicString()) { + LogicInfo tmp(options.getForceLogicString()); + retval = retval.withForcedLogic(tmp.getLogicString()); } return retval; } diff --git a/src/parser/smt1/Smt1.g b/src/parser/smt1/Smt1.g index 98825f1c3..e8b7d5b9b 100644 --- a/src/parser/smt1/Smt1.g +++ b/src/parser/smt1/Smt1.g @@ -39,6 +39,11 @@ options { }/* @header */ @lexer::includes { + +// This should come immediately after #include in the generated +// files. See the documentation in "parser/antlr_undefines.h" for more details. +#include "parser/antlr_undefines.h" + /** This suppresses warnings about the redefinition of token symbols between * different parsers. The redefinitions should be harmless as long as no * client: (a) #include's the lexer headers for two grammars AND (b) uses the @@ -61,6 +66,10 @@ options { @parser::includes { +// This should come immediately after #include in the generated +// files. See the documentation in "parser/antlr_undefines.h" for more details. +#include "parser/antlr_undefines.h" + #include #include "smt_util/command.h" diff --git a/src/parser/smt1/smt1_input.cpp b/src/parser/smt1/smt1_input.cpp index 1391c7e85..8a8aa577e 100644 --- a/src/parser/smt1/smt1_input.cpp +++ b/src/parser/smt1/smt1_input.cpp @@ -14,9 +14,13 @@ ** [[ Add file-specific comments here ]] **/ +// These headers must be the first two included. +// See the documentation in "parser/antlr_undefines.h" for more details. #include +#include "parser/antlr_undefines.h" #include "parser/smt1/smt1_input.h" + #include "expr/expr_manager.h" #include "parser/input.h" #include "parser/parser.h" diff --git a/src/parser/smt2/Smt2.g b/src/parser/smt2/Smt2.g index 7f639762a..8be9ad2dd 100644 --- a/src/parser/smt2/Smt2.g +++ b/src/parser/smt2/Smt2.g @@ -40,6 +40,10 @@ options { @lexer::includes { +// This should come immediately after #include in the generated +// files. See the documentation in "parser/antlr_undefines.h" for more details. +#include "parser/antlr_undefines.h" + /** This suppresses warnings about the redefinition of token symbols between * different parsers. The redefinitions should be harmless as long as no * client: (a) #include's the lexer headers for two grammars AND (b) uses the @@ -75,6 +79,11 @@ using namespace CVC4::parser; }/* @lexer::postinclude */ @parser::includes { + +// This should come immediately after #include in the generated +// files. See the documentation in "parser/antlr_undefines.h" for more details. +#include "parser/antlr_undefines.h" + #include "parser/parser.h" #include "parser/antlr_tracing.h" #include "smt_util/command.h" diff --git a/src/parser/smt2/smt2.cpp b/src/parser/smt2/smt2.cpp index 355b58067..3b1467b5e 100644 --- a/src/parser/smt2/smt2.cpp +++ b/src/parser/smt2/smt2.cpp @@ -20,6 +20,7 @@ #include "parser/antlr_input.h" #include "parser/parser.h" #include "parser/smt1/smt1.h" +#include "parser/smt2/smt2_input.h" #include "smt_util/command.h" #include "util/bitvector.h" @@ -40,6 +41,10 @@ Smt2::Smt2(ExprManager* exprManager, Input* input, bool strictMode, bool parseOn } } +void Smt2::setLanguage(InputLanguage lang) { + ((Smt2Input*) getInput())->setLanguage(lang); +} + void Smt2::addArithmeticOperators() { Parser::addOperator(kind::PLUS); Parser::addOperator(kind::MINUS); diff --git a/src/parser/smt2/smt2.h b/src/parser/smt2/smt2.h index c8b89799c..7cf92f008 100644 --- a/src/parser/smt2/smt2.h +++ b/src/parser/smt2/smt2.h @@ -19,16 +19,15 @@ #ifndef __CVC4__PARSER__SMT2_H #define __CVC4__PARSER__SMT2_H +#include +#include +#include +#include + #include "parser/parser.h" #include "parser/smt1/smt1.h" #include "theory/logic_info.h" #include "util/abstract_value.h" -#include "parser/smt2/smt2_input.h" - -#include -#include -#include -#include namespace CVC4 { @@ -115,9 +114,7 @@ public: return getInput()->getLanguage() == language::input::LANG_SYGUS; } - void setLanguage(InputLanguage lang) { - ((Smt2Input*) getInput())->setLanguage(lang); - } + void setLanguage(InputLanguage lang); void setInfo(const std::string& flag, const SExpr& sexpr); diff --git a/src/parser/smt2/smt2_input.cpp b/src/parser/smt2/smt2_input.cpp index 9f1fae16f..cea6db278 100644 --- a/src/parser/smt2/smt2_input.cpp +++ b/src/parser/smt2/smt2_input.cpp @@ -14,9 +14,14 @@ ** [[ Add file-specific comments here ]] **/ +// These headers should be the first two included. +// See the documentation in "parser/antlr_undefines.h" for more details. #include +#include "parser/antlr_undefines.h" + #include "parser/smt2/smt2_input.h" + #include "expr/expr_manager.h" #include "parser/input.h" #include "parser/parser.h" diff --git a/src/parser/smt2/smt2_input.h b/src/parser/smt2/smt2_input.h index 0eb4a504b..9a07ddc08 100644 --- a/src/parser/smt2/smt2_input.h +++ b/src/parser/smt2/smt2_input.h @@ -26,7 +26,7 @@ // extern void Smt2ParserSetAntlrParser(CVC4::parser::AntlrParser* newAntlrParser); namespace CVC4 { - + class Command; class Expr; class ExprManager; diff --git a/src/parser/smt2/sygus_input.cpp b/src/parser/smt2/sygus_input.cpp index 086a04d27..e4f36b3df 100644 --- a/src/parser/smt2/sygus_input.cpp +++ b/src/parser/smt2/sygus_input.cpp @@ -14,9 +14,14 @@ ** [[ Add file-specific comments here ]] **/ +// These headers should be the first two included. +// See the documentation in "parser/antlr_undefines.h" for more details. #include +#include "parser/antlr_undefines.h" + #include "parser/smt2/sygus_input.h" + #include "expr/expr_manager.h" #include "parser/input.h" #include "parser/parser.h" diff --git a/src/parser/tptp/Tptp.g b/src/parser/tptp/Tptp.g index a2bad4988..52951dd38 100644 --- a/src/parser/tptp/Tptp.g +++ b/src/parser/tptp/Tptp.g @@ -41,6 +41,10 @@ options { @lexer::includes { +// This should come immediately after #include in the generated +// files. See the documentation in "parser/antlr_undefines.h" for more details. +#include "parser/antlr_undefines.h" + /** This suppresses warnings about the redefinition of token symbols between * different parsers. The redefinitions should be harmless as long as no * client: (a) #include's the lexer headers for two grammars AND (b) uses the @@ -83,6 +87,11 @@ using namespace CVC4::parser; }/* @lexer::postinclude */ @parser::includes { + +// This should come immediately after #include in the generated +// files. See the documentation in "parser/antlr_undefines.h" for more details. +#include "parser/antlr_undefines.h" + #include "smt_util/command.h" #include "parser/parser.h" #include "parser/tptp/tptp.h" diff --git a/src/parser/tptp/tptp.cpp b/src/parser/tptp/tptp.cpp index b674b12dc..9d3bd4b1c 100644 --- a/src/parser/tptp/tptp.cpp +++ b/src/parser/tptp/tptp.cpp @@ -14,10 +14,11 @@ ** Definitions of TPTP constants. **/ +// Do not #include "parser/antlr_input.h" directly. Rely on the header. +#include "parser/tptp/tptp.h" + #include "expr/type.h" #include "parser/parser.h" -#include "parser/tptp/tptp.h" -#include "parser/antlr_input.h" // ANTLR defines these, which is really bad! #undef true diff --git a/src/parser/tptp/tptp.h b/src/parser/tptp/tptp.h index 4fdbc236d..5e00ea1ce 100644 --- a/src/parser/tptp/tptp.h +++ b/src/parser/tptp/tptp.h @@ -14,6 +14,8 @@ ** Definitions of TPTP constants. **/ +#include "parser/antlr_input.h" // Needs to go first. + #include "cvc4parser_private.h" #ifndef __CVC4__PARSER__TPTP_H @@ -22,8 +24,6 @@ #include #include -#include "options/parser_options.h" -#include "parser/antlr_input.h" #include "parser/parser.h" #include "smt_util/command.h" #include "util/hash.h" diff --git a/src/parser/tptp/tptp_input.cpp b/src/parser/tptp/tptp_input.cpp index e41a539bb..5a393a58c 100644 --- a/src/parser/tptp/tptp_input.cpp +++ b/src/parser/tptp/tptp_input.cpp @@ -14,7 +14,11 @@ ** [[ Add file-specific comments here ]] **/ +// These headers should be the first two included. +// See the documentation in "parser/antlr_undefines.h" for more details. #include +#include "parser/antlr_undefines.h" + #include "parser/tptp/tptp_input.h" #include "expr/expr_manager.h" diff --git a/src/printer/printer.h b/src/printer/printer.h index ca9aff65d..aa6bf0470 100644 --- a/src/printer/printer.h +++ b/src/printer/printer.h @@ -38,8 +38,8 @@ class Printer { static Printer* makePrinter(OutputLanguage lang) throw(); // disallow copy, assignment - Printer(const Printer&) CVC4_UNUSED; - Printer& operator=(const Printer&) CVC4_UNUSED; + Printer(const Printer&) CVC4_UNDEFINED; + Printer& operator=(const Printer&) CVC4_UNDEFINED; protected: // derived classes can construct, but no one else. diff --git a/src/proof/proof.h b/src/proof/proof.h index d69cd6198..97dad7150 100644 --- a/src/proof/proof.h +++ b/src/proof/proof.h @@ -29,7 +29,7 @@ * ... * #endif * - * The macro IS_PROOFS_BUILD is defined in util/configuration_private.h + * The macro IS_PROOFS_BUILD is defined in base/configuration_private.h * * This has the effect of forcing that location to have included this header * *before* performing this test. This includes C preprocessing expansion. @@ -42,7 +42,7 @@ * and should list the exceptions here: * - Makefile.am * - proof/proofs.h - * - util/configuration_private.h + * - base/configuration_private.h */ #ifdef CVC4_PROOF diff --git a/src/proof/proof_manager.cpp b/src/proof/proof_manager.cpp index 0ae020090..b90d589b8 100644 --- a/src/proof/proof_manager.cpp +++ b/src/proof/proof_manager.cpp @@ -153,22 +153,23 @@ void ProofManager::initCnfProof(prop::CnfStream* cnfStream, } -void ProofManager::initTheoryProofEngine(SmtGlobals* globals) { +void ProofManager::initTheoryProofEngine() { Assert (currentPM()->d_theoryProof == NULL); Assert (currentPM()->d_format == LFSC); - currentPM()->d_theoryProof = new LFSCTheoryProofEngine(globals); + currentPM()->d_theoryProof = new LFSCTheoryProofEngine(); } std::string ProofManager::getInputClauseName(ClauseId id, const std::string& prefix) { return append(prefix+".pb", id); } + std::string ProofManager::getLemmaClauseName(ClauseId id, const std::string& prefix) { return append(prefix+".lemc", id); } - std::string ProofManager::getLemmaName(ClauseId id, - const std::string& prefix) { + +std::string ProofManager::getLemmaName(ClauseId id, const std::string& prefix) { return append(prefix+"lem", id); } diff --git a/src/proof/proof_manager.h b/src/proof/proof_manager.h index 5d8bf3d58..96c4e1d61 100644 --- a/src/proof/proof_manager.h +++ b/src/proof/proof_manager.h @@ -31,8 +31,6 @@ namespace CVC4 { -class SmtGlobals; - // forward declarations namespace Minisat { class Solver; @@ -146,7 +144,7 @@ public: static void initSatProof(Minisat::Solver* solver); static void initCnfProof(CVC4::prop::CnfStream* cnfStream, context::Context* ctx); - static void initTheoryProofEngine(SmtGlobals* globals); + static void initTheoryProofEngine(); // getting various proofs static Proof* getProof(SmtEngine* smt); @@ -157,12 +155,14 @@ public: static UFProof* getUfProof(); static BitVectorProof* getBitVectorProof(); static ArrayProof* getArrayProof(); - + // iterators over data shared by proofs typedef ExprSet::const_iterator assertions_iterator; // iterate over the assertions (these are arbitrary boolean formulas) - assertions_iterator begin_assertions() const { return d_inputFormulas.begin(); } + assertions_iterator begin_assertions() const { + return d_inputFormulas.begin(); + } assertions_iterator end_assertions() const { return d_inputFormulas.end(); } size_t num_assertions() const { return d_inputFormulas.size(); } diff --git a/src/proof/theory_proof.cpp b/src/proof/theory_proof.cpp index b0d6988a5..1bc8ae949 100644 --- a/src/proof/theory_proof.cpp +++ b/src/proof/theory_proof.cpp @@ -111,10 +111,9 @@ public: void done(TNode node) { } }; /* class MyPreRegisterVisitor */ -TheoryProofEngine::TheoryProofEngine(SmtGlobals* globals) +TheoryProofEngine::TheoryProofEngine() : d_registrationCache() , d_theoryProofTable() - , d_globals(globals) { d_theoryProofTable[theory::THEORY_BOOL] = new LFSCBooleanProof(this); } @@ -508,12 +507,10 @@ void TheoryProof::printTheoryLemmaProof(std::vector& lemma, std::ostream& if(d_theory->getId()==theory::THEORY_UF) { th = new theory::uf::TheoryUF(&fakeContext, &fakeContext, oc, v, ProofManager::currentPM()->getLogicInfo(), - ProofManager::currentPM()->getTheoryProofEngine()->d_globals, "replay::"); } else if(d_theory->getId()==theory::THEORY_ARRAY) { th = new theory::arrays::TheoryArrays(&fakeContext, &fakeContext, oc, v, ProofManager::currentPM()->getLogicInfo(), - ProofManager::currentPM()->getTheoryProofEngine()->d_globals, "replay::"); } else { InternalError(std::string("can't generate theory-proof for ") + ProofManager::currentPM()->getLogic()); diff --git a/src/proof/theory_proof.h b/src/proof/theory_proof.h index 3d700c388..d997d6e23 100644 --- a/src/proof/theory_proof.h +++ b/src/proof/theory_proof.h @@ -30,8 +30,6 @@ namespace CVC4 { -class SmtGlobals; - namespace theory { class Theory; } @@ -89,7 +87,7 @@ typedef __gnu_cxx::hash_map < ClauseId, prop::SatClause* > IdToSatClause; typedef __gnu_cxx::hash_map LetMap; typedef std::vector Bindings; -class TheoryProof; +class TheoryProof; typedef unsigned ClauseId; typedef __gnu_cxx::hash_set ExprSet; @@ -99,67 +97,69 @@ class TheoryProofEngine { protected: ExprSet d_registrationCache; TheoryProofTable d_theoryProofTable; - + /** * Returns whether the theory is currently supported in proof * production mode. */ bool supportedTheory(theory::TheoryId id); public: - SmtGlobals* d_globals; - - TheoryProofEngine(SmtGlobals* globals); + + TheoryProofEngine(); virtual ~TheoryProofEngine(); - /** - * Print the theory term (could be atom) by delegating to the - * proper theory - * - * @param term - * @param os - * - * @return + + /** + * Print the theory term (could be an atom) by delegating to the proper theory. + * + * @param term + * @param os */ virtual void printLetTerm(Expr term, std::ostream& os) = 0; - virtual void printBoundTerm(Expr term, std::ostream& os, const LetMap& map) = 0; - /** + virtual void printBoundTerm(Expr term, std::ostream& os, + const LetMap& map) = 0; + + /** * Print the proof representation of the given sort. - * - * @param os + * + * @param os */ - virtual void printSort(Type type, std::ostream& os) = 0; - /** + virtual void printSort(Type type, std::ostream& os) = 0; + + /** * Print the theory assertions (arbitrary formulas over * theory atoms) - * - * @param os + * + * @param os * @param paren closing parenthesis */ virtual void printAssertions(std::ostream& os, std::ostream& paren) = 0; - /** + + /** * Print proofs of all the theory lemmas (must prove * actual clause used in resolution proof). - * - * @param os - * @param paren + * + * @param os + * @param paren */ - virtual void printTheoryLemmas(const IdToSatClause& lemmas, - std::ostream& os, + virtual void printTheoryLemmas(const IdToSatClause& lemmas, std::ostream& os, std::ostream& paren) = 0; - /** - * Register theory atom (ensures all terms and atoms are declared). - * - * @param atom + + /** + * Register theory atom (ensures all terms and atoms are declared). + * + * @param atom */ void registerTerm(Expr atom); - /** - * Ensures that a theory proof class for the given theory - * is created. - * - * @param theory + + /** + * Ensures that a theory proof class for the given theory is created. + * + * @param theory */ void registerTheory(theory::Theory* theory); + theory::TheoryId getTheoryForLemma(ClauseId id); - TheoryProof* getTheoryProof(theory::TheoryId id); + TheoryProof* getTheoryProof(theory::TheoryId id); }; class LFSCTheoryProofEngine : public TheoryProofEngine { @@ -167,9 +167,9 @@ class LFSCTheoryProofEngine : public TheoryProofEngine { void printTheoryTerm(Expr term, std::ostream& os, const LetMap& map); void bind(Expr term, LetMap& map, Bindings& let_order); public: - LFSCTheoryProofEngine(SmtGlobals* globals) - : TheoryProofEngine(globals) {} - + LFSCTheoryProofEngine() + : TheoryProofEngine() {} + void printDeclarations(std::ostream& os, std::ostream& paren); virtual void printCoreTerm(Expr term, std::ostream& os, const LetMap& map); virtual void printLetTerm(Expr term, std::ostream& os); @@ -178,7 +178,7 @@ public: virtual void printTheoryLemmas(const IdToSatClause& lemmas, std::ostream& os, std::ostream& paren); - virtual void printSort(Type type, std::ostream& os); + virtual void printSort(Type type, std::ostream& os); }; class TheoryProof { diff --git a/src/prop/bvminisat/bvminisat.h b/src/prop/bvminisat/bvminisat.h index 383948e3e..ec8c3455a 100644 --- a/src/prop/bvminisat/bvminisat.h +++ b/src/prop/bvminisat/bvminisat.h @@ -122,7 +122,7 @@ public: private: /* Disable the default constructor. */ - BVMinisatSatSolver() CVC4_UNUSED; + BVMinisatSatSolver() CVC4_UNDEFINED; class Statistics { public: diff --git a/src/prop/cnf_stream.cpp b/src/prop/cnf_stream.cpp index a3d411738..1cd32bee8 100644 --- a/src/prop/cnf_stream.cpp +++ b/src/prop/cnf_stream.cpp @@ -37,18 +37,12 @@ using namespace std; using namespace CVC4::kind; -#ifdef CVC4_REPLAY -# define CVC4_USE_REPLAY true -#else /* CVC4_REPLAY */ -# define CVC4_USE_REPLAY false -#endif /* CVC4_REPLAY */ - namespace CVC4 { namespace prop { CnfStream::CnfStream(SatSolver* satSolver, Registrar* registrar, - context::Context* context, SmtGlobals* globals, - bool fullLitToNodeMap, std::string name) + context::Context* context, bool fullLitToNodeMap, + std::string name) : d_satSolver(satSolver), d_booleanVariables(context), d_nodeToLiteralMap(context), @@ -58,15 +52,13 @@ CnfStream::CnfStream(SatSolver* satSolver, Registrar* registrar, d_registrar(registrar), d_name(name), d_cnfProof(NULL), - d_globals(globals), d_removable(false) { } TseitinCnfStream::TseitinCnfStream(SatSolver* satSolver, Registrar* registrar, context::Context* context, - SmtGlobals* globals, bool fullLitToNodeMap, - std::string name) - : CnfStream(satSolver, registrar, context, globals, fullLitToNodeMap, name) + bool fullLitToNodeMap, std::string name) + : CnfStream(satSolver, registrar, context, fullLitToNodeMap, name) {} void CnfStream::assertClause(TNode node, SatClause& c) { @@ -200,10 +192,7 @@ SatLiteral CnfStream::newLiteral(TNode node, bool isTheoryAtom, bool preRegister } // If it's a theory literal, need to store it for back queries - if ( isTheoryAtom || d_fullLitToNodeMap || - ( CVC4_USE_REPLAY && d_globals->getReplayLog() != NULL ) || - (Dump.isOn("clauses")) ) { - + if ( isTheoryAtom || d_fullLitToNodeMap || (Dump.isOn("clauses")) ) { d_literalToNodeMap.insert_safe(lit, node); d_literalToNodeMap.insert_safe(~lit, node.notNode()); } diff --git a/src/prop/cnf_stream.h b/src/prop/cnf_stream.h index a07944a58..a6b6781ca 100644 --- a/src/prop/cnf_stream.h +++ b/src/prop/cnf_stream.h @@ -33,7 +33,7 @@ #include "proof/proof_manager.h" #include "prop/registrar.h" #include "prop/theory_proxy.h" -#include "smt/smt_globals.h" +#include "smt_util/lemma_channels.h" namespace CVC4 { namespace prop { @@ -90,9 +90,6 @@ protected: /** Pointer to the proof corresponding to this CnfStream */ CnfProof* d_cnfProof; - /** Container for misc. globals. */ - SmtGlobals* d_globals; - /** * How many literals were already mapped at the top-level when we * tried to convertAndAssert() something. This @@ -194,7 +191,6 @@ public: CnfStream(SatSolver* satSolver, Registrar* registrar, context::Context* context, - SmtGlobals* globals, bool fullLitToNodeMap = false, std::string name=""); @@ -291,7 +287,9 @@ public: * @param fullLitToNodeMap maintain a full SAT-literal-to-Node mapping, * even for non-theory literals */ - TseitinCnfStream(SatSolver* satSolver, Registrar* registrar, context::Context* context, SmtGlobals* globals, bool fullLitToNodeMap = false, std::string name = ""); + TseitinCnfStream(SatSolver* satSolver, Registrar* registrar, + context::Context* context, bool fullLitToNodeMap = false, + std::string name = ""); private: diff --git a/src/prop/prop_engine.cpp b/src/prop/prop_engine.cpp index 593c522a8..36d6408b5 100644 --- a/src/prop/prop_engine.cpp +++ b/src/prop/prop_engine.cpp @@ -45,6 +45,13 @@ using namespace std; using namespace CVC4::context; + +#ifdef CVC4_REPLAY +# define CVC4_USE_REPLAY true +#else /* CVC4_REPLAY */ +# define CVC4_USE_REPLAY false +#endif /* CVC4_REPLAY */ + namespace CVC4 { namespace prop { @@ -68,7 +75,9 @@ public: } }; -PropEngine::PropEngine(TheoryEngine* te, DecisionEngine *de, Context* satContext, Context* userContext, SmtGlobals* globals) : +PropEngine::PropEngine(TheoryEngine* te, DecisionEngine *de, Context* satContext, + Context* userContext, std::ostream* replayLog, + ExprStream* replayStream, LemmaChannels* channels) : d_inCheckSat(false), d_theoryEngine(te), d_decisionEngine(de), @@ -78,8 +87,7 @@ PropEngine::PropEngine(TheoryEngine* te, DecisionEngine *de, Context* satContext d_registrar(NULL), d_cnfStream(NULL), d_interrupted(false), - d_resourceManager(NodeManager::currentResourceManager()), - d_globals(globals) + d_resourceManager(NodeManager::currentResourceManager()) { Debug("prop") << "Constructing the PropEngine" << endl; @@ -88,13 +96,15 @@ PropEngine::PropEngine(TheoryEngine* te, DecisionEngine *de, Context* satContext d_registrar = new theory::TheoryRegistrar(d_theoryEngine); d_cnfStream = new CVC4::prop::TseitinCnfStream - (d_satSolver, d_registrar, userContext, d_globals, + (d_satSolver, d_registrar, userContext, // fullLitToNode Map = options::threads() > 1 || - options::decisionMode() == decision::DECISION_STRATEGY_RELEVANCY - ); + options::decisionMode() == decision::DECISION_STRATEGY_RELEVANCY || + ( CVC4_USE_REPLAY && replayLog != NULL )); - d_theoryProxy = new TheoryProxy(this, d_theoryEngine, d_decisionEngine, d_context, d_cnfStream, d_globals); + d_theoryProxy = new TheoryProxy( + this, d_theoryEngine, d_decisionEngine, d_context, d_cnfStream, replayLog, + replayStream, channels); d_satSolver->initialize(d_context, d_theoryProxy); d_decisionEngine->setSatSolver(d_satSolver); diff --git a/src/prop/prop_engine.h b/src/prop/prop_engine.h index dfa84ef14..a71d4832d 100644 --- a/src/prop/prop_engine.h +++ b/src/prop/prop_engine.h @@ -24,12 +24,13 @@ #include #include "base/modal_exception.h" +#include "expr/expr_stream.h" #include "expr/node.h" #include "options/options.h" #include "proof/proof_manager.h" -#include "smt/smt_globals.h" -#include "util/unsafe_interrupt_exception.h" +#include "smt_util/lemma_channels.h" #include "util/result.h" +#include "util/unsafe_interrupt_exception.h" namespace CVC4 { @@ -92,15 +93,14 @@ class PropEngine { /** Dump out the satisfying assignment (after SAT result) */ void printSatisfyingAssignment(); - /** Container for misc. globals. */ - SmtGlobals* d_globals; - public: /** * Create a PropEngine with a particular decision and theory engine. */ - PropEngine(TheoryEngine*, DecisionEngine*, context::Context* satContext, context::Context* userContext, SmtGlobals* global); + PropEngine(TheoryEngine*, DecisionEngine*, context::Context* satContext, + context::Context* userContext, std::ostream* replayLog, + ExprStream* replayStream, LemmaChannels* channels); /** * Destructor. diff --git a/src/prop/theory_proxy.cpp b/src/prop/theory_proxy.cpp index 5304691a6..5de97d0d8 100644 --- a/src/prop/theory_proxy.cpp +++ b/src/prop/theory_proxy.cpp @@ -39,12 +39,16 @@ TheoryProxy::TheoryProxy(PropEngine* propEngine, DecisionEngine* decisionEngine, context::Context* context, CnfStream* cnfStream, - SmtGlobals* globals) + std::ostream* replayLog, + ExprStream* replayStream, + LemmaChannels* channels) : d_propEngine(propEngine), d_cnfStream(cnfStream), d_decisionEngine(decisionEngine), d_theoryEngine(theoryEngine), - d_globals(globals), + d_channels(channels), + d_replayLog(replayLog), + d_replayStream(replayStream), d_queue(context), d_replayedDecisions("prop::theoryproxy::replayedDecisions", 0) { @@ -58,20 +62,12 @@ TheoryProxy::~TheoryProxy() { /** The lemma input channel we are using. */ LemmaInputChannel* TheoryProxy::inputChannel() { - return d_globals->getLemmaInputChannel(); + return d_channels->getLemmaInputChannel(); } /** The lemma output channel we are using. */ LemmaOutputChannel* TheoryProxy::outputChannel() { - return d_globals->getLemmaOutputChannel(); -} - -std::ostream* TheoryProxy::replayLog() { - return d_globals->getReplayLog(); -} - -ExprStream* TheoryProxy::replayStream() { - return d_globals->getReplayStream(); + return d_channels->getLemmaOutputChannel(); } @@ -203,8 +199,8 @@ void TheoryProxy::notifyNewLemma(SatClause& lemma) { SatLiteral TheoryProxy::getNextReplayDecision() { #ifdef CVC4_REPLAY - if(replayStream() != NULL) { - Expr e = replayStream()->nextExpr(); + if(d_replayStream != NULL) { + Expr e = d_replayStream->nextExpr(); if(!e.isNull()) { // we get null node when out of decisions to replay // convert & return ++d_replayedDecisions; @@ -217,9 +213,9 @@ SatLiteral TheoryProxy::getNextReplayDecision() { void TheoryProxy::logDecision(SatLiteral lit) { #ifdef CVC4_REPLAY - if(replayLog() != NULL) { + if(d_replayLog != NULL) { Assert(lit != undefSatLiteral, "logging an `undef' decision ?!"); - (*replayLog()) << d_cnfStream->getNode(lit) << std::endl; + (*d_replayLog) << d_cnfStream->getNode(lit) << std::endl; } #endif /* CVC4_REPLAY */ } diff --git a/src/prop/theory_proxy.h b/src/prop/theory_proxy.h index 261db8c87..acc242ab6 100644 --- a/src/prop/theory_proxy.h +++ b/src/prop/theory_proxy.h @@ -26,11 +26,12 @@ #include #include "context/cdqueue.h" +#include "expr/expr_stream.h" #include "expr/node.h" #include "prop/sat_solver.h" -#include "smt/smt_globals.h" -#include "smt_util/lemma_output_channel.h" +#include "smt_util/lemma_channels.h" #include "smt_util/lemma_input_channel.h" +#include "smt_util/lemma_output_channel.h" #include "theory/theory.h" #include "util/statistics_registry.h" @@ -54,7 +55,9 @@ public: DecisionEngine* decisionEngine, context::Context* context, CnfStream* cnfStream, - SmtGlobals* globals); + std::ostream* replayLog, + ExprStream* replayStream, + LemmaChannels* globals); ~TheoryProxy(); @@ -110,11 +113,14 @@ public: TheoryEngine* d_theoryEngine; - /** - * Container for inputChannel, outputChannel, replayLog, and - * replayStream. - */ - SmtGlobals* d_globals; + /** Container for inputChannel() and outputChannel(). */ + LemmaChannels* d_channels; + + /** Stream on which to log replay events. */ + std::ostream* d_replayLog; + + /** Stream for replaying decisions. */ + ExprStream* d_replayStream; /** The lemma input channel we are using. */ LemmaInputChannel* inputChannel(); @@ -122,9 +128,6 @@ public: /** The lemma output channel we are using. */ LemmaOutputChannel* outputChannel(); - std::ostream* replayLog(); - ExprStream* replayStream(); - /** Queue of asserted facts */ context::CDQueue d_queue; diff --git a/src/smt/managed_ostreams.cpp b/src/smt/managed_ostreams.cpp new file mode 100644 index 000000000..1901f731d --- /dev/null +++ b/src/smt/managed_ostreams.cpp @@ -0,0 +1,192 @@ +/********************* */ +/*! \file managed_ostreams.cpp + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2016 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Wrappers to handle memory management of ostreams. + ** + ** This file contains wrappers to handle special cases of managing memory + ** related to ostreams. + **/ + +#include "smt/managed_ostreams.h" + +#include + +#include "options/open_ostream.h" +#include "options/smt_options.h" +#include "smt/update_ostream.h" + +namespace CVC4 { + +ManagedOstream::ManagedOstream() : d_managed(NULL) {} + +ManagedOstream::~ManagedOstream() { + manage(NULL); + Assert(d_managed == NULL); +} + +void ManagedOstream::set(const std::string& filename) { + std::pair pair = open(filename); + initialize(pair.second); + manage(pair.first ? pair.second : NULL); +} + +std::pair ManagedOstream::open(const std::string& filename) + const { + OstreamOpener opener(getName()); + addSpecialCases(&opener); + return opener.open(filename); +} + +void ManagedOstream::manage(std::ostream* new_managed_value) { + if(d_managed == new_managed_value){ + // This is a no-op. + } else { + Assert(d_managed != new_managed_value); + std::ostream* old_managed_value = d_managed; + d_managed = new_managed_value; + if(old_managed_value != NULL){ + delete old_managed_value; + } + } +} + +ManagedDumpOStream::~ManagedDumpOStream() { + if(Dump.getStreamPointer() == getManagedOstream()) { + Dump.setStream(&null_os); + } +} + +std::string ManagedDumpOStream::defaultSource() const{ + return options::dumpToFileName(); +} + + +void ManagedDumpOStream::initialize(std::ostream* outStream) { +#ifdef CVC4_DUMPING + DumpOstreamUpdate dumpGetStream; + dumpGetStream.apply(outStream); +#else /* CVC4_DUMPING */ + throw OptionException( + "The dumping feature was disabled in this build of CVC4."); +#endif /* CVC4_DUMPING */ +} + +void ManagedDumpOStream::addSpecialCases(OstreamOpener* opener) const { + opener->addSpecialCase("-", &DumpOutC::dump_cout); +} + +ManagedRegularOutputChannel::~ManagedRegularOutputChannel() { + // Set all ostream that may still be using the old value of this channel + // to null_os. Consult RegularOutputChannelListener for the list of + // channels. + if(options::err() == getManagedOstream()){ + options::err.set(&null_os); + } +} + +std::string ManagedRegularOutputChannel::defaultSource() const { + return options::regularChannelName(); +} + +void ManagedRegularOutputChannel::initialize(std::ostream* outStream) { + OptionsErrOstreamUpdate optionsErrOstreamUpdate; + optionsErrOstreamUpdate.apply(outStream); +} + +void ManagedRegularOutputChannel::addSpecialCases(OstreamOpener* opener) + const { + opener->addSpecialCase("stdout", &std::cout); + opener->addSpecialCase("stderr", &std::cerr); +} + +ManagedDiagnosticOutputChannel::~ManagedDiagnosticOutputChannel() { + // Set all ostreams that may still be using the old value of this channel + // to null_os. Consult DiagnosticOutputChannelListener for the list of + // channels. + if(options::err() == getManagedOstream()){ + options::err.set(&null_os); + } + + if(Debug.getStreamPointer() == getManagedOstream()) { + Debug.setStream(&null_os); + } + if(Warning.getStreamPointer() == getManagedOstream()){ + Warning.setStream(&null_os); + } + if(Message.getStreamPointer() == getManagedOstream()){ + Message.setStream(&null_os); + } + if(Notice.getStreamPointer() == getManagedOstream()){ + Notice.setStream(&null_os); + } + if(Chat.getStreamPointer() == getManagedOstream()){ + Chat.setStream(&null_os); + } + if(Trace.getStreamPointer() == getManagedOstream()){ + Trace.setStream(&null_os); + } +} + + +std::string ManagedDiagnosticOutputChannel::defaultSource() const { + return options::diagnosticChannelName(); +} +void ManagedDiagnosticOutputChannel::initialize(std::ostream* outStream) { + DebugOstreamUpdate debugOstreamUpdate; + debugOstreamUpdate.apply(outStream); + WarningOstreamUpdate warningOstreamUpdate; + warningOstreamUpdate.apply(outStream); + MessageOstreamUpdate messageOstreamUpdate; + messageOstreamUpdate.apply(outStream); + NoticeOstreamUpdate noticeOstreamUpdate; + noticeOstreamUpdate.apply(outStream); + ChatOstreamUpdate chatOstreamUpdate; + chatOstreamUpdate.apply(outStream); + TraceOstreamUpdate traceOstreamUpdate; + traceOstreamUpdate.apply(outStream); + OptionsErrOstreamUpdate optionsErrOstreamUpdate; + optionsErrOstreamUpdate.apply(outStream); +} + +void ManagedDiagnosticOutputChannel::addSpecialCases(OstreamOpener* opener) + const { + opener->addSpecialCase("stdout", &std::cout); + opener->addSpecialCase("stderr", &std::cerr); +} + + +ManagedReplayLogOstream::ManagedReplayLogOstream() : d_replayLog(NULL) {} +ManagedReplayLogOstream::~ManagedReplayLogOstream(){ + if(d_replayLog != NULL) { + (*d_replayLog) << std::flush; + } +} + +std::string ManagedReplayLogOstream::defaultSource() const { + return options::replayLogFilename(); +} + +void ManagedReplayLogOstream::initialize(std::ostream* outStream) { + if(outStream != NULL){ + *outStream << language::SetLanguage(options::outputLanguage()) + << expr::ExprSetDepth(-1); + } + /* Do this regardless of managing the memory. */ + d_replayLog = outStream; +} + +/** Adds special cases to an ostreamopener. */ +void ManagedReplayLogOstream::addSpecialCases(OstreamOpener* opener) const { + opener->addSpecialCase("-", &std::cout); +} + + +}/* CVC4 namespace */ diff --git a/src/smt/managed_ostreams.h b/src/smt/managed_ostreams.h new file mode 100644 index 000000000..05d026b24 --- /dev/null +++ b/src/smt/managed_ostreams.h @@ -0,0 +1,181 @@ +/********************* */ +/*! \file managed_ostreams.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2016 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief Wrappers to handle memory management of ostreams. + ** + ** This file contains wrappers to handle special cases of managing memory + ** related to ostreams. + **/ + +#include "cvc4_private.h" + +#ifndef __CVC4__MANAGED_OSTREAMS_H +#define __CVC4__MANAGED_OSTREAMS_H + +#include + +#include "options/open_ostream.h" +#include "smt/update_ostream.h" + +namespace CVC4 { + +/** This abstracts the management of ostream memory and initialization. */ +class ManagedOstream { + public: + /** Initially getManagedOstream() == NULL. */ + ManagedOstream(); + virtual ~ManagedOstream(); + + /** Returns the pointer to the managed ostream. */ + std::ostream* getManagedOstream() const { return d_managed; } + + /** Returns the name of the ostream geing managed. */ + virtual const char* getName() const = 0; + + /** + * Set opens a file with filename, initializes the stream. + * If the opened ostream is marked as managed, this calls manage(stream). + * If the opened ostream is not marked as managed, this calls manage(NULL). + */ + void set(const std::string& filename); + + /** If this is associated with an option, return the string value. */ + virtual std::string defaultSource() { return ""; } + + protected: + + /** + * Opens an ostream using OstreamOpener with the name getName() with the + * special cases added by addSpecialCases(). + */ + std::pair open(const std::string& filename) const; + + /** + * Updates the value of managed pointer. Whenever this changes, + * beforeRelease() is called on the old value. + */ + void manage(std::ostream* new_managed_value); + + /** Initializes an output stream. Not necessarily managed. */ + virtual void initialize(std::ostream* outStream) {} + + /** Adds special cases to an ostreamopener. */ + virtual void addSpecialCases(OstreamOpener* opener) const {} + + private: + std::ostream* d_managed; +}; /* class ManagedOstream */ + +class SetToDefaultSourceListener : public Listener { + public: + SetToDefaultSourceListener(ManagedOstream* managedOstream) + : d_managedOstream(managedOstream){} + + virtual void notify() { + d_managedOstream->set(d_managedOstream->defaultSource()); + } + + private: + ManagedOstream* d_managedOstream; +}; + +/** + * This controls the memory associated with --dump-to. + * This is is assumed to recieve a set whenever diagnosticChannelName + * is updated. + */ +class ManagedDumpOStream : public ManagedOstream { + public: + ManagedDumpOStream(){} + ~ManagedDumpOStream(); + + virtual const char* getName() const { return "dump-to"; } + virtual std::string defaultSource() const; + + protected: + /** Initializes an output stream. Not necessarily managed. */ + virtual void initialize(std::ostream* outStream); + + /** Adds special cases to an ostreamopener. */ + virtual void addSpecialCases(OstreamOpener* opener) const; +};/* class ManagedDumpOStream */ + +/** + * When d_managedRegularChannel is non-null, it owns the memory allocated + * with the regular-output-channel. This is set when + * options::regularChannelName is set. + */ +class ManagedRegularOutputChannel : public ManagedOstream { + public: + ManagedRegularOutputChannel(){} + + /** Assumes Options are in scope. */ + ~ManagedRegularOutputChannel(); + + virtual const char* getName() const { return "regular-output-channel"; } + virtual std::string defaultSource() const; + + protected: + /** Initializes an output stream. Not necessarily managed. */ + virtual void initialize(std::ostream* outStream); + + /** Adds special cases to an ostreamopener. */ + virtual void addSpecialCases(OstreamOpener* opener) const; +};/* class ManagedRegularOutputChannel */ + + +/** + * This controls the memory associated with diagnostic-output-channel. + * This is is assumed to recieve a set whenever options::diagnosticChannelName + * is updated. + */ +class ManagedDiagnosticOutputChannel : public ManagedOstream { + public: + ManagedDiagnosticOutputChannel(){} + + /** Assumes Options are in scope. */ + ~ManagedDiagnosticOutputChannel(); + + virtual const char* getName() const { return "diagnostic-output-channel"; } + virtual std::string defaultSource() const; + + protected: + /** Initializes an output stream. Not necessarily managed. */ + virtual void initialize(std::ostream* outStream); + + /** Adds special cases to an ostreamopener. */ + virtual void addSpecialCases(OstreamOpener* opener) const; +};/* class ManagedRegularOutputChannel */ + +/** This controls the memory associated with replay-log. */ +class ManagedReplayLogOstream : public ManagedOstream { + public: + ManagedReplayLogOstream(); + ~ManagedReplayLogOstream(); + + std::ostream* getReplayLog() const { return d_replayLog; } + virtual const char* getName() const { return "replay-log"; } + virtual std::string defaultSource() const; + + protected: + /** Initializes an output stream. Not necessarily managed. */ + virtual void initialize(std::ostream* outStream); + + /** Adds special cases to an ostreamopener. */ + virtual void addSpecialCases(OstreamOpener* opener) const; + + private: + std::ostream* d_replayLog; +};/* class ManagedRegularOutputChannel */ + +}/* CVC4 namespace */ + +#endif /* __CVC4__MANAGED_OSTREAMS_H */ diff --git a/src/smt/smt_engine.cpp b/src/smt/smt_engine.cpp index c66031265..df3466d92 100644 --- a/src/smt/smt_engine.cpp +++ b/src/smt/smt_engine.cpp @@ -26,6 +26,8 @@ #include #include +#include "base/configuration.h" +#include "base/configuration_private.h" #include "base/exception.h" #include "base/listener.h" #include "base/modal_exception.h" @@ -52,8 +54,8 @@ #include "options/decision_mode.h" #include "options/decision_options.h" #include "options/main_options.h" +#include "options/open_ostream.h" #include "options/option_exception.h" -#include "options/options_handler_interface.h" #include "options/printer_options.h" #include "options/prop_options.h" #include "options/quantifiers_options.h" @@ -72,9 +74,10 @@ #include "smt/boolean_terms.h" #include "smt/command_list.h" #include "smt/logic_request.h" +#include "smt/managed_ostreams.h" #include "smt/model_postprocessor.h" #include "smt/smt_engine_scope.h" -#include "smt/smt_options_handler.h" +#include "smt/update_ostream.h" #include "smt_util/boolean_simplification.h" #include "smt_util/command.h" #include "smt_util/ite_removal.h" @@ -95,8 +98,6 @@ #include "theory/theory_engine.h" #include "theory/theory_model.h" #include "theory/theory_traits.h" -#include "util/configuration.h" -#include "util/configuration_private.h" #include "util/hash.h" #include "util/proof.h" #include "util/resource_manager.h" @@ -322,6 +323,125 @@ class HardResourceOutListener : public Listener { SmtEngine* d_smt; }; /* class HardResourceOutListener */ +class SetLogicListener : public Listener { + public: + SetLogicListener(SmtEngine& smt) : d_smt(&smt) {} + virtual void notify() { + LogicInfo inOptions(options::forceLogicString()); + d_smt->setLogic(inOptions); + } + private: + SmtEngine* d_smt; +}; /* class SetLogicListener */ + +class BeforeSearchListener : public Listener { + public: + BeforeSearchListener(SmtEngine& smt) : d_smt(&smt) {} + virtual void notify() { + d_smt->beforeSearch(); + } + private: + SmtEngine* d_smt; +}; /* class BeforeSearchListener */ + +class UseTheoryListListener : public Listener { + public: + UseTheoryListListener(TheoryEngine* theoryEngine) + : d_theoryEngine(theoryEngine) + {} + + void notify() { + std::stringstream commaList(options::useTheoryList()); + std::string token; + + Debug("UseTheoryListListener") << "UseTheoryListListener::notify() " + << options::useTheoryList() << std::endl; + + while(std::getline(commaList, token, ',')){ + if(token == "help") { + puts(theory::useTheoryHelp); + exit(1); + } + if(theory::useTheoryValidate(token)) { + d_theoryEngine->enableTheoryAlternative(token); + } else { + throw OptionException( + std::string("unknown option for --use-theory : `") + token + + "'. Try --use-theory=help."); + } + } + } + + private: + TheoryEngine* d_theoryEngine; +}; /* class UseTheoryListListener */ + + +class SetDefaultExprDepthListener : public Listener { + public: + virtual void notify() { + int depth = options::defaultExprDepth(); + Debug.getStream() << expr::ExprSetDepth(depth); + Trace.getStream() << expr::ExprSetDepth(depth); + Notice.getStream() << expr::ExprSetDepth(depth); + Chat.getStream() << expr::ExprSetDepth(depth); + Message.getStream() << expr::ExprSetDepth(depth); + Warning.getStream() << expr::ExprSetDepth(depth); + // intentionally exclude Dump stream from this list + } +}; + +class SetDefaultExprDagListener : public Listener { + public: + virtual void notify() { + int dag = options::defaultDagThresh(); + Debug.getStream() << expr::ExprDag(dag); + Trace.getStream() << expr::ExprDag(dag); + Notice.getStream() << expr::ExprDag(dag); + Chat.getStream() << expr::ExprDag(dag); + Message.getStream() << expr::ExprDag(dag); + Warning.getStream() << expr::ExprDag(dag); + Dump.getStream() << expr::ExprDag(dag); + } +}; + +class SetPrintExprTypesListener : public Listener { + public: + virtual void notify() { + bool value = options::printExprTypes(); + Debug.getStream() << expr::ExprPrintTypes(value); + Trace.getStream() << expr::ExprPrintTypes(value); + Notice.getStream() << expr::ExprPrintTypes(value); + Chat.getStream() << expr::ExprPrintTypes(value); + Message.getStream() << expr::ExprPrintTypes(value); + Warning.getStream() << expr::ExprPrintTypes(value); + // intentionally exclude Dump stream from this list + } +}; + +class DumpModeListener : public Listener { + public: + virtual void notify() { + const std::string& value = options::dumpModeString(); + Dump.setDumpFromString(value); + } +}; + +class PrintSuccessListener : public Listener { + public: + virtual void notify() { + bool value = options::printSuccess(); + Debug.getStream() << Command::printsuccess(value); + Trace.getStream() << Command::printsuccess(value); + Notice.getStream() << Command::printsuccess(value); + Chat.getStream() << Command::printsuccess(value); + Message.getStream() << Command::printsuccess(value); + Warning.getStream() << Command::printsuccess(value); + *options::out() << Command::printsuccess(value); + } +}; + + /** * This is an inelegant solution, but for the present, it will work. @@ -340,20 +460,38 @@ class HardResourceOutListener : public Listener { class SmtEnginePrivate : public NodeManagerListener { SmtEngine& d_smt; + typedef hash_map NodeToNodeHashMap; + typedef hash_map NodeToBoolHashMap; + /** * Manager for limiting time and abstract resource usage. */ ResourceManager* d_resourceManager; - /** - * Listener for the when a soft resource out occurs. - */ - RegisterListener* d_softResourceOutListener; + /** Manager for the memory of regular-output-channel. */ + ManagedRegularOutputChannel d_managedRegularChannel; + + /** Manager for the memory of diagnostic-output-channel. */ + ManagedDiagnosticOutputChannel d_managedDiagnosticChannel; + + /** Manager for the memory of --dump-to. */ + ManagedDumpOStream d_managedDumpChannel; + + /** Manager for --replay-log. */ + ManagedReplayLogOstream d_managedReplayLog; /** - * Listener for the when a hard resource out occurs. + * This list contains: + * softResourceOut + * hardResourceOut + * setForceLogic + * beforeSearchListener + * UseTheoryListListener + * + * This needs to be deleted before both NodeManager's Options, + * SmtEngine, d_resourceManager, and TheoryEngine. */ - RegisterListener* d_hardResourceOutListener; + ListenerRegistrationList* d_listenerRegistrations; /** Learned literals */ vector d_nonClausalLearnedLiterals; @@ -399,7 +537,7 @@ class SmtEnginePrivate : public NodeManagerListener { * same AbstractValues for the same real constants. Only used if * options::abstractValues() is on. */ - hash_map d_abstractValues; + NodeToNodeHashMap d_abstractValues; /** Number of calls of simplify assertions active. */ @@ -442,18 +580,20 @@ private: */ void removeITEs(); - Node intToBV(TNode n, std::hash_map& cache); - Node intToBVMakeBinary(TNode n, std::hash_map& cache); + Node intToBV(TNode n, NodeToNodeHashMap& cache); + Node intToBVMakeBinary(TNode n, NodeToNodeHashMap& cache); /** - * Helper function to fix up assertion list to restore invariants needed after ite removal + * Helper function to fix up assertion list to restore invariants needed after + * ite removal. */ - void collectSkolems(TNode n, set& skolemSet, hash_map& cache); + void collectSkolems(TNode n, set& skolemSet, NodeToBoolHashMap& cache); /** - * Helper function to fix up assertion list to restore invariants needed after ite removal + * Helper function to fix up assertion list to restore invariants needed after + * ite removal. */ - bool checkForBadSkolems(TNode n, TNode skolem, hash_map& cache); + bool checkForBadSkolems(TNode n, TNode skolem, NodeToBoolHashMap& cache); // Lift bit-vectors of size 1 to booleans void bvToBool(); @@ -468,8 +608,10 @@ private: // Simplify based on unconstrained values void unconstrainedSimp(); - // Ensures the assertions asserted after before now - // effectively come before d_realAssertionsEnd + /** + * Ensures the assertions asserted after before now effectively come before + * d_realAssertionsEnd. + */ void compressBeforeRealAssertions(size_t before); /** @@ -480,12 +622,21 @@ private: void constrainSubtypes(TNode n, AssertionPipeline& assertions) throw(); - // trace nodes back to their assertions using CircuitPropagator's BackEdgesMap - void traceBackToAssertions(const std::vector& nodes, std::vector& assertions); - // remove conjuncts in toRemove from conjunction n; return # of removed conjuncts - size_t removeFromConjunction(Node& n, const std::hash_set& toRemove); + /** + * Trace nodes back to their assertions using CircuitPropagator's + * BackEdgesMap. + */ + void traceBackToAssertions(const std::vector& nodes, + std::vector& assertions); - // scrub miplib encodings + /** + * Remove conjuncts in toRemove from conjunction n. Return # of removed + * conjuncts. + */ + size_t removeFromConjunction(Node& n, + const std::hash_set& toRemove); + + /** Scrub miplib encodings. */ void doMiplibTrick(); /** @@ -495,15 +646,18 @@ private: * * Returns false if the formula simplifies to "false" */ - bool simplifyAssertions() throw(TypeCheckingException, LogicException, UnsafeInterruptException); + bool simplifyAssertions() throw(TypeCheckingException, LogicException, + UnsafeInterruptException); public: SmtEnginePrivate(SmtEngine& smt) : d_smt(smt), - d_resourceManager(NULL), - d_softResourceOutListener(NULL), - d_hardResourceOutListener(NULL), + d_managedRegularChannel(), + d_managedDiagnosticChannel(), + d_managedDumpChannel(), + d_managedReplayLog(), + d_listenerRegistrations(new ListenerRegistrationList()), d_nonClausalLearnedLiterals(), d_realAssertionsEnd(0), d_booleanTermConverter(NULL), @@ -525,21 +679,59 @@ public: d_true = NodeManager::currentNM()->mkConst(true); d_resourceManager = NodeManager::currentResourceManager(); - d_softResourceOutListener = new RegisterListener( - d_resourceManager->getSoftListeners(), - new SoftResourceOutListener(d_smt)); - - d_hardResourceOutListener = new RegisterListener( - d_resourceManager->getHardListeners(), - new HardResourceOutListener(d_smt)); - + d_listenerRegistrations->add(d_resourceManager->registerSoftListener( + new SoftResourceOutListener(d_smt))); + + d_listenerRegistrations->add(d_resourceManager->registerHardListener( + new HardResourceOutListener(d_smt))); + + Options& nodeManagerOptions = NodeManager::currentNM()->getOptions(); + d_listenerRegistrations->add( + nodeManagerOptions.registerForceLogicListener( + new SetLogicListener(d_smt), true)); + + // Multiple options reuse BeforeSearchListener so registration requires an + // extra bit of care. + // We can safely not call notify on this before search listener at + // registration time. This d_smt cannot be beforeSearch at construction + // time. Therefore the BeforeSearchListener is a no-op. Therefore it does + // not have to be called. + d_listenerRegistrations->add( + nodeManagerOptions.registerBeforeSearchListener( + new BeforeSearchListener(d_smt))); + + // These do need registration calls. + d_listenerRegistrations->add( + nodeManagerOptions.registerSetDefaultExprDepthListener( + new SetDefaultExprDepthListener(), true)); + d_listenerRegistrations->add( + nodeManagerOptions.registerSetDefaultExprDagListener( + new SetDefaultExprDagListener(), true)); + d_listenerRegistrations->add( + nodeManagerOptions.registerSetPrintExprTypesListener( + new SetPrintExprTypesListener(), true)); + d_listenerRegistrations->add( + nodeManagerOptions.registerSetDumpModeListener( + new DumpModeListener(), true)); + d_listenerRegistrations->add( + nodeManagerOptions.registerSetPrintSuccessListener( + new PrintSuccessListener(), true)); + d_listenerRegistrations->add( + nodeManagerOptions.registerSetRegularOutputChannelListener( + new SetToDefaultSourceListener(&d_managedRegularChannel), true)); + d_listenerRegistrations->add( + nodeManagerOptions.registerSetDiagnosticOutputChannelListener( + new SetToDefaultSourceListener(&d_managedDiagnosticChannel), true)); + d_listenerRegistrations->add( + nodeManagerOptions.registerDumpToFileNameListener( + new SetToDefaultSourceListener(&d_managedDumpChannel), true)); + d_listenerRegistrations->add( + nodeManagerOptions.registerSetReplayLogFilename( + new SetToDefaultSourceListener(&d_managedReplayLog), true)); } ~SmtEnginePrivate() throw() { - delete d_hardResourceOutListener; - d_hardResourceOutListener = NULL; - delete d_softResourceOutListener; - d_softResourceOutListener = NULL; + delete d_listenerRegistrations; if(d_propagatorNeedsFinish) { d_propagator.finish(); @@ -642,11 +834,10 @@ public: void addFormula(TNode n, bool inUnsatCore, bool inInput = true) throw(TypeCheckingException, LogicException); - /** - * Expand definitions in n. - */ - Node expandDefinitions(TNode n, hash_map& cache, bool expandOnly = false) - throw(TypeCheckingException, LogicException, UnsafeInterruptException); + /** Expand definitions in n. */ + Node expandDefinitions(TNode n, NodeToNodeHashMap& cache, + bool expandOnly = false) + throw(TypeCheckingException, LogicException, UnsafeInterruptException); /** * Rewrite Boolean terms in a Node. @@ -660,7 +851,7 @@ public: Node simplify(TNode in) { // Substitute out any abstract values in ex. // Expand definitions. - hash_map cache; + NodeToNodeHashMap cache; Node n = expandDefinitions(in, cache).toExpr(); // Make sure we've done all preprocessing, etc. Assert(d_assertions.size() == 0); @@ -689,24 +880,33 @@ public: d_abstractValueMap.addSubstitution(val, n); } // We are supposed to ascribe types to all abstract values that go out. - Node retval = d_smt.d_nodeManager->mkNode(kind::APPLY_TYPE_ASCRIPTION, d_smt.d_nodeManager->mkConst(AscriptionType(n.getType().toType())), val); + NodeManager* current = d_smt.d_nodeManager; + Node ascription = current->mkConst(AscriptionType(n.getType().toType())); + Node retval = current->mkNode(kind::APPLY_TYPE_ASCRIPTION, ascription, val); return retval; } - std::hash_map rewriteApplyToConstCache; + NodeToNodeHashMap d_rewriteApplyToConstCache; Node rewriteApplyToConst(TNode n) { Trace("rewriteApplyToConst") << "rewriteApplyToConst :: " << n << std::endl; - if(n.getMetaKind() == kind::metakind::CONSTANT || n.getMetaKind() == kind::metakind::VARIABLE) { + if(n.getMetaKind() == kind::metakind::CONSTANT || + n.getMetaKind() == kind::metakind::VARIABLE) + { return n; } - if(rewriteApplyToConstCache.find(n) != rewriteApplyToConstCache.end()) { - Trace("rewriteApplyToConst") << "in cache :: " << rewriteApplyToConstCache[n] << std::endl; - return rewriteApplyToConstCache[n]; + if(d_rewriteApplyToConstCache.find(n) != d_rewriteApplyToConstCache.end()) { + Trace("rewriteApplyToConst") << "in cache :: " + << d_rewriteApplyToConstCache[n] + << std::endl; + return d_rewriteApplyToConstCache[n]; } + if(n.getKind() == kind::APPLY_UF) { - if(n.getNumChildren() == 1 && n[0].isConst() && n[0].getType().isInteger()) { + if(n.getNumChildren() == 1 && n[0].isConst() && + n[0].getType().isInteger()) + { stringstream ss; ss << n.getOperator() << "_"; if(n[0].getConst() < 0) { @@ -714,15 +914,19 @@ public: } else { ss << n[0]; } - Node newvar = NodeManager::currentNM()->mkSkolem(ss.str(), n.getType(), "rewriteApplyToConst skolem", NodeManager::SKOLEM_EXACT_NAME); - rewriteApplyToConstCache[n] = newvar; + Node newvar = NodeManager::currentNM()->mkSkolem( + ss.str(), n.getType(), "rewriteApplyToConst skolem", + NodeManager::SKOLEM_EXACT_NAME); + d_rewriteApplyToConstCache[n] = newvar; Trace("rewriteApplyToConst") << "made :: " << newvar << std::endl; return newvar; } else { stringstream ss; - ss << "The rewrite-apply-to-const preprocessor is currently limited;\n" - << "it only works if all function symbols are unary and with Integer\n" - << "domain, and all applications are to integer values.\n" + ss << "The rewrite-apply-to-const preprocessor is currently limited;" + << std::endl + << "it only works if all function symbols are unary and with Integer" + << std::endl + << "domain, and all applications are to integer values." << std::endl << "Found application: " << n; Unhandled(ss.str()); } @@ -736,11 +940,21 @@ public: builder << rewriteApplyToConst(n[i]); } Node rewr = builder; - rewriteApplyToConstCache[n] = rewr; + d_rewriteApplyToConstCache[n] = rewr; Trace("rewriteApplyToConst") << "built :: " << rewr << std::endl; return rewr; } + void addUseTheoryListListener(TheoryEngine* theoryEngine){ + Options& nodeManagerOptions = NodeManager::currentNM()->getOptions(); + d_listenerRegistrations->add( + nodeManagerOptions.registerUseTheoryListListener( + new UseTheoryListListener(theoryEngine), true)); + } + + std::ostream* getReplayLog() const { + return d_managedReplayLog.getReplayLog(); + } };/* class SmtEnginePrivate */ }/* namespace CVC4::smt */ @@ -765,7 +979,7 @@ SmtEngine::SmtEngine(ExprManager* em) throw() : d_dumpCommands(), d_defineCommands(), d_logic(), - d_originalOptions(em->getOptions()), + d_originalOptions(), d_pendingPops(0), d_fullyInited(false), d_problemExtended(false), @@ -773,15 +987,15 @@ SmtEngine::SmtEngine(ExprManager* em) throw() : d_needPostsolve(false), d_earlyTheoryPP(true), d_status(), - d_optionsHandler(new SmtOptionsHandler(this)), + d_replayStream(NULL), d_private(NULL), d_smtAttributes(NULL), d_statisticsRegistry(NULL), d_stats(NULL), - d_globals(new SmtGlobals()) + d_channels(new LemmaChannels()) { - SmtScope smts(this); + d_originalOptions.copyValues(em->getOptions()); d_smtAttributes = new expr::attr::SmtAttributes(d_context); d_private = new smt::SmtEnginePrivate(*this); d_statisticsRegistry = new StatisticsRegistry(); @@ -800,7 +1014,7 @@ SmtEngine::SmtEngine(ExprManager* em) throw() : d_theoryEngine = new TheoryEngine(d_context, d_userContext, d_private->d_iteRemover, const_cast(d_logic), - d_globals); + d_channels); // Add the theories for(TheoryId id = theory::THEORY_FIRST; id < theory::THEORY_LAST; ++id) { @@ -809,6 +1023,8 @@ SmtEngine::SmtEngine(ExprManager* em) throw() : THEORY_PROOF(ProofManager::currentPM()->getTheoryProofEngine()->registerTheory(d_theoryEngine->theoryOf(id)); ); } + d_private->addUseTheoryListListener(d_theoryEngine); + // global push/pop around everything, to ensure proper destruction // of context-dependent data structures d_userContext->push(); @@ -830,7 +1046,8 @@ void SmtEngine::finishInit() { d_decisionEngine->init(); // enable appropriate strategies d_propEngine = new PropEngine(d_theoryEngine, d_decisionEngine, d_context, - d_userContext, d_globals); + d_userContext, d_private->getReplayLog(), + d_replayStream, d_channels); d_theoryEngine->setPropEngine(d_propEngine); d_theoryEngine->setDecisionEngine(d_decisionEngine); @@ -959,9 +1176,6 @@ SmtEngine::~SmtEngine() throw() { delete d_statisticsRegistry; d_statisticsRegistry = NULL; - delete d_optionsHandler; - d_optionsHandler = NULL; - delete d_private; d_private = NULL; @@ -973,8 +1187,8 @@ SmtEngine::~SmtEngine() throw() { delete d_context; d_context = NULL; - delete d_globals; - d_globals = NULL; + delete d_channels; + d_channels = NULL; } catch(Exception& e) { Warning() << "CVC4 threw an exception during cleanup." << endl @@ -985,13 +1199,15 @@ SmtEngine::~SmtEngine() throw() { void SmtEngine::setLogic(const LogicInfo& logic) throw(ModalException) { SmtScope smts(this); if(d_fullyInited) { - throw ModalException("Cannot set logic in SmtEngine after the engine has finished initializing"); + throw ModalException("Cannot set logic in SmtEngine after the engine has " + "finished initializing."); } d_logic = logic; setLogicInternal(); } -void SmtEngine::setLogic(const std::string& s) throw(ModalException, LogicException) { +void SmtEngine::setLogic(const std::string& s) + throw(ModalException, LogicException) { SmtScope smts(this); try { setLogic(LogicInfo(s)); @@ -1000,7 +1216,8 @@ void SmtEngine::setLogic(const std::string& s) throw(ModalException, LogicExcept } } -void SmtEngine::setLogic(const char* logic) throw(ModalException, LogicException) { +void SmtEngine::setLogic(const char* logic) + throw(ModalException, LogicException) { setLogic(string(logic)); } @@ -1009,13 +1226,14 @@ LogicInfo SmtEngine::getLogicInfo() const { } void SmtEngine::setLogicInternal() throw() { - Assert(!d_fullyInited, "setting logic in SmtEngine but the engine has already finished initializing for this run"); + Assert(!d_fullyInited, "setting logic in SmtEngine but the engine has already" + " finished initializing for this run"); d_logic.lock(); } void SmtEngine::setDefaults() { - if(options::forceLogic.wasSetByUser()) { - d_logic = *(options::forceLogic()); + if(options::forceLogicString.wasSetByUser()) { + d_logic = LogicInfo(options::forceLogicString()); } else if (options::solveIntAsBV() > 0) { d_logic = LogicInfo("QF_BV"); @@ -1039,11 +1257,13 @@ void SmtEngine::setDefaults() { d_logic = d_logic.getUnlockedCopy(); d_logic.enableQuantifiers(); d_logic.lock(); - Trace("smt") << "turning on quantifier logic, for strings-exp" << std::endl; + Trace("smt") << "turning on quantifier logic, for strings-exp" + << std::endl; } if(! options::finiteModelFind.wasSetByUser()) { options::finiteModelFind.set( true ); - Trace("smt") << "turning on finite-model-find, for strings-exp" << std::endl; + Trace("smt") << "turning on finite-model-find, for strings-exp" + << std::endl; } if(! options::fmfBoundInt.wasSetByUser()) { if(! options::fmfBoundIntLazy.wasSetByUser()) { @@ -1067,7 +1287,8 @@ void SmtEngine::setDefaults() { if(options::checkModels()) { if(! options::produceAssertions()) { - Notice() << "SmtEngine: turning on produce-assertions to support check-models" << endl; + Notice() << "SmtEngine: turning on produce-assertions to support " + << "check-models." << endl; setOption("produce-assertions", SExpr("true")); } } @@ -1077,7 +1298,8 @@ void SmtEngine::setDefaults() { if(options::simplificationMode.wasSetByUser()) { throw OptionException("simplification not supported with unsat cores"); } - Notice() << "SmtEngine: turning off simplification to support unsat-cores" << endl; + Notice() << "SmtEngine: turning off simplification to support unsat-cores" + << endl; options::simplificationMode.set(SIMPLIFICATION_MODE_NONE); } @@ -4923,9 +5145,10 @@ void SmtEngine::reset() throw() { if(Dump.isOn("benchmark")) { Dump("benchmark") << ResetCommand(); } - Options opts = d_originalOptions; + Options opts; + opts.copyValues(d_originalOptions); this->~SmtEngine(); - NodeManager::fromExprManager(em)->getOptions() = opts; + NodeManager::fromExprManager(em)->getOptions().copyValues(opts); new(this) SmtEngine(em); } @@ -5022,11 +5245,10 @@ void SmtEngine::setPrintFuncInModel(Expr f, bool p) { -void SmtEngine::beforeSearch(SmtEngine* smt, const std::string& option) throw(ModalException) { - if(smt != NULL && smt->d_fullyInited) { - std::stringstream ss; - ss << "cannot change option `" << option << "' after final initialization (i.e., after logic has been set)"; - throw ModalException(ss.str()); +void SmtEngine::beforeSearch() throw(ModalException) { + if(d_fullyInited) { + throw ModalException( + "SmtEngine::beforeSearch called after initialization."); } } @@ -5064,8 +5286,8 @@ void SmtEngine::setOption(const std::string& key, const CVC4::SExpr& value) } string optionarg = value.getValue(); - - d_optionsHandler->setOption(key, optionarg); + Options& nodeManagerOptions = NodeManager::currentNM()->getOptions(); + nodeManagerOptions.setOption(key, optionarg); } CVC4::SExpr SmtEngine::getOption(const std::string& key) const @@ -5121,7 +5343,14 @@ CVC4::SExpr SmtEngine::getOption(const std::string& key) const return SExpr(result); } - return SExpr::parseAtom(d_optionsHandler->getOption(key)); + Options& nodeManagerOptions = NodeManager::currentNM()->getOptions(); + return SExpr::parseAtom(nodeManagerOptions.getOption(key)); +} + +void SmtEngine::setReplayStream(ExprStream* replayStream) { + AlwaysAssert(!d_fullyInited, + "Cannot set replay stream once fully initialized"); + d_replayStream = replayStream; } }/* CVC4 namespace */ diff --git a/src/smt/smt_engine.h b/src/smt/smt_engine.h index 2f222790c..3616762bc 100644 --- a/src/smt/smt_engine.h +++ b/src/smt/smt_engine.h @@ -28,10 +28,11 @@ #include "context/cdlist_forward.h" #include "expr/expr.h" #include "expr/expr_manager.h" +#include "expr/expr_stream.h" #include "options/options.h" #include "proof/unsat_core.h" #include "smt/logic_exception.h" -#include "smt/smt_globals.h" +#include "smt_util/lemma_channels.h" #include "theory/logic_info.h" #include "util/hash.h" #include "util/proof.h" @@ -73,10 +74,6 @@ namespace prop { class PropEngine; }/* CVC4::prop namespace */ -namespace options { - class OptionsHandler; -}/* CVC4::prop namespace */ - namespace expr { namespace attr { class AttributeManager; @@ -267,10 +264,8 @@ class CVC4_PUBLIC SmtEngine { */ std::map d_commandVerbosity; - /** - * This responds to requests to set options. - */ - options::OptionsHandler* d_optionsHandler; + /** ReplayStream for the solver. */ + ExprStream* d_replayStream; /** * A private utility class to SmtEngine. @@ -386,7 +381,8 @@ class CVC4_PUBLIC SmtEngine { smt::SmtEngineStatistics* d_stats; - SmtGlobals* d_globals; + /** Container for the lemma input and output channels for this SmtEngine.*/ + LemmaChannels* d_channels; /** * Add to Model command. This is used for recording a command @@ -728,12 +724,19 @@ public: void setPrintFuncInModel(Expr f, bool p); + /** Throws a ModalException if the SmtEngine has been fully initialized. */ + void beforeSearch() throw(ModalException); + + LemmaChannels* channels() { return d_channels; } + + /** - * Throws a ModalException if smt is non-null and the SmtEngine has not been fully initialized. + * Expermintal feature: Sets the sequence of decisions. + * This currently requires very fine grained knowledge about literal + * translation. */ - static void beforeSearch(SmtEngine* smt, const std::string& option) throw(ModalException); + void setReplayStream(ExprStream* exprStream); - SmtGlobals* globals() { return d_globals; } };/* class SmtEngine */ }/* CVC4 namespace */ diff --git a/src/smt/smt_engine_check_proof.cpp b/src/smt/smt_engine_check_proof.cpp index 14adcc536..354a43cc8 100644 --- a/src/smt/smt_engine_check_proof.cpp +++ b/src/smt/smt_engine_check_proof.cpp @@ -25,10 +25,10 @@ #warning "TODO: Why is lfsc's check.h being included like this?" #include "check.h" +#include "base/configuration_private.h" #include "base/cvc4_assert.h" #include "base/output.h" #include "smt/smt_engine.h" -#include "util/configuration_private.h" #include "util/statistics_registry.h" using namespace CVC4; diff --git a/src/smt/smt_engine_scope.h b/src/smt/smt_engine_scope.h index c4ec15371..5a7e39849 100644 --- a/src/smt/smt_engine_scope.h +++ b/src/smt/smt_engine_scope.h @@ -19,6 +19,7 @@ #pragma once +#include "base/configuration_private.h" #include "base/cvc4_assert.h" #include "base/output.h" #include "base/tls.h" @@ -27,7 +28,6 @@ #include "proof/proof_manager.h" #include "options/smt_options.h" #include "smt/smt_engine.h" -#include "util/configuration_private.h" namespace CVC4 { diff --git a/src/smt/smt_globals.cpp b/src/smt/smt_globals.cpp deleted file mode 100644 index 4c1b0dc72..000000000 --- a/src/smt/smt_globals.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/********************* */ -/*! \file smt_globals.cpp - ** \verbatim - ** Original author: Tim King - ** Major contributors: none - ** Minor contributors (to current version): none - ** This file is part of the CVC4 project. - ** Copyright (c) 2009-2015 New York University and The University of Iowa - ** See the file COPYING in the top-level source directory for licensing - ** information.\endverbatim - ** - ** \brief This class is a light container for globals that used to live - ** in options. This is NOT a good long term solution, but is a reasonable - ** stop gap. - ** - ** This class is a light container for globals that used to live - ** in options. This is NOT a good long term solution, but is a reasonable - ** stop gap. - **/ - -#include "smt/smt_globals.h" - -#include -#include -#include -#include - -#include "cvc4autoconfig.h" // Needed for CVC4_REPLAY -#include "expr/expr_stream.h" -#include "options/option_exception.h" -#include "options/parser_options.h" -#include "smt_util/lemma_input_channel.h" -#include "smt_util/lemma_output_channel.h" -#include "smt/smt_options_handler.h" - -namespace CVC4 { - -SmtGlobals::SmtGlobals() - : d_gcReplayLog(false) - , d_replayLog(NULL) - , d_replayStream(NULL) - , d_lemmaInputChannel(NULL) - , d_lemmaOutputChannel(NULL) -{} - -SmtGlobals::~SmtGlobals(){ - if(d_gcReplayLog){ - delete d_replayLog; - d_gcReplayLog = false; - d_replayLog = NULL; - } -} - -void SmtGlobals::setReplayLog(std::ostream* log){ - d_replayLog = log; -} - -void SmtGlobals::setReplayStream(ExprStream* stream) { - d_replayStream = stream; -} - -void SmtGlobals::setLemmaInputChannel(LemmaInputChannel* in) { - d_lemmaInputChannel = in; -} - -void SmtGlobals::setLemmaOutputChannel(LemmaOutputChannel* out) { - d_lemmaOutputChannel = out; -} - -void SmtGlobals::parseReplayLog(std::string optarg) throw (OptionException) { - if(d_gcReplayLog){ - delete d_replayLog; - d_gcReplayLog = false; - d_replayLog = NULL; - } - - std::pair checkResult = checkReplayLogFilename(optarg); - d_gcReplayLog = checkResult.first; - d_replayLog = checkResult.second; -} - -#warning "TODO: Move checkReplayLogFilename back into options and has calling setReplayLog as a side effect." -std::pair SmtGlobals::checkReplayLogFilename(std::string optarg) - throw (OptionException) -{ -#ifdef CVC4_REPLAY - if(optarg == "") { - throw OptionException(std::string("Bad file name for --replay-log")); - } else if(optarg == "-") { - return std::make_pair(false, &std::cout); - } else if(!options::filesystemAccess()) { - throw OptionException(std::string("Filesystem access not permitted")); - } else { - errno = 0; - std::ios_base::openmode out_trunc = std::ofstream::out | std::ofstream::trunc; - std::ostream* replayLog = new std::ofstream(optarg.c_str(), out_trunc); - if(replayLog == NULL || !*replayLog) { - std::stringstream ss; - ss << "Cannot open replay-log file: `" << optarg << "': " - << smt::SmtOptionsHandler::__cvc4_errno_failreason(); - throw OptionException(ss.str()); - } - return std::make_pair(true, replayLog); - } -#else /* CVC4_REPLAY */ - throw OptionException("The replay feature was disabled in this build of CVC4."); -#endif /* CVC4_REPLAY */ -} - - -} /* namespace CVC4 */ diff --git a/src/smt/smt_globals.h b/src/smt/smt_globals.h deleted file mode 100644 index 00b90a703..000000000 --- a/src/smt/smt_globals.h +++ /dev/null @@ -1,106 +0,0 @@ -/********************* */ -/*! \file smt_globals.h - ** \verbatim - ** Original author: Tim King - ** Major contributors: none - ** Minor contributors (to current version): none - ** This file is part of the CVC4 project. - ** Copyright (c) 2009-2015 New York University and The University of Iowa - ** See the file COPYING in the top-level source directory for licensing - ** information.\endverbatim - ** - ** \brief SmtGlobals is a light container for psuedo-global datastructures - ** that are set by the user. - ** - ** SmtGlobals is a light container for psuedo-global datastructures - ** that are set by the user. These contain paramaters for infrequently - ** used modes: Portfolio and Replay. There should be exactly one of these - ** per SmtEngine with the same lifetime as the SmtEngine. - ** A user directly passes these as pointers and is resonsible for cleaning up - ** the memory. - ** - ** Basically, the problem this class is solving is that previously these were - ** using smt_options.h and the Options class as globals for these same - ** datastructures. - ** - ** This class is NOT a good long term solution, but is a reasonable stop gap. - **/ - -#include "cvc4_public.h" - -#ifndef __CVC4__SMT__SMT_GLOBALS_H -#define __CVC4__SMT__SMT_GLOBALS_H - -#include -#include -#include - -#include "expr/expr_stream.h" -#include "options/option_exception.h" -#include "smt_util/lemma_input_channel.h" -#include "smt_util/lemma_output_channel.h" - -namespace CVC4 { - -/** - * SmtGlobals is a wrapper around 4 pointers: - * - getReplayLog() - * - getReplayStream() - * - getLemmaInputChannel() - * - getLemmaOutputChannel() - * - * The user can directly set these and is responsible for handling the - * memory for these. These datastructures are used for the Replay and Portfolio - * modes. - */ -class CVC4_PUBLIC SmtGlobals { - public: - /** Creates an empty SmtGlobals with all 4 pointers initially NULL. */ - SmtGlobals(); - ~SmtGlobals(); - - /** This setsReplayLog based on --replay-log */ - void parseReplayLog(std::string optarg) throw (OptionException); - void setReplayLog(std::ostream*); - std::ostream* getReplayLog() { return d_replayLog; } - - void setReplayStream(ExprStream* stream); - ExprStream* getReplayStream() { return d_replayStream; } - - void setLemmaInputChannel(LemmaInputChannel* in); - LemmaInputChannel* getLemmaInputChannel() { return d_lemmaInputChannel; } - - void setLemmaOutputChannel(LemmaOutputChannel* out); - LemmaOutputChannel* getLemmaOutputChannel() { return d_lemmaOutputChannel; } - - private: - // Disable copy constructor. - SmtGlobals(const SmtGlobals&) CVC4_UNDEFINED; - - // Disable assignment operator. - SmtGlobals& operator=(const SmtGlobals&) CVC4_UNDEFINED; - - static std::pair - checkReplayLogFilename(std::string optarg) throw (OptionException); - - /** - * d_gcReplayLog is true iff d_replayLog was allocated by parseReplayLog. - */ - bool d_gcReplayLog; - - /** This captures the old options::replayLog .*/ - std::ostream* d_replayLog; - - /** This captures the old options::replayStream .*/ - ExprStream* d_replayStream; - - /** This captures the old options::lemmaInputChannel .*/ - LemmaInputChannel* d_lemmaInputChannel; - - /** This captures the old options::lemmaOutputChannel .*/ - LemmaOutputChannel* d_lemmaOutputChannel; -}; /* class SmtGlobals */ - -} /* namespace CVC4 */ - -#endif /* __CVC4__SMT__SMT_GLOBALS_H */ diff --git a/src/smt/smt_options_handler.h b/src/smt/smt_options_handler.h deleted file mode 100644 index f8e2ac155..000000000 --- a/src/smt/smt_options_handler.h +++ /dev/null @@ -1,198 +0,0 @@ -/********************* */ -/*! \file options_handler_interface.h - ** \verbatim - ** Original author: Tim King - ** Major contributors: none - ** Minor contributors (to current version): none - ** This file is part of the CVC4 project. - ** Copyright (c) 2009-2014 New York University and The University of Iowa - ** See the file COPYING in the top-level source directory for licensing - ** information.\endverbatim - ** - ** \brief Interface for custom handlers and predicates options. - ** - ** Interface for custom handlers and predicates options. - **/ - -#include "cvc4_private.h" - -#ifndef __CVC4__SMT__SMT_OPTIONS_HANDLER_H -#define __CVC4__SMT__SMT_OPTIONS_HANDLER_H - -#include -#include - -#include "base/modal_exception.h" -#include "options/arith_heuristic_pivot_rule.h" -#include "options/arith_propagation_mode.h" -#include "options/arith_unate_lemma_mode.h" -#include "options/boolean_term_conversion_mode.h" -#include "options/bv_bitblast_mode.h" -#include "options/decision_mode.h" -#include "options/language.h" -#include "options/option_exception.h" -#include "options/options_handler_interface.h" -#include "options/printer_modes.h" -#include "options/quantifiers_modes.h" -#include "options/simplification_mode.h" -#include "options/theoryof_mode.h" -#include "options/ufss_mode.h" -#include "smt/smt_engine.h" -#include "theory/logic_info.h" - -namespace CVC4 { -namespace smt { - -class CVC4_PUBLIC SmtOptionsHandler : public options::OptionsHandler { -public: - SmtOptionsHandler(SmtEngine* smt); - ~SmtOptionsHandler(); - - // TODO - // theory/arith/options_handlers.h - // theory/quantifiers/options_handlers.h - // theory/bv/options_handlers.h - // theory/booleans/options_handlers.h - // theory/uf/options_handlers.h - // theory/options_handlers.h - // printer/options_handlers.h - // decision/options_handlers.h - // smt/options_handlers.h - // expr/options_handlers.h - // main/options_handlers.h - // options/base_options_handlers.h - - // theory/arith/options_handlers.h - virtual ArithUnateLemmaMode stringToArithUnateLemmaMode(std::string option, std::string optarg) throw(OptionException); - virtual ArithPropagationMode stringToArithPropagationMode(std::string option, std::string optarg) throw(OptionException); - virtual ErrorSelectionRule stringToErrorSelectionRule(std::string option, std::string optarg) throw(OptionException); - - // theory/quantifiers/options_handlers.h - virtual theory::quantifiers::InstWhenMode stringToInstWhenMode(std::string option, std::string optarg) throw(OptionException); - virtual void checkInstWhenMode(std::string option, theory::quantifiers::InstWhenMode mode) throw(OptionException); - virtual theory::quantifiers::LiteralMatchMode stringToLiteralMatchMode(std::string option, std::string optarg) throw(OptionException); - virtual void checkLiteralMatchMode(std::string option, theory::quantifiers::LiteralMatchMode mode) throw(OptionException); - virtual theory::quantifiers::MbqiMode stringToMbqiMode(std::string option, std::string optarg) throw(OptionException); - virtual void checkMbqiMode(std::string option, theory::quantifiers::MbqiMode mode) throw(OptionException); - virtual theory::quantifiers::QcfWhenMode stringToQcfWhenMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::QcfMode stringToQcfMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::UserPatMode stringToUserPatMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::TriggerSelMode stringToTriggerSelMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::PrenexQuantMode stringToPrenexQuantMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::CegqiFairMode stringToCegqiFairMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::TermDbMode stringToTermDbMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::IteLiftQuantMode stringToIteLiftQuantMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::SygusInvTemplMode stringToSygusInvTemplMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::quantifiers::MacrosQuantMode stringToMacrosQuantMode(std::string option, std::string optarg) throw(OptionException); - - // theory/bv/options_handlers.h - virtual void abcEnabledBuild(std::string option, bool value) throw(OptionException); - virtual void abcEnabledBuild(std::string option, std::string value) throw(OptionException); - virtual theory::bv::BitblastMode stringToBitblastMode(std::string option, std::string optarg) throw(OptionException); - virtual theory::bv::BvSlicerMode stringToBvSlicerMode(std::string option, std::string optarg) throw(OptionException); - virtual void setBitblastAig(std::string option, bool arg) throw(OptionException); - - - // theory/booleans/options_handlers.h - virtual theory::booleans::BooleanTermConversionMode stringToBooleanTermConversionMode(std::string option, std::string optarg) throw(OptionException); - - // theory/uf/options_handlers.h - virtual theory::uf::UfssMode stringToUfssMode(std::string option, std::string optarg) throw(OptionException); - - // theory/options_handlers.h - virtual theory::TheoryOfMode stringToTheoryOfMode(std::string option, std::string optarg); - virtual void useTheory(std::string option, std::string optarg); - - - // printer/options_handlers.h - virtual ModelFormatMode stringToModelFormatMode(std::string option, std::string optarg) throw(OptionException); - virtual InstFormatMode stringToInstFormatMode(std::string option, std::string optarg) throw(OptionException); - - // decision/options_handlers.h - virtual decision::DecisionMode stringToDecisionMode(std::string option, std::string optarg) throw(OptionException); - virtual decision::DecisionWeightInternal stringToDecisionWeightInternal(std::string option, std::string optarg) throw(OptionException); - - - // smt/options_handlers.h - virtual void dumpMode(std::string option, std::string optarg); - virtual LogicInfo* stringToLogicInfo(std::string option, std::string optarg) throw(OptionException); - virtual SimplificationMode stringToSimplificationMode(std::string option, std::string optarg) throw(OptionException); - virtual void beforeSearch(std::string option, bool value) throw(ModalException); - virtual void setProduceAssertions(std::string option, bool value) throw(); - virtual void proofEnabledBuild(std::string option, bool value) throw(OptionException); - virtual void dumpToFile(std::string option, std::string optarg); - virtual void setRegularOutputChannel(std::string option, std::string optarg); - virtual void setDiagnosticOutputChannel(std::string option, std::string optarg); - virtual std::string checkReplayFilename(std::string option, std::string optarg); - virtual void statsEnabledBuild(std::string option, bool value) throw(OptionException); - virtual unsigned long tlimitHandler(std::string option, std::string optarg) throw(OptionException); - virtual unsigned long tlimitPerHandler(std::string option, std::string optarg) throw(OptionException); - virtual unsigned long rlimitHandler(std::string option, std::string optarg) throw(OptionException); - virtual unsigned long rlimitPerHandler(std::string option, std::string optarg) throw(OptionException); - - /* expr/options_handlers.h */ - virtual void setDefaultExprDepth(std::string option, int depth); - virtual void setDefaultDagThresh(std::string option, int dag); - virtual void setPrintExprTypes(std::string option); - - /* main/options_handlers.h */ - virtual void showConfiguration(std::string option); - virtual void showDebugTags(std::string option); - virtual void showTraceTags(std::string option); - virtual void threadN(std::string option); - - /* options/base_options_handlers.h */ - virtual void setVerbosity(std::string option, int value) throw(OptionException); - virtual void increaseVerbosity(std::string option); - virtual void decreaseVerbosity(std::string option); - virtual OutputLanguage stringToOutputLanguage(std::string option, std::string optarg) throw(OptionException); - virtual InputLanguage stringToInputLanguage(std::string option, std::string optarg) throw(OptionException) ; - virtual void addTraceTag(std::string option, std::string optarg); - virtual void addDebugTag(std::string option, std::string optarg); - virtual void setPrintSuccess(std::string option, bool value); - - static std::string __cvc4_errno_failreason(); - -private: - SmtEngine* d_smtEngine; - - /* Helper utilities */ - static std::string suggestTags(char const* const* validTags, std::string inputTag, - char const* const* additionalTags = NULL); - - /* Help strings */ - static const std::string s_bitblastingModeHelp; - static const std::string s_booleanTermConversionModeHelp; - static const std::string s_bvSlicerModeHelp; - static const std::string s_cegqiFairModeHelp; - static const std::string s_decisionModeHelp; - static const std::string s_dumpHelp; - static const std::string s_instFormatHelp ; - static const std::string s_instWhenHelp; - static const std::string s_iteLiftQuantHelp; - static const std::string s_literalMatchHelp; - static const std::string s_macrosQuantHelp; - static const std::string s_mbqiModeHelp; - static const std::string s_modelFormatHelp; - static const std::string s_prenexQuantModeHelp; - static const std::string s_qcfModeHelp; - static const std::string s_qcfWhenModeHelp; - static const std::string s_simplificationHelp; - static const std::string s_sygusInvTemplHelp; - static const std::string s_termDbModeHelp; - static const std::string s_theoryOfModeHelp; - static const std::string s_triggerSelModeHelp; - static const std::string s_ufssModeHelp; - static const std::string s_userPatModeHelp; - static const std::string s_errorSelectionRulesHelp; - static const std::string s_arithPropagationModeHelp; - static const std::string s_arithUnateLemmasHelp; - - -}; /* class SmtOptionsHandler */ - - -}/* CVC4::smt namespace */ -}/* CVC4 namespace */ - -#endif /* __CVC4__SMT__SMT_OPTIONS_HANDLER_H */ diff --git a/src/smt/update_ostream.h b/src/smt/update_ostream.h new file mode 100644 index 000000000..9e0100786 --- /dev/null +++ b/src/smt/update_ostream.h @@ -0,0 +1,122 @@ +/********************* */ +/*! \file update_ostream.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2016 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief [[ Add one-line brief description here ]] + ** + ** [[ Add lengthier description here ]] + ** \todo document this file + **/ + +#include "cvc4_private.h" + +#ifndef __CVC4__UPDATE_OSTREAM_H +#define __CVC4__UPDATE_OSTREAM_H + +#include + +#include "base/cvc4_assert.h" +#include "base/output.h" +#include "expr/expr_iomanip.h" +#include "options/language.h" +#include "options/set_language.h" +#include "options/base_options.h" +#include "smt_util/dump.h" + +namespace CVC4 { + +class ChannelSettings { + public: + ChannelSettings(std::ostream& out) + : d_dagSetting(expr::ExprDag::getDag(out)), + d_exprDepthSetting(expr::ExprSetDepth::getDepth(out)), + d_printtypesSetting(expr::ExprPrintTypes::getPrintTypes(out)), + d_languageSetting(language::SetLanguage::getLanguage(out)) + {} + + void apply(std::ostream& out) { + out << expr::ExprDag(d_dagSetting); + out << expr::ExprSetDepth(d_exprDepthSetting); + out << expr::ExprPrintTypes(d_printtypesSetting); + out << language::SetLanguage(d_languageSetting); + } + + private: + const int d_dagSetting; + const size_t d_exprDepthSetting; + const bool d_printtypesSetting; + const OutputLanguage d_languageSetting; +}; /* class ChannelSettings */ + +class OstreamUpdate { +public: + virtual std::ostream& get() = 0; + virtual void set(std::ostream* setTo) = 0; + + void apply(std::ostream* setTo) { + PrettyCheckArgument(setTo != NULL, setTo); + + ChannelSettings initialSettings(get()); + set(setTo); + initialSettings.apply(get()); + } +}; /* class OstreamUpdate */ + +class OptionsErrOstreamUpdate : public OstreamUpdate { + public: + virtual std::ostream& get() { return *(options::err()); } + virtual void set(std::ostream* setTo) { return options::err.set(setTo); } +}; /* class OptionsErrOstreamUpdate */ + +class DumpOstreamUpdate : public OstreamUpdate { + public: + virtual std::ostream& get() { return Dump.getStream(); } + virtual void set(std::ostream* setTo) { Dump.setStream(setTo); } +}; /* class DumpOstreamUpdate */ + +class DebugOstreamUpdate : public OstreamUpdate { + public: + virtual std::ostream& get() { return Debug.getStream(); } + virtual void set(std::ostream* setTo) { Debug.setStream(setTo); } +}; /* class DebugOstreamUpdate */ + +class WarningOstreamUpdate : public OstreamUpdate { + public: + virtual std::ostream& get() { return Warning.getStream(); } + virtual void set(std::ostream* setTo) { Warning.setStream(setTo); } +}; /* class WarningOstreamUpdate */ + +class MessageOstreamUpdate : public OstreamUpdate { + public: + virtual std::ostream& get() { return Message.getStream(); } + virtual void set(std::ostream* setTo) { Message.setStream(setTo); } +}; /* class MessageOstreamUpdate */ + +class NoticeOstreamUpdate : public OstreamUpdate { + public: + virtual std::ostream& get() { return Notice.getStream(); } + virtual void set(std::ostream* setTo) { Notice.setStream(setTo); } +}; /* class NoticeOstreamUpdate */ + +class ChatOstreamUpdate : public OstreamUpdate { + public: + virtual std::ostream& get() { return Chat.getStream(); } + virtual void set(std::ostream* setTo) { Chat.setStream(setTo); } +}; /* class ChatOstreamUpdate */ + +class TraceOstreamUpdate : public OstreamUpdate { + public: + virtual std::ostream& get() { return Trace.getStream(); } + virtual void set(std::ostream* setTo) { Trace.setStream(setTo); } +}; /* class TraceOstreamUpdate */ + +}/* CVC4 namespace */ + +#endif /* __CVC4__UPDATE_OSTREAM_H */ diff --git a/src/smt_util/Makefile.am b/src/smt_util/Makefile.am index 3b457f641..ae1ea1f70 100644 --- a/src/smt_util/Makefile.am +++ b/src/smt_util/Makefile.am @@ -12,12 +12,14 @@ libsmtutil_la_SOURCES = \ boolean_simplification.h \ command.cpp \ command.h \ - dump.h \ dump.cpp \ - lemma_input_channel.h \ - lemma_output_channel.h \ + dump.h \ ite_removal.cpp \ ite_removal.h \ + lemma_channels.cpp \ + lemma_channels.h \ + lemma_input_channel.h \ + lemma_output_channel.h \ model.cpp \ model.h \ nary_builder.cpp \ diff --git a/src/smt_util/boolean_simplification.h b/src/smt_util/boolean_simplification.h index 2732eaea7..27fdc3d28 100644 --- a/src/smt_util/boolean_simplification.h +++ b/src/smt_util/boolean_simplification.h @@ -35,8 +35,8 @@ namespace CVC4 { */ class BooleanSimplification { // cannot construct one of these - BooleanSimplification() CVC4_UNUSED; - BooleanSimplification(const BooleanSimplification&) CVC4_UNUSED; + BooleanSimplification() CVC4_UNDEFINED; + BooleanSimplification(const BooleanSimplification&) CVC4_UNDEFINED; static bool push_back_associative_commute_recursive (Node n, std::vector& buffer, Kind k, Kind notK, bool negateNode) diff --git a/src/smt_util/dump.cpp b/src/smt_util/dump.cpp index 56313f4d8..218691bd0 100644 --- a/src/smt_util/dump.cpp +++ b/src/smt_util/dump.cpp @@ -21,4 +21,201 @@ namespace CVC4 { DumpC DumpChannel CVC4_PUBLIC; +std::ostream& DumpC::setStream(std::ostream* os) { + DumpOut.setStream(os); + return *os; +} +std::ostream& DumpC::getStream() { return DumpOut.getStream(); } +std::ostream* DumpC::getStreamPointer() { return DumpOut.getStreamPointer(); } + + +void DumpC::setDumpFromString(const std::string& optarg) { +#ifdef CVC4_DUMPING + char* optargPtr = strdup(optarg.c_str()); + char* tokstr = optargPtr; + char* toksave; + while((optargPtr = strtok_r(tokstr, ",", &toksave)) != NULL) { + tokstr = NULL; + if(!strcmp(optargPtr, "benchmark")) { + } else if(!strcmp(optargPtr, "declarations")) { + } else if(!strcmp(optargPtr, "assertions")) { + Dump.on("assertions:post-everything"); + } else if(!strncmp(optargPtr, "assertions:", 11)) { + const char* p = optargPtr + 11; + if(!strncmp(p, "pre-", 4)) { + p += 4; + } else if(!strncmp(p, "post-", 5)) { + p += 5; + } else { + throw OptionException(std::string("don't know how to dump `") + + optargPtr + "'. Please consult --dump help."); + } + if(!strcmp(p, "everything")) { + } else if(!strcmp(p, "definition-expansion")) { + } else if(!strcmp(p, "boolean-terms")) { + } else if(!strcmp(p, "constrain-subtypes")) { + } else if(!strcmp(p, "substitution")) { + } else if(!strcmp(p, "strings-pp")) { + } else if(!strcmp(p, "skolem-quant")) { + } else if(!strcmp(p, "simplify")) { + } else if(!strcmp(p, "static-learning")) { + } else if(!strcmp(p, "ite-removal")) { + } else if(!strcmp(p, "repeat-simplify")) { + } else if(!strcmp(p, "rewrite-apply-to-const")) { + } else if(!strcmp(p, "theory-preprocessing")) { + } else if(!strcmp(p, "nonclausal")) { + } else if(!strcmp(p, "theorypp")) { + } else if(!strcmp(p, "itesimp")) { + } else if(!strcmp(p, "unconstrained")) { + } else if(!strcmp(p, "repeatsimp")) { + } else { + throw OptionException(std::string("don't know how to dump `") + + optargPtr + "'. Please consult --dump help."); + } + Dump.on("assertions"); + } else if(!strcmp(optargPtr, "skolems")) { + } else if(!strcmp(optargPtr, "clauses")) { + } else if(!strcmp(optargPtr, "t-conflicts") || + !strcmp(optargPtr, "t-lemmas") || + !strcmp(optargPtr, "t-explanations") || + !strcmp(optargPtr, "bv-rewrites") || + !strcmp(optargPtr, "theory::fullcheck")) { + // These are "non-state-dumping" modes. If state (SAT decisions, + // propagations, etc.) is dumped, it will interfere with the validity + // of these generated queries. + if(Dump.isOn("state")) { + throw OptionException(std::string("dump option `") + optargPtr + + "' conflicts with a previous, " + "state-dumping dump option. You cannot " + "mix stateful and non-stateful dumping modes; " + "see --dump help."); + } else { + Dump.on("no-permit-state"); + } + } else if(!strcmp(optargPtr, "state") || + !strcmp(optargPtr, "missed-t-conflicts") || + !strcmp(optargPtr, "t-propagations") || + !strcmp(optargPtr, "missed-t-propagations")) { + // These are "state-dumping" modes. If state (SAT decisions, + // propagations, etc.) is not dumped, it will interfere with the + // validity of these generated queries. + if(Dump.isOn("no-permit-state")) { + throw OptionException(std::string("dump option `") + optargPtr + + "' conflicts with a previous, " + "non-state-dumping dump option. You cannot " + "mix stateful and non-stateful dumping modes; " + "see --dump help."); + } else { + Dump.on("state"); + } + } else if(!strcmp(optargPtr, "help")) { + puts(s_dumpHelp.c_str()); + exit(1); + } else if(!strcmp(optargPtr, "bv-abstraction")) { + Dump.on("bv-abstraction"); + } else if(!strcmp(optargPtr, "bv-algebraic")) { + Dump.on("bv-algebraic"); + } else { + throw OptionException(std::string("unknown option for --dump: `") + + optargPtr + "'. Try --dump help."); + } + + Dump.on(optargPtr); + Dump.on("benchmark"); + if(strcmp(optargPtr, "benchmark")) { + Dump.on("declarations"); + if(strcmp(optargPtr, "declarations")) { + Dump.on("skolems"); + } + } + } + free(optargPtr); +#else /* CVC4_DUMPING */ + throw OptionException("The dumping feature was disabled in this build of CVC4."); +#endif /* CVC4_DUMPING */ +} + + +const std::string DumpC::s_dumpHelp = "\ +Dump modes currently supported by the --dump option:\n\ +\n\ +benchmark\n\ ++ Dump the benchmark structure (set-logic, push/pop, queries, etc.), but\n\ + does not include any declarations or assertions. Implied by all following\n\ + modes.\n\ +\n\ +declarations\n\ ++ Dump user declarations. Implied by all following modes.\n\ +\n\ +skolems\n\ ++ Dump internally-created skolem variable declarations. These can\n\ + arise from preprocessing simplifications, existential elimination,\n\ + and a number of other things. Implied by all following modes.\n\ +\n\ +assertions\n\ ++ Output the assertions after preprocessing and before clausification.\n\ + Can also specify \"assertions:pre-PASS\" or \"assertions:post-PASS\",\n\ + where PASS is one of the preprocessing passes: definition-expansion\n\ + boolean-terms constrain-subtypes substitution strings-pp skolem-quant\n\ + simplify static-learning ite-removal repeat-simplify\n\ + rewrite-apply-to-const theory-preprocessing.\n\ + PASS can also be the special value \"everything\", in which case the\n\ + assertions are printed before any preprocessing (with\n\ + \"assertions:pre-everything\") or after all preprocessing completes\n\ + (with \"assertions:post-everything\").\n\ +\n\ +clauses\n\ ++ Do all the preprocessing outlined above, and dump the CNF-converted\n\ + output\n\ +\n\ +state\n\ ++ Dump all contextual assertions (e.g., SAT decisions, propagations..).\n\ + Implied by all \"stateful\" modes below and conflicts with all\n\ + non-stateful modes below.\n\ +\n\ +t-conflicts [non-stateful]\n\ ++ Output correctness queries for all theory conflicts\n\ +\n\ +missed-t-conflicts [stateful]\n\ ++ Output completeness queries for theory conflicts\n\ +\n\ +t-propagations [stateful]\n\ ++ Output correctness queries for all theory propagations\n\ +\n\ +missed-t-propagations [stateful]\n\ ++ Output completeness queries for theory propagations (LARGE and EXPENSIVE)\n\ +\n\ +t-lemmas [non-stateful]\n\ ++ Output correctness queries for all theory lemmas\n\ +\n\ +t-explanations [non-stateful]\n\ ++ Output correctness queries for all theory explanations\n\ +\n\ +bv-rewrites [non-stateful]\n\ ++ Output correctness queries for all bitvector rewrites\n\ +\n\ +bv-abstraction [non-stateful]\n\ ++ Output correctness queries for all bv abstraction \n\ +\n\ +bv-algebraic [non-stateful]\n\ ++ Output correctness queries for bv algebraic solver. \n\ +\n\ +theory::fullcheck [non-stateful]\n \ ++ Output completeness queries for all full-check effort-level theory checks\n\ +\n\ +Dump modes can be combined with multiple uses of --dump. Generally you want\n\ +one from the assertions category (either assertions or clauses), and\n\ +perhaps one or more stateful or non-stateful modes for checking correctness\n\ +and completeness of decision procedure implementations. Stateful modes dump\n\ +the contextual assertions made by the core solver (all decisions and\n\ +propagations as assertions; that affects the validity of the resulting\n\ +correctness and completeness queries, so of course stateful and non-stateful\n\ +modes cannot be mixed in the same run.\n\ +\n\ +The --output-language option controls the language used for dumping, and\n\ +this allows you to connect CVC4 to another solver implementation via a UNIX\n\ +pipe to perform on-line checking. The --dump-to option can be used to dump\n\ +to a file.\n\ +"; + }/* CVC4 namespace */ diff --git a/src/smt_util/dump.h b/src/smt_util/dump.h index 1f4efe640..19f9118e3 100644 --- a/src/smt_util/dump.h +++ b/src/smt_util/dump.h @@ -75,6 +75,8 @@ class CVC4_PUBLIC DumpC { std::set d_tags; CommandSequence d_commands; + static const std::string s_dumpHelp; + public: CVC4dumpstream operator()(const char* tag) { if(!d_tags.empty() && d_tags.find(std::string(tag)) != d_tags.end()) { @@ -83,6 +85,7 @@ public: return CVC4dumpstream(); } } + CVC4dumpstream operator()(std::string tag) { if(!d_tags.empty() && d_tags.find(tag) != d_tags.end()) { return CVC4dumpstream(getStream(), d_commands); @@ -103,8 +106,11 @@ public: bool isOn(const char* tag) { return d_tags.find(std::string(tag)) != d_tags.end(); } bool isOn(std::string tag) { return d_tags.find(tag) != d_tags.end(); } - std::ostream& setStream(std::ostream& os) { DumpOut.setStream(os); return os; } - std::ostream& getStream() { return DumpOut.getStream(); } + std::ostream& setStream(std::ostream* os); + std::ostream& getStream(); + std::ostream* getStreamPointer(); + + void setDumpFromString(const std::string& optarg); };/* class DumpC */ /** The dump singleton */ diff --git a/src/smt_util/lemma_channels.cpp b/src/smt_util/lemma_channels.cpp new file mode 100644 index 000000000..e75866c5e --- /dev/null +++ b/src/smt_util/lemma_channels.cpp @@ -0,0 +1,54 @@ +/********************* */ +/*! \file lemma_channels.cpp + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2015 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief This class is a light container for globals that used to live + ** in options. This is NOT a good long term solution, but is a reasonable + ** stop gap. + ** + ** This class is a light container for globals that used to live + ** in options. This is NOT a good long term solution, but is a reasonable + ** stop gap. + **/ + +#include "smt_util/lemma_channels.h" + +#include +#include +#include +#include + +#include "cvc4autoconfig.h" // Needed for CVC4_REPLAY +#include "expr/expr_stream.h" +#include "options/open_ostream.h" +#include "options/option_exception.h" +#include "options/parser_options.h" +#include "smt_util/lemma_input_channel.h" +#include "smt_util/lemma_output_channel.h" + +namespace CVC4 { + +LemmaChannels::LemmaChannels() + : d_lemmaInputChannel(NULL) + , d_lemmaOutputChannel(NULL) +{} + +LemmaChannels::~LemmaChannels(){} + +void LemmaChannels::setLemmaInputChannel(LemmaInputChannel* in) { + d_lemmaInputChannel = in; +} + +void LemmaChannels::setLemmaOutputChannel(LemmaOutputChannel* out) { + d_lemmaOutputChannel = out; +} + + +} /* namespace CVC4 */ diff --git a/src/smt_util/lemma_channels.h b/src/smt_util/lemma_channels.h new file mode 100644 index 000000000..6cd81795e --- /dev/null +++ b/src/smt_util/lemma_channels.h @@ -0,0 +1,77 @@ +/********************* */ +/*! \file lemma_channels.h + ** \verbatim + ** Original author: Tim King + ** Major contributors: none + ** Minor contributors (to current version): none + ** This file is part of the CVC4 project. + ** Copyright (c) 2009-2015 New York University and The University of Iowa + ** See the file COPYING in the top-level source directory for licensing + ** information.\endverbatim + ** + ** \brief LemmaChannels is a light container for a pair of input and output + ** lemma channels. + ** + ** LemmaChannels is a light container for a pair of input and output + ** lemma channels. These contain paramaters for the infrequently + ** used Portfolio mode. There should be exactly one of these per SmtEngine + ** with the same lifetime as the SmtEngine. The user directly passes these as + ** pointers and is resonsible for cleaning up the memory. + ** + ** Basically, the problem this class is solving is that previously these were + ** using smt_options.h and the Options class as globals for these same + ** datastructures. + **/ + +#include "cvc4_public.h" + +#ifndef __CVC4__SMT_UTIL__LEMMA_CHANNELS_H +#define __CVC4__SMT_UTIL__LEMMA_CHANNELS_H + +#include +#include +#include + +#include "options/option_exception.h" +#include "smt_util/lemma_input_channel.h" +#include "smt_util/lemma_output_channel.h" + +namespace CVC4 { + +/** + * LemmaChannels is a wrapper around two pointers: + * - getLemmaInputChannel() + * - getLemmaOutputChannel() + * + * The user can directly set these and is responsible for handling the + * memory for these. These datastructures are used for Portfolio mode. + */ +class CVC4_PUBLIC LemmaChannels { + public: + /** Creates an empty LemmaChannels with all 4 pointers initially NULL. */ + LemmaChannels(); + ~LemmaChannels(); + + void setLemmaInputChannel(LemmaInputChannel* in); + LemmaInputChannel* getLemmaInputChannel() { return d_lemmaInputChannel; } + + void setLemmaOutputChannel(LemmaOutputChannel* out); + LemmaOutputChannel* getLemmaOutputChannel() { return d_lemmaOutputChannel; } + + private: + // Disable copy constructor. + LemmaChannels(const LemmaChannels&) CVC4_UNDEFINED; + + // Disable assignment operator. + LemmaChannels& operator=(const LemmaChannels&) CVC4_UNDEFINED; + + /** This captures the old options::lemmaInputChannel .*/ + LemmaInputChannel* d_lemmaInputChannel; + + /** This captures the old options::lemmaOutputChannel .*/ + LemmaOutputChannel* d_lemmaOutputChannel; +}; /* class LemmaChannels */ + +} /* namespace CVC4 */ + +#endif /* __CVC4__SMT_UTIL__LEMMA_CHANNELS_H */ diff --git a/src/theory/arith/constraint.h b/src/theory/arith/constraint.h index 877546da8..2c8fa9bcd 100644 --- a/src/theory/arith/constraint.h +++ b/src/theory/arith/constraint.h @@ -75,25 +75,22 @@ #ifndef __CVC4__THEORY__ARITH__CONSTRAINT_H #define __CVC4__THEORY__ARITH__CONSTRAINT_H -#include "expr/node.h" -#include "proof/proof.h" +#include +#include +#include +#include -#include "context/context.h" +#include "base/configuration_private.h" #include "context/cdlist.h" #include "context/cdqueue.h" - +#include "context/context.h" +#include "expr/node.h" +#include "proof/proof.h" #include "theory/arith/arithvar.h" -#include "theory/arith/delta_rational.h" +#include "theory/arith/callbacks.h" #include "theory/arith/congruence_manager.h" #include "theory/arith/constraint_forward.h" -#include "theory/arith/callbacks.h" - -#include "util/configuration_private.h" - -#include -#include -#include -#include +#include "theory/arith/delta_rational.h" namespace CVC4 { namespace theory { @@ -107,7 +104,7 @@ namespace theory { namespace arith { /** - * Logs the types of different proofs. + * Logs the types of different proofs. * Current, proof types: * - NoAP : This constraint is not known to be true. * - AssumeAP : This is an input assertion. There is no proof. diff --git a/src/theory/arith/cut_log.h b/src/theory/arith/cut_log.h index 054ab01e7..82d45871f 100644 --- a/src/theory/arith/cut_log.h +++ b/src/theory/arith/cut_log.h @@ -234,7 +234,7 @@ std::ostream& operator<<(std::ostream& os, const NodeLog& nl); class ApproximateSimplex; class TreeLog { private: - ApproximateSimplex* d_generator CVC4_UNUSED; + ApproximateSimplex* d_generator; int next_exec_ord; typedef std::map ToNodeMap; diff --git a/src/theory/arith/theory_arith.cpp b/src/theory/arith/theory_arith.cpp index 843feed01..3c7a767c6 100644 --- a/src/theory/arith/theory_arith.cpp +++ b/src/theory/arith/theory_arith.cpp @@ -31,8 +31,8 @@ namespace arith { TheoryArith::TheoryArith(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals) - : Theory(THEORY_ARITH, c, u, out, valuation, logicInfo, globals) + const LogicInfo& logicInfo) + : Theory(THEORY_ARITH, c, u, out, valuation, logicInfo) , d_internal(new TheoryArithPrivate(*this, c, u, out, valuation, logicInfo)) , d_ppRewriteTimer("theory::arith::ppRewriteTimer") { diff --git a/src/theory/arith/theory_arith.h b/src/theory/arith/theory_arith.h index c54414109..b69d51966 100644 --- a/src/theory/arith/theory_arith.h +++ b/src/theory/arith/theory_arith.h @@ -47,8 +47,7 @@ private: public: TheoryArith(context::Context* c, context::UserContext* u, OutputChannel& out, - Valuation valuation, const LogicInfo& logicInfo, - SmtGlobals* globals); + Valuation valuation, const LogicInfo& logicInfo); virtual ~TheoryArith(); /** diff --git a/src/theory/arrays/theory_arrays.cpp b/src/theory/arrays/theory_arrays.cpp index cbcccd734..f9e036aa3 100644 --- a/src/theory/arrays/theory_arrays.cpp +++ b/src/theory/arrays/theory_arrays.cpp @@ -55,9 +55,8 @@ const bool d_solveWrite2 = false; TheoryArrays::TheoryArrays(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals, - std::string name) - : Theory(THEORY_ARRAY, c, u, out, valuation, logicInfo, globals, name), + const LogicInfo& logicInfo, std::string name) + : Theory(THEORY_ARRAY, c, u, out, valuation, logicInfo, name), d_numRow(name + "theory::arrays::number of Row lemmas", 0), d_numExt(name + "theory::arrays::number of Ext lemmas", 0), d_numProp(name + "theory::arrays::number of propagations", 0), diff --git a/src/theory/arrays/theory_arrays.h b/src/theory/arrays/theory_arrays.h index 88d83bfb9..eba6c000e 100644 --- a/src/theory/arrays/theory_arrays.h +++ b/src/theory/arrays/theory_arrays.h @@ -93,7 +93,7 @@ class TheoryArrays : public Theory { // MISC ///////////////////////////////////////////////////////////////////////////// - private: + private: /** True node for predicates = true */ Node d_true; @@ -124,11 +124,11 @@ class TheoryArrays : public Theory { /** conflicts in setModelVal */ IntStat d_numSetModelValConflicts; - public: + public: TheoryArrays(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo, - SmtGlobals* globals, std::string name = ""); + std::string instanceName = ""); ~TheoryArrays(); void setMasterEqualityEngine(eq::EqualityEngine* eq); @@ -139,7 +139,7 @@ class TheoryArrays : public Theory { // PREPROCESSING ///////////////////////////////////////////////////////////////////////////// - private: + private: // PPNotifyClass: dummy template class for d_ppEqualityEngine - notifications not used class PPNotifyClass { diff --git a/src/theory/booleans/theory_bool.h b/src/theory/booleans/theory_bool.h index 246f1e7e8..dc42fc281 100644 --- a/src/theory/booleans/theory_bool.h +++ b/src/theory/booleans/theory_bool.h @@ -29,9 +29,8 @@ namespace booleans { class TheoryBool : public Theory { public: TheoryBool(context::Context* c, context::UserContext* u, OutputChannel& out, - Valuation valuation, const LogicInfo& logicInfo, - SmtGlobals* globals) - : Theory(THEORY_BOOL, c, u, out, valuation, logicInfo, globals) + Valuation valuation, const LogicInfo& logicInfo) + : Theory(THEORY_BOOL, c, u, out, valuation, logicInfo) {} PPAssertStatus ppAssert(TNode in, SubstitutionMap& outSubstitutions); diff --git a/src/theory/builtin/theory_builtin.h b/src/theory/builtin/theory_builtin.h index 2fbc0e402..facc10c67 100644 --- a/src/theory/builtin/theory_builtin.h +++ b/src/theory/builtin/theory_builtin.h @@ -29,8 +29,8 @@ class TheoryBuiltin : public Theory { public: TheoryBuiltin(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals) - : Theory(THEORY_BUILTIN, c, u, out, valuation, logicInfo, globals) {} + const LogicInfo& logicInfo) + : Theory(THEORY_BUILTIN, c, u, out, valuation, logicInfo) {} std::string identify() const { return std::string("TheoryBuiltin"); } };/* class TheoryBuiltin */ diff --git a/src/theory/bv/bitblaster_template.h b/src/theory/bv/bitblaster_template.h index 66eea0997..9c6c4af9b 100644 --- a/src/theory/bv/bitblaster_template.h +++ b/src/theory/bv/bitblaster_template.h @@ -26,7 +26,6 @@ #include "context/cdhashmap.h" #include "expr/node.h" #include "prop/sat_solver.h" -#include "smt/smt_globals.h" #include "theory/theory_registrar.h" #include "theory/valuation.h" #include "util/resource_manager.h" diff --git a/src/theory/bv/eager_bitblaster.cpp b/src/theory/bv/eager_bitblaster.cpp index 2e4f06c38..dd561667c 100644 --- a/src/theory/bv/eager_bitblaster.cpp +++ b/src/theory/bv/eager_bitblaster.cpp @@ -43,16 +43,13 @@ EagerBitblaster::EagerBitblaster(TheoryBV* theory_bv) d_bitblastingRegistrar = new BitblastingRegistrar(this); d_nullContext = new context::Context(); - d_satSolver = prop::SatSolverFactory::createMinisat(d_nullContext, - smtStatisticsRegistry(), - "EagerBitblaster"); - d_cnfStream = new prop::TseitinCnfStream(d_satSolver, - d_bitblastingRegistrar, - d_nullContext, - d_bv->globals(), - options::proof(), - "EagerBitblaster"); - + d_satSolver = prop::SatSolverFactory::createMinisat( + d_nullContext, smtStatisticsRegistry(), "EagerBitblaster"); + + d_cnfStream = new prop::TseitinCnfStream( + d_satSolver, d_bitblastingRegistrar, d_nullContext, options::proof(), + "EagerBitblaster"); + MinisatEmptyNotify* notify = new MinisatEmptyNotify(); d_satSolver->setNotify(notify); d_bvp = NULL; diff --git a/src/theory/bv/lazy_bitblaster.cpp b/src/theory/bv/lazy_bitblaster.cpp index 9268e2152..ca21e98c4 100644 --- a/src/theory/bv/lazy_bitblaster.cpp +++ b/src/theory/bv/lazy_bitblaster.cpp @@ -56,13 +56,13 @@ TLazyBitblaster::TLazyBitblaster(context::Context* c, bv::TheoryBV* bv, d_cnfStream = new prop::TseitinCnfStream(d_satSolver, d_nullRegistrar, d_nullContext, - d_bv->globals(), options::proof(), "LazyBitblaster"); d_satSolverNotify = d_emptyNotify ? (prop::BVSatSolverInterface::Notify*) new MinisatEmptyNotify() : - (prop::BVSatSolverInterface::Notify*) new MinisatNotify(d_cnfStream, bv, this); + (prop::BVSatSolverInterface::Notify*) new MinisatNotify(d_cnfStream, bv, + this); d_satSolver->setNotify(d_satSolverNotify); } @@ -526,11 +526,12 @@ void TLazyBitblaster::clearSolver() { d_satSolver = prop::SatSolverFactory::createMinisat( d_ctx, smtStatisticsRegistry()); d_cnfStream = new prop::TseitinCnfStream(d_satSolver, d_nullRegistrar, - d_nullContext, d_bv->globals()); + d_nullContext); d_satSolverNotify = d_emptyNotify ? (prop::BVSatSolverInterface::Notify*) new MinisatEmptyNotify() : - (prop::BVSatSolverInterface::Notify*) new MinisatNotify(d_cnfStream, d_bv, this); + (prop::BVSatSolverInterface::Notify*) new MinisatNotify(d_cnfStream, d_bv, + this); d_satSolver->setNotify(d_satSolverNotify); } diff --git a/src/theory/bv/theory_bv.cpp b/src/theory/bv/theory_bv.cpp index 8f7e975cd..191f70638 100644 --- a/src/theory/bv/theory_bv.cpp +++ b/src/theory/bv/theory_bv.cpp @@ -44,8 +44,8 @@ namespace bv { TheoryBV::TheoryBV(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals) - : Theory(THEORY_BV, c, u, out, valuation, logicInfo, globals), + const LogicInfo& logicInfo) + : Theory(THEORY_BV, c, u, out, valuation, logicInfo), d_context(c), d_alreadyPropagatedSet(c), d_sharedTermsSet(c), diff --git a/src/theory/bv/theory_bv.h b/src/theory/bv/theory_bv.h index 27138abfc..1da15abf8 100644 --- a/src/theory/bv/theory_bv.h +++ b/src/theory/bv/theory_bv.h @@ -22,7 +22,6 @@ #include "context/cdhashset.h" #include "context/cdlist.h" #include "context/context.h" -#include "smt/smt_globals.h" #include "theory/bv/bv_subtheory.h" #include "theory/bv/theory_bv_utils.h" #include "theory/theory.h" @@ -56,7 +55,8 @@ class TheoryBV : public Theory { public: - TheoryBV(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo, SmtGlobals* globals); + TheoryBV(context::Context* c, context::UserContext* u, OutputChannel& out, + Valuation valuation, const LogicInfo& logicInfo); ~TheoryBV(); diff --git a/src/theory/datatypes/theory_datatypes.cpp b/src/theory/datatypes/theory_datatypes.cpp index d49974df2..e33b4d05c 100644 --- a/src/theory/datatypes/theory_datatypes.cpp +++ b/src/theory/datatypes/theory_datatypes.cpp @@ -40,10 +40,8 @@ namespace theory { namespace datatypes { TheoryDatatypes::TheoryDatatypes(Context* c, UserContext* u, OutputChannel& out, - Valuation valuation, - const LogicInfo& logicInfo, - SmtGlobals* globals) - : Theory(THEORY_DATATYPES, c, u, out, valuation, logicInfo, globals), + Valuation valuation, const LogicInfo& logicInfo) + : Theory(THEORY_DATATYPES, c, u, out, valuation, logicInfo), //d_cycle_check(c), d_hasSeenCycle(c, false), d_infer(c), diff --git a/src/theory/datatypes/theory_datatypes.h b/src/theory/datatypes/theory_datatypes.h index 212b9d7cf..82306b863 100644 --- a/src/theory/datatypes/theory_datatypes.h +++ b/src/theory/datatypes/theory_datatypes.h @@ -215,7 +215,7 @@ protected: public: TheoryDatatypes(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals); + const LogicInfo& logicInfo); ~TheoryDatatypes(); void setMasterEqualityEngine(eq::EqualityEngine* eq); diff --git a/src/theory/fp/theory_fp.cpp b/src/theory/fp/theory_fp.cpp index 9a8d77844..18bf993ad 100644 --- a/src/theory/fp/theory_fp.cpp +++ b/src/theory/fp/theory_fp.cpp @@ -7,44 +7,52 @@ namespace theory { namespace fp { namespace removeToFPGeneric { - + Node removeToFPGeneric (TNode node) { Assert(node.getKind() == kind::FLOATINGPOINT_TO_FP_GENERIC); - - FloatingPointToFPGeneric info = node.getOperator().getConst(); - + + FloatingPointToFPGeneric info = + node.getOperator().getConst(); + size_t children = node.getNumChildren(); - + Node op; - + if (children == 1) { - op = NodeManager::currentNM()->mkConst(FloatingPointToFPIEEEBitVector(info.t.exponent(), - info.t.significand())); + op = NodeManager::currentNM()->mkConst( + FloatingPointToFPIEEEBitVector(info.t.exponent(), + info.t.significand())); return NodeManager::currentNM()->mkNode(op, node[0]); - + } else { Assert(children == 2); Assert(node[0].getType().isRoundingMode()); - + TypeNode t = node[1].getType(); - + if (t.isFloatingPoint()) { - op = NodeManager::currentNM()->mkConst(FloatingPointToFPFloatingPoint(info.t.exponent(), - info.t.significand())); + op = NodeManager::currentNM()->mkConst( + FloatingPointToFPFloatingPoint(info.t.exponent(), + info.t.significand())); } else if (t.isReal()) { - op = NodeManager::currentNM()->mkConst(FloatingPointToFPReal(info.t.exponent(), - info.t.significand())); + op = NodeManager::currentNM()->mkConst( + FloatingPointToFPReal(info.t.exponent(), + info.t.significand())); } else if (t.isBitVector()) { - op = NodeManager::currentNM()->mkConst(FloatingPointToFPSignedBitVector(info.t.exponent(), - info.t.significand())); - + op = NodeManager::currentNM()->mkConst( + FloatingPointToFPSignedBitVector(info.t.exponent(), + info.t.significand())); + } else { - throw TypeCheckingExceptionPrivate(node, "cannot rewrite to_fp generic due to incorrect type of second argument"); + throw TypeCheckingExceptionPrivate( + node, + "cannot rewrite to_fp generic due to incorrect type of second " + "argument"); } - + return NodeManager::currentNM()->mkNode(op, node[0], node[1]); } - + Unreachable("to_fp generic not rewritten"); } } @@ -53,8 +61,8 @@ namespace removeToFPGeneric { /** Constructs a new instance of TheoryFp w.r.t. the provided contexts. */ TheoryFp::TheoryFp(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals) - : Theory(THEORY_FP, c, u, out, valuation, logicInfo, globals) + const LogicInfo& logicInfo) + : Theory(THEORY_FP, c, u, out, valuation, logicInfo) {}/* TheoryFp::TheoryFp() */ diff --git a/src/theory/fp/theory_fp.h b/src/theory/fp/theory_fp.h index fe3c377af..ac2c68ac4 100644 --- a/src/theory/fp/theory_fp.h +++ b/src/theory/fp/theory_fp.h @@ -17,8 +17,7 @@ public: context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, - SmtGlobals* globals); + const LogicInfo& logicInfo); Node expandDefinition(LogicRequest &, Node node); diff --git a/src/theory/idl/theory_idl.cpp b/src/theory/idl/theory_idl.cpp index 8cba51c8f..815f5e76a 100644 --- a/src/theory/idl/theory_idl.cpp +++ b/src/theory/idl/theory_idl.cpp @@ -32,8 +32,8 @@ namespace idl { TheoryIdl::TheoryIdl(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals) - : Theory(THEORY_ARITH, c, u, out, valuation, logicInfo, globals) + const LogicInfo& logicInfo) + : Theory(THEORY_ARITH, c, u, out, valuation, logicInfo) , d_model(c) , d_assertionsDB(c) {} diff --git a/src/theory/idl/theory_idl.h b/src/theory/idl/theory_idl.h index aa7267eb7..7c879e722 100644 --- a/src/theory/idl/theory_idl.h +++ b/src/theory/idl/theory_idl.h @@ -45,8 +45,7 @@ public: /** Theory constructor. */ TheoryIdl(context::Context* c, context::UserContext* u, OutputChannel& out, - Valuation valuation, const LogicInfo& logicInfo, - SmtGlobals* globals); + Valuation valuation, const LogicInfo& logicInfo); /** Pre-processing of input atoms */ Node ppRewrite(TNode atom); diff --git a/src/theory/logic_info.cpp b/src/theory/logic_info.cpp index 02eeefcaf..fb689609d 100644 --- a/src/theory/logic_info.cpp +++ b/src/theory/logic_info.cpp @@ -24,8 +24,6 @@ #include "base/cvc4_assert.h" #include "expr/kind.h" -#warning "TODO: Remove logic_info_forward.h" - using namespace std; using namespace CVC4::theory; diff --git a/src/theory/logic_info.h b/src/theory/logic_info.h index 54b735114..6d7297c63 100644 --- a/src/theory/logic_info.h +++ b/src/theory/logic_info.h @@ -24,7 +24,6 @@ #include #include #include "expr/kind.h" -#include "options/logic_info_forward.h" namespace CVC4 { diff --git a/src/theory/mktheorytraits b/src/theory/mktheorytraits index b6162ec38..9107eb72d 100755 --- a/src/theory/mktheorytraits +++ b/src/theory/mktheorytraits @@ -128,7 +128,7 @@ function alternate { " eval "alternate_for_$1=\"\${alternate_for_$1} - if(options::theoryAlternates()[\\\"$2\\\"]) { + if(engine->useTheoryAlternative(\\\"$2\\\")) { engine->addTheory< $3 >($1); return; }\"" diff --git a/src/theory/quantifiers/theory_quantifiers.cpp b/src/theory/quantifiers/theory_quantifiers.cpp index b808f4cd5..86fc057ea 100644 --- a/src/theory/quantifiers/theory_quantifiers.cpp +++ b/src/theory/quantifiers/theory_quantifiers.cpp @@ -34,8 +34,8 @@ using namespace CVC4::context; using namespace CVC4::theory; using namespace CVC4::theory::quantifiers; -TheoryQuantifiers::TheoryQuantifiers(Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo, SmtGlobals* globals) : - Theory(THEORY_QUANTIFIERS, c, u, out, valuation, logicInfo, globals), +TheoryQuantifiers::TheoryQuantifiers(Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo) : + Theory(THEORY_QUANTIFIERS, c, u, out, valuation, logicInfo), d_masterEqualityEngine(0) { d_numInstantiations = 0; diff --git a/src/theory/quantifiers/theory_quantifiers.h b/src/theory/quantifiers/theory_quantifiers.h index 63f3379b8..6335349b1 100644 --- a/src/theory/quantifiers/theory_quantifiers.h +++ b/src/theory/quantifiers/theory_quantifiers.h @@ -53,7 +53,7 @@ private: public: TheoryQuantifiers(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals); + const LogicInfo& logicInfo); ~TheoryQuantifiers(); void setMasterEqualityEngine(eq::EqualityEngine* eq); diff --git a/src/theory/sets/theory_sets.cpp b/src/theory/sets/theory_sets.cpp index 82ebb5bf8..1280ad58d 100644 --- a/src/theory/sets/theory_sets.cpp +++ b/src/theory/sets/theory_sets.cpp @@ -25,9 +25,8 @@ TheorySets::TheorySets(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, - SmtGlobals* globals) - : Theory(THEORY_SETS, c, u, out, valuation, logicInfo, globals), + const LogicInfo& logicInfo) + : Theory(THEORY_SETS, c, u, out, valuation, logicInfo), d_internal(new TheorySetsPrivate(*this, c, u)) {} diff --git a/src/theory/sets/theory_sets.h b/src/theory/sets/theory_sets.h index 7ff8abec6..bc39fcbbd 100644 --- a/src/theory/sets/theory_sets.h +++ b/src/theory/sets/theory_sets.h @@ -41,8 +41,7 @@ public: * contexts. */ TheorySets(context::Context* c, context::UserContext* u, OutputChannel& out, - Valuation valuation, const LogicInfo& logicInfo, - SmtGlobals* globals); + Valuation valuation, const LogicInfo& logicInfo); ~TheorySets(); diff --git a/src/theory/strings/theory_strings.cpp b/src/theory/strings/theory_strings.cpp index 07a170a08..c0a892926 100644 --- a/src/theory/strings/theory_strings.cpp +++ b/src/theory/strings/theory_strings.cpp @@ -58,8 +58,8 @@ Node TheoryStrings::TermIndex::add( Node n, unsigned index, TheoryStrings* t, No TheoryStrings::TheoryStrings(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals) - : Theory(THEORY_STRINGS, c, u, out, valuation, logicInfo, globals), + const LogicInfo& logicInfo) + : Theory(THEORY_STRINGS, c, u, out, valuation, logicInfo), RMAXINT(LONG_MAX), d_notify( *this ), d_equalityEngine(d_notify, c, "theory::strings::TheoryStrings", true), diff --git a/src/theory/strings/theory_strings.h b/src/theory/strings/theory_strings.h index ddb800ee1..fef2983fd 100644 --- a/src/theory/strings/theory_strings.h +++ b/src/theory/strings/theory_strings.h @@ -54,7 +54,7 @@ class TheoryStrings : public Theory { public: TheoryStrings(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals); + const LogicInfo& logicInfo); ~TheoryStrings(); void setMasterEqualityEngine(eq::EqualityEngine* eq); diff --git a/src/theory/theory.cpp b/src/theory/theory.cpp index 45c9b1936..ee5efc8db 100644 --- a/src/theory/theory.cpp +++ b/src/theory/theory.cpp @@ -17,6 +17,9 @@ #include "theory/theory.h" #include +#include +#include +#include #include "base/cvc4_assert.h" #include "smt/smt_statistics_registry.h" @@ -48,9 +51,11 @@ std::ostream& operator<<(std::ostream& os, Theory::Effort level){ return os; }/* ostream& operator<<(ostream&, Theory::Effort) */ -Theory::Theory(TheoryId id, context::Context* satContext, context::UserContext* userContext, - OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo, - SmtGlobals* globals, std::string name) throw() + +Theory::Theory(TheoryId id, context::Context* satContext, + context::UserContext* userContext, OutputChannel& out, + Valuation valuation, const LogicInfo& logicInfo, + std::string name) throw() : d_id(id) , d_instanceName(name) , d_satContext(satContext) @@ -67,7 +72,6 @@ Theory::Theory(TheoryId id, context::Context* satContext, context::UserContext* , d_out(&out) , d_valuation(valuation) , d_proofsEnabled(false) - , d_globals(globals) { smtStatisticsRegistry()->registerStat(&d_checkTime); smtStatisticsRegistry()->registerStat(&d_computeCareGraphTime); @@ -204,7 +208,8 @@ void Theory::debugPrintFacts() const{ std::hash_set Theory::currentlySharedTerms() const{ std::hash_set currentlyShared; - for(shared_terms_iterator i = shared_terms_begin(), i_end = shared_terms_end(); i != i_end; ++i){ + for (shared_terms_iterator i = shared_terms_begin(), + i_end = shared_terms_end(); i != i_end; ++i) { currentlyShared.insert (*i); } return currentlyShared; @@ -242,18 +247,21 @@ void Theory::computeRelevantTerms(set& termSet) const } -Theory::PPAssertStatus Theory::ppAssert(TNode in, SubstitutionMap& outSubstitutions) +Theory::PPAssertStatus Theory::ppAssert(TNode in, + SubstitutionMap& outSubstitutions) { if (in.getKind() == kind::EQUAL) { // (and (= x t) phi) can be replaced by phi[x/t] if // 1) x is a variable // 2) x is not in the term t // 3) x : T and t : S, then S <: T - if (in[0].isVar() && !in[1].hasSubterm(in[0]) && (in[1].getType()).isSubtypeOf(in[0].getType()) ){ + if (in[0].isVar() && !in[1].hasSubterm(in[0]) && + (in[1].getType()).isSubtypeOf(in[0].getType()) ){ outSubstitutions.addSubstitution(in[0], in[1]); return PP_ASSERT_STATUS_SOLVED; } - if (in[1].isVar() && !in[0].hasSubterm(in[1]) && (in[0].getType()).isSubtypeOf(in[1].getType())){ + if (in[1].isVar() && !in[0].hasSubterm(in[1]) && + (in[0].getType()).isSubtypeOf(in[1].getType())){ outSubstitutions.addSubstitution(in[1], in[0]); return PP_ASSERT_STATUS_SOLVED; } @@ -267,9 +275,10 @@ Theory::PPAssertStatus Theory::ppAssert(TNode in, SubstitutionMap& outSubstituti return PP_ASSERT_STATUS_UNSOLVED; } -std::pair Theory::entailmentCheck(TNode lit, - const EntailmentCheckParameters* params, - EntailmentCheckSideEffects* out){ +std::pair Theory::entailmentCheck( + TNode lit, + const EntailmentCheckParameters* params, + EntailmentCheckSideEffects* out) { return make_pair(false, Node::null()); } @@ -277,6 +286,12 @@ EntailmentCheckParameters::EntailmentCheckParameters(TheoryId tid) : d_tid(tid) { } +std::string Theory::getFullInstanceName() const { + std::stringstream ss; + ss << "theory<" << d_id << ">" << d_instanceName; + return ss.str(); +} + EntailmentCheckParameters::~EntailmentCheckParameters(){} TheoryId EntailmentCheckParameters::getTheoryId() const { diff --git a/src/theory/theory.h b/src/theory/theory.h index 2c3c66d8b..9849dd0b9 100644 --- a/src/theory/theory.h +++ b/src/theory/theory.h @@ -20,9 +20,8 @@ #define __CVC4__THEORY__THEORY_H #include -#include +#include #include -#include #include "context/cdlist.h" #include "context/cdo.h" @@ -33,7 +32,6 @@ #include "options/theory_options.h" #include "options/theoryof_mode.h" #include "smt/logic_request.h" -#include "smt/smt_globals.h" #include "smt_util/command.h" #include "smt_util/dump.h" #include "theory/logic_info.h" @@ -140,9 +138,9 @@ private: friend class ::CVC4::TheoryEngine; // Disallow default construction, copy, assignment. - Theory() CVC4_UNUSED; - Theory(const Theory&) CVC4_UNUSED; - Theory& operator=(const Theory&) CVC4_UNUSED; + Theory() CVC4_UNDEFINED; + Theory(const Theory&) CVC4_UNDEFINED; + Theory& operator=(const Theory&) CVC4_UNDEFINED; /** * An integer identifying the type of the theory @@ -153,7 +151,7 @@ private: * an unique string identifier for each instance of a Theory class. We need * this to ensure unique statistics names over multiple theory instances. */ std::string d_instanceName; - + /** * The SAT search context for the Theory. */ @@ -243,10 +241,14 @@ protected: /** * Construct a Theory. + * + * The pair is assumed to uniquely identify this Theory + * w.r.t. the SmtEngine. */ - Theory(TheoryId id, context::Context* satContext, context::UserContext* userContext, - OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo, - SmtGlobals* globals, std::string name = "") throw(); // taking : No default. + Theory(TheoryId id, context::Context* satContext, + context::UserContext* userContext, OutputChannel& out, + Valuation valuation, const LogicInfo& logicInfo, + std::string instance = "") throw(); // taking : No default. /** * This is called at shutdown time by the TheoryEngine, just before @@ -295,7 +297,11 @@ protected: void printFacts(std::ostream& os) const; void debugPrintFacts() const; - SmtGlobals* d_globals; + /** + * Whether proofs are enabled + * + */ + bool d_proofEnabled; public: @@ -415,13 +421,13 @@ public: return d_id; } - std::string getFullInstanceName() const { - std::stringstream ss; - ss << "theory<" << d_id << ">" << d_instanceName; - return ss.str(); - } + /** + * Returns a string that uniquely identifies this theory solver w.r.t. the + * SmtEngine. + */ + std::string getFullInstanceName() const; + - /** * Get the SAT context associated to this Theory. */ @@ -865,9 +871,6 @@ public: * Turn on proof-production mode. */ void produceProofs() { d_proofsEnabled = true; } - - /** Returns a pointer to the globals copy the theory is using. */ - SmtGlobals* globals() { return d_globals; } };/* class Theory */ diff --git a/src/theory/theory_engine.cpp b/src/theory/theory_engine.cpp index be2a89dbc..60716146e 100644 --- a/src/theory/theory_engine.cpp +++ b/src/theory/theory_engine.cpp @@ -104,7 +104,7 @@ TheoryEngine::TheoryEngine(context::Context* context, context::UserContext* userContext, RemoveITE& iteRemover, const LogicInfo& logicInfo, - SmtGlobals* globals) + LemmaChannels* channels) : d_propEngine(NULL), d_decisionEngine(NULL), d_context(context), @@ -133,16 +133,20 @@ TheoryEngine::TheoryEngine(context::Context* context, d_false(), d_interrupted(false), d_resourceManager(NodeManager::currentResourceManager()), - d_globals(globals), + d_channels(channels), d_inPreregister(false), d_factsAsserted(context, false), d_preRegistrationVisitor(this, context), d_sharedTermsVisitor(d_sharedTerms), d_unconstrainedSimp(new UnconstrainedSimplifier(context, logicInfo)), d_bvToBoolPreprocessor(), + d_theoryAlternatives(), + d_attr_handle(), d_arithSubstitutionsAdded("theory::arith::zzz::arith::substitutions", 0) { - for(TheoryId theoryId = theory::THEORY_FIRST; theoryId != theory::THEORY_LAST; ++ theoryId) { + for(TheoryId theoryId = theory::THEORY_FIRST; theoryId != theory::THEORY_LAST; + ++ theoryId) + { d_theoryTable[theoryId] = NULL; d_theoryOut[theoryId] = NULL; } @@ -155,7 +159,7 @@ TheoryEngine::TheoryEngine(context::Context* context, d_true = NodeManager::currentNM()->mkConst(true); d_false = NodeManager::currentNM()->mkConst(false); - PROOF (ProofManager::currentPM()->initTheoryProofEngine(d_globals); ); + PROOF (ProofManager::currentPM()->initTheoryProofEngine(); ); d_iteUtilities = new ITEUtilities(d_iteRemover.getContainsVisitor()); @@ -1398,8 +1402,8 @@ theory::LemmaStatus TheoryEngine::lemma(TNode node, } // Share with other portfolio threads - if(d_globals->getLemmaOutputChannel() != NULL) { - d_globals->getLemmaOutputChannel()->notifyNewLemma(node.toExpr()); + if(d_channels->getLemmaOutputChannel() != NULL) { + d_channels->getLemmaOutputChannel()->notifyNewLemma(node.toExpr()); } // Run theory preprocessing, maybe @@ -1769,6 +1773,18 @@ void TheoryEngine::spendResource(unsigned ammount) { d_resourceManager->spendResource(ammount); } +void TheoryEngine::enableTheoryAlternative(const std::string& name){ + Debug("TheoryEngine::enableTheoryAlternative") + << "TheoryEngine::enableTheoryAlternative(" << name << ")" << std::endl; + + d_theoryAlternatives.insert(name); +} + +bool TheoryEngine::useTheoryAlternative(const std::string& name) { + return d_theoryAlternatives.find(name) != d_theoryAlternatives.end(); +} + + TheoryEngine::Statistics::Statistics(theory::TheoryId theory): conflicts(mkName("theory<", theory, ">::conflicts"), 0), propagations(mkName("theory<", theory, ">::propagations"), 0), diff --git a/src/theory/theory_engine.h b/src/theory/theory_engine.h index 0bf00c079..cdd05c096 100644 --- a/src/theory/theory_engine.h +++ b/src/theory/theory_engine.h @@ -20,6 +20,7 @@ #define __CVC4__THEORY_ENGINE_H #include +#include #include #include @@ -29,8 +30,8 @@ #include "options/options.h" #include "options/smt_options.h" #include "prop/prop_engine.h" -#include "smt/smt_globals.h" #include "smt_util/command.h" +#include "smt_util/lemma_channels.h" #include "theory/atom_requests.h" #include "theory/bv/bv_to_bool.h" #include "theory/interrupted.h" @@ -467,14 +468,15 @@ class TheoryEngine { bool d_interrupted; ResourceManager* d_resourceManager; - /** Container for misc. globals. */ - SmtGlobals* d_globals; + /** Container for lemma input and output channels. */ + LemmaChannels* d_channels; public: /** Constructs a theory engine */ TheoryEngine(context::Context* context, context::UserContext* userContext, - RemoveITE& iteRemover, const LogicInfo& logic, SmtGlobals* globals); + RemoveITE& iteRemover, const LogicInfo& logic, + LemmaChannels* channels); /** Destroys a theory engine */ ~TheoryEngine(); @@ -495,7 +497,7 @@ public: d_theoryOut[theoryId] = new EngineOutputChannel(this, theoryId); d_theoryTable[theoryId] = new TheoryClass(d_context, d_userContext, *d_theoryOut[theoryId], - theory::Valuation(this), d_logicInfo, d_globals); + theory::Valuation(this), d_logicInfo); } inline void setPropEngine(prop::PropEngine* propEngine) { @@ -832,7 +834,15 @@ public: /** Prints the assertions to the debug stream */ void printAssertions(const char* tag); + /** Theory alternative is in use. */ + bool useTheoryAlternative(const std::string& name); + + /** Enables using a theory alternative by name. */ + void enableTheoryAlternative(const std::string& name); + private: + std::set< std::string > d_theoryAlternatives; + std::map< std::string, std::vector< theory::Theory* > > d_attr_handle; public: diff --git a/src/theory/uf/theory_uf.cpp b/src/theory/uf/theory_uf.cpp index 93a920f82..e58c11aca 100644 --- a/src/theory/uf/theory_uf.cpp +++ b/src/theory/uf/theory_uf.cpp @@ -36,18 +36,19 @@ namespace uf { /** Constructs a new instance of TheoryUF w.r.t. the provided context.*/ TheoryUF::TheoryUF(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, - const LogicInfo& logicInfo, SmtGlobals* globals, std::string name) - : Theory(THEORY_UF, c, u, out, valuation, logicInfo, globals, name), + const LogicInfo& logicInfo, std::string instanceName) + : Theory(THEORY_UF, c, u, out, valuation, logicInfo, instanceName), d_notify(*this), /* The strong theory solver can be notified by EqualityEngine::init(), * so make sure it's initialized first. */ d_thss(NULL), - d_equalityEngine(d_notify, c, name + "theory::uf::TheoryUF", true), + d_equalityEngine(d_notify, c, instanceName + "theory::uf::TheoryUF", + true), d_conflict(c, false), d_literalsToPropagate(c), d_literalsToPropagateIndex(c, 0), d_functionsTerms(c), - d_symb(u, name) + d_symb(u, instanceName) { // The kinds we are treating as function application in congruence d_equalityEngine.addFunctionKind(kind::APPLY_UF); diff --git a/src/theory/uf/theory_uf.h b/src/theory/uf/theory_uf.h index bd0016be7..e29b923f9 100644 --- a/src/theory/uf/theory_uf.h +++ b/src/theory/uf/theory_uf.h @@ -169,7 +169,7 @@ public: /** Constructs a new instance of TheoryUF w.r.t. the provided context.*/ TheoryUF(context::Context* c, context::UserContext* u, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo, - SmtGlobals* globals, std::string name = ""); + std::string instanceName = ""); ~TheoryUF(); diff --git a/src/util/Makefile.am b/src/util/Makefile.am index e95faea56..a8e37c93c 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -25,9 +25,6 @@ libutil_la_SOURCES = \ cardinality.cpp \ cardinality.h \ channel.h \ - configuration.cpp \ - configuration.h \ - configuration_private.h \ debug.h \ dense_map.h \ divisible.cpp \ @@ -81,7 +78,6 @@ EXTRA_DIST = \ bitvector.i \ bool.i \ cardinality.i \ - configuration.i \ divisible.i \ floatingpoint.i \ hash.i \ diff --git a/src/util/cache.h b/src/util/cache.h index 5183c439b..788c89d83 100644 --- a/src/util/cache.h +++ b/src/util/cache.h @@ -39,8 +39,8 @@ class Cache { typename Map::iterator d_result; // disallow copy/assignment - Cache(const Cache&) CVC4_UNUSED; - Cache& operator=(const Cache&) CVC4_UNUSED; + Cache(const Cache&) CVC4_UNDEFINED; + Cache& operator=(const Cache&) CVC4_UNDEFINED; public: diff --git a/src/util/resource_manager.cpp b/src/util/resource_manager.cpp index d426ab03e..8d6e5e6d4 100644 --- a/src/util/resource_manager.cpp +++ b/src/util/resource_manager.cpp @@ -17,6 +17,7 @@ #include "base/cvc4_assert.h" #include "base/output.h" +#include "options/smt_options.h" using namespace std; @@ -180,9 +181,10 @@ void ResourceManager::spendResource(unsigned ammount) throw (UnsafeInterruptExce d_thisCallResourceUsed += ammount; if(out()) { Trace("limit") << "ResourceManager::spendResource: interrupt!" << std::endl; - Trace("limit") << " on call " << d_spendResourceCalls << std::endl; + Trace("limit") << " on call " << d_spendResourceCalls << std::endl; if (outOfTime()) { - Trace("limit") << "ResourceManager::spendResource: elapsed time" << d_cumulativeTimer.elapsed() << std::endl; + Trace("limit") << "ResourceManager::spendResource: elapsed time" + << d_cumulativeTimer.elapsed() << std::endl; } if (d_isHardLimit) { @@ -281,12 +283,16 @@ void ResourceManager::enable(bool on) { d_on = on; } -ListenerCollection* ResourceManager::getHardListeners() { - return &d_hardListeners; +ListenerCollection::Registration* ResourceManager::registerHardListener( + Listener* listener) +{ + return d_hardListeners.registerListener(listener); } -ListenerCollection* ResourceManager::getSoftListeners() { - return &d_softListeners; +ListenerCollection::Registration* ResourceManager::registerSoftListener( + Listener* listener) +{ + return d_softListeners.registerListener(listener); } } /* namespace CVC4 */ diff --git a/src/util/resource_manager.h b/src/util/resource_manager.h index 2c54011a5..f3bb42a08 100644 --- a/src/util/resource_manager.h +++ b/src/util/resource_manager.h @@ -114,6 +114,18 @@ class CVC4_PUBLIC ResourceManager { /** Receives a notification on reaching a hard limit. */ ListenerCollection d_softListeners; + /** + * ResourceManagers cannot be copied as they are given an explicit + * list of Listeners to respond to. + */ + ResourceManager(const ResourceManager&) CVC4_UNDEFINED; + + /** + * ResourceManagers cannot be assigned as they are given an explicit + * list of Listeners to respond to. + */ + ResourceManager& operator=(const ResourceManager&) CVC4_UNDEFINED; + public: ResourceManager(); @@ -162,13 +174,25 @@ public: static uint64_t getFrequencyCount() { return s_resourceCount; } - /** Collection of listeners that are notified on a hard resource out. */ - ListenerCollection* getHardListeners(); + /** + * Registers a listener that is notified on a hard resource out. + * + * This Registration must be destroyed by the user before this + * ResourceManager. + */ + ListenerCollection::Registration* registerHardListener(Listener* listener); + + /** + * Registers a listener that is notified on a soft resource out. + * + * This Registration must be destroyed by the user before this + * ResourceManager. + */ + ListenerCollection::Registration* registerSoftListener(Listener* listener); - /** Collection of listeners that are notified on a soft resource out. */ - ListenerCollection* getSoftListeners(); };/* class ResourceManager */ + }/* CVC4 namespace */ #endif /* __CVC4__RESOURCE_MANAGER_H */ diff --git a/src/util/sexpr.cpp b/src/util/sexpr.cpp index eb53e34c2..9837a7045 100644 --- a/src/util/sexpr.cpp +++ b/src/util/sexpr.cpp @@ -149,12 +149,12 @@ SExpr::SExpr(const std::string& value) : d_children(NULL) { } - /** - * This constructs a string expression from a const char* value. - * This cannot be removed in order to support SExpr("foo"). - * Given the other constructors this SExpr("foo") converts to bool. - * instead of SExpr(string("foo")). - */ +/** + * This constructs a string expression from a const char* value. + * This cannot be removed in order to support SExpr("foo"). + * Given the other constructors this SExpr("foo") converts to bool. + * instead of SExpr(string("foo")). + */ SExpr::SExpr(const char* value) : d_sexprType(SEXPR_STRING), d_integerValue(0), @@ -163,7 +163,6 @@ SExpr::SExpr(const char* value) : d_children(NULL) { } -#warning "TODO: Discuss this change with Clark." SExpr::SExpr(bool value) : d_sexprType(SEXPR_KEYWORD), d_integerValue(0), diff --git a/test/system/smt2_compliance.cpp b/test/system/smt2_compliance.cpp index b202bcccc..bc976685e 100644 --- a/test/system/smt2_compliance.cpp +++ b/test/system/smt2_compliance.cpp @@ -19,9 +19,8 @@ #include #include "expr/expr_manager.h" -#include "options/base_options.h" +#include "options/options.h" #include "options/set_language.h" -#include "options/smt_options.h" #include "parser/parser.h" #include "parser/parser_builder.h" #include "smt/smt_engine.h" @@ -35,8 +34,8 @@ void testGetInfo(SmtEngine& smt, const char* s); int main() { Options opts; - opts.set(options::inputLanguage, language::input::LANG_SMTLIB_V2); - opts.set(options::outputLanguage, language::output::LANG_SMTLIB_V2); + opts.setInputLanguage(language::input::LANG_SMTLIB_V2); + opts.setOutputLanguage(language::output::LANG_SMTLIB_V2); cout << language::SetLanguage(language::output::LANG_SMTLIB_V2); @@ -59,7 +58,8 @@ int main() { } void testGetInfo(SmtEngine& smt, const char* s) { - ParserBuilder pb(smt.getExprManager(), "", smt.getExprManager()->getOptions()); + ParserBuilder pb(smt.getExprManager(), "", + smt.getExprManager()->getOptions()); Parser* p = pb.withStringInput(string("(get-info ") + s + ")").build(); assert(p != NULL); Command* c = p->nextCommand(); diff --git a/test/unit/expr/attribute_black.h b/test/unit/expr/attribute_black.h index d162171d6..bea04a139 100644 --- a/test/unit/expr/attribute_black.h +++ b/test/unit/expr/attribute_black.h @@ -145,9 +145,10 @@ public: } class Foo { - int blah CVC4_UNUSED; + int d_bar; public: - Foo(int b) : blah(b) {} + Foo(int b) : d_bar(b) {} + int getBar() const { return d_bar; } }; struct PtrAttributeId {}; @@ -175,6 +176,8 @@ public: TS_ASSERT(!node->getAttribute(cdattr, data2)); node->setAttribute(cdattr, val); TS_ASSERT(node->getAttribute(cdattr, data3)); + TS_ASSERT(data3 != NULL); + TS_ASSERT_EQUALS(63489, data3->getBar()); TS_ASSERT_EQUALS(data3, val); delete node; delete val; diff --git a/test/unit/expr/expr_public.h b/test/unit/expr/expr_public.h index a83e53780..194aec0b1 100644 --- a/test/unit/expr/expr_public.h +++ b/test/unit/expr/expr_public.h @@ -22,7 +22,7 @@ #include "base/exception.h" #include "expr/expr_manager.h" #include "expr/expr.h" -#include "smt/smt_options_handler.h" +#include "options/options.h" using namespace CVC4; using namespace CVC4::kind; @@ -32,7 +32,6 @@ class ExprPublic : public CxxTest::TestSuite { private: Options opts; - smt::SmtOptionsHandler* d_handler; ExprManager* d_em; @@ -55,12 +54,11 @@ public: void setUp() { try { - d_handler = new smt::SmtOptionsHandler(NULL); char *argv[2]; argv[0] = strdup(""); argv[1] = strdup("--output-language=ast"); - opts.parseOptions(2, argv, d_handler); + opts.parseOptions(2, argv); free(argv[0]); free(argv[1]); @@ -102,7 +100,6 @@ public: delete c_bool_and; delete b_bool; delete a_bool; - delete d_handler; delete d_em; } catch(Exception e) { diff --git a/test/unit/expr/node_black.h b/test/unit/expr/node_black.h index 3a24057b2..7d6ee523a 100644 --- a/test/unit/expr/node_black.h +++ b/test/unit/expr/node_black.h @@ -25,7 +25,6 @@ #include "expr/node_builder.h" #include "expr/node_manager.h" #include "expr/node.h" -#include "smt/smt_options_handler.h" using namespace CVC4; using namespace CVC4::kind; @@ -35,7 +34,6 @@ class NodeBlack : public CxxTest::TestSuite { private: Options opts; - smt::SmtOptionsHandler* d_handler; NodeManager* d_nodeManager; NodeManagerScope* d_scope; TypeNode* d_booleanType; @@ -44,13 +42,10 @@ private: public: void setUp() { -#warning "TODO: Discuss the effects of this change with Clark." - d_handler = new smt::SmtOptionsHandler(NULL); - char *argv[2]; argv[0] = strdup(""); argv[1] = strdup("--output-language=ast"); - opts.parseOptions(2, argv, d_handler); + opts.parseOptions(2, argv); free(argv[0]); free(argv[1]); @@ -64,7 +59,6 @@ public: delete d_booleanType; delete d_scope; delete d_nodeManager; - delete d_handler; } bool imp(bool a, bool b) const { diff --git a/test/unit/prop/cnf_stream_white.h b/test/unit/prop/cnf_stream_white.h index 0736ec052..f76a1e4d3 100644 --- a/test/unit/prop/cnf_stream_white.h +++ b/test/unit/prop/cnf_stream_white.h @@ -160,7 +160,7 @@ class CnfStreamWhite : public CxxTest::TestSuite { d_satSolver = new FakeSatSolver(); d_cnfStream = new CVC4::prop::TseitinCnfStream( d_satSolver, new theory::TheoryRegistrar(d_theoryEngine), - new context::Context(), d_smt->globals()); + new context::Context(), d_smt->channels()); } void tearDown() { diff --git a/test/unit/theory/theory_arith_white.h b/test/unit/theory/theory_arith_white.h index 4313a9b64..49231071b 100644 --- a/test/unit/theory/theory_arith_white.h +++ b/test/unit/theory/theory_arith_white.h @@ -115,7 +115,7 @@ public: d_smt->d_theoryEngine->d_theoryOut[THEORY_ARITH] = NULL; d_arith = new TheoryArith(d_ctxt, d_uctxt, d_outputChannel, Valuation(NULL), - d_logicInfo, d_smt->globals()); + d_logicInfo); preregistered = new std::set(); diff --git a/test/unit/theory/theory_engine_white.h b/test/unit/theory/theory_engine_white.h index 62ed96900..e72b2cf4d 100644 --- a/test/unit/theory/theory_engine_white.h +++ b/test/unit/theory/theory_engine_white.h @@ -123,8 +123,8 @@ class FakeTheory : public Theory { // static std::deque s_expected; public: - FakeTheory(context::Context* ctxt, context::UserContext* uctxt, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo, SmtGlobals* globals) : - Theory(theoryId, ctxt, uctxt, out, valuation, logicInfo, globals) + FakeTheory(context::Context* ctxt, context::UserContext* uctxt, OutputChannel& out, Valuation valuation, const LogicInfo& logicInfo) : + Theory(theoryId, ctxt, uctxt, out, valuation, logicInfo) { } /** Register an expected rewrite call */ diff --git a/test/unit/theory/theory_white.h b/test/unit/theory/theory_white.h index daa98855a..9a0cbeea4 100644 --- a/test/unit/theory/theory_white.h +++ b/test/unit/theory/theory_white.h @@ -126,8 +126,8 @@ public: vector d_getSequence; DummyTheory(Context* ctxt, UserContext* uctxt, OutputChannel& out, - Valuation valuation, const LogicInfo& logicInfo, SmtGlobals* globals) - : Theory(theory::THEORY_BUILTIN, ctxt, uctxt, out, valuation, logicInfo, globals) + Valuation valuation, const LogicInfo& logicInfo) + : Theory(theory::THEORY_BUILTIN, ctxt, uctxt, out, valuation, logicInfo) {} void registerTerm(TNode n) { @@ -204,7 +204,7 @@ public: d_smt->d_theoryEngine->d_theoryOut[THEORY_BUILTIN] = NULL; d_dummy = new DummyTheory(d_ctxt, d_uctxt, d_outputChannel, Valuation(NULL), - *d_logicInfo, d_smt->globals()); + *d_logicInfo); d_outputChannel.clear(); atom0 = d_nm->mkConst(true); atom1 = d_nm->mkConst(false); diff --git a/test/unit/util/configuration_black.h b/test/unit/util/configuration_black.h index 2d7378a67..f07763595 100644 --- a/test/unit/util/configuration_black.h +++ b/test/unit/util/configuration_black.h @@ -16,7 +16,7 @@ #include -#include "util/configuration.h" +#include "base/configuration.h" using namespace CVC4; using namespace std; diff --git a/test/unit/util/listener_black.h b/test/unit/util/listener_black.h index cd3a08d4e..682a7c67b 100644 --- a/test/unit/util/listener_black.h +++ b/test/unit/util/listener_black.h @@ -64,7 +64,7 @@ public: ListenerCollection collection; std::string expected[1] = {"a"}; { - RegisterListener a(&collection, new EventListener(d_events, "a")); + ListenerCollection::Registration a(&collection, new EventListener(d_events, "a")); collection.notify(); TS_ASSERT(not collection.empty()); } @@ -77,7 +77,7 @@ public: // registering a single event. ListenerCollection* collection = new ListenerCollection; { - RegisterListener a(collection, new EventListener(d_events, "a")); + ListenerCollection::Registration a(collection, new EventListener(d_events, "a")); TS_ASSERT(not collection->empty()); // The destructor for a now runs. } @@ -88,11 +88,11 @@ public: void testMultipleCollection() { ListenerCollection* collection = new ListenerCollection; { - RegisterListener c(collection, new EventListener(d_events, "c")); + ListenerCollection::Registration c(collection, new EventListener(d_events, "c")); collection->notify(); // d_events == {"c"} - RegisterListener b(collection, new EventListener(d_events, "b")); - RegisterListener a(collection, new EventListener(d_events, "a")); + ListenerCollection::Registration b(collection, new EventListener(d_events, "b")); + ListenerCollection::Registration a(collection, new EventListener(d_events, "a")); collection->notify(); // d_events == {"a", "b", "c", "c"} TS_ASSERT(not collection->empty()); @@ -107,10 +107,10 @@ public: // registering several events. ListenerCollection* collection = new ListenerCollection; { - RegisterListener a(collection, new EventListener(d_events, "a")); - RegisterListener* b = - new RegisterListener(collection, new EventListener(d_events, "b")); - RegisterListener c(collection, new EventListener(d_events, "c")); + ListenerCollection::Registration a(collection, new EventListener(d_events, "a")); + ListenerCollection::Registration* b = + new ListenerCollection::Registration(collection, new EventListener(d_events, "b")); + ListenerCollection::Registration c(collection, new EventListener(d_events, "c")); collection->notify(); delete b; @@ -128,17 +128,17 @@ public: // This tests adds and notify multiple times. ListenerCollection collection; - std::vector listeners; + std::vector listeners; for(int i = 0; i < 4 ; ++i){ stringstream ss; ss << i; Listener* listener = new EventListener(d_events, ss.str()); - listeners.push_back(new RegisterListener(&collection, listener)); + listeners.push_back(new ListenerCollection::Registration(&collection, listener)); collection.notify(); } TS_ASSERT(not collection.empty()); for(int i=0; i < listeners.size(); ++i){ - RegisterListener* at_i = listeners[i]; + ListenerCollection::Registration* at_i = listeners[i]; delete at_i; } listeners.clear(); diff --git a/test/unit/util/output_black.h b/test/unit/util/output_black.h index 87423f026..369f5b673 100644 --- a/test/unit/util/output_black.h +++ b/test/unit/util/output_black.h @@ -36,12 +36,12 @@ class OutputBlack : public CxxTest::TestSuite { public: void setUp() { - DebugChannel.setStream(d_debugStream); - TraceChannel.setStream(d_traceStream); - NoticeChannel.setStream(d_noticeStream); - ChatChannel.setStream(d_chatStream); - MessageChannel.setStream(d_messageStream); - WarningChannel.setStream(d_warningStream); + DebugChannel.setStream(&d_debugStream); + TraceChannel.setStream(&d_traceStream); + NoticeChannel.setStream(&d_noticeStream); + ChatChannel.setStream(&d_chatStream); + MessageChannel.setStream(&d_messageStream); + WarningChannel.setStream(&d_warningStream); d_debugStream.str(""); d_traceStream.str(""); -- 2.30.2