1 //===- TextDiagnosticBuffer.h - Buffer Text Diagnostics ---------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This is a concrete diagnostic client, which buffers the diagnostic messages.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H
14 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H
16 #include "clang/Basic/Diagnostic.h"
17 #include "clang/Basic/SourceLocation.h"
25 class TextDiagnosticBuffer : public DiagnosticConsumer {
27 using DiagList = std::vector<std::pair<SourceLocation, std::string>>;
28 using iterator = DiagList::iterator;
29 using const_iterator = DiagList::const_iterator;
32 DiagList Errors, Warnings, Remarks, Notes;
34 /// All - All diagnostics in the order in which they were generated. That
35 /// order likely doesn't correspond to user input order, but it at least
36 /// keeps notes in the right places. Each pair in the vector is a diagnostic
37 /// level and an index into the corresponding DiagList above.
38 std::vector<std::pair<DiagnosticsEngine::Level, size_t>> All;
41 const_iterator err_begin() const { return Errors.begin(); }
42 const_iterator err_end() const { return Errors.end(); }
44 const_iterator warn_begin() const { return Warnings.begin(); }
45 const_iterator warn_end() const { return Warnings.end(); }
47 const_iterator remark_begin() const { return Remarks.begin(); }
48 const_iterator remark_end() const { return Remarks.end(); }
50 const_iterator note_begin() const { return Notes.begin(); }
51 const_iterator note_end() const { return Notes.end(); }
53 void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
54 const Diagnostic &Info) override;
56 /// FlushDiagnostics - Flush the buffered diagnostics to an given
57 /// diagnostic engine.
58 void FlushDiagnostics(DiagnosticsEngine &Diags) const;
63 #endif // LLVM_CLANG_FRONTEND_TEXTDIAGNOSTICBUFFER_H