*
const TokNames[] = {
33llvm_unreachable(
"unknown TokenType");
39 "clock_t",
"int16_t",
"int32_t",
"int64_t",
"int8_t",
40 "intptr_t",
"ptrdiff_t",
"size_t",
"time_t",
"uint16_t",
41 "uint32_t",
"uint64_t",
"uint8_t",
"uintptr_t",
47 const boolIsCpp = LangOpts.CXXOperatorNames;
48 returnIsCpp &&
is(tok::identifier) &&
58assert(
is(tok::r_brace));
59 if(!Style.Cpp11BracedListStyle ||
64assert(LBrace && LBrace->is(tok::l_brace));
67 if(LBrace->Previous && LBrace->Previous->is(tok::equal))
78 return is(TT_ArrayInitializerLSquare) ||
is(TT_ProtoExtensionLSquare) ||
79(
is(tok::l_brace) &&
82(
is(tok::less) && Style.isProto());
92 if(!State.NextToken || !State.NextToken->Previous)
95 if(Formats.size() <= 1)
100State.NextToken->Previous->getPreviousNonComment();
101 if(!LBrace || !LBrace->
isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
102LBrace->
is(
BK_Block) || LBrace->
is(TT_DictLiteral) ||
103LBrace->
Next->
is(TT_DesignatedInitializerPeriod)) {
109 unsignedRemainingCodePoints =
110 Style.
ColumnLimit- State.Column + State.NextToken->Previous->ColumnWidth;
113 constColumnFormat *Format = getColumnFormat(RemainingCodePoints);
122 unsignedPenalty = 0;
127 unsignedExtraSpaces = 0;
130 if(Item < Commas.size() && State.NextToken->Previous == Commas[Item]) {
131 if(!State.NextToken->isTrailingComment()) {
132ExtraSpaces += Format->ColumnSizes[
Column] - ItemLengths[Item];
138 if(
Column== Format->Columns || State.NextToken->MustBreakBefore) {
144Penalty +=
Indenter->addTokenToState(State,
NewLine, DryRun, ExtraSpaces);
154 if(Formats.size() == 1 || HasNestedBracedList)
155State.Stack.back().AvoidBinPacking =
true;
163assert(End->TotalLength >=
Begin->TotalLength);
164 returnEnd->TotalLength -
Begin->TotalLength +
Begin->ColumnWidth;
169 if(!
Token->MatchingParen ||
170!
Token->
isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
178Commas.size() < 19) {
185 if(
Token->
is(TT_ArrayInitializerLSquare) && Commas.size() < 19)
194ItemBegin = ItemBegin->
Next;
200MustBreakBeforeItem.reserve(Commas.size() + 1);
201EndOfLineItemLength.reserve(Commas.size() + 1);
202ItemLengths.reserve(Commas.size() + 1);
204 boolHasSeparatingComment =
false;
205 for(
unsignedi = 0, e = Commas.size() + 1; i != e; ++i) {
209ItemBegin = ItemBegin->
Next;
210HasSeparatingComment = i > 0;
214 if(ItemBegin->
is(tok::l_brace))
215HasNestedBracedList =
true;
217 if(i == Commas.size()) {
218ItemEnd =
Token->MatchingParen;
226ItemEnd = ItemEnd->
Next;
229ItemEnd =
Token->MatchingParen->Previous;
239ItemEnd = ItemEnd->
Next;
247ItemBegin = ItemEnd->
Next;
252 if(Commas.size() < 5 || HasSeparatingComment)
255 if(
Token->NestingLevel != 0 &&
Token->
is(tok::l_brace) && Commas.size() < 19)
262MinSizeInColumn.reserve(MaxItems);
263 for(
unsignedColumns = 1; Columns <= MaxItems; ++Columns) {
265Format.Columns = Columns;
266Format.ColumnSizes.resize(Columns);
267MinSizeInColumn.assign(Columns,
UINT_MAX);
268Format.LineCount = 1;
269 boolHasRowWithSufficientColumns =
false;
271 for(
unsignedi = 0, e = ItemLengths.size(); i != e; ++i) {
272assert(i < MustBreakBeforeItem.size());
273 if(MustBreakBeforeItem[i] ||
Column== Columns) {
277 if(
Column== Columns - 1)
278HasRowWithSufficientColumns =
true;
280(
Column== Columns - 1) ? EndOfLineItemLength[i] : ItemLengths[i];
281Format.ColumnSizes[
Column] = std::max(Format.ColumnSizes[
Column], Length);
282MinSizeInColumn[
Column] = std::min(MinSizeInColumn[
Column], Length);
287 if(!HasRowWithSufficientColumns)
289Format.TotalWidth = Columns - 1;
291 for(
unsignedi = 0; i < Columns; ++i)
292Format.TotalWidth += Format.ColumnSizes[i];
297 for(
unsignedi = 0; i < Columns - 1; ++i)
298 if(Format.ColumnSizes[i] - MinSizeInColumn[i] > 10)
309Formats.push_back(Format);
313constCommaSeparatedList::ColumnFormat *
314CommaSeparatedList::getColumnFormat(
unsignedRemainingCharacters)
const{
315 constColumnFormat *BestFormat =
nullptr;
316 for(
constColumnFormat &Format : llvm::reverse(Formats)) {
317 if(Format.TotalWidth <= RemainingCharacters || Format.Columns == 1) {
318 if(BestFormat && Format.LineCount > BestFormat->LineCount)
320BestFormat = &Format;
329 if(Current.
is(TT_CtorInitializerComma) &&
336((
Previous.isNot(TT_CtorInitializerComma) ||
339(
Previous.isNot(TT_InheritanceComma) ||
This file implements an indenter that manages the indentation of continuations.
This file contains the declaration of the FormatToken, a wrapper around Token with additional informa...
static constexpr bool isOneOf()
static const char *const TokNames[]
ContinuationIndenter * Indenter
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Token - This structure provides full information about a lexed token.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
bool isSimpleTypeSpecifier(const LangOptions &LangOpts) const
Determine whether the token kind starts a simple-type-specifier.
The base class of the type hierarchy.
unsigned formatFromToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) override
Apply the special formatting that the given role demands.
unsigned formatAfterToken(LineState &State, ContinuationIndenter *Indenter, bool DryRun) override
Same as formatFromToken, but assumes that the first token has already been set thereby deciding on th...
void precomputeFormattingInfos(const FormatToken *Token) override
After the TokenAnnotator has finished annotating all the tokens, this function precomputes required i...
virtual void precomputeFormattingInfos(const FormatToken *Token)
After the TokenAnnotator has finished annotating all the tokens, this function precomputes required i...
const FormatStyle & Style
const char * getTokenTypeName(TokenType Type)
Determines the name of a token type.
static SmallVector< StringRef > CppNonKeywordTypes
static unsigned CodePointsBetween(const FormatToken *Begin, const FormatToken *End)
TokenType
Determines the semantic type of a syntactic token, e.g.
bool startsNextParameter(const FormatToken &Current, const FormatStyle &Style)
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
The FormatStyle is used to configure the formatting to follow specific guidelines.
@ LK_Proto
Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
bool Cpp11BracedListStyle
If true, format braced lists as best suited for C++11 braced lists.
BreakInheritanceListStyle BreakInheritanceList
The inheritance list style to use.
@ BCIS_BeforeComma
Break constructor initializers before the colon and commas, and align the commas with the colon.
LanguageKind Language
Language, this format style is targeted at.
@ BAS_DontAlign
Don't align, instead use ContinuationIndentWidth, e.g.:
@ BAS_BlockIndent
Always break after an open bracket, if the parameters don't fit on a single line.
BreakConstructorInitializersStyle BreakConstructorInitializers
The break constructor initializers style to use.
@ BILS_BeforeComma
Break inheritance list before the colon and commas, and align the commas with the colon.
bool BinPackArguments
If false, a function call's arguments will either be all on the same line or will have one line each.
BracketAlignmentStyle AlignAfterOpenBracket
If true, horizontally aligns arguments after an open bracket.
unsigned ColumnLimit
The column limit.
A wrapper around a Token storing information about the whitespace characters preceding it.
unsigned NestingLevel
The nesting level of this token, i.e.
bool isTypeName(const LangOptions &LangOpts) const
unsigned CanBreakBefore
true if it is allowed to break before this token.
StringRef TokenText
The raw text of the token.
bool opensScope() const
Returns whether Tok is ([{ or an opening < of a template or in protos.
FormatToken * getNextNonComment() const
Returns the next token ignoring comments.
FormatToken * getPreviousNonComment() const
Returns the previous token ignoring comments.
BraceBlockKind getBlockKind() const
FormatToken * Next
The next token in the unwrapped line.
unsigned MustBreakBefore
Whether there must be a line break before this token.
unsigned HasUnescapedNewline
Whether there is at least one unescaped newline before the Token.
bool isBlockIndentedInitRBrace(const FormatStyle &Style) const
Returns true if this token ends a block indented initializer list.
bool is(tok::TokenKind Kind) const
bool opensBlockOrBlockTypeList(const FormatStyle &Style) const
Returns true if this tokens starts a block-type list, i.e.
bool isOneOf(A K1, B K2) const
bool isTrailingComment() const
bool isTypeOrIdentifier(const LangOptions &LangOpts) const
FormatToken * MatchingParen
If this is a bracket, this points to the matching one.
FormatToken * Previous
The previous token in the unwrapped line.
The current state when indenting a unwrapped line.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4