clang 20.0.0git
|
Class to encapsulate the logic for formatting and printing a textual diagnostic message. More...
#include "clang/Frontend/TextDiagnostic.h"
Classes | |
struct | StyleRange |
Public Member Functions | |
TextDiagnostic (raw_ostream &OS, const LangOptions &LangOpts, DiagnosticOptions *DiagOpts, const Preprocessor *PP=nullptr) | |
~TextDiagnostic () override | |
Public Member Functions inherited from clang::DiagnosticRenderer | |
void | emitDiagnostic (FullSourceLoc Loc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef< CharSourceRange > Ranges, ArrayRef< FixItHint > FixItHints, DiagOrStoredDiag D=(Diagnostic *) nullptr) |
Emit a diagnostic. | |
void | emitStoredDiagnostic (StoredDiagnostic &Diag) |
Static Public Member Functions | |
static void | printDiagnosticLevel (raw_ostream &OS, DiagnosticsEngine::Level Level, bool ShowColors) |
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. | |
Additional Inherited Members | |
Protected Attributes inherited from clang::DiagnosticRenderer | |
const LangOptions & | LangOpts |
IntrusiveRefCntPtr< DiagnosticOptions > | DiagOpts |
SourceLocation | LastLoc |
The location of the previous diagnostic if known. | |
SourceLocation | LastIncludeLoc |
The location of the last include whose stack was printed if known. | |
DiagnosticsEngine::Level | LastLevel = DiagnosticsEngine::Ignored |
The level of the last diagnostic emitted. | |
Class to encapsulate the logic for formatting and printing a textual diagnostic message.
This class provides an interface for building and emitting a textual diagnostic, including all of the macro backtraces, caret diagnostics, FixIt Hints, and code snippets. In the presence of macros this involves a recursive process, synthesizing notes for each macro expansion.
The purpose of this class is to isolate the implementation of printing beautiful text diagnostics from any particular interfaces. The Clang DiagnosticClient is implemented through this class as is diagnostic printing coming out of libclang.
Definition at line 35 of file TextDiagnostic.h.
TextDiagnostic::TextDiagnostic | ( | raw_ostream & | OS, |
const LangOptions & | LangOpts, | ||
DiagnosticOptions * | DiagOpts, | ||
const Preprocessor * | PP = nullptr |
||
) |
Definition at line 656 of file TextDiagnostic.cpp.
|
override |
Definition at line 661 of file TextDiagnostic.cpp.
|
overrideprotectedvirtual |
Implements clang::DiagnosticRenderer.
Definition at line 901 of file TextDiagnostic.cpp.
References clang::DiagnosticRenderer::DiagOpts, clang::PresumedLoc::getFilename(), clang::PresumedLoc::getLine(), and clang::PresumedLoc::isValid().
|
inlineoverrideprotectedvirtual |
Implements clang::DiagnosticRenderer.
Definition at line 94 of file TextDiagnostic.h.
References Loc.
|
overrideprotectedvirtual |
Print out the file/line/column information and include trace.
This method handles the emission of the diagnostic location information. This includes extracting as much location information as is present for the diagnostic and printing it, as well as any include stack or source ranges necessary.
Implements clang::DiagnosticRenderer.
Definition at line 784 of file TextDiagnostic.cpp.
References clang::DiagnosticOptions::Clang, clang::DiagnosticRenderer::DiagOpts, E, clang::PresumedLoc::getColumn(), clang::FullSourceLoc::getColumnNumber(), clang::CharSourceRange::getEnd(), clang::PresumedLoc::getFilename(), clang::PresumedLoc::getLine(), clang::FullSourceLoc::getLineNumber(), clang::LangOptions::isCompatibleWithMSVC(), clang::PresumedLoc::isInvalid(), clang::CharSourceRange::isTokenRange(), clang::SourceLocation::isValid(), clang::DiagnosticRenderer::LangOpts, Loc, clang::Lexer::MeasureTokenLength(), clang::DiagnosticOptions::MSVC, clang::LangOptionsBase::MSVC2012, clang::LangOptionsBase::MSVC2015, clang::DiagnosticOptions::SARIF, savedColor, SM, and clang::DiagnosticOptions::Vi.
Referenced by emitDiagnosticMessage().
|
overrideprotectedvirtual |
Implements clang::DiagnosticRenderer.
Definition at line 663 of file TextDiagnostic.cpp.
References clang::DiagnosticRenderer::DiagOpts, emitDiagnosticLoc(), clang::SourceLocation::isValid(), Loc, clang::DiagnosticsEngine::Note, printDiagnosticLevel(), and printDiagnosticMessage().
|
overrideprotectedvirtual |
Implements clang::DiagnosticRenderer.
Definition at line 892 of file TextDiagnostic.cpp.
References clang::DiagnosticRenderer::DiagOpts, clang::PresumedLoc::getFilename(), clang::PresumedLoc::getLine(), and clang::PresumedLoc::isValid().
|
overrideprotectedvirtual |
Implements clang::DiagnosticRenderer.
Definition at line 883 of file TextDiagnostic.cpp.
References clang::DiagnosticRenderer::DiagOpts, clang::PresumedLoc::getFilename(), clang::PresumedLoc::getLine(), clang::PresumedLoc::isValid(), and Loc.
|
static |
Print the diagonstic level to a raw_ostream.
This is a static helper that handles colorizing the level and formatting it into an arbitrary output stream. This is used internally by the TextDiagnostic emission code, but it can also be used directly by consumers that don't have a source manager or other state that the full TextDiagnostic logic requires.
Definition at line 685 of file TextDiagnostic.cpp.
References clang::DiagnosticsEngine::Error, errorColor, clang::DiagnosticsEngine::Fatal, fatalColor, clang::DiagnosticsEngine::Ignored, clang::DiagnosticsEngine::Note, noteColor, clang::DiagnosticsEngine::Remark, remarkColor, ShowColors, clang::DiagnosticsEngine::Warning, and warningColor.
Referenced by emitDiagnosticMessage(), and clang::TextDiagnosticPrinter::HandleDiagnostic().
|
static |
Pretty-print a diagnostic message to a raw_ostream.
This is a static helper to handle the line wrapping, colorizing, and rendering of a diagnostic message to a particular ostream. It is publicly visible so that clients which do not have sufficient state to build a complete TextDiagnostic object can still get consistent formatting of their diagnostic messages.
OS | Where the message is printed |
IsSupplemental | true if this is a continuation note diagnostic |
Message | The text actually printed |
CurrentColumn | The starting column of the first line, accounting for any prefix. |
Columns | The number of columns to use in line-wrapping, 0 disables all line-wrapping. |
ShowColors | Enable colorizing of the message. |
Definition at line 716 of file TextDiagnostic.cpp.
References applyTemplateHighlighting(), clang::Normal, printWordWrapped(), savedColor, and ShowColors.
Referenced by emitDiagnosticMessage(), and clang::TextDiagnosticPrinter::HandleDiagnostic().