feat(library/tactic/goal): add auxiliary method

This commit is contained in:
Leonardo de Moura 2015-03-11 20:39:41 -07:00
parent ebdda67812
commit 0a5340aa22
2 changed files with 15 additions and 3 deletions

View file

@ -146,12 +146,13 @@ list<expr> goal::to_context() const {
return to_list(locals.begin(), locals.end());
}
optional<pair<expr, unsigned>> goal::find_hyp(name const & uname) const {
expr const * it = &m_meta;
template<typename F>
static optional<pair<expr, unsigned>> find_hyp_core(expr const & meta, F && pred) {
expr const * it = &meta;
unsigned i = 0;
while (is_app(*it)) {
expr const & h = app_arg(*it);
if (local_pp_name(h) == uname)
if (pred(h))
return some(mk_pair(h, i));
i++;
it = &app_fn(*it);
@ -159,6 +160,14 @@ optional<pair<expr, unsigned>> goal::find_hyp(name const & uname) const {
return optional<pair<expr, unsigned>>();
}
optional<pair<expr, unsigned>> goal::find_hyp(name const & uname) const {
return find_hyp_core(m_meta, [&](expr const & h) { return local_pp_name(h) == uname; });
}
optional<pair<expr, unsigned>> goal::find_hyp_from_internal_name(name const & n) const {
return find_hyp_core(m_meta, [&](expr const & h) { return mlocal_name(h) == n; });
}
void goal::get_hyps(buffer<expr> & r) const {
get_app_args(m_meta, r);
}

View file

@ -85,6 +85,9 @@ public:
*/
optional<pair<expr, unsigned>> find_hyp(name const & uname) const;
/** \brief Similar to find_hyp but use internal name */
optional<pair<expr, unsigned>> find_hyp_from_internal_name(name const & hname) const;
/** \brief Store hypotheses in the given buffer.
\remark The hypotheses are stored from left to right.