Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/lib/Format/IntegerLiteralSeparatorFixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ IntegerLiteralSeparatorFixer::process(const Environment &Env,
}
if (Style.isCpp()) {
// Hex alpha digits a-f/A-F must be at the end of the string literal.
StringRef Suffixes = "_himnsuyd";
static constexpr StringRef Suffixes("_himnsuyd");
if (const auto Pos =
Text.find_first_of(IsBase16 ? Suffixes.drop_back() : Suffixes);
Pos != StringRef::npos) {
Expand Down
48 changes: 22 additions & 26 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ class AnnotatingParser {
Contexts.back().IsExpression = true;
next();
if (CurrentToken)
CurrentToken->SpacesRequiredBefore = true;
CurrentToken->SpacesRequiredBefore = 1;
parseLine();
break;
default:
Expand Down Expand Up @@ -2639,8 +2639,8 @@ class AnnotatingParser {
if (PreviousNotConst->is(TT_TemplateCloser)) {
return PreviousNotConst && PreviousNotConst->MatchingParen &&
PreviousNotConst->MatchingParen->Previous &&
PreviousNotConst->MatchingParen->Previous->isNot(tok::period) &&
PreviousNotConst->MatchingParen->Previous->isNot(tok::kw_template);
!PreviousNotConst->MatchingParen->Previous->isOneOf(
tok::period, tok::kw_template);
}

if ((PreviousNotConst->is(tok::r_paren) &&
Expand Down Expand Up @@ -3369,7 +3369,7 @@ class ExpressionParser {
Current->isOneOf(Keywords.kw_in, Keywords.kw_as)) {
return prec::Relational;
}
if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
if (Current->isOneOf(TT_BinaryOperator, tok::comma))
return Current->getPrecedence();
if (Current->isOneOf(tok::period, tok::arrow) &&
Current->isNot(TT_TrailingReturnArrow)) {
Expand Down Expand Up @@ -4314,8 +4314,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,

if (Left.is(tok::coloncolon))
return Style.PenaltyBreakScopeResolution;
if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName) ||
Right.is(tok::kw_operator)) {
if (Right.isOneOf(TT_StartOfName, TT_FunctionDeclarationName,
tok::kw_operator)) {
if (Line.startsWith(tok::kw_for) && Right.PartOfMultiVariableDeclStmt)
return 3;
if (Left.is(TT_StartOfName))
Expand Down Expand Up @@ -4757,7 +4757,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
if (Previous) {
if (Previous->endsSequence(tok::kw_operator))
return Style.PointerAlignment != FormatStyle::PAS_Left;
if (Previous->is(tok::kw_const) || Previous->is(tok::kw_volatile)) {
if (Previous->isOneOf(tok::kw_const, tok::kw_volatile)) {
return (Style.PointerAlignment != FormatStyle::PAS_Left) ||
(Style.SpaceAroundPointerQualifiers ==
FormatStyle::SAPQ_After) ||
Expand Down Expand Up @@ -4931,8 +4931,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
}
if (Left.is(TT_TemplateCloser) && Left.MatchingParen &&
Left.MatchingParen->Previous &&
(Left.MatchingParen->Previous->is(tok::period) ||
Left.MatchingParen->Previous->is(tok::coloncolon))) {
Left.MatchingParen->Previous->isOneOf(tok::period, tok::coloncolon)) {
// Java call to generic function with explicit type:
// A.<B<C<...>>>DoSomething();
// A::<B<C<...>>>DoSomething(); // With a Java 8 method reference.
Expand Down Expand Up @@ -5207,8 +5206,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
// (e.g. as "const x of y" in a for loop), or after a destructuring
// operation (const [x, y] of z, const {a, b} of c).
(Left.is(Keywords.kw_of) && BeforeLeft &&
(BeforeLeft->is(tok::identifier) ||
BeforeLeft->isOneOf(tok::r_square, tok::r_brace)))) &&
BeforeLeft->isOneOf(tok::identifier, tok::r_square, tok::r_brace))) &&
(!BeforeLeft || BeforeLeft->isNot(tok::period))) {
return true;
}
Expand Down Expand Up @@ -5516,7 +5514,7 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
return false;
}
if (Style.isJava() && Right.is(tok::coloncolon) &&
(Left.is(tok::identifier) || Left.is(tok::kw_this))) {
Left.isOneOf(tok::identifier, tok::kw_this)) {
return false;
}
if (Right.is(tok::coloncolon) && Left.is(tok::identifier)) {
Expand Down Expand Up @@ -5587,8 +5585,8 @@ static bool IsFunctionArgument(const FormatToken &Tok) {
}

static bool
isItAnEmptyLambdaAllowed(const FormatToken &Tok,
FormatStyle::ShortLambdaStyle ShortLambdaOption) {
isEmptyLambdaAllowed(const FormatToken &Tok,
FormatStyle::ShortLambdaStyle ShortLambdaOption) {
return Tok.Children.empty() && ShortLambdaOption != FormatStyle::SLS_None;
}

Expand Down Expand Up @@ -5808,8 +5806,8 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
}

if (Right.is(tok::comment)) {
return Left.isNot(BK_BracedInit) && Left.isNot(TT_CtorInitializerColon) &&
(Right.NewlinesBefore > 0 && Right.HasUnescapedNewline);
return !Left.isOneOf(BK_BracedInit, TT_CtorInitializerColon) &&
Right.NewlinesBefore > 0 && Right.HasUnescapedNewline;
}
if (Left.isTrailingComment())
return true;
Expand Down Expand Up @@ -5977,7 +5975,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
// Put multiple Java annotation on a new line.
if ((Style.isJava() || Style.isJavaScript()) &&
Left.is(TT_LeadingJavaAnnotation) &&
Right.isNot(TT_LeadingJavaAnnotation) && Right.isNot(tok::l_paren) &&
!Right.isOneOf(TT_LeadingJavaAnnotation, tok::l_paren) &&
(Line.Last->is(tok::l_brace) || Style.BreakAfterJavaFieldAnnotations)) {
return true;
}
Expand Down Expand Up @@ -6043,7 +6041,7 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
((LBrace->is(tok::l_brace) &&
(LBrace->is(TT_DictLiteral) ||
(LBrace->Next && LBrace->Next->is(tok::r_brace)))) ||
LBrace->is(TT_ArrayInitializerLSquare) || LBrace->is(tok::less))) {
LBrace->isOneOf(TT_ArrayInitializerLSquare, tok::less))) {
// If Left.ParameterCount is 0, then this submessage entry is not the
// first in its parent submessage, and we want to break before this entry.
// If Left.ParameterCount is greater than 0, then its parent submessage
Expand Down Expand Up @@ -6257,9 +6255,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
}
if (Left.is(tok::question) && Right.is(tok::colon))
return false;
if (Right.is(TT_ConditionalExpr) || Right.is(tok::question))
if (Right.isOneOf(TT_ConditionalExpr, tok::question))
return Style.BreakBeforeTernaryOperators;
if (Left.is(TT_ConditionalExpr) || Left.is(tok::question))
if (Left.isOneOf(TT_ConditionalExpr, tok::question))
return !Style.BreakBeforeTernaryOperators;
if (Left.is(TT_InheritanceColon))
return Style.BreakInheritanceList == FormatStyle::BILS_AfterColon;
Expand Down Expand Up @@ -6302,7 +6300,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
// submessage: { ... }
// submessage: < ... >
// repeated: [ ... ]
if (((Right.is(tok::l_brace) || Right.is(tok::less)) &&
if ((Right.isOneOf(tok::l_brace, tok::less) &&
Right.is(TT_DictLiteral)) ||
Right.is(TT_ArrayInitializerLSquare)) {
return false;
Expand Down Expand Up @@ -6352,10 +6350,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
Right.getPrecedence() != prec::Assignment)) {
return true;
}
if (Left.isOneOf(TT_TemplateCloser, TT_UnaryOperator) ||
Left.is(tok::kw_operator)) {
if (Left.isOneOf(TT_TemplateCloser, TT_UnaryOperator, tok::kw_operator))
return false;
}
if (Left.is(tok::equal) && !Right.isOneOf(tok::kw_default, tok::kw_delete) &&
Line.Type == LT_VirtualFunctionDecl && Left.NestingLevel == 0) {
return false;
Expand Down Expand Up @@ -6440,9 +6436,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
auto ShortLambdaOption = Style.AllowShortLambdasOnASingleLine;
if (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace)) {
if (isAllmanLambdaBrace(Left))
return !isItAnEmptyLambdaAllowed(Left, ShortLambdaOption);
return !isEmptyLambdaAllowed(Left, ShortLambdaOption);
if (isAllmanLambdaBrace(Right))
return !isItAnEmptyLambdaAllowed(Right, ShortLambdaOption);
return !isEmptyLambdaAllowed(Right, ShortLambdaOption);
}

if (Right.is(tok::kw_noexcept) && Right.is(TT_TrailingAnnotation)) {
Expand Down