From patchwork Sat Oct 30 13:29:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 69655 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id B38ADB6EF0 for ; Sun, 31 Oct 2010 00:29:35 +1100 (EST) Received: (qmail 28556 invoked by alias); 30 Oct 2010 13:29:34 -0000 Received: (qmail 28547 invoked by uid 22791); 30 Oct 2010 13:29:33 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 30 Oct 2010 13:29:29 +0000 Received: from eggs.gnu.org ([140.186.70.92]:52883) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PCBUs-0000Qc-Pb for gcc-patches@gnu.org; Sat, 30 Oct 2010 09:29:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PCBUr-00008n-JC for gcc-patches@gnu.org; Sat, 30 Oct 2010 09:29:27 -0400 Received: from smtp171.iad.emailsrvr.com ([207.97.245.171]:59818) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PCBUr-00008A-Gf for gcc-patches@gnu.org; Sat, 30 Oct 2010 09:29:25 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp37.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 37D2E3B0622 for ; Sat, 30 Oct 2010 09:29:23 -0400 (EDT) Received: from dynamic5.wm-web.iad.mlsrvr.com (dynamic5.wm-web.iad1a.rsapps.net [192.168.2.146]) by smtp37.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 1CB113B05FD for ; Sat, 30 Oct 2010 09:29:23 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic5.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 0E2BF8D0A51 for ; Sat, 30 Oct 2010 09:29:23 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Sat, 30 Oct 2010 15:29:23 +0200 (CEST) Date: Sat, 30 Oct 2010 15:29:23 +0200 (CEST) Subject: ObjC/ObjC++ - support for deprecating properties From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1288445363.055511990@192.168.4.58> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch makes "__attribute__ ((deprecated))" work for Objective-C/Objective-C++ properties. Testcases included. Ok to commit to trunk ? Thanks 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 + * 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 + 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 + * objc.dg/property/at-property-deprecated-1.m: New. + * obj-c++.dg/property/at-property-deprecated-1.mm: New. + +2010-10-30 Nicola Pero + 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 , October 2010. */ +/* { dg-do compile } */ + +/* Test that properties can be deprecated. */ + +#include +#include +#include + +@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); +}