Martin Brænne | 198ff49 | 2023-04-05 01:41:25 -0700 | [diff] [blame] | 1 | // Part of the Crubit project, under the Apache License v2.0 with LLVM |
| 2 | // Exceptions. See /LICENSE for license information. |
| 3 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | |
Dmitri Gribenko | efc8664 | 2023-07-10 04:49:39 -0700 | [diff] [blame] | 5 | #ifndef CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_ERROR_H_ |
| 6 | #define CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_ERROR_H_ |
Martin Brænne | 198ff49 | 2023-04-05 01:41:25 -0700 | [diff] [blame] | 7 | |
Dmitri Gribenko | a087d23 | 2023-07-10 08:03:46 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <system_error> |
| 10 | #include <utility> |
| 11 | |
Martin Brænne | 198ff49 | 2023-04-05 01:41:25 -0700 | [diff] [blame] | 12 | #include "llvm/Support/Error.h" |
Dmitri Gribenko | a087d23 | 2023-07-10 08:03:46 -0700 | [diff] [blame] | 13 | #include "llvm/Support/raw_ostream.h" |
Martin Brænne | 198ff49 | 2023-04-05 01:41:25 -0700 | [diff] [blame] | 14 | |
| 15 | namespace clang { |
| 16 | namespace tidy { |
| 17 | namespace lifetimes { |
| 18 | |
| 19 | // Error information for errors that originate in the `lifetime_analysis` |
| 20 | // package. |
| 21 | class LifetimeError : public llvm::ErrorInfo<LifetimeError> { |
| 22 | public: |
| 23 | enum class Type { |
| 24 | ElisionNotEnabled, |
| 25 | CannotElideOutputLifetimes, |
| 26 | Other, |
| 27 | }; |
| 28 | |
| 29 | LifetimeError(Type type, std::string message) |
| 30 | : type_(type), message_(std::move(message)) {} |
| 31 | |
| 32 | Type type() const { return type_; } |
| 33 | |
| 34 | void log(llvm::raw_ostream& OS) const override { OS << message_; } |
| 35 | |
| 36 | std::error_code convertToErrorCode() const override { |
| 37 | return llvm::inconvertibleErrorCode(); |
| 38 | } |
| 39 | |
| 40 | static char ID; |
| 41 | |
| 42 | private: |
| 43 | Type type_; |
| 44 | std::string message_; |
| 45 | }; |
| 46 | |
| 47 | } // namespace lifetimes |
| 48 | } // namespace tidy |
| 49 | } // namespace clang |
| 50 | |
Dmitri Gribenko | efc8664 | 2023-07-10 04:49:39 -0700 | [diff] [blame] | 51 | #endif // CRUBIT_LIFETIME_ANNOTATIONS_LIFETIME_ERROR_H_ |