2013-10-23 22:01:33 +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-12-18 19:42:43 +00:00
|
|
|
#include "kernel/expr_maps.h"
|
2013-10-23 22:01:33 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
/**
|
|
|
|
\brief Base class for implementing operations that apply modifications
|
2014-02-19 07:15:55 +00:00
|
|
|
on expressions.
|
2013-10-23 22:01:33 +00:00
|
|
|
The default behavior is a NOOP, users must create subclasses and
|
|
|
|
redefine the visit_* methods.
|
|
|
|
*/
|
|
|
|
class replace_visitor {
|
|
|
|
protected:
|
2013-12-18 19:42:43 +00:00
|
|
|
typedef expr_map<expr> cache;
|
2013-12-16 23:09:41 +00:00
|
|
|
cache m_cache;
|
2013-12-08 07:21:07 +00:00
|
|
|
expr save_result(expr const & e, expr && r, bool shared);
|
2014-05-14 22:53:09 +00:00
|
|
|
virtual expr visit_sort(expr const &);
|
|
|
|
virtual expr visit_macro(expr const &);
|
|
|
|
virtual expr visit_constant(expr const &);
|
|
|
|
virtual expr visit_var(expr const &);
|
|
|
|
virtual expr visit_mlocal(expr const &);
|
|
|
|
virtual expr visit_meta(expr const &);
|
|
|
|
virtual expr visit_local(expr const &);
|
|
|
|
virtual expr visit_app(expr const &);
|
|
|
|
virtual expr visit_binder(expr const &);
|
|
|
|
virtual expr visit_lambda(expr const &);
|
|
|
|
virtual expr visit_pi(expr const &);
|
|
|
|
virtual expr visit_let(expr const &);
|
|
|
|
virtual expr visit(expr const &);
|
2013-10-23 22:01:33 +00:00
|
|
|
public:
|
2014-05-14 22:53:09 +00:00
|
|
|
expr operator()(expr const & e) { return visit(e); }
|
|
|
|
void clear() { m_cache.clear(); }
|
2013-10-23 22:01:33 +00:00
|
|
|
};
|
|
|
|
}
|