diff options
Diffstat (limited to 'clang/lib/Format/BreakableToken.cpp')
| -rw-r--r-- | clang/lib/Format/BreakableToken.cpp | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index b23819d1027..cbc50f566a7 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -145,10 +145,10 @@ unsigned BreakableSingleLineToken::getLineLengthAfterSplit( } BreakableSingleLineToken::BreakableSingleLineToken( - const FormatToken &Tok, unsigned StartColumn, StringRef Prefix, - StringRef Postfix, bool InPPDirective, encoding::Encoding Encoding, - const FormatStyle &Style) - : BreakableToken(Tok, InPPDirective, Encoding, Style), + const FormatToken &Tok, unsigned IndentLevel, unsigned StartColumn, + StringRef Prefix, StringRef Postfix, bool InPPDirective, + encoding::Encoding Encoding, const FormatStyle &Style) + : BreakableToken(Tok, IndentLevel, InPPDirective, Encoding, Style), StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix) { assert(Tok.TokenText.startswith(Prefix) && Tok.TokenText.endswith(Postfix)); Line = Tok.TokenText.substr( @@ -156,11 +156,11 @@ BreakableSingleLineToken::BreakableSingleLineToken( } BreakableStringLiteral::BreakableStringLiteral( - const FormatToken &Tok, unsigned StartColumn, StringRef Prefix, - StringRef Postfix, bool InPPDirective, encoding::Encoding Encoding, - const FormatStyle &Style) - : BreakableSingleLineToken(Tok, StartColumn, Prefix, Postfix, InPPDirective, - Encoding, Style) {} + const FormatToken &Tok, unsigned IndentLevel, unsigned StartColumn, + StringRef Prefix, StringRef Postfix, bool InPPDirective, + encoding::Encoding Encoding, const FormatStyle &Style) + : BreakableSingleLineToken(Tok, IndentLevel, StartColumn, Prefix, Postfix, + InPPDirective, Encoding, Style) {} BreakableToken::Split BreakableStringLiteral::getSplit(unsigned LineIndex, unsigned TailOffset, @@ -175,7 +175,7 @@ void BreakableStringLiteral::insertBreak(unsigned LineIndex, WhitespaceManager &Whitespaces) { Whitespaces.replaceWhitespaceInToken( Tok, Prefix.size() + TailOffset + Split.first, Split.second, Postfix, - Prefix, InPPDirective, 1, StartColumn); + Prefix, InPPDirective, 1, IndentLevel, StartColumn); } static StringRef getLineCommentPrefix(StringRef Comment) { @@ -186,12 +186,10 @@ static StringRef getLineCommentPrefix(StringRef Comment) { return ""; } -BreakableLineComment::BreakableLineComment(const FormatToken &Token, - unsigned StartColumn, - bool InPPDirective, - encoding::Encoding Encoding, - const FormatStyle &Style) - : BreakableSingleLineToken(Token, StartColumn, +BreakableLineComment::BreakableLineComment( + const FormatToken &Token, unsigned IndentLevel, unsigned StartColumn, + bool InPPDirective, encoding::Encoding Encoding, const FormatStyle &Style) + : BreakableSingleLineToken(Token, IndentLevel, StartColumn, getLineCommentPrefix(Token.TokenText), "", InPPDirective, Encoding, Style) { OriginalPrefix = Prefix; @@ -216,7 +214,7 @@ void BreakableLineComment::insertBreak(unsigned LineIndex, unsigned TailOffset, WhitespaceManager &Whitespaces) { Whitespaces.replaceWhitespaceInToken( Tok, OriginalPrefix.size() + TailOffset + Split.first, Split.second, - Postfix, Prefix, InPPDirective, 1, StartColumn); + Postfix, Prefix, InPPDirective, 1, IndentLevel, StartColumn); } void @@ -224,15 +222,15 @@ BreakableLineComment::replaceWhitespaceBefore(unsigned LineIndex, WhitespaceManager &Whitespaces) { if (OriginalPrefix != Prefix) { Whitespaces.replaceWhitespaceInToken(Tok, OriginalPrefix.size(), 0, "", "", - false, 0, 1); + false, 0, /*IndentLevel=*/0, 1); } } BreakableBlockComment::BreakableBlockComment( - const FormatToken &Token, unsigned StartColumn, + const FormatToken &Token, unsigned IndentLevel, unsigned StartColumn, unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective, encoding::Encoding Encoding, const FormatStyle &Style) - : BreakableToken(Token, InPPDirective, Encoding, Style) { + : BreakableToken(Token, IndentLevel, InPPDirective, Encoding, Style) { StringRef TokenText(Token.TokenText); assert(TokenText.startswith("/*") && TokenText.endswith("*/")); TokenText.substr(2, TokenText.size() - 4).split(Lines, "\n"); @@ -327,12 +325,6 @@ void BreakableBlockComment::adjustWhitespace(unsigned LineIndex, LeadingWhitespace[LineIndex] = Lines[LineIndex].begin() - Lines[LineIndex - 1].end(); - // FIXME: We currently count tabs as 1 character. To solve this, we need to - // get the correct indentation width of the start of the comment, which - // requires correct counting of the tab expansions before the comment, and - // a configurable tab width. Since the current implementation only breaks - // if leading tabs are intermixed with spaces, that is not a high priority. - // Adjust the start column uniformly accross all lines. StartOfLineColumn[LineIndex] = std::max<int>( 0, @@ -376,9 +368,9 @@ void BreakableBlockComment::insertBreak(unsigned LineIndex, unsigned TailOffset, Text.data() - Tok.TokenText.data() + Split.first; unsigned CharsToRemove = Split.second; assert(IndentAtLineBreak >= Decoration.size()); - Whitespaces.replaceWhitespaceInToken(Tok, BreakOffsetInToken, CharsToRemove, - "", Prefix, InPPDirective, 1, - IndentAtLineBreak - Decoration.size()); + Whitespaces.replaceWhitespaceInToken( + Tok, BreakOffsetInToken, CharsToRemove, "", Prefix, InPPDirective, 1, + IndentLevel, IndentAtLineBreak - Decoration.size()); } void @@ -412,7 +404,8 @@ BreakableBlockComment::replaceWhitespaceBefore(unsigned LineIndex, assert(StartOfLineColumn[LineIndex] >= Prefix.size()); Whitespaces.replaceWhitespaceInToken( Tok, WhitespaceOffsetInToken, LeadingWhitespace[LineIndex], "", Prefix, - InPPDirective, 1, StartOfLineColumn[LineIndex] - Prefix.size()); + InPPDirective, 1, IndentLevel, + StartOfLineColumn[LineIndex] - Prefix.size()); } unsigned |

