feat(kernel): add max_free_var function
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
f2cac0410e
commit
4d9eb4ac6c
2 changed files with 23 additions and 0 deletions
|
@ -8,6 +8,7 @@ Author: Leonardo de Moura
|
|||
#include "kernel/free_vars.h"
|
||||
#include "kernel/expr_sets.h"
|
||||
#include "kernel/replace_fn.h"
|
||||
#include "kernel/for_each_fn.h"
|
||||
#include "kernel/metavar.h"
|
||||
|
||||
namespace lean {
|
||||
|
@ -397,4 +398,20 @@ context_entry lift_free_vars(context_entry const & e, unsigned s, unsigned d, me
|
|||
else
|
||||
return context_entry(e.get_name(), none_expr(), lift_free_vars(*body, s, d, menv));
|
||||
}
|
||||
|
||||
optional<unsigned> max_free_var(expr const & e) {
|
||||
optional<unsigned> r;
|
||||
for_each(e, [&](expr const & v, unsigned offset) {
|
||||
if (is_var(v)) {
|
||||
unsigned vidx = var_idx(v);
|
||||
if (vidx >= offset) {
|
||||
vidx -= offset;
|
||||
if (!r || vidx > *r)
|
||||
r = vidx;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,4 +88,10 @@ expr lift_free_vars(expr const & e, unsigned d, metavar_env const & menv);
|
|||
expr lift_free_vars(expr const & e, unsigned d);
|
||||
|
||||
context_entry lift_free_vars(context_entry const & e, unsigned s, unsigned d, metavar_env const & menv);
|
||||
|
||||
/**
|
||||
\brief Return the index of the max free var occurring in \c e.
|
||||
Return none if \c e does not contain free variables.
|
||||
*/
|
||||
optional<unsigned> max_free_var(expr const & e);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue