r178888 - Allow breaking after 'class' for classes with looong names.
Daniel Jasper
djasper at google.com
Fri Apr 5 10:22:09 PDT 2013
Author: djasper
Date: Fri Apr 5 12:22:09 2013
New Revision: 178888
URL: http://llvm.org/viewvc/llvm-project?rev=178888&view=rev
Log:
Allow breaking after 'class' for classes with looong names.
(Don't ask, this was a user request).
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=178888&r1=178887&r2=178888&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Apr 5 12:22:09 2013
@@ -939,6 +939,8 @@ unsigned TokenAnnotator::splitPenalty(co
return 150;
if (Left.is(tok::coloncolon))
return 500;
+ if (Left.isOneOf(tok::kw_class, tok::kw_struct))
+ return 5000;
if (Left.Type == TT_RangeBasedForLoopColon ||
Left.Type == TT_InheritanceColon)
@@ -1176,7 +1178,8 @@ bool TokenAnnotator::canBreakBefore(cons
if (Left.is(tok::identifier) && Right.is(tok::string_literal))
return true;
return (isBinaryOperator(Left) && Left.isNot(tok::lessless)) ||
- Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace) ||
+ Left.isOneOf(tok::comma, tok::coloncolon, tok::semi, tok::l_brace,
+ tok::kw_class, tok::kw_struct) ||
Right.isOneOf(tok::lessless, tok::arrow, tok::period, tok::colon) ||
(Left.is(tok::r_paren) && Left.Type != TT_CastRParen &&
Right.isOneOf(tok::identifier, tok::kw___attribute)) ||
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=178888&r1=178887&r2=178888&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Apr 5 12:22:09 2013
@@ -987,7 +987,7 @@ TEST_F(FormatTest, SeparatesLogicalBlock
"};"));
}
-TEST_F(FormatTest, FormatsDerivedClass) {
+TEST_F(FormatTest, FormatsClasses) {
verifyFormat("class A : public B {\n};");
verifyFormat("class A : public ::B {\n};");
@@ -1009,6 +1009,10 @@ TEST_F(FormatTest, FormatsDerivedClass)
" public F,\n"
" public G {\n"
"};");
+
+ verifyFormat("class\n"
+ " ReallyReallyLongClassName {\n};",
+ getLLVMStyleWithColumns(32));
}
TEST_F(FormatTest, FormatsVariableDeclarationsAfterStructOrClass) {
More information about the cfe-commits
mailing list