Esempio n. 1
0
environment find_cmd(parser & p) {
    expr e; level_param_names ls;
    {
        bool save_options = true;
        parser::local_scope scope(p, save_options);
        p.set_option(get_elaborator_ignore_instances_name(), true);
        std::tie(e, ls) = parse_local_expr(p);
    }
    buffer<std::string> pos_names, neg_names;
    parse_filters(p, pos_names, neg_names);
    environment env = p.env();
    auto tc = mk_opaque_type_checker(env, p.mk_ngen());
    flycheck_information info(p.regular_stream());
    if (info.enabled()) {
        p.display_information_pos(p.cmd_pos());
    }
    p.regular_stream() << "find_decl result:\n";

    unsigned max_steps = get_find_max_steps(p.get_options());
    bool cheap         = !get_find_expensive(p.get_options());
    bool found = false;
    env.for_each_declaration([&](declaration const & d) {
            if (std::all_of(pos_names.begin(), pos_names.end(),
                            [&](std::string const & pos) { return is_part_of(pos, d.get_name()); }) &&
                std::all_of(neg_names.begin(), neg_names.end(),
                            [&](std::string const & neg) { return !is_part_of(neg, d.get_name()); }) &&
                match_pattern(*tc.get(), e, d, max_steps, cheap)) {
                found = true;
                p.regular_stream() << " " << get_decl_short_name(d.get_name(), env) << " : " << d.get_type() << endl;
            }
        });
    if (!found)
        p.regular_stream() << "no matches\n";
    return env;
}
Esempio n. 2
0
environment check_cmd(parser & p) {
    expr e   = p.parse_expr();
    list<expr> ctx = locals_to_context(e, p);
    level_param_names ls = to_level_param_names(collect_univ_params(e));
    level_param_names new_ls;
    std::tie(e, new_ls) = p.elaborate_relaxed(e, ctx);
    auto tc = mk_type_checker_with_hints(p.env(), p.mk_ngen(), true);
    expr type = tc->check(e, append(ls, new_ls));
    auto reg              = p.regular_stream();
    formatter const & fmt = reg.get_formatter();
    options opts          = p.ios().get_options();
    unsigned indent       = get_pp_indent(opts);
    format r = group(format{fmt(e), space(), colon(), nest(indent, compose(line(), fmt(type)))});
    reg << mk_pair(r, opts) << endl;
    return p.env();
}