clang 20.0.0git
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
clang::TextDiagnostic Class Reference

Class to encapsulate the logic for formatting and printing a textual diagnostic message. More...

#include "clang/Frontend/TextDiagnostic.h"

Inheritance diagram for clang::TextDiagnostic:
Inheritance graph
[legend]

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.
 

Protected Member Functions

void emitDiagnosticMessage (FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef< CharSourceRange > Ranges, DiagOrStoredDiag D) override
 
void emitDiagnosticLoc (FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, ArrayRef< CharSourceRange > Ranges) override
 Print out the file/line/column information and include trace.
 
void emitCodeContext (FullSourceLoc Loc, DiagnosticsEngine::Level Level, SmallVectorImpl< CharSourceRange > &Ranges, ArrayRef< FixItHint > Hints) override
 
void emitIncludeLocation (FullSourceLoc Loc, PresumedLoc PLoc) override
 
void emitImportLocation (FullSourceLoc Loc, PresumedLoc PLoc, StringRef ModuleName) override
 
void emitBuildingModuleLocation (FullSourceLoc Loc, PresumedLoc PLoc, StringRef ModuleName) override
 
- Protected Member Functions inherited from clang::DiagnosticRenderer
 DiagnosticRenderer (const LangOptions &LangOpts, DiagnosticOptions *DiagOpts)
 
virtual ~DiagnosticRenderer ()
 
virtual void emitDiagnosticMessage (FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef< CharSourceRange > Ranges, DiagOrStoredDiag Info)=0
 
virtual void emitDiagnosticLoc (FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, ArrayRef< CharSourceRange > Ranges)=0
 
virtual void emitCodeContext (FullSourceLoc Loc, DiagnosticsEngine::Level Level, SmallVectorImpl< CharSourceRange > &Ranges, ArrayRef< FixItHint > Hints)=0
 
virtual void emitIncludeLocation (FullSourceLoc Loc, PresumedLoc PLoc)=0
 
virtual void emitImportLocation (FullSourceLoc Loc, PresumedLoc PLoc, StringRef ModuleName)=0
 
virtual void emitBuildingModuleLocation (FullSourceLoc Loc, PresumedLoc PLoc, StringRef ModuleName)=0
 
virtual void beginDiagnostic (DiagOrStoredDiag D, DiagnosticsEngine::Level Level)
 
virtual void endDiagnostic (DiagOrStoredDiag D, DiagnosticsEngine::Level Level)
 

Additional Inherited Members

- Protected Attributes inherited from clang::DiagnosticRenderer
const LangOptionsLangOpts
 
IntrusiveRefCntPtr< DiagnosticOptionsDiagOpts
 
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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ TextDiagnostic()

TextDiagnostic::TextDiagnostic ( raw_ostream &  OS,
const LangOptions LangOpts,
DiagnosticOptions DiagOpts,
const Preprocessor PP = nullptr 
)

Definition at line 656 of file TextDiagnostic.cpp.

◆ ~TextDiagnostic()

TextDiagnostic::~TextDiagnostic ( )
override

Definition at line 661 of file TextDiagnostic.cpp.

Member Function Documentation

◆ emitBuildingModuleLocation()

void TextDiagnostic::emitBuildingModuleLocation ( FullSourceLoc  Loc,
PresumedLoc  PLoc,
StringRef  ModuleName 
)
overrideprotectedvirtual

◆ emitCodeContext()

void clang::TextDiagnostic::emitCodeContext ( FullSourceLoc  Loc,
DiagnosticsEngine::Level  Level,
SmallVectorImpl< CharSourceRange > &  Ranges,
ArrayRef< FixItHint Hints 
)
inlineoverrideprotectedvirtual

Implements clang::DiagnosticRenderer.

Definition at line 94 of file TextDiagnostic.h.

References Loc.

◆ emitDiagnosticLoc()

void TextDiagnostic::emitDiagnosticLoc ( FullSourceLoc  Loc,
PresumedLoc  PLoc,
DiagnosticsEngine::Level  Level,
ArrayRef< CharSourceRange Ranges 
)
overrideprotectedvirtual

◆ emitDiagnosticMessage()

void TextDiagnostic::emitDiagnosticMessage ( FullSourceLoc  Loc,
PresumedLoc  PLoc,
DiagnosticsEngine::Level  Level,
StringRef  Message,
ArrayRef< CharSourceRange Ranges,
DiagOrStoredDiag  D 
)
overrideprotectedvirtual

◆ emitImportLocation()

void TextDiagnostic::emitImportLocation ( FullSourceLoc  Loc,
PresumedLoc  PLoc,
StringRef  ModuleName 
)
overrideprotectedvirtual

◆ emitIncludeLocation()

void TextDiagnostic::emitIncludeLocation ( FullSourceLoc  Loc,
PresumedLoc  PLoc 
)
overrideprotectedvirtual

◆ printDiagnosticLevel()

void TextDiagnostic::printDiagnosticLevel ( raw_ostream &  OS,
DiagnosticsEngine::Level  Level,
bool  ShowColors 
)
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().

◆ printDiagnosticMessage()

void TextDiagnostic::printDiagnosticMessage ( raw_ostream &  OS,
bool  IsSupplemental,
StringRef  Message,
unsigned  CurrentColumn,
unsigned  Columns,
bool  ShowColors 
)
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.

Parameters
OSWhere the message is printed
IsSupplementaltrue if this is a continuation note diagnostic
MessageThe text actually printed
CurrentColumnThe starting column of the first line, accounting for any prefix.
ColumnsThe number of columns to use in line-wrapping, 0 disables all line-wrapping.
ShowColorsEnable 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().


The documentation for this class was generated from the following files: