diff options
author | Lang Hames <lhames@gmail.com> | 2016-04-05 18:50:09 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2016-04-05 18:50:09 +0000 |
commit | bbdccbe963363e174d52fc9d9a3d1691e09229f6 (patch) | |
tree | 7fe6890487d3af13f218eec6e07a2c9277eb9da3 | |
parent | 072772bf05783f198daed64dc937e6eea16bc83a (diff) | |
download | bcm5719-llvm-bbdccbe963363e174d52fc9d9a3d1691e09229f6.tar.gz bcm5719-llvm-bbdccbe963363e174d52fc9d9a3d1691e09229f6.zip |
[Support] clang-format Error.h.
This tidies up the ExitOnError class and some other recently added code. NFC.
llvm-svn: 265438
-rw-r--r-- | llvm/include/llvm/Support/Error.h | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/llvm/include/llvm/Support/Error.h b/llvm/include/llvm/Support/Error.h index 304925c6ba7..fb17a0dbe8a 100644 --- a/llvm/include/llvm/Support/Error.h +++ b/llvm/include/llvm/Support/Error.h @@ -571,6 +571,7 @@ public: if (!Err) Err = Error::success(); } + private: Error &Err; }; @@ -776,24 +777,21 @@ inline Error errorCodeToError(std::error_code EC) { /// will trigger a call to abort(). inline std::error_code errorToErrorCode(Error Err) { std::error_code EC; - handleAllErrors(std::move(Err), - [&](const ErrorInfoBase &EI) { - EC = EI.convertToErrorCode(); - }); + handleAllErrors(std::move(Err), [&](const ErrorInfoBase &EI) { + EC = EI.convertToErrorCode(); + }); return EC; } /// Convert an ErrorOr<T> to an Expected<T>. -template <typename T> -Expected<T> errorOrToExpected(ErrorOr<T> &&EO) { +template <typename T> Expected<T> errorOrToExpected(ErrorOr<T> &&EO) { if (auto EC = EO.getError()) return errorCodeToError(EC); return std::move(*EO); } /// Convert an Expected<T> to an ErrorOr<T>. -template <typename T> -ErrorOr<T> expectedToErrorOr(Expected<T> &&E) { +template <typename T> ErrorOr<T> expectedToErrorOr(Expected<T> &&E) { if (auto Err = E.takeError()) return errorToErrorCode(std::move(Err)); return std::move(*E); @@ -805,37 +803,30 @@ ErrorOr<T> expectedToErrorOr(Expected<T> &&E) { /// class ExitOnError { public: - /// Create an error on exit helper. ExitOnError(std::string Banner = "", int DefaultErrorExitCode = 1) - : Banner(std::move(Banner)), - GetExitCode([=](const Error&) { return DefaultErrorExitCode; }) {} + : Banner(std::move(Banner)), + GetExitCode([=](const Error &) { return DefaultErrorExitCode; }) {} /// Set the banner string for any errors caught by operator(). - void setBanner(std::string Banner) { - this->Banner = std::move(Banner); - } + void setBanner(std::string Banner) { this->Banner = std::move(Banner); } /// Set the exit-code mapper function. - void setExitCodeMapper(std::function<int(const Error&)> GetExitCode) { + void setExitCodeMapper(std::function<int(const Error &)> GetExitCode) { this->GetExitCode = std::move(GetExitCode); } /// Check Err. If it's in a failure state log the error(s) and exit. - void operator()(Error Err) const { - checkError(std::move(Err)); - } + void operator()(Error Err) const { checkError(std::move(Err)); } /// Check E. If it's in a success state return the contained value. If it's /// in a failure state log the error(s) and exit. - template <typename T> - T operator()(Expected<T> &&E) const { + template <typename T> T operator()(Expected<T> &&E) const { checkError(E.takeError()); return std::move(*E); } private: - void checkError(Error Err) const { if (Err) { int ExitCode = GetExitCode(Err); @@ -845,7 +836,7 @@ private: } std::string Banner; - std::function<int(const Error&)> GetExitCode; + std::function<int(const Error &)> GetExitCode; }; } // namespace llvm |