refactor(kernel/io_state): move io_state_stream to library
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
b81d3309b9
commit
0592261847
40 changed files with 134 additions and 80 deletions
|
@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/coercion.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/environment.h"
|
||||
#include "kernel/replace_fn.h"
|
||||
#include "kernel/abstract.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
||||
namespace lean {
|
||||
|
|
|
@ -19,6 +19,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/expr_sets.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "kernel/io_state.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/expr_pair.h"
|
||||
#include "library/expr_pair_maps.h"
|
||||
#include "library/arith/nat.h"
|
||||
|
|
|
@ -17,6 +17,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/unification_constraint.h"
|
||||
#include "kernel/instantiate.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/placeholder.h"
|
||||
#include "library/elaborator/elaborator.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
|
|
@ -5,6 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include "util/rc.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/operator_info.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser.h"
|
||||
#include "frontends/lean/pp.h"
|
||||
#include "frontends/lean/parser_imp.h"
|
||||
|
|
|
@ -6,6 +6,7 @@ Author: Leonardo de Moura
|
|||
*/
|
||||
#include "kernel/builtin.h"
|
||||
#include "library/placeholder.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser_calc.h"
|
||||
#include "frontends/lean/parser_imp.h"
|
||||
#include "frontends/lean/operator_info.h"
|
||||
|
|
|
@ -15,6 +15,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/normalizer.h"
|
||||
#include "kernel/type_checker.h"
|
||||
#include "library/placeholder.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser_imp.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
#include "frontends/lean/pp.h"
|
||||
|
|
|
@ -6,6 +6,7 @@ Author: Leonardo de Moura
|
|||
*/
|
||||
#include <utility>
|
||||
#include "kernel/kernel_exception.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser_imp.h"
|
||||
|
||||
namespace lean {
|
||||
|
|
|
@ -14,6 +14,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/free_vars.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "library/placeholder.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/arith/nat.h"
|
||||
#include "library/arith/int.h"
|
||||
#include "library/arith/real.h"
|
||||
|
|
|
@ -7,6 +7,7 @@ Author: Leonardo de Moura
|
|||
#include <utility>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser_imp.h"
|
||||
#include "frontends/lean/parser_macros.h"
|
||||
#include "frontends/lean/parser_calc.h"
|
||||
|
|
|
@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser_imp.h"
|
||||
namespace lean {
|
||||
// ==========================================
|
||||
|
|
|
@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
|
|||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser_imp.h"
|
||||
#include "frontends/lean/notation.h"
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/type_checker.h"
|
||||
#include "kernel/type_checker_justification.h"
|
||||
#include "kernel/unification_constraint.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/expr_lt.h"
|
||||
#include "library/elaborator/elaborator.h"
|
||||
#include "frontends/lean/parser_imp.h"
|
||||
|
|
|
@ -23,6 +23,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/replace_fn.h"
|
||||
#include "library/context_to_lambda.h"
|
||||
#include "library/placeholder.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/notation.h"
|
||||
#include "frontends/lean/pp.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
|
|
@ -10,6 +10,7 @@ Author: Leonardo de Moura
|
|||
#include "util/sexpr/options.h"
|
||||
#include "kernel/io_state.h"
|
||||
#include "library/kernel_bindings.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
#include "frontends/lean/pp.h"
|
||||
|
|
|
@ -8,6 +8,7 @@ Author: Leonardo de Moura
|
|||
#include "util/numerics/register_module.h"
|
||||
#include "util/sexpr/register_module.h"
|
||||
#include "library/register_module.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/arith/register_module.h"
|
||||
#include "library/tactic/register_module.h"
|
||||
#include "frontends/lean/register_module.h"
|
||||
|
|
|
@ -40,33 +40,4 @@ void io_state::set_options(options const & opts) {
|
|||
void io_state::set_formatter(formatter const & f) {
|
||||
m_formatter = f;
|
||||
}
|
||||
|
||||
io_state_stream const & operator<<(io_state_stream const & out, endl_class) {
|
||||
out.get_stream() << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
io_state_stream const & operator<<(io_state_stream const & out, environment const & env) {
|
||||
options const & opts = out.get_options();
|
||||
out.get_stream() << mk_pair(out.get_formatter()(env, opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,54 +40,4 @@ public:
|
|||
set_options(get_options().update(n, v));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
\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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
struct endl_class { endl_class() {} };
|
||||
const endl_class endl;
|
||||
|
||||
class kernel_exception;
|
||||
|
||||
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, environment const & env);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
add_library(library kernel_bindings.cpp deep_copy.cpp max_sharing.cpp
|
||||
context_to_lambda.cpp placeholder.cpp expr_lt.cpp substitution.cpp
|
||||
fo_unify.cpp bin_op.cpp eq_heq.cpp)
|
||||
fo_unify.cpp bin_op.cpp eq_heq.cpp io_state_stream.cpp)
|
||||
|
||||
target_link_libraries(library ${LEAN_LIBS})
|
||||
|
|
38
src/library/io_state_stream.cpp
Normal file
38
src/library/io_state_stream.cpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
||||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
|
||||
Author: Leonardo de Moura
|
||||
*/
|
||||
#include "library/io_state_stream.h"
|
||||
#include "kernel/kernel_exception.h"
|
||||
namespace lean {
|
||||
io_state_stream const & operator<<(io_state_stream const & out, endl_class) {
|
||||
out.get_stream() << std::endl;
|
||||
return out;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
io_state_stream const & operator<<(io_state_stream const & out, environment const & env) {
|
||||
options const & opts = out.get_options();
|
||||
out.get_stream() << mk_pair(out.get_formatter()(env, opts), opts);
|
||||
return out;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
60
src/library/io_state_stream.h
Normal file
60
src/library/io_state_stream.h
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
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
|
||||
#include "kernel/io_state.h"
|
||||
|
||||
namespace lean {
|
||||
/**
|
||||
\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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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
|
||||
struct endl_class { endl_class() {} };
|
||||
const endl_class endl;
|
||||
|
||||
class kernel_exception;
|
||||
|
||||
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, environment const & env);
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/builtin.h"
|
||||
#include "kernel/io_state.h"
|
||||
#include "kernel/type_checker.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/expr_lt.h"
|
||||
#include "library/kernel_bindings.h"
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/type_checker.h"
|
||||
#include "kernel/abstract.h"
|
||||
#include "kernel/replace_visitor.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/fo_unify.h"
|
||||
#include "library/placeholder.h"
|
||||
#include "library/kernel_bindings.h"
|
||||
|
|
|
@ -9,6 +9,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/builtin.h"
|
||||
#include "kernel/abstract.h"
|
||||
#include "kernel/occurs.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/tactic/goal.h"
|
||||
#include "library/tactic/proof_builder.h"
|
||||
#include "library/tactic/proof_state.h"
|
||||
|
|
|
@ -8,6 +8,7 @@ Author: Leonardo de Moura
|
|||
#include "util/sstream.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "kernel/type_checker.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/kernel_bindings.h"
|
||||
#include "library/tactic/proof_state.h"
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ Author: Leonardo de Moura
|
|||
#include "util/sstream.h"
|
||||
#include "util/interrupt.h"
|
||||
#include "util/lazy_list_fn.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "kernel/replace_visitor.h"
|
||||
#include "kernel/instantiate.h"
|
||||
#include "kernel/update_expr.h"
|
||||
|
|
|
@ -22,6 +22,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/formatter.h"
|
||||
#include "kernel/io_state.h"
|
||||
#include "library/kernel_bindings.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/parser.h"
|
||||
#include "frontends/lean/shell.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
|
|
@ -12,6 +12,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/abstract.h"
|
||||
#include "kernel/printer.h"
|
||||
#include "library/bin_op.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
#include "frontends/lean/operator_info.h"
|
||||
#include "frontends/lean/pp.h"
|
||||
|
|
|
@ -11,6 +11,7 @@ Author: Leonardo de Moura
|
|||
#include "util/numerics/mpq.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "kernel/printer.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/arith/arith.h"
|
||||
#include "frontends/lean/parser.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
|
|
@ -8,6 +8,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/abstract.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "kernel/printer.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
#include "frontends/lean/pp.h"
|
||||
using namespace lean;
|
||||
|
|
|
@ -14,6 +14,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/normalizer.h"
|
||||
#include "kernel/abstract.h"
|
||||
#include "kernel/printer.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/arith/arith.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
using namespace lean;
|
||||
|
|
|
@ -20,6 +20,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/kernel_exception.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "kernel/io_state.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/placeholder.h"
|
||||
#include "library/arith/arith.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
|
|
@ -18,6 +18,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/printer.h"
|
||||
#include "kernel/metavar.h"
|
||||
#include "kernel/free_vars.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/deep_copy.h"
|
||||
#include "library/arith/int.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
|
|
|
@ -11,6 +11,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/free_vars.h"
|
||||
#include "kernel/abstract.h"
|
||||
#include "kernel/normalizer.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/max_sharing.h"
|
||||
#include "library/deep_copy.h"
|
||||
#include "library/arith/arith.h"
|
||||
|
|
|
@ -21,6 +21,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/kernel_exception.h"
|
||||
#include "kernel/type_checker_justification.h"
|
||||
#include "kernel/io_state.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/arith/arith.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
using namespace lean;
|
||||
|
|
|
@ -10,6 +10,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/normalizer.h"
|
||||
#include "kernel/type_checker.h"
|
||||
#include "kernel/abstract.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/arith/arith.h"
|
||||
#include "frontends/lean/frontend.h"
|
||||
using namespace lean;
|
||||
|
|
|
@ -12,6 +12,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/normalizer.h"
|
||||
#include "kernel/instantiate.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/placeholder.h"
|
||||
#include "library/arith/arith.h"
|
||||
#include "library/elaborator/elaborator.h"
|
||||
|
|
|
@ -12,6 +12,7 @@ Author: Soonho Kong
|
|||
#include "kernel/printer.h"
|
||||
#include "kernel/io_state.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/arith/arith.h"
|
||||
#include "library/arith/nat.h"
|
||||
#include "library/rewriter/fo_match.h"
|
||||
|
|
|
@ -9,6 +9,7 @@ Author: Leonardo de Moura
|
|||
#include "util/interrupt.h"
|
||||
#include "kernel/builtin.h"
|
||||
#include "kernel/kernel_exception.h"
|
||||
#include "library/io_state_stream.h"
|
||||
#include "library/tactic/goal.h"
|
||||
#include "library/tactic/proof_builder.h"
|
||||
#include "library/tactic/proof_state.h"
|
||||
|
|
Loading…
Reference in a new issue