[cfe-commits] r172799 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Fri Jan 18 01:19:34 PST 2013
Author: djasper
Date: Fri Jan 18 03:19:33 2013
New Revision: 172799
URL: http://llvm.org/viewvc/llvm-project?rev=172799&view=rev
Log:
Also align trailing line comments in include directives.
Before:
#include <a> // for x
#include <a/b/c> // for yz
After:
#include <a> // for x
#include <a/b/c> // for yz
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=172799&r1=172798&r2=172799&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Jan 18 03:19:33 2013
@@ -350,13 +350,15 @@
// Start iterating at 1 as we have correctly formatted of Token #0 above.
while (State.NextToken != NULL) {
- if (State.NextToken->Type == TT_ImplicitStringLiteral)
- // We will not touch the rest of the white space in this
- // \c UnwrappedLine. The returned value can also not matter, as we
- // cannot continue an top-level implicit string literal on the next
- // line.
- return 0;
- if (Line.Last->TotalLength <= getColumnLimit() - FirstIndent) {
+ if (State.NextToken->Type == TT_ImplicitStringLiteral) {
+ // Calculating the column is important for aligning trailing comments.
+ // FIXME: This does not seem to happen in conjunction with escaped
+ // newlines. If it does, fix!
+ State.Column += State.NextToken->FormatTok.WhiteSpaceLength +
+ State.NextToken->FormatTok.TokenLength;
+ State.NextToken = State.NextToken->Children.empty() ? NULL :
+ &State.NextToken->Children[0];
+ } else if (Line.Last->TotalLength <= getColumnLimit() - FirstIndent) {
addTokenToState(false, false, State);
} else {
unsigned NoBreak = calcPenalty(State, false, UINT_MAX);
@@ -1096,7 +1098,9 @@
if (CurrentToken != NULL && CurrentToken->is(tok::less)) {
next();
while (CurrentToken != NULL) {
- CurrentToken->Type = TT_ImplicitStringLiteral;
+ if (CurrentToken->isNot(tok::comment) ||
+ !CurrentToken->Children.empty())
+ CurrentToken->Type = TT_ImplicitStringLiteral;
next();
}
} else {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=172799&r1=172798&r2=172799&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Jan 18 03:19:33 2013
@@ -386,7 +386,10 @@
"int bbbbbbbbbbbbbbbbbbbbb; // comment\n"
"int ccccccccccccccccccc; // comment");
-
+ verifyFormat("#include \"a\" // comment\n"
+ "#include \"a/b/c\" // comment");
+ verifyFormat("#include <a> // comment\n"
+ "#include <a/b/c> // comment");
verifyFormat("enum E {\n"
" // comment\n"
More information about the cfe-commits
mailing list