krasimir updated this revision to Diff 86412. krasimir marked an inline comment as done. krasimir added a comment.
- Add a FIXME also in the parser https://reviews.llvm.org/D29322 Files: lib/Format/BreakableToken.cpp lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -934,6 +934,24 @@ " VAL_B\n" "};"); + EXPECT_EQ("enum A {\n" + " // line a\n" + " a,\n" + " b, // line b\n" + "\n" + " // line c\n" + " c\n" + "};", + format("enum A {\n" + " // line a\n" + " a,\n" + " b, // line b\n" + "\n" + " // line c\n" + " c\n" + "};", + getLLVMStyleWithColumns(20))); + verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; // Trailing comment"); Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -2124,7 +2124,12 @@ I != E; ++I) { // Line comments that belong to the same line comment section are put on the // same line since later we might want to reflow content between them. - // See BreakableToken. + // Additional fine-grained breaking of line comment sections is controlled + // by the class BreakableLineCommentSection in case it is desirable to keep + // several line comment sections in the same unwrapped line. + // + // FIXME: Consider putting separate line comment sections as children to the + // unwrapped line instead. if (isOnNewLine(**I) && JustComments && !continuesLineComment(**I, *Line)) addUnwrappedLine(); pushToken(*I); Index: lib/Format/BreakableToken.cpp =================================================================== --- lib/Format/BreakableToken.cpp +++ lib/Format/BreakableToken.cpp @@ -682,6 +682,23 @@ Content[i] = Content[i].substr(0, EndOfLine); } LineTok = CurrentTok->Next; + if (CurrentTok->Next && CurrentTok->Next->NewlinesBefore > 1) { + // A line comment section needs to broken by a line comment that is + // preceded by at least two newlines. Note that we put this break here + // instead of breaking at a previous stage during parsing, since that + // would split the contents of the enum into two unwrapped lines in this + // example, which is undesirable: + // enum A { + // a, // comment about a + // + // // comment about b + // b + // }; + // + // FIXME: Consider putting separate line comment sections as children to + // the unwrapped line instead. + break; + } } }
Index: unittests/Format/FormatTest.cpp =================================================================== --- unittests/Format/FormatTest.cpp +++ unittests/Format/FormatTest.cpp @@ -934,6 +934,24 @@ " VAL_B\n" "};"); + EXPECT_EQ("enum A {\n" + " // line a\n" + " a,\n" + " b, // line b\n" + "\n" + " // line c\n" + " c\n" + "};", + format("enum A {\n" + " // line a\n" + " a,\n" + " b, // line b\n" + "\n" + " // line c\n" + " c\n" + "};", + getLLVMStyleWithColumns(20))); + verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa =\n" " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; // Trailing comment"); Index: lib/Format/UnwrappedLineParser.cpp =================================================================== --- lib/Format/UnwrappedLineParser.cpp +++ lib/Format/UnwrappedLineParser.cpp @@ -2124,7 +2124,12 @@ I != E; ++I) { // Line comments that belong to the same line comment section are put on the // same line since later we might want to reflow content between them. - // See BreakableToken. + // Additional fine-grained breaking of line comment sections is controlled + // by the class BreakableLineCommentSection in case it is desirable to keep + // several line comment sections in the same unwrapped line. + // + // FIXME: Consider putting separate line comment sections as children to the + // unwrapped line instead. if (isOnNewLine(**I) && JustComments && !continuesLineComment(**I, *Line)) addUnwrappedLine(); pushToken(*I); Index: lib/Format/BreakableToken.cpp =================================================================== --- lib/Format/BreakableToken.cpp +++ lib/Format/BreakableToken.cpp @@ -682,6 +682,23 @@ Content[i] = Content[i].substr(0, EndOfLine); } LineTok = CurrentTok->Next; + if (CurrentTok->Next && CurrentTok->Next->NewlinesBefore > 1) { + // A line comment section needs to broken by a line comment that is + // preceded by at least two newlines. Note that we put this break here + // instead of breaking at a previous stage during parsing, since that + // would split the contents of the enum into two unwrapped lines in this + // example, which is undesirable: + // enum A { + // a, // comment about a + // + // // comment about b + // b + // }; + // + // FIXME: Consider putting separate line comment sections as children to + // the unwrapped line instead. + break; + } } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits