clang  7.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 "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.
25  const Diagnostic &Info) {
26  // Default implementation (Warnings/errors count).
28 
29  SmallString<100> Buf;
30  Info.FormatDiagnostic(Buf);
31  switch (Level) {
32  default: llvm_unreachable(
33  "Diagnostic not handled during diagnostic buffering!");
35  All.emplace_back(Level, Notes.size());
36  Notes.emplace_back(Info.getLocation(), Buf.str());
37  break;
39  All.emplace_back(Level, Warnings.size());
40  Warnings.emplace_back(Info.getLocation(), Buf.str());
41  break;
43  All.emplace_back(Level, Remarks.size());
44  Remarks.emplace_back(Info.getLocation(), Buf.str());
45  break;
48  All.emplace_back(Level, Errors.size());
49  Errors.emplace_back(Info.getLocation(), Buf.str());
50  break;
51  }
52 }
53 
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!");
61  Diag << Notes[I.second].second;
62  break;
64  Diag << Warnings[I.second].second;
65  break;
67  Diag << Remarks[I.second].second;
68  break;
71  Diag << Errors[I.second].second;
72  break;
73  }
74  }
75 }
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:1294
const SourceLocation & getLocation() const
Definition: Diagnostic.h:1326
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
Defines the Diagnostic-related interfaces.
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:525
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Definition: Diagnostic.h:775
Dataflow Directional Tag Classes.
Level
The level of the diagnostic, after it has been through mapping.
Definition: Diagnostic.h:152
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
Definition: Diagnostic.h:1315
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:756