feat(frontends/lean): add helper function mk_section_local_ref

This commit is contained in:
Leonardo de Moura 2014-10-08 19:19:27 -07:00
parent d445857f56
commit f7bbe09db2
4 changed files with 15 additions and 6 deletions

View file

@ -362,10 +362,8 @@ environment definition_cmd_core(parser & p, bool is_theorem, bool is_opaque, boo
ls = to_list(ls_buffer.begin(), ls_buffer.end());
levels section_ls = collect_section_nonvar_levels(p, ls);
remove_section_variables(p, section_ps);
for (expr & param : section_ps)
param = mk_explicit(param);
if (!section_ps.empty()) {
expr ref = mk_implicit(mk_app(mk_explicit(mk_constant(real_n, section_ls)), section_ps));
expr ref = mk_section_local_ref(real_n, section_ls, section_ps.size(), section_ps.data());
p.add_local_expr(n, ref);
} else if (section_ls) {
expr ref = mk_constant(real_n, section_ls);

View file

@ -594,9 +594,7 @@ struct inductive_cmd_fn {
else
id = name(full_id.get_string());
if (in_section_or_context(env)) {
expr r = mk_explicit(mk_constant(full_id, section_levels));
r = mk_app(r, section_params);
r = mk_implicit(r);
expr r = mk_section_local_ref(full_id, section_levels, section_params.size(), section_params.data());
m_p.add_local_expr(id, r);
}
if (full_id != id)

View file

@ -107,6 +107,13 @@ list<expr> locals_to_context(expr const & e, parser const & p) {
return to_list(locals.begin(), locals.end());
}
expr mk_section_local_ref(name const & n, levels const & sec_ls, unsigned num_sec_params, expr const * sec_params) {
buffer<expr> params;
for (unsigned i = 0; i < num_sec_params; i++)
params.push_back(mk_explicit(sec_params[i]));
return mk_implicit(mk_app(mk_explicit(mk_constant(n, sec_ls)), params));
}
expr Fun(buffer<expr> const & locals, expr const & e, parser & p) {
bool use_cache = false;
return p.rec_save_pos(Fun(locals, e, use_cache), p.pos_of(e));

View file

@ -31,6 +31,12 @@ void sort_section_params(expr_struct_set const & locals, parser const & p, buffe
/** \brief Remove from \c ps local constants that are tagged as section variables. */
void remove_section_variables(parser const & p, buffer<expr> & ps);
list<expr> locals_to_context(expr const & e, parser const & p);
/** \brief Create the term <tt>(@^-1 (@n.{sec_ls} @sec_params[0] ... @sec_params[num_sec_params-1]))</tt>
When we declare \c n inside of a section, the section parameters and universes are fixes.
That is, when the user writes \c n inside the section she is really getting the term returned by this function.
*/
expr mk_section_local_ref(name const & n, levels const & sec_ls, unsigned num_sec_params, expr const * sec_params);
/** \brief Fun(locals, e), but also propagate \c e position to result */
expr Fun(buffer<expr> const & locals, expr const & e, parser & p);
/** \brief Pi(locals, e), but also propagate \c e position to result */