[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align
This revision was automatically updated to reflect the committed changes. Closed by commit rGe71c537a487c: [clang-format] Fix line lengths w/ comments in align (authored by MyDeveloperDay). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79465/new/ https://reviews.llvm.org/D79465 Files: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12010,6 +12010,16 @@ " x = 1;\n" "y = 1;\n", Alignment); + + Alignment.ReflowComments = true; + Alignment.ColumnLimit = 50; + EXPECT_EQ("int x = 0;\n" +"int yy = 1; /// specificlennospace\n" +"int zzz = 2;\n", +format("int x = 0;\n" + "int yy = 1; ///specificlennospace\n" + "int zzz = 2;\n", + Alignment)); } TEST_F(FormatTest, AlignConsecutiveDeclarations) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -445,8 +445,16 @@ unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; int LineLengthAfter = Changes[i].TokenLength; -for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) - LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength; +for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) { + LineLengthAfter += Changes[j].Spaces; + // Changes are generally 1:1 with the tokens, but a change could also be + // inside of a token, in which case it's counted more than once: once for + // the whitespace surrounding the token (!IsInsideToken) and once for + // each whitespace change within it (IsInsideToken). + // Therefore, changes inside of a token should only count the space. + if (!Changes[j].IsInsideToken) +LineLengthAfter += Changes[j].TokenLength; +} unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; // If we are restricted by the maximum column width, end the sequence. Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -12010,6 +12010,16 @@ " x = 1;\n" "y = 1;\n", Alignment); + + Alignment.ReflowComments = true; + Alignment.ColumnLimit = 50; + EXPECT_EQ("int x = 0;\n" +"int yy = 1; /// specificlennospace\n" +"int zzz = 2;\n", +format("int x = 0;\n" + "int yy = 1; ///specificlennospace\n" + "int zzz = 2;\n", + Alignment)); } TEST_F(FormatTest, AlignConsecutiveDeclarations) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -445,8 +445,16 @@ unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; int LineLengthAfter = Changes[i].TokenLength; -for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) - LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength; +for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) { + LineLengthAfter += Changes[j].Spaces; + // Changes are generally 1:1 with the tokens, but a change could also be + // inside of a token, in which case it's counted more than once: once for + // the whitespace surrounding the token (!IsInsideToken) and once for + // each whitespace change within it (IsInsideToken). + // Therefore, changes inside of a token should only count the space. + if (!Changes[j].IsInsideToken) +LineLengthAfter += Changes[j].TokenLength; +} unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; // If we are restricted by the maximum column width, end the sequence. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align
JakeMerdichAMD added a comment. Hey @MyDeveloperDay, can I get your assistance committing this when you have the chance? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79465/new/ https://reviews.llvm.org/D79465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align
MyDeveloperDay accepted this revision. MyDeveloperDay added a comment. This revision is now accepted and ready to land. LGTM Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79465/new/ https://reviews.llvm.org/D79465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align
JakeMerdichAMD updated this revision to Diff 264294. JakeMerdichAMD added a comment. Rebase to fix merge conflict Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79465/new/ https://reviews.llvm.org/D79465 Files: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -11953,6 +11953,16 @@ " x = 1;\n" "y = 1;\n", Alignment); + + Alignment.ReflowComments = true; + Alignment.ColumnLimit = 50; + EXPECT_EQ("int x = 0;\n" +"int yy = 1; /// specificlennospace\n" +"int zzz = 2;\n", +format("int x = 0;\n" + "int yy = 1; ///specificlennospace\n" + "int zzz = 2;\n", + Alignment)); } TEST_F(FormatTest, AlignConsecutiveDeclarations) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -445,8 +445,16 @@ unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; int LineLengthAfter = Changes[i].TokenLength; -for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) - LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength; +for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) { + LineLengthAfter += Changes[j].Spaces; + // Changes are generally 1:1 with the tokens, but a change could also be + // inside of a token, in which case it's counted more than once: once for + // the whitespace surrounding the token (!IsInsideToken) and once for + // each whitespace change within it (IsInsideToken). + // Therefore, changes inside of a token should only count the space. + if (!Changes[j].IsInsideToken) +LineLengthAfter += Changes[j].TokenLength; +} unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; // If we are restricted by the maximum column width, end the sequence. Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -11953,6 +11953,16 @@ " x = 1;\n" "y = 1;\n", Alignment); + + Alignment.ReflowComments = true; + Alignment.ColumnLimit = 50; + EXPECT_EQ("int x = 0;\n" +"int yy = 1; /// specificlennospace\n" +"int zzz = 2;\n", +format("int x = 0;\n" + "int yy = 1; ///specificlennospace\n" + "int zzz = 2;\n", + Alignment)); } TEST_F(FormatTest, AlignConsecutiveDeclarations) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -445,8 +445,16 @@ unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; int LineLengthAfter = Changes[i].TokenLength; -for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) - LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength; +for (unsigned j = i + 1; j != e && Changes[j].NewlinesBefore == 0; ++j) { + LineLengthAfter += Changes[j].Spaces; + // Changes are generally 1:1 with the tokens, but a change could also be + // inside of a token, in which case it's counted more than once: once for + // the whitespace surrounding the token (!IsInsideToken) and once for + // each whitespace change within it (IsInsideToken). + // Therefore, changes inside of a token should only count the space. + if (!Changes[j].IsInsideToken) +LineLengthAfter += Changes[j].TokenLength; +} unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; // If we are restricted by the maximum column width, end the sequence. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align
JakeMerdichAMD updated this revision to Diff 264259. JakeMerdichAMD added a comment. Add a comment explaining why checking IsInsideToken is needed here. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79465/new/ https://reviews.llvm.org/D79465 Files: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -11564,6 +11564,16 @@ " x = 1;\n" "y = 1;\n", Alignment); + + Alignment.ReflowComments = true; + Alignment.ColumnLimit = 50; + EXPECT_EQ("int x = 0;\n" +"int yy = 1; /// specificlennospace\n" +"int zzz = 2;\n", +format("int x = 0;\n" + "int yy = 1; ///specificlennospace\n" + "int zzz = 2;\n", + Alignment)); } TEST_F(FormatTest, AlignConsecutiveDeclarations) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -410,8 +410,16 @@ unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; int LineLengthAfter = -Changes[i].Spaces; -for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j) - LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength; +for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j) { + LineLengthAfter += Changes[j].Spaces; + // Changes are generally 1:1 with the tokens, but a change could also be + // inside of a token, in which case it's counted more than once: once for + // the whitespace surrounding the token (!IsInsideToken) and once for + // each whitespace change within it (IsInsideToken). + // Therefore, changes inside of a token should only count the space. + if (!Changes[j].IsInsideToken) +LineLengthAfter += Changes[j].TokenLength; +} unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; // If we are restricted by the maximum column width, end the sequence. Index: clang/unittests/Format/FormatTest.cpp === --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -11564,6 +11564,16 @@ " x = 1;\n" "y = 1;\n", Alignment); + + Alignment.ReflowComments = true; + Alignment.ColumnLimit = 50; + EXPECT_EQ("int x = 0;\n" +"int yy = 1; /// specificlennospace\n" +"int zzz = 2;\n", +format("int x = 0;\n" + "int yy = 1; ///specificlennospace\n" + "int zzz = 2;\n", + Alignment)); } TEST_F(FormatTest, AlignConsecutiveDeclarations) { Index: clang/lib/Format/WhitespaceManager.cpp === --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -410,8 +410,16 @@ unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn; int LineLengthAfter = -Changes[i].Spaces; -for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j) - LineLengthAfter += Changes[j].Spaces + Changes[j].TokenLength; +for (unsigned j = i; j != e && Changes[j].NewlinesBefore == 0; ++j) { + LineLengthAfter += Changes[j].Spaces; + // Changes are generally 1:1 with the tokens, but a change could also be + // inside of a token, in which case it's counted more than once: once for + // the whitespace surrounding the token (!IsInsideToken) and once for + // each whitespace change within it (IsInsideToken). + // Therefore, changes inside of a token should only count the space. + if (!Changes[j].IsInsideToken) +LineLengthAfter += Changes[j].TokenLength; +} unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; // If we are restricted by the maximum column width, end the sequence. ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align
MyDeveloperDay added inline comments. Comment at: clang/lib/Format/WhitespaceManager.cpp:417 +LineLengthAfter += Changes[j].TokenLength; +} unsigned ChangeMaxColumn = Style.ColumnLimit - LineLengthAfter; could you help us here with a comment, I don't understand what they mean by Change.IsInsideToken? Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79465/new/ https://reviews.llvm.org/D79465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D79465: [clang-format] Fix line lengths w/ comments in align
MyDeveloperDay added a comment. I've been able to reproduce and the patch looks good, I've just not had a chance to read the review in-depth (I don't know this section of the code as well as other parts). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D79465/new/ https://reviews.llvm.org/D79465 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits