2014-06-13 22:13:32 +00:00
|
|
|
/*
|
2015-06-06 04:13:05 +00:00
|
|
|
Copyright (c) 2014-2015 Microsoft Corporation. All rights reserved.
|
2014-06-13 22:13:32 +00:00
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "util/name_set.h"
|
|
|
|
#include "kernel/expr.h"
|
2014-07-14 03:12:58 +00:00
|
|
|
#include "kernel/expr_sets.h"
|
2014-06-13 22:13:32 +00:00
|
|
|
namespace lean {
|
2014-12-03 20:56:30 +00:00
|
|
|
void collect_univ_params_core(level const & l, name_set & r);
|
2014-06-13 22:13:32 +00:00
|
|
|
name_set collect_univ_params(expr const & e, name_set const & ls = name_set());
|
2015-05-02 02:45:23 +00:00
|
|
|
/**
|
|
|
|
\remark If restricted is true, then locals in meta-variable applications and local constants
|
|
|
|
are ignored.
|
|
|
|
*/
|
2015-06-06 00:29:36 +00:00
|
|
|
class collected_locals {
|
|
|
|
name_set m_local_names;
|
|
|
|
buffer<expr> m_locals;
|
|
|
|
public:
|
|
|
|
void insert(expr const & l);
|
|
|
|
bool contains(expr const & l) const { return m_local_names.contains(mlocal_name(l)); }
|
|
|
|
buffer<expr> const & get_collected() const { return m_locals; }
|
|
|
|
bool empty() const { return m_locals.empty(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
void collect_locals(expr const & e, collected_locals & ls, bool restricted = false);
|
2014-06-13 22:13:32 +00:00
|
|
|
level_param_names to_level_param_names(name_set const & ls);
|
2014-08-03 23:03:58 +00:00
|
|
|
|
|
|
|
/** \brief Return true iff \c [begin_locals, end_locals) contains \c local */
|
2015-01-04 06:23:08 +00:00
|
|
|
template<typename It>
|
|
|
|
bool contains_local(expr const & local, It const & begin_locals, It const & end_locals) {
|
2014-08-03 23:03:58 +00:00
|
|
|
return std::any_of(begin_locals, end_locals, [&](expr const & l) { return mlocal_name(local) == mlocal_name(l); });
|
|
|
|
}
|
|
|
|
|
2015-01-04 06:23:08 +00:00
|
|
|
template<typename T>
|
|
|
|
bool contains_local(expr const & l, T const & locals) {
|
|
|
|
return std::any_of(locals.begin(), locals.end(),
|
|
|
|
[&](expr const & l1) { return mlocal_name(l1) == mlocal_name(l); });
|
2014-08-03 23:03:58 +00:00
|
|
|
}
|
2014-11-26 21:09:42 +00:00
|
|
|
|
|
|
|
/** \brief Return true iff \c e contains a local constant named \c n (it uses mlocal_name) */
|
|
|
|
bool contains_local(expr const & e, name const & n);
|
2014-11-27 01:08:14 +00:00
|
|
|
|
|
|
|
/** \brief Return true iff \e contains the local constant \c h */
|
|
|
|
inline bool depends_on(expr const & e, expr const & h) {
|
|
|
|
return contains_local(e, mlocal_name(h));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \brief Return true iff one of \c es contains the local constant \c h */
|
2015-02-17 02:18:37 +00:00
|
|
|
optional<expr> depends_on(unsigned sz, expr const * es, expr const & h);
|
2015-05-15 22:56:18 +00:00
|
|
|
|
|
|
|
/** \brief Return true iff \c e depends on any of the local constants in \c hs */
|
|
|
|
bool depends_on_any(expr const & e, unsigned hs_sz, expr const * hs);
|
|
|
|
inline bool depends_on_any(expr const & e, buffer<expr> const & hs) {
|
|
|
|
return depends_on_any(e, hs.size(), hs.data());
|
|
|
|
}
|
2015-06-06 04:13:05 +00:00
|
|
|
|
|
|
|
/** \brief Replace the given local constants occurring in \c e with the given terms */
|
|
|
|
expr replace_locals(expr const & e, unsigned sz, expr const * locals, expr const * terms);
|
|
|
|
expr replace_locals(expr const & e, buffer<expr> const & locals, buffer<expr> const & terms);
|
2014-06-13 22:13:32 +00:00
|
|
|
}
|