r175291 - Recognize < and > as binary expressions in builder-type calls.
Daniel Jasper
djasper at google.com
Fri Feb 15 12:33:07 PST 2013
Author: djasper
Date: Fri Feb 15 14:33:06 2013
New Revision: 175291
URL: http://llvm.org/viewvc/llvm-project?rev=175291&view=rev
Log:
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();
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=175291&r1=175290&r2=175291&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Fri Feb 15 14:33:06 2013
@@ -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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175291&r1=175290&r2=175291&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Fri Feb 15 14:33:06 2013
@@ -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) {
More information about the cfe-commits
mailing list