2013-07-24 17:14:22 +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
|
|
|
|
*/
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/buffer.h"
|
|
|
|
#include "kernel/expr.h"
|
2014-06-11 20:48:28 +00:00
|
|
|
#include "kernel/replace_fn.h"
|
2013-07-24 17:14:22 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-05-17 18:20:24 +00:00
|
|
|
expr copy(expr const & a) {
|
2014-06-11 20:48:28 +00:00
|
|
|
scoped_expr_caching scope(false);
|
2014-05-17 18:20:24 +00:00
|
|
|
switch (a.kind()) {
|
|
|
|
case expr_kind::Var: return mk_var(var_idx(a));
|
|
|
|
case expr_kind::Constant: return mk_constant(const_name(a), const_levels(a));
|
|
|
|
case expr_kind::Sort: return mk_sort(sort_level(a));
|
|
|
|
case expr_kind::Macro: return mk_macro(to_macro(a)->m_definition, macro_num_args(a), macro_args(a));
|
|
|
|
case expr_kind::App: return mk_app(app_fn(a), app_arg(a));
|
|
|
|
case expr_kind::Lambda: return mk_lambda(binding_name(a), binding_domain(a), binding_body(a), binding_info(a));
|
|
|
|
case expr_kind::Pi: return mk_pi(binding_name(a), binding_domain(a), binding_body(a), binding_info(a));
|
|
|
|
case expr_kind::Meta: return mk_metavar(mlocal_name(a), mlocal_type(a));
|
2014-06-30 16:14:55 +00:00
|
|
|
case expr_kind::Local: return mk_local(mlocal_name(a), local_pp_name(a), mlocal_type(a), local_info(a));
|
2014-05-17 18:20:24 +00:00
|
|
|
}
|
|
|
|
lean_unreachable(); // LCOV_EXCL_LINE
|
|
|
|
}
|
|
|
|
|
2014-06-11 20:48:28 +00:00
|
|
|
expr deep_copy(expr const & e) {
|
|
|
|
scoped_expr_caching scope(false);
|
2014-07-19 11:53:01 +00:00
|
|
|
return replace(e, [](expr const & e) {
|
2014-06-11 20:48:28 +00:00
|
|
|
if (is_atomic(e))
|
|
|
|
return some_expr(copy(e));
|
|
|
|
else
|
|
|
|
return none_expr();
|
|
|
|
});
|
|
|
|
}
|
2013-07-24 17:14:22 +00:00
|
|
|
}
|