Left->Type = TT_ObjCMethodExpr;
}
+ bool MightBeFunctionType = CurrentToken->is(tok::star);
while (CurrentToken != NULL) {
// LookForDecls is set when "if (" has been seen. Check for
// 'identifier' '*' 'identifier' followed by not '=' -- this
}
if (CurrentToken->is(tok::r_paren)) {
- if (CurrentToken->Children.empty() ||
- !CurrentToken->Children[0].isOneOf(tok::l_paren, tok::l_square))
- Left->DefinesFunctionType = false;
+ if (MightBeFunctionType && !CurrentToken->Children.empty() &&
+ CurrentToken->Children[0].isOneOf(tok::l_paren, tok::l_square))
+ Left->Type = TT_FunctionTypeLParen;
Left->MatchingParen = CurrentToken;
CurrentToken->MatchingParen = Left;
return false;
if (CurrentToken->Parent->Type == TT_PointerOrReference &&
CurrentToken->Parent->Parent->isOneOf(tok::l_paren, tok::coloncolon))
- Left->DefinesFunctionType = true;
+ MightBeFunctionType = true;
updateParameterCount(Left, CurrentToken);
if (!consumeToken())
return false;
if (NextToken == NULL)
return TT_Unknown;
- if (PrevToken->is(tok::l_paren) && !IsExpression)
+ if (PrevToken->is(tok::coloncolon) ||
+ (PrevToken->is(tok::l_paren) && !IsExpression))
return TT_PointerOrReference;
if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
return Left.FormatTok.Tok.isLiteral() ||
((Left.Type != TT_PointerOrReference) && Left.isNot(tok::l_paren) &&
!Style.PointerBindsToType);
- if (Right.DefinesFunctionType &&
+ if (Right.Type == TT_FunctionTypeLParen &&
(Left.Type != TT_PointerOrReference || Style.PointerBindsToType))
return true;
if (Left.Type == TT_PointerOrReference)
TT_ImplicitStringLiteral,
TT_InlineASMColon,
TT_InheritanceColon,
+ TT_FunctionTypeLParen,
TT_LineComment,
TT_ObjCArrayLiteral,
TT_ObjCBlockLParen,
ClosesTemplateDeclaration(false), MatchingParen(NULL),
ParameterCount(0), TotalLength(FormatTok.TokenLength),
UnbreakableTailLength(0), BindingStrength(0), SplitPenalty(0),
- LongestObjCSelectorName(0), DefinesFunctionType(false), Parent(NULL),
- FakeRParens(0), LastInChainOfCalls(false),
- PartOfMultiVariableDeclStmt(false) {}
+ LongestObjCSelectorName(0), Parent(NULL), FakeRParens(0),
+ LastInChainOfCalls(false), PartOfMultiVariableDeclStmt(false) {}
bool is(tok::TokenKind Kind) const { return FormatTok.Tok.is(Kind); }
/// definition or call, this contains the length of the longest name.
unsigned LongestObjCSelectorName;
- /// \brief \c true if this is a "(" that starts a function type definition.
- bool DefinesFunctionType;
-
std::vector<AnnotatedToken> Children;
AnnotatedToken *Parent;
TEST_F(FormatTest, UnderstandsPointersToMembers) {
verifyFormat("int A::*x;");
verifyFormat("int (S::*func)(void *);");
+ verifyFormat("void f() { int (S::*func)(void *); }");
verifyFormat("typedef bool *(Class::*Member)() const;");
verifyFormat("void f() {\n"
" (a->*f)();\n"
TEST_F(FormatTest, FormatsFunctionTypes) {
verifyFormat("A<bool()> a;");
verifyFormat("A<SomeType()> a;");
- verifyFormat("A<void(*)(int, std::string)> a;");
+ verifyFormat("A<void (*)(int, std::string)> a;");
verifyFormat("A<void *(int)>;");
verifyFormat("void *(*a)(int *, SomeType *);");
-
- // FIXME: Inconsistent.
verifyFormat("int (*func)(void *);");
- verifyFormat("void f() { int(*func)(void *); }");
+ verifyFormat("void f() { int (*func)(void *); }");
verifyGoogleFormat("A<void*(int*, SomeType*)>;");
verifyGoogleFormat("void* (*a)(int);");
// protocol lists (but not for template classes):
//verifyFormat("- (void)setDelegate:(id <Protocol>)delegate;");
- verifyFormat("- (int(*)())foo:(int(*)())f;");
- verifyGoogleFormat("- (int(*)())foo:(int(*)())foo;");
+ verifyFormat("- (int (*)())foo:(int (*)())f;");
+ verifyGoogleFormat("- (int (*)())foo:(int (*)())foo;");
// If there's no return type (very rare in practice!), LLVM and Google style
// agree.