r186117 - clang-format: Break before trailing annotations.
Daniel Jasper
djasper at google.com
Thu Jul 11 14:02:56 PDT 2013
Author: djasper
Date: Thu Jul 11 16:02:56 2013
New Revision: 186117
URL: http://llvm.org/viewvc/llvm-project?rev=186117&view=rev
Log:
clang-format: Break before trailing annotations.
(if they are not function-like).
Before:
SomeFunction(aaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaa)
OVERRIDE;
After:
SomeFunction(aaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=186117&r1=186116&r2=186117&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Jul 11 16:02:56 2013
@@ -1052,8 +1052,10 @@ unsigned TokenAnnotator::splitPenalty(co
return 150;
}
- // Breaking before a trailing 'const' is bad.
- if (Left.is(tok::r_paren) && Right.is(tok::kw_const))
+ // Breaking before a trailing 'const' or not-function-like annotation is bad.
+ if (Left.is(tok::r_paren) &&
+ (Right.is(tok::kw_const) || (Right.is(tok::identifier) && Right.Next &&
+ Right.Next->isNot(tok::l_paren))))
return 150;
// In for-loops, prefer breaking at ',' and ';'.
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=186117&r1=186116&r2=186117&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Jul 11 16:02:56 2013
@@ -2482,6 +2482,7 @@ TEST_F(FormatTest, TrailingReturnType) {
}
TEST_F(FormatTest, BreaksFunctionDeclarationsWithTrailingTokens) {
+ // Avoid breaking before trailing 'const'.
verifyFormat("void someLongFunction(\n"
" int someLongParameter) const {}",
getLLVMStyleWithColumns(46));
@@ -2500,6 +2501,13 @@ TEST_F(FormatTest, BreaksFunctionDeclara
" const {}",
Style);
+ // Avoid breaking before other trailing annotations, if they are not
+ // function-like.
+ verifyFormat("void SomeFunction(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaa) OVERRIDE;");
+
+ // Breaking before function-like trailing annotations is fine to keep them
+ // close to their arguments.
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)\n"
" LOCKS_EXCLUDED(aaaaaaaaaaaaa);");
verifyFormat("void aaaaaaaaaaaa(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) const\n"
More information about the cfe-commits
mailing list