2013-09-13 01:25:38 +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
|
|
|
|
*/
|
|
|
|
#include "kernel/occurs.h"
|
2013-09-17 18:09:59 +00:00
|
|
|
#include "kernel/metavar.h"
|
|
|
|
#include "kernel/expr_maps.h"
|
2013-10-23 22:01:33 +00:00
|
|
|
#include "kernel/replace_visitor.h"
|
2013-09-13 01:25:38 +00:00
|
|
|
#include "library/placeholder.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
static name g_placeholder_name("_");
|
2013-12-06 22:42:49 +00:00
|
|
|
expr mk_placeholder(expr const & t) {
|
|
|
|
return mk_constant(g_placeholder_name, t);
|
2013-09-13 01:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_placeholder(expr const & e) {
|
|
|
|
return is_constant(e) && const_name(e) == g_placeholder_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_placeholder(expr const & e) {
|
2013-12-02 16:46:47 +00:00
|
|
|
return occurs(mk_placeholder(), e);
|
2013-09-13 01:25:38 +00:00
|
|
|
}
|
2013-09-17 18:09:59 +00:00
|
|
|
|
2013-10-23 22:01:33 +00:00
|
|
|
class replace_placeholders_with_metavars_proc : public replace_visitor {
|
|
|
|
metavar_env & m_menv;
|
|
|
|
expr_map<expr> * m_new2old;
|
|
|
|
protected:
|
|
|
|
expr visit_constant(expr const & e, context const & c) {
|
2013-09-17 18:09:59 +00:00
|
|
|
if (is_placeholder(e)) {
|
2013-12-06 22:42:49 +00:00
|
|
|
return m_menv.mk_metavar(c, const_type(e));
|
2013-09-17 18:09:59 +00:00
|
|
|
} else {
|
|
|
|
return e;
|
|
|
|
}
|
2013-10-23 22:01:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
expr visit(expr const & e, context const & c) {
|
|
|
|
expr r = replace_visitor::visit(e, c);
|
|
|
|
if (!is_eqp(r, e) && m_new2old)
|
|
|
|
(*m_new2old)[r] = e;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
public:
|
|
|
|
replace_placeholders_with_metavars_proc(metavar_env & menv, expr_map<expr> * new2old):
|
|
|
|
m_menv(menv),
|
|
|
|
m_new2old(new2old) {
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
expr replace_placeholders_with_metavars(expr const & e, metavar_env & menv, expr_map<expr> * new2old) {
|
|
|
|
replace_placeholders_with_metavars_proc proc(menv, new2old);
|
|
|
|
return proc(e);
|
2013-09-17 18:09:59 +00:00
|
|
|
}
|
2013-09-13 01:25:38 +00:00
|
|
|
}
|