Lines Matching +full:non +full:- +full:comment

1 //===--- BreakableToken.cpp - Format C++ code -----------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 //===----------------------------------------------------------------------===//
23 #define DEBUG_TYPE "format-token-breaker"
42 static StringRef getLineCommentIndentPrefix(StringRef Comment, in getLineCommentIndentPrefix() argument
58 if (Comment.starts_with(KnownPrefix)) { in getLineCommentIndentPrefix()
60 Comment.find_first_not_of(' ', KnownPrefix.size()); in getLineCommentIndentPrefix()
61 return Comment.substr(0, PrefixLength); in getLineCommentIndentPrefix()
72 LLVM_DEBUG(llvm::dbgs() << "Comment split: \"" << Text in getCommentSplit()
78 unsigned MaxSplit = ColumnLimit - ContentStartColumn + 1; in getCommentSplit()
92 // these comments will fail to understand the comment if followed by a line in getCommentSplit()
105 static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\."); in getCommentSplit()
108 // If a line-comment ends with `\`, the next line continues the comment, in getCommentSplit()
110 // -Wcomment. in getCommentSplit()
123 // as a numbered list, which would prevent re-flowing in subsequent passes. in getCommentSplit()
146 // If the comment is only whitespace, we cannot split. in getCommentSplit()
153 // adaptStartOfLine will break after lines starting with /** if the comment in getCommentSplit()
157 if (SpaceOffset == 1 && Text[SpaceOffset - 1] == '*') in getCommentSplit()
165 AfterCut.begin() - BeforeCut.end()); in getCommentSplit()
178 unsigned MaxSplit = ColumnLimit - UsedColumns; in getStringSplit()
221 "formatting regions are switched by comment tokens"); in switchesFormatting()
223 return Content.starts_with("clang-format on") || in switchesFormatting()
224 Content.starts_with("clang-format off"); in switchesFormatting()
232 // - RemainingTokenColumns is the original number of columns, 10; in getLengthAfterCompression()
233 // - Split is (4, 2), denoting the two spaces between the two words; in getLengthAfterCompression()
241 return RemainingTokenColumns + 1 - Split.second; in getLengthAfterCompression()
276 Prefix.size(), Tok.TokenText.size() - Prefix.size() - Postfix.size()); in BreakableStringLiteral()
283 ColumnLimit - Postfix.size(), Style.TabWidth, Encoding); in getSplit()
348 ContinuationIndent = BracesNeeded ? LeftBraceQuote.size() - 1 : 0; in BreakableStringLiteralUsingOperators()
353 ContinuationIndent -= 2; in BreakableStringLiteralUsingOperators()
371 : (BracesNeeded ? static_cast<int>(LeftBraceQuote.size()) - 1 in getContentStartColumn()
404 Tok, /*Offset=*/Tok.TokenText.size() - 1, /*ReplaceChars=*/1, in updateAfterBroken()
422 // Don't break lines matching the comment pragmas regex. in getSplit()
439 Text.data() - tokenAt(LineIndex).TokenText.data() + Split.first; in compressWhitespace()
453 // Lines starting with '-', '-#', '+' or '*' are bulleted/numbered lists. in mayReflowContent()
456 {"@", "\\", "TODO", "FIXME", "XXX", "-# ", "- ", "+ ", "* "}) { in mayReflowContent()
466 static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\. "); in mayReflowContent()
472 // non-punctuation. in mayReflowContent()
475 // Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is in mayReflowContent()
488 "block comment section must start with a block comment"); in BreakableBlockComment()
492 TokenText.substr(2, TokenText.size() - 4) in BreakableBlockComment()
495 int IndentDelta = StartColumn - OriginalStartColumn; in BreakableBlockComment()
509 // Account for comment decoration patterns like this: in BreakableBlockComment()
578 // Detect a multiline jsdoc comment and set DelimitersOnNewline in that case. in BreakableBlockComment()
581 // This is a multiline jsdoc comment. in BreakableBlockComment()
584 // Detect a long single-line comment, like: in BreakableBlockComment()
602 << "IN=" << (Content[i].data() - Lines[i].data()) << "\n"; in BreakableBlockComment()
610 // Don't break lines matching the comment pragmas regex. in getSplit()
620 // When in a preprocessor directive, the trailing backslash in a block comment in adjustWhitespace()
622 // newlines outside the comment. In this case we remove it here before in adjustWhitespace()
623 // trimming the trailing whitespace. The backslash will be re-added later when in adjustWhitespace()
625 size_t EndOfPreviousLine = Lines[LineIndex - 1].size(); in adjustWhitespace()
626 if (InPPDirective && Lines[LineIndex - 1].ends_with("\\")) in adjustWhitespace()
627 --EndOfPreviousLine; in adjustWhitespace()
629 // Calculate the end of the non-whitespace text in the previous line. in adjustWhitespace()
631 Lines[LineIndex - 1].find_last_not_of(Blanks, EndOfPreviousLine); in adjustWhitespace()
636 // Calculate the start of the non-whitespace text in the current line. in adjustWhitespace()
644 Content[LineIndex - 1].data() - Lines[LineIndex - 1].data(); in adjustWhitespace()
645 Content[LineIndex - 1] = Lines[LineIndex - 1].substr( in adjustWhitespace()
646 PreviousContentOffset, EndOfPreviousLine - PreviousContentOffset); in adjustWhitespace()
677 LineLength -= Decoration.size(); in getRemainingLength()
699 // The content at LineIndex 0 of a comment like: in getContentIndent()
726 LocalIndentAtLineBreak -= 2; in insertBreak()
731 Text.data() - tokenAt(LineIndex).TokenText.data() + Split.first; in insertBreak()
739 /*Spaces=*/LocalIndentAtLineBreak + ContentIndent - in insertBreak()
752 unsigned PreviousContentIndent = getContentIndent(LineIndex - 1); in getReflowSplit()
772 assert(Tokens[LineIndex - 1] == Tokens[LineIndex] && in reflow()
776 unsigned WhitespaceOffsetInToken = Content[LineIndex - 1].data() + in reflow()
777 Content[LineIndex - 1].size() - in reflow()
779 unsigned WhitespaceLength = TrimmedContent.data() - in reflow()
780 tokenAt(LineIndex).TokenText.data() - in reflow()
826 unsigned WhitespaceOffsetInToken = Content[LineIndex - 1].data() + in adaptStartOfLine()
827 Content[LineIndex - 1].size() - in adaptStartOfLine()
829 unsigned WhitespaceLength = Content[LineIndex].data() - in adaptStartOfLine()
830 tokenAt(LineIndex).TokenText.data() - in adaptStartOfLine()
834 InPPDirective, /*Newlines=*/1, ContentColumn[LineIndex] - Prefix.size()); in adaptStartOfLine()
846 return Split(TrimmedLine.size(), Line.size() - TrimmedLine.size()); in getSplitAfterLastLine()
854 // case, we compute the start of the comment pragma manually. in mayReflow()
868 "line comment section must start with a line comment"); in BreakableLineCommentSection()
875 CurrentTok && CurrentTok->is(TT_LineComment); in BreakableLineCommentSection()
876 CurrentTok = CurrentTok->Next) { in BreakableLineCommentSection()
878 StringRef TokenText(CurrentTok->TokenText); in BreakableLineCommentSection()
880 "unsupported line comment prefix, '//' and '#' are supported"); in BreakableLineCommentSection()
907 // In C-like comments, add a space before #. For example this is useful in BreakableLineCommentSection()
911 // In languages using # as the comment leader such as proto, don't in BreakableLineCommentSection()
922 // On the first line of the comment section we calculate how many spaces in BreakableLineCommentSection()
925 // actual first line, we calculate that when the non space Prefix changes, in BreakableLineCommentSection()
928 OriginalPrefix[i - 1].rtrim(Blanks)) { in BreakableLineCommentSection()
931 FirstLineSpaceChange = Minimum - SpacesInPrefix; in BreakableLineCommentSection()
935 Style.SpacesInLineCommentPrefix.Maximum - SpacesInPrefix; in BreakableLineCommentSection()
946 Minimum - (SpacesInPrefix + PrefixSpaceChange[i]); in BreakableLineCommentSection()
965 -PrefixSpaceChange[i], SpacesInPrefix)) in BreakableLineCommentSection()
982 // Calculate the end of the non-whitespace text in this line. in BreakableLineCommentSection()
990 LineTok = CurrentTok->Next; in BreakableLineCommentSection()
991 if (CurrentTok->Next && !CurrentTok->Next->ContinuesLineCommentSection) { in BreakableLineCommentSection()
992 // A line comment section needs to broken by a line comment that is in BreakableLineCommentSection()
998 // a, // comment about a in BreakableLineCommentSection()
1000 // // comment about b in BreakableLineCommentSection()
1004 // FIXME: Consider putting separate line comment sections as children to in BreakableLineCommentSection()
1033 Text.data() - tokenAt(LineIndex).TokenText.data() + Split.first; in insertBreak()
1038 /*Spaces=*/ContentColumn[LineIndex] - Prefix[LineIndex].size()); in insertBreak()
1048 // In a line comment section each line is a separate token; thus, after a in getReflowSplit()
1049 // split we replace all whitespace before the current line comment token in getReflowSplit()
1057 if (LineIndex > 0 && Tokens[LineIndex] != Tokens[LineIndex - 1]) { in reflow()
1067 // // line comment \ in reflow()
1070 // the reflow happens inside the single comment token (it is a single line in reflow()
1071 // comment with an unescaped newline). in reflow()
1075 unsigned Offset = Lines[LineIndex - 1].data() + in reflow()
1076 Lines[LineIndex - 1].size() - in reflow()
1077 tokenAt(LineIndex - 1).TokenText.data(); in reflow()
1081 Lines[LineIndex].data() - tokenAt(LineIndex).TokenText.data() - Offset; in reflow()
1092 Lines[LineIndex].data() - tokenAt(LineIndex).TokenText.data(); in reflow()
1094 Content[LineIndex].data() - Lines[LineIndex].data(); in reflow()
1112 if (LineIndex > 0 && Tokens[LineIndex] != Tokens[LineIndex - 1]) { in adaptStartOfLine()
1119 ContentColumn[LineIndex] - in adaptStartOfLine()
1120 (Content[LineIndex].data() - Lines[LineIndex].data()) + in adaptStartOfLine()
1121 (OriginalPrefix[LineIndex].size() - Prefix[LineIndex].size()); in adaptStartOfLine()
1136 const auto SpacesToRemove = -std::min(PrefixSpaceChange[LineIndex], 0); in adaptStartOfLine()
1139 tokenAt(LineIndex), OriginalPrefix[LineIndex].size() - SpacesToRemove, in adaptStartOfLine()
1147 State.NextToken = LastLineTok->Next; in updateNextToken()
1157 // FIXME: Decide whether we want to reflow non-regular indents: in mayReflow()
1159 // OriginalPrefix[LineIndex-1]. That means we don't reflow in mayReflow()
1166 OriginalPrefix[LineIndex] == OriginalPrefix[LineIndex - 1]; in mayReflow()