clang 10.0.0git

TextDiagnosticBuffer.cpp
Go to the documentation of this file.
1 //===- TextDiagnosticBuffer.cpp - Buffer Text Diagnostics -----------------===//
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, which buffers the diagnostic messages.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #include "clang/Frontend/TextDiagnosticBuffer.h"
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Basic/LLVM.h"
16 #include "llvm/ADT/SmallString.h"
17 #include "llvm/Support/ErrorHandling.h"
18
19 using namespace clang;
20
21 /// HandleDiagnostic - Store the errors, warnings, and notes that are
22 /// reported.
23 void TextDiagnosticBuffer::HandleDiagnostic(DiagnosticsEngine::Level Level,
24 const Diagnostic &Info) {
25 // Default implementation (Warnings/errors count).
26 DiagnosticConsumer::HandleDiagnostic(Level, Info);
27
28 SmallString<100> Buf;
29 Info.FormatDiagnostic(Buf);
30 switch (Level) {
31 default: llvm_unreachable(
32 "Diagnostic not handled during diagnostic buffering!");
33 case DiagnosticsEngine::Note:
34 All.emplace_back(Level, Notes.size());
35 Notes.emplace_back(Info.getLocation(), Buf.str());
36 break;
37 case DiagnosticsEngine::Warning:
38 All.emplace_back(Level, Warnings.size());
39 Warnings.emplace_back(Info.getLocation(), Buf.str());
40 break;
41 case DiagnosticsEngine::Remark:
42 All.emplace_back(Level, Remarks.size());
43 Remarks.emplace_back(Info.getLocation(), Buf.str());
44 break;
45 case DiagnosticsEngine::Error:
46 case DiagnosticsEngine::Fatal:
47 All.emplace_back(Level, Errors.size());
48 Errors.emplace_back(Info.getLocation(), Buf.str());
49 break;
50 }
51 }
52
53 void TextDiagnosticBuffer::FlushDiagnostics(DiagnosticsEngine &Diags) const {
54 for (const auto &I : All) {
55 auto Diag = Diags.Report(Diags.getCustomDiagID(I.first, "%0"));
56 switch (I.first) {
57 default: llvm_unreachable(
58 "Diagnostic not handled during diagnostic flushing!");
59 case DiagnosticsEngine::Note:
60 Diag << Notes[I.second].second;
61 break;
62 case DiagnosticsEngine::Warning:
63 Diag << Warnings[I.second].second;
64 break;
65 case DiagnosticsEngine::Remark:
66 Diag << Remarks[I.second].second;
67 break;
68 case DiagnosticsEngine::Error:
69 case DiagnosticsEngine::Fatal:
70 Diag << Errors[I.second].second;
71 break;
72 }
73 }
74 }
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:77
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:23
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1300
TextDiagnosticBuffer.h
clang::DiagnosticsEngine::Note
Definition: Diagnostic.h:154
clang::Diagnostic::getLocation
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1338
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:34
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:532
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:782
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
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:1327
clang::TextDiagnosticBuffer::FlushDiagnostics
void FlushDiagnostics(DiagnosticsEngine &Diags) const
FlushDiagnostics - Flush the buffered diagnostics to an given diagnostic engine.
Definition: TextDiagnosticBuffer.cpp:53
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:763
clang::prec::Level
Level
Definition: OperatorPrecedence.h:26
clang::DiagnosticsEngine::Fatal
Definition: Diagnostic.h:158