[PATCH] D151578: [Format/ObjC] Support NS_ASSUME_NONNULL_BEGIN and FOUNDATION_EXPORT in ObjC language guesser
Ben Hamilton via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 26 12:06:39 PDT 2023
benhamilton updated this revision to Diff 526154.
benhamilton added a comment.
Add `FOUNDATION_EXTERN` alias for `FOUNDATION_EXPORT` (Apple `#define`s the former to the latter).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151578/new/
https://reviews.llvm.org/D151578
Files:
clang/lib/Format/Format.cpp
clang/test/Format/dump-config-objc-macros.h
clang/unittests/Format/FormatTestObjC.cpp
Index: clang/unittests/Format/FormatTestObjC.cpp
===================================================================
--- clang/unittests/Format/FormatTestObjC.cpp
+++ clang/unittests/Format/FormatTestObjC.cpp
@@ -94,6 +94,26 @@
ASSERT_TRUE((bool)Style);
EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+ Style = getStyle("{}", "a.h", "none", R"objc(
+NS_ASSUME_NONNULL_BEGIN
+extern int i;
+NS_ASSUME_NONNULL_END
+)objc");
+ ASSERT_TRUE((bool)Style);
+ EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+ Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXTERN void DoStuff(void);
+)objc");
+ ASSERT_TRUE((bool)Style);
+ EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
+ Style = getStyle("{}", "a.h", "none", R"objc(
+FOUNDATION_EXPORT void DoStuff(void);
+)objc");
+ ASSERT_TRUE((bool)Style);
+ EXPECT_EQ(FormatStyle::LK_ObjC, Style->Language);
+
Style = getStyle("{}", "a.h", "none", "enum Foo {};");
ASSERT_TRUE((bool)Style);
EXPECT_EQ(FormatStyle::LK_Cpp, Style->Language);
Index: clang/test/Format/dump-config-objc-macros.h
===================================================================
--- /dev/null
+++ clang/test/Format/dump-config-objc-macros.h
@@ -0,0 +1,8 @@
+// RUN: clang-format -dump-config %s | FileCheck %s
+
+// CHECK: Language: ObjC
+NS_ASSUME_NONNULL_BEGIN
+
+FOUNDATION_EXTERN int kConstant;
+
+NS_ASSUME_NONNULL_END
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2687,6 +2687,8 @@
"CGSizeMake",
"CGVector",
"CGVectorMake",
+ "FOUNDATION_EXPORT", // This is an alias for FOUNDATION_EXTERN.
+ "FOUNDATION_EXTERN",
"NSAffineTransform",
"NSArray",
"NSAttributedString",
@@ -2743,6 +2745,7 @@
"NSURLQueryItem",
"NSUUID",
"NSValue",
+ "NS_ASSUME_NONNULL_BEGIN",
"UIImage",
"UIView",
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151578.526154.patch
Type: text/x-patch
Size: 1998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230526/bf0222de/attachment-0001.bin>
More information about the cfe-commits
mailing list