diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
| commit | d8e91e46262bc44006913e6796843909f1ac7bcd (patch) | |
| tree | 7d0c143d9b38190e0fa0180805389da22cd834c5 /lib/Support/Error.cpp | |
| parent | b7eb8e35e481a74962664b63dfb09483b200209a (diff) | |
Notes
Diffstat (limited to 'lib/Support/Error.cpp')
| -rw-r--r-- | lib/Support/Error.cpp | 47 |
1 files changed, 44 insertions, 3 deletions
diff --git a/lib/Support/Error.cpp b/lib/Support/Error.cpp index 83345bf6edb9..30bfc3e6d2fb 100644 --- a/lib/Support/Error.cpp +++ b/lib/Support/Error.cpp @@ -19,6 +19,7 @@ namespace { enum class ErrorErrorCode : int { MultipleErrors = 1, + FileError, InconvertibleError }; @@ -37,6 +38,8 @@ namespace { return "Inconvertible error value. An error has occurred that could " "not be converted to a known std::error_code. Please file a " "bug."; + case ErrorErrorCode::FileError: + return "A file error occurred."; } llvm_unreachable("Unhandled error code"); } @@ -51,8 +54,10 @@ namespace llvm { void ErrorInfoBase::anchor() {} char ErrorInfoBase::ID = 0; char ErrorList::ID = 0; +void ECError::anchor() {} char ECError::ID = 0; char StringError::ID = 0; +char FileError::ID = 0; void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner) { if (!E) @@ -75,6 +80,11 @@ std::error_code inconvertibleErrorCode() { *ErrorErrorCat); } +std::error_code FileError::convertToErrorCode() const { + return std::error_code(static_cast<int>(ErrorErrorCode::FileError), + *ErrorErrorCat); +} + Error errorCodeToError(std::error_code EC) { if (!EC) return Error::success(); @@ -103,10 +113,21 @@ void Error::fatalUncheckedError() const { } #endif -StringError::StringError(const Twine &S, std::error_code EC) +StringError::StringError(std::error_code EC, const Twine &S) : Msg(S.str()), EC(EC) {} -void StringError::log(raw_ostream &OS) const { OS << Msg; } +StringError::StringError(const Twine &S, std::error_code EC) + : Msg(S.str()), EC(EC), PrintMsgOnly(true) {} + +void StringError::log(raw_ostream &OS) const { + if (PrintMsgOnly) { + OS << Msg; + } else { + OS << EC.message(); + if (!Msg.empty()) + OS << (" " + Msg); + } +} std::error_code StringError::convertToErrorCode() const { return EC; @@ -121,11 +142,31 @@ void report_fatal_error(Error Err, bool GenCrashDiag) { std::string ErrMsg; { raw_string_ostream ErrStream(ErrMsg); - logAllUnhandledErrors(std::move(Err), ErrStream, ""); + logAllUnhandledErrors(std::move(Err), ErrStream); } report_fatal_error(ErrMsg); } +} // end namespace llvm + +LLVMErrorTypeId LLVMGetErrorTypeId(LLVMErrorRef Err) { + return reinterpret_cast<ErrorInfoBase *>(Err)->dynamicClassID(); +} + +void LLVMConsumeError(LLVMErrorRef Err) { consumeError(unwrap(Err)); } + +char *LLVMGetErrorMessage(LLVMErrorRef Err) { + std::string Tmp = toString(unwrap(Err)); + char *ErrMsg = new char[Tmp.size() + 1]; + memcpy(ErrMsg, Tmp.data(), Tmp.size()); + ErrMsg[Tmp.size()] = '\0'; + return ErrMsg; +} + +void LLVMDisposeErrorMessage(char *ErrMsg) { delete[] ErrMsg; } + +LLVMErrorTypeId LLVMGetStringErrorTypeId() { + return reinterpret_cast<void *>(&StringError::ID); } #ifndef _MSC_VER |
