r175959 - Allow splitting between string literals and identifiers.
Daniel Jasper
djasper at google.com
Fri Feb 22 23:46:38 PST 2013
Author: djasper
Date: Sat Feb 23 01:46:38 2013
New Revision: 175959
URL: http://llvm.org/viewvc/llvm-project?rev=175959&view=rev
Log:
Allow splitting between string literals and identifiers.
Also don't break in long include directives as that is not desired.
We can now format:
#include "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
#define LL_FORMAT "ll"
printf("aaaaa: %d, bbbbbbbbb: %" LL_FORMAT "d, cccccccc: %" LL_FORMAT
"d, ddddddddd: %" LL_FORMAT "d\n");
Before, this led to weird results.
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=175959&r1=175958&r2=175959&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Sat Feb 23 01:46:38 2013
@@ -415,6 +415,10 @@ private:
}
} else {
while (CurrentToken != NULL) {
+ if (CurrentToken->is(tok::string_literal))
+ // Mark these string literals as "implicit" literals, too, so that
+ // they are not split or line-wrapped.
+ CurrentToken->Type = TT_ImplicitStringLiteral;
next();
}
}
@@ -1098,6 +1102,8 @@ bool TokenAnnotator::canBreakBefore(cons
if (Right.is(tok::r_paren) || Right.is(tok::greater))
return false;
+ if (Left.is(tok::identifier) && Right.is(tok::string_literal))
+ return true;
return (isBinaryOperator(Left) && Left.isNot(tok::lessless)) ||
Left.is(tok::comma) || Right.is(tok::lessless) ||
Right.is(tok::arrow) || Right.is(tok::period) ||
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175959&r1=175958&r2=175959&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Feb 23 01:46:38 2013
@@ -1460,6 +1460,11 @@ TEST_F(FormatTest, AlignsStringLiterals)
verifyFormat("a = a + \"a\"\n"
" \"a\"\n"
" \"a\";");
+
+ verifyFormat(
+ "#define LL_FORMAT \"ll\"\n"
+ "printf(\"aaaaa: %d, bbbbbb: %\" LL_FORMAT \"d, cccccccc: %\" LL_FORMAT\n"
+ " \"d, ddddddddd: %\" LL_FORMAT \"d\");");
}
TEST_F(FormatTest, AlignsPipes) {
@@ -1933,7 +1938,9 @@ TEST_F(FormatTest, HandlesIncludeDirecti
"#include \"string.h\"\n"
"#include \"string.h\"\n"
"#include <a-a>\n"
- "#include < path with space >\n");
+ "#include < path with space >\n"
+ "#include \"some very long include paaaaaaaaaaaaaaaaaaaaaaath\"",
+ getLLVMStyleWithColumns(35));
verifyFormat("#import <string>");
verifyFormat("#import <a/b/c.h>");
More information about the cfe-commits
mailing list