r177505 - Improve formatting of function types in template parameters.
Daniel Jasper
djasper at google.com
Wed Mar 20 02:53:18 PDT 2013
Author: djasper
Date: Wed Mar 20 04:53:18 2013
New Revision: 177505
URL: http://llvm.org/viewvc/llvm-project?rev=177505&view=rev
Log:
Improve formatting of function types in template parameters.
Before: A<int * (int)>;
After: A<int *(int)>;
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=177505&r1=177504&r2=177505&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Mar 20 04:53:18 2013
@@ -681,10 +681,15 @@ private:
if (PrevToken->FormatTok.Tok.isLiteral() ||
PrevToken->isOneOf(tok::r_paren, tok::r_square) ||
- NextToken->FormatTok.Tok.isLiteral() || isUnaryOperator(*NextToken) ||
- NextToken->isOneOf(tok::l_paren, tok::l_square))
+ NextToken->FormatTok.Tok.isLiteral() || isUnaryOperator(*NextToken))
return TT_BinaryOperator;
+ // "*(" is probably part of a function type if within template parameters.
+ // Otherwise, it is probably a binary operator.
+ if (NextToken->is(tok::l_paren))
+ return Contexts.back().ContextKind == tok::less ? TT_PointerOrReference
+ : TT_BinaryOperator;
+
// It is very unlikely that we are going to find a pointer or reference type
// definition on the RHS of an assignment.
if (IsExpression)
@@ -989,7 +994,8 @@ bool TokenAnnotator::spaceRequiredBetwee
!Style.PointerBindsToType);
if (Left.Type == TT_PointerOrReference)
return Right.FormatTok.Tok.isLiteral() ||
- ((Right.Type != TT_PointerOrReference) && Style.PointerBindsToType);
+ ((Right.Type != TT_PointerOrReference) &&
+ Right.isNot(tok::l_paren) && Style.PointerBindsToType);
if (Right.is(tok::star) && Left.is(tok::l_paren))
return false;
if (Left.is(tok::l_square))
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=177505&r1=177504&r2=177505&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Mar 20 04:53:18 2013
@@ -2265,10 +2265,13 @@ TEST_F(FormatTest, FormatsFunctionTypes)
verifyFormat("A<bool()> a;");
verifyFormat("A<SomeType()> a;");
verifyFormat("A<void(*)(int, std::string)> a;");
+ verifyFormat("A<void *(int)>;");
// FIXME: Inconsistent.
verifyFormat("int (*func)(void *);");
verifyFormat("void f() { int(*func)(void *); }");
+
+ verifyGoogleFormat("A<void*(int)>;");
}
TEST_F(FormatTest, BreaksLongDeclarations) {
More information about the cfe-commits
mailing list