diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2016-01-06 20:20:48 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2016-01-06 20:20:48 +0000 | 
| commit | ea942507b10d5b808801dd58d777ea4e02997931 (patch) | |
| tree | 7ea42cf427bda317125421123460445eb3c7075f /contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp | |
| parent | 4d0b32cd7f47f4836ea0a7a9da24d3576c6e2fe0 (diff) | |
| parent | 97b17066aaac3f1590a809d79abe98fde03821ec (diff) | |
Notes
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp')
| -rw-r--r-- | contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp | 41 | 
1 files changed, 27 insertions, 14 deletions
| diff --git a/contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp b/contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp index 41451b91f881..8faab2869de6 100644 --- a/contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp +++ b/contrib/llvm/tools/clang/lib/Format/ContinuationIndenter.cpp @@ -38,6 +38,12 @@ static unsigned getLengthToMatchingParen(const FormatToken &Tok) {    return End->TotalLength - Tok.TotalLength + 1;  } +static unsigned getLengthToNextOperator(const FormatToken &Tok) { +  if (!Tok.NextOperator) +    return 0; +  return Tok.NextOperator->TotalLength - Tok.TotalLength; +} +  // Returns \c true if \c Tok is the "." or "->" of a call and starts the next  // segment of a builder type call.  static bool startsSegmentOfBuilderTypeCall(const FormatToken &Tok) { @@ -153,7 +159,8 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {        !Current.isOneOf(tok::r_paren, tok::r_brace))      return true;    if (((Previous.is(TT_DictLiteral) && Previous.is(tok::l_brace)) || -       Previous.is(TT_ArrayInitializerLSquare)) && +       (Previous.is(TT_ArrayInitializerLSquare) && +        Previous.ParameterCount > 1)) &&        Style.ColumnLimit > 0 &&        getLengthToMatchingParen(Previous) + State.Column - 1 >            getColumnLimit(State)) @@ -170,9 +177,13 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {      return true;    unsigned NewLineColumn = getNewLineColumn(State); -  if (State.Column < NewLineColumn) +  if (State.Column <= NewLineColumn)      return false; +  if (Current.isMemberAccess() && +      State.Column + getLengthToNextOperator(Current) > Style.ColumnLimit) +    return true; +    if (Style.AlwaysBreakBeforeMultilineStrings &&        (NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||         Previous.is(tok::comma) || Current.NestingLevel < 2) && @@ -246,8 +257,10 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {        Previous.is(tok::l_brace) && !Current.isOneOf(tok::r_brace, tok::comment))      return true; -  if (Current.is(tok::lessless) && Previous.is(tok::identifier) && -      Previous.TokenText == "endl") +  if (Current.is(tok::lessless) && +      ((Previous.is(tok::identifier) && Previous.TokenText == "endl") || +       (Previous.Tok.isLiteral() && (Previous.TokenText.endswith("\\n\"") || +                                     Previous.TokenText == "\'\\n\'"))))      return true;    return false; @@ -316,16 +329,16 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,    if (Current.is(TT_SelectorName) &&        !State.Stack.back().ObjCSelectorNameFound) { +    unsigned MinIndent = +        std::max(State.FirstIndent + Style.ContinuationIndentWidth, +                 State.Stack.back().Indent); +    unsigned FirstColonPos = State.Column + Spaces + Current.ColumnWidth;      if (Current.LongestObjCSelectorName == 0)        State.Stack.back().AlignColons = false; -    else if (State.Stack.back().Indent + Current.LongestObjCSelectorName > -             State.Column + Spaces + Current.ColumnWidth) -      State.Stack.back().ColonPos = -          std::max(State.FirstIndent + Style.ContinuationIndentWidth, -                   State.Stack.back().Indent) + -          Current.LongestObjCSelectorName; +    else if (MinIndent + Current.LongestObjCSelectorName > FirstColonPos) +      State.Stack.back().ColonPos = MinIndent + Current.LongestObjCSelectorName;      else -      State.Stack.back().ColonPos = State.Column + Spaces + Current.ColumnWidth; +      State.Stack.back().ColonPos = FirstColonPos;    }    // In "AlwaysBreak" mode, enforce wrapping directly after the parenthesis by @@ -377,7 +390,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,                                 TT_CtorInitializerColon)) &&               ((Previous.getPrecedence() != prec::Assignment &&                 (Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 || -                !Previous.LastOperator)) || +                Previous.NextOperator)) ||                Current.StartsBinaryExpression)) {      // Always indent relative to the RHS of the expression unless this is a      // simple assignment without binary expression on the RHS. Also indent @@ -692,7 +705,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,          std::min(State.LowestLevelOnLine, Current.NestingLevel);    if (Current.isMemberAccess())      State.Stack.back().StartOfFunctionCall = -        Current.LastOperator ? 0 : State.Column; +        !Current.NextOperator ? 0 : State.Column;    if (Current.is(TT_SelectorName)) {      State.Stack.back().ObjCSelectorNameFound = true;      if (Style.IndentWrappedFunctionNames) { @@ -728,7 +741,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,    //   }, a, b, c);    if (Current.isNot(tok::comment) && Previous &&        Previous->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) && -      State.Stack.size() > 1) { +      !Previous->is(TT_DictLiteral) && State.Stack.size() > 1) {      if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline)        for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i)          State.Stack[i].NoLineBreak = true; | 
