diff options
Diffstat (limited to 'lib/Format/WhitespaceManager.cpp')
| -rw-r--r-- | lib/Format/WhitespaceManager.cpp | 33 | 
1 files changed, 19 insertions, 14 deletions
diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 377ec3a681b6..a5477a996327 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -67,6 +67,11 @@ void WhitespaceManager::addUntouchableToken(const FormatToken &Tok,                             /*IsInsideToken=*/false));  } +llvm::Error +WhitespaceManager::addReplacement(const tooling::Replacement &Replacement) { +  return Replaces.add(Replacement); +} +  void WhitespaceManager::replaceWhitespaceInToken(      const FormatToken &Tok, unsigned Offset, unsigned ReplaceChars,      StringRef PreviousPostfix, StringRef CurrentPrefix, bool InPPDirective, @@ -166,15 +171,15 @@ void WhitespaceManager::calculateLineBreakInformation() {          // BreakableLineCommentSection does comment reflow changes and here is          // the aligning of trailing comments. Consider the case where we reflow          // the second line up in this example: -        //  +        //          // // line 1          // // line 2 -        //  +        //          // That amounts to 2 changes by BreakableLineCommentSection:          //  - the first, delimited by (), for the whitespace between the tokens,          //  - and second, delimited by [], for the whitespace at the beginning          //  of the second token: -        //  +        //          // // line 1(          // )[// ]line 2          // @@ -608,8 +613,9 @@ void WhitespaceManager::generateChanges() {      if (C.CreateReplacement) {        std::string ReplacementText = C.PreviousLinePostfix;        if (C.ContinuesPPDirective) -        appendNewlineText(ReplacementText, C.NewlinesBefore, -                          C.PreviousEndOfTokenColumn, C.EscapedNewlineColumn); +        appendEscapedNewlineText(ReplacementText, C.NewlinesBefore, +                                 C.PreviousEndOfTokenColumn, +                                 C.EscapedNewlineColumn);        else          appendNewlineText(ReplacementText, C.NewlinesBefore);        appendIndentText(ReplacementText, C.Tok->IndentLevel, @@ -621,8 +627,7 @@ void WhitespaceManager::generateChanges() {    }  } -void WhitespaceManager::storeReplacement(SourceRange Range, -                                         StringRef Text) { +void WhitespaceManager::storeReplacement(SourceRange Range, StringRef Text) {    unsigned WhitespaceLength = SourceMgr.getFileOffset(Range.getEnd()) -                                SourceMgr.getFileOffset(Range.getBegin());    // Don't create a replacement, if it does not change anything. @@ -645,16 +650,16 @@ void WhitespaceManager::appendNewlineText(std::string &Text,      Text.append(UseCRLF ? "\r\n" : "\n");  } -void WhitespaceManager::appendNewlineText(std::string &Text, unsigned Newlines, -                                          unsigned PreviousEndOfTokenColumn, -                                          unsigned EscapedNewlineColumn) { +void WhitespaceManager::appendEscapedNewlineText( +    std::string &Text, unsigned Newlines, unsigned PreviousEndOfTokenColumn, +    unsigned EscapedNewlineColumn) {    if (Newlines > 0) { -    unsigned Offset = -        std::min<int>(EscapedNewlineColumn - 2, PreviousEndOfTokenColumn); +    unsigned Spaces = +        std::max<int>(1, EscapedNewlineColumn - PreviousEndOfTokenColumn - 1);      for (unsigned i = 0; i < Newlines; ++i) { -      Text.append(EscapedNewlineColumn - Offset - 1, ' '); +      Text.append(Spaces, ' ');        Text.append(UseCRLF ? "\\\r\n" : "\\\n"); -      Offset = 0; +      Spaces = std::max<int>(0, EscapedNewlineColumn - 1);      }    }  }  | 
