[cfe-commits] r171358 - in /cfe/trunk: lib/Format/Format.cpp unittests/Format/FormatTest.cpp
Daniel Jasper
djasper at google.com
Wed Jan 2 00:57:13 PST 2013
Author: djasper
Date: Wed Jan 2 02:57:10 2013
New Revision: 171358
URL: http://llvm.org/viewvc/llvm-project?rev=171358&view=rev
Log:
Understand * and & in ternary expressions.
Before: "int a = b ? *c : * d;"
After: "int a = b ? *c : *d;
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=171358&r1=171357&r2=171358&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 2 02:57:10 2013
@@ -806,6 +806,7 @@
if (Index == 0 || Line.Tokens[Index - 1].Tok.is(tok::l_paren) ||
Line.Tokens[Index - 1].Tok.is(tok::comma) ||
Line.Tokens[Index - 1].Tok.is(tok::kw_return) ||
+ Line.Tokens[Index - 1].Tok.is(tok::colon) ||
Annotations[Index - 1].Type == TokenAnnotation::TT_BinaryOperator)
return TokenAnnotation::TT_UnaryOperator;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171358&r1=171357&r2=171358&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 2 02:57:10 2013
@@ -650,7 +650,7 @@
verifyFormat("void operator delete[](void *ptr);");
}
-TEST_F(FormatTest, UnderstandsUsesOfStar) {
+TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("int *f(int *a) {\n}");
verifyFormat("f(a, *a);");
verifyFormat("f(*a);");
@@ -668,6 +668,8 @@
verifyFormat("return 10 * b;");
verifyFormat("return *b * *c;");
verifyFormat("return a & ~b;");
+ verifyFormat("f(b ? *c : *d);");
+ verifyFormat("int a = b ? *c : *d;");
// FIXME: Is this desired for LLVM? Fix if not.
verifyFormat("A<int *> a;");
@@ -680,6 +682,8 @@
verifyGoogleFormat("A<int**> a;");
verifyGoogleFormat("A<int*, int*> a;");
verifyGoogleFormat("A<int**, int**> a;");
+ verifyGoogleFormat("f(b ? *c : *d);");
+ verifyGoogleFormat("int a = b ? *c : *d;");
}
TEST_F(FormatTest, DoesNotBreakBeforePointerOrReference) {
More information about the cfe-commits
mailing list