forked from OSchip/llvm-project
[clang-format][NFC] Be more careful about the layout of FormatToken.
The underlying ABI forces FormatToken to have a lot of padding. Currently (on x86-64 linux) `sizeof(FormatToken) == 288`. After this patch `sizeof(FormatToken) == 232`. No functional changes. Reviewed By: MyDeveloperDay Differential Revision: https://reviews.llvm.org/D84306
This commit is contained in:
parent
e2f5444c9c
commit
f5acd11d2c
|
@ -284,7 +284,7 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
|
|||
// The opening "{" of a braced list has to be on the same line as the first
|
||||
// element if it is nested in another braced init list or function call.
|
||||
if (!Current.MustBreakBefore && Previous.is(tok::l_brace) &&
|
||||
Previous.isNot(TT_DictLiteral) && Previous.BlockKind == BK_BracedInit &&
|
||||
Previous.isNot(TT_DictLiteral) && Previous.is(BK_BracedInit) &&
|
||||
Previous.Previous &&
|
||||
Previous.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma))
|
||||
return false;
|
||||
|
@ -501,7 +501,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
|
|||
// The following could be precomputed as they do not depend on the state.
|
||||
// However, as they should take effect only if the UnwrappedLine does not fit
|
||||
// into the ColumnLimit, they are checked here in the ContinuationIndenter.
|
||||
if (Style.ColumnLimit != 0 && Previous.BlockKind == BK_Block &&
|
||||
if (Style.ColumnLimit != 0 && Previous.is(BK_Block) &&
|
||||
Previous.is(tok::l_brace) && !Current.isOneOf(tok::r_brace, tok::comment))
|
||||
return true;
|
||||
|
||||
|
@ -627,7 +627,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
|
|||
// opening parenthesis. Don't break if it doesn't conserve columns.
|
||||
if (Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak &&
|
||||
(Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) ||
|
||||
(Previous.is(tok::l_brace) && Previous.BlockKind != BK_Block &&
|
||||
(Previous.is(tok::l_brace) && Previous.isNot(BK_Block) &&
|
||||
Style.Cpp11BracedListStyle)) &&
|
||||
State.Column > getNewLineColumn(State) &&
|
||||
(!Previous.Previous || !Previous.Previous->isOneOf(
|
||||
|
@ -648,7 +648,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
|
|||
if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
|
||||
!State.Stack.back().IsCSharpGenericTypeConstraint &&
|
||||
Previous.opensScope() && Previous.isNot(TT_ObjCMethodExpr) &&
|
||||
(Current.isNot(TT_LineComment) || Previous.BlockKind == BK_BracedInit)) {
|
||||
(Current.isNot(TT_LineComment) || Previous.is(BK_BracedInit))) {
|
||||
State.Stack.back().Indent = State.Column + Spaces;
|
||||
State.Stack.back().IsAligned = true;
|
||||
}
|
||||
|
@ -972,7 +972,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
|
|||
return (Style.IndentWidth * State.Line->First->IndentLevel) +
|
||||
Style.IndentWidth;
|
||||
|
||||
if (NextNonComment->is(tok::l_brace) && NextNonComment->BlockKind == BK_Block)
|
||||
if (NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block))
|
||||
return Current.NestingLevel == 0 ? State.FirstIndent
|
||||
: State.Stack.back().Indent;
|
||||
if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
|
||||
|
@ -982,8 +982,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
|
|||
State.Stack.size() > 1) {
|
||||
if (Current.closesBlockOrBlockTypeList(Style))
|
||||
return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
|
||||
if (Current.MatchingParen &&
|
||||
Current.MatchingParen->BlockKind == BK_BracedInit)
|
||||
if (Current.MatchingParen && Current.MatchingParen->is(BK_BracedInit))
|
||||
return State.Stack[State.Stack.size() - 2].LastSpace;
|
||||
return State.FirstIndent;
|
||||
}
|
||||
|
@ -1417,7 +1416,7 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
|
|||
State.Stack.back().IsCSharpGenericTypeConstraint)
|
||||
return;
|
||||
|
||||
if (Current.MatchingParen && Current.BlockKind == BK_Block) {
|
||||
if (Current.MatchingParen && Current.is(BK_Block)) {
|
||||
moveStateToNewBlock(State);
|
||||
return;
|
||||
}
|
||||
|
@ -1486,9 +1485,8 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
|
|||
(State.Line->MustBeDeclaration && !BinPackDeclaration) ||
|
||||
(!State.Line->MustBeDeclaration && !Style.BinPackArguments) ||
|
||||
(Style.ExperimentalAutoDetectBinPacking &&
|
||||
(Current.PackingKind == PPK_OnePerLine ||
|
||||
(!BinPackInconclusiveFunctions &&
|
||||
Current.PackingKind == PPK_Inconclusive)));
|
||||
(Current.is(PPK_OnePerLine) ||
|
||||
(!BinPackInconclusiveFunctions && Current.is(PPK_Inconclusive))));
|
||||
|
||||
if (Current.is(TT_ObjCMethodExpr) && Current.MatchingParen &&
|
||||
Style.ObjCBreakBeforeNestedBlockParam) {
|
||||
|
|
|
@ -1575,9 +1575,9 @@ private:
|
|||
continue;
|
||||
FormatToken *Tok = AnnotatedLines[i]->First->Next;
|
||||
while (Tok->Next) {
|
||||
if (Tok->PackingKind == PPK_BinPacked)
|
||||
if (Tok->is(PPK_BinPacked))
|
||||
HasBinPackedFunction = true;
|
||||
if (Tok->PackingKind == PPK_OnePerLine)
|
||||
if (Tok->is(PPK_OnePerLine))
|
||||
HasOnePerLineFunction = true;
|
||||
|
||||
Tok = Tok->Next;
|
||||
|
|
|
@ -85,8 +85,8 @@ unsigned CommaSeparatedList::formatAfterToken(LineState &State,
|
|||
const FormatToken *LBrace =
|
||||
State.NextToken->Previous->getPreviousNonComment();
|
||||
if (!LBrace || !LBrace->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
|
||||
LBrace->BlockKind == BK_Block || LBrace->getType() == TT_DictLiteral ||
|
||||
LBrace->Next->getType() == TT_DesignatedInitializerPeriod)
|
||||
LBrace->is(BK_Block) || LBrace->is(TT_DictLiteral) ||
|
||||
LBrace->Next->is(TT_DesignatedInitializerPeriod))
|
||||
return 0;
|
||||
|
||||
// Calculate the number of code points we have to format this list. As the
|
||||
|
|
|
@ -140,24 +140,141 @@ class AnnotatedLine;
|
|||
/// A wrapper around a \c Token storing information about the
|
||||
/// whitespace characters preceding it.
|
||||
struct FormatToken {
|
||||
FormatToken() {}
|
||||
FormatToken()
|
||||
: HasUnescapedNewline(false), IsMultiline(false), IsFirst(false),
|
||||
MustBreakBefore(false), MustBreakAlignBefore(false),
|
||||
IsUnterminatedLiteral(false), CanBreakBefore(false),
|
||||
ClosesTemplateDeclaration(false), StartsBinaryExpression(false),
|
||||
EndsBinaryExpression(false), PartOfMultiVariableDeclStmt(false),
|
||||
ContinuesLineCommentSection(false), Finalized(false),
|
||||
BlockKind(BK_Unknown), Type(TT_Unknown), Decision(FD_Unformatted),
|
||||
PackingKind(PPK_Inconclusive) {}
|
||||
|
||||
/// The \c Token.
|
||||
Token Tok;
|
||||
|
||||
/// The raw text of the token.
|
||||
///
|
||||
/// Contains the raw token text without leading whitespace and without leading
|
||||
/// escaped newlines.
|
||||
StringRef TokenText;
|
||||
|
||||
/// A token can have a special role that can carry extra information
|
||||
/// about the token's formatting.
|
||||
std::unique_ptr<TokenRole> Role;
|
||||
|
||||
/// The range of the whitespace immediately preceding the \c Token.
|
||||
SourceRange WhitespaceRange;
|
||||
|
||||
/// Whether there is at least one unescaped newline before the \c
|
||||
/// Token.
|
||||
unsigned HasUnescapedNewline : 1;
|
||||
|
||||
/// Whether the token text contains newlines (escaped or not).
|
||||
unsigned IsMultiline : 1;
|
||||
|
||||
/// Indicates that this is the first token of the file.
|
||||
unsigned IsFirst : 1;
|
||||
|
||||
/// Whether there must be a line break before this token.
|
||||
///
|
||||
/// This happens for example when a preprocessor directive ended directly
|
||||
/// before the token.
|
||||
unsigned MustBreakBefore : 1;
|
||||
|
||||
/// Whether to not align across this token
|
||||
///
|
||||
/// This happens for example when a preprocessor directive ended directly
|
||||
/// before the token, but very rarely otherwise.
|
||||
unsigned MustBreakAlignBefore : 1;
|
||||
|
||||
/// Set to \c true if this token is an unterminated literal.
|
||||
unsigned IsUnterminatedLiteral : 1;
|
||||
|
||||
/// \c true if it is allowed to break before this token.
|
||||
unsigned CanBreakBefore : 1;
|
||||
|
||||
/// \c true if this is the ">" of "template<..>".
|
||||
unsigned ClosesTemplateDeclaration : 1;
|
||||
|
||||
/// \c true if this token starts a binary expression, i.e. has at least
|
||||
/// one fake l_paren with a precedence greater than prec::Unknown.
|
||||
unsigned StartsBinaryExpression : 1;
|
||||
/// \c true if this token ends a binary expression.
|
||||
unsigned EndsBinaryExpression : 1;
|
||||
|
||||
/// Is this token part of a \c DeclStmt defining multiple variables?
|
||||
///
|
||||
/// Only set if \c Type == \c TT_StartOfName.
|
||||
unsigned PartOfMultiVariableDeclStmt : 1;
|
||||
|
||||
/// Does this line comment continue a line comment section?
|
||||
///
|
||||
/// Only set to true if \c Type == \c TT_LineComment.
|
||||
unsigned ContinuesLineCommentSection : 1;
|
||||
|
||||
/// If \c true, this token has been fully formatted (indented and
|
||||
/// potentially re-formatted inside), and we do not allow further formatting
|
||||
/// changes.
|
||||
unsigned Finalized : 1;
|
||||
|
||||
private:
|
||||
/// Contains the kind of block if this token is a brace.
|
||||
unsigned BlockKind : 2;
|
||||
|
||||
public:
|
||||
BraceBlockKind getBlockKind() const {
|
||||
return static_cast<BraceBlockKind>(BlockKind);
|
||||
}
|
||||
void setBlockKind(BraceBlockKind BBK) {
|
||||
BlockKind = BBK;
|
||||
assert(getBlockKind() == BBK && "BraceBlockKind overflow!");
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned Type : 8;
|
||||
|
||||
public:
|
||||
/// Returns the token's type, e.g. whether "<" is a template opener or
|
||||
/// binary operator.
|
||||
TokenType getType() const { return static_cast<TokenType>(Type); }
|
||||
void setType(TokenType T) {
|
||||
Type = T;
|
||||
assert(getType() == T && "TokenType overflow!");
|
||||
}
|
||||
|
||||
private:
|
||||
/// Stores the formatting decision for the token once it was made.
|
||||
unsigned Decision : 2;
|
||||
|
||||
public:
|
||||
FormatDecision getDecision() const {
|
||||
return static_cast<FormatDecision>(Decision);
|
||||
}
|
||||
void setDecision(FormatDecision D) {
|
||||
Decision = D;
|
||||
assert(getDecision() == D && "FormatDecision overflow!");
|
||||
}
|
||||
|
||||
private:
|
||||
/// If this is an opening parenthesis, how are the parameters packed?
|
||||
unsigned PackingKind : 2;
|
||||
|
||||
public:
|
||||
ParameterPackingKind getPackingKind() const {
|
||||
return static_cast<ParameterPackingKind>(PackingKind);
|
||||
}
|
||||
void setPackingKind(ParameterPackingKind K) {
|
||||
PackingKind = K;
|
||||
assert(getPackingKind() == K && "ParameterPackingKind overflow!");
|
||||
}
|
||||
|
||||
/// The number of newlines immediately before the \c Token.
|
||||
///
|
||||
/// This can be used to determine what the user wrote in the original code
|
||||
/// and thereby e.g. leave an empty line between two function definitions.
|
||||
unsigned NewlinesBefore = 0;
|
||||
|
||||
/// Whether there is at least one unescaped newline before the \c
|
||||
/// Token.
|
||||
bool HasUnescapedNewline = false;
|
||||
|
||||
/// The range of the whitespace immediately preceding the \c Token.
|
||||
SourceRange WhitespaceRange;
|
||||
|
||||
/// The offset just past the last '\n' in this token's leading
|
||||
/// whitespace (relative to \c WhiteSpaceStart). 0 if there is no '\n'.
|
||||
unsigned LastNewlineOffset = 0;
|
||||
|
@ -171,50 +288,9 @@ struct FormatToken {
|
|||
/// token.
|
||||
unsigned LastLineColumnWidth = 0;
|
||||
|
||||
/// Whether the token text contains newlines (escaped or not).
|
||||
bool IsMultiline = false;
|
||||
|
||||
/// Indicates that this is the first token of the file.
|
||||
bool IsFirst = false;
|
||||
|
||||
/// Whether there must be a line break before this token.
|
||||
///
|
||||
/// This happens for example when a preprocessor directive ended directly
|
||||
/// before the token.
|
||||
bool MustBreakBefore = false;
|
||||
|
||||
/// Whether to not align across this token
|
||||
///
|
||||
/// This happens for example when a preprocessor directive ended directly
|
||||
/// before the token, but very rarely otherwise.
|
||||
bool MustBreakAlignBefore = false;
|
||||
|
||||
/// The raw text of the token.
|
||||
///
|
||||
/// Contains the raw token text without leading whitespace and without leading
|
||||
/// escaped newlines.
|
||||
StringRef TokenText;
|
||||
|
||||
/// Set to \c true if this token is an unterminated literal.
|
||||
bool IsUnterminatedLiteral = 0;
|
||||
|
||||
/// Contains the kind of block if this token is a brace.
|
||||
BraceBlockKind BlockKind = BK_Unknown;
|
||||
|
||||
/// Returns the token's type, e.g. whether "<" is a template opener or
|
||||
/// binary operator.
|
||||
TokenType getType() const { return Type; }
|
||||
void setType(TokenType T) { Type = T; }
|
||||
|
||||
/// The number of spaces that should be inserted before this token.
|
||||
unsigned SpacesRequiredBefore = 0;
|
||||
|
||||
/// \c true if it is allowed to break before this token.
|
||||
bool CanBreakBefore = false;
|
||||
|
||||
/// \c true if this is the ">" of "template<..>".
|
||||
bool ClosesTemplateDeclaration = false;
|
||||
|
||||
/// Number of parameters, if this is "(", "[" or "<".
|
||||
unsigned ParameterCount = 0;
|
||||
|
||||
|
@ -226,13 +302,6 @@ struct FormatToken {
|
|||
/// the surrounding bracket.
|
||||
tok::TokenKind ParentBracket = tok::unknown;
|
||||
|
||||
/// A token can have a special role that can carry extra information
|
||||
/// about the token's formatting.
|
||||
std::unique_ptr<TokenRole> Role;
|
||||
|
||||
/// If this is an opening parenthesis, how are the parameters packed?
|
||||
ParameterPackingKind PackingKind = PPK_Inconclusive;
|
||||
|
||||
/// The total length of the unwrapped line up to and including this
|
||||
/// token.
|
||||
unsigned TotalLength = 0;
|
||||
|
@ -286,12 +355,6 @@ struct FormatToken {
|
|||
/// Insert this many fake ) after this token for correct indentation.
|
||||
unsigned FakeRParens = 0;
|
||||
|
||||
/// \c true if this token starts a binary expression, i.e. has at least
|
||||
/// one fake l_paren with a precedence greater than prec::Unknown.
|
||||
bool StartsBinaryExpression = false;
|
||||
/// \c true if this token ends a binary expression.
|
||||
bool EndsBinaryExpression = false;
|
||||
|
||||
/// If this is an operator (or "."/"->") in a sequence of operators
|
||||
/// with the same precedence, contains the 0-based operator index.
|
||||
unsigned OperatorIndex = 0;
|
||||
|
@ -300,16 +363,6 @@ struct FormatToken {
|
|||
/// with the same precedence, points to the next operator.
|
||||
FormatToken *NextOperator = nullptr;
|
||||
|
||||
/// Is this token part of a \c DeclStmt defining multiple variables?
|
||||
///
|
||||
/// Only set if \c Type == \c TT_StartOfName.
|
||||
bool PartOfMultiVariableDeclStmt = false;
|
||||
|
||||
/// Does this line comment continue a line comment section?
|
||||
///
|
||||
/// Only set to true if \c Type == \c TT_LineComment.
|
||||
bool ContinuesLineCommentSection = false;
|
||||
|
||||
/// If this is a bracket, this points to the matching one.
|
||||
FormatToken *MatchingParen = nullptr;
|
||||
|
||||
|
@ -323,16 +376,8 @@ struct FormatToken {
|
|||
/// in it.
|
||||
SmallVector<AnnotatedLine *, 1> Children;
|
||||
|
||||
/// Stores the formatting decision for the token once it was made.
|
||||
FormatDecision Decision = FD_Unformatted;
|
||||
|
||||
/// If \c true, this token has been fully formatted (indented and
|
||||
/// potentially re-formatted inside), and we do not allow further formatting
|
||||
/// changes.
|
||||
bool Finalized = false;
|
||||
|
||||
bool is(tok::TokenKind Kind) const { return Tok.is(Kind); }
|
||||
bool is(TokenType TT) const { return Type == TT; }
|
||||
bool is(TokenType TT) const { return getType() == TT; }
|
||||
bool is(const IdentifierInfo *II) const {
|
||||
return II && II == Tok.getIdentifierInfo();
|
||||
}
|
||||
|
@ -340,6 +385,9 @@ struct FormatToken {
|
|||
return Tok.getIdentifierInfo() &&
|
||||
Tok.getIdentifierInfo()->getPPKeywordID() == Kind;
|
||||
}
|
||||
bool is(BraceBlockKind BBK) const { return getBlockKind() == BBK; }
|
||||
bool is(ParameterPackingKind PPK) const { return getPackingKind() == PPK; }
|
||||
|
||||
template <typename A, typename B> bool isOneOf(A K1, B K2) const {
|
||||
return is(K1) || is(K2);
|
||||
}
|
||||
|
@ -355,7 +403,7 @@ struct FormatToken {
|
|||
}
|
||||
|
||||
bool closesScopeAfterBlock() const {
|
||||
if (BlockKind == BK_Block)
|
||||
if (getBlockKind() == BK_Block)
|
||||
return true;
|
||||
if (closesScope())
|
||||
return Previous->closesScopeAfterBlock();
|
||||
|
@ -525,13 +573,13 @@ struct FormatToken {
|
|||
/// list that should be indented with a block indent.
|
||||
bool opensBlockOrBlockTypeList(const FormatStyle &Style) const {
|
||||
// C# Does not indent object initialisers as continuations.
|
||||
if (is(tok::l_brace) && BlockKind == BK_BracedInit && Style.isCSharp())
|
||||
if (is(tok::l_brace) && getBlockKind() == BK_BracedInit && Style.isCSharp())
|
||||
return true;
|
||||
if (is(TT_TemplateString) && opensScope())
|
||||
return true;
|
||||
return is(TT_ArrayInitializerLSquare) || is(TT_ProtoExtensionLSquare) ||
|
||||
(is(tok::l_brace) &&
|
||||
(BlockKind == BK_Block || is(TT_DictLiteral) ||
|
||||
(getBlockKind() == BK_Block || is(TT_DictLiteral) ||
|
||||
(!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
|
||||
(is(tok::less) && (Style.Language == FormatStyle::LK_Proto ||
|
||||
Style.Language == FormatStyle::LK_TextProto));
|
||||
|
@ -602,8 +650,6 @@ private:
|
|||
return Previous->endsSequenceInternal(K1, Tokens...);
|
||||
return is(K1) && Previous && Previous->endsSequenceInternal(Tokens...);
|
||||
}
|
||||
|
||||
TokenType Type = TT_Unknown;
|
||||
};
|
||||
|
||||
class ContinuationIndenter;
|
||||
|
|
|
@ -343,11 +343,11 @@ private:
|
|||
CurrentToken->setType(TT_AttributeSquare);
|
||||
|
||||
if (!HasMultipleLines)
|
||||
Left->PackingKind = PPK_Inconclusive;
|
||||
Left->setPackingKind(PPK_Inconclusive);
|
||||
else if (HasMultipleParametersOnALine)
|
||||
Left->PackingKind = PPK_BinPacked;
|
||||
Left->setPackingKind(PPK_BinPacked);
|
||||
else
|
||||
Left->PackingKind = PPK_OnePerLine;
|
||||
Left->setPackingKind(PPK_OnePerLine);
|
||||
|
||||
next();
|
||||
return true;
|
||||
|
@ -704,7 +704,7 @@ private:
|
|||
|
||||
ScopedContextCreator ContextCreator(*this, tok::l_brace, 1);
|
||||
Contexts.back().ColonIsDictLiteral = true;
|
||||
if (Left->BlockKind == BK_BracedInit)
|
||||
if (Left->is(BK_BracedInit))
|
||||
Contexts.back().IsExpression = true;
|
||||
if (Style.Language == FormatStyle::LK_JavaScript && Left->Previous &&
|
||||
Left->Previous->is(TT_JsTypeColon))
|
||||
|
@ -751,7 +751,7 @@ private:
|
|||
// For ObjC methods, the number of parameters is calculated differently as
|
||||
// method declarations have a different structure (the parameters are not
|
||||
// inside a bracket scope).
|
||||
if (Current->is(tok::l_brace) && Current->BlockKind == BK_Block)
|
||||
if (Current->is(tok::l_brace) && Current->is(BK_Block))
|
||||
++Left->BlockParameterCount;
|
||||
if (Current->is(tok::comma)) {
|
||||
++Left->ParameterCount;
|
||||
|
@ -2420,7 +2420,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
|
|||
if (isFunctionDeclarationName(*Current, Line))
|
||||
Current->setType(TT_FunctionDeclarationName);
|
||||
if (Current->is(TT_LineComment)) {
|
||||
if (Current->Previous->BlockKind == BK_BracedInit &&
|
||||
if (Current->Previous->is(BK_BracedInit) &&
|
||||
Current->Previous->opensScope())
|
||||
Current->SpacesRequiredBefore =
|
||||
(Style.Cpp11BracedListStyle && !Style.SpacesInParentheses) ? 0 : 1;
|
||||
|
@ -2755,8 +2755,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
if (Left.isOneOf(tok::hashhash, tok::hash))
|
||||
return Right.is(tok::hash);
|
||||
if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
|
||||
(Left.is(tok::l_brace) && Left.BlockKind != BK_Block &&
|
||||
Right.is(tok::r_brace) && Right.BlockKind != BK_Block))
|
||||
(Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
|
||||
Right.is(tok::r_brace) && Right.isNot(BK_Block)))
|
||||
return Style.SpaceInEmptyParentheses;
|
||||
if (Style.SpacesInConditionalStatement) {
|
||||
if (Left.is(tok::l_paren) && Left.Previous &&
|
||||
|
@ -2836,7 +2836,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
return Right.Tok.isLiteral() || Right.is(TT_BlockComment) ||
|
||||
(Right.isOneOf(Keywords.kw_override, Keywords.kw_final) &&
|
||||
!Right.is(TT_StartOfName)) ||
|
||||
(Right.is(tok::l_brace) && Right.BlockKind == BK_Block) ||
|
||||
(Right.is(tok::l_brace) && Right.is(BK_Block)) ||
|
||||
(!Right.isOneOf(TT_PointerOrReference, TT_ArraySubscriptLSquare,
|
||||
tok::l_paren) &&
|
||||
(Style.PointerAlignment != FormatStyle::PAS_Right &&
|
||||
|
@ -2921,9 +2921,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
return false;
|
||||
if (Left.is(tok::l_brace) && Right.is(tok::r_brace))
|
||||
return !Left.Children.empty(); // No spaces in "{}".
|
||||
if ((Left.is(tok::l_brace) && Left.BlockKind != BK_Block) ||
|
||||
if ((Left.is(tok::l_brace) && Left.isNot(BK_Block)) ||
|
||||
(Right.is(tok::r_brace) && Right.MatchingParen &&
|
||||
Right.MatchingParen->BlockKind != BK_Block))
|
||||
Right.MatchingParen->isNot(BK_Block)))
|
||||
return Style.Cpp11BracedListStyle ? Style.SpacesInParentheses : true;
|
||||
if (Left.is(TT_BlockComment))
|
||||
// No whitespace in x(/*foo=*/1), except for JavaScript.
|
||||
|
@ -2967,7 +2967,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
|||
tok::r_paren) ||
|
||||
Left.isSimpleTypeSpecifier()) &&
|
||||
Right.is(tok::l_brace) && Right.getNextNonComment() &&
|
||||
Right.BlockKind != BK_Block)
|
||||
Right.isNot(BK_Block))
|
||||
return false;
|
||||
if (Left.is(tok::period) || Right.is(tok::period))
|
||||
return false;
|
||||
|
@ -3009,7 +3009,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
|||
if (Style.isCpp()) {
|
||||
if (Left.is(tok::kw_operator))
|
||||
return Right.is(tok::coloncolon);
|
||||
if (Right.is(tok::l_brace) && Right.BlockKind == BK_BracedInit &&
|
||||
if (Right.is(tok::l_brace) && Right.is(BK_BracedInit) &&
|
||||
!Left.opensScope() && Style.SpaceBeforeCpp11BracedList)
|
||||
return true;
|
||||
} else if (Style.Language == FormatStyle::LK_Proto ||
|
||||
|
@ -3362,7 +3362,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
|
|||
|
||||
// Returns 'true' if 'Tok' is a brace we'd want to break before in Allman style.
|
||||
static bool isAllmanBrace(const FormatToken &Tok) {
|
||||
return Tok.is(tok::l_brace) && Tok.BlockKind == BK_Block &&
|
||||
return Tok.is(tok::l_brace) && Tok.is(BK_Block) &&
|
||||
!Tok.isOneOf(TT_ObjCBlockLBrace, TT_LambdaLBrace, TT_DictLiteral);
|
||||
}
|
||||
|
||||
|
@ -3398,7 +3398,7 @@ static bool isOneChildWithoutMustBreakBefore(const FormatToken &Tok) {
|
|||
return true;
|
||||
}
|
||||
static bool isAllmanLambdaBrace(const FormatToken &Tok) {
|
||||
return (Tok.is(tok::l_brace) && Tok.BlockKind == BK_Block &&
|
||||
return (Tok.is(tok::l_brace) && Tok.is(BK_Block) &&
|
||||
!Tok.isOneOf(TT_ObjCBlockLBrace, TT_DictLiteral));
|
||||
}
|
||||
|
||||
|
@ -3498,7 +3498,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
|
|||
if ((Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
|
||||
(Style.Language == FormatStyle::LK_JavaScript &&
|
||||
Left.is(tok::l_paren))) &&
|
||||
Left.BlockKind != BK_Block && Left.MatchingParen)
|
||||
Left.isNot(BK_Block) && Left.MatchingParen)
|
||||
BeforeClosingBrace = Left.MatchingParen->Previous;
|
||||
else if (Right.MatchingParen &&
|
||||
(Right.MatchingParen->isOneOf(tok::l_brace,
|
||||
|
@ -3512,8 +3512,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
|
|||
}
|
||||
|
||||
if (Right.is(tok::comment))
|
||||
return Left.BlockKind != BK_BracedInit &&
|
||||
Left.isNot(TT_CtorInitializerColon) &&
|
||||
return Left.isNot(BK_BracedInit) && Left.isNot(TT_CtorInitializerColon) &&
|
||||
(Right.NewlinesBefore > 0 && Right.HasUnescapedNewline);
|
||||
if (Left.isTrailingComment())
|
||||
return true;
|
||||
|
@ -3822,7 +3821,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
|
|||
// The first comment in a braced lists is always interpreted as belonging to
|
||||
// the first list element. Otherwise, it should be placed outside of the
|
||||
// list.
|
||||
return Left.BlockKind == BK_BracedInit ||
|
||||
return Left.is(BK_BracedInit) ||
|
||||
(Left.is(TT_CtorInitializerColon) &&
|
||||
Style.BreakConstructorInitializers == FormatStyle::BCIS_AfterColon);
|
||||
if (Left.is(tok::question) && Right.is(tok::colon))
|
||||
|
@ -3923,7 +3922,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
|
|||
// We only break before r_brace if there was a corresponding break before
|
||||
// the l_brace, which is tracked by BreakBeforeClosingBrace.
|
||||
if (Right.is(tok::r_brace))
|
||||
return Right.MatchingParen && Right.MatchingParen->BlockKind == BK_Block;
|
||||
return Right.MatchingParen && Right.MatchingParen->is(BK_Block);
|
||||
|
||||
// Allow breaking after a trailing annotation, e.g. after a method
|
||||
// declaration.
|
||||
|
@ -4008,9 +4007,9 @@ void TokenAnnotator::printDebugInfo(const AnnotatedLine &Line) {
|
|||
<< " T=" << getTokenTypeName(Tok->getType())
|
||||
<< " S=" << Tok->SpacesRequiredBefore
|
||||
<< " F=" << Tok->Finalized << " B=" << Tok->BlockParameterCount
|
||||
<< " BK=" << Tok->BlockKind << " P=" << Tok->SplitPenalty
|
||||
<< " BK=" << Tok->getBlockKind() << " P=" << Tok->SplitPenalty
|
||||
<< " Name=" << Tok->Tok.getName() << " L=" << Tok->TotalLength
|
||||
<< " PPK=" << Tok->PackingKind << " FakeLParens=";
|
||||
<< " PPK=" << Tok->getPackingKind() << " FakeLParens=";
|
||||
for (unsigned i = 0, e = Tok->FakeLParens.size(); i != e; ++i)
|
||||
llvm::errs() << Tok->FakeLParens[i] << "/";
|
||||
llvm::errs() << " FakeRParens=" << Tok->FakeRParens;
|
||||
|
|
|
@ -606,7 +606,7 @@ private:
|
|||
if (I[1]->Last->is(TT_LineComment))
|
||||
return 0;
|
||||
do {
|
||||
if (Tok->is(tok::l_brace) && Tok->BlockKind != BK_BracedInit)
|
||||
if (Tok->is(tok::l_brace) && Tok->isNot(BK_BracedInit))
|
||||
return 0;
|
||||
Tok = Tok->Next;
|
||||
} while (Tok);
|
||||
|
@ -767,8 +767,8 @@ protected:
|
|||
unsigned &Penalty) {
|
||||
const FormatToken *LBrace = State.NextToken->getPreviousNonComment();
|
||||
FormatToken &Previous = *State.NextToken->Previous;
|
||||
if (!LBrace || LBrace->isNot(tok::l_brace) ||
|
||||
LBrace->BlockKind != BK_Block || Previous.Children.size() == 0)
|
||||
if (!LBrace || LBrace->isNot(tok::l_brace) || LBrace->isNot(BK_Block) ||
|
||||
Previous.Children.size() == 0)
|
||||
// The previous token does not open a block. Nothing to do. We don't
|
||||
// assert so that we can simply call this function for all tokens.
|
||||
return true;
|
||||
|
@ -979,7 +979,7 @@ private:
|
|||
// State already examined with lower penalty.
|
||||
continue;
|
||||
|
||||
FormatDecision LastFormat = Node->State.NextToken->Decision;
|
||||
FormatDecision LastFormat = Node->State.NextToken->getDecision();
|
||||
if (LastFormat == FD_Unformatted || LastFormat == FD_Continue)
|
||||
addNextStateToQueue(Penalty, Node, /*NewLine=*/false, &Count, &Queue);
|
||||
if (LastFormat == FD_Unformatted || LastFormat == FD_Break)
|
||||
|
|
|
@ -472,19 +472,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
|
|||
// individual members in a type member list, which would normally
|
||||
// trigger BK_Block. In both cases, this must be parsed as an inline
|
||||
// braced init.
|
||||
Tok->BlockKind = BK_BracedInit;
|
||||
Tok->setBlockKind(BK_BracedInit);
|
||||
else if (PrevTok->is(tok::r_paren))
|
||||
// `) { }` can only occur in function or method declarations in JS.
|
||||
Tok->BlockKind = BK_Block;
|
||||
Tok->setBlockKind(BK_Block);
|
||||
} else {
|
||||
Tok->BlockKind = BK_Unknown;
|
||||
Tok->setBlockKind(BK_Unknown);
|
||||
}
|
||||
LBraceStack.push_back(Tok);
|
||||
break;
|
||||
case tok::r_brace:
|
||||
if (LBraceStack.empty())
|
||||
break;
|
||||
if (LBraceStack.back()->BlockKind == BK_Unknown) {
|
||||
if (LBraceStack.back()->is(BK_Unknown)) {
|
||||
bool ProbablyBracedList = false;
|
||||
if (Style.Language == FormatStyle::LK_Proto) {
|
||||
ProbablyBracedList = NextTok->isOneOf(tok::comma, tok::r_square);
|
||||
|
@ -524,11 +524,11 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
|
|||
}
|
||||
}
|
||||
if (ProbablyBracedList) {
|
||||
Tok->BlockKind = BK_BracedInit;
|
||||
LBraceStack.back()->BlockKind = BK_BracedInit;
|
||||
Tok->setBlockKind(BK_BracedInit);
|
||||
LBraceStack.back()->setBlockKind(BK_BracedInit);
|
||||
} else {
|
||||
Tok->BlockKind = BK_Block;
|
||||
LBraceStack.back()->BlockKind = BK_Block;
|
||||
Tok->setBlockKind(BK_Block);
|
||||
LBraceStack.back()->setBlockKind(BK_Block);
|
||||
}
|
||||
}
|
||||
LBraceStack.pop_back();
|
||||
|
@ -545,8 +545,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
|
|||
case tok::kw_switch:
|
||||
case tok::kw_try:
|
||||
case tok::kw___try:
|
||||
if (!LBraceStack.empty() && LBraceStack.back()->BlockKind == BK_Unknown)
|
||||
LBraceStack.back()->BlockKind = BK_Block;
|
||||
if (!LBraceStack.empty() && LBraceStack.back()->is(BK_Unknown))
|
||||
LBraceStack.back()->setBlockKind(BK_Block);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -557,8 +557,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
|
|||
|
||||
// Assume other blocks for all unclosed opening braces.
|
||||
for (unsigned i = 0, e = LBraceStack.size(); i != e; ++i) {
|
||||
if (LBraceStack[i]->BlockKind == BK_Unknown)
|
||||
LBraceStack[i]->BlockKind = BK_Block;
|
||||
if (LBraceStack[i]->is(BK_Unknown))
|
||||
LBraceStack[i]->setBlockKind(BK_Block);
|
||||
}
|
||||
|
||||
FormatTok = Tokens->setPosition(StoredPosition);
|
||||
|
@ -584,7 +584,7 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
|
|||
assert(FormatTok->isOneOf(tok::l_brace, TT_MacroBlockBegin) &&
|
||||
"'{' or macro block token expected");
|
||||
const bool MacroBlock = FormatTok->is(TT_MacroBlockBegin);
|
||||
FormatTok->BlockKind = BK_Block;
|
||||
FormatTok->setBlockKind(BK_Block);
|
||||
|
||||
size_t PPStartHash = computePPHash();
|
||||
|
||||
|
@ -614,7 +614,7 @@ void UnwrappedLineParser::parseBlock(bool MustBeDeclaration, bool AddLevel,
|
|||
if (MacroBlock ? !FormatTok->is(TT_MacroBlockEnd)
|
||||
: !FormatTok->is(tok::r_brace)) {
|
||||
Line->Level = InitialLevel;
|
||||
FormatTok->BlockKind = BK_Block;
|
||||
FormatTok->setBlockKind(BK_Block);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -690,7 +690,7 @@ static bool ShouldBreakBeforeBrace(const FormatStyle &Style,
|
|||
}
|
||||
|
||||
void UnwrappedLineParser::parseChildBlock() {
|
||||
FormatTok->BlockKind = BK_Block;
|
||||
FormatTok->setBlockKind(BK_Block);
|
||||
nextToken();
|
||||
{
|
||||
bool SkipIndent = (Style.Language == FormatStyle::LK_JavaScript &&
|
||||
|
@ -1476,7 +1476,7 @@ void UnwrappedLineParser::parseStructuralElement() {
|
|||
// C# needs this change to ensure that array initialisers and object
|
||||
// initialisers are indented the same way.
|
||||
if (Style.isCSharp())
|
||||
FormatTok->BlockKind = BK_BracedInit;
|
||||
FormatTok->setBlockKind(BK_BracedInit);
|
||||
nextToken();
|
||||
parseBracedList();
|
||||
} else if (Style.Language == FormatStyle::LK_Proto &&
|
||||
|
@ -1747,10 +1747,10 @@ void UnwrappedLineParser::tryToParseJSFunction() {
|
|||
}
|
||||
|
||||
bool UnwrappedLineParser::tryToParseBracedList() {
|
||||
if (FormatTok->BlockKind == BK_Unknown)
|
||||
if (FormatTok->is(BK_Unknown))
|
||||
calculateBraceTypes();
|
||||
assert(FormatTok->BlockKind != BK_Unknown);
|
||||
if (FormatTok->BlockKind == BK_Block)
|
||||
assert(FormatTok->isNot(BK_Unknown));
|
||||
if (FormatTok->is(BK_Block))
|
||||
return false;
|
||||
nextToken();
|
||||
parseBracedList();
|
||||
|
@ -1830,7 +1830,7 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
|
|||
case tok::l_brace:
|
||||
// Assume there are no blocks inside a braced init list apart
|
||||
// from the ones we explicitly parse out (like lambdas).
|
||||
FormatTok->BlockKind = BK_BracedInit;
|
||||
FormatTok->setBlockKind(BK_BracedInit);
|
||||
nextToken();
|
||||
parseBracedList();
|
||||
break;
|
||||
|
@ -2318,7 +2318,7 @@ bool UnwrappedLineParser::parseEnum() {
|
|||
// Just a declaration or something is wrong.
|
||||
if (FormatTok->isNot(tok::l_brace))
|
||||
return true;
|
||||
FormatTok->BlockKind = BK_Block;
|
||||
FormatTok->setBlockKind(BK_Block);
|
||||
|
||||
if (Style.Language == FormatStyle::LK_Java) {
|
||||
// Java enums are different.
|
||||
|
@ -2726,7 +2726,7 @@ void UnwrappedLineParser::parseJavaScriptEs6ImportExport() {
|
|||
return;
|
||||
}
|
||||
if (FormatTok->is(tok::l_brace)) {
|
||||
FormatTok->BlockKind = BK_Block;
|
||||
FormatTok->setBlockKind(BK_Block);
|
||||
nextToken();
|
||||
parseBracedList();
|
||||
} else {
|
||||
|
|
|
@ -49,7 +49,7 @@ void WhitespaceManager::replaceWhitespace(FormatToken &Tok, unsigned Newlines,
|
|||
bool IsAligned, bool InPPDirective) {
|
||||
if (Tok.Finalized)
|
||||
return;
|
||||
Tok.Decision = (Newlines > 0) ? FD_Break : FD_Continue;
|
||||
Tok.setDecision((Newlines > 0) ? FD_Break : FD_Continue);
|
||||
Changes.push_back(Change(Tok, /*CreateReplacement=*/true, Tok.WhitespaceRange,
|
||||
Spaces, StartOfTokenColumn, Newlines, "", "",
|
||||
IsAligned, InPPDirective && !Tok.IsFirst,
|
||||
|
|
Loading…
Reference in New Issue