[PATCH] D56924: Handle ObjCCategoryDecl class extensions for print

David Goldman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 22 13:05:40 PST 2019


dgoldman updated this revision to Diff 182971.
dgoldman added a comment.
Herald added a subscriber: jfb.

- Add test


Repository:
  rC Clang

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

https://reviews.llvm.org/D56924

Files:
  lib/AST/Decl.cpp
  unittests/AST/NamedDeclPrinterTest.cpp


Index: unittests/AST/NamedDeclPrinterTest.cpp
===================================================================
--- unittests/AST/NamedDeclPrinterTest.cpp
+++ unittests/AST/NamedDeclPrinterTest.cpp
@@ -115,6 +115,18 @@
                                  "input.cc");
 }
 
+::testing::AssertionResult
+PrintedWrittenPropertyDeclObjCMatches(StringRef Code, StringRef DeclName,
+                                   StringRef ExpectedPrinted) {
+  std::vector<std::string> Args{"-std=c++11", "-xobjective-c++"};
+  return PrintedNamedDeclMatches(Code,
+                                 Args,
+                                 /*SuppressUnwrittenScope*/ true,
+                                 objcPropertyDecl(hasName(DeclName)).bind("id"),
+                                 ExpectedPrinted,
+                                 "input.m");
+}
+
 } // unnamed namespace
 
 TEST(NamedDeclPrinter, TestNamespace1) {
@@ -179,3 +191,17 @@
     "A",
     "X::A"));
 }
+
+TEST(NamedDeclPrinter, TestObjCClassExtension) {
+  ASSERT_TRUE(PrintedWrittenPropertyDeclObjCMatches(
+    R"(
+      @interface Obj
+      @end
+
+      @interface Obj ()
+      @property(nonatomic) int property;
+      @end
+    )",
+    "property",
+    "(class extension)::property"));
+}
Index: lib/AST/Decl.cpp
===================================================================
--- lib/AST/Decl.cpp
+++ lib/AST/Decl.cpp
@@ -1604,6 +1604,11 @@
         OS << *ED;
       else
         continue;
+    } else if (const auto *CD = dyn_cast<ObjCCategoryDecl>(DC)) {
+      if (CD->IsClassExtension())
+         OS << "(class extension)";
+      else
+        OS << *CD;
     } else {
       OS << *cast<NamedDecl>(DC);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56924.182971.patch
Type: text/x-patch
Size: 1688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190122/a2163849/attachment.bin>


More information about the cfe-commits mailing list