refactor(kernel): move printer and formatter objects to the kernel

The printer and formatter objects are not trusted code.
We moved them to the kernel to be able to provide them as an argument to the trace objects.
Another motivation is to eliminate the kernel_exception_formatter hack.
With the formatter in the kernel, we can implement the pretty printer for kernel exceptions as a virtual method.

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-09-30 18:16:13 -07:00
parent ddb90d3038
commit d843d432d3
38 changed files with 38 additions and 43 deletions

View file

@ -17,7 +17,7 @@ Author: Leonardo de Moura
#include "kernel/replace.h"
#include "kernel/instantiate.h"
#include "kernel/metavar.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "library/placeholder.h"
#include "library/reduce.h"
#include "library/update_expr.h"

View file

@ -7,7 +7,7 @@ Author: Leonardo de Moura
#pragma once
#include <memory>
#include "kernel/environment.h"
#include "library/formatter.h"
#include "kernel/formatter.h"
namespace lean {
class frontend;

View file

@ -25,8 +25,8 @@ Author: Leonardo de Moura
#include "kernel/builtin.h"
#include "kernel/kernel_exception.h"
#include "kernel/expr_maps.h"
#include "kernel/printer.h"
#include "library/arith/arith.h"
#include "library/printer.h"
#include "library/state.h"
#include "library/kernel_exception_formatter.h"
#include "library/placeholder.h"

View file

@ -7,7 +7,7 @@ Author: Leonardo de Moura
#pragma once
#include "util/sexpr/options.h"
#include "kernel/context.h"
#include "library/formatter.h"
#include "kernel/formatter.h"
namespace lean {
class frontend;

View file

@ -1,6 +1,6 @@
add_library(kernel expr.cpp free_vars.cpp abstract.cpp instantiate.cpp
normalizer.cpp context.cpp level.cpp object.cpp environment.cpp
type_checker.cpp builtin.cpp occurs.cpp metavar.cpp trace.cpp
unification_constraint.cpp)
unification_constraint.cpp printer.cpp formatter.cpp)
target_link_libraries(kernel ${LEAN_LIBS})

View file

@ -60,7 +60,5 @@ inline context extend(context const & c, name const & n, expr const & d, expr co
inline context extend(context const & c, name const & n, expr const & d) { return context(c, n, d); }
inline bool empty(context const & c) { return c.empty(); }
// Remark: the implementation is at library/printer.cpp
// We add the definition here to prevent the compiler from using the coercion to bool.
std::ostream & operator<<(std::ostream & out, context const & ctx);
}

View file

@ -625,7 +625,5 @@ inline expr update_metavar(expr const & e, local_context const & lctx) {
}
// =======================================
// Remark: the implementation is at library/printer.cpp
// We add the definition here to prevent the compiler from using the coercion to bool.
std::ostream & operator<<(std::ostream & out, expr const & e);
}

View file

@ -6,8 +6,8 @@ Author: Leonardo de Moura
*/
#include <sstream>
#include "kernel/kernel_exception.h"
#include "library/printer.h"
#include "library/formatter.h"
#include "kernel/printer.h"
#include "kernel/formatter.h"
namespace lean {
class simple_formatter_cell : public formatter_cell {

View file

@ -7,7 +7,7 @@ Author: Leonardo de Moura
#include <algorithm>
#include <utility>
#include "util/exception.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "kernel/environment.h"
namespace lean {

View file

@ -1,6 +1,6 @@
add_library(library basic_thms.cpp deep_copy.cpp max_sharing.cpp
printer.cpp formatter.cpp context_to_lambda.cpp
state.cpp update_expr.cpp kernel_exception_formatter.cpp
reduce.cpp light_checker.cpp placeholder.cpp ho_unifier.cpp
expr_lt.cpp)
context_to_lambda.cpp state.cpp update_expr.cpp
kernel_exception_formatter.cpp reduce.cpp light_checker.cpp
placeholder.cpp ho_unifier.cpp expr_lt.cpp)
target_link_libraries(library ${LEAN_LIBS})

View file

@ -13,11 +13,11 @@ Author: Leonardo de Moura
#include "kernel/free_vars.h"
#include "kernel/instantiate.h"
#include "kernel/normalizer.h"
#include "kernel/printer.h"
#include "library/light_checker.h"
#include "library/reduce.h"
#include "library/update_expr.h"
#include "library/ho_unifier.h"
#include "library/printer.h"
#ifndef LEAN_LIBRARY_HO_UNIFIER_MAX_SOLUTIONS
#define LEAN_LIBRARY_HO_UNIFIER_MAX_SOLUTIONS std::numeric_limits<unsigned>::max()

View file

@ -6,7 +6,7 @@ Author: Leonardo de Moura
*/
#pragma once
#include "kernel/kernel_exception.h"
#include "library/formatter.h"
#include "kernel/formatter.h"
#include "library/state.h"
namespace lean {

View file

@ -7,12 +7,12 @@ Author: Soonho Kong
#include <utility>
#include "util/trace.h"
#include "kernel/expr.h"
#include "kernel/printer.h"
#include "library/all/all.h"
#include "library/arith/nat.h"
#include "library/arith/arith.h"
#include "library/rewriter/fo_match.h"
#include "library/rewriter/rewriter.h"
#include "library/printer.h"
using std::cout;
using std::endl;

View file

@ -5,7 +5,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Author: Soonho Kong
*/
#pragma once
#include "library/printer.h"
#include "kernel/printer.h"
#include "util/scoped_map.h"
#include "kernel/expr.h"
#include "kernel/context.h"

View file

@ -10,9 +10,9 @@
#include "kernel/environment.h"
#include "kernel/expr.h"
#include "kernel/replace.h"
#include "kernel/printer.h"
#include "library/basic_thms.h"
#include "library/light_checker.h"
#include "library/printer.h"
#include "library/rewriter/fo_match.h"
#include "library/rewriter/rewriter.h"
#include "util/buffer.h"

View file

@ -7,7 +7,7 @@ Author: Leonardo de Moura
#pragma once
#include "util/output_channel.h"
#include "util/sexpr/options.h"
#include "library/formatter.h"
#include "kernel/formatter.h"
namespace lean {
/**

View file

@ -8,7 +8,7 @@ Author: Leonardo de Moura
#include <fstream>
#include <signal.h>
#include "util/interruptable_ptr.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "frontends/lean/parser.h"
#include "version.h"

View file

@ -10,7 +10,7 @@ Author: Leonardo de Moura
#include "kernel/kernel_exception.h"
#include "kernel/builtin.h"
#include "kernel/abstract.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "frontends/lean/frontend.h"
#include "frontends/lean/operator_info.h"
#include "frontends/lean/pp.h"

View file

@ -10,8 +10,8 @@ Author: Leonardo de Moura
#include "kernel/occurs.h"
#include "kernel/abstract.h"
#include "kernel/free_vars.h"
#include "kernel/printer.h"
#include "library/placeholder.h"
#include "library/printer.h"
#include "library/basic_thms.h"
#include "library/all/all.h"
#include "frontends/lean/frontend.h"

View file

@ -9,7 +9,7 @@ Author: Leonardo de Moura
#include "util/exception.h"
#include "util/numerics/mpq.h"
#include "kernel/builtin.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "library/arith/arith.h"
#include "frontends/lean/parser.h"
#include "frontends/lean/pp.h"

View file

@ -7,7 +7,7 @@ Author: Leonardo de Moura
#include "util/test.h"
#include "kernel/abstract.h"
#include "kernel/builtin.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "frontends/lean/frontend.h"
#include "frontends/lean/pp.h"
using namespace lean;

View file

@ -11,7 +11,7 @@ Author: Leonardo de Moura
#include "kernel/builtin.h"
#include "kernel/normalizer.h"
#include "kernel/abstract.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "library/arith/arith.h"
#include "library/all/all.h"
using namespace lean;

View file

@ -13,7 +13,7 @@ Author: Leonardo de Moura
#include "kernel/builtin.h"
#include "kernel/normalizer.h"
#include "kernel/abstract.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "library/arith/arith.h"
#include "library/all/all.h"
using namespace lean;

View file

@ -14,8 +14,8 @@ Author: Leonardo de Moura
#include "kernel/free_vars.h"
#include "kernel/abstract.h"
#include "kernel/instantiate.h"
#include "kernel/printer.h"
#include "library/max_sharing.h"
#include "library/printer.h"
#include "library/arith/arith.h"
using namespace lean;

View file

@ -8,7 +8,7 @@ Author: Leonardo de Moura
#include "util/test.h"
#include "util/exception.h"
#include "kernel/environment.h"
#include "library/printer.h"
#include "kernel/printer.h"
using namespace lean;
static void tst0() {

View file

@ -16,7 +16,7 @@ Author: Leonardo de Moura
#include "kernel/normalizer.h"
#include "kernel/environment.h"
#include "kernel/type_checker.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "library/placeholder.h"
#include "library/arith/arith.h"
#include "library/all/all.h"

View file

@ -15,7 +15,7 @@ Author: Leonardo de Moura
#include "kernel/expr_sets.h"
#include "kernel/abstract.h"
#include "kernel/kernel_exception.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "library/all/all.h"
using namespace lean;

View file

@ -7,7 +7,7 @@ Author: Leonardo de Moura
#include "util/test.h"
#include "kernel/occurs.h"
#include "kernel/abstract.h"
#include "library/printer.h"
#include "kernel/printer.h"
using namespace lean;
static void tst1() {

View file

@ -11,8 +11,8 @@ Author: Leonardo de Moura
#include "kernel/instantiate.h"
#include "kernel/expr_maps.h"
#include "kernel/replace.h"
#include "kernel/printer.h"
#include "library/deep_copy.h"
#include "library/printer.h"
using namespace lean;
expr mk_big(expr f, unsigned depth, unsigned val) {

View file

@ -15,7 +15,7 @@ Author: Leonardo de Moura
#include "kernel/abstract.h"
#include "kernel/builtin.h"
#include "kernel/normalizer.h"
#include "library/printer.h"
#include "kernel/printer.h"
#include "library/basic_thms.h"
#include "library/arith/arith.h"
#include "library/all/all.h"

View file

@ -9,7 +9,7 @@ Author: Leonardo de Moura
#include "util/test.h"
#include "kernel/environment.h"
#include "kernel/abstract.h"
#include "library/formatter.h"
#include "kernel/formatter.h"
using namespace lean;
static void check(format const & f, char const * expected) {

View file

@ -8,8 +8,8 @@ Author: Leonardo de Moura
#include "kernel/environment.h"
#include "kernel/builtin.h"
#include "kernel/abstract.h"
#include "kernel/printer.h"
#include "library/ho_unifier.h"
#include "library/printer.h"
#include "library/reduce.h"
#include "library/arith/arith.h"
using namespace lean;

View file

@ -9,8 +9,8 @@ Author: Leonardo de Moura
#include "kernel/type_checker.h"
#include "kernel/environment.h"
#include "kernel/abstract.h"
#include "kernel/printer.h"
#include "library/light_checker.h"
#include "library/printer.h"
#include "library/arith/arith.h"
#include "library/all/all.h"
using namespace lean;

View file

@ -7,8 +7,8 @@ Author: Leonardo de Moura
#include <iostream>
#include "util/test.h"
#include "kernel/abstract.h"
#include "kernel/printer.h"
#include "library/max_sharing.h"
#include "library/printer.h"
using namespace lean;
static void tst1() {

View file

@ -9,13 +9,13 @@ Author: Soonho Kong
#include "kernel/abstract.h"
#include "kernel/expr.h"
#include "kernel/metavar.h"
#include "kernel/printer.h"
#include "library/all/all.h"
#include "library/arith/arith.h"
#include "library/arith/nat.h"
#include "library/rewriter/fo_match.h"
#include "library/rewriter/rewriter.h"
#include "library/basic_thms.h"
#include "library/printer.h"
using namespace lean;
using std::cout;

View file

@ -8,14 +8,13 @@ Author: Soonho Kong
#include "kernel/abstract.h"
#include "kernel/context.h"
#include "kernel/expr.h"
#include "kernel/printer.h"
#include "library/all/all.h"
#include "library/arith/arith.h"
#include "library/arith/nat.h"
#include "library/rewriter/fo_match.h"
#include "library/rewriter/rewriter.h"
#include "library/basic_thms.h"
#include "library/printer.h"
#include "library/kernel_exception_formatter.h"
using namespace lean;
using std::cout;