feat(kernel/expr): add flat_app auxiliary function

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-06-25 12:51:22 -07:00
parent f2b41312fb
commit c9133f33dd
2 changed files with 13 additions and 2 deletions

View file

@ -343,16 +343,23 @@ expr mk_app_vars(expr const & f, unsigned n) {
}
expr const & get_app_args(expr const & e, buffer<expr> & args) {
lean_assert(args.empty());
unsigned sz = args.size();
expr const * it = &e;
while (is_app(*it)) {
args.push_back(app_arg(*it));
it = &(app_fn(*it));
}
std::reverse(args.begin(), args.end());
std::reverse(args.begin() + sz, args.end());
return *it;
}
void flat_app(expr const & e, buffer<expr> & args) {
unsigned i = args.size();
args.push_back(expr());
expr const & f = get_app_args(e, args);
args[i] = f;
}
expr const & get_app_rev_args(expr const & e, buffer<expr> & args) {
expr const * it = &e;
while (is_app(*it)) {

View file

@ -586,6 +586,10 @@ expr const & get_app_args(expr const & e, buffer<expr> & args);
If e is of the form <tt>(...(f a1) ... an)</tt>, then the procedure stores [an, ..., a1] in \c args.
*/
expr const & get_app_rev_args(expr const & e, buffer<expr> & args);
/**
\brief Given an application \c e of the form <tt>(...(f a1) ... an)</tt>, store f, a1, ... an in args.
*/
void flat_app(expr const & e, buffer<expr> & args);
/** \brief Given \c e of the form <tt>(...(f a_1) ... a_n)</tt>, return \c f. If \c e is not an application, then return \c e. */
expr const & get_app_fn(expr const & e);
/** \brief Given \c e of the form <tt>(...(f a_1) ... a_n)</tt>, return \c n. If \c e is not an application, then return 0. */