forked from OSchip/llvm-project
Clean up formatting of function types.
Before: int (*func)(void*); void f() { int(*func)(void*); } After (consistent space after "int"): int (*func)(void*); void f() { int (*func)(void*); } llvm-svn: 182756
This commit is contained in:
parent
f3e663af39
commit
3719428c06
|
@ -141,6 +141,7 @@ private:
|
||||||
Left->Type = TT_ObjCMethodExpr;
|
Left->Type = TT_ObjCMethodExpr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MightBeFunctionType = CurrentToken->is(tok::star);
|
||||||
while (CurrentToken != NULL) {
|
while (CurrentToken != NULL) {
|
||||||
// LookForDecls is set when "if (" has been seen. Check for
|
// LookForDecls is set when "if (" has been seen. Check for
|
||||||
// 'identifier' '*' 'identifier' followed by not '=' -- this
|
// 'identifier' '*' 'identifier' followed by not '=' -- this
|
||||||
|
@ -158,9 +159,9 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CurrentToken->is(tok::r_paren)) {
|
if (CurrentToken->is(tok::r_paren)) {
|
||||||
if (CurrentToken->Children.empty() ||
|
if (MightBeFunctionType && !CurrentToken->Children.empty() &&
|
||||||
!CurrentToken->Children[0].isOneOf(tok::l_paren, tok::l_square))
|
CurrentToken->Children[0].isOneOf(tok::l_paren, tok::l_square))
|
||||||
Left->DefinesFunctionType = false;
|
Left->Type = TT_FunctionTypeLParen;
|
||||||
Left->MatchingParen = CurrentToken;
|
Left->MatchingParen = CurrentToken;
|
||||||
CurrentToken->MatchingParen = Left;
|
CurrentToken->MatchingParen = Left;
|
||||||
|
|
||||||
|
@ -179,7 +180,7 @@ private:
|
||||||
return false;
|
return false;
|
||||||
if (CurrentToken->Parent->Type == TT_PointerOrReference &&
|
if (CurrentToken->Parent->Type == TT_PointerOrReference &&
|
||||||
CurrentToken->Parent->Parent->isOneOf(tok::l_paren, tok::coloncolon))
|
CurrentToken->Parent->Parent->isOneOf(tok::l_paren, tok::coloncolon))
|
||||||
Left->DefinesFunctionType = true;
|
MightBeFunctionType = true;
|
||||||
updateParameterCount(Left, CurrentToken);
|
updateParameterCount(Left, CurrentToken);
|
||||||
if (!consumeToken())
|
if (!consumeToken())
|
||||||
return false;
|
return false;
|
||||||
|
@ -699,7 +700,8 @@ private:
|
||||||
if (NextToken == NULL)
|
if (NextToken == NULL)
|
||||||
return TT_Unknown;
|
return TT_Unknown;
|
||||||
|
|
||||||
if (PrevToken->is(tok::l_paren) && !IsExpression)
|
if (PrevToken->is(tok::coloncolon) ||
|
||||||
|
(PrevToken->is(tok::l_paren) && !IsExpression))
|
||||||
return TT_PointerOrReference;
|
return TT_PointerOrReference;
|
||||||
|
|
||||||
if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
|
if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace,
|
||||||
|
@ -1068,7 +1070,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
|
||||||
return Left.FormatTok.Tok.isLiteral() ||
|
return Left.FormatTok.Tok.isLiteral() ||
|
||||||
((Left.Type != TT_PointerOrReference) && Left.isNot(tok::l_paren) &&
|
((Left.Type != TT_PointerOrReference) && Left.isNot(tok::l_paren) &&
|
||||||
!Style.PointerBindsToType);
|
!Style.PointerBindsToType);
|
||||||
if (Right.DefinesFunctionType &&
|
if (Right.Type == TT_FunctionTypeLParen &&
|
||||||
(Left.Type != TT_PointerOrReference || Style.PointerBindsToType))
|
(Left.Type != TT_PointerOrReference || Style.PointerBindsToType))
|
||||||
return true;
|
return true;
|
||||||
if (Left.Type == TT_PointerOrReference)
|
if (Left.Type == TT_PointerOrReference)
|
||||||
|
|
|
@ -36,6 +36,7 @@ enum TokenType {
|
||||||
TT_ImplicitStringLiteral,
|
TT_ImplicitStringLiteral,
|
||||||
TT_InlineASMColon,
|
TT_InlineASMColon,
|
||||||
TT_InheritanceColon,
|
TT_InheritanceColon,
|
||||||
|
TT_FunctionTypeLParen,
|
||||||
TT_LineComment,
|
TT_LineComment,
|
||||||
TT_ObjCArrayLiteral,
|
TT_ObjCArrayLiteral,
|
||||||
TT_ObjCBlockLParen,
|
TT_ObjCBlockLParen,
|
||||||
|
@ -78,9 +79,8 @@ public:
|
||||||
ClosesTemplateDeclaration(false), MatchingParen(NULL),
|
ClosesTemplateDeclaration(false), MatchingParen(NULL),
|
||||||
ParameterCount(0), TotalLength(FormatTok.TokenLength),
|
ParameterCount(0), TotalLength(FormatTok.TokenLength),
|
||||||
UnbreakableTailLength(0), BindingStrength(0), SplitPenalty(0),
|
UnbreakableTailLength(0), BindingStrength(0), SplitPenalty(0),
|
||||||
LongestObjCSelectorName(0), DefinesFunctionType(false), Parent(NULL),
|
LongestObjCSelectorName(0), Parent(NULL), FakeRParens(0),
|
||||||
FakeRParens(0), LastInChainOfCalls(false),
|
LastInChainOfCalls(false), PartOfMultiVariableDeclStmt(false) {}
|
||||||
PartOfMultiVariableDeclStmt(false) {}
|
|
||||||
|
|
||||||
bool is(tok::TokenKind Kind) const { return FormatTok.Tok.is(Kind); }
|
bool is(tok::TokenKind Kind) const { return FormatTok.Tok.is(Kind); }
|
||||||
|
|
||||||
|
@ -171,9 +171,6 @@ public:
|
||||||
/// definition or call, this contains the length of the longest name.
|
/// definition or call, this contains the length of the longest name.
|
||||||
unsigned LongestObjCSelectorName;
|
unsigned LongestObjCSelectorName;
|
||||||
|
|
||||||
/// \brief \c true if this is a "(" that starts a function type definition.
|
|
||||||
bool DefinesFunctionType;
|
|
||||||
|
|
||||||
std::vector<AnnotatedToken> Children;
|
std::vector<AnnotatedToken> Children;
|
||||||
AnnotatedToken *Parent;
|
AnnotatedToken *Parent;
|
||||||
|
|
||||||
|
|
|
@ -2820,6 +2820,7 @@ TEST_F(FormatTest, UnderstandsBinaryOperators) {
|
||||||
TEST_F(FormatTest, UnderstandsPointersToMembers) {
|
TEST_F(FormatTest, UnderstandsPointersToMembers) {
|
||||||
verifyFormat("int A::*x;");
|
verifyFormat("int A::*x;");
|
||||||
verifyFormat("int (S::*func)(void *);");
|
verifyFormat("int (S::*func)(void *);");
|
||||||
|
verifyFormat("void f() { int (S::*func)(void *); }");
|
||||||
verifyFormat("typedef bool *(Class::*Member)() const;");
|
verifyFormat("typedef bool *(Class::*Member)() const;");
|
||||||
verifyFormat("void f() {\n"
|
verifyFormat("void f() {\n"
|
||||||
" (a->*f)();\n"
|
" (a->*f)();\n"
|
||||||
|
@ -3124,13 +3125,11 @@ TEST_F(FormatTest, FormatsCasts) {
|
||||||
TEST_F(FormatTest, FormatsFunctionTypes) {
|
TEST_F(FormatTest, FormatsFunctionTypes) {
|
||||||
verifyFormat("A<bool()> a;");
|
verifyFormat("A<bool()> a;");
|
||||||
verifyFormat("A<SomeType()> a;");
|
verifyFormat("A<SomeType()> a;");
|
||||||
verifyFormat("A<void(*)(int, std::string)> a;");
|
verifyFormat("A<void (*)(int, std::string)> a;");
|
||||||
verifyFormat("A<void *(int)>;");
|
verifyFormat("A<void *(int)>;");
|
||||||
verifyFormat("void *(*a)(int *, SomeType *);");
|
verifyFormat("void *(*a)(int *, SomeType *);");
|
||||||
|
|
||||||
// FIXME: Inconsistent.
|
|
||||||
verifyFormat("int (*func)(void *);");
|
verifyFormat("int (*func)(void *);");
|
||||||
verifyFormat("void f() { int(*func)(void *); }");
|
verifyFormat("void f() { int (*func)(void *); }");
|
||||||
|
|
||||||
verifyGoogleFormat("A<void*(int*, SomeType*)>;");
|
verifyGoogleFormat("A<void*(int*, SomeType*)>;");
|
||||||
verifyGoogleFormat("void* (*a)(int);");
|
verifyGoogleFormat("void* (*a)(int);");
|
||||||
|
@ -3691,8 +3690,8 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) {
|
||||||
// protocol lists (but not for template classes):
|
// protocol lists (but not for template classes):
|
||||||
//verifyFormat("- (void)setDelegate:(id <Protocol>)delegate;");
|
//verifyFormat("- (void)setDelegate:(id <Protocol>)delegate;");
|
||||||
|
|
||||||
verifyFormat("- (int(*)())foo:(int(*)())f;");
|
verifyFormat("- (int (*)())foo:(int (*)())f;");
|
||||||
verifyGoogleFormat("- (int(*)())foo:(int(*)())foo;");
|
verifyGoogleFormat("- (int (*)())foo:(int (*)())foo;");
|
||||||
|
|
||||||
// If there's no return type (very rare in practice!), LLVM and Google style
|
// If there's no return type (very rare in practice!), LLVM and Google style
|
||||||
// agree.
|
// agree.
|
||||||
|
|
Loading…
Reference in New Issue