summaryrefslogtreecommitdiff
path: root/src/smt/managed_ostreams.cpp
diff options
context:
space:
mode:
authorTim King <taking@google.com>2016-01-28 12:35:45 -0800
committerTim King <taking@google.com>2016-01-28 12:35:45 -0800
commit2ba8bb701ce289ba60afec01b653b0930cc59298 (patch)
tree46df365b7b41ce662a0f94de5b11c3ed20829851 /src/smt/managed_ostreams.cpp
parent42b665f2a00643c81b42932fab1441987628c5a5 (diff)
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}.
Diffstat (limited to 'src/smt/managed_ostreams.cpp')
-rw-r--r--src/smt/managed_ostreams.cpp192
1 files changed, 192 insertions, 0 deletions
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 <ostream>
+
+#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<bool, std::ostream*> pair = open(filename);
+ initialize(pair.second);
+ manage(pair.first ? pair.second : NULL);
+}
+
+std::pair<bool, std::ostream*> 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 */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback