r175165 - Fix counting of parameters so that r175162 works as expected.
Daniel Jasper
djasper at google.com
Thu Feb 14 07:01:34 PST 2013
Author: djasper
Date: Thu Feb 14 09:01:34 2013
New Revision: 175165
URL: http://llvm.org/viewvc/llvm-project?rev=175165&view=rev
Log:
Fix counting of parameters so that r175162 works as expected.
Before:
aaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa()
.aaaaaaaaaaaaaaaaa());
After:
aaaaaaaaaaaaaaaaaaaaaaaaa(
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa());
Not sure which of the formattings above is better, but we should not pick
one by accident.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/TokenAnnotator.h
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=175165&r1=175164&r2=175165&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Thu Feb 14 09:01:34 2013
@@ -107,8 +107,7 @@ private:
if (CurrentToken->is(tok::pipepipe) || CurrentToken->is(tok::ampamp) ||
CurrentToken->is(tok::question) || CurrentToken->is(tok::colon))
return false;
- if (CurrentToken->is(tok::comma))
- ++Left->ParameterCount;
+ updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
}
@@ -175,8 +174,7 @@ private:
}
if (CurrentToken->is(tok::r_square) || CurrentToken->is(tok::r_brace))
return false;
- if (CurrentToken->is(tok::comma))
- ++Left->ParameterCount;
+ updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
}
@@ -240,8 +238,7 @@ private:
}
if (CurrentToken->is(tok::r_paren) || CurrentToken->is(tok::r_brace))
return false;
- if (CurrentToken->is(tok::comma))
- ++Left->ParameterCount;
+ updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
}
@@ -263,13 +260,19 @@ private:
}
if (CurrentToken->is(tok::r_paren) || CurrentToken->is(tok::r_square))
return false;
- if (CurrentToken->is(tok::comma))
- ++Left->ParameterCount;
+ updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
}
return true;
}
+
+ void updateParameterCount(AnnotatedToken *Left, AnnotatedToken *Current) {
+ if (Current->is(tok::comma))
+ ++Left->ParameterCount;
+ else if (Left->ParameterCount == 0 && Current->isNot(tok::comment))
+ Left->ParameterCount = 1;
+ }
bool parseConditional() {
while (CurrentToken != NULL) {
Modified: cfe/trunk/lib/Format/TokenAnnotator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=175165&r1=175164&r2=175165&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.h (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.h Thu Feb 14 09:01:34 2013
@@ -73,7 +73,7 @@ public:
: FormatTok(FormatTok), Type(TT_Unknown), SpacesRequiredBefore(0),
CanBreakBefore(false), MustBreakBefore(false),
ClosesTemplateDeclaration(false), MatchingParen(NULL),
- ParameterCount(1), BindingStrength(0), SplitPenalty(0),
+ ParameterCount(0), BindingStrength(0), SplitPenalty(0),
LongestObjCSelectorName(0), Parent(NULL), FakeLParens(0),
FakeRParens(0) {
}
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175165&r1=175164&r2=175165&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Feb 14 09:01:34 2013
@@ -1453,6 +1453,10 @@ TEST_F(FormatTest, WrapsAtFunctionCallsI
"aaaaaaaaaaa->aaaaaaaaa(\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaa->aaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaa));\n");
+
+ verifyFormat(
+ "aaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa().aaaaaaaaaaaaaaaaa());");
}
TEST_F(FormatTest, WrapsTemplateDeclarations) {
More information about the cfe-commits
mailing list