clang 20.0.0git
|
#include "clang/Frontend/TextDiagnostic.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Lex/Lexer.h"
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Locale.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <optional>
Go to the source code of this file.
Classes | |
struct | LineRange |
Functions | |
static void | applyTemplateHighlighting (raw_ostream &OS, StringRef Str, bool &Normal, bool Bold) |
Add highlights to differences in template strings. | |
static int | bytesSincePreviousTabOrLineBegin (StringRef SourceLine, size_t i) |
static std::pair< SmallString< 16 >, bool > | printableTextForNextCharacter (StringRef SourceLine, size_t *I, unsigned TabStop) |
returns a printable representation of first item from input range | |
static void | expandTabs (std::string &SourceLine, unsigned TabStop) |
static void | genColumnByteMapping (StringRef SourceLine, unsigned TabStop, SmallVectorImpl< int > &BytesOut, SmallVectorImpl< int > &ColumnsOut) |
BytesOut: A mapping from columns to the byte of the source line that produced the character displaying at that column. | |
static void | selectInterestingSourceRegion (std::string &SourceLine, std::string &CaretLine, std::string &FixItInsertionLine, unsigned Columns, const SourceColumnMap &map) |
When the source code line we want to print is too long for the terminal, select the "interesting" region. | |
static unsigned | skipWhitespace (unsigned Idx, StringRef Str, unsigned Length) |
Skip over whitespace in the string, starting at the given index. | |
static char | findMatchingPunctuation (char c) |
If the given character is the start of some kind of balanced punctuation (e.g., quotes or parentheses), return the character that will terminate the punctuation. | |
static unsigned | findEndOfWord (unsigned Start, StringRef Str, unsigned Length, unsigned Column, unsigned Columns) |
Find the end of the word starting at the given offset within a string. | |
static bool | printWordWrapped (raw_ostream &OS, StringRef Str, unsigned Columns, unsigned Column, bool Bold) |
Print the given string to a stream, word-wrapping it to some number of columns in the process. | |
static std::optional< std::pair< unsigned, unsigned > > | findLinesForRange (const CharSourceRange &R, FileID FID, const SourceManager &SM) |
Find the suitable set of lines to show to include a set of ranges. | |
static std::pair< unsigned, unsigned > | maybeAddRange (std::pair< unsigned, unsigned > A, std::pair< unsigned, unsigned > B, unsigned MaxRange) |
Add as much of range B into range A as possible without exceeding a maximum size of MaxRange. | |
static void | highlightRange (const LineRange &R, const SourceColumnMap &Map, std::string &CaretLine) |
Highlight R (with ~'s) on the current source line. | |
static std::string | buildFixItInsertionLine (FileID FID, unsigned LineNo, const SourceColumnMap &map, ArrayRef< FixItHint > Hints, const SourceManager &SM, const DiagnosticOptions *DiagOpts) |
static unsigned | getNumDisplayWidth (unsigned N) |
static SmallVector< LineRange > | prepareAndFilterRanges (const SmallVectorImpl< CharSourceRange > &Ranges, const SourceManager &SM, const std::pair< unsigned, unsigned > &Lines, FileID FID, const LangOptions &LangOpts) |
Filter out invalid ranges, ranges that don't fit into the window of source lines we will print, and ranges from other files. | |
static std::unique_ptr< llvm::SmallVector< TextDiagnostic::StyleRange >[]> | highlightLines (StringRef FileData, unsigned StartLineNumber, unsigned EndLineNumber, const Preprocessor *PP, const LangOptions &LangOpts, bool ShowColors, FileID FID, const SourceManager &SM) |
Creates syntax highlighting information in form of StyleRanges. | |
Variables | |
static enum raw_ostream::Colors | noteColor = raw_ostream::CYAN |
static enum raw_ostream::Colors | remarkColor |
static enum raw_ostream::Colors | fixitColor |
static enum raw_ostream::Colors | caretColor |
static enum raw_ostream::Colors | warningColor |
static enum raw_ostream::Colors | templateColor |
static enum raw_ostream::Colors | errorColor = raw_ostream::RED |
static enum raw_ostream::Colors | fatalColor = raw_ostream::RED |
static enum raw_ostream::Colors | savedColor |
static constexpr raw_ostream::Colors | CommentColor = raw_ostream::YELLOW |
static constexpr raw_ostream::Colors | LiteralColor = raw_ostream::GREEN |
static constexpr raw_ostream::Colors | KeywordColor = raw_ostream::BLUE |
const unsigned | WordWrapIndentation = 6 |
Number of spaces to indent when word-wrapping. | |
|
static |
Add highlights to differences in template strings.
Definition at line 54 of file TextDiagnostic.cpp.
References clang::Normal, savedColor, templateColor, and clang::ToggleHighlight.
Referenced by clang::TextDiagnostic::printDiagnosticMessage(), and printWordWrapped().
|
static |
Definition at line 1001 of file TextDiagnostic.cpp.
References expandTabs(), and SM.
Definition at line 77 of file TextDiagnostic.cpp.
References bytes().
Referenced by printableTextForNextCharacter().
|
static |
Definition at line 176 of file TextDiagnostic.cpp.
References printableTextForNextCharacter().
Referenced by buildFixItInsertionLine().
|
static |
Find the end of the word starting at the given offset within a string.
Definition at line 543 of file TextDiagnostic.cpp.
References clang::Column, findEndOfWord(), findMatchingPunctuation(), and clang::isWhitespace().
Referenced by findEndOfWord(), and printWordWrapped().
|
static |
Find the suitable set of lines to show to include a set of ranges.
Definition at line 913 of file TextDiagnostic.cpp.
References Begin, clang::CharSourceRange::getBegin(), clang::CharSourceRange::getEnd(), clang::CharSourceRange::isValid(), and SM.
|
inlinestatic |
If the given character is the start of some kind of balanced punctuation (e.g., quotes or parentheses), return the character that will terminate the punctuation.
Definition at line 524 of file TextDiagnostic.cpp.
References c.
Referenced by findEndOfWord().
|
static |
BytesOut:
A mapping from columns to the byte of the source line that produced the character displaying at that column.
This is the inverse of ColumnsOut
.
The last element in the array is the number of bytes in the source string.
example: (given a tabstop of 8)
"a \t \u3042" -> {0,1,2,-1,-1,-1,-1,-1,3,4,-1,7}
(\u3042 is represented in UTF-8 by three bytes and takes two columns to display)
ColumnsOut:
A mapping from the bytes of the printable representation of the line to the columns those printable characters will appear at (numbering the first column as 0).
If a byte 'i' corresponds to multiple columns (e.g. the byte contains a tab character) then the array will map that byte to the first column the tab appears at and the next value in the map will have been incremented more than once.
If a byte is the first in a sequence of bytes that together map to a single entity in the output, then the array will map that byte to the appropriate column while the subsequent bytes will be -1.
The last element in the array does not correspond to any byte in the input and instead is the number of columns needed to display the source
example: (given a tabstop of 8)
"a \t \u3042" -> {0,1,2,8,9,-1,-1,11}
(\u3042 is represented in UTF-8 by three bytes and takes two columns to display)
Definition at line 225 of file TextDiagnostic.cpp.
References printableTextForNextCharacter().
Definition at line 1065 of file TextDiagnostic.cpp.
|
static |
Creates syntax highlighting information in form of StyleRanges.
The returned unique ptr has always exactly size (EndLineNumber
- StartLineNumber
+ 1). Each SmallVector in there corresponds to syntax highlighting information in one line. In each line, the StyleRanges are non-overlapping and sorted from start to end of the line.
Definition at line 1132 of file TextDiagnostic.cpp.
References clang::CommentColor, clang::Preprocessor::getCheckPoint(), clang::IdentifierTable::getExternalIdentifierLookup(), clang::Preprocessor::getIdentifierInfo(), clang::Preprocessor::getIdentifierTable(), clang::Lexer::getSpelling(), clang::Invalid, clang::IdentifierInfo::isKeyword(), clang::tok::isLiteral(), clang::isVerticalWhitespace(), KeywordColor, LiteralColor, ShowColors, SM, and clang::T.
|
static |
Highlight R
(with ~'s) on the current source line.
Definition at line 969 of file TextDiagnostic.cpp.
References LineRange::EndCol, and LineRange::StartCol.
|
static |
Add as much of range B into range A as possible without exceeding a maximum size of MaxRange.
Ranges are inclusive.
Definition at line 930 of file TextDiagnostic.cpp.
References clang::Max, and clang::Min.
|
static |
Filter out invalid ranges, ranges that don't fit into the window of source lines we will print, and ranges from other files.
For the remaining ranges, convert them to simple LineRange structs, which only cover one line at a time.
Definition at line 1079 of file TextDiagnostic.cpp.
References Begin, clang::Lexer::MeasureTokenLength(), and SM.
|
static |
returns a printable representation of first item from input range
This function returns a printable representation of the next item in a line of source. If the next byte begins a valid and printable character, that character is returned along with 'true'.
Otherwise, if the next byte begins a valid, but unprintable character, a printable, escaped representation of the character is returned, along with 'false'. Otherwise a printable, escaped representation of the next byte is returned along with 'false'.
SourceLine | The line of source |
I | Pointer to byte index, |
TabStop | used to expand tabs |
Definition at line 107 of file TextDiagnostic.cpp.
References Begin, bytesSincePreviousTabOrLineBegin(), clang::C, and clang::DiagnosticOptions::MaxTabStop.
Referenced by expandTabs(), and genColumnByteMapping().
|
static |
Print the given string to a stream, word-wrapping it to some number of columns in the process.
OS | the stream to which the word-wrapping string will be emitted. |
Str | the string to word-wrap and output. |
Columns | the number of columns to word-wrap to. |
Column | the column number at which the first character of Str will be printed. This will be non-zero when part of the first line has already been printed. |
Bold | if the current text should be bold |
Definition at line 608 of file TextDiagnostic.cpp.
References applyTemplateHighlighting(), clang::Column, findEndOfWord(), skipWhitespace(), and WordWrapIndentation.
Referenced by clang::TextDiagnostic::printDiagnosticMessage().
|
static |
When the source code line we want to print is too long for the terminal, select the "interesting" region.
Definition at line 322 of file TextDiagnostic.cpp.
References c, and clang::isWhitespace().
Skip over whitespace in the string, starting at the given index.
Definition at line 512 of file TextDiagnostic.cpp.
References clang::isWhitespace().
Referenced by printWordWrapped().
|
static |
Definition at line 33 of file TextDiagnostic.cpp.
|
staticconstexpr |
Definition at line 49 of file TextDiagnostic.cpp.
|
static |
Definition at line 39 of file TextDiagnostic.cpp.
Referenced by clang::TextDiagnostic::printDiagnosticLevel().
|
static |
Definition at line 40 of file TextDiagnostic.cpp.
Referenced by clang::TextDiagnostic::printDiagnosticLevel().
|
static |
Definition at line 31 of file TextDiagnostic.cpp.
|
staticconstexpr |
Definition at line 51 of file TextDiagnostic.cpp.
Referenced by highlightLines().
|
staticconstexpr |
Definition at line 50 of file TextDiagnostic.cpp.
Referenced by highlightLines().
|
static |
Definition at line 28 of file TextDiagnostic.cpp.
Referenced by clang::TextDiagnostic::printDiagnosticLevel().
|
static |
Definition at line 29 of file TextDiagnostic.cpp.
Referenced by clang::TextDiagnostic::printDiagnosticLevel().
|
static |
Definition at line 42 of file TextDiagnostic.cpp.
Referenced by applyTemplateHighlighting(), clang::TextDiagnostic::emitDiagnosticLoc(), and clang::TextDiagnostic::printDiagnosticMessage().
|
static |
Definition at line 37 of file TextDiagnostic.cpp.
Referenced by applyTemplateHighlighting().
|
static |
Definition at line 35 of file TextDiagnostic.cpp.
Referenced by clang::TextDiagnostic::printDiagnosticLevel().
const unsigned WordWrapIndentation = 6 |
Number of spaces to indent when word-wrapping.
Definition at line 75 of file TextDiagnostic.cpp.
Referenced by printWordWrapped().