20 #include "llvm/ADT/SmallString.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/MemoryBuffer.h"
23 #include "llvm/Support/raw_ostream.h"
25 using namespace clang;
29 bool _OwnsOutputStream)
30 : OS(os), DiagOpts(diags),
31 OwnsOutputStream(_OwnsOutputStream) {
59 if (DiagOpts.ShowOptionNames) {
61 if (Info.
getID() == diag::fatal_too_many_errors) {
62 OS <<
" [-ferror-limit=]";
84 OS << (Started ?
"," :
" [")
87 if (!OptValue.empty())
88 OS <<
"=" << OptValue;
94 if (DiagOpts.ShowCategories) {
95 unsigned DiagCategory =
98 OS << (Started ?
"," :
" [");
100 if (DiagOpts.ShowCategories == 1)
103 assert(DiagOpts.ShowCategories == 2 &&
"Invalid ShowCategories value");
122 llvm::raw_svector_ostream DiagMessageStream(OutStr);
129 uint64_t StartOfLocationInfo = OS.tell();
132 OS << Prefix <<
": ";
140 DiagOpts->CLFallbackMode);
142 OS.tell() - StartOfLocationInfo,
143 DiagOpts->MessageLength,
144 DiagOpts->ShowColors);
150 assert(DiagOpts &&
"Unexpected diagnostic without options set");
152 "Unexpected diagnostic with no source manager");
153 assert(TextDiag &&
"Unexpected diagnostic outside source file processing");
155 TextDiag->emitDiagnostic(Info.
getLocation(),
Level, DiagMessageStream.str(),
static unsigned getCategoryNumberForDiag(unsigned DiagID)
Return the category number that a specified DiagID belongs to, or 0 if no category.
Defines the clang::FileManager interface and associated types.
StringRef getFlagValue() const
Return the value associated with this diagnostic flag.
Defines the SourceManager interface.
static StringRef getCategoryNameFromID(unsigned CategoryID)
Given a category ID, return the name of the category.
const DiagnosticsEngine * getDiags() const
Class to encapsulate the logic for formatting and printing a textual diagnostic message.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const SourceLocation & getLocation() const
void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) override
Callback to inform the diagnostic client that processing of a source file is beginning.
static bool isBuiltinWarningOrExtension(unsigned DiagID)
Return true if the unmapped diagnostic levelof the specified diagnostic ID is a Warning or Extension...
static void printDiagnosticOptions(raw_ostream &OS, DiagnosticsEngine::Level Level, const Diagnostic &Info, const DiagnosticOptions &DiagOpts)
Print any diagnostic option information to a raw_ostream.
void HandleDiagnostic(DiagnosticsEngine::Level Level, const Diagnostic &Info) override
Handle this diagnostic, reporting it to the user or capturing it to a log as needed.
~TextDiagnosticPrinter() override
static StringRef getWarningOptionForDiag(unsigned DiagID)
Return the lowest-level warning option that enables the specified diagnostic.
void EndSourceFile() override
Callback to inform the diagnostic client that processing of a source file has ended.
bool isValid() const
Return true if this is a valid SourceLocation object.
Options for controlling the compiler diagnostics engine.
static void printDiagnosticLevel(raw_ostream &OS, DiagnosticsEngine::Level Level, bool ShowColors, bool CLFallbackMode=false)
Print the diagonstic level to a raw_ostream.
static void printDiagnosticMessage(raw_ostream &OS, bool IsSupplemental, StringRef Message, unsigned CurrentColumn, unsigned Columns, bool ShowColors)
Pretty-print a diagnostic message to a raw_ostream.
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.
TextDiagnosticPrinter(raw_ostream &os, DiagnosticOptions *diags, bool OwnsOutputStream=false)
bool hasSourceManager() const
ArrayRef< CharSourceRange > getRanges() const
Return an array reference for this diagnostic's ranges.
SourceManager & getSourceManager() const
static bool isDefaultMappingAsError(unsigned DiagID)
Return true if the specified diagnostic is mapped to errors by default.
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...
ArrayRef< FixItHint > getFixItHints() const
Engages in a tight little dance with the lexer to efficiently preprocess tokens.