aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format')
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp97
-rw-r--r--clang/lib/Format/Format.cpp111
-rw-r--r--clang/lib/Format/FormatToken.cpp4
-rw-r--r--clang/lib/Format/FormatToken.h6
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp30
5 files changed, 187 insertions, 61 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index e5abf83..9ab024a 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -356,9 +356,11 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
return CurrentState.BreakBeforeClosingBrace;
}
- // Allow breaking before the right parens with block indentation if there was
- // a break after the left parens, which is tracked by BreakBeforeClosingParen.
- if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
+ // Check need to break before the right parens if there was a break after
+ // the left parens, which is tracked by BreakBeforeClosingParen.
+ if ((Style.BreakBeforeCloseBracketFunction ||
+ Style.BreakBeforeCloseBracketIf || Style.BreakBeforeCloseBracketLoop ||
+ Style.BreakBeforeCloseBracketSwitch) &&
Current.is(tok::r_paren)) {
return CurrentState.BreakBeforeClosingParen;
}
@@ -837,32 +839,38 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
return Tok.is(tok::l_brace) && Tok.isNot(BK_Block) &&
Style.Cpp11BracedListStyle != FormatStyle::BLS_Block;
};
- if (Tok.isNoneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) &&
- !IsStartOfBracedList()) {
+ if (IsStartOfBracedList())
+ return Style.BreakAfterOpenBracketBracedList;
+ if (Tok.isNoneOf(tok::l_paren, TT_TemplateOpener, tok::l_square))
return false;
- }
if (!Tok.Previous)
return true;
if (Tok.Previous->isIf())
- return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
- return Tok.Previous->isNoneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
- tok::kw_switch) &&
- !(Style.isJavaScript() && Tok.Previous->is(Keywords.kw_await));
+ return Style.BreakAfterOpenBracketIf;
+ if (Tok.Previous->isLoop(Style))
+ return Style.BreakAfterOpenBracketLoop;
+ if (Tok.Previous->is(tok::kw_switch))
+ return Style.BreakAfterOpenBracketSwitch;
+ if (Style.BreakAfterOpenBracketFunction) {
+ return !Tok.Previous->is(TT_CastRParen) &&
+ !(Style.isJavaScript() && Tok.is(Keywords.kw_await));
+ }
+ return false;
};
auto IsFunctionCallParen = [](const FormatToken &Tok) {
return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
Tok.Previous->is(tok::identifier);
};
- auto IsInTemplateString = [this](const FormatToken &Tok) {
+ auto IsInTemplateString = [this](const FormatToken &Tok, bool NestBlocks) {
if (!Style.isJavaScript())
return false;
for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) {
if (Prev->is(TT_TemplateString) && Prev->opensScope())
return true;
- if (Prev->opensScope() ||
- (Prev->is(TT_TemplateString) && Prev->closesScope())) {
- break;
- }
+ if (Prev->opensScope() && !NestBlocks)
+ return false;
+ if (Prev->is(TT_TemplateString) && Prev->closesScope())
+ return false;
}
return false;
};
@@ -884,21 +892,25 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
Tok.isOneOf(tok::ellipsis, Keywords.kw_await))) {
return true;
}
- if (const auto *Previous = Tok.Previous;
- !Previous || (Previous->isNoneOf(TT_FunctionDeclarationLParen,
- TT_LambdaDefinitionLParen) &&
- !IsFunctionCallParen(*Previous))) {
+ const auto *Previous = TokAfterLParen.Previous;
+ assert(Previous); // IsOpeningBracket(Previous)
+ if (Previous->Previous &&
+ (Previous->Previous->isIf() || Previous->Previous->isLoop(Style) ||
+ Previous->Previous->is(tok::kw_switch))) {
+ return false;
+ }
+ if (Previous->isNoneOf(TT_FunctionDeclarationLParen,
+ TT_LambdaDefinitionLParen) &&
+ !IsFunctionCallParen(*Previous)) {
return true;
}
- if (IsOpeningBracket(Tok) || IsInTemplateString(Tok))
+ if (IsOpeningBracket(Tok) || IsInTemplateString(Tok, true))
return true;
const auto *Next = Tok.Next;
return !Next || Next->isMemberAccess() ||
Next->is(TT_FunctionDeclarationLParen) || IsFunctionCallParen(*Next);
};
- if ((Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak ||
- Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) &&
- IsOpeningBracket(Previous) && State.Column > getNewLineColumn(State) &&
+ if (IsOpeningBracket(Previous) && State.Column > getNewLineColumn(State) &&
// Don't do this for simple (no expressions) one-argument function calls
// as that feels like needlessly wasting whitespace, e.g.:
//
@@ -920,7 +932,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
// Note: This doesn't apply to macro expansion lines, which are MACRO( , , )
// with args as children of the '(' and ',' tokens. It does not make sense to
// align the commas with the opening paren.
- if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
+ if (Style.AlignAfterOpenBracket &&
!CurrentState.IsCSharpGenericTypeConstraint && Previous.opensScope() &&
Previous.isNoneOf(TT_ObjCMethodExpr, TT_RequiresClause,
TT_TableGenDAGArgOpener,
@@ -933,7 +945,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
Previous.Previous->isNoneOf(tok::identifier, tok::l_paren,
BK_BracedInit))) ||
Previous.is(TT_VerilogMultiLineListLParen)) &&
- !IsInTemplateString(Current)) {
+ !IsInTemplateString(Current, false)) {
CurrentState.Indent = State.Column + Spaces;
CurrentState.IsAligned = true;
}
@@ -1271,8 +1283,20 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
}
if (PreviousNonComment && PreviousNonComment->is(tok::l_paren)) {
- CurrentState.BreakBeforeClosingParen =
- Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
+ if (auto Previous = PreviousNonComment->Previous) {
+ if (Previous->isIf()) {
+ CurrentState.BreakBeforeClosingParen = Style.BreakBeforeCloseBracketIf;
+ } else if (Previous->isLoop(Style)) {
+ CurrentState.BreakBeforeClosingParen =
+ Style.BreakBeforeCloseBracketLoop;
+ } else if (Previous->is(tok::kw_switch)) {
+ CurrentState.BreakBeforeClosingParen =
+ Style.BreakBeforeCloseBracketSwitch;
+ } else {
+ CurrentState.BreakBeforeClosingParen =
+ Style.BreakBeforeCloseBracketFunction;
+ }
+ }
}
if (PreviousNonComment && PreviousNonComment->is(TT_TemplateOpener))
@@ -1416,13 +1440,17 @@ unsigned ContinuationIndenter::getNewLineColumn(const LineState &State) {
State.Stack.size() > 1) {
return State.Stack[State.Stack.size() - 2].LastSpace;
}
- if (Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent &&
- (Current.is(tok::r_paren) ||
- (Current.is(tok::r_brace) && Current.MatchingParen &&
- Current.MatchingParen->is(BK_BracedInit))) &&
+ if (Style.BreakBeforeCloseBracketBracedList && Current.is(tok::r_brace) &&
+ Current.MatchingParen && Current.MatchingParen->is(BK_BracedInit) &&
State.Stack.size() > 1) {
return State.Stack[State.Stack.size() - 2].LastSpace;
}
+ if ((Style.BreakBeforeCloseBracketFunction ||
+ Style.BreakBeforeCloseBracketIf || Style.BreakBeforeCloseBracketLoop ||
+ Style.BreakBeforeCloseBracketSwitch) &&
+ Current.is(tok::r_paren) && State.Stack.size() > 1) {
+ return State.Stack[State.Stack.size() - 2].LastSpace;
+ }
if (Style.BreakBeforeTemplateCloser && Current.is(TT_TemplateCloser) &&
State.Stack.size() > 1) {
return State.Stack[State.Stack.size() - 2].LastSpace;
@@ -1844,8 +1872,8 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
PrecedenceLevel < prec::Assignment) &&
(!Previous || Previous->isNot(tok::kw_return) ||
(!Style.isJava() && PrecedenceLevel > 0)) &&
- (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
- PrecedenceLevel > prec::Comma || Current.NestingLevel == 0) &&
+ (Style.AlignAfterOpenBracket || PrecedenceLevel > prec::Comma ||
+ Current.NestingLevel == 0) &&
(!Style.isTableGen() ||
(Previous && Previous->isOneOf(TT_TableGenDAGArgListComma,
TT_TableGenDAGArgListCommaToBreak)))) {
@@ -1885,8 +1913,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
if (PrecedenceLevel > prec::Unknown)
NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
if (PrecedenceLevel != prec::Conditional &&
- Current.isNot(TT_UnaryOperator) &&
- Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) {
+ Current.isNot(TT_UnaryOperator) && Style.AlignAfterOpenBracket) {
NewParenState.StartOfFunctionCall = State.Column;
}
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index edd126c..dd14fcd 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -32,6 +32,13 @@ using clang::format::FormatStyle;
LLVM_YAML_IS_SEQUENCE_VECTOR(FormatStyle::RawStringFormat)
+enum BracketAlignmentStyle : int8_t {
+ BAS_Align,
+ BAS_DontAlign,
+ BAS_AlwaysBreak,
+ BAS_BlockIndent
+};
+
namespace llvm {
namespace yaml {
template <>
@@ -204,16 +211,16 @@ template <> struct MappingTraits<FormatStyle::BraceWrappingFlags> {
}
};
-template <> struct ScalarEnumerationTraits<FormatStyle::BracketAlignmentStyle> {
- static void enumeration(IO &IO, FormatStyle::BracketAlignmentStyle &Value) {
- IO.enumCase(Value, "Align", FormatStyle::BAS_Align);
- IO.enumCase(Value, "DontAlign", FormatStyle::BAS_DontAlign);
- IO.enumCase(Value, "AlwaysBreak", FormatStyle::BAS_AlwaysBreak);
- IO.enumCase(Value, "BlockIndent", FormatStyle::BAS_BlockIndent);
+template <> struct ScalarEnumerationTraits<BracketAlignmentStyle> {
+ static void enumeration(IO &IO, BracketAlignmentStyle &Value) {
+ IO.enumCase(Value, "Align", BAS_Align);
+ IO.enumCase(Value, "DontAlign", BAS_DontAlign);
// For backward compatibility.
- IO.enumCase(Value, "true", FormatStyle::BAS_Align);
- IO.enumCase(Value, "false", FormatStyle::BAS_DontAlign);
+ IO.enumCase(Value, "true", BAS_Align);
+ IO.enumCase(Value, "false", BAS_DontAlign);
+ IO.enumCase(Value, "AlwaysBreak", BAS_AlwaysBreak);
+ IO.enumCase(Value, "BlockIndent", BAS_BlockIndent);
}
};
@@ -979,6 +986,54 @@ template <> struct MappingTraits<FormatStyle> {
bool SpacesInCStyleCastParentheses = false;
bool SpacesInParentheses = false;
+ if (IO.outputting()) {
+ IO.mapOptional("AlignAfterOpenBracket", Style.AlignAfterOpenBracket);
+ } else {
+ // For backward compatibility.
+ BracketAlignmentStyle LocalBAS = BAS_Align;
+ if (IsGoogleOrChromium) {
+ FormatStyle::LanguageKind Language = Style.Language;
+ if (Language == FormatStyle::LK_None)
+ Language = ((FormatStyle *)IO.getContext())->Language;
+ if (Language == FormatStyle::LK_JavaScript)
+ LocalBAS = BAS_AlwaysBreak;
+ else if (Language == FormatStyle::LK_Java)
+ LocalBAS = BAS_DontAlign;
+ } else if (BasedOnStyle.equals_insensitive("webkit")) {
+ LocalBAS = BAS_DontAlign;
+ }
+ IO.mapOptional("AlignAfterOpenBracket", LocalBAS);
+ Style.BreakAfterOpenBracketBracedList = false;
+ Style.BreakAfterOpenBracketFunction = false;
+ Style.BreakAfterOpenBracketIf = false;
+ Style.BreakAfterOpenBracketLoop = false;
+ Style.BreakAfterOpenBracketSwitch = false;
+ Style.BreakBeforeCloseBracketBracedList = false;
+ Style.BreakBeforeCloseBracketFunction = false;
+ Style.BreakBeforeCloseBracketIf = false;
+ Style.BreakBeforeCloseBracketLoop = false;
+ Style.BreakBeforeCloseBracketSwitch = false;
+
+ switch (LocalBAS) {
+ case BAS_DontAlign:
+ Style.AlignAfterOpenBracket = false;
+ break;
+ case BAS_BlockIndent:
+ Style.BreakBeforeCloseBracketBracedList = true;
+ Style.BreakBeforeCloseBracketFunction = true;
+ Style.BreakBeforeCloseBracketIf = true;
+ [[fallthrough]];
+ case BAS_AlwaysBreak:
+ Style.BreakAfterOpenBracketBracedList = true;
+ Style.BreakAfterOpenBracketFunction = true;
+ Style.BreakAfterOpenBracketIf = true;
+ [[fallthrough]];
+ case BAS_Align:
+ Style.AlignAfterOpenBracket = true;
+ break;
+ }
+ }
+
// For backward compatibility.
if (!IO.outputting()) {
IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlines);
@@ -1014,7 +1069,6 @@ template <> struct MappingTraits<FormatStyle> {
}
IO.mapOptional("AccessModifierOffset", Style.AccessModifierOffset);
- IO.mapOptional("AlignAfterOpenBracket", Style.AlignAfterOpenBracket);
IO.mapOptional("AlignArrayOfStructures", Style.AlignArrayOfStructures);
IO.mapOptional("AlignConsecutiveAssignments",
Style.AlignConsecutiveAssignments);
@@ -1079,10 +1133,29 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("BreakAfterAttributes", Style.BreakAfterAttributes);
IO.mapOptional("BreakAfterJavaFieldAnnotations",
Style.BreakAfterJavaFieldAnnotations);
+ IO.mapOptional("BreakAfterOpenBracketBracedList",
+ Style.BreakAfterOpenBracketBracedList);
+ IO.mapOptional("BreakAfterOpenBracketFunction",
+ Style.BreakAfterOpenBracketFunction);
+ IO.mapOptional("BreakAfterOpenBracketIf", Style.BreakAfterOpenBracketIf);
+ IO.mapOptional("BreakAfterOpenBracketLoop",
+ Style.BreakAfterOpenBracketLoop);
+ IO.mapOptional("BreakAfterOpenBracketSwitch",
+ Style.BreakAfterOpenBracketSwitch);
IO.mapOptional("BreakAfterReturnType", Style.BreakAfterReturnType);
IO.mapOptional("BreakArrays", Style.BreakArrays);
IO.mapOptional("BreakBeforeBinaryOperators",
Style.BreakBeforeBinaryOperators);
+ IO.mapOptional("BreakBeforeCloseBracketBracedList",
+ Style.BreakBeforeCloseBracketBracedList);
+ IO.mapOptional("BreakBeforeCloseBracketFunction",
+ Style.BreakBeforeCloseBracketFunction);
+ IO.mapOptional("BreakBeforeCloseBracketIf",
+ Style.BreakBeforeCloseBracketIf);
+ IO.mapOptional("BreakBeforeCloseBracketLoop",
+ Style.BreakBeforeCloseBracketLoop);
+ IO.mapOptional("BreakBeforeCloseBracketSwitch",
+ Style.BreakBeforeCloseBracketSwitch);
IO.mapOptional("BreakBeforeConceptDeclarations",
Style.BreakBeforeConceptDeclarations);
IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);
@@ -1561,7 +1634,7 @@ static void expandPresetsSpacesInParens(FormatStyle &Expanded) {
FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
FormatStyle LLVMStyle;
LLVMStyle.AccessModifierOffset = -2;
- LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
+ LLVMStyle.AlignAfterOpenBracket = true;
LLVMStyle.AlignArrayOfStructures = FormatStyle::AIAS_None;
LLVMStyle.AlignConsecutiveAssignments = {};
LLVMStyle.AlignConsecutiveAssignments.PadOperators = true;
@@ -1621,10 +1694,20 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
LLVMStyle.BreakAdjacentStringLiterals = true;
LLVMStyle.BreakAfterAttributes = FormatStyle::ABS_Leave;
LLVMStyle.BreakAfterJavaFieldAnnotations = false;
+ LLVMStyle.BreakAfterOpenBracketBracedList = false;
+ LLVMStyle.BreakAfterOpenBracketFunction = false;
+ LLVMStyle.BreakAfterOpenBracketIf = false;
+ LLVMStyle.BreakAfterOpenBracketLoop = false;
+ LLVMStyle.BreakAfterOpenBracketSwitch = false;
LLVMStyle.BreakAfterReturnType = FormatStyle::RTBS_None;
LLVMStyle.BreakArrays = true;
LLVMStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_None;
LLVMStyle.BreakBeforeBraces = FormatStyle::BS_Attach;
+ LLVMStyle.BreakBeforeCloseBracketBracedList = false;
+ LLVMStyle.BreakBeforeCloseBracketFunction = false;
+ LLVMStyle.BreakBeforeCloseBracketIf = false;
+ LLVMStyle.BreakBeforeCloseBracketLoop = false;
+ LLVMStyle.BreakBeforeCloseBracketSwitch = false;
LLVMStyle.BreakBeforeConceptDeclarations = FormatStyle::BBCDS_Always;
LLVMStyle.BreakBeforeInlineASMColon = FormatStyle::BBIAS_OnlyMultiline;
LLVMStyle.BreakBeforeTemplateCloser = false;
@@ -1877,7 +1960,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
GoogleStyle.PenaltyReturnTypeOnItsOwnLine = 200;
if (Language == FormatStyle::LK_Java) {
- GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
+ GoogleStyle.AlignAfterOpenBracket = false;
GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
GoogleStyle.AlignTrailingComments = {};
GoogleStyle.AlignTrailingComments.Kind = FormatStyle::TCAS_Never;
@@ -1889,7 +1972,9 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
GoogleStyle.SpaceAfterCStyleCast = true;
GoogleStyle.SpacesBeforeTrailingComments = 1;
} else if (Language == FormatStyle::LK_JavaScript) {
- GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+ GoogleStyle.BreakAfterOpenBracketBracedList = true;
+ GoogleStyle.BreakAfterOpenBracketFunction = true;
+ GoogleStyle.BreakAfterOpenBracketIf = true;
GoogleStyle.AlignOperands = FormatStyle::OAS_DontAlign;
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
// TODO: still under discussion whether to switch to SLS_All.
@@ -2026,7 +2111,7 @@ FormatStyle getMozillaStyle() {
FormatStyle getWebKitStyle() {
FormatStyle Style = getLLVMStyle();
Style.AccessModifierOffset = -4;
- Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
+ Style.AlignAfterOpenBracket = false;
Style.AlignOperands = FormatStyle::OAS_DontAlign;
Style.AlignTrailingComments = {};
Style.AlignTrailingComments.Kind = FormatStyle::TCAS_Never;
diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp
index d1c6264..28fdbcb 100644
--- a/clang/lib/Format/FormatToken.cpp
+++ b/clang/lib/Format/FormatToken.cpp
@@ -68,7 +68,7 @@ bool FormatToken::isBlockIndentedInitRBrace(const FormatStyle &Style) const {
assert(MatchingParen);
assert(MatchingParen->is(tok::l_brace));
if (Style.Cpp11BracedListStyle == FormatStyle::BLS_Block ||
- Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent) {
+ !Style.BreakBeforeCloseBracketBracedList) {
return false;
}
const auto *LBrace = MatchingParen;
@@ -198,7 +198,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
return;
// Column format doesn't really make sense if we don't align after brackets.
- if (Style.AlignAfterOpenBracket == FormatStyle::BAS_DontAlign)
+ if (!Style.AlignAfterOpenBracket)
return;
FormatToken *ItemBegin = Token->Next;
diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h
index 6f3d24a..d833130 100644
--- a/clang/lib/Format/FormatToken.h
+++ b/clang/lib/Format/FormatToken.h
@@ -666,6 +666,12 @@ public:
(endsSequence(tok::identifier, tok::kw_if) && AllowConstexprMacro);
}
+ bool isLoop(const FormatStyle &Style) const {
+ return isOneOf(tok::kw_for, tok::kw_while) ||
+ (Style.isJavaScript() && isNot(tok::l_paren) && Previous &&
+ Previous->is(tok::kw_for));
+ }
+
bool closesScopeAfterBlock() const {
if (getBlockKind() == BK_Block)
return true;
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 1d0dfd0b..8e227da 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2674,8 +2674,11 @@ private:
}
// *a or &a or &&a.
- if (PreviousNotConst->is(TT_PointerOrReference))
+ if (PreviousNotConst->is(TT_PointerOrReference) ||
+ PreviousNotConst->endsSequence(tok::coloncolon,
+ TT_PointerOrReference)) {
return true;
+ }
// MyClass a;
if (PreviousNotConst->isTypeName(LangOpts))
@@ -4424,10 +4427,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
if (Left.is(tok::l_paren) && Style.PenaltyBreakOpenParenthesis != 0)
return Style.PenaltyBreakOpenParenthesis;
- if (Left.is(tok::l_paren) && InFunctionDecl &&
- Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign) {
+ if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket)
return 100;
- }
if (Left.is(tok::l_paren) && Left.Previous &&
(Left.Previous->isOneOf(tok::kw_for, tok::kw__Generic) ||
Left.Previous->isIf())) {
@@ -4443,7 +4444,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
// If we aren't aligning after opening parens/braces we can always break
// here unless the style does not want us to place all arguments on the
// next line.
- if (Style.AlignAfterOpenBracket == FormatStyle::BAS_DontAlign &&
+ if (!Style.AlignAfterOpenBracket &&
(Left.ParameterCount <= 1 || Style.AllowAllArgumentsOnNextLine)) {
return 0;
}
@@ -6223,24 +6224,31 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
(Right.isBlockIndentedInitRBrace(Style)));
}
- // We only break before r_paren if we're in a block indented context.
+ // We can break before r_paren if we're in a block indented context or
+ // a control statement with an explicit style option.
if (Right.is(tok::r_paren)) {
- if (Style.AlignAfterOpenBracket != FormatStyle::BAS_BlockIndent ||
- !Right.MatchingParen) {
+ if (!Right.MatchingParen)
return false;
- }
auto Next = Right.Next;
if (Next && Next->is(tok::r_paren))
Next = Next->Next;
if (Next && Next->is(tok::l_paren))
return false;
const FormatToken *Previous = Right.MatchingParen->Previous;
- return !(Previous && (Previous->is(tok::kw_for) || Previous->isIf()));
+ if (!Previous)
+ return false;
+ if (Previous->isIf())
+ return Style.BreakBeforeCloseBracketIf;
+ if (Previous->isLoop(Style))
+ return Style.BreakBeforeCloseBracketLoop;
+ if (Previous->is(tok::kw_switch))
+ return Style.BreakBeforeCloseBracketSwitch;
+ return Style.BreakBeforeCloseBracketFunction;
}
if (Left.isOneOf(tok::r_paren, TT_TrailingAnnotation) &&
Right.is(TT_TrailingAnnotation) &&
- Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
+ Style.BreakBeforeCloseBracketFunction) {
return false;
}