diff options
Diffstat (limited to 'lib/Format/UnwrappedLineFormatter.cpp')
| -rw-r--r-- | lib/Format/UnwrappedLineFormatter.cpp | 46 | 
1 files changed, 21 insertions, 25 deletions
diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index d7f1c4232d86..c3c154afeb8a 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -530,34 +530,33 @@ protected:      if (Previous.Children[0]->First->MustBreakBefore)        return false; -    // Cannot merge multiple statements into a single line. -    if (Previous.Children.size() > 1) -      return false; -      // Cannot merge into one line if this line ends on a comment.      if (Previous.is(tok::comment))        return false; +    // Cannot merge multiple statements into a single line. +    if (Previous.Children.size() > 1) +      return false; + +    const AnnotatedLine *Child = Previous.Children[0];      // We can't put the closing "}" on a line with a trailing comment. -    if (Previous.Children[0]->Last->isTrailingComment()) +    if (Child->Last->isTrailingComment())        return false;      // If the child line exceeds the column limit, we wouldn't want to merge it.      // We add +2 for the trailing " }".      if (Style.ColumnLimit > 0 && -        Previous.Children[0]->Last->TotalLength + State.Column + 2 > -            Style.ColumnLimit) +        Child->Last->TotalLength + State.Column + 2 > Style.ColumnLimit)        return false;      if (!DryRun) {        Whitespaces->replaceWhitespace( -          *Previous.Children[0]->First, -          /*Newlines=*/0, /*IndentLevel=*/0, /*Spaces=*/1, +          *Child->First, /*Newlines=*/0, /*Spaces=*/1,            /*StartOfTokenColumn=*/State.Column, State.Line->InPPDirective);      } -    Penalty += formatLine(*Previous.Children[0], State.Column + 1, DryRun); +    Penalty += formatLine(*Child, State.Column + 1, DryRun); -    State.Column += 1 + Previous.Children[0]->Last->TotalLength; +    State.Column += 1 + Child->Last->TotalLength;      return true;    } @@ -841,8 +840,7 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,      if (ShouldFormat && TheLine.Type != LT_Invalid) {        if (!DryRun) -        formatFirstToken(*TheLine.First, PreviousLine, TheLine.Level, Indent, -                         TheLine.InPPDirective); +        formatFirstToken(TheLine, PreviousLine, Indent);        NextLine = Joiner.getNextMergedLine(DryRun, IndentTracker);        unsigned ColumnLimit = getColumnLimit(TheLine.InPPDirective, NextLine); @@ -882,9 +880,8 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,                                TheLine.LeadingEmptyLinesAffected);          // Format the first token.          if (ReformatLeadingWhitespace) -          formatFirstToken(*TheLine.First, PreviousLine, TheLine.Level, -                           TheLine.First->OriginalColumn, -                           TheLine.InPPDirective); +          formatFirstToken(TheLine, PreviousLine, +                           TheLine.First->OriginalColumn);          else            Whitespaces->addUntouchableToken(*TheLine.First,                                             TheLine.InPPDirective); @@ -904,15 +901,14 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,    return Penalty;  } -void UnwrappedLineFormatter::formatFirstToken(FormatToken &RootToken, +void UnwrappedLineFormatter::formatFirstToken(const AnnotatedLine &Line,                                                const AnnotatedLine *PreviousLine, -                                              unsigned IndentLevel, -                                              unsigned Indent, -                                              bool InPPDirective) { +                                              unsigned Indent) { +  FormatToken& RootToken = *Line.First;    if (RootToken.is(tok::eof)) {      unsigned Newlines = std::min(RootToken.NewlinesBefore, 1u); -    Whitespaces->replaceWhitespace(RootToken, Newlines, /*IndentLevel=*/0, -                                   /*Spaces=*/0, /*TargetColumn=*/0); +    Whitespaces->replaceWhitespace(RootToken, Newlines, /*Spaces=*/0, +                                   /*StartOfTokenColumn=*/0);      return;    }    unsigned Newlines = @@ -944,9 +940,9 @@ void UnwrappedLineFormatter::formatFirstToken(FormatToken &RootToken,        (!PreviousLine->InPPDirective || !RootToken.HasUnescapedNewline))      Newlines = std::min(1u, Newlines); -  Whitespaces->replaceWhitespace(RootToken, Newlines, IndentLevel, Indent, -                                 Indent, InPPDirective && -                                             !RootToken.HasUnescapedNewline); +  Whitespaces->replaceWhitespace(RootToken, Newlines, Indent, Indent, +                                 Line.InPPDirective && +                                     !RootToken.HasUnescapedNewline);  }  unsigned  | 
