From e7aad357a95be22a91d4d7d4131fb5fcf49f50ca Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Wed, 23 Mar 2016 23:57:28 +0000 Subject: [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 --- llvm/lib/Support/CMakeLists.txt | 1 + llvm/lib/Support/Error.cpp | 45 ++++++++++++++++++++++++++++++++++++++ llvm/lib/Support/ErrorHandling.cpp | 3 --- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 llvm/lib/Support/Error.cpp (limited to 'llvm/lib/Support') diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index d14d7d305fd..98108e54cf2 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -48,6 +48,7 @@ add_llvm_library(LLVMSupport DeltaAlgorithm.cpp DAGDeltaAlgorithm.cpp Dwarf.cpp + Error.cpp ErrorHandling.cpp FileUtilities.cpp FileOutputBuffer.cpp diff --git a/llvm/lib/Support/Error.cpp b/llvm/lib/Support/Error.cpp new file mode 100644 index 00000000000..0cf50153c0e --- /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(condition)) { + case ErrorErrorCode::MultipleErrors: + return "Multiple errors"; + }; + llvm_unreachable("Unhandled error code"); + } + }; + +}; + +void ErrorInfoBase::anchor() {} +char ErrorInfoBase::ID = 0; + +static ManagedStatic ErrorErrorCat; + +std::error_code ErrorList::convertToErrorCode() const { + return std::error_code(static_cast(ErrorErrorCode::MultipleErrors), + *ErrorErrorCat); +} diff --git a/llvm/lib/Support/ErrorHandling.cpp b/llvm/lib/Support/ErrorHandling.cpp index c743d388887..a7d3a18003e 100644 --- a/llvm/lib/Support/ErrorHandling.cpp +++ b/llvm/lib/Support/ErrorHandling.cpp @@ -139,9 +139,6 @@ void LLVMResetFatalErrorHandler() { remove_fatal_error_handler(); } -void ErrorInfoBase::anchor() {} -char ErrorInfoBase::ID = 0; - #ifdef LLVM_ON_WIN32 #include -- cgit v1.2.3