diff options
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/Format.cpp | 4 | ||||
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 11 | ||||
-rw-r--r-- | lib/Format/TokenAnnotator.h | 1 |
3 files changed, 14 insertions, 2 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 8c2128eb01..1bd864e5c9 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -524,6 +524,8 @@ private: Previous.Type == TT_CtorInitializerColon) && getPrecedence(Previous) != prec::Assignment) State.Stack.back().LastSpace = State.Column; + else if (Previous.Type == TT_InheritanceColon) + State.Stack.back().Indent = State.Column; else if (Previous.ParameterCount > 1 && (Previous.is(tok::l_paren) || Previous.is(tok::l_square) || Previous.is(tok::l_brace) || @@ -564,6 +566,8 @@ private: const AnnotatedToken &Current = *State.NextToken; assert(State.Stack.size()); + if (Current.Type == TT_InheritanceColon) + State.Stack.back().AvoidBinPacking = true; if (Current.is(tok::lessless) && State.Stack.back().FirstLessLess == 0) State.Stack.back().FirstLessLess = State.Column; if (Current.is(tok::question)) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 4c36536104..22e67df1ec 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -323,6 +323,8 @@ private: Contexts.back().FirstObjCSelectorName = Tok->Parent; } else if (Contexts.back().ColonIsForRangeExpr) { Tok->Type = TT_RangeBasedForLoopColon; + } else if (Contexts.size() == 1) { + Tok->Type = TT_InheritanceColon; } break; case tok::kw_if: @@ -856,7 +858,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line, if (Left.is(tok::coloncolon)) return 500; - if (Left.Type == TT_RangeBasedForLoopColon) + if (Left.Type == TT_RangeBasedForLoopColon || + Left.Type == TT_InheritanceColon) return 5; if (Right.is(tok::arrow) || Right.is(tok::period)) { @@ -1040,7 +1043,11 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line, return true; if (Right.Type == TT_ConditionalExpr || Right.is(tok::question)) return true; - if (Left.Type == TT_RangeBasedForLoopColon) + if (Right.Type == TT_RangeBasedForLoopColon || + Right.Type == TT_InheritanceColon) + return false; + if (Left.Type == TT_RangeBasedForLoopColon || + Left.Type == TT_InheritanceColon) return true; if (Left.Type == TT_PointerOrReference || Left.Type == TT_TemplateCloser || Left.Type == TT_UnaryOperator || Left.Type == TT_ConditionalExpr || diff --git a/lib/Format/TokenAnnotator.h b/lib/Format/TokenAnnotator.h index 506f271dc5..5ce84af96a 100644 --- a/lib/Format/TokenAnnotator.h +++ b/lib/Format/TokenAnnotator.h @@ -34,6 +34,7 @@ enum TokenType { TT_ConditionalExpr, TT_CtorInitializerColon, TT_ImplicitStringLiteral, + TT_InheritanceColon, TT_LineComment, TT_ObjCArrayLiteral, TT_ObjCBlockLParen, |