Author: djasper Date: Tue Dec 1 07:28:53 2015 New Revision: 254414 URL: http://llvm.org/viewvc/llvm-project?rev=254414&view=rev Log: clang-format: Make it possible to turn off comment reflowing.
Modified: cfe/trunk/include/clang/Format/Format.h cfe/trunk/lib/Format/ContinuationIndenter.cpp cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/FormatTest.cpp Modified: cfe/trunk/include/clang/Format/Format.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Format/Format.h?rev=254414&r1=254413&r2=254414&view=diff ============================================================================== --- cfe/trunk/include/clang/Format/Format.h (original) +++ cfe/trunk/include/clang/Format/Format.h Tue Dec 1 07:28:53 2015 @@ -466,9 +466,12 @@ struct FormatStyle { PAS_Middle }; - /// Pointer and reference alignment style. + /// \brief Pointer and reference alignment style. PointerAlignmentStyle PointerAlignment; + /// \brief If true, clang-format will attempt to re-flow comments. + bool ReflowComments; + /// \brief If true, clang-format will sort #includes. bool SortIncludes; Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=254414&r1=254413&r2=254414&view=diff ============================================================================== --- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original) +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Dec 1 07:28:53 2015 @@ -1076,7 +1076,8 @@ unsigned ContinuationIndenter::breakProt return 0; } } else if (Current.is(TT_BlockComment) && Current.isTrailingComment()) { - if (CommentPragmasRegex.match(Current.TokenText.substr(2))) + if (!Style.ReflowComments || + CommentPragmasRegex.match(Current.TokenText.substr(2))) return 0; Token.reset(new BreakableBlockComment( Current, State.Line->Level, StartColumn, Current.OriginalColumn, @@ -1084,7 +1085,8 @@ unsigned ContinuationIndenter::breakProt } else if (Current.is(TT_LineComment) && (Current.Previous == nullptr || Current.Previous->isNot(TT_ImplicitStringLiteral))) { - if (CommentPragmasRegex.match(Current.TokenText.substr(2))) + if (!Style.ReflowComments || + CommentPragmasRegex.match(Current.TokenText.substr(2))) return 0; Token.reset(new BreakableLineComment(Current, State.Line->Level, StartColumn, /*InPPDirective=*/false, Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=254414&r1=254413&r2=254414&view=diff ============================================================================== --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Tue Dec 1 07:28:53 2015 @@ -284,8 +284,9 @@ template <> struct MappingTraits<FormatS IO.mapOptional("PenaltyExcessCharacter", Style.PenaltyExcessCharacter); IO.mapOptional("PenaltyReturnTypeOnItsOwnLine", Style.PenaltyReturnTypeOnItsOwnLine); - IO.mapOptional("SortIncludes", Style.SortIncludes); IO.mapOptional("PointerAlignment", Style.PointerAlignment); + IO.mapOptional("ReflowComments", Style.ReflowComments); + IO.mapOptional("SortIncludes", Style.SortIncludes); IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast); IO.mapOptional("SpaceBeforeAssignmentOperators", Style.SpaceBeforeAssignmentOperators); @@ -490,6 +491,7 @@ FormatStyle getLLVMStyle() { LLVMStyle.SpacesBeforeTrailingComments = 1; LLVMStyle.Standard = FormatStyle::LS_Cpp11; LLVMStyle.UseTab = FormatStyle::UT_Never; + LLVMStyle.ReflowComments = true; LLVMStyle.SpacesInParentheses = false; LLVMStyle.SpacesInSquareBrackets = false; LLVMStyle.SpaceInEmptyParentheses = false; Modified: cfe/trunk/unittests/Format/FormatTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=254414&r1=254413&r2=254414&view=diff ============================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp (original) +++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Dec 1 07:28:53 2015 @@ -1197,6 +1197,13 @@ TEST_F(FormatTest, AlignsBlockComments) "comment */")); } +TEST_F(FormatTest, CommentReflowingCanBeTurnedOff) { + FormatStyle Style = getLLVMStyleWithColumns(20); + Style.ReflowComments = false; + verifyFormat("// aaaaaaaaa aaaaaaaaaa aaaaaaaaaa", Style); + verifyFormat("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa */", Style); +} + TEST_F(FormatTest, CorrectlyHandlesLengthOfBlockComments) { EXPECT_EQ("double *x; /* aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa */", @@ -9639,6 +9646,7 @@ TEST_F(FormatTest, ParsesConfigurationBo CHECK_PARSE_BOOL(ObjCSpaceAfterProperty); CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList); CHECK_PARSE_BOOL(Cpp11BracedListStyle); + CHECK_PARSE_BOOL(ReflowComments); CHECK_PARSE_BOOL(SortIncludes); CHECK_PARSE_BOOL(SpacesInParentheses); CHECK_PARSE_BOOL(SpacesInSquareBrackets); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits