From 81d2d38d2d774a2550fa0d2efffa707e7a53b39c Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 1 Apr 2013 17:13:26 +0000 Subject: Improve formatting of function types. Before: void * (*a)(int *, SomeType *); After: void *(*a)(int *, SomeType *); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@178474 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 1 - lib/Format/TokenAnnotator.cpp | 12 ++++-------- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'lib/Format') diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 245b7f60a6..e8a8388387 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -805,7 +805,6 @@ private: // parameter, i.e. let nested calls have an indent of 4. State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(". else if (Previous.is(tok::comma)) - // Top-level spaces are exempt as that mostly leads to better results. State.Stack.back().LastSpace = State.Column; else if ((Previous.Type == TT_BinaryOperator || Previous.Type == TT_ConditionalExpr || diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 25670d4f68..23c5a46355 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -682,12 +682,6 @@ private: 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) @@ -993,7 +987,8 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line, if (Left.Type == TT_PointerOrReference) return Right.FormatTok.Tok.isLiteral() || ((Right.Type != TT_PointerOrReference) && - Right.isNot(tok::l_paren) && Style.PointerBindsToType); + Right.isNot(tok::l_paren) && Style.PointerBindsToType && + Left.Parent && Left.Parent->isNot(tok::l_paren)); if (Right.is(tok::star) && Left.is(tok::l_paren)) return false; if (Left.is(tok::l_square)) @@ -1057,7 +1052,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, Tok.Children[0].Type == TT_PointerOrReference && !Tok.Children[0].Children.empty() && Tok.Children[0].Children[0].isNot(tok::r_paren) && - Tok.Parent->isNot(tok::l_paren)) + Tok.Parent->isNot(tok::l_paren) && + (Tok.Parent->Type != TT_PointerOrReference || Style.PointerBindsToType)) return true; if (Tok.Parent->Type == TT_UnaryOperator || Tok.Parent->Type == TT_CastRParen) return false; -- cgit v1.2.3-18-g5258