Recognize < and > as binary expressions in builder-type calls.

The current heuristic assumes that there can't be binary operators in
builder-type calls (excluding assigments). However, it also excluded
< and > in general, which is wrong. Now they are only excluded if they
are template parameters.

Before:
return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa()i
       .aaaaaa() < aaaaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();

After:
return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <
       aaaaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();

llvm-svn: 175291
This commit is contained in:
Daniel Jasper 2013-02-15 20:33:06 +00:00
parent b7eec015d0
commit eb50c676ba
2 changed files with 8 additions and 3 deletions

View File

@ -467,11 +467,13 @@ public:
KeywordVirtualFound = true;
if (CurrentToken->is(tok::period) || CurrentToken->is(tok::arrow))
++PeriodsAndArrows;
if (getPrecedence(*CurrentToken) > prec::Assignment &&
CurrentToken->isNot(tok::less) && CurrentToken->isNot(tok::greater))
CanBeBuilderTypeStmt = false;
AnnotatedToken *TheToken = CurrentToken;
if (!consumeToken())
return LT_Invalid;
if (getPrecedence(*TheToken) > prec::Assignment &&
TheToken->Type != TT_TemplateOpener &&
TheToken->Type != TT_TemplateCloser)
CanBeBuilderTypeStmt = false;
}
if (KeywordVirtualFound)
return LT_VirtualFunctionDecl;

View File

@ -1221,6 +1221,9 @@ TEST_F(FormatTest, FormatsBuilderPattern) {
" .StartsWith(\".eh_frame\", ORDER_EH_FRAME).StartsWith(\".init\", ORDER_INIT)\n"
" .StartsWith(\".fini\", ORDER_FINI).StartsWith(\".hash\", ORDER_HASH)\n"
" .Default(ORDER_TEXT);\n");
verifyFormat("return aaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa() <\n"
" aaaaaaaaaaaaaaaaaaa->aaaaa().aaaaaaaaaaaaa().aaaaaa();");
}
TEST_F(FormatTest, DoesNotBreakTrailingAnnotation) {