From patchwork Mon Nov 29 18:41:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 73477 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 3C067B70AA for ; Tue, 30 Nov 2010 05:42:17 +1100 (EST) Received: (qmail 13981 invoked by alias); 29 Nov 2010 18:42:15 -0000 Received: (qmail 13959 invoked by uid 22791); 29 Nov 2010 18:42:14 -0000 X-SWARE-Spam-Status: No, hits=-1.4 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; Mon, 29 Nov 2010 18:42:07 +0000 Received: from eggs.gnu.org ([140.186.70.92]:38283) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PN8fr-0003F0-Gv for gcc-patches@gnu.org; Mon, 29 Nov 2010 13:42:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PN8fs-0006bs-A8 for gcc-patches@gnu.org; Mon, 29 Nov 2010 13:42:05 -0500 Received: from smtp131.iad.emailsrvr.com ([207.97.245.131]:37739) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PN8fs-0006bg-3P for gcc-patches@gnu.org; Mon, 29 Nov 2010 13:42:04 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp43.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id C20142D0306 for ; Mon, 29 Nov 2010 13:42:03 -0500 (EST) Received: from dynamic4.wm-web.iad.mlsrvr.com (dynamic4.wm-web.iad1a.rsapps.net [192.168.2.153]) by smtp43.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 88BC82D0685 for ; Mon, 29 Nov 2010 13:41:57 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic4.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 727071D4A270 for ; Mon, 29 Nov 2010 13:41:57 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Mon, 29 Nov 2010 19:41:57 +0100 (CET) Date: Mon, 29 Nov 2010 19:41:57 +0100 (CET) Subject: ObjC/ObjC++ patch: remove TODO for dotsyntax with super in categories, and add testcases From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1291056117.461620987@192.168.2.228> 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 removes a TODO comment in objc-act.c about dotsyntax with super in categories. It turns out the existing code works fine; testcases are included with this patch. Ok to commit ? Thanks Index: objc/objc-act.c =================================================================== --- objc/objc-act.c (revision 167242) +++ objc/objc-act.c (working copy) @@ -1539,11 +1539,8 @@ objc_maybe_build_component_ref (tree object, tree || TREE_CODE (t) == COMPONENT_REF) t = TREE_OPERAND (t, 0); - if (t == UOBJC_SUPER_decl) - { - /* TODO: Check if this is correct also for 'super' in categories. */ - interface_type = lookup_interface (CLASS_SUPER_NAME (implementation_template)); - } + if (t == UOBJC_SUPER_decl) + interface_type = lookup_interface (CLASS_SUPER_NAME (implementation_template)); else if (t == self_decl) interface_type = lookup_interface (CLASS_NAME (implementation_template)); Index: objc/ChangeLog =================================================================== --- objc/ChangeLog (revision 167242) +++ objc/ChangeLog (working copy) @@ -1,5 +1,9 @@ 2010-11-29 Nicola Pero + * objc-act.c (objc_maybe_build_component_ref): Removed TODO. + +2010-11-29 Nicola Pero + * objc-act.c (objc_eh_runtime_type): Avoid ICE if error_mark_node is passed as argument. (objc_begin_catch_clause): Added code to deal with an Index: testsuite/ChangeLog =================================================================== --- testsuite/ChangeLog (revision 167242) +++ testsuite/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-11-29 Nicola Pero + + * objc.dg/property/dotsyntax-21.m + * obj-c++.dg/property/dotsyntax-21.mm + 2010-11-29 Iain Sandoe Mike Stump Index: testsuite/objc.dg/property/dotsyntax-21.m =================================================================== --- testsuite/objc.dg/property/dotsyntax-21.m (revision 0) +++ testsuite/objc.dg/property/dotsyntax-21.m (revision 0) @@ -0,0 +1,115 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do run } */ +/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ + +/* Test dot-syntax with super in a category. */ + +#include +#include +#include + +@interface MyRootClass +{ + Class isa; + int a; +} ++ (id) initialize; ++ (id) alloc; +- (id) init; +- (int) count; +- (void) setCount: (int)count; +@end + +@implementation MyRootClass ++ (id) initialize { return self; } ++ (id) alloc { return class_createInstance (self, 0); } +- (id) init { return self; } +- (int) count +{ + return a; +} +- (void) setCount: (int)count +{ + a = count; +} +@end + +/* First, test 'super' in the main implementation of a subclass. */ +@interface MySubClass : MyRootClass +- (int) superCount; +- (void) setSuperCount: (int)count; +@end + +@implementation MySubClass +- (int) superCount +{ + return super.count; +} +- (void) setSuperCount: (int)count +{ + super.count = count; +} +@end + +/* Now, test 'super' in a category of a subclass. */ +@interface MySubClass (Category) +- (int) superCount2; +- (void) setSuperCount2: (int)count; +- (int) test: (int)x; +@end + +@implementation MySubClass (Category) +- (int) superCount2 +{ + return super.count; +} +- (void) setSuperCount2: (int)count +{ + super.count = count; +} +- (int) test: (int)x +{ + /* For positive x, the following will leave super.count + unchanged. */ + super.count++; + --super.count; + + super.count = (x < 0 ? x : super.count); + + if ((x = super.count)) + super.count += 1; + + if ((x = super.count)) + super.count -= 1; + + /* Finally, also put a bit of self.count in the mix. */ + self.count++; + super.count--; + + return super.count; +} +@end + +int main (void) +{ + MySubClass *object = [[MySubClass alloc] init]; + + object.count = 10; + if (object.count != 10) + abort (); + + object.superCount = 11; + if (object.superCount != 11) + abort (); + + object.superCount2 = 12; + if (object.superCount2 != 12) + abort (); + + if ([object test: 45] != 12) + abort (); + + return 0; +} + + Index: testsuite/obj-c++.dg/property/dotsyntax-21.mm =================================================================== --- testsuite/obj-c++.dg/property/dotsyntax-21.mm (revision 0) +++ testsuite/obj-c++.dg/property/dotsyntax-21.mm (revision 0) @@ -0,0 +1,115 @@ +/* Contributed by Nicola Pero , November 2010. */ +/* { dg-do run } */ +/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ + +/* Test dot-syntax with super in a category. */ + +#include +#include +#include + +@interface MyRootClass +{ + Class isa; + int a; +} ++ (id) initialize; ++ (id) alloc; +- (id) init; +- (int) count; +- (void) setCount: (int)count; +@end + +@implementation MyRootClass ++ (id) initialize { return self; } ++ (id) alloc { return class_createInstance (self, 0); } +- (id) init { return self; } +- (int) count +{ + return a; +} +- (void) setCount: (int)count +{ + a = count; +} +@end + +/* First, test 'super' in the main implementation of a subclass. */ +@interface MySubClass : MyRootClass +- (int) superCount; +- (void) setSuperCount: (int)count; +@end + +@implementation MySubClass +- (int) superCount +{ + return super.count; +} +- (void) setSuperCount: (int)count +{ + super.count = count; +} +@end + +/* Now, test 'super' in a category of a subclass. */ +@interface MySubClass (Category) +- (int) superCount2; +- (void) setSuperCount2: (int)count; +- (int) test: (int)x; +@end + +@implementation MySubClass (Category) +- (int) superCount2 +{ + return super.count; +} +- (void) setSuperCount2: (int)count +{ + super.count = count; +} +- (int) test: (int)x +{ + /* For positive x, the following will leave super.count + unchanged. */ + super.count++; + --super.count; + + super.count = (x < 0 ? x : super.count); + + if ((x = super.count)) + super.count += 1; + + if ((x = super.count)) + super.count -= 1; + + /* Finally, also put a bit of self.count in the mix. */ + self.count++; + super.count--; + + return super.count; +} +@end + +int main (void) +{ + MySubClass *object = [[MySubClass alloc] init]; + + object.count = 10; + if (object.count != 10) + abort (); + + object.superCount = 11; + if (object.superCount != 11) + abort (); + + object.superCount2 = 12; + if (object.superCount2 != 12) + abort (); + + if ([object test: 45] != 12) + abort (); + + return 0; +} + +