2013-08-08 02:10:12 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2013 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2013-10-25 21:52:08 +00:00
|
|
|
#include <memory>
|
2013-11-19 02:08:28 +00:00
|
|
|
#include <utility>
|
2014-02-16 19:23:25 +00:00
|
|
|
#include <functional>
|
2013-11-19 02:08:28 +00:00
|
|
|
#include "util/buffer.h"
|
2013-09-13 10:35:29 +00:00
|
|
|
#include "kernel/expr.h"
|
|
|
|
#include "kernel/expr_sets.h"
|
2013-08-08 02:10:12 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-09-13 20:46:22 +00:00
|
|
|
/**
|
2014-02-16 19:23:25 +00:00
|
|
|
\brief Expression visitor.
|
2013-10-25 22:25:17 +00:00
|
|
|
|
2014-02-16 19:23:25 +00:00
|
|
|
The argument \c F must be a lambda (function object) containing the method
|
2013-08-08 02:10:12 +00:00
|
|
|
|
2014-02-16 19:23:25 +00:00
|
|
|
<code>
|
2014-06-11 22:06:11 +00:00
|
|
|
bool operator()(expr const & e, unsigned offset)
|
2014-02-16 19:23:25 +00:00
|
|
|
</code>
|
2013-08-08 02:10:12 +00:00
|
|
|
|
2014-02-16 19:23:25 +00:00
|
|
|
The \c offset is the number of binders under which \c e occurs.
|
|
|
|
*/
|
|
|
|
class for_each_fn {
|
|
|
|
std::unique_ptr<expr_cell_offset_set> m_visited;
|
2014-02-18 01:06:33 +00:00
|
|
|
std::function<bool(expr const &, unsigned)> m_f; // NOLINT
|
2014-02-16 19:23:25 +00:00
|
|
|
void apply(expr const & e, unsigned offset);
|
2013-08-08 02:10:12 +00:00
|
|
|
public:
|
2014-02-16 19:23:25 +00:00
|
|
|
template<typename F> for_each_fn(F && f):m_f(f) {}
|
|
|
|
template<typename F> for_each_fn(F const & f):m_f(f) {}
|
2013-08-08 02:10:12 +00:00
|
|
|
void operator()(expr const & e) { apply(e, 0); }
|
|
|
|
};
|
2013-11-19 21:03:46 +00:00
|
|
|
|
2014-02-16 19:23:25 +00:00
|
|
|
template<typename F> void for_each(expr const & e, F && f) {
|
|
|
|
return for_each_fn(f)(e);
|
2013-11-19 21:03:46 +00:00
|
|
|
}
|
2013-08-08 02:10:12 +00:00
|
|
|
}
|