class TextDiagnostic

Declaration

class TextDiagnostic : public DiagnosticRenderer { /* full declaration omitted */ };

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.

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:34

Inherits from: DiagnosticRenderer

Member Variables

private llvm::raw_ostream& OS

Inherited from DiagnosticRenderer:

protected LangOpts
protected DiagOpts
protected LastLoc
protected LastIncludeLoc
protected LastLevel = DiagnosticsEngine::Ignored

Method Overview

  • public TextDiagnostic(llvm::raw_ostream & OS, const clang::LangOptions & LangOpts, clang::DiagnosticOptions * DiagOpts)
  • protected void emitBuildingModuleLocation(clang::FullSourceLoc Loc, clang::PresumedLoc PLoc, llvm::StringRef ModuleName)
  • protected void emitCodeContext(clang::FullSourceLoc Loc, DiagnosticsEngine::Level Level, SmallVectorImpl<clang::CharSourceRange> & Ranges, ArrayRef<clang::FixItHint> Hints)
  • protected void emitDiagnosticLoc(clang::FullSourceLoc Loc, clang::PresumedLoc PLoc, DiagnosticsEngine::Level Level, ArrayRef<clang::CharSourceRange> Ranges)
  • protected void emitDiagnosticMessage(clang::FullSourceLoc Loc, clang::PresumedLoc PLoc, DiagnosticsEngine::Level Level, llvm::StringRef Message, ArrayRef<clang::CharSourceRange> Ranges, clang::DiagOrStoredDiag D)
  • private void emitFilename(llvm::StringRef Filename, const clang::SourceManager & SM)
  • protected void emitImportLocation(clang::FullSourceLoc Loc, clang::PresumedLoc PLoc, llvm::StringRef ModuleName)
  • protected void emitIncludeLocation(clang::FullSourceLoc Loc, clang::PresumedLoc PLoc)
  • private void emitParseableFixits(ArrayRef<clang::FixItHint> Hints, const clang::SourceManager & SM)
  • private void emitSnippet(llvm::StringRef SourceLine)
  • private void emitSnippetAndCaret(clang::FullSourceLoc Loc, DiagnosticsEngine::Level Level, SmallVectorImpl<clang::CharSourceRange> & Ranges, ArrayRef<clang::FixItHint> Hints)
  • public static void printDiagnosticLevel(llvm::raw_ostream & OS, DiagnosticsEngine::Level Level, bool ShowColors)
  • public static void printDiagnosticMessage(llvm::raw_ostream & OS, bool IsSupplemental, llvm::StringRef Message, unsigned int CurrentColumn, unsigned int Columns, bool ShowColors)
  • public ~TextDiagnostic()

Inherited from DiagnosticRenderer:

Methods

TextDiagnostic(llvm::raw_ostream& OS,
               const clang::LangOptions& LangOpts,
               clang::DiagnosticOptions* DiagOpts)

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:38

Parameters

llvm::raw_ostream& OS
const clang::LangOptions& LangOpts
clang::DiagnosticOptions* DiagOpts

void emitBuildingModuleLocation(
    clang::FullSourceLoc Loc,
    clang::PresumedLoc PLoc,
    llvm::StringRef ModuleName)

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:96

Parameters

clang::FullSourceLoc Loc
clang::PresumedLoc PLoc
llvm::StringRef ModuleName

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

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:85

Parameters

clang::FullSourceLoc Loc
DiagnosticsEngine::Level Level
SmallVectorImpl<clang::CharSourceRange>& Ranges
ArrayRef<clang::FixItHint> Hints

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

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:81

Parameters

clang::FullSourceLoc Loc
clang::PresumedLoc PLoc
DiagnosticsEngine::Level Level
ArrayRef<clang::CharSourceRange> Ranges

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

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:76

Parameters

clang::FullSourceLoc Loc
clang::PresumedLoc PLoc
DiagnosticsEngine::Level Level
llvm::StringRef Message
ArrayRef<clang::CharSourceRange> Ranges
clang::DiagOrStoredDiag D

void emitFilename(llvm::StringRef Filename,
                  const clang::SourceManager& SM)

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:100

Parameters

llvm::StringRef Filename
const clang::SourceManager& SM

void emitImportLocation(
    clang::FullSourceLoc Loc,
    clang::PresumedLoc PLoc,
    llvm::StringRef ModuleName)

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:93

Parameters

clang::FullSourceLoc Loc
clang::PresumedLoc PLoc
llvm::StringRef ModuleName

void emitIncludeLocation(clang::FullSourceLoc Loc,
                         clang::PresumedLoc PLoc)

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:91

Parameters

clang::FullSourceLoc Loc
clang::PresumedLoc PLoc

void emitParseableFixits(
    ArrayRef<clang::FixItHint> Hints,
    const clang::SourceManager& SM)

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:108

Parameters

ArrayRef<clang::FixItHint> Hints
const clang::SourceManager& SM

void emitSnippet(llvm::StringRef SourceLine)

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:106

Parameters

llvm::StringRef SourceLine

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

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:102

Parameters

clang::FullSourceLoc Loc
DiagnosticsEngine::Level Level
SmallVectorImpl<clang::CharSourceRange>& Ranges
ArrayRef<clang::FixItHint> Hints

static void printDiagnosticLevel(
    llvm::raw_ostream& OS,
    DiagnosticsEngine::Level Level,
    bool ShowColors)

Description

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.

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:51

Parameters

llvm::raw_ostream& OS
DiagnosticsEngine::Level Level
bool ShowColors

static void printDiagnosticMessage(
    llvm::raw_ostream& OS,
    bool IsSupplemental,
    llvm::StringRef Message,
    unsigned int CurrentColumn,
    unsigned int Columns,
    bool ShowColors)

Description

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.

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:71

Parameters

llvm::raw_ostream& OS
Where the message is printed
bool IsSupplemental
true if this is a continuation note diagnostic
llvm::StringRef Message
The text actually printed
unsigned int CurrentColumn
The starting column of the first line, accounting for any prefix.
unsigned int Columns
The number of columns to use in line-wrapping, 0 disables all line-wrapping.
bool ShowColors
Enable colorizing of the message.

~TextDiagnostic()

Declared at: clang/include/clang/Frontend/TextDiagnostic.h:42