2014-06-18 17:36:21 +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-14 03:12:58 +00:00
|
|
|
#include <algorithm>
|
2014-06-18 17:36:21 +00:00
|
|
|
#include "util/sstream.h"
|
2014-07-14 03:25:53 +00:00
|
|
|
#include "kernel/abstract.h"
|
|
|
|
#include "kernel/instantiate.h"
|
2014-09-10 17:24:35 +00:00
|
|
|
#include "kernel/replace_fn.h"
|
2014-09-13 17:21:10 +00:00
|
|
|
#include "kernel/error_msgs.h"
|
2014-09-10 22:20:45 +00:00
|
|
|
#include "kernel/for_each_fn.h"
|
2014-06-18 17:36:21 +00:00
|
|
|
#include "library/scoped_ext.h"
|
2014-07-14 02:47:49 +00:00
|
|
|
#include "library/locals.h"
|
2014-07-14 05:27:36 +00:00
|
|
|
#include "library/explicit.h"
|
2014-11-24 07:00:59 +00:00
|
|
|
#include "library/aliases.h"
|
2015-06-10 23:26:32 +00:00
|
|
|
#include "library/normalize.h"
|
2014-11-03 23:43:58 +00:00
|
|
|
#include "library/placeholder.h"
|
2015-06-10 22:02:43 +00:00
|
|
|
#include "library/abbreviation.h"
|
|
|
|
#include "library/unfold_macros.h"
|
2015-03-03 02:20:05 +00:00
|
|
|
#include "library/replace_visitor.h"
|
2014-11-21 18:07:16 +00:00
|
|
|
#include "library/tactic/expr_to_tactic.h"
|
2014-06-18 17:36:21 +00:00
|
|
|
#include "frontends/lean/parser.h"
|
2014-09-23 17:00:36 +00:00
|
|
|
#include "frontends/lean/tokens.h"
|
2014-06-18 17:36:21 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2015-03-14 06:25:46 +00:00
|
|
|
void consume_until_end(parser & p) {
|
|
|
|
while (!p.curr_is_token(get_end_tk())) {
|
|
|
|
if (p.curr() == scanner::token_kind::Eof)
|
|
|
|
return;
|
|
|
|
p.next();
|
|
|
|
}
|
|
|
|
p.next();
|
|
|
|
}
|
|
|
|
|
2014-09-19 19:42:22 +00:00
|
|
|
bool parse_persistent(parser & p, bool & persistent) {
|
2014-09-23 17:00:36 +00:00
|
|
|
if (p.curr_is_token_or_id(get_persistent_tk())) {
|
2014-09-19 19:42:22 +00:00
|
|
|
p.next();
|
|
|
|
persistent = true;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-10 22:36:21 +00:00
|
|
|
void check_command_period_or_eof(parser const & p) {
|
|
|
|
if (!p.curr_is_command() && !p.curr_is_eof() && !p.curr_is_token(get_period_tk()) &&
|
|
|
|
!p.curr_is_script_block())
|
|
|
|
throw parser_error("unexpected token, '.', command, Lua script, or end-of-file expected", p.pos());
|
|
|
|
}
|
|
|
|
|
|
|
|
void check_command_period_open_binder_or_eof(parser const & p) {
|
|
|
|
if (!p.curr_is_command() && !p.curr_is_eof() && !p.curr_is_token(get_period_tk()) &&
|
|
|
|
!p.curr_is_script_block() &&
|
|
|
|
!p.curr_is_token(get_lparen_tk()) && !p.curr_is_token(get_lbracket_tk()) &&
|
|
|
|
!p.curr_is_token(get_lcurly_tk()) && !p.curr_is_token(get_ldcurly_tk()))
|
|
|
|
throw parser_error("unexpected token, '(', '{', '[', '⦃', '.', command, Lua script, or end-of-file expected", p.pos());
|
|
|
|
}
|
|
|
|
|
2014-06-18 17:36:21 +00:00
|
|
|
void check_atomic(name const & n) {
|
|
|
|
if (!n.is_atomic())
|
|
|
|
throw exception(sstream() << "invalid declaration name '" << n << "', identifier must be atomic");
|
|
|
|
}
|
|
|
|
|
2015-04-22 18:32:02 +00:00
|
|
|
void check_in_section(parser const & p) {
|
|
|
|
if (!in_section(p.env()))
|
|
|
|
throw exception(sstream() << "invalid command, it must be used in a section");
|
2015-01-24 01:42:19 +00:00
|
|
|
}
|
|
|
|
|
2014-07-08 02:15:46 +00:00
|
|
|
bool is_root_namespace(name const & n) {
|
2014-09-23 17:00:36 +00:00
|
|
|
return n == get_root_tk();
|
2014-07-08 02:15:46 +00:00
|
|
|
}
|
2015-01-24 01:42:19 +00:00
|
|
|
|
2014-07-08 02:15:46 +00:00
|
|
|
name remove_root_prefix(name const & n) {
|
2014-09-23 17:00:36 +00:00
|
|
|
return n.replace_prefix(get_root_tk(), name());
|
2014-07-08 02:15:46 +00:00
|
|
|
}
|
2014-07-14 02:47:49 +00:00
|
|
|
|
2014-10-11 22:33:31 +00:00
|
|
|
// Sort local names by order of occurrence, and copy the associated parameters to ps
|
2015-06-06 00:29:36 +00:00
|
|
|
void sort_locals(buffer<expr> const & locals, parser const & p, buffer<expr> & ps) {
|
2014-11-09 22:43:22 +00:00
|
|
|
for (expr const & l : locals) {
|
|
|
|
// we only copy the locals that are in p's local context
|
|
|
|
if (p.is_local_decl(l))
|
|
|
|
ps.push_back(l);
|
|
|
|
}
|
2014-10-11 22:33:31 +00:00
|
|
|
std::sort(ps.begin(), ps.end(), [&](expr const & p1, expr const & p2) {
|
2014-10-11 17:25:02 +00:00
|
|
|
bool is_var1 = p.is_local_variable(p1);
|
|
|
|
bool is_var2 = p.is_local_variable(p2);
|
|
|
|
if (!is_var1 && is_var2)
|
2014-10-03 00:42:33 +00:00
|
|
|
return true;
|
2014-10-11 17:25:02 +00:00
|
|
|
else if (is_var1 && !is_var2)
|
2014-10-03 00:42:33 +00:00
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return p.get_local_index(p1) < p.get_local_index(p2);
|
2014-07-14 02:47:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-11 17:58:15 +00:00
|
|
|
// Return the local levels in \c ls that are not associated with variables
|
|
|
|
levels collect_local_nonvar_levels(parser & p, level_param_names const & ls) {
|
2014-07-14 02:47:49 +00:00
|
|
|
buffer<level> section_ls_buffer;
|
|
|
|
for (name const & l : ls) {
|
2014-10-11 17:25:02 +00:00
|
|
|
if (p.get_local_level_index(l) && !p.is_local_level_variable(l))
|
2014-07-14 02:47:49 +00:00
|
|
|
section_ls_buffer.push_back(mk_param_univ(l));
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return to_list(section_ls_buffer.begin(), section_ls_buffer.end());
|
|
|
|
}
|
|
|
|
|
2015-06-06 00:29:36 +00:00
|
|
|
// Version of collect_locals(expr const & e, collected_locals & ls) that ignores local constants occurring in
|
2014-11-21 18:07:16 +00:00
|
|
|
// tactics.
|
2015-06-06 00:29:36 +00:00
|
|
|
static void collect_locals_ignoring_tactics(expr const & e, collected_locals & ls) {
|
2014-11-21 18:07:16 +00:00
|
|
|
if (!has_local(e))
|
|
|
|
return;
|
|
|
|
for_each(e, [&](expr const & e, unsigned) {
|
|
|
|
if (!has_local(e))
|
|
|
|
return false;
|
|
|
|
if (is_by(e))
|
|
|
|
return false; // do not visit children
|
|
|
|
if (is_local(e))
|
|
|
|
ls.insert(e);
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-11 22:33:31 +00:00
|
|
|
// Collect local constants occurring in type and value, sort them, and store in ctx_ps
|
|
|
|
void collect_locals(expr const & type, expr const & value, parser const & p, buffer<expr> & ctx_ps) {
|
2015-06-06 00:29:36 +00:00
|
|
|
collected_locals ls;
|
2014-10-03 14:23:24 +00:00
|
|
|
buffer<expr> include_vars;
|
|
|
|
p.get_include_variables(include_vars);
|
|
|
|
for (expr const & param : include_vars) {
|
2015-04-24 22:08:58 +00:00
|
|
|
if (is_local(param)) {
|
|
|
|
collect_locals_ignoring_tactics(mlocal_type(param), ls);
|
|
|
|
ls.insert(param);
|
|
|
|
}
|
2014-10-03 14:23:24 +00:00
|
|
|
}
|
2014-11-21 18:07:16 +00:00
|
|
|
collect_locals_ignoring_tactics(type, ls);
|
|
|
|
collect_locals_ignoring_tactics(value, ls);
|
2015-06-06 00:29:36 +00:00
|
|
|
sort_locals(ls.get_collected(), p, ctx_ps);
|
2014-07-14 02:47:49 +00:00
|
|
|
}
|
2014-07-14 03:25:53 +00:00
|
|
|
|
2014-12-03 20:56:30 +00:00
|
|
|
name_set collect_univ_params_ignoring_tactics(expr const & e, name_set const & ls) {
|
|
|
|
if (!has_param_univ(e)) {
|
|
|
|
return ls;
|
|
|
|
} else {
|
|
|
|
name_set r = ls;
|
|
|
|
for_each(e, [&](expr const & e, unsigned) {
|
|
|
|
if (!has_param_univ(e)) {
|
|
|
|
return false;
|
|
|
|
} else if (is_by(e)) {
|
|
|
|
return false; // do not visit children
|
|
|
|
} else if (is_sort(e)) {
|
|
|
|
collect_univ_params_core(sort_level(e), r);
|
|
|
|
} else if (is_constant(e)) {
|
|
|
|
for (auto const & l : const_levels(e))
|
|
|
|
collect_univ_params_core(l, r);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-11 22:33:31 +00:00
|
|
|
void remove_local_vars(parser const & p, buffer<expr> & locals) {
|
2014-10-04 14:13:19 +00:00
|
|
|
unsigned j = 0;
|
2014-10-11 22:33:31 +00:00
|
|
|
for (unsigned i = 0; i < locals.size(); i++) {
|
|
|
|
expr const & param = locals[i];
|
2014-10-11 17:25:02 +00:00
|
|
|
if (!is_local(param) || !p.is_local_variable(param)) {
|
2014-10-11 22:33:31 +00:00
|
|
|
locals[j] = param;
|
2014-10-04 14:13:19 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
2014-10-11 22:33:31 +00:00
|
|
|
locals.shrink(j);
|
2014-10-04 14:13:19 +00:00
|
|
|
}
|
|
|
|
|
2014-10-30 02:47:14 +00:00
|
|
|
levels remove_local_vars(parser const & p, levels const & ls) {
|
|
|
|
return filter(ls, [&](level const & l) {
|
|
|
|
return !is_param(l) || !p.is_local_level_variable(param_id(l));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-07-14 04:04:01 +00:00
|
|
|
list<expr> locals_to_context(expr const & e, parser const & p) {
|
2015-06-06 00:29:36 +00:00
|
|
|
collected_locals ls;
|
2014-11-21 18:07:16 +00:00
|
|
|
collect_locals_ignoring_tactics(e, ls);
|
2014-07-14 04:04:01 +00:00
|
|
|
buffer<expr> locals;
|
2015-06-06 00:29:36 +00:00
|
|
|
sort_locals(ls.get_collected(), p, locals);
|
2014-07-14 04:04:01 +00:00
|
|
|
std::reverse(locals.begin(), locals.end());
|
|
|
|
return to_list(locals.begin(), locals.end());
|
2014-07-14 03:25:53 +00:00
|
|
|
}
|
2014-07-14 04:41:44 +00:00
|
|
|
|
2014-10-11 22:33:31 +00:00
|
|
|
expr mk_local_ref(name const & n, levels const & ctx_ls, unsigned num_ctx_params, expr const * ctx_params) {
|
2014-10-09 02:19:27 +00:00
|
|
|
buffer<expr> params;
|
2014-10-11 22:33:31 +00:00
|
|
|
for (unsigned i = 0; i < num_ctx_params; i++)
|
|
|
|
params.push_back(mk_explicit(ctx_params[i]));
|
|
|
|
return mk_as_atomic(mk_app(mk_explicit(mk_constant(n, ctx_ls)), params));
|
2014-10-09 02:19:27 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 22:33:31 +00:00
|
|
|
bool is_local_ref(expr const & e) {
|
2014-10-10 22:41:55 +00:00
|
|
|
if (!is_as_atomic(e))
|
2014-10-09 05:21:29 +00:00
|
|
|
return false;
|
2014-10-10 22:41:55 +00:00
|
|
|
expr const & imp_arg = get_as_atomic_arg(e);
|
2014-10-09 05:21:29 +00:00
|
|
|
if (!is_app(imp_arg))
|
|
|
|
return false;
|
|
|
|
buffer<expr> locals;
|
|
|
|
expr const & f = get_app_args(imp_arg, locals);
|
|
|
|
return
|
|
|
|
is_explicit(f) &&
|
|
|
|
is_constant(get_explicit_arg(f)) &&
|
|
|
|
std::all_of(locals.begin(), locals.end(),
|
|
|
|
[](expr const & l) {
|
|
|
|
return is_explicit(l) && is_local(get_explicit_arg(l));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-10-11 22:33:31 +00:00
|
|
|
expr update_local_ref(expr const & e, name_set const & lvls_to_remove, name_set const & locals_to_remove) {
|
|
|
|
lean_assert(is_local_ref(e));
|
2014-10-09 05:21:29 +00:00
|
|
|
if (locals_to_remove.empty() && lvls_to_remove.empty())
|
|
|
|
return e;
|
|
|
|
buffer<expr> locals;
|
2014-10-10 22:41:55 +00:00
|
|
|
expr const & f = get_app_args(get_as_atomic_arg(e), locals);
|
2014-10-09 05:21:29 +00:00
|
|
|
lean_assert(is_explicit(f));
|
|
|
|
|
|
|
|
expr new_f;
|
|
|
|
if (!lvls_to_remove.empty()) {
|
|
|
|
expr const & c = get_explicit_arg(f);
|
|
|
|
lean_assert(is_constant(c));
|
|
|
|
new_f = mk_explicit(update_constant(c, filter(const_levels(c), [&](level const & l) {
|
2014-11-03 23:43:58 +00:00
|
|
|
return is_placeholder(l) || (is_param(l) && !lvls_to_remove.contains(param_id(l)));
|
2014-10-09 05:21:29 +00:00
|
|
|
})));
|
|
|
|
} else {
|
|
|
|
new_f = f;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!locals_to_remove.empty()) {
|
|
|
|
unsigned j = 0;
|
|
|
|
for (unsigned i = 0; i < locals.size(); i++) {
|
|
|
|
expr const & l = locals[i];
|
|
|
|
if (!locals_to_remove.contains(mlocal_name(get_explicit_arg(l)))) {
|
|
|
|
locals[j] = l;
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
locals.shrink(j);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (locals.empty()) {
|
|
|
|
return get_explicit_arg(new_f);
|
|
|
|
} else {
|
2014-10-10 22:41:55 +00:00
|
|
|
return mk_as_atomic(mk_app(new_f, locals));
|
2014-10-09 05:21:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-14 04:41:44 +00:00
|
|
|
expr Fun(buffer<expr> const & locals, expr const & e, parser & p) {
|
2014-10-01 21:02:49 +00:00
|
|
|
bool use_cache = false;
|
|
|
|
return p.rec_save_pos(Fun(locals, e, use_cache), p.pos_of(e));
|
2014-07-14 04:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expr Pi(buffer<expr> const & locals, expr const & e, parser & p) {
|
2014-10-01 21:02:49 +00:00
|
|
|
bool use_cache = false;
|
|
|
|
return p.rec_save_pos(Pi(locals, e, use_cache), p.pos_of(e));
|
2014-07-14 04:41:44 +00:00
|
|
|
}
|
2014-07-14 05:27:36 +00:00
|
|
|
|
|
|
|
template<bool is_lambda>
|
|
|
|
static expr mk_binding_as_is(unsigned num, expr const * locals, expr const & b) {
|
|
|
|
expr r = abstract_locals(b, num, locals);
|
|
|
|
unsigned i = num;
|
|
|
|
while (i > 0) {
|
|
|
|
--i;
|
|
|
|
expr const & l = locals[i];
|
|
|
|
expr t = abstract_locals(mlocal_type(l), i, locals);
|
|
|
|
if (is_lambda)
|
|
|
|
r = mk_lambda(local_pp_name(l), mk_as_is(t), r, local_info(l));
|
|
|
|
else
|
|
|
|
r = mk_pi(local_pp_name(l), mk_as_is(t), r, local_info(l));
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
expr Fun_as_is(buffer<expr> const & locals, expr const & e, parser & p) {
|
|
|
|
return p.rec_save_pos(mk_binding_as_is<true>(locals.size(), locals.data(), e), p.pos_of(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
expr Pi_as_is(buffer<expr> const & locals, expr const & e, parser & p) {
|
|
|
|
return p.rec_save_pos(mk_binding_as_is<false>(locals.size(), locals.data(), e), p.pos_of(e));
|
|
|
|
}
|
2014-07-29 02:04:57 +00:00
|
|
|
|
|
|
|
level mk_result_level(environment const & env, buffer<level> const & r_lvls) {
|
|
|
|
bool impredicative = env.impredicative();
|
|
|
|
if (r_lvls.empty()) {
|
|
|
|
return impredicative ? mk_level_one() : mk_level_zero();
|
|
|
|
} else {
|
|
|
|
level r = r_lvls[0];
|
|
|
|
for (unsigned i = 1; i < r_lvls.size(); i++)
|
|
|
|
r = mk_max(r, r_lvls[i]);
|
|
|
|
r = normalize(r);
|
|
|
|
if (is_not_zero(r))
|
|
|
|
return normalize(r);
|
|
|
|
else
|
|
|
|
return impredicative ? normalize(mk_max(r, mk_level_one())) : normalize(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool occurs(level const & u, level const & l) {
|
|
|
|
bool found = false;
|
|
|
|
for_each(l, [&](level const & l) {
|
|
|
|
if (found) return false;
|
|
|
|
if (l == u) { found = true; return false; }
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
return found;
|
|
|
|
}
|
2014-09-10 17:24:35 +00:00
|
|
|
|
|
|
|
/** \brief Functional object for converting the universe metavariables in an expression in new universe parameters.
|
|
|
|
The substitution is updated with the mapping metavar -> new param.
|
|
|
|
The set of parameter names m_params and the buffer m_new_params are also updated.
|
|
|
|
*/
|
2015-03-03 02:20:05 +00:00
|
|
|
class univ_metavars_to_params_fn : public replace_visitor {
|
2014-09-10 17:24:35 +00:00
|
|
|
environment const & m_env;
|
|
|
|
local_decls<level> const & m_lls;
|
|
|
|
substitution & m_subst;
|
|
|
|
name_set & m_params;
|
|
|
|
buffer<name> & m_new_params;
|
|
|
|
unsigned m_next_idx;
|
|
|
|
|
|
|
|
/** \brief Create a new universe parameter s.t. the new name does not occur in \c m_params, nor it is
|
|
|
|
a global universe in \e m_env or in the local_decls<level> m_lls.
|
|
|
|
The new name is added to \c m_params, and the new level parameter is returned.
|
|
|
|
The name is of the form "l_i" where \c i >= m_next_idx.
|
|
|
|
*/
|
|
|
|
level mk_new_univ_param() {
|
|
|
|
name l("l");
|
|
|
|
name r = l.append_after(m_next_idx);
|
|
|
|
while (m_lls.contains(r) || m_params.contains(r) || m_env.is_universe(r)) {
|
|
|
|
m_next_idx++;
|
|
|
|
r = l.append_after(m_next_idx);
|
|
|
|
}
|
|
|
|
m_params.insert(r);
|
|
|
|
m_new_params.push_back(r);
|
|
|
|
return mk_param_univ(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
univ_metavars_to_params_fn(environment const & env, local_decls<level> const & lls, substitution & s,
|
|
|
|
name_set & ps, buffer<name> & new_ps):
|
|
|
|
m_env(env), m_lls(lls), m_subst(s), m_params(ps), m_new_params(new_ps), m_next_idx(1) {}
|
|
|
|
|
|
|
|
level apply(level const & l) {
|
|
|
|
return replace(l, [&](level const & l) {
|
|
|
|
if (!has_meta(l))
|
|
|
|
return some_level(l);
|
|
|
|
if (is_meta(l)) {
|
|
|
|
if (auto it = m_subst.get_level(meta_id(l))) {
|
|
|
|
return some_level(*it);
|
|
|
|
} else {
|
|
|
|
level new_p = mk_new_univ_param();
|
|
|
|
m_subst.assign(l, new_p);
|
|
|
|
return some_level(new_p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return none_level();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-03-03 02:20:05 +00:00
|
|
|
virtual expr visit_sort(expr const & e) {
|
|
|
|
return update_sort(e, apply(sort_level(e)));
|
2014-09-10 17:24:35 +00:00
|
|
|
}
|
|
|
|
|
2015-03-03 02:20:05 +00:00
|
|
|
virtual expr visit_constant(expr const & e) {
|
|
|
|
levels ls = map(const_levels(e), [&](level const & l) { return apply(l); });
|
|
|
|
return update_constant(e, ls);
|
|
|
|
}
|
2014-09-10 17:24:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
expr univ_metavars_to_params(environment const & env, local_decls<level> const & lls, substitution & s,
|
|
|
|
name_set & ps, buffer<name> & new_ps, expr const & e) {
|
|
|
|
return univ_metavars_to_params_fn(env, lls, s, ps, new_ps)(e);
|
|
|
|
}
|
2014-09-10 18:19:14 +00:00
|
|
|
|
2015-03-15 03:32:39 +00:00
|
|
|
std::tuple<expr, level_param_names> parse_local_expr(parser & p, bool relaxed) {
|
2014-11-24 07:00:59 +00:00
|
|
|
expr e = p.parse_expr();
|
|
|
|
list<expr> ctx = p.locals_to_context();
|
|
|
|
level_param_names new_ls;
|
2015-03-15 03:32:39 +00:00
|
|
|
if (relaxed)
|
|
|
|
std::tie(e, new_ls) = p.elaborate_relaxed(e, ctx);
|
|
|
|
else
|
|
|
|
std::tie(e, new_ls) = p.elaborate(e, ctx);
|
2014-11-24 07:00:59 +00:00
|
|
|
level_param_names ls = to_level_param_names(collect_univ_params(e));
|
|
|
|
return std::make_tuple(e, ls);
|
|
|
|
}
|
|
|
|
|
|
|
|
optional<name> is_uniquely_aliased(environment const & env, name const & n) {
|
|
|
|
if (auto it = is_expr_aliased(env, n))
|
|
|
|
if (length(get_expr_aliases(env, *it)) == 1)
|
|
|
|
return it;
|
|
|
|
return optional<name>();
|
|
|
|
}
|
|
|
|
|
|
|
|
name get_decl_short_name(name const & d, environment const & env) {
|
|
|
|
// using namespace override resolution rule
|
|
|
|
list<name> const & ns_list = get_namespaces(env);
|
|
|
|
for (name const & ns : ns_list) {
|
|
|
|
if (is_prefix_of(ns, d) && ns != d)
|
|
|
|
return d.replace_prefix(ns, name());
|
|
|
|
}
|
|
|
|
// if the alias is unique use it
|
|
|
|
if (auto it = is_uniquely_aliased(env, d))
|
|
|
|
return *it;
|
|
|
|
else
|
|
|
|
return d;
|
|
|
|
}
|
2014-11-30 03:08:37 +00:00
|
|
|
|
|
|
|
environment open_num_notation(environment const & env) {
|
|
|
|
name num("num");
|
|
|
|
try {
|
2015-05-20 18:42:16 +00:00
|
|
|
bool persistent = false;
|
|
|
|
environment new_env = override_notation(env, num, persistent);
|
2014-11-30 03:08:37 +00:00
|
|
|
return overwrite_aliases(new_env, num, name());
|
|
|
|
} catch (exception &) {
|
|
|
|
// num namespace is not available, then use only the aliases
|
|
|
|
return overwrite_aliases(env, num, name());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
environment open_prec_aliases(environment const & env) {
|
|
|
|
name prec("std", "prec");
|
|
|
|
return overwrite_aliases(env, prec, name());
|
|
|
|
}
|
|
|
|
|
2015-02-14 20:23:54 +00:00
|
|
|
name get_priority_namespace() {
|
|
|
|
return name("std", "priority");
|
|
|
|
}
|
|
|
|
|
2014-11-30 03:08:37 +00:00
|
|
|
environment open_priority_aliases(environment const & env) {
|
2015-02-14 20:23:54 +00:00
|
|
|
return overwrite_aliases(env, get_priority_namespace(), name());
|
2014-11-30 03:08:37 +00:00
|
|
|
}
|
2015-04-29 22:22:10 +00:00
|
|
|
|
|
|
|
char const * open_binder_string(binder_info const & bi, bool unicode) {
|
|
|
|
if (bi.is_implicit()) return "{";
|
|
|
|
else if (bi.is_inst_implicit()) return "[";
|
|
|
|
else if (bi.is_strict_implicit() && unicode) return "⦃";
|
|
|
|
else if (bi.is_strict_implicit() && !unicode) return "{{";
|
|
|
|
else return "(";
|
|
|
|
}
|
|
|
|
|
|
|
|
char const * close_binder_string(binder_info const & bi, bool unicode) {
|
|
|
|
if (bi.is_implicit()) return "}";
|
|
|
|
else if (bi.is_inst_implicit()) return "]";
|
|
|
|
else if (bi.is_strict_implicit() && unicode) return "⦄";
|
|
|
|
else if (bi.is_strict_implicit() && !unicode) return "}}";
|
|
|
|
else return ")";
|
|
|
|
}
|
2015-06-10 22:02:43 +00:00
|
|
|
|
|
|
|
expr postprocess(environment const & env, expr const & e) {
|
2015-06-10 23:26:32 +00:00
|
|
|
return eta_reduce(expand_abbreviations(env, unfold_untrusted_macros(env, e)));
|
2015-06-10 22:02:43 +00:00
|
|
|
}
|
2014-06-18 17:36:21 +00:00
|
|
|
}
|