2014-02-24 01:50:43 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2014-07-27 16:41:25 +00:00
|
|
|
#include <string>
|
2014-02-24 01:50:43 +00:00
|
|
|
#include "kernel/error_msgs.h"
|
|
|
|
|
|
|
|
namespace lean {
|
2014-07-10 17:32:00 +00:00
|
|
|
format pp_indent_expr(formatter const & fmt, expr const & e) {
|
|
|
|
return nest(get_pp_indent(fmt.get_options()), compose(line(), fmt(e)));
|
2014-02-24 01:50:43 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 17:32:00 +00:00
|
|
|
format pp_type_expected(formatter const & fmt, expr const & e) {
|
|
|
|
return compose(format("type expected at"), pp_indent_expr(fmt, e));
|
2014-02-24 01:50:43 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 17:32:00 +00:00
|
|
|
format pp_function_expected(formatter const & fmt, expr const & e) {
|
|
|
|
return compose(format("function expected at"), pp_indent_expr(fmt, e));
|
2014-02-24 01:50:43 +00:00
|
|
|
}
|
|
|
|
|
2014-07-27 16:41:25 +00:00
|
|
|
MK_THREAD_LOCAL_GET_DEF(list<options>, get_distinguishing_pp_options)
|
|
|
|
|
|
|
|
list<options> set_distinguishing_pp_options(list<options> const & opts) {
|
|
|
|
list<options> r = get_distinguishing_pp_options();
|
|
|
|
get_distinguishing_pp_options() = opts;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::tuple<format, format> pp_until_different(formatter const & fmt, expr const & e1, expr const & e2, list<options> extra) {
|
|
|
|
formatter fmt1 = fmt;
|
|
|
|
while (true) {
|
|
|
|
format r1 = pp_indent_expr(fmt1, e1);
|
|
|
|
format r2 = pp_indent_expr(fmt1, e2);
|
|
|
|
if (!format_pp_eq(r1, r2, fmt1.get_options()))
|
|
|
|
return mk_pair(r1, r2);
|
|
|
|
if (!extra)
|
|
|
|
return mk_pair(pp_indent_expr(fmt, e1), pp_indent_expr(fmt, e2));
|
|
|
|
options o = join(head(extra), fmt.get_options());
|
|
|
|
fmt1 = fmt.update_options(o);
|
|
|
|
extra = tail(extra);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::tuple<format, format> pp_until_different(formatter const & fmt, expr const & e1, expr const & e2) {
|
|
|
|
return pp_until_different(fmt, e1, e2, get_distinguishing_pp_options());
|
|
|
|
}
|
|
|
|
|
2014-07-28 14:08:12 +00:00
|
|
|
format pp_app_type_mismatch(formatter const & fmt, expr const & app, expr const & arg, expr const & expected_type, expr const & given_type) {
|
2014-02-24 01:50:43 +00:00
|
|
|
format r;
|
2014-07-27 16:41:25 +00:00
|
|
|
format expected_fmt, given_fmt;
|
|
|
|
std::tie(expected_fmt, given_fmt) = pp_until_different(fmt, expected_type, given_type);
|
2014-02-24 01:50:43 +00:00
|
|
|
r += format("type mismatch at application");
|
2014-07-10 17:32:00 +00:00
|
|
|
r += pp_indent_expr(fmt, app);
|
2014-07-28 14:08:12 +00:00
|
|
|
r += compose(line(), format("term"));
|
|
|
|
r += pp_indent_expr(fmt, arg);
|
2014-08-07 23:18:40 +00:00
|
|
|
r += compose(line(), format("has type"));
|
2014-07-27 16:41:25 +00:00
|
|
|
r += given_fmt;
|
2014-08-07 23:18:40 +00:00
|
|
|
r += compose(line(), format("but is expected to have type"));
|
|
|
|
r += expected_fmt;
|
2014-02-24 01:50:43 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2014-07-10 17:32:00 +00:00
|
|
|
format pp_def_type_mismatch(formatter const & fmt, name const & n, expr const & expected_type, expr const & given_type) {
|
2014-07-27 16:41:25 +00:00
|
|
|
format expected_fmt, given_fmt;
|
|
|
|
std::tie(expected_fmt, given_fmt) = pp_until_different(fmt, expected_type, given_type);
|
2014-02-24 01:50:43 +00:00
|
|
|
format r("type mismatch at definition '");
|
|
|
|
r += format(n);
|
2014-08-07 23:18:40 +00:00
|
|
|
r += format("', has type");
|
2014-07-27 16:41:25 +00:00
|
|
|
r += given_fmt;
|
2014-08-07 23:18:40 +00:00
|
|
|
r += compose(line(), format("but is expected to have type"));
|
|
|
|
r += expected_fmt;
|
2014-02-24 01:50:43 +00:00
|
|
|
return r;
|
|
|
|
}
|
2014-06-25 15:51:33 +00:00
|
|
|
|
2014-07-27 16:41:25 +00:00
|
|
|
static format pp_until_meta_visible(formatter const & fmt, expr const & e, list<options> extra) {
|
|
|
|
formatter fmt1 = fmt;
|
|
|
|
while (true) {
|
|
|
|
format r = pp_indent_expr(fmt1, e);
|
|
|
|
std::ostringstream out;
|
|
|
|
out << mk_pair(r, fmt1.get_options());
|
|
|
|
if (out.str().find("?M") != std::string::npos)
|
|
|
|
return r;
|
|
|
|
if (!extra)
|
|
|
|
return pp_indent_expr(fmt, e);
|
|
|
|
options o = join(head(extra), fmt.get_options());
|
|
|
|
fmt1 = fmt.update_options(o);
|
|
|
|
extra = tail(extra);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
format pp_until_meta_visible(formatter const & fmt, expr const & e) {
|
|
|
|
return pp_until_meta_visible(fmt, e, get_distinguishing_pp_options());
|
|
|
|
}
|
|
|
|
|
2014-07-10 17:32:00 +00:00
|
|
|
format pp_decl_has_metavars(formatter const & fmt, name const & n, expr const & e, bool is_type) {
|
2014-06-25 15:51:33 +00:00
|
|
|
format r("failed to add declaration '");
|
|
|
|
r += format(n);
|
|
|
|
r += format("' to environment, ");
|
|
|
|
if (is_type)
|
|
|
|
r += format("type");
|
|
|
|
else
|
|
|
|
r += format("value");
|
|
|
|
r += format(" has metavariables");
|
2014-07-27 16:41:25 +00:00
|
|
|
r += pp_until_meta_visible(fmt, e);
|
2014-06-25 15:51:33 +00:00
|
|
|
return r;
|
|
|
|
}
|
2014-02-24 01:50:43 +00:00
|
|
|
}
|