2013-08-25 01:02: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
|
|
|
|
*/
|
|
|
|
#pragma once
|
2013-08-30 03:12:43 +00:00
|
|
|
#include <memory>
|
2013-10-24 22:14:29 +00:00
|
|
|
#include <utility>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "kernel/environment.h"
|
2013-10-01 01:16:13 +00:00
|
|
|
#include "kernel/formatter.h"
|
2013-08-25 01:02:38 +00:00
|
|
|
|
|
|
|
namespace lean {
|
2013-09-02 01:16:26 +00:00
|
|
|
class frontend;
|
2013-08-25 01:02:38 +00:00
|
|
|
/**
|
2013-10-24 17:45:59 +00:00
|
|
|
\brief Expression elaborator for the Lean default frontend, it is responsible for "filling" holes
|
2013-08-25 01:02:38 +00:00
|
|
|
in terms left by the user. This is the main module resposible for computing
|
2013-10-24 17:45:59 +00:00
|
|
|
the value of implicit arguments. It is based on the general purpose elaborator defined at
|
|
|
|
library/elaborator/elaborator.h
|
2013-08-25 01:02:38 +00:00
|
|
|
*/
|
2013-10-24 17:45:59 +00:00
|
|
|
class frontend_elaborator {
|
2013-08-30 03:12:43 +00:00
|
|
|
class imp;
|
|
|
|
std::shared_ptr<imp> m_ptr;
|
2013-08-31 00:18:39 +00:00
|
|
|
static void print(imp * ptr);
|
2013-08-25 01:02:38 +00:00
|
|
|
public:
|
2013-10-24 17:45:59 +00:00
|
|
|
explicit frontend_elaborator(frontend const & fe);
|
|
|
|
~frontend_elaborator();
|
2013-08-25 17:34:19 +00:00
|
|
|
|
2013-10-24 17:45:59 +00:00
|
|
|
/**
|
|
|
|
\brief Elaborate the given expression.
|
|
|
|
*/
|
2013-08-30 03:12:43 +00:00
|
|
|
expr operator()(expr const & e);
|
2013-10-24 17:45:59 +00:00
|
|
|
/**
|
|
|
|
\brief Elaborate the given type and expression. The typeof(e) == t.
|
|
|
|
This information is used by the elaborator. The result is a new
|
|
|
|
elaborated type and expression.
|
|
|
|
*/
|
2013-10-24 22:14:29 +00:00
|
|
|
std::pair<expr, expr> operator()(name const & n, expr const & t, expr const & e);
|
2013-08-25 17:34:19 +00:00
|
|
|
|
2013-08-31 23:46:41 +00:00
|
|
|
/**
|
|
|
|
\brief If \c e is an expression instantiated by the elaborator, then it
|
|
|
|
returns the expression (the one with "holes") used to generate \c e.
|
|
|
|
Otherwise, it just returns \c e.
|
|
|
|
*/
|
|
|
|
expr const & get_original(expr const & e) const;
|
|
|
|
|
2013-08-30 03:12:43 +00:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
environment const & get_environment() const;
|
|
|
|
};
|
2013-10-24 17:45:59 +00:00
|
|
|
|
2013-09-01 17:24:10 +00:00
|
|
|
/**
|
|
|
|
\brief Create a choice expression for the given functions.
|
|
|
|
It is used to mark which functions can be used in a particular application.
|
|
|
|
The elaborator decides which one should be used based on the type of the arguments.
|
|
|
|
|
|
|
|
\pre num_fs >= 2
|
|
|
|
*/
|
|
|
|
expr mk_choice(unsigned num_fs, expr const * fs);
|
|
|
|
/**
|
|
|
|
\brief Return true iff \c e is an expression created using \c mk_choice.
|
|
|
|
*/
|
|
|
|
bool is_choice(expr const & e);
|
|
|
|
/**
|
|
|
|
\brief Return the number of alternatives in a choice expression.
|
|
|
|
We have that <tt>get_num_choices(mk_choice(n, fs)) == n</tt>.
|
|
|
|
|
|
|
|
\pre is_choice(e)
|
|
|
|
*/
|
|
|
|
unsigned get_num_choices(expr const & e);
|
|
|
|
/**
|
|
|
|
\brief Return the (i+1)-th alternative of a choice expression.
|
|
|
|
|
|
|
|
\pre is_choice(e)
|
|
|
|
\pre i < get_num_choices(e)
|
|
|
|
*/
|
|
|
|
expr const & get_choice(expr const & e, unsigned i);
|
2013-08-25 01:02:38 +00:00
|
|
|
}
|