feat(frontends/lean): store 'overload' information, remove #setline

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-08-06 19:13:09 -07:00
parent 1ba9a92df2
commit 0276f4c1c0
10 changed files with 33 additions and 29 deletions

View file

@ -98,15 +98,6 @@ environment check_cmd(parser & p) {
return p.env(); return p.env();
} }
environment set_line_cmd(parser & p) {
if (!p.curr_is_numeral())
throw parser_error("invalid #setline command, numeral expected", p.pos());
unsigned r = p.get_small_nat();
p.set_line(r);
p.next();
return p.env();
}
environment exit_cmd(parser &) { environment exit_cmd(parser &) {
throw interrupt_parser(); throw interrupt_parser();
} }
@ -300,7 +291,7 @@ cmd_table init_cmd_table() {
add_cmd(r, cmd_info("check", "type check given expression, and display its type", check_cmd)); add_cmd(r, cmd_info("check", "type check given expression, and display its type", check_cmd));
add_cmd(r, cmd_info("coercion", "add a new coercion", coercion_cmd)); add_cmd(r, cmd_info("coercion", "add a new coercion", coercion_cmd));
add_cmd(r, cmd_info("opaque_hint", "add hints for the elaborator/unifier", opaque_hint_cmd)); add_cmd(r, cmd_info("opaque_hint", "add hints for the elaborator/unifier", opaque_hint_cmd));
add_cmd(r, cmd_info("#setline", "modify the current line number, it only affects error/report messages", set_line_cmd));
register_decl_cmds(r); register_decl_cmds(r);
register_inductive_cmd(r); register_inductive_cmd(r);
register_structure_cmd(r); register_structure_cmd(r);

View file

@ -30,12 +30,15 @@ void type_info_data::display(io_state_stream const & ios) const {
void overload_info_data::display(io_state_stream const & ios) const { void overload_info_data::display(io_state_stream const & ios) const {
ios << "-- OVERLOAD|" << get_line() << "|" << get_column() << "\n"; ios << "-- OVERLOAD|" << get_line() << "|" << get_column() << "\n";
options os = ios.get_options();
os = os.update(get_pp_full_names_option_name(), true);
auto new_ios = ios.update_options(os);
for (unsigned i = 0; i < get_num_choices(m_choices); i++) { for (unsigned i = 0; i < get_num_choices(m_choices); i++) {
if (i > 0) if (i > 0)
ios << "--\n"; ios << "--\n";
ios << get_choice(m_choices, i) << endl; new_ios << get_choice(m_choices, i) << endl;
} }
ios << "-- ACK" << endl; new_ios << "-- ACK" << endl;
} }
void coercion_info_data::display(io_state_stream const & ios) const { void coercion_info_data::display(io_state_stream const & ios) const {
@ -85,7 +88,8 @@ unsigned info_manager::find(unsigned line, unsigned column) {
void info_manager::invalidate(unsigned sline) { void info_manager::invalidate(unsigned sline) {
lock_guard<mutex> lc(m_mutex); lock_guard<mutex> lc(m_mutex);
sort_core(); sort_core();
m_data.resize(find(sline, 0)); unsigned i = find(sline, 0);
m_data.resize(i);
m_sorted_upto = m_data.size(); m_sorted_upto = m_data.size();
} }

View file

@ -85,11 +85,10 @@ parser::parser(environment const & env, io_state const & ios,
unsigned line, snapshot_vector * sv, info_manager * im): unsigned line, snapshot_vector * sv, info_manager * im):
m_env(env), m_ios(ios), m_ngen(g_tmp_prefix), m_env(env), m_ios(ios), m_ngen(g_tmp_prefix),
m_verbose(true), m_use_exceptions(use_exceptions), m_verbose(true), m_use_exceptions(use_exceptions),
m_scanner(strm, strm_name), m_local_level_decls(lds), m_local_decls(eds), m_scanner(strm, strm_name, line), m_local_level_decls(lds), m_local_decls(eds),
m_pos_table(std::make_shared<pos_info_table>()), m_pos_table(std::make_shared<pos_info_table>()),
m_theorem_queue(*this, num_threads > 1 ? num_threads - 1 : 0), m_theorem_queue(*this, num_threads > 1 ? num_threads - 1 : 0),
m_snapshot_vector(sv), m_info_manager(im) { m_snapshot_vector(sv), m_info_manager(im) {
m_scanner.set_line(line);
m_num_threads = num_threads; m_num_threads = num_threads;
m_no_undef_id_error = false; m_no_undef_id_error = false;
m_found_errors = false; m_found_errors = false;
@ -838,7 +837,9 @@ expr parser::parse_notation(parse_table t, expr * left) {
expr r = instantiate_rev(copy_with_new_pos(a, p), args.size(), args.data()); expr r = instantiate_rev(copy_with_new_pos(a, p), args.size(), args.data());
cs.push_back(r); cs.push_back(r);
} }
return save_pos(mk_choice(cs.size(), cs.data()), p); expr r = save_pos(mk_choice(cs.size(), cs.data()), p);
save_overload(r);
return r;
} }
expr parser::parse_nud_notation() { expr parser::parse_nud_notation() {
@ -896,6 +897,7 @@ expr parser::id_to_expr(name const & id, pos_info const & p) {
new_as.push_back(copy_with_new_pos(mk_constant(e, ls), p)); new_as.push_back(copy_with_new_pos(mk_constant(e, ls), p));
} }
r = save_pos(mk_choice(new_as.size(), new_as.data()), p); r = save_pos(mk_choice(new_as.size(), new_as.data()), p);
save_overload(*r);
} }
if (!r && m_no_undef_id_error) if (!r && m_no_undef_id_error)
r = save_pos(mk_constant(get_namespace(m_env) + id, ls), p); r = save_pos(mk_constant(get_namespace(m_env) + id, ls), p);
@ -1173,6 +1175,13 @@ void parser::save_snapshot() {
m_snapshot_vector->push_back(snapshot(m_env, m_local_level_decls, m_local_decls, m_ios.get_options(), m_scanner.get_line())); m_snapshot_vector->push_back(snapshot(m_env, m_local_level_decls, m_local_decls, m_ios.get_options(), m_scanner.get_line()));
} }
void parser::save_overload(expr const & e) {
if (!m_info_manager)
return;
auto p = pos_of(e);
m_info_manager->add(std::unique_ptr<info_data>(new overload_info_data(p.first, p.second, e)));
}
bool parse_commands(environment & env, io_state & ios, std::istream & in, char const * strm_name, bool use_exceptions, bool parse_commands(environment & env, io_state & ios, std::istream & in, char const * strm_name, bool use_exceptions,
unsigned num_threads) { unsigned num_threads) {
parser p(env, ios, in, strm_name, use_exceptions, num_threads); parser p(env, ios, in, strm_name, use_exceptions, num_threads);

View file

@ -151,7 +151,9 @@ class parser {
void push_local_scope(); void push_local_scope();
void pop_local_scope(); void pop_local_scope();
void save_snapshot(); void save_snapshot();
void save_overload(expr const & e);
public: public:
parser(environment const & env, io_state const & ios, parser(environment const & env, io_state const & ios,

View file

@ -53,9 +53,8 @@ static name g_pp_full_names {"pp", "full_names"};
static name g_pp_private_names {"pp", "private_names"}; static name g_pp_private_names {"pp", "private_names"};
static name g_pp_metavar_args {"pp", "metavar_args"}; static name g_pp_metavar_args {"pp", "metavar_args"};
name const & get_pp_coercion_option_name() { name const & get_pp_coercion_option_name() { return g_pp_coercion; }
return g_pp_coercion; name const & get_pp_full_names_option_name() { return g_pp_full_names; }
}
list<options> const & get_distinguishing_pp_options() { list<options> const & get_distinguishing_pp_options() {
static options g_universes_true(g_pp_universes, true); static options g_universes_true(g_pp_universes, true);

View file

@ -8,6 +8,8 @@ Author: Leonardo de Moura
#include "util/sexpr/options.h" #include "util/sexpr/options.h"
namespace lean { namespace lean {
name const & get_pp_coercion_option_name(); name const & get_pp_coercion_option_name();
name const & get_pp_full_names_option_name();
unsigned get_pp_max_depth(options const & opts); unsigned get_pp_max_depth(options const & opts);
unsigned get_pp_max_steps(options const & opts); unsigned get_pp_max_steps(options const & opts);
bool get_pp_notation(options const & opts); bool get_pp_notation(options const & opts);

View file

@ -78,11 +78,6 @@ bool is_super_sub_script_alnum_unicode(unsigned u) {
(0x2090 <= u && u <= 0x209c); (0x2090 <= u && u <= 0x209c);
} }
void scanner::set_line(unsigned p) {
m_line = p;
m_sline = p;
}
void scanner::next() { void scanner::next() {
lean_assert(m_curr != EOF); lean_assert(m_curr != EOF);
m_curr = m_stream.get(); m_curr = m_stream.get();
@ -472,11 +467,13 @@ auto scanner::scan(environment const & env) -> token_kind {
} }
} }
scanner::scanner(std::istream & strm, char const * strm_name): scanner::scanner(std::istream & strm, char const * strm_name, unsigned line):
m_tokens(nullptr), m_stream(strm), m_spos(0), m_upos(0), m_uskip(0), m_sline(1), m_curr(0), m_pos(0), m_line(1), m_tokens(nullptr), m_stream(strm), m_spos(0), m_upos(0), m_uskip(0), m_sline(line), m_curr(0), m_pos(0), m_line(line),
m_token_info(nullptr) { m_token_info(nullptr) {
m_stream_name = strm_name ? strm_name : "[unknown]"; m_stream_name = strm_name ? strm_name : "[unknown]";
next(); next();
m_spos = 0;
m_upos = 0;
} }
std::ostream & operator<<(std::ostream & out, scanner::token_kind k) { std::ostream & operator<<(std::ostream & out, scanner::token_kind k) {

View file

@ -68,7 +68,7 @@ protected:
token_kind read_quoted_symbol(); token_kind read_quoted_symbol();
public: public:
scanner(std::istream & strm, char const * strm_name = nullptr); scanner(std::istream & strm, char const * strm_name = nullptr, unsigned line = 1);
int get_line() const { return m_line; } int get_line() const { return m_line; }
int get_pos() const { return m_pos; } int get_pos() const { return m_pos; }

View file

@ -62,12 +62,12 @@ unsigned server::find(unsigned linenum) {
} }
void server::process_from(unsigned linenum) { void server::process_from(unsigned linenum) {
m_info.invalidate(linenum);
unsigned i = find(linenum); unsigned i = find(linenum);
m_snapshots.resize(i); m_snapshots.resize(i);
snapshot & s = i == 0 ? m_empty_snapshot : m_snapshots[i-1]; snapshot & s = i == 0 ? m_empty_snapshot : m_snapshots[i-1];
std::string block; std::string block;
lean_assert(s.m_line > 0); lean_assert(s.m_line > 0);
m_info.invalidate(s.m_line-1);
for (unsigned j = s.m_line-1; j < m_lines.size(); j++) { for (unsigned j = s.m_line-1; j < m_lines.size(); j++) {
block += m_lines[j]; block += m_lines[j];
block += '\n'; block += '\n';

View file

@ -78,7 +78,7 @@ token_table init_token_table() {
"abbreviation", "inductive", "record", "renaming", "extends", "structure", "module", "universe", "abbreviation", "inductive", "record", "renaming", "extends", "structure", "module", "universe",
"precedence", "infixl", "infixr", "infix", "postfix", "prefix", "notation", "precedence", "infixl", "infixr", "infix", "postfix", "prefix", "notation",
"exit", "set_option", "using", "calc_subst", "calc_refl", "calc_trans", "tactic_hint", "exit", "set_option", "using", "calc_subst", "calc_refl", "calc_trans", "tactic_hint",
"add_proof_qed", "set_proof_qed", "#setline", "instance", nullptr}; "add_proof_qed", "set_proof_qed", "instance", nullptr};
std::pair<char const *, char const *> aliases[] = std::pair<char const *, char const *> aliases[] =
{{g_lambda_unicode, "fun"}, {"forall", "Pi"}, {g_forall_unicode, "Pi"}, {g_pi_unicode, "Pi"}, {{g_lambda_unicode, "fun"}, {"forall", "Pi"}, {g_forall_unicode, "Pi"}, {g_pi_unicode, "Pi"},