diff mbox

ObjC/ObjC++ - support for deprecating properties

Message ID 1288445363.055511990@192.168.4.58
State New
Headers show

Commit Message

Nicola Pero Oct. 30, 2010, 1:29 p.m. UTC
This patch makes "__attribute__ ((deprecated))" work for Objective-C/Objective-C++ properties.
Testcases included.

Ok to commit to trunk ?

Thanks

Comments

Mike Stump Nov. 1, 2010, 4:06 p.m. UTC | #1
On Oct 30, 2010, at 6:29 AM, Nicola Pero wrote:
> This patch makes "__attribute__ ((deprecated))" work for Objective-C/Objective-C++ properties.

> Ok to commit to trunk ?

Ok.
diff mbox

Patch

Index: objc/objc-act.c
===================================================================
--- objc/objc-act.c     (revision 166087)
+++ objc/objc-act.c     (working copy)
@@ -1121,6 +1121,9 @@  objc_maybe_build_component_ref (tree object, tree
     {
       tree expression;
 
+      if (TREE_DEPRECATED (x))
+       warn_deprecated_use (x, NULL_TREE);
+
       expression = build2 (PROPERTY_REF, TREE_TYPE(x), object, x);
       SET_EXPR_LOCATION (expression, input_location);
       TREE_SIDE_EFFECTS (expression) = 1;
@@ -10873,6 +10876,13 @@  objc_maybe_printable_name (tree decl, int v ATTRIB
     case CLASS_METHOD_DECL:
       return IDENTIFIER_POINTER (DECL_NAME (decl));
       break;
+      /* This happens when printing a deprecation warning for a
+        property.  We may want to consider some sort of pretty
+        printing (eg, include the class name where it was declared
+        ?).  */
+    case PROPERTY_DECL:
+      return IDENTIFIER_POINTER (PROPERTY_NAME (decl));
+      break;
     default:
       return NULL;
       break;
Index: objc/ChangeLog
===================================================================
--- objc/ChangeLog      (revision 166087)
+++ objc/ChangeLog      (working copy)
@@ -1,5 +1,11 @@ 
 2010-10-30  Nicola Pero  <nicola.pero@meta-innovation.com>
 
+       * objc-act.c (objc_maybe_build_component_ref): Warn about using
+       deprecated properties.
+       (objc_maybe_printable_name): Support PROPERTY_DECL.
+       
+2010-10-30  Nicola Pero  <nicola.pero@meta-innovation.com>
+
        Implemented Objective-C 2.0 @property, @synthesize and @dynamic.
        * objc-tree.def (PROPERTY_REF): New.
        * objc-act.h: Added comments for all the PROPERTY_ macros.
Index: testsuite/ChangeLog
===================================================================
--- testsuite/ChangeLog (revision 166087)
+++ testsuite/ChangeLog (working copy)
@@ -1,5 +1,10 @@ 
 2010-10-30  Nicola Pero  <nicola.pero@meta-innovation.com>
 
+       * objc.dg/property/at-property-deprecated-1.m: New.
+       * obj-c++.dg/property/at-property-deprecated-1.mm: New. 
+
+2010-10-30  Nicola Pero  <nicola.pero@meta-innovation.com>
+
        Implemented Objective-C 2.0 @property, @synthesize and @dynamic.
        * objc.dg/property/property-neg-1.m: Updated for changes in the
        syntax of @property and the implementation of
Index: testsuite/objc.dg/property/at-property-deprecated-1.m
===================================================================
--- testsuite/objc.dg/property/at-property-deprecated-1.m       (revision 0)
+++ testsuite/objc.dg/property/at-property-deprecated-1.m       (revision 0)
@@ -0,0 +1,37 @@ 
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010.  */
+/* { dg-do compile } */
+
+/* Test that properties can be deprecated.  */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+  Class isa;
+  int a;
+}
+@property int a __attribute__((deprecated));
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+@synthesize a;
+@end
+
+int main (void)
+{
+  MyRootClass *object = [[MyRootClass alloc] init];
+
+  object.a = 40;      /* { dg-warning ".a. is deprecated .declared at " } */
+  if (object.a != 40) /* { dg-warning ".a. is deprecated .declared at " } */
+    abort ();
+
+  return (0);
+}