2021-04-11 00:02:56 +01:00
|
|
|
/* -*- C++ -*-
|
2021-10-12 20:51:03 +01:00
|
|
|
* Serene Programming Language
|
2021-04-11 00:02:56 +01:00
|
|
|
*
|
2022-01-27 11:44:44 +00:00
|
|
|
* Copyright (c) 2019-2022 Sameer Rahmani <lxsameer@gnu.org>
|
2021-04-11 00:02:56 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 2.
|
2021-04-11 00:02:56 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2021-04-11 00:02:56 +01:00
|
|
|
*
|
2021-10-12 20:51:03 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2021-04-11 00:02:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SERENE_ERRORS_H
|
|
|
|
#define SERENE_ERRORS_H
|
|
|
|
|
2022-02-04 22:47:01 +00:00
|
|
|
#include "serene/errors/base.h"
|
2021-04-11 00:02:56 +01:00
|
|
|
#include "serene/errors/errc.h"
|
2022-03-08 15:58:02 +00:00
|
|
|
#include "serene/export.h"
|
2022-03-08 13:19:34 +00:00
|
|
|
|
2022-03-08 17:38:02 +00:00
|
|
|
#include <llvm/Support/Casting.h>
|
2022-02-04 22:47:01 +00:00
|
|
|
#include <llvm/Support/Error.h>
|
|
|
|
|
2022-03-10 19:31:48 +00:00
|
|
|
namespace serene {
|
|
|
|
class SereneContext;
|
|
|
|
} // namespace serene
|
|
|
|
|
2022-02-04 22:47:01 +00:00
|
|
|
namespace serene::errors {
|
|
|
|
|
2022-03-08 13:19:34 +00:00
|
|
|
/// Create and return a Serene flavored `llvm::Error` by passing the parameters
|
|
|
|
/// directly to the constructor of type `E`.
|
|
|
|
///
|
|
|
|
/// This is the official way of creating error objects in Serene.
|
2022-03-10 19:31:48 +00:00
|
|
|
template <typename... Args>
|
|
|
|
SERENE_EXPORT llvm::Error makeError(SereneContext &ctx, ErrorType errtype,
|
|
|
|
Args &&...args) {
|
|
|
|
return llvm::make_error<Error>(ctx, errtype, std::forward<Args>(args)...);
|
2022-02-04 22:47:01 +00:00
|
|
|
};
|
|
|
|
|
2022-03-10 19:31:48 +00:00
|
|
|
/// Returns the messange that the given error \p e is holding. It doesn't cast
|
|
|
|
/// the error to a concrete error type.
|
2022-03-08 17:38:02 +00:00
|
|
|
SERENE_EXPORT std::string getMessage(const llvm::Error &e);
|
2022-03-10 19:31:48 +00:00
|
|
|
|
|
|
|
SERENE_EXPORT const ErrorVariant *getVariant(ErrorType t);
|
2022-02-04 22:47:01 +00:00
|
|
|
} // namespace serene::errors
|
2021-04-11 00:02:56 +01:00
|
|
|
|
|
|
|
#endif
|