clang
3.9.0
|
Manages the whitespaces around tokens and their replacements. More...
#include <WhitespaceManager.h>
Classes | |
struct | Change |
Represents a change before a token, a break inside a token, or the layout of an unchanged token (or whitespace within). More... | |
Public Member Functions | |
WhitespaceManager (const SourceManager &SourceMgr, const FormatStyle &Style, bool UseCRLF) | |
void | reset () |
Prepares the WhitespaceManager for another run. More... | |
void | replaceWhitespace (FormatToken &Tok, unsigned Newlines, unsigned IndentLevel, unsigned Spaces, unsigned StartOfTokenColumn, bool InPPDirective=false) |
Replaces the whitespace in front of Tok . More... | |
void | addUntouchableToken (const FormatToken &Tok, bool InPPDirective) |
Adds information about an unchangeable token's whitespace. More... | |
void | replaceWhitespaceInToken (const FormatToken &Tok, unsigned Offset, unsigned ReplaceChars, StringRef PreviousPostfix, StringRef CurrentPrefix, bool InPPDirective, unsigned Newlines, unsigned IndentLevel, int Spaces) |
Inserts or replaces whitespace in the middle of a token. More... | |
const tooling::Replacements & | generateReplacements () |
Returns all the Replacements created during formatting. More... | |
Manages the whitespaces around tokens and their replacements.
This includes special handling for certain constructs, e.g. the alignment of trailing line comments.
To guarantee correctness of alignment operations, the WhitespaceManager
must be informed about every token in the source file; for each token, there must be exactly one call to either replaceWhitespace
or addUntouchableToken
.
There may be multiple calls to breakToken
for a given token.
Definition at line 38 of file WhitespaceManager.h.
|
inline |
Definition at line 40 of file WhitespaceManager.h.
void clang::format::WhitespaceManager::addUntouchableToken | ( | const FormatToken & | Tok, |
bool | InPPDirective | ||
) |
Adds information about an unchangeable token's whitespace.
Needs to be called for every token for which replaceWhitespace
was not called.
Definition at line 65 of file WhitespaceManager.cpp.
References clang::format::FormatToken::Finalized, clang::Token::getKind(), clang::format::FormatToken::is(), clang::format::FormatToken::IsFirst, clang::format::FormatToken::NewlinesBefore, clang::format::FormatToken::OriginalColumn, clang::format::FormatToken::Tok, and clang::format::FormatToken::WhitespaceRange.
const tooling::Replacements & clang::format::WhitespaceManager::generateReplacements | ( | ) |
Returns all the Replacements
created during formatting.
Definition at line 93 of file WhitespaceManager.cpp.
void clang::format::WhitespaceManager::replaceWhitespace | ( | FormatToken & | Tok, |
unsigned | Newlines, | ||
unsigned | IndentLevel, | ||
unsigned | Spaces, | ||
unsigned | StartOfTokenColumn, | ||
bool | InPPDirective = false |
||
) |
Replaces the whitespace in front of Tok
.
Only call once for each AnnotatedToken
.
Definition at line 50 of file WhitespaceManager.cpp.
References clang::format::FormatToken::Decision, clang::format::FD_Break, clang::format::FD_Continue, clang::format::FormatToken::Finalized, clang::Token::getKind(), clang::format::FormatToken::is(), clang::format::FormatToken::IsFirst, clang::format::FormatToken::Tok, and clang::format::FormatToken::WhitespaceRange.
void clang::format::WhitespaceManager::replaceWhitespaceInToken | ( | const FormatToken & | Tok, |
unsigned | Offset, | ||
unsigned | ReplaceChars, | ||
StringRef | PreviousPostfix, | ||
StringRef | CurrentPrefix, | ||
bool | InPPDirective, | ||
unsigned | Newlines, | ||
unsigned | IndentLevel, | ||
int | Spaces | ||
) |
Inserts or replaces whitespace in the middle of a token.
Inserts PreviousPostfix
, Newlines
, Spaces
and CurrentPrefix
(in this order) at Offset
inside Tok
, replacing ReplaceChars
characters.
Note: Spaces
can be negative to retain information about initial relative column offset between a line of a block comment and the start of the comment. This negative offset may be compensated by trailing comment alignment here. In all other cases negative Spaces
will be truncated to 0.
When InPPDirective
is true, escaped newlines are inserted. Spaces
is used to align backslashes correctly.
Definition at line 77 of file WhitespaceManager.cpp.
References clang::format::FormatToken::Finalized, clang::SourceLocation::getLocWithOffset(), clang::format::FormatToken::getStartOfNonWhitespace(), clang::format::FormatToken::is(), clang::format::FormatToken::IsFirst, and max().
Referenced by clang::format::BreakableStringLiteral::insertBreak(), clang::format::BreakableLineComment::insertBreak(), clang::format::BreakableBlockComment::insertBreak(), clang::format::BreakableLineComment::replaceWhitespace(), clang::format::BreakableBlockComment::replaceWhitespace(), clang::format::BreakableLineComment::replaceWhitespaceBefore(), and clang::format::BreakableBlockComment::replaceWhitespaceBefore().
void clang::format::WhitespaceManager::reset | ( | ) |
Prepares the WhitespaceManager
for another run.
Definition at line 45 of file WhitespaceManager.cpp.