15 #include "llvm/ADT/SmallString.h" 16 #include "llvm/Support/ErrorHandling.h" 17 #include "llvm/Support/raw_ostream.h" 18 using namespace clang;
23 std::unique_ptr<raw_ostream> StreamOwner)
24 : OS(os), StreamOwner(
std::move(StreamOwner)), LangOpts(nullptr),
36 llvm_unreachable(
"Invalid DiagnosticsEngine level!");
40 LogDiagnosticPrinter::EmitDiagEntry(llvm::raw_ostream &OS,
41 const LogDiagnosticPrinter::DiagEntry &DE) {
43 OS <<
" <key>level</key>\n" 46 if (!DE.Filename.empty()) {
47 OS <<
" <key>filename</key>\n" 52 OS <<
" <key>line</key>\n" 57 OS <<
" <key>column</key>\n" 61 if (!DE.Message.empty()) {
62 OS <<
" <key>message</key>\n" 66 OS <<
" <key>ID</key>\n" 69 if (!DE.WarningOption.empty()) {
70 OS <<
" <key>WarningOption</key>\n" 89 llvm::raw_svector_ostream OS(Msg);
92 if (!MainFilename.empty()) {
93 OS <<
" <key>main-file</key>\n" 97 if (!DwarfDebugFlags.empty()) {
98 OS <<
" <key>dwarf-debug-flags</key>\n" 102 OS <<
" <key>diagnostics</key>\n";
104 for (
auto &DE : Entries)
105 EmitDiagEntry(OS, DE);
109 this->OS << OS.str();
130 DE.DiagnosticID = Info.
getID();
131 DE.DiagnosticLevel =
Level;
138 DE.Message = MessageStr.str();
142 DE.Line = DE.Column = 0;
163 Entries.push_back(DE);
Defines the clang::FileManager interface and associated types.
Defines the SourceManager interface.
void EndSourceFile() override
Callback to inform the diagnostic client that processing of a source file has ended.
raw_ostream & EmitInteger(raw_ostream &o, int64_t value)
bool hasSourceManager() const
const SourceLocation & getLocation() const
bool isInvalid() const
Return true if this object is invalid or uninitialized.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
unsigned getLine() const
Return the presumed line number of this location.
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.
static StringRef getWarningOptionForDiag(unsigned DiagID)
Return the lowest-level warning option that enables the specified diagnostic.
Represents an unpacked "presumed" location which can be presented to the user.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getColumn() const
Return the presumed column number of this location.
StringRef getName() const
Options for controlling the compiler diagnostics engine.
Cached information about one file (either on disk or in the virtual file system). ...
static StringRef getLevelName(DiagnosticsEngine::Level Level)
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.
SourceManager & getSourceManager() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
LogDiagnosticPrinter(raw_ostream &OS, DiagnosticOptions *Diags, std::unique_ptr< raw_ostream > StreamOwner)
FileID getMainFileID() const
Returns the FileID of the main source file.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
raw_ostream & EmitString(raw_ostream &o, StringRef s)
Level
The level of the diagnostic, after it has been through mapping.
A little helper class (which is basically a smart pointer that forwards info from DiagnosticsEngine) ...
void FormatDiagnostic(SmallVectorImpl< char > &OutStr) const
Format this diagnostic into a string, substituting the formal arguments into the %0 slots...
This class handles loading and caching of source files into memory.