r185346 - Fix incorrect token counting introduced by r185319.
Daniel Jasper
djasper at google.com
Mon Jul 1 09:43:38 PDT 2013
Author: djasper
Date: Mon Jul 1 11:43:38 2013
New Revision: 185346
URL: http://llvm.org/viewvc/llvm-project?rev=185346&view=rev
Log:
Fix incorrect token counting introduced by r185319.
This lead to weird formatting.
Before:
DoSomethingWithVector({ {} /* No data */ }, {
{ 1, 2 }
});
After:
DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } });
Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=185346&r1=185345&r2=185346&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jul 1 11:43:38 2013
@@ -257,8 +257,10 @@ void UnwrappedLineParser::calculateBrace
do {
// Get next none-comment token.
FormatToken *NextTok;
+ unsigned ReadTokens = 0;
do {
NextTok = Tokens->getNextToken();
+ ++ReadTokens;
} while (NextTok->is(tok::comment));
switch (Tok->Tok.getKind()) {
@@ -298,7 +300,7 @@ void UnwrappedLineParser::calculateBrace
break;
}
Tok = NextTok;
- ++Position;
+ Position += ReadTokens;
} while (Tok->Tok.isNot(tok::eof));
// Assume other blocks for all unclosed opening braces.
for (unsigned i = 0, e = LBraceStack.size(); i != e; ++i) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=185346&r1=185345&r2=185346&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jul 1 11:43:38 2013
@@ -3683,6 +3683,7 @@ TEST_F(FormatTest, LayoutCxx11Constructo
" : vector<int>{ bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
" bbbbbbbbbbbbbbbbbbbb, bbbbb };");
verifyFormat("DoSomethingWithVector({} /* No data */);");
+ verifyFormat("DoSomethingWithVector({ {} /* No data */ }, { { 1, 2 } });");
FormatStyle NoSpaces = getLLVMStyle();
NoSpaces.SpacesInBracedLists = false;
More information about the cfe-commits
mailing list