2013-09-13 01:25:38 +00:00
|
|
|
/*
|
2014-05-31 03:26:06 +00:00
|
|
|
Copyright (c) 2013-2014 Microsoft Corporation. All rights reserved.
|
2013-09-13 01:25:38 +00:00
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
2014-05-31 03:26:06 +00:00
|
|
|
#include "kernel/find_fn.h"
|
2013-09-13 01:25:38 +00:00
|
|
|
#include "library/placeholder.h"
|
2013-12-20 05:36:17 +00:00
|
|
|
#include "library/kernel_bindings.h"
|
2013-09-13 01:25:38 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-05-31 03:26:06 +00:00
|
|
|
static name g_placeholder_name = name(name::mk_internal_unique_name(), "_");
|
|
|
|
|
|
|
|
level mk_level_placeholder() { return mk_global_univ(g_placeholder_name); }
|
|
|
|
expr mk_expr_placeholder() { return mk_constant(g_placeholder_name); }
|
|
|
|
bool is_placeholder(level const & e) { return is_global(e) && global_id(e) == g_placeholder_name; }
|
|
|
|
bool is_placeholder(expr const & e) { return is_constant(e) && const_name(e) == g_placeholder_name; }
|
|
|
|
|
|
|
|
bool has_placeholder(level const & l) {
|
|
|
|
bool r = false;
|
|
|
|
for_each(l, [&](level const & e) {
|
|
|
|
if (is_placeholder(e))
|
|
|
|
r = true;
|
|
|
|
return !r;
|
|
|
|
});
|
|
|
|
return r;
|
2013-09-13 01:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool has_placeholder(expr const & e) {
|
2014-05-31 03:26:06 +00:00
|
|
|
return (bool) find(e, [](expr const & e, unsigned) { // NOLINT
|
|
|
|
if (is_placeholder(e))
|
|
|
|
return true;
|
|
|
|
else if (is_sort(e))
|
|
|
|
return has_placeholder(sort_level(e));
|
|
|
|
else if (is_constant(e))
|
|
|
|
return std::any_of(const_levels(e).begin(), const_levels(e).end(), [](level const & l) { return has_placeholder(l); });
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
});
|
2013-09-13 01:25:38 +00:00
|
|
|
}
|
2013-09-17 18:09:59 +00:00
|
|
|
|
2014-05-31 03:26:06 +00:00
|
|
|
static int mk_level_placeholder(lua_State * L) { return push_level(L, mk_level_placeholder()); }
|
|
|
|
static int mk_expr_placeholder(lua_State * L) { return push_expr(L, mk_expr_placeholder()); }
|
|
|
|
static int is_placeholder(lua_State * L) {
|
|
|
|
if (is_expr(L, 1))
|
|
|
|
return push_boolean(L, is_placeholder(to_expr(L, 1)));
|
|
|
|
else
|
|
|
|
return push_boolean(L, is_placeholder(to_level(L, 1)));
|
2013-09-17 18:09:59 +00:00
|
|
|
}
|
2014-05-31 03:26:06 +00:00
|
|
|
static int has_placeholder(lua_State * L) {
|
|
|
|
if (is_expr(L, 1))
|
|
|
|
return push_boolean(L, has_placeholder(to_expr(L, 1)));
|
|
|
|
else
|
|
|
|
return push_boolean(L, has_placeholder(to_level(L, 1)));
|
2013-12-20 05:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void open_placeholder(lua_State * L) {
|
2014-05-31 03:26:06 +00:00
|
|
|
SET_GLOBAL_FUN(mk_level_placeholder, "mk_level_placeholder");
|
|
|
|
SET_GLOBAL_FUN(mk_expr_placeholder, "mk_expr_placeholder");
|
|
|
|
SET_GLOBAL_FUN(is_placeholder, "is_placeholder");
|
|
|
|
SET_GLOBAL_FUN(has_placeholder, "has_placeholder");
|
2013-12-20 05:36:17 +00:00
|
|
|
}
|
2013-09-13 01:25:38 +00:00
|
|
|
}
|