refactor(kernel): finish formatter interface

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-02-22 23:17:52 -08:00
parent 28516a8dc2
commit 4b7fe064fe
3 changed files with 10 additions and 7 deletions

View file

@ -151,6 +151,12 @@ public:
virtual format operator()(expr const & e, options const &) { virtual format operator()(expr const & e, options const &) {
std::ostringstream s; s << e; return format(s.str()); std::ostringstream s; s << e; return format(s.str());
} }
virtual format operator()(object const & /* obj */, options const & /* opts */) {
return format(); // TODO(Leo)
}
virtual format operator()(ro_environment const & /* env */, options const & /* opts */) {
return format(); // TODO(Leo)
}
}; };
formatter mk_simple_formatter() { formatter mk_simple_formatter() {
return mk_formatter(simple_formatter_cell()); return mk_formatter(simple_formatter_cell());

View file

@ -7,6 +7,7 @@ Author: Leonardo de Moura
#pragma once #pragma once
#include <memory> #include <memory>
#include "util/sexpr/options.h" #include "util/sexpr/options.h"
#include "kernel/environment.h"
#include "kernel/expr.h" #include "kernel/expr.h"
namespace lean { namespace lean {
@ -18,7 +19,6 @@ public:
virtual ~formatter_cell() {} virtual ~formatter_cell() {}
/** \brief Format the given expression. */ /** \brief Format the given expression. */
virtual format operator()(expr const & e, options const & opts) = 0; virtual format operator()(expr const & e, options const & opts) = 0;
#if 0
/** \brief Format the given object */ /** \brief Format the given object */
virtual format operator()(object const & obj, options const & opts) = 0; virtual format operator()(object const & obj, options const & opts) = 0;
/** \brief Format the given environment */ /** \brief Format the given environment */
@ -29,7 +29,6 @@ public:
Not every formatter has an associated environment object. Not every formatter has an associated environment object.
*/ */
virtual optional<ro_environment> get_environment() const { return optional<ro_environment>(); } virtual optional<ro_environment> get_environment() const { return optional<ro_environment>(); }
#endif
}; };
/** /**
\brief Smart-pointer for the actual formatter object (aka \c formatter_cell). \brief Smart-pointer for the actual formatter object (aka \c formatter_cell).
@ -39,11 +38,9 @@ class formatter {
formatter(formatter_cell * c):m_cell(c) {} formatter(formatter_cell * c):m_cell(c) {}
public: public:
format operator()(expr const & e, options const & opts = options()) const { return (*m_cell)(e, opts); } format operator()(expr const & e, options const & opts = options()) const { return (*m_cell)(e, opts); }
#if 0
format operator()(object const & obj, options const & opts = options()) const { return (*m_cell)(obj, opts); } format operator()(object const & obj, options const & opts = options()) const { return (*m_cell)(obj, opts); }
format operator()(ro_environment const & env, options const & opts = options()) const { return (*m_cell)(env, opts); } format operator()(ro_environment const & env, options const & opts = options()) const { return (*m_cell)(env, opts); }
optional<ro_environment> get_environment() { return m_cell->get_environment(); } optional<ro_environment> get_environment() { return m_cell->get_environment(); }
#endif
template<typename FCell> friend formatter mk_formatter(FCell && fcell); template<typename FCell> friend formatter mk_formatter(FCell && fcell);
}; };

View file

@ -1,7 +1,7 @@
add_library(library deep_copy.cpp expr_lt.cpp) add_library(library deep_copy.cpp expr_lt.cpp io_state_stream.cpp)
# kernel_bindings.cpp # kernel_bindings.cpp
# context_to_lambda.cpp placeholder.cpp substitution.cpp # context_to_lambda.cpp placeholder.cpp
# fo_unify.cpp bin_op.cpp equality.cpp io_state_stream.cpp printer.cpp # fo_unify.cpp bin_op.cpp equality.cpp printer.cpp
# hop_match.cpp) # hop_match.cpp)
target_link_libraries(library ${LEAN_LIBS}) target_link_libraries(library ${LEAN_LIBS})