Warning: This file is not a C or C++ file. It does not have highlighting.
1 | //===- TextDiagnosticBuffer.h - Buffer Text Diagnostics ---------*- C++ -*-===// |
---|---|
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | // |
9 | // This is a concrete diagnostic client. The diagnostics are buffered rather |
10 | // than printed. In order to print them, use the FlushDiagnostics method. |
11 | // Pretty-printing is not supported. |
12 | // |
13 | //===----------------------------------------------------------------------===// |
14 | // |
15 | // Coding style: https://mlir.llvm.org/getting_started/DeveloperGuide/ |
16 | // |
17 | //===----------------------------------------------------------------------===// |
18 | |
19 | #ifndef FORTRAN_FRONTEND_TEXTDIAGNOSTICBUFFER_H |
20 | #define FORTRAN_FRONTEND_TEXTDIAGNOSTICBUFFER_H |
21 | |
22 | #include "clang/Basic/Diagnostic.h" |
23 | #include "clang/Basic/SourceLocation.h" |
24 | #include <cstddef> |
25 | #include <string> |
26 | #include <utility> |
27 | #include <vector> |
28 | |
29 | namespace Fortran::frontend { |
30 | |
31 | class TextDiagnosticBuffer : public clang::DiagnosticConsumer { |
32 | public: |
33 | using DiagList = std::vector<std::pair<clang::SourceLocation, std::string>>; |
34 | using DiagnosticsLevelAndIndexPairs = |
35 | std::vector<std::pair<clang::DiagnosticsEngine::Level, size_t>>; |
36 | |
37 | private: |
38 | DiagList errors, warnings, remarks, notes; |
39 | |
40 | /// All diagnostics in the order in which they were generated. That order |
41 | /// likely doesn't correspond to user input order, but at least it keeps |
42 | /// notes in the right places. Each pair is a diagnostic level and an index |
43 | /// into the corresponding DiagList above. |
44 | DiagnosticsLevelAndIndexPairs all; |
45 | |
46 | public: |
47 | void HandleDiagnostic(clang::DiagnosticsEngine::Level diagLevel, |
48 | const clang::Diagnostic &info) override; |
49 | |
50 | /// Flush the buffered diagnostics to a given diagnostic engine. |
51 | void flushDiagnostics(clang::DiagnosticsEngine &diags) const; |
52 | }; |
53 | |
54 | } // namespace Fortran::frontend |
55 | |
56 | #endif // FORTRAN_FRONTEND_TEXTDIAGNOSTICBUFFER_H |
57 |
Warning: This file is not a C or C++ file. It does not have highlighting.