clang  6.0.0svn
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 
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/Support/ErrorHandling.h"
17 using namespace clang;
18 
19 /// HandleDiagnostic - Store the errors, warnings, and notes that are
20 /// reported.
21 ///
23  const Diagnostic &Info) {
24  // Default implementation (Warnings/errors count).
26 
27  SmallString<100> Buf;
28  Info.FormatDiagnostic(Buf);
29  switch (Level) {
30  default: llvm_unreachable(
31  "Diagnostic not handled during diagnostic buffering!");
33  All.emplace_back(Level, Notes.size());
34  Notes.emplace_back(Info.getLocation(), Buf.str());
35  break;
37  All.emplace_back(Level, Warnings.size());
38  Warnings.emplace_back(Info.getLocation(), Buf.str());
39  break;
41  All.emplace_back(Level, Remarks.size());
42  Remarks.emplace_back(Info.getLocation(), Buf.str());
43  break;
46  All.emplace_back(Level, Errors.size());
47  Errors.emplace_back(Info.getLocation(), Buf.str());
48  break;
49  }
50 }
51 
53  for (auto it = All.begin(), ie = All.end(); it != ie; ++it) {
54  auto Diag = Diags.Report(Diags.getCustomDiagID(it->first, "%0"));
55  switch (it->first) {
56  default: llvm_unreachable(
57  "Diagnostic not handled during diagnostic flushing!");
59  Diag << Notes[it->second].second;
60  break;
62  Diag << Warnings[it->second].second;
63  break;
65  Diag << Remarks[it->second].second;
66  break;
69  Diag << Errors[it->second].second;
70  break;
71  }
72  }
73 }
74 
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.
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
HandleDiagnostic - Store the errors, warnings, and notes that are reported.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1207
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1238
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:147
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:435
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:691
Dataflow Directional Tag Classes.
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:150
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1227
void FlushDiagnostics(DiagnosticsEngine &Diags) const
FlushDiagnostics - Flush the buffered diagnostics to an given diagnostic engine.
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots...
Definition: Diagnostic.cpp:667