summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-01-30 14:38:37 +0000
committerDaniel Jasper <djasper@google.com>2014-01-30 14:38:37 +0000
commita88f80a1bee417216b13cf133f56826150df9ef5 (patch)
treecc12cc17f748aed1b24a0483050ae58782bf3178
parent3f6af151df0b971bb0f0f2b20e15dc7cee11ac72 (diff)
downloadbcm5719-llvm-a88f80a1bee417216b13cf133f56826150df9ef5.tar.gz
bcm5719-llvm-a88f80a1bee417216b13cf133f56826150df9ef5.zip
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 }; llvm-svn: 200469
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp11
-rw-r--r--clang/unittests/Format/FormatTest.cpp12
2 files changed, 22 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index b56140e763d..ef55b681940 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 9b0a11c3bc2..93e3f7a5936 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/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"
OpenPOWER on IntegriCloud