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 #ifndef LLVM_FLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H 16 #define LLVM_FLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H 17 18 #include "clang/Basic/Diagnostic.h" 19 #include "clang/Basic/SourceLocation.h" 20 #include <cstddef> 21 #include <string> 22 #include <utility> 23 #include <vector> 24 25 namespace Fortran::frontend { 26 27 class TextDiagnosticBuffer : public clang::DiagnosticConsumer { 28 public: 29 using DiagList = std::vector<std::pair<clang::SourceLocation, std::string>>; 30 using DiagnosticsLevelAndIndexPairs = 31 std::vector<std::pair<clang::DiagnosticsEngine::Level, size_t>>; 32 33 private: 34 DiagList errors_, warnings_, remarks_, notes_; 35 36 /// All diagnostics in the order in which they were generated. That order 37 /// likely doesn't correspond to user input order, but at least it keeps 38 /// notes in the right places. Each pair is a diagnostic level and an index 39 /// into the corresponding DiagList above. 40 DiagnosticsLevelAndIndexPairs all_; 41 42 public: 43 void HandleDiagnostic(clang::DiagnosticsEngine::Level diagLevel, 44 const clang::Diagnostic &info) override; 45 46 /// Flush the buffered diagnostics to a given diagnostic engine. 47 void FlushDiagnostics(clang::DiagnosticsEngine &diags) const; 48 }; 49 50 } // namespace Fortran::frontend 51 52 #endif // LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H 53