[clang-format] Improve ObjC headers detection
Summary: Detect ObjC characteristic types when they start a line and add additional keywords.
Reviewers: benhamilton
Reviewed By: benhamilton
Subscribers: klimek, cfe-commits
Differential Revision: https://reviews.llvm.org/D43124
llvm-svn: 325221
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index ff437f1..af03696 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1440,7 +1440,9 @@
"NSAffineTransform",
"NSArray",
"NSAttributedString",
+ "NSBundle",
"NSCache",
+ "NSCalendar",
"NSCharacterSet",
"NSCountedSet",
"NSData",
@@ -1466,6 +1468,7 @@
"NSMutableString",
"NSNumber",
"NSNumberFormatter",
+ "NSObject",
"NSOrderedSet",
"NSPoint",
"NSPointerArray",
@@ -1475,17 +1478,19 @@
"NSSet",
"NSSize",
"NSString",
+ "NSTimeZone",
"NSUInteger",
"NSURL",
"NSURLComponents",
"NSURLQueryItem",
"NSUUID",
+ "NSValue",
};
for (auto &Line : AnnotatedLines) {
- for (FormatToken *FormatTok = Line->First->Next; FormatTok;
+ for (FormatToken *FormatTok = Line->First; FormatTok;
FormatTok = FormatTok->Next) {
- if ((FormatTok->Previous->is(tok::at) &&
+ if ((FormatTok->Previous && FormatTok->Previous->is(tok::at) &&
(FormatTok->isObjCAtKeyword(tok::objc_interface) ||
FormatTok->isObjCAtKeyword(tok::objc_implementation) ||
FormatTok->isObjCAtKeyword(tok::objc_protocol) ||