HazardyKnusperkeks updated this revision to Diff 326928. HazardyKnusperkeks added a comment.
- Work with `::max` instead of many checks for `== 0`. - Additional Testcase Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D96896/new/ https://reviews.llvm.org/D96896 Files: clang/lib/Format/ContinuationIndenter.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/FormatTestComments.cpp
Index: clang/unittests/Format/FormatTestComments.cpp =================================================================== --- clang/unittests/Format/FormatTestComments.cpp +++ clang/unittests/Format/FormatTestComments.cpp @@ -3793,6 +3793,189 @@ "int i;// A Comment to be moved\n" " // with indent\n", Style)); + + Style = getLLVMStyleWithColumns(0); + EXPECT_EQ("// Free comment without space\n" + "\n" + "// Free comment with 3 spaces\n" + "\n" + "/// Free Doxygen without space\n" + "\n" + "/// Free Doxygen with 3 spaces\n" + "\n" + "/// A Doxygen Comment with a nested list:\n" + "/// - Foo\n" + "/// - Bar\n" + "/// - Baz\n" + "/// - End\n" + "/// of the inner list\n" + "/// .\n" + "/// .\n" + "\n" + "namespace Foo {\n" + "bool bar(bool b) {\n" + " bool ret1 = true; ///< Doxygenstyle without space\n" + " bool ret2 = true; ///< Doxygenstyle with 3 spaces\n" + " if (b) {\n" + " // Foo\n" + "\n" + " // In function comment\n" + " ret2 = false;\n" + " } // End of if\n" + "\n" + " // if (ret1) {\n" + " // return ret2;\n" + " // }\n" + "\n" + " // if (ret1) {\n" + " // return ret2;\n" + " // }\n" + "\n" + " return ret1 && ret2;\n" + "}\n" + "} // namespace Foo\n" + "\n" + "namespace Bar {\n" + "int foo();\n" + "} // namespace Bar\n" + "//@Nothing added because of the non ascii char\n" + "\n" + "//@ Nothing removed because of the non ascii char\n" + "\n" + "// Comment to move to the left\n" + "// But not this?\n" + "// @but this\n" + "\n" + "// Comment to move to the right\n" + "//@ this stays\n" + "\n" + "//} will not move\n" + "\n" + "// vv will only move\n" + "// } if the line above does\n", + format(Code, Style)); + + Style.SpacesInLineCommentPrefix = {0, 0}; + EXPECT_EQ("//Free comment without space\n" + "\n" + "//Free comment with 3 spaces\n" + "\n" + "///Free Doxygen without space\n" + "\n" + "///Free Doxygen with 3 spaces\n" + "\n" + "///A Doxygen Comment with a nested list:\n" + "///- Foo\n" + "///- Bar\n" + "/// - Baz\n" // Here we keep the relative indentation + "/// - End\n" + "/// of the inner list\n" + "/// .\n" + "///.\n" + "\n" + "namespace Foo {\n" + "bool bar(bool b) {\n" + " bool ret1 = true; ///<Doxygenstyle without space\n" + " bool ret2 = true; ///<Doxygenstyle with 3 spaces\n" + " if (b) {\n" + " //Foo\n" + "\n" + " //In function comment\n" + " ret2 = false;\n" + " } //End of if\n" + "\n" + " //if (ret1) {\n" + " // return ret2;\n" + " //}\n" + "\n" + " //if (ret1) {\n" + " // return ret2;\n" + " //}\n" + "\n" + " return ret1 && ret2;\n" + "}\n" + "} //namespace Foo\n" + "\n" + "namespace Bar {\n" + "int foo();\n" + "} //namespace Bar\n" + "//@Nothing added because of the non ascii char\n" + "\n" + "//@ Nothing removed because of the non ascii char\n" + "\n" + "//Comment to move to the left\n" + "//But not this?\n" + "//@but this\n" + "\n" + "//Comment to move to the right\n" + "//@ this stays\n" + "\n" + "//} will not move\n" + "\n" + "//vv will only move\n" + "//} if the line above does\n", + format(Code, Style)); + + Style.SpacesInLineCommentPrefix = {2, -1u}; + EXPECT_EQ("// Free comment without space\n" + "\n" + "// Free comment with 3 spaces\n" + "\n" + "/// Free Doxygen without space\n" + "\n" + "/// Free Doxygen with 3 spaces\n" + "\n" + "/// A Doxygen Comment with a nested list:\n" + "/// - Foo\n" + "/// - Bar\n" + "/// - Baz\n" + "/// - End\n" + "/// of the inner list\n" + "/// .\n" + "/// .\n" + "\n" + "namespace Foo {\n" + "bool bar(bool b) {\n" + " bool ret1 = true; ///< Doxygenstyle without space\n" + " bool ret2 = true; ///< Doxygenstyle with 3 spaces\n" + " if (b) {\n" + " // Foo\n" + "\n" + " // In function comment\n" + " ret2 = false;\n" + " } // End of if\n" + "\n" + " // if (ret1) {\n" + " // return ret2;\n" + " // }\n" + "\n" + " // if (ret1) {\n" + " // return ret2;\n" + " // }\n" + "\n" + " return ret1 && ret2;\n" + "}\n" + "} // namespace Foo\n" + "\n" + "namespace Bar {\n" + "int foo();\n" + "} // namespace Bar\n" + "//@Nothing added because of the non ascii char\n" + "\n" + "//@ Nothing removed because of the non ascii char\n" + "\n" + "// Comment to move to the left\n" + "// But not this?\n" + "// @but this\n" + "\n" + "// Comment to move to the right\n" + "//@ this stays\n" + "\n" + "//} will not move\n" + "\n" + "// vv will only move\n" + "// } if the line above does\n", + format(Code, Style)); } } // end namespace Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -19253,6 +19253,33 @@ "};\n", Style); } + +TEST_F(FormatTest, LimitlessStringsAndComments) { + auto Style = getLLVMStyleWithColumns(0); + constexpr StringRef Code = + "/**\n" + " * This is a multiline comment with quite some long lines, at least for " + "the LLVM Style.\n" + " * We will redo this with strings and line comments. Just to check if " + "everything is working.\n" + " */\n" + "bool foo() {\n" + " /* Single line multi line comment. */\n" + " const std::string String = \"This is a multiline string with quite " + "some long lines, at least for the LLVM Style.\"\n" + " \"We already did it with multi line " + "comments, and we will do it with line comments. Just to check if " + "everything is working.\";\n" + " // This is a line comment (block) with quite some long lines, at " + "least for the LLVM Style.\n" + " // We already did this with multi line comments and strings. Just to " + "check if everything is working.\n" + " const std::string SmallString = \"Hello World\";\n" + " // Small line comment\n" + " return String.size() > SmallString.size();\n" + "}"; + EXPECT_EQ(Code, format(Code, Style)); +} } // namespace } // namespace format } // namespace clang Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -1993,6 +1993,11 @@ // We don't insert backslashes when breaking line comments. ColumnLimit = Style.ColumnLimit; } + if (ColumnLimit == 0) { + // To make the rest of the function easier set the column limit to the + // maximum, if there should be no limit. + ColumnLimit = std::numeric_limits<decltype(ColumnLimit)>::max(); + } if (Current.UnbreakableTailLength >= ColumnLimit) return {0, false}; // ColumnWidth was already accounted into State.Column before calling
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits