This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
ObjC/ObjC++ patch: remove TODO for dotsyntax with super in categories, and add testcases
- From: "Nicola Pero" <nicola dot pero at meta-innovation dot com>
- To: "gcc-patches at gnu dot org" <gcc-patches at gnu dot org>
- 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
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 <nicola.pero@meta-innovation.com>
+ * objc-act.c (objc_maybe_build_component_ref): Removed TODO.
+
+2010-11-29 Nicola Pero <nicola.pero@meta-innovation.com>
+
* 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 <nicola.pero@meta-innovation.com>
+
+ * objc.dg/property/dotsyntax-21.m
+ * obj-c++.dg/property/dotsyntax-21.mm
+
2010-11-29 Iain Sandoe <iains@gcc.gnu.org>
Mike Stump <mrs@gcc.gnu.org>
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 <nicola.pero@meta-innovation.com>, 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 <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@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 <nicola.pero@meta-innovation.com>, 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 <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@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;
+}
+
+