2014-07-02 02:05:22 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
2014-07-02 03:43:53 +00:00
|
|
|
#include "kernel/pos_info_provider.h"
|
2014-07-02 02:05:22 +00:00
|
|
|
#include "library/tactic/tactic.h"
|
2014-10-23 16:01:19 +00:00
|
|
|
#include "library/tactic/elaborate.h"
|
2014-07-02 02:05:22 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2014-07-03 15:33:29 +00:00
|
|
|
/**
|
|
|
|
\brief Return true iff the environment \c env contains the following declarations
|
|
|
|
in the namespace 'tactic'
|
2014-09-04 23:36:06 +00:00
|
|
|
tactic.builtin : tactic
|
2014-07-03 15:33:29 +00:00
|
|
|
and_then : tactic -> tactic -> tactic
|
|
|
|
or_else : tactic -> tactic -> tactic
|
|
|
|
repeat : tactic -> tactic
|
|
|
|
*/
|
|
|
|
bool has_tactic_decls(environment const & env);
|
|
|
|
|
|
|
|
/**
|
|
|
|
\brief Creates a tactic by 'executing' \c e. Definitions are unfolded, whnf procedure is invoked,
|
2014-09-04 23:36:06 +00:00
|
|
|
and definitions marked as 'tactic.builtin' are handled by the code registered using
|
2014-07-03 15:33:29 +00:00
|
|
|
\c register_expr_to_tactic.
|
|
|
|
*/
|
2014-10-15 00:12:57 +00:00
|
|
|
tactic expr_to_tactic(environment const & env, elaborate_fn const & fn, expr const & e, pos_info_provider const * p);
|
2015-07-13 22:33:27 +00:00
|
|
|
// auxiliary procedure used to compile nested tactic in tacticals
|
|
|
|
tactic expr_to_tactic(type_checker & tc, elaborate_fn const & fn, expr e, pos_info_provider const * p);
|
2014-07-03 15:33:29 +00:00
|
|
|
|
2014-10-30 00:38:59 +00:00
|
|
|
name const & get_tactic_name();
|
|
|
|
|
2015-05-01 00:52:29 +00:00
|
|
|
unsigned get_unsigned_arg(type_checker & tc, expr const & e, unsigned i);
|
2015-05-01 04:13:27 +00:00
|
|
|
optional<unsigned> get_optional_unsigned(type_checker & tc, expr const & e);
|
2015-05-01 00:52:29 +00:00
|
|
|
|
2014-10-22 22:18:43 +00:00
|
|
|
expr const & get_tactic_expr_type();
|
2015-04-22 23:03:22 +00:00
|
|
|
expr const & get_tactic_identifier_type();
|
2014-10-22 22:18:43 +00:00
|
|
|
expr mk_tactic_expr(expr const & e);
|
|
|
|
bool is_tactic_expr(expr const & e);
|
|
|
|
expr const & get_tactic_expr_expr(expr const & e);
|
|
|
|
void check_tactic_expr(expr const & e, char const * msg);
|
2014-10-29 05:32:52 +00:00
|
|
|
expr const & get_tactic_expr_list_type();
|
2015-05-18 16:25:07 +00:00
|
|
|
expr const & get_tactic_using_expr_type();
|
2014-10-22 22:18:43 +00:00
|
|
|
|
2015-02-03 03:20:24 +00:00
|
|
|
expr mk_expr_list(unsigned num, expr const * args);
|
|
|
|
|
2014-10-22 23:15:00 +00:00
|
|
|
name const & tactic_expr_to_id(expr e, char const * error_msg);
|
|
|
|
void get_tactic_expr_list_elements(expr l, buffer<expr> & r, char const * error_msg);
|
|
|
|
void get_tactic_id_list_elements(expr l, buffer<name> & r, char const * error_msg);
|
2015-02-03 00:03:06 +00:00
|
|
|
expr ids_to_tactic_expr(buffer<name> const & ids);
|
2014-10-22 23:15:00 +00:00
|
|
|
|
2014-07-03 15:33:29 +00:00
|
|
|
/**
|
|
|
|
\brief Create an expression `by t`, where \c t is an expression of type `tactic`.
|
|
|
|
This kind of expression only affects the elaborator, the kernel will reject
|
|
|
|
any declaration that contains it.
|
|
|
|
|
|
|
|
\post get_by_arg(mk_by(t)) == t
|
|
|
|
\post is_by(mk_by(t))
|
|
|
|
*/
|
|
|
|
expr mk_by(expr const & t);
|
|
|
|
/** \brief Return true iff \c t is an expression created using \c mk_by */
|
|
|
|
bool is_by(expr const & t);
|
|
|
|
/** \see mk_by */
|
|
|
|
expr const & get_by_arg(expr const & t);
|
|
|
|
|
2015-05-06 01:17:43 +00:00
|
|
|
// Similar to mk_by, but instructs the elaborator to include the whole context
|
|
|
|
expr mk_by_plus(expr const & t);
|
|
|
|
bool is_by_plus(expr const & t);
|
|
|
|
expr const & get_by_plus_arg(expr const & t);
|
|
|
|
|
2014-07-03 15:33:29 +00:00
|
|
|
expr const & get_tactic_type();
|
|
|
|
expr const & get_and_then_tac_fn();
|
|
|
|
expr const & get_or_else_tac_fn();
|
2014-10-15 00:12:57 +00:00
|
|
|
expr const & get_id_tac_fn();
|
2014-07-03 15:33:29 +00:00
|
|
|
expr const & get_repeat_tac_fn();
|
2014-08-12 23:49:21 +00:00
|
|
|
expr const & get_determ_tac_fn();
|
2014-07-03 15:33:29 +00:00
|
|
|
|
|
|
|
/** \brief Exception used to report a problem when an expression is being converted into a tactic. */
|
2015-02-17 00:56:42 +00:00
|
|
|
class expr_to_tactic_exception : public exception {
|
|
|
|
expr m_expr;
|
2014-07-03 15:06:28 +00:00
|
|
|
public:
|
2015-02-17 00:56:42 +00:00
|
|
|
expr_to_tactic_exception(expr const & e, char const * msg):exception(msg), m_expr(e) {}
|
|
|
|
expr_to_tactic_exception(expr const & e, sstream const & strm):exception(strm), m_expr(e) {}
|
|
|
|
expr const & get_expr() const { return m_expr; }
|
2014-07-02 17:35:43 +00:00
|
|
|
};
|
|
|
|
|
2014-10-15 00:12:57 +00:00
|
|
|
typedef std::function<tactic(type_checker &, elaborate_fn const & fn, expr const &, pos_info_provider const *)>
|
|
|
|
expr_to_tactic_fn;
|
2014-07-03 15:33:29 +00:00
|
|
|
|
|
|
|
/** \brief Register a new "procedural attachment" for expr_to_tactic. */
|
2014-09-22 22:26:41 +00:00
|
|
|
void register_tac(name const & n, expr_to_tactic_fn const & fn);
|
2014-10-21 00:32:32 +00:00
|
|
|
// remark: we cannot use "std::function <...> const &" in the following procedures, for some obscure reason it produces
|
2014-09-24 19:51:04 +00:00
|
|
|
// memory leaks when we compile using clang 3.3
|
|
|
|
void register_simple_tac(name const & n, std::function<tactic()> f);
|
|
|
|
void register_bin_tac(name const & n, std::function<tactic(tactic const &, tactic const &)> f);
|
|
|
|
void register_unary_tac(name const & n, std::function<tactic(tactic const &)> f);
|
|
|
|
void register_unary_num_tac(name const & n, std::function<tactic(tactic const &, unsigned)> f);
|
2014-10-30 02:13:55 +00:00
|
|
|
void register_num_tac(name const & n, std::function<tactic(unsigned k)> f);
|
2014-07-03 15:33:29 +00:00
|
|
|
|
2014-09-22 22:26:41 +00:00
|
|
|
void initialize_expr_to_tactic();
|
|
|
|
void finalize_expr_to_tactic();
|
2014-07-02 02:05:22 +00:00
|
|
|
}
|