clang: lib/Frontend/LogDiagnosticPrinter.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
14#include "llvm/ADT/SmallString.h"
15#include "llvm/Support/ErrorHandling.h"
16#include "llvm/Support/raw_ostream.h"
17using namespace clang;
18using namespace markup;
19
22 std::unique_ptr<raw_ostream> StreamOwner)
23 : OS(os), StreamOwner(std::move(StreamOwner)), LangOpts(nullptr),
24 DiagOpts(diags) {}
25
27 switch (Level) {
34 }
35 llvm_unreachable("Invalid DiagnosticsEngine level!");
36}
37
38void
39LogDiagnosticPrinter::EmitDiagEntry(llvm::raw_ostream &OS,
40 const LogDiagnosticPrinter::DiagEntry &DE) {
41 OS << " \n";
42 OS << " level\n"
43 << " ";
45 if (!DE.Filename.empty()) {
46 OS << " filename\n"
47 << " ";
49 }
50 if (DE.Line != 0) {
51 OS << " line\n"
52 << " ";
54 }
55 if (DE.Column != 0) {
56 OS << " column\n"
57 << " ";
59 }
60 if (!DE.Message.empty()) {
61 OS << " message\n"
62 << " ";
64 }
65 OS << " ID\n"
66 << " ";
68 if (!DE.WarningOption.empty()) {
69 OS << " WarningOption\n"
70 << " ";
71 EmitString(OS, DE.WarningOption) << '\n';
72 }
73 OS << " \n";
74}
75
77
78
79
80
81
82
83 if (Entries.empty())
84 return;
85
86
88 llvm::raw_svector_ostream OS(Msg);
89
90 OS << "\n";
91 if (!MainFilename.empty()) {
92 OS << " main-file\n"
93 << " ";
95 }
96 if (!DwarfDebugFlags.empty()) {
97 OS << " dwarf-debug-flags\n"
98 << " ";
99 EmitString(OS, DwarfDebugFlags) << '\n';
100 }
101 OS << " diagnostics\n";
102 OS << " \n";
103 for (auto &DE : Entries)
104 EmitDiagEntry(OS, DE);
105 OS << " \n";
106 OS << "\n";
107
108 this->OS << OS.str();
109}
110
113
115
116
119 FileID FID = SM.getMainFileID();
122 MainFilename = std::string(FE->getName());
123 }
124 }
125
126
127 DiagEntry DE;
128 DE.DiagnosticID = Info.getID();
129 DE.DiagnosticLevel = Level;
130
131 DE.WarningOption =
133
134
137 DE.Message = std::string(MessageStr);
138
139
140 DE.Filename = "";
141 DE.Line = DE.Column = 0;
145
147
151 DE.Filename = std::string(FE->getName());
152 }
153 } else {
155 DE.Line = PLoc.getLine();
157 }
158 }
159
160
161 Entries.push_back(DE);
162}
163
Defines the clang::FileManager interface and associated types.
static StringRef getLevelName(DiagnosticsEngine::Level Level)
Defines the SourceManager interface.
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.
static StringRef getWarningOptionForDiag(unsigned DiagID)
Return the lowest-level warning option that enables the specified diagnostic.
Options for controlling the compiler diagnostics engine.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine a...
const SourceLocation & getLocation() const
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots.
SourceManager & getSourceManager() const
bool hasSourceManager() const
Level
The level of the diagnostic, after it has been through mapping.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags, std::unique_ptr< raw_ostream > StreamOwner)
void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, const Diagnostic &Info) override
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
void EndSourceFile() override
Callback to inform the diagnostic client that processing of a source file has ended.
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
raw_ostream & EmitString(raw_ostream &o, StringRef s)
raw_ostream & EmitInteger(raw_ostream &o, int64_t value)
The JSON file list parser is used to communicate input to InstallAPI.