[PATCH] D37192: [clang-format] Add support for generic Obj-C categories
Daniel MartÃn via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 27 05:18:35 PDT 2017
danielmartin created this revision.
Herald added a subscriber: klimek.
Objective C supports lightweight generics in categories. This patch
adds support for that in clang-format.
https://reviews.llvm.org/D37192
Files:
lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestObjC.cpp
Index: unittests/Format/FormatTestObjC.cpp
===================================================================
--- unittests/Format/FormatTestObjC.cpp
+++ unittests/Format/FormatTestObjC.cpp
@@ -821,6 +821,13 @@
" NSBundle.mainBundle.infoDictionary[@\"a\"]\n"
"]];");
}
+
+TEST_F(FormatTestObjC, FormatGenericObjCCategory) {
+ verifyFormat(
+ "@interface NSHashTable <ObjectType>(MYFoundation)\n"
+ "- (void)xyz_addObjectsFromArray:(nonnull NSArray<ObjectType> *)array;\n"
+ "@end");
+}
} // end namespace
} // end namespace format
} // end namespace clang
Index: lib/Format/UnwrappedLineParser.cpp
===================================================================
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -2096,6 +2096,11 @@
if (FormatTok->Tok.is(tok::less))
parseObjCProtocolList();
+ // After a protocol list, we can have a category (Obj-C generic
+ // category).
+ if (FormatTok->Tok.is(tok::l_paren))
+ parseParens();
+
if (FormatTok->Tok.is(tok::l_brace)) {
if (Style.BraceWrapping.AfterObjCDeclaration)
addUnwrappedLine();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37192.112819.patch
Type: text/x-patch
Size: 1156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170827/50b5f4fd/attachment.bin>
More information about the cfe-commits
mailing list