summaryrefslogtreecommitdiffstats
path: root/lib/Format
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Format')
-rw-r--r--lib/Format/ContinuationIndenter.cpp5
-rw-r--r--lib/Format/Format.cpp159
-rw-r--r--lib/Format/TokenAnnotator.cpp31
-rw-r--r--lib/Format/UnwrappedLineParser.cpp15
4 files changed, 138 insertions, 72 deletions
diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp
index 2357abd..ed01d68 100644
--- a/lib/Format/ContinuationIndenter.cpp
+++ b/lib/Format/ContinuationIndenter.cpp
@@ -126,7 +126,8 @@ bool ContinuationIndenter::canBreak(const LineState &State) {
// Don't break after very short return types (e.g. "void") as that is often
// unexpected.
if (Current.is(TT_FunctionDeclarationName) &&
- !Style.AlwaysBreakAfterDefinitionReturnType && State.Column < 6)
+ Style.AlwaysBreakAfterDefinitionReturnType == FormatStyle::DRTBS_None &&
+ State.Column < 6)
return false;
return !State.Stack.back().NoLineBreak;
@@ -815,7 +816,7 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
// ParameterToInnerFunction));
if (*I > prec::Unknown)
NewParenState.LastSpace = std::max(NewParenState.LastSpace, State.Column);
- if (*I != prec::Conditional)
+ if (*I != prec::Conditional && !Current.is(TT_UnaryOperator))
NewParenState.StartOfFunctionCall = State.Column;
// Always indent conditional expressions. Never indent expression where
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 0feeaa0..2bbe4c6 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -99,6 +99,18 @@ template <> struct ScalarEnumerationTraits<FormatStyle::BraceBreakingStyle> {
}
};
+template <> struct ScalarEnumerationTraits<FormatStyle::DefinitionReturnTypeBreakingStyle> {
+ static void enumeration(IO &IO, FormatStyle::DefinitionReturnTypeBreakingStyle &Value) {
+ IO.enumCase(Value, "None", FormatStyle::DRTBS_None);
+ IO.enumCase(Value, "All", FormatStyle::DRTBS_All);
+ IO.enumCase(Value, "TopLevel", FormatStyle::DRTBS_TopLevel);
+
+ // For backward compatibility.
+ IO.enumCase(Value, "false", FormatStyle::DRTBS_None);
+ IO.enumCase(Value, "true", FormatStyle::DRTBS_All);
+ }
+};
+
template <>
struct ScalarEnumerationTraits<FormatStyle::NamespaceIndentationKind> {
static void enumeration(IO &IO,
@@ -169,55 +181,70 @@ template <> struct MappingTraits<FormatStyle> {
}
}
+ // For backward compatibility.
+ if (!IO.outputting()) {
+ IO.mapOptional("DerivePointerBinding", Style.DerivePointerAlignment);
+ IO.mapOptional("IndentFunctionDeclarationAfterType",
+ Style.IndentWrappedFunctionNames);
+ IO.mapOptional("PointerBindsToType", Style.PointerAlignment);
+ IO.mapOptional("SpaceAfterControlStatementKeyword",
+ Style.SpaceBeforeParens);
+ }
+
IO.mapOptional("AccessModifierOffset", Style.AccessModifierOffset);
IO.mapOptional("AlignAfterOpenBracket", Style.AlignAfterOpenBracket);
+ IO.mapOptional("AlignConsecutiveAssignments",
+ Style.AlignConsecutiveAssignments);
IO.mapOptional("AlignEscapedNewlinesLeft", Style.AlignEscapedNewlinesLeft);
IO.mapOptional("AlignOperands", Style.AlignOperands);
IO.mapOptional("AlignTrailingComments", Style.AlignTrailingComments);
- IO.mapOptional("AlignConsecutiveAssignments",
- Style.AlignConsecutiveAssignments);
IO.mapOptional("AllowAllParametersOfDeclarationOnNextLine",
Style.AllowAllParametersOfDeclarationOnNextLine);
IO.mapOptional("AllowShortBlocksOnASingleLine",
Style.AllowShortBlocksOnASingleLine);
IO.mapOptional("AllowShortCaseLabelsOnASingleLine",
Style.AllowShortCaseLabelsOnASingleLine);
+ IO.mapOptional("AllowShortFunctionsOnASingleLine",
+ Style.AllowShortFunctionsOnASingleLine);
IO.mapOptional("AllowShortIfStatementsOnASingleLine",
Style.AllowShortIfStatementsOnASingleLine);
IO.mapOptional("AllowShortLoopsOnASingleLine",
Style.AllowShortLoopsOnASingleLine);
- IO.mapOptional("AllowShortFunctionsOnASingleLine",
- Style.AllowShortFunctionsOnASingleLine);
IO.mapOptional("AlwaysBreakAfterDefinitionReturnType",
Style.AlwaysBreakAfterDefinitionReturnType);
- IO.mapOptional("AlwaysBreakTemplateDeclarations",
- Style.AlwaysBreakTemplateDeclarations);
IO.mapOptional("AlwaysBreakBeforeMultilineStrings",
Style.AlwaysBreakBeforeMultilineStrings);
+ IO.mapOptional("AlwaysBreakTemplateDeclarations",
+ Style.AlwaysBreakTemplateDeclarations);
+ IO.mapOptional("BinPackArguments", Style.BinPackArguments);
+ IO.mapOptional("BinPackParameters", Style.BinPackParameters);
IO.mapOptional("BreakBeforeBinaryOperators",
Style.BreakBeforeBinaryOperators);
+ IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);
IO.mapOptional("BreakBeforeTernaryOperators",
Style.BreakBeforeTernaryOperators);
IO.mapOptional("BreakConstructorInitializersBeforeComma",
Style.BreakConstructorInitializersBeforeComma);
- IO.mapOptional("BinPackParameters", Style.BinPackParameters);
- IO.mapOptional("BinPackArguments", Style.BinPackArguments);
IO.mapOptional("ColumnLimit", Style.ColumnLimit);
+ IO.mapOptional("CommentPragmas", Style.CommentPragmas);
IO.mapOptional("ConstructorInitializerAllOnOneLineOrOnePerLine",
Style.ConstructorInitializerAllOnOneLineOrOnePerLine);
IO.mapOptional("ConstructorInitializerIndentWidth",
Style.ConstructorInitializerIndentWidth);
+ IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth);
+ IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
IO.mapOptional("DerivePointerAlignment", Style.DerivePointerAlignment);
+ IO.mapOptional("DisableFormat", Style.DisableFormat);
IO.mapOptional("ExperimentalAutoDetectBinPacking",
Style.ExperimentalAutoDetectBinPacking);
+ IO.mapOptional("ForEachMacros", Style.ForEachMacros);
IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
+ IO.mapOptional("IndentWidth", Style.IndentWidth);
IO.mapOptional("IndentWrappedFunctionNames",
Style.IndentWrappedFunctionNames);
- IO.mapOptional("IndentFunctionDeclarationAfterType",
- Style.IndentWrappedFunctionNames);
- IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
IO.mapOptional("KeepEmptyLinesAtTheStartOfBlocks",
Style.KeepEmptyLinesAtTheStartOfBlocks);
+ IO.mapOptional("MaxEmptyLinesToKeep", Style.MaxEmptyLinesToKeep);
IO.mapOptional("NamespaceIndentation", Style.NamespaceIndentation);
IO.mapOptional("ObjCBlockIndentWidth", Style.ObjCBlockIndentWidth);
IO.mapOptional("ObjCSpaceAfterProperty", Style.ObjCSpaceAfterProperty);
@@ -226,45 +253,30 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("PenaltyBreakBeforeFirstCallParameter",
Style.PenaltyBreakBeforeFirstCallParameter);
IO.mapOptional("PenaltyBreakComment", Style.PenaltyBreakComment);
- IO.mapOptional("PenaltyBreakString", Style.PenaltyBreakString);
IO.mapOptional("PenaltyBreakFirstLessLess",
Style.PenaltyBreakFirstLessLess);
+ IO.mapOptional("PenaltyBreakString", Style.PenaltyBreakString);
IO.mapOptional("PenaltyExcessCharacter", Style.PenaltyExcessCharacter);
IO.mapOptional("PenaltyReturnTypeOnItsOwnLine",
Style.PenaltyReturnTypeOnItsOwnLine);
IO.mapOptional("PointerAlignment", Style.PointerAlignment);
+ IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
+ IO.mapOptional("SpaceBeforeAssignmentOperators",
+ Style.SpaceBeforeAssignmentOperators);
+ IO.mapOptional("SpaceBeforeParens", Style.SpaceBeforeParens);
+ IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses);
IO.mapOptional("SpacesBeforeTrailingComments",
Style.SpacesBeforeTrailingComments);
- IO.mapOptional("Cpp11BracedListStyle", Style.Cpp11BracedListStyle);
- IO.mapOptional("Standard", Style.Standard);
- IO.mapOptional("IndentWidth", Style.IndentWidth);
- IO.mapOptional("TabWidth", Style.TabWidth);
- IO.mapOptional("UseTab", Style.UseTab);
- IO.mapOptional("BreakBeforeBraces", Style.BreakBeforeBraces);
- IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
- IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
IO.mapOptional("SpacesInAngles", Style.SpacesInAngles);
- IO.mapOptional("SpaceInEmptyParentheses", Style.SpaceInEmptyParentheses);
- IO.mapOptional("SpacesInCStyleCastParentheses",
- Style.SpacesInCStyleCastParentheses);
- IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
IO.mapOptional("SpacesInContainerLiterals",
Style.SpacesInContainerLiterals);
- IO.mapOptional("SpaceBeforeAssignmentOperators",
- Style.SpaceBeforeAssignmentOperators);
- IO.mapOptional("ContinuationIndentWidth", Style.ContinuationIndentWidth);
- IO.mapOptional("CommentPragmas", Style.CommentPragmas);
- IO.mapOptional("ForEachMacros", Style.ForEachMacros);
-
- // For backward compatibility.
- if (!IO.outputting()) {
- IO.mapOptional("SpaceAfterControlStatementKeyword",
- Style.SpaceBeforeParens);
- IO.mapOptional("PointerBindsToType", Style.PointerAlignment);
- IO.mapOptional("DerivePointerBinding", Style.DerivePointerAlignment);
- }
- IO.mapOptional("SpaceBeforeParens", Style.SpaceBeforeParens);
- IO.mapOptional("DisableFormat", Style.DisableFormat);
+ IO.mapOptional("SpacesInCStyleCastParentheses",
+ Style.SpacesInCStyleCastParentheses);
+ IO.mapOptional("SpacesInParentheses", Style.SpacesInParentheses);
+ IO.mapOptional("SpacesInSquareBrackets", Style.SpacesInSquareBrackets);
+ IO.mapOptional("Standard", Style.Standard);
+ IO.mapOptional("TabWidth", Style.TabWidth);
+ IO.mapOptional("UseTab", Style.UseTab);
}
};
@@ -338,7 +350,7 @@ FormatStyle getLLVMStyle() {
LLVMStyle.AllowShortCaseLabelsOnASingleLine = false;
LLVMStyle.AllowShortIfStatementsOnASingleLine = false;
LLVMStyle.AllowShortLoopsOnASingleLine = false;
- LLVMStyle.AlwaysBreakAfterDefinitionReturnType = false;
+ LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None;
LLVMStyle.AlwaysBreakBeforeMultilineStrings = false;
LLVMStyle.AlwaysBreakTemplateDeclarations = false;
LLVMStyle.BinPackParameters = true;
@@ -462,15 +474,19 @@ FormatStyle getChromiumStyle(FormatStyle::LanguageKind Language) {
FormatStyle getMozillaStyle() {
FormatStyle MozillaStyle = getLLVMStyle();
MozillaStyle.AllowAllParametersOfDeclarationOnNextLine = false;
+ MozillaStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
+ MozillaStyle.AlwaysBreakAfterDefinitionReturnType =
+ FormatStyle::DRTBS_TopLevel;
+ MozillaStyle.AlwaysBreakTemplateDeclarations = true;
+ MozillaStyle.BreakConstructorInitializersBeforeComma = true;
+ MozillaStyle.ConstructorInitializerIndentWidth = 2;
+ MozillaStyle.ContinuationIndentWidth = 2;
MozillaStyle.Cpp11BracedListStyle = false;
- MozillaStyle.ConstructorInitializerAllOnOneLineOrOnePerLine = true;
- MozillaStyle.DerivePointerAlignment = true;
MozillaStyle.IndentCaseLabels = true;
MozillaStyle.ObjCSpaceAfterProperty = true;
MozillaStyle.ObjCSpaceBeforeProtocolList = false;
MozillaStyle.PenaltyReturnTypeOnItsOwnLine = 200;
MozillaStyle.PointerAlignment = FormatStyle::PAS_Left;
- MozillaStyle.Standard = FormatStyle::LS_Cpp03;
return MozillaStyle;
}
@@ -496,7 +512,7 @@ FormatStyle getWebKitStyle() {
FormatStyle getGNUStyle() {
FormatStyle Style = getLLVMStyle();
- Style.AlwaysBreakAfterDefinitionReturnType = true;
+ Style.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_All;
Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
Style.BreakBeforeBraces = FormatStyle::BS_GNU;
Style.BreakBeforeTernaryOperators = true;
@@ -738,35 +754,62 @@ private:
bool tryMergeJSRegexLiteral() {
if (Tokens.size() < 2)
return false;
+
+ // If this is a string literal with a slash inside, compute the slash's
+ // offset and try to find the beginning of the regex literal.
+ // Also look at tok::unknown, as it can be an unterminated char literal.
+ size_t SlashInStringPos = StringRef::npos;
+ if (Tokens.back()->isOneOf(tok::string_literal, tok::char_constant,
+ tok::unknown)) {
+ // Start search from position 1 as otherwise, this is an unknown token
+ // for an unterminated /*-comment which is handled elsewhere.
+ SlashInStringPos = Tokens.back()->TokenText.find('/', 1);
+ if (SlashInStringPos == StringRef::npos)
+ return false;
+ }
+
// If a regex literal ends in "\//", this gets represented by an unknown
// token "\" and a comment.
bool MightEndWithEscapedSlash =
Tokens.back()->is(tok::comment) &&
Tokens.back()->TokenText.startswith("//") &&
Tokens[Tokens.size() - 2]->TokenText == "\\";
- if (!MightEndWithEscapedSlash &&
+ if (!MightEndWithEscapedSlash && SlashInStringPos == StringRef::npos &&
(Tokens.back()->isNot(tok::slash) ||
(Tokens[Tokens.size() - 2]->is(tok::unknown) &&
Tokens[Tokens.size() - 2]->TokenText == "\\")))
return false;
+
unsigned TokenCount = 0;
- unsigned LastColumn = Tokens.back()->OriginalColumn;
for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; ++I) {
++TokenCount;
- if (I[0]->isOneOf(tok::slash, tok::slashequal) && I + 1 != E &&
- (I[1]->isOneOf(tok::l_paren, tok::semi, tok::l_brace, tok::r_brace,
- tok::exclaim, tok::l_square, tok::colon, tok::comma,
- tok::question, tok::kw_return) ||
- I[1]->isBinaryOperator())) {
+ auto Prev = I + 1;
+ while (Prev != E && Prev[0]->is(tok::comment))
+ ++Prev;
+ if (I[0]->isOneOf(tok::slash, tok::slashequal) &&
+ (Prev == E ||
+ ((Prev[0]->isOneOf(tok::l_paren, tok::semi, tok::l_brace,
+ tok::r_brace, tok::exclaim, tok::l_square,
+ tok::colon, tok::comma, tok::question,
+ tok::kw_return) ||
+ Prev[0]->isBinaryOperator())))) {
+ unsigned LastColumn = Tokens.back()->OriginalColumn;
+ SourceLocation Loc = Tokens.back()->Tok.getLocation();
if (MightEndWithEscapedSlash) {
// This regex literal ends in '\//'. Skip past the '//' of the last
// token and re-start lexing from there.
- SourceLocation Loc = Tokens.back()->Tok.getLocation();
resetLexer(SourceMgr.getFileOffset(Loc) + 2);
+ } else if (SlashInStringPos != StringRef::npos) {
+ // This regex literal ends in a string_literal with a slash inside.
+ // Calculate end column and reset lexer appropriately.
+ resetLexer(SourceMgr.getFileOffset(Loc) + SlashInStringPos + 1);
+ LastColumn += SlashInStringPos;
}
Tokens.resize(Tokens.size() - TokenCount);
Tokens.back()->Tok.setKind(tok::unknown);
Tokens.back()->Type = TT_RegexLiteral;
+ // Treat regex literals like other string_literals.
+ Tokens.back()->Tok.setKind(tok::string_literal);
Tokens.back()->ColumnWidth += LastColumn - I[0]->OriginalColumn;
return true;
}
@@ -801,7 +844,7 @@ private:
EndBacktick->OriginalColumn + EndBacktick->ColumnWidth;
for (auto I = Tokens.rbegin() + 1, E = Tokens.rend(); I != E; I++) {
++TokenCount;
- if (I[0]->NewlinesBefore > 0 || I[0]->IsMultiline)
+ if (I[0]->IsMultiline)
IsMultiline = true;
// If there was a preceding template string, this must be the start of a
@@ -817,9 +860,10 @@ private:
EndColumnInFirstLine = I[0]->OriginalColumn + I[0]->ColumnWidth;
// If the token has newlines, the token before it (if it exists) is the
// rhs end of the previous line.
- if (I[0]->NewlinesBefore > 0 && (I + 1 != E))
+ if (I[0]->NewlinesBefore > 0 && (I + 1 != E)) {
EndColumnInFirstLine = I[1]->OriginalColumn + I[1]->ColumnWidth;
-
+ IsMultiline = true;
+ }
continue;
}
@@ -852,7 +896,8 @@ private:
// until here`;
Tokens.back()->ColumnWidth =
EndColumnInFirstLine - Tokens.back()->OriginalColumn;
- Tokens.back()->LastLineColumnWidth = EndOriginalColumn;
+ // +1 for the ` itself.
+ Tokens.back()->LastLineColumnWidth = EndOriginalColumn + 1;
Tokens.back()->IsMultiline = true;
} else {
// Token simply spans from start to end, +1 for the ` itself.
@@ -1044,7 +1089,6 @@ private:
break;
default:
FormatTok->Type = TT_ImplicitStringLiteral;
- ++Column;
break;
}
}
@@ -1189,6 +1233,7 @@ private:
getFormattingLangOpts(Style), Buffer.begin(),
Buffer.begin() + Offset, Buffer.end()));
Lex->SetKeepWhitespaceMode(true);
+ TrailingWhitespace = 0;
}
};
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp
index 8d08c3d..0e1f14a 100644
--- a/lib/Format/TokenAnnotator.cpp
+++ b/lib/Format/TokenAnnotator.cpp
@@ -1008,7 +1008,7 @@ private:
if (Tok.isNot(tok::identifier) || !Tok.Previous)
return false;
- if (Tok.Previous->is(TT_LeadingJavaAnnotation))
+ if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof))
return false;
// Skip "const" as it does not have an influence on whether this is a name.
@@ -1123,7 +1123,7 @@ private:
return TT_UnaryOperator;
const FormatToken *NextToken = Tok.getNextNonComment();
- if (!NextToken ||
+ if (!NextToken || NextToken->is(tok::arrow) ||
(NextToken->is(tok::l_brace) && !NextToken->getNextNonComment()))
return TT_Unknown;
@@ -1336,6 +1336,10 @@ private:
return 0;
if (Current->is(TT_RangeBasedForLoopColon))
return prec::Comma;
+ if ((Style.Language == FormatStyle::LK_Java ||
+ Style.Language == FormatStyle::LK_JavaScript) &&
+ Current->is(Keywords.kw_instanceof))
+ return prec::Relational;
if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
return Current->getPrecedence();
if (Current->isOneOf(tok::period, tok::arrow))
@@ -1539,8 +1543,11 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) {
Current->MustBreakBefore =
Current->MustBreakBefore || mustBreakBefore(Line, *Current);
- if (Style.AlwaysBreakAfterDefinitionReturnType && InFunctionDecl &&
- Current->is(TT_FunctionDeclarationName) &&
+ if ((Style.AlwaysBreakAfterDefinitionReturnType == FormatStyle::DRTBS_All ||
+ (Style.AlwaysBreakAfterDefinitionReturnType ==
+ FormatStyle::DRTBS_TopLevel &&
+ Line.Level == 0)) &&
+ InFunctionDecl && Current->is(TT_FunctionDeclarationName) &&
!Line.Last->isOneOf(tok::semi, tok::comment)) // Only for definitions.
// FIXME: Line.Last points to other characters than tok::semi
// and tok::lbrace.
@@ -1876,7 +1883,12 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
const FormatToken &Right) {
const FormatToken &Left = *Right.Previous;
- if (Style.Language == FormatStyle::LK_Proto) {
+ if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo())
+ return true; // Never ever merge two identifiers.
+ if (Style.Language == FormatStyle::LK_Cpp) {
+ if (Left.is(tok::kw_operator))
+ return Right.is(tok::coloncolon);
+ } else if (Style.Language == FormatStyle::LK_Proto) {
if (Right.is(tok::period) &&
Left.isOneOf(Keywords.kw_optional, Keywords.kw_required,
Keywords.kw_repeated))
@@ -1913,8 +1925,6 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
Right.is(TT_TemplateOpener))
return true;
}
- if (Right.Tok.getIdentifierInfo() && Left.Tok.getIdentifierInfo())
- return true; // Never ever merge two identifiers.
if (Left.is(TT_ImplicitStringLiteral))
return Right.WhitespaceRange.getBegin() != Right.WhitespaceRange.getEnd();
if (Line.Type == LT_ObjCMethodDecl) {
@@ -1937,8 +1947,6 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
return false;
if (Right.isOneOf(TT_CtorInitializerColon, TT_ObjCBlockLParen))
return true;
- if (Left.is(tok::kw_operator))
- return Right.is(tok::coloncolon);
if (Right.is(TT_OverloadedOperatorLParen))
return false;
if (Right.is(tok::colon)) {
@@ -2128,6 +2136,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
} else if (Style.Language == FormatStyle::LK_JavaScript) {
if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
return false;
+ if (Left.is(TT_JsTypeColon))
+ return true;
}
if (Left.is(tok::at))
@@ -2234,7 +2244,8 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
return true;
if (Right.is(tok::kw_typename) && Left.isNot(tok::kw_const))
return true;
- if (Left.isBinaryOperator() && !Left.isOneOf(tok::arrowstar, tok::lessless) &&
+ if ((Left.isBinaryOperator() || Left.is(TT_BinaryOperator)) &&
+ !Left.isOneOf(tok::arrowstar, tok::lessless) &&
Style.BreakBeforeBinaryOperators != FormatStyle::BOS_All &&
(Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None ||
Left.getPrecedence() == prec::Assignment))
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index ea1ca39..c58e6bc 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -656,6 +656,16 @@ void UnwrappedLineParser::parseStructuralElement() {
nextToken();
addUnwrappedLine();
return;
+ case tok::objc_autoreleasepool:
+ nextToken();
+ if (FormatTok->Tok.is(tok::l_brace)) {
+ if (Style.BreakBeforeBraces == FormatStyle::BS_Allman ||
+ Style.BreakBeforeBraces == FormatStyle::BS_GNU)
+ addUnwrappedLine();
+ parseBlock(/*MustBeDeclaration=*/false);
+ }
+ addUnwrappedLine();
+ return;
case tok::objc_try:
// This branch isn't strictly necessary (the kw_try case below would
// do this too after the tok::at is parsed above). But be explicit.
@@ -1101,16 +1111,15 @@ bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) {
FormatTok->BlockKind = BK_BracedInit;
parseBracedList();
break;
- case tok::r_paren:
+ case tok::l_paren:
+ parseParens();
// JavaScript can just have free standing methods and getters/setters in
// object literals. Detect them by a "{" following ")".
if (Style.Language == FormatStyle::LK_JavaScript) {
- nextToken();
if (FormatTok->is(tok::l_brace))
parseChildBlock();
break;
}
- nextToken();
break;
case tok::r_brace:
nextToken();
OpenPOWER on IntegriCloud