1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #ifndef LLVM_CLANG_BASIC_DIAGNOSTIC_ERROR_H |
10 | #define LLVM_CLANG_BASIC_DIAGNOSTIC_ERROR_H |
11 | |
12 | #include "clang/Basic/PartialDiagnostic.h" |
13 | #include "llvm/Support/Error.h" |
14 | |
15 | namespace clang { |
16 | |
17 | |
18 | |
19 | |
20 | class DiagnosticError : public llvm::ErrorInfo<DiagnosticError> { |
21 | public: |
22 | DiagnosticError(PartialDiagnosticAt Diag) : Diag(std::move(Diag)) {} |
23 | |
24 | void log(raw_ostream &OS) const override { OS << "clang diagnostic"; } |
25 | |
26 | PartialDiagnosticAt &getDiagnostic() { return Diag; } |
27 | const PartialDiagnosticAt &getDiagnostic() const { return Diag; } |
28 | |
29 | |
30 | |
31 | static llvm::Error create(SourceLocation Loc, PartialDiagnostic Diag) { |
32 | return llvm::make_error<DiagnosticError>( |
33 | PartialDiagnosticAt(Loc, std::move(Diag))); |
34 | } |
35 | |
36 | |
37 | |
38 | |
39 | static Optional<PartialDiagnosticAt> take(llvm::Error &Err) { |
40 | Optional<PartialDiagnosticAt> Result; |
41 | Err = llvm::handleErrors(std::move(Err), [&](DiagnosticError &E) { |
42 | Result = std::move(E.getDiagnostic()); |
43 | }); |
44 | return Result; |
45 | } |
46 | |
47 | static char ID; |
48 | |
49 | private: |
50 | |
51 | std::error_code convertToErrorCode() const override { |
52 | return llvm::inconvertibleErrorCode(); |
53 | } |
54 | |
55 | PartialDiagnosticAt Diag; |
56 | }; |
57 | |
58 | } |
59 | |
60 | #endif |
61 | |