From 886568dc24eb0a1ccf73bf32d1eafa8fd4008cc6 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 9 Jan 2013 08:36:49 +0000 Subject: [PATCH] Fix ObjC block declarations. Before: int ( ^ Block1) (int, int) = ^ (int i, int j) After: int (^Block1) (int, int) = ^(int i, int j) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171959 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 7 ++++--- test/Index/comment-c-decls.c | 4 ++-- test/Index/format-comment-cdecls.c | 4 ++-- unittests/Format/FormatTest.cpp | 5 +++++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index e8c6210fae..16e8c2d6c5 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -846,8 +846,9 @@ private: if (Current.Type == TT_Unknown) { if (Current.is(tok::star) || Current.is(tok::amp)) { Current.Type = determineStarAmpUsage(Current, IsRHS); - } else if (Current.is(tok::minus) || Current.is(tok::plus)) { - Current.Type = determinePlusMinusUsage(Current); + } else if (Current.is(tok::minus) || Current.is(tok::plus) || + Current.is(tok::caret)) { + Current.Type = determinePlusMinusCaretUsage(Current); } else if (Current.is(tok::minusminus) || Current.is(tok::plusplus)) { Current.Type = determineIncrementUsage(Current); } else if (Current.is(tok::exclaim)) { @@ -905,7 +906,7 @@ private: return TT_PointerOrReference; } - TokenType determinePlusMinusUsage(const AnnotatedToken &Tok) { + TokenType determinePlusMinusCaretUsage(const AnnotatedToken &Tok) { // At the start of the line, +/- specific ObjectiveC method declarations. if (Tok.Parent == NULL) return TT_ObjCMethodSpecifier; diff --git a/test/Index/comment-c-decls.c b/test/Index/comment-c-decls.c index be45ee205f..f6d3feec81 100644 --- a/test/Index/comment-c-decls.c +++ b/test/Index/comment-c-decls.c @@ -95,10 +95,10 @@ enum e { *\brief block declaration */ int (^Block) (int i, int j); -// CHECK: int ( ^ Block) (int, int) +// CHECK: int (^Block) (int, int) /** *\brief block declaration */ int (^Block1) (int i, int j) = ^(int i, int j) { return i + j; }; -// CHECK: int ( ^ Block1) (int, int) = ^ (int i, int j) {\n} +// CHECK: int (^Block1) (int, int) = ^(int i, int j) {\n} diff --git a/test/Index/format-comment-cdecls.c b/test/Index/format-comment-cdecls.c index b1539fe1cc..31ec95b921 100644 --- a/test/Index/format-comment-cdecls.c +++ b/test/Index/format-comment-cdecls.c @@ -90,10 +90,10 @@ enum e { *\brief block declaration */ int (^Block) (int i, int j); -// CHECK: int ( ^ Block) (int, int) +// CHECK: int (^Block) (int, int) /** *\brief block declaration */ int (^Block1) (int i, int j) = ^(int i, int j) { return i + j; }; -// CHECK: int ( ^ Block1) (int, int) = ^ (int i, int j) {\n} +// CHECK: int (^Block1) (int, int) = ^(int i, int j) {\n} diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9bf3097a5c..2e6424dd00 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1122,6 +1122,11 @@ TEST_F(FormatTest, FormatForObjectiveCMethodDecls) { "outRange8:(NSRange) out_range8 outRange9:(NSRange) out_range9;")); } +TEST_F(FormatTest, FormatObjCBlocks) { + verifyFormat("int (^Block) (int, int);"); + verifyFormat("int (^Block1) (int, int) = ^(int i, int j)"); +} + TEST_F(FormatTest, ObjCAt) { verifyFormat("@autoreleasepool"); verifyFormat("@catch"); -- 2.40.0