clang API Documentation
Class to encapsulate the logic for formatting and printing a textual diagnostic message. More...
#include <TextDiagnostic.h>


Public Member Functions | |
| TextDiagnostic (raw_ostream &OS, const LangOptions &LangOpts, const DiagnosticOptions &DiagOpts) | |
| virtual | ~TextDiagnostic () |
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, DiagnosticsEngine::Level Level, StringRef Message, unsigned CurrentColumn, unsigned Columns, bool ShowColors) |
| Pretty-print a diagnostic message to a raw_ostream. | |
Protected Member Functions | |
| virtual void | emitDiagnosticMessage (SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, StringRef Message, ArrayRef< CharSourceRange > Ranges, const SourceManager *SM, DiagOrStoredDiag D) |
| virtual void | emitDiagnosticLoc (SourceLocation Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level, ArrayRef< CharSourceRange > Ranges, const SourceManager &SM) |
| Print out the file/line/column information and include trace. | |
| virtual void | emitCodeContext (SourceLocation Loc, DiagnosticsEngine::Level Level, SmallVectorImpl< CharSourceRange > &Ranges, ArrayRef< FixItHint > Hints, const SourceManager &SM) |
| virtual void | emitBasicNote (StringRef Message) |
| virtual void | emitIncludeLocation (SourceLocation Loc, PresumedLoc PLoc, const SourceManager &SM) |
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 37 of file TextDiagnostic.h.
| TextDiagnostic::TextDiagnostic | ( | raw_ostream & | OS, |
| const LangOptions & | LangOpts, | ||
| const DiagnosticOptions & | DiagOpts | ||
| ) |
Definition at line 604 of file TextDiagnostic.cpp.
| TextDiagnostic::~TextDiagnostic | ( | ) | [virtual] |
Definition at line 609 of file TextDiagnostic.cpp.
| void TextDiagnostic::emitBasicNote | ( | StringRef | Message | ) | [protected, virtual] |
Implements clang::DiagnosticRenderer.
Definition at line 797 of file TextDiagnostic.cpp.
| virtual void clang::TextDiagnostic::emitCodeContext | ( | SourceLocation | Loc, |
| DiagnosticsEngine::Level | Level, | ||
| SmallVectorImpl< CharSourceRange > & | Ranges, | ||
| ArrayRef< FixItHint > | Hints, | ||
| const SourceManager & | SM | ||
| ) | [inline, protected, virtual] |
Implements clang::DiagnosticRenderer.
Definition at line 93 of file TextDiagnostic.h.
| void TextDiagnostic::emitDiagnosticLoc | ( | SourceLocation | Loc, |
| PresumedLoc | PLoc, | ||
| DiagnosticsEngine::Level | Level, | ||
| ArrayRef< CharSourceRange > | Ranges, | ||
| const SourceManager & | SM | ||
| ) | [protected, virtual] |
Print out the file/line/column information and include trace.
This method handlen 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 695 of file TextDiagnostic.cpp.
References clang::DiagnosticOptions::Clang, clang::DiagnosticRenderer::DiagOpts, clang::DiagnosticOptions::Format, clang::PresumedLoc::getColumn(), clang::SourceManager::getColumnNumber(), clang::SourceManager::getDecomposedLoc(), clang::FileEntry::getDevice(), clang::SourceManager::getExpansionLoc(), clang::SourceManager::getExpansionRange(), clang::SourceManager::getFileEntryForID(), clang::SourceManager::getFileID(), clang::FileEntry::getFileMode(), clang::PresumedLoc::getFilename(), clang::FileEntry::getInode(), clang::PresumedLoc::getLine(), clang::SourceManager::getLineNumber(), clang::FileEntry::getName(), clang::FileID::isInvalid(), clang::PresumedLoc::isInvalid(), clang::SourceLocation::isMacroID(), clang::DiagnosticRenderer::LangOpts, clang::Lexer::MeasureTokenLength(), clang::DiagnosticOptions::Msvc, savedColor, clang::DiagnosticOptions::ShowColors, clang::DiagnosticOptions::ShowColumn, clang::DiagnosticOptions::ShowLocation, clang::DiagnosticOptions::ShowSourceRanges, and clang::DiagnosticOptions::Vi.
Referenced by emitDiagnosticMessage().
| void TextDiagnostic::emitDiagnosticMessage | ( | SourceLocation | Loc, |
| PresumedLoc | PLoc, | ||
| DiagnosticsEngine::Level | Level, | ||
| StringRef | Message, | ||
| ArrayRef< CharSourceRange > | Ranges, | ||
| const SourceManager * | SM, | ||
| DiagOrStoredDiag | D | ||
| ) | [protected, virtual] |
Implements clang::DiagnosticRenderer.
Definition at line 612 of file TextDiagnostic.cpp.
References clang::DiagnosticRenderer::DiagOpts, emitDiagnosticLoc(), clang::SourceLocation::isValid(), clang::DiagnosticOptions::MessageLength, printDiagnosticLevel(), printDiagnosticMessage(), and clang::DiagnosticOptions::ShowColors.
| void TextDiagnostic::emitIncludeLocation | ( | SourceLocation | Loc, |
| PresumedLoc | PLoc, | ||
| const SourceManager & | SM | ||
| ) | [protected, virtual] |
Implements clang::DiagnosticRenderer.
Definition at line 803 of file TextDiagnostic.cpp.
References clang::DiagnosticRenderer::DiagOpts, clang::PresumedLoc::getFilename(), clang::PresumedLoc::getLine(), and clang::DiagnosticOptions::ShowLocation.
| 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 635 of file TextDiagnostic.cpp.
References clang::DiagnosticsEngine::Error, errorColor, clang::DiagnosticsEngine::Fatal, fatalColor, clang::DiagnosticsEngine::Ignored, clang::DiagnosticsEngine::Note, noteColor, clang::DiagnosticsEngine::Warning, and warningColor.
Referenced by emitDiagnosticMessage(), and clang::TextDiagnosticPrinter::HandleDiagnostic().
| void TextDiagnostic::printDiagnosticMessage | ( | raw_ostream & | OS, |
| DiagnosticsEngine::Level | Level, | ||
| 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 publically 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 |
| Level | Used to colorizing the message |
| 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 664 of file TextDiagnostic.cpp.
References clang::DiagnosticsEngine::Error, clang::DiagnosticsEngine::Fatal, printWordWrapped(), savedColor, and clang::DiagnosticsEngine::Warning.
Referenced by emitDiagnosticMessage(), and clang::TextDiagnosticPrinter::HandleDiagnostic().