clang 19.0.0git
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
clang::DiagnosticRenderer Class Referenceabstract

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

#include "clang/Frontend/DiagnosticRenderer.h"

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

Public Member Functions

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)
 

Protected Member Functions

 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)
 

Protected Attributes

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 a diagnostic message.

Actual "printing" logic is implemented by subclasses.

This class provides an interface for building and emitting 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.

A brief worklist: FIXME: Sink the recursive printing of template instantiations into this class.

Definition at line 47 of file DiagnosticRenderer.h.

Constructor & Destructor Documentation

◆ DiagnosticRenderer()

DiagnosticRenderer::DiagnosticRenderer ( const LangOptions LangOpts,
DiagnosticOptions DiagOpts 
)
protected

Definition at line 32 of file DiagnosticRenderer.cpp.

◆ ~DiagnosticRenderer()

DiagnosticRenderer::~DiagnosticRenderer ( )
protectedvirtualdefault

Member Function Documentation

◆ beginDiagnostic()

virtual void clang::DiagnosticRenderer::beginDiagnostic ( DiagOrStoredDiag  D,
DiagnosticsEngine::Level  Level 
)
inlineprotectedvirtual

Definition at line 97 of file DiagnosticRenderer.h.

Referenced by emitDiagnostic().

◆ emitBuildingModuleLocation()

virtual void clang::DiagnosticRenderer::emitBuildingModuleLocation ( FullSourceLoc  Loc,
PresumedLoc  PLoc,
StringRef  ModuleName 
)
protectedpure virtual

◆ emitCodeContext()

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

◆ emitDiagnostic()

void DiagnosticRenderer::emitDiagnostic ( FullSourceLoc  Loc,
DiagnosticsEngine::Level  Level,
StringRef  Message,
ArrayRef< CharSourceRange Ranges,
ArrayRef< FixItHint FixItHints,
DiagOrStoredDiag  D = (Diagnostic *)nullptr 
)

Emit a diagnostic.

This is the primary entry point for emitting diagnostic messages. It handles formatting and rendering the message as well as any ancillary information needed based on macros whose expansions impact the diagnostic.

Parameters
LocThe location for this caret.
LevelThe level of the diagnostic to be emitted.
MessageThe diagnostic message to emit.
RangesThe underlined ranges for this code snippet.
FixItHintsThe FixIt hints active for this diagnostic.

Definition at line 86 of file DiagnosticRenderer.cpp.

References beginDiagnostic(), DiagOpts, emitDiagnosticMessage(), endDiagnostic(), clang::FullSourceLoc::getFileLoc(), clang::FullSourceLoc::getManager(), clang::FullSourceLoc::getPresumedLoc(), clang::FullSourceLoc::hasManager(), clang::SourceLocation::isInvalid(), clang::SourceLocation::isMacroID(), clang::SourceLocation::isValid(), LangOpts, LastLevel, LastLoc, and mergeFixits().

Referenced by emitStoredDiagnostic().

◆ emitDiagnosticLoc()

virtual void clang::DiagnosticRenderer::emitDiagnosticLoc ( FullSourceLoc  Loc,
PresumedLoc  PLoc,
DiagnosticsEngine::Level  Level,
ArrayRef< CharSourceRange Ranges 
)
protectedpure virtual

◆ emitDiagnosticMessage()

virtual void clang::DiagnosticRenderer::emitDiagnosticMessage ( FullSourceLoc  Loc,
PresumedLoc  PLoc,
DiagnosticsEngine::Level  Level,
StringRef  Message,
ArrayRef< CharSourceRange Ranges,
DiagOrStoredDiag  Info 
)
protectedpure virtual

Implemented in clang::SARIFDiagnostic, and clang::TextDiagnostic.

Referenced by emitDiagnostic().

◆ emitImportLocation()

virtual void clang::DiagnosticRenderer::emitImportLocation ( FullSourceLoc  Loc,
PresumedLoc  PLoc,
StringRef  ModuleName 
)
protectedpure virtual

◆ emitIncludeLocation()

virtual void clang::DiagnosticRenderer::emitIncludeLocation ( FullSourceLoc  Loc,
PresumedLoc  PLoc 
)
protectedpure virtual

◆ emitStoredDiagnostic()

void DiagnosticRenderer::emitStoredDiagnostic ( StoredDiagnostic Diag)

Definition at line 142 of file DiagnosticRenderer.cpp.

References Diag(), and emitDiagnostic().

◆ endDiagnostic()

virtual void clang::DiagnosticRenderer::endDiagnostic ( DiagOrStoredDiag  D,
DiagnosticsEngine::Level  Level 
)
inlineprotectedvirtual

Definition at line 99 of file DiagnosticRenderer.h.

Referenced by emitDiagnostic().

Member Data Documentation

◆ DiagOpts

IntrusiveRefCntPtr<DiagnosticOptions> clang::DiagnosticRenderer::DiagOpts
protected

◆ LangOpts

const LangOptions& clang::DiagnosticRenderer::LangOpts
protected

◆ LastIncludeLoc

SourceLocation clang::DiagnosticRenderer::LastIncludeLoc
protected

The location of the last include whose stack was printed if known.

Same restriction as LastLoc essentially, but tracking include stack root locations rather than diagnostic locations.

Definition at line 63 of file DiagnosticRenderer.h.

◆ LastLevel

DiagnosticsEngine::Level clang::DiagnosticRenderer::LastLevel = DiagnosticsEngine::Ignored
protected

The level of the last diagnostic emitted.

The level of the last diagnostic emitted. Used to detect level changes which change the amount of information displayed.

Definition at line 69 of file DiagnosticRenderer.h.

Referenced by emitDiagnostic().

◆ LastLoc

SourceLocation clang::DiagnosticRenderer::LastLoc
protected

The location of the previous diagnostic if known.

This will be invalid in cases where there is no (known) previous diagnostic location, or that location itself is invalid or comes from a different source manager than SM.

Definition at line 57 of file DiagnosticRenderer.h.

Referenced by emitDiagnostic().


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