clang 8.0.0

TextDiagnosticBuffer.cpp
Go to the documentation of this file.
1 //===- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics -----------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This is a concrete diagnostic client, which buffers the diagnostic messages.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/Frontend/TextDiagnosticBuffer.h"
15 #include "clang/Basic/Diagnostic.h"
16 #include "clang/Basic/LLVM.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/Support/ErrorHandling.h"
19
20 using namespace clang;
21
22 /// HandleDiagnostic - Store the errors, warnings, and notes that are
23 /// reported.
24 void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
25 const Diagnostic &Info) {
26 // Default implementation (Warnings/errors count).
27 DiagnosticConsumer::HandleDiagnostic(Level, Info);
28
29 SmallString<100> Buf;
30 Info.FormatDiagnostic(Buf);
31 switch (Level) {
32 default: llvm_unreachable(
33 "Diagnostic not handled during diagnostic buffering!");
34 case DiagnosticsEngine::Note:
35 All.emplace_back(Level, Notes.size());
36 Notes.emplace_back(Info.getLocation(), Buf.str());
37 break;
38 case DiagnosticsEngine::Warning:
39 All.emplace_back(Level, Warnings.size());
40 Warnings.emplace_back(Info.getLocation(), Buf.str());
41 break;
42 case DiagnosticsEngine::Remark:
43 All.emplace_back(Level, Remarks.size());
44 Remarks.emplace_back(Info.getLocation(), Buf.str());
45 break;
46 case DiagnosticsEngine::Error:
47 case DiagnosticsEngine::Fatal:
48 All.emplace_back(Level, Errors.size());
49 Errors.emplace_back(Info.getLocation(), Buf.str());
50 break;
51 }
52 }
53
54 void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
55 for (const auto &I : All) {
56 auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0"));
57 switch (I.first) {
58 default: llvm_unreachable(
59 "Diagnostic not handled during diagnostic flushing!");
60 case DiagnosticsEngine::Note:
61 Diag << Notes[I.second].second;
62 break;
63 case DiagnosticsEngine::Warning:
64 Diag << Warnings[I.second].second;
65 break;
66 case DiagnosticsEngine::Remark:
67 Diag << Remarks[I.second].second;
68 break;
69 case DiagnosticsEngine::Error:
70 case DiagnosticsEngine::Fatal:
71 Diag << Errors[I.second].second;
72 break;
73 }
74 }
75 }
Diag
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
Definition: LiteralSupport.cpp:78
clang::TextDiagnosticBuffer::HandleDiagnostic
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
HandleDiagnostic - Store the errors, warnings, and notes that are reported.
Definition: TextDiagnosticBuffer.cpp:24
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1295
TextDiagnosticBuffer.h
clang::DiagnosticsEngine::Note
Definition: Diagnostic.h:154
clang::Diagnostic::getLocation
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1327
LLVM.h
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
Diagnostic.h
Defines the Diagnostic-related interfaces.
llvm::SmallString
Definition: LLVM.h:35
clang::DiagnosticsEngine::Remark
Definition: Diagnostic.h:155
clang::DiagnosticConsumer::HandleDiagnostic
virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info)
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
Definition: Diagnostic.cpp:533
clang::DiagnosticsEngine::getCustomDiagID
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:776
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::DiagnosticsEngine::Warning
Definition: Diagnostic.h:156
clang::DiagnosticsEngine::Error
Definition: Diagnostic.h:157
clang::DiagnosticsEngine::Level
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:152
clang::Diagnostic
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1316
clang::TextDiagnosticBuffer::FlushDiagnostics
void FlushDiagnostics(DiagnosticsEngine &Diags) const
FlushDiagnostics - Flush the buffered diagnostics to an given diagnostic engine.
Definition: TextDiagnosticBuffer.cpp:54
clang::Diagnostic::FormatDiagnostic
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots...
Definition: Diagnostic.cpp:764
clang::prec::Level
Level
Definition: OperatorPrecedence.h:27
clang::DiagnosticsEngine::Fatal
Definition: Diagnostic.h:158