2013-10-01 01:38:47 +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
|
|
|
|
*/
|
|
|
|
#include <vector>
|
2014-02-19 06:55:00 +00:00
|
|
|
#include <string>
|
|
|
|
#include "util/sstream.h"
|
2013-10-01 01:38:47 +00:00
|
|
|
#include "kernel/kernel_exception.h"
|
|
|
|
|
|
|
|
namespace lean {
|
2014-02-19 06:55:00 +00:00
|
|
|
format kernel_exception::pp(formatter const &, options const &) const { return format(what()); }
|
|
|
|
|
|
|
|
class generic_kernel_exception : public kernel_exception {
|
|
|
|
protected:
|
|
|
|
optional<expr> m_main_expr;
|
|
|
|
pp_fn m_pp_fn;
|
|
|
|
public:
|
|
|
|
generic_kernel_exception(ro_environment const & env, char const * msg, optional<expr> const & m, pp_fn const & fn):
|
|
|
|
kernel_exception(env, msg),
|
|
|
|
m_main_expr(m),
|
|
|
|
m_pp_fn(fn) {}
|
|
|
|
virtual ~generic_kernel_exception() noexcept {}
|
|
|
|
virtual optional<expr> get_main_expr() const { return m_main_expr; }
|
|
|
|
virtual format pp(formatter const & fmt, options const & opts) const { return m_pp_fn(fmt, opts); }
|
|
|
|
virtual exception * clone() const { return new generic_kernel_exception(m_env, m_msg.c_str(), m_main_expr, m_pp_fn); }
|
|
|
|
virtual void rethrow() const { throw *this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
[[ noreturn ]] void throw_kernel_exception(ro_environment const & env, char const * msg, optional<expr> const & m) {
|
|
|
|
std::string msg_str = msg;
|
|
|
|
throw generic_kernel_exception(env, msg, m, [=](formatter const &, options const &) { return format(msg); });
|
2013-10-01 01:38:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-19 06:55:00 +00:00
|
|
|
[[ noreturn ]] void throw_kernel_exception(ro_environment const & env, sstream const & strm, optional<expr> const & m) {
|
|
|
|
throw_kernel_exception(env, strm.str().c_str(), m);
|
|
|
|
}
|
|
|
|
|
2014-02-25 00:30:56 +00:00
|
|
|
[[ noreturn ]] void throw_kernel_exception(ro_environment const & env, char const * msg, optional<expr> const & m, pp_fn const & fn) {
|
2014-02-19 06:55:00 +00:00
|
|
|
throw generic_kernel_exception(env, msg, m, fn);
|
|
|
|
}
|
|
|
|
|
2014-02-25 00:30:56 +00:00
|
|
|
[[ noreturn ]] void throw_kernel_exception(ro_environment const & env, optional<expr> const & m, pp_fn const & fn) {
|
2014-02-19 06:55:00 +00:00
|
|
|
throw generic_kernel_exception(env, "kernel exception", m, fn);
|
|
|
|
}
|
|
|
|
|
2014-02-25 00:30:56 +00:00
|
|
|
[[ noreturn ]] void throw_kernel_exception(ro_environment const & env, char const * msg, expr const & m, pp_fn const & fn) {
|
|
|
|
throw_kernel_exception(env, msg, some_expr(m), fn);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[ noreturn ]] void throw_kernel_exception(ro_environment const & env, expr const & m, pp_fn const & fn) {
|
|
|
|
throw_kernel_exception(env, some_expr(m), fn);
|
|
|
|
}
|
|
|
|
|
2014-02-19 06:55:00 +00:00
|
|
|
[[ noreturn ]] void throw_unknown_object(ro_environment const & env, name const & n) {
|
|
|
|
throw_kernel_exception(env, sstream() << "unknown object '" << n << "'");
|
2013-10-01 01:38:47 +00:00
|
|
|
}
|
|
|
|
|
2014-02-19 06:55:00 +00:00
|
|
|
[[ noreturn ]] void throw_already_declared(ro_environment const & env, name const & n) {
|
|
|
|
throw_kernel_exception(env, sstream() << "invalid object declaration, environment already has an object named '" << n << "'");
|
|
|
|
}
|
|
|
|
|
|
|
|
[[ noreturn ]] void throw_read_only_environment(ro_environment const & env) {
|
|
|
|
throw_kernel_exception(env, "environment cannot be updated because it has children environments");
|
|
|
|
}
|
2013-10-01 01:38:47 +00:00
|
|
|
}
|