[PATCH] D145262: [clang-format] Treat AttributeMacros more like attribute macros

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 23 23:10:36 PDT 2023


owenpan added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:4380
+    // Apply this logic for parens that are not function attribute macros.
+    if ((Left.is(tok::r_paren) && !Left.is(TT_AttributeParen)) &&
+        canBeObjCSelectorComponent(Right)) {
----------------



================
Comment at: clang/unittests/Format/FormatTestObjC.cpp:1682-1693
+  verifyFormat("@property(weak) id delegate ATTRIBUTE_MACRO(X)\n"
+               "ATTRIBUTE_MACRO;");
+  verifyFormat("@property(weak) id delegate ATTRIBUTE_MACRO\n"
+               "ATTRIBUTE_MACRO(X);");
+  verifyFormat("@property(weak) id delegate __attribute__((X))\n"
+               "ATTRIBUTE_MACRO;");
+  verifyFormat("@property(weak) id delegate ATTRIBUTE_MACRO\n"
----------------



================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:1307-1313
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("A(X) void Foo(void);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  EXPECT_TOKEN(Tokens[0], tok::identifier, TT_Unknown);
+  EXPECT_TOKEN(Tokens[1], tok::l_paren, TT_Unknown);
+  // 'TT_FunctionAnnotationRParen' doesn't seem right; fix?
+  EXPECT_TOKEN(Tokens[3], tok::r_paren, TT_FunctionAnnotationRParen);
----------------
I would delete it.


================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:1335-1342
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("A(X) @interface Foo");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  // Note: Don't check token-type as a random token in this position is hard to
+  // reason about.
+  EXPECT_TOKEN_KIND(Tokens[0], tok::identifier);
+  EXPECT_TOKEN_KIND(Tokens[1], tok::l_paren);
----------------
Ditto.


================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:1364-1371
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("- (id)init A(X);");
+  ASSERT_EQ(Tokens.size(), 11u) << Tokens;
+  // Note: Don't check token-type as a random token in this position is hard to
+  // reason about.
+  EXPECT_TOKEN_KIND(Tokens[5], tok::identifier);
+  EXPECT_TOKEN_KIND(Tokens[6], tok::l_paren);
----------------
Ditto.


================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:1393-1400
+  // Generic macro has no special handling in this location.
+  Tokens = annotate("@property(weak) id delegate A(X);");
+  ASSERT_EQ(Tokens.size(), 13u) << Tokens;
+  // Note: Don't check token-type as a random token in this position is hard to
+  // reason about.
+  EXPECT_TOKEN_KIND(Tokens[7], tok::identifier);
+  EXPECT_TOKEN_KIND(Tokens[8], tok::l_paren);
----------------
Ditto.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145262/new/

https://reviews.llvm.org/D145262



More information about the cfe-commits mailing list