From 77730d1141cf83f677b3c4d5e94db33291602b21 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Thu, 30 Jan 2014 14:38:37 +0000 Subject: [PATCH] clang-format: Support ObjC's NS_ENUMs. Before: typedef NS_ENUM(NSInteger, MyType) { /// Information about someDecentlyLongValue. someDecentlyLongValue, /// Information about anotherDecentlyLongValue. anotherDecentlyLongValue, /// Information about aThirdDecentlyLongValue. aThirdDecentlyLongValue}; After: typedef NS_ENUM(NSInteger, MyType) { /// Information about someDecentlyLongValue. someDecentlyLongValue, /// Information about anotherDecentlyLongValue. anotherDecentlyLongValue, /// Information about aThirdDecentlyLongValue. aThirdDecentlyLongValue }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@200469 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/UnwrappedLineParser.cpp | 11 ++++++++++- unittests/Format/FormatTest.cpp | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index b56140e763..ef55b68194 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -668,6 +668,12 @@ void UnwrappedLineParser::parseStructuralElement() { case tok::kw_enum: parseEnum(); break; + case tok::kw_typedef: + nextToken(); + // FIXME: Use the IdentifierTable instead. + if (FormatTok->TokenText == "NS_ENUM") + parseEnum(); + break; case tok::kw_struct: case tok::kw_union: case tok::kw_class: @@ -1129,7 +1135,10 @@ void UnwrappedLineParser::parseAccessSpecifier() { } void UnwrappedLineParser::parseEnum() { - nextToken(); + if (FormatTok->Tok.is(tok::kw_enum)) { + // Won't be 'enum' for NS_ENUMs. + nextToken(); + } // Eat up enum class ... if (FormatTok->Tok.is(tok::kw_class) || FormatTok->Tok.is(tok::kw_struct)) diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9b0a11c3bc..93e3f7a593 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1713,6 +1713,18 @@ TEST_F(FormatTest, FormatsEnumTypes) { verifyFormat("enum X : std::uint32_t { A, B };"); } +TEST_F(FormatTest, FormatsNSEnums) { + verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }"); + verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n" + " // Information about someDecentlyLongValue.\n" + " someDecentlyLongValue,\n" + " // Information about anotherDecentlyLongValue.\n" + " anotherDecentlyLongValue,\n" + " // Information about aThirdDecentlyLongValue.\n" + " aThirdDecentlyLongValue\n" + "};"); +} + TEST_F(FormatTest, FormatsBitfields) { verifyFormat("struct Bitfields {\n" " unsigned sClass : 8;\n" -- 2.40.0