Example #1
0
 level collect(level const & l) {
     return replace(l, [&](level const & l) {
             if (is_meta(l)) {
                 name const & id = meta_id(l);
                 if (auto r = m_univ_meta_to_param.find(id)) {
                     return some_level(*r);
                 } else {
                     name n      = m_prefix.append_after(m_next_idx);
                     m_next_idx++;
                     level new_r = mk_param_univ(n);
                     m_univ_meta_to_param.insert(id, new_r);
                     m_univ_meta_to_param_inv.insert(n, l);
                     m_level_params.push_back(n);
                     return some_level(new_r);
                 }
             } else if (is_param(l)) {
                 name const & id = param_id(l);
                 if (!m_found_univ_params.contains(id)) {
                     m_found_univ_params.insert(id);
                     m_level_params.push_back(id);
                 }
             }
             return none_level();
         });
 }
Example #2
0
name get_unused_name(name const & prefix, unsigned & idx, buffer<expr> const & locals) {
    while (true) {
        name curr = prefix.append_after(idx);
        idx++;
        if (!uses_name(curr, locals))
            return curr;
    }
}
Example #3
0
static name mk_fresh_name(environment const & env, buffer<name> const & names, name const & s) {
    unsigned i = 1;
    name c = s;
    while (true) {
        if (!env.find(c) &&
            std::find(names.begin(), names.end(), c) == names.end())
            return c;
        c = s.append_after(i);
        i++;
    }
}
Example #4
0
 name mk_name_for(expr const & e) {
     lean_assert(is_nested_declaration(e));
     if (auto n = get_nested_declaration_name(e)) {
         return *n;
     } else {
         name ns  = get_namespace(m_env);
         while (true) {
             name aux = m_dname.append_after(m_idx);
             m_idx++;
             if (!m_env.find(ns + aux))
                 return aux;
         }
     }
 }