[clang] a8eb2f0 - [Clang][AST] Print attributes of Obj-C interfaces

via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 11 11:49:01 PDT 2024


Author: Egor Zhdan
Date: 2024-03-11T18:47:30Z
New Revision: a8eb2f0dabacb334cbfc78eaffde9a75b1ba64a4

URL: https://github.com/llvm/llvm-project/commit/a8eb2f0dabacb334cbfc78eaffde9a75b1ba64a4
DIFF: https://github.com/llvm/llvm-project/commit/a8eb2f0dabacb334cbfc78eaffde9a75b1ba64a4.diff

LOG: [Clang][AST] Print attributes of Obj-C interfaces

When pretty printing an Objective-C interface declaration, Clang
previously didn't print any attributes that are applied to the
declaration.

Added: 
    

Modified: 
    clang/lib/AST/DeclPrinter.cpp
    clang/test/AST/ast-print-objectivec.m

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 43d221968ea3fb..b701581b2474a9 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -1517,6 +1517,11 @@ void DeclPrinter::VisitObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
     return;
   }
   bool eolnOut = false;
+  if (OID->hasAttrs()) {
+    prettyPrintAttributes(OID);
+    Out << "\n";
+  }
+
   Out << "@interface " << I;
 
   if (auto TypeParams = OID->getTypeParamListAsWritten()) {

diff  --git a/clang/test/AST/ast-print-objectivec.m b/clang/test/AST/ast-print-objectivec.m
index 05a0a5d4aa74c4..a0652f38e713fa 100644
--- a/clang/test/AST/ast-print-objectivec.m
+++ b/clang/test/AST/ast-print-objectivec.m
@@ -21,6 +21,10 @@ - (void)MethI __attribute__((availability(macosx,introduced=10.1.0,deprecated=10
 - (void)methodWithArg:(int)x andAnotherOne:(int)y { }
 @end
 
+__attribute__((availability(macosx,introduced=10.1.0,deprecated=10.2)))
+ at interface InterfaceWithAttribute
+ at end
+
 // CHECK: @protocol P
 // CHECK: - (void)MethP __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2)));
 // CHECK: @end
@@ -45,6 +49,10 @@ - (void)methodWithArg:(int)x andAnotherOne:(int)y { }
 
 // CHECK: @end
 
+// CHECK: __attribute__((availability(macos, introduced=10.1.0, deprecated=10.2)))
+// CHECK: @interface InterfaceWithAttribute
+// CHECK: @end
+
 @class C1;
 struct __attribute__((objc_bridge_related(C1,,))) S1;
 


        


More information about the cfe-commits mailing list