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"
|
|
|
|
#include "kernel/replace.h"
|
2013-09-13 01:25:38 +00:00
|
|
|
#include "library/placeholder.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
static name g_placeholder_name("_");
|
|
|
|
expr mk_placholder() {
|
|
|
|
return mk_constant(g_placeholder_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool is_placeholder(expr const & e) {
|
|
|
|
return is_constant(e) && const_name(e) == g_placeholder_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool has_placeholder(expr const & e) {
|
|
|
|
return occurs(mk_placholder(), e);
|
|
|
|
}
|
2013-09-17 18:09:59 +00:00
|
|
|
|
2013-09-27 01:24:45 +00:00
|
|
|
expr replace_placeholders_with_metavars(expr const & e, metavar_generator & mgen, expr_map<expr> * trace) {
|
|
|
|
auto f = [&](expr const & e, unsigned) -> expr {
|
2013-09-17 18:09:59 +00:00
|
|
|
if (is_placeholder(e)) {
|
2013-09-27 01:24:45 +00:00
|
|
|
return mgen.mk();
|
2013-09-17 18:09:59 +00:00
|
|
|
} else {
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
auto p = [&](expr const & s, expr const & t) {
|
|
|
|
if (trace)
|
|
|
|
(*trace)[t] = s;
|
|
|
|
};
|
2013-09-27 01:24:45 +00:00
|
|
|
return replace_fn<decltype(f), decltype(p)>(f, p)(e);
|
2013-09-17 18:09:59 +00:00
|
|
|
}
|
2013-09-13 01:25:38 +00:00
|
|
|
}
|