2013-08-20 19:19:28 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/output_channel.h"
|
|
|
|
#include "util/sexpr/options.h"
|
2013-10-01 01:16:13 +00:00
|
|
|
#include "kernel/formatter.h"
|
2013-08-20 19:19:28 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
/**
|
|
|
|
\brief State provided to internal lean procedures that need to:
|
|
|
|
1- Access user defined options
|
|
|
|
2- Produce verbosity messages
|
|
|
|
3- Output results
|
|
|
|
4- Produce formatted output
|
|
|
|
*/
|
2013-11-21 23:51:29 +00:00
|
|
|
class io_state {
|
2013-08-20 19:19:28 +00:00
|
|
|
options m_options;
|
|
|
|
formatter m_formatter;
|
|
|
|
std::shared_ptr<output_channel> m_regular_channel;
|
|
|
|
std::shared_ptr<output_channel> m_diagnostic_channel;
|
|
|
|
public:
|
2013-11-21 23:51:29 +00:00
|
|
|
io_state();
|
|
|
|
io_state(options const & opts, formatter const & fmt);
|
|
|
|
~io_state();
|
2013-08-20 19:19:28 +00:00
|
|
|
|
|
|
|
options get_options() const { return m_options; }
|
|
|
|
formatter get_formatter() const { return m_formatter; }
|
|
|
|
output_channel & get_regular_channel() const { return *m_regular_channel; }
|
|
|
|
output_channel & get_diagnostic_channel() const { return *m_diagnostic_channel; }
|
|
|
|
|
|
|
|
void set_regular_channel(std::shared_ptr<output_channel> const & out);
|
|
|
|
void set_diagnostic_channel(std::shared_ptr<output_channel> const & out);
|
|
|
|
void set_options(options const & opts);
|
|
|
|
void set_formatter(formatter const & f);
|
2013-08-20 20:55:31 +00:00
|
|
|
template<typename T> void set_option(name const & n, T const & v) {
|
|
|
|
set_options(get_options().update(n, v));
|
|
|
|
}
|
2013-08-20 19:19:28 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 20:46:22 +00:00
|
|
|
/**
|
2013-11-21 23:51:29 +00:00
|
|
|
\brief Wrapper for the io_state object that provides access to the
|
|
|
|
io_state's regular channel
|
2013-09-13 20:46:22 +00:00
|
|
|
*/
|
2013-08-20 19:19:28 +00:00
|
|
|
struct regular {
|
2013-11-21 23:51:29 +00:00
|
|
|
io_state const & m_io_state;
|
|
|
|
regular(io_state const & s):m_io_state(s) {}
|
2013-10-01 01:38:47 +00:00
|
|
|
void flush();
|
2013-08-20 19:19:28 +00:00
|
|
|
};
|
|
|
|
|
2013-09-13 20:46:22 +00:00
|
|
|
/**
|
2013-11-21 23:51:29 +00:00
|
|
|
\brief Wrapper for the io_state object that provides access to the
|
|
|
|
io_state's diagnostic channel
|
2013-09-13 20:46:22 +00:00
|
|
|
*/
|
2013-08-20 19:19:28 +00:00
|
|
|
struct diagnostic {
|
2013-11-21 23:51:29 +00:00
|
|
|
io_state const & m_io_state;
|
|
|
|
diagnostic(io_state const & s):m_io_state(s) {}
|
2013-10-01 01:38:47 +00:00
|
|
|
void flush();
|
2013-08-20 19:19:28 +00:00
|
|
|
};
|
|
|
|
|
2013-08-21 19:42:55 +00:00
|
|
|
// hack for using std::endl with channels
|
2013-08-21 23:43:59 +00:00
|
|
|
struct endl_class { endl_class() {} };
|
2013-08-21 19:42:55 +00:00
|
|
|
const endl_class endl;
|
2013-08-20 19:19:28 +00:00
|
|
|
|
2013-10-01 01:38:47 +00:00
|
|
|
class kernel_exception;
|
2013-08-21 19:42:55 +00:00
|
|
|
|
2013-10-01 01:38:47 +00:00
|
|
|
regular const & operator<<(regular const & out, endl_class);
|
|
|
|
diagnostic const & operator<<(diagnostic const & out, endl_class);
|
|
|
|
regular const & operator<<(regular const & out, expr const & e);
|
|
|
|
diagnostic const & operator<<(diagnostic const & out, expr const & e);
|
|
|
|
regular const & operator<<(regular const & out, object const & obj);
|
|
|
|
diagnostic const & operator<<(diagnostic const & out, object const & obj);
|
|
|
|
regular const & operator<<(regular const & out, kernel_exception const & ex);
|
|
|
|
diagnostic const & operator<<(diagnostic const & out, kernel_exception const & ex);
|
2013-08-21 19:42:55 +00:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline regular const & operator<<(regular const & out, T const & t) {
|
2013-11-21 23:51:29 +00:00
|
|
|
out.m_io_state.get_regular_channel().get_stream() << t;
|
2013-08-21 19:42:55 +00:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
inline diagnostic const & operator<<(diagnostic const & out, T const & t) {
|
2013-11-21 23:51:29 +00:00
|
|
|
out.m_io_state.get_diagnostic_channel().get_stream() << t;
|
2013-08-21 19:42:55 +00:00
|
|
|
return out;
|
|
|
|
}
|
2013-08-20 19:19:28 +00:00
|
|
|
}
|