aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/TokenAnnotator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/TokenAnnotator.cpp')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index c97a9e8..a8a9c51 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3791,12 +3791,18 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
if (Current.is(TT_FunctionDeclarationName))
return true;
- if (Current.isNoneOf(tok::identifier, tok::kw_operator))
+ if (!Current.Tok.getIdentifierInfo())
return false;
const auto *Prev = Current.getPreviousNonComment();
assert(Prev);
+ if (Prev->is(tok::coloncolon))
+ Prev = Prev->Previous;
+
+ if (!Prev)
+ return false;
+
const auto &Previous = *Prev;
if (const auto *PrevPrev = Previous.getPreviousNonComment();
@@ -3845,8 +3851,6 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
// Find parentheses of parameter list.
if (Current.is(tok::kw_operator)) {
- if (Line.startsWith(tok::kw_friend))
- return true;
if (Previous.Tok.getIdentifierInfo() &&
Previous.isNoneOf(tok::kw_return, tok::kw_co_return)) {
return true;
@@ -4407,8 +4411,12 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
// breaking after it.
if (Right.is(TT_SelectorName))
return 0;
- if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr))
- return Line.MightBeFunctionDecl ? 50 : 500;
+ if (Left.is(tok::colon)) {
+ if (Left.is(TT_ObjCMethodExpr))
+ return Line.MightBeFunctionDecl ? 50 : 500;
+ if (Left.is(TT_ObjCSelector))
+ return 500;
+ }
// In Objective-C type declarations, avoid breaking after the category's
// open paren (we'll prefer breaking after the protocol list's opening
@@ -6291,7 +6299,9 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
TT_BitFieldColon)) {
return false;
}
- if (Left.is(tok::colon) && Left.isOneOf(TT_DictLiteral, TT_ObjCMethodExpr)) {
+ if (Left.is(tok::colon) && Left.isOneOf(TT_ObjCSelector, TT_ObjCMethodExpr))
+ return true;
+ if (Left.is(tok::colon) && Left.is(TT_DictLiteral)) {
if (Style.isProto()) {
if (!Style.AlwaysBreakBeforeMultilineStrings && Right.isStringLiteral())
return false;