[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:02:02 PDT 2023
benhamilton created this revision.
benhamilton added a reviewer: MyDeveloperDay.
Herald added projects: All, clang, clang-format.
Herald added a subscriber: cfe-commits.
Herald added reviewers: rymiel, HazardyKnusperkeks, owenpan.
benhamilton requested review of this revision.
This adds to the ObjC language guesser a few more common macros used
in ObjC headers. These can help distinguish ObjC headers which
otherwise lack ObjC types from C++ headers.
Contributed by danblakemore.
Tested:
New tests included. Ran unit tests with:
```
% cmake -S llvm -B build -G Ninja && \
ninja -C build FormatTests && \
./build/tools/clang/unittests/Format/FormatTests --gtest_filter="*FormatTestObjC*"
(snip)
[----------] 24 tests from FormatTestObjC (265 ms total)
[----------] Global test environment tear-down
[==========] 26 tests from 2 test suites ran. (270 ms total)
[ PASSED ] 26 tests.
```
Repository:
rG LLVM Github Monorepo
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,20 @@
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", "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_EXPORT 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,7 @@
"CGSizeMake",
"CGVector",
"CGVectorMake",
+ "FOUNDATION_EXTERN",
"NSAffineTransform",
"NSArray",
"NSAttributedString",
@@ -2743,6 +2744,7 @@
"NSURLQueryItem",
"NSUUID",
"NSValue",
+ "NS_ASSUME_NONNULL_BEGIN",
"UIImage",
"UIView",
};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151578.526150.patch
Type: text/x-patch
Size: 1743 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230526/0e16f2d1/attachment.bin>
More information about the cfe-commits
mailing list