diff options
author | Lang Hames <lhames@gmail.com> | 2016-03-23 23:57:28 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-03-23 23:57:28 +0000 |
commit | e7aad357a95be22a91d4d7d4131fb5fcf49f50ca (patch) | |
tree | 96389cfb0103da5454cd2d5d47077fe0b47f6735 /llvm/lib/Support/Error.cpp | |
parent | ea00b499c703bbdbf4c87573cf2fe5b46a0bf1c2 (diff) | |
download | llvm-e7aad357a95be22a91d4d7d4131fb5fcf49f50ca.zip llvm-e7aad357a95be22a91d4d7d4131fb5fcf49f50ca.tar.gz llvm-e7aad357a95be22a91d4d7d4131fb5fcf49f50ca.tar.bz2 |
[Support] Make all Errors convertible to std::error_code.
This is a temporary crutch to enable code that currently uses std::error_code
to be incrementally moved over to Error. Requiring all Error instances be
convertible enables clients to call errorToErrorCode on any error (not just
ECErrors created by conversion *from* an error_code).
This patch also moves code for Error from ErrorHandling.cpp into a new
Error.cpp file.
llvm-svn: 264221
Diffstat (limited to 'llvm/lib/Support/Error.cpp')
-rw-r--r-- | llvm/lib/Support/Error.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp new file mode 100644 index 0000000..0cf5015 --- /dev/null +++ b/llvm/lib/Support/Error.cpp @@ -0,0 +1,45 @@ +//===----- lib/Support/Error.cpp - Error and associated utilities ---------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/Error.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ManagedStatic.h" + +using namespace llvm; + +namespace { + + enum class ErrorErrorCode { + MultipleErrors + }; + + class ErrorErrorCategory : public std::error_category { + public: + const char *name() const LLVM_NOEXCEPT override { return "Error"; } + + std::string message(int condition) const override { + switch (static_cast<ErrorErrorCode>(condition)) { + case ErrorErrorCode::MultipleErrors: + return "Multiple errors"; + }; + llvm_unreachable("Unhandled error code"); + } + }; + +}; + +void ErrorInfoBase::anchor() {} +char ErrorInfoBase::ID = 0; + +static ManagedStatic<ErrorErrorCategory> ErrorErrorCat; + +std::error_code ErrorList::convertToErrorCode() const { + return std::error_code(static_cast<int>(ErrorErrorCode::MultipleErrors), + *ErrorErrorCat); +} |