refactor(library/io_state): simplify regular/diagnostic
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
6b1b6c7bd1
commit
c0b9c7ffc4
6 changed files with 46 additions and 88 deletions
|
@ -184,13 +184,8 @@ std::ostream & operator<<(std::ostream & out, operator_info const & o) {
|
|||
return out;
|
||||
}
|
||||
|
||||
regular const & operator<<(regular const & out, operator_info const & o) {
|
||||
out.m_io_state.get_regular_channel().get_stream() << mk_pair(pp(o), out.m_io_state.get_options());
|
||||
return out;
|
||||
}
|
||||
|
||||
diagnostic const & operator<<(diagnostic const & out, operator_info const & o) {
|
||||
out.m_io_state.get_diagnostic_channel().get_stream() << mk_pair(pp(o), out.m_io_state.get_options());
|
||||
io_state_stream const & operator<<(io_state_stream const & out, operator_info const & o) {
|
||||
out.get_stream() << mk_pair(pp(o), out.get_options());
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,8 +111,7 @@ inline operator_info mixfixo(std::initializer_list<name> const & l, unsigned pre
|
|||
format pp(operator_info const & o);
|
||||
std::ostream & operator<<(std::ostream & out, operator_info const & o);
|
||||
|
||||
regular const & operator<<(regular const & out, operator_info const & o);
|
||||
diagnostic const & operator<<(diagnostic const & out, operator_info const & o);
|
||||
io_state_stream const & operator<<(io_state_stream const & out, operator_info const & o);
|
||||
|
||||
/**
|
||||
\brief Create object for tracking notation/operator declarations.
|
||||
|
|
|
@ -42,57 +42,26 @@ void io_state::set_formatter(formatter const & f) {
|
|||
m_formatter = f;
|
||||
}
|
||||
|
||||
void regular::flush() {
|
||||
m_io_state.get_regular_channel().get_stream().flush();
|
||||
}
|
||||
|
||||
void diagnostic::flush() {
|
||||
m_io_state.get_diagnostic_channel().get_stream().flush();
|
||||
}
|
||||
|
||||
regular const & operator<<(regular const & out, endl_class) {
|
||||
out.m_io_state.get_regular_channel().get_stream() << std::endl;
|
||||
io_state_stream const & operator<<(io_state_stream const & out, endl_class) {
|
||||
out.get_stream() << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
diagnostic const & operator<<(diagnostic const & out, endl_class) {
|
||||
out.m_io_state.get_diagnostic_channel().get_stream() << std::endl;
|
||||
io_state_stream const & operator<<(io_state_stream const & out, expr const & e) {
|
||||
options const & opts = out.get_options();
|
||||
out.get_stream() << mk_pair(out.get_formatter()(e, opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
regular const & operator<<(regular const & out, expr const & e) {
|
||||
options const & opts = out.m_io_state.get_options();
|
||||
out.m_io_state.get_regular_channel().get_stream() << mk_pair(out.m_io_state.get_formatter()(e, opts), opts);
|
||||
io_state_stream const & operator<<(io_state_stream const & out, object const & obj) {
|
||||
options const & opts = out.get_options();
|
||||
out.get_stream() << mk_pair(out.get_formatter()(obj, opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
diagnostic const & operator<<(diagnostic const & out, expr const & e) {
|
||||
options const & opts = out.m_io_state.get_options();
|
||||
out.m_io_state.get_diagnostic_channel().get_stream() << mk_pair(out.m_io_state.get_formatter()(e, opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
regular const & operator<<(regular const & out, object const & obj) {
|
||||
options const & opts = out.m_io_state.get_options();
|
||||
out.m_io_state.get_regular_channel().get_stream() << mk_pair(out.m_io_state.get_formatter()(obj, opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
diagnostic const & operator<<(diagnostic const & out, object const & obj) {
|
||||
options const & opts = out.m_io_state.get_options();
|
||||
out.m_io_state.get_diagnostic_channel().get_stream() << mk_pair(out.m_io_state.get_formatter()(obj, opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
regular const & operator<<(regular const & out, kernel_exception const & ex) {
|
||||
options const & opts = out.m_io_state.get_options();
|
||||
out.m_io_state.get_regular_channel().get_stream() << mk_pair(ex.pp(out.m_io_state.get_formatter(), opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
diagnostic const & operator<<(diagnostic const & out, kernel_exception const & ex) {
|
||||
options const & opts = out.m_io_state.get_options();
|
||||
out.m_io_state.get_diagnostic_channel().get_stream() << mk_pair(ex.pp(out.m_io_state.get_formatter(), opts), opts);
|
||||
io_state_stream const & operator<<(io_state_stream const & out, kernel_exception const & ex) {
|
||||
options const & opts = out.get_options();
|
||||
out.get_stream() << mk_pair(ex.pp(out.get_formatter(), opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,24 +41,38 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Base class for \c regular and \c diagnostic wrapper classes.
|
||||
*/
|
||||
class io_state_stream {
|
||||
protected:
|
||||
io_state const & m_io_state;
|
||||
public:
|
||||
io_state_stream(io_state const & s):m_io_state(s) {}
|
||||
virtual std::ostream & get_stream() const = 0;
|
||||
void flush() { get_stream().flush(); }
|
||||
formatter get_formatter() const { return m_io_state.get_formatter(); }
|
||||
options get_options() const { return m_io_state.get_options(); }
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Wrapper for the io_state object that provides access to the
|
||||
io_state's regular channel
|
||||
*/
|
||||
struct regular {
|
||||
io_state const & m_io_state;
|
||||
regular(io_state const & s):m_io_state(s) {}
|
||||
void flush();
|
||||
class regular : public io_state_stream {
|
||||
public:
|
||||
regular(io_state const & s):io_state_stream(s) {}
|
||||
std::ostream & get_stream() const { return m_io_state.get_regular_channel().get_stream(); }
|
||||
};
|
||||
|
||||
/**
|
||||
\brief Wrapper for the io_state object that provides access to the
|
||||
io_state's diagnostic channel
|
||||
*/
|
||||
struct diagnostic {
|
||||
io_state const & m_io_state;
|
||||
diagnostic(io_state const & s):m_io_state(s) {}
|
||||
void flush();
|
||||
class diagnostic : public io_state_stream {
|
||||
public:
|
||||
diagnostic(io_state const & s):io_state_stream(s) {}
|
||||
std::ostream & get_stream() const { return m_io_state.get_diagnostic_channel().get_stream(); }
|
||||
};
|
||||
|
||||
// hack for using std::endl with channels
|
||||
|
@ -67,24 +81,12 @@ const endl_class endl;
|
|||
|
||||
class kernel_exception;
|
||||
|
||||
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);
|
||||
|
||||
template<typename T>
|
||||
inline regular const & operator<<(regular const & out, T const & t) {
|
||||
out.m_io_state.get_regular_channel().get_stream() << t;
|
||||
return out;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline diagnostic const & operator<<(diagnostic const & out, T const & t) {
|
||||
out.m_io_state.get_diagnostic_channel().get_stream() << t;
|
||||
io_state_stream const & operator<<(io_state_stream const & out, endl_class);
|
||||
io_state_stream const & operator<<(io_state_stream const & out, expr const & e);
|
||||
io_state_stream const & operator<<(io_state_stream const & out, object const & obj);
|
||||
io_state_stream const & operator<<(io_state_stream const & out, kernel_exception const & ex);
|
||||
template<typename T> io_state_stream const & operator<<(io_state_stream const & out, T const & t) {
|
||||
out.get_stream() << t;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,15 +100,9 @@ proof_state to_proof_state(environment const & env, context const & ctx, expr co
|
|||
return proof_state(goals(mk_pair(g_main, g)), metavar_env(), pr_builder, cex_builder);
|
||||
}
|
||||
|
||||
regular const & operator<<(regular const & out, proof_state & s) {
|
||||
options const & opts = out.m_io_state.get_options();
|
||||
out.m_io_state.get_regular_channel().get_stream() << mk_pair(s.pp(out.m_io_state.get_formatter(), opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
diagnostic const & operator<<(diagnostic const & out, proof_state & s) {
|
||||
options const & opts = out.m_io_state.get_options();
|
||||
out.m_io_state.get_diagnostic_channel().get_stream() << mk_pair(s.pp(out.m_io_state.get_formatter(), opts), opts);
|
||||
io_state_stream const & operator<<(io_state_stream const & out, proof_state & s) {
|
||||
options const & opts = out.get_options();
|
||||
out.get_stream() << mk_pair(s.pp(out.get_formatter(), opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
@ -118,8 +118,7 @@ goals map_goals(proof_state const & s, F && f) {
|
|||
});
|
||||
}
|
||||
|
||||
regular const & operator<<(regular const & out, proof_state & s);
|
||||
diagnostic const & operator<<(diagnostic const & out, proof_state & s);
|
||||
io_state_stream const & operator<<(io_state_stream const & out, proof_state & s);
|
||||
|
||||
UDATA_DEFS_CORE(goals)
|
||||
UDATA_DEFS(proof_state)
|
||||
|
|
Loading…
Reference in a new issue