2013-08-16 19:51:12 +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-09-13 10:35:29 +00:00
|
|
|
#include <vector>
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "util/exception.h"
|
2013-10-01 01:38:47 +00:00
|
|
|
#include "util/sexpr/options.h"
|
2013-09-13 03:04:10 +00:00
|
|
|
#include "kernel/context.h"
|
|
|
|
#include "kernel/environment.h"
|
2013-10-01 01:38:47 +00:00
|
|
|
#include "kernel/formatter.h"
|
2013-08-16 19:51:12 +00:00
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
class environment;
|
|
|
|
/** \brief Base class for all kernel exceptions. */
|
|
|
|
class kernel_exception : public exception {
|
|
|
|
protected:
|
2014-04-18 21:21:49 +00:00
|
|
|
environment m_env;
|
2013-08-16 19:51:12 +00:00
|
|
|
public:
|
2014-04-18 21:21:49 +00:00
|
|
|
kernel_exception(environment const & env):m_env(env) {}
|
|
|
|
kernel_exception(environment const & env, char const * msg):exception(msg), m_env(env) {}
|
|
|
|
kernel_exception(environment const & env, sstream const & strm):exception(strm), m_env(env) {}
|
2013-08-16 19:51:12 +00:00
|
|
|
virtual ~kernel_exception() noexcept {}
|
2014-04-18 21:21:49 +00:00
|
|
|
environment const & get_environment() const { return m_env; }
|
2013-08-24 20:16:43 +00:00
|
|
|
/**
|
2013-12-08 07:21:07 +00:00
|
|
|
\brief Return a reference (if available) to the main expression associated with this exception.
|
|
|
|
This information is used to provide better error messages.
|
2013-08-24 20:16:43 +00:00
|
|
|
*/
|
2013-12-08 18:34:38 +00:00
|
|
|
virtual optional<expr> get_main_expr() const { return none_expr(); }
|
2013-10-01 01:38:47 +00:00
|
|
|
virtual format pp(formatter const & fmt, options const & opts) const;
|
2013-11-27 20:19:54 +00:00
|
|
|
virtual exception * clone() const { return new kernel_exception(m_env, m_msg.c_str()); }
|
|
|
|
virtual void rethrow() const { throw *this; }
|
2013-08-16 19:51:12 +00:00
|
|
|
};
|
|
|
|
|
2014-04-18 21:21:49 +00:00
|
|
|
[[ noreturn ]] void throw_kernel_exception(environment const & env, char const * msg, optional<expr> const & m = none_expr());
|
|
|
|
[[ noreturn ]] void throw_kernel_exception(environment const & env, sstream const & strm,
|
2014-02-19 06:55:00 +00:00
|
|
|
optional<expr> const & m = none_expr());
|
2014-04-18 21:21:49 +00:00
|
|
|
[[ noreturn ]] void throw_kernel_exception(environment const & env, char const * msg, optional<expr> const & m, pp_fn const & fn);
|
|
|
|
[[ noreturn ]] void throw_kernel_exception(environment const & env, optional<expr> const & m, pp_fn const & fn);
|
|
|
|
[[ noreturn ]] void throw_kernel_exception(environment const & env, char const * msg, expr const & m, pp_fn const & fn);
|
|
|
|
[[ noreturn ]] void throw_kernel_exception(environment const & env, expr const & m, pp_fn const & fn);
|
|
|
|
[[ noreturn ]] void throw_unknown_declaration(environment const & env, name const & n);
|
|
|
|
[[ noreturn ]] void throw_already_declared(environment const & env, name const & n);
|
2013-08-16 19:51:12 +00:00
|
|
|
}
|