diff options
author | Nicola Pero <nicola.pero@meta-innovation.com> | 2010-11-01 20:06:36 +0000 |
---|---|---|
committer | Nicola Pero <nicola@gcc.gnu.org> | 2010-11-01 20:06:36 +0000 |
commit | 8f07a2aa357fd67ca7ef1e640424bc605c6cec31 (patch) | |
tree | 53252370c4f738209d137b61fe83ed7b6b403a21 /gcc/testsuite/objc.dg/property | |
parent | 1fccc6c3464c8862297bdf74d7bf22ac245e4639 (diff) | |
download | gcc-8f07a2aa357fd67ca7ef1e640424bc605c6cec31.zip gcc-8f07a2aa357fd67ca7ef1e640424bc605c6cec31.tar.gz gcc-8f07a2aa357fd67ca7ef1e640424bc605c6cec31.tar.bz2 |
In gcc/objc/: 2010-11-01 Nicola Pero <nicola.pero@meta-innovation.com>
In gcc/objc/:
2010-11-01 Nicola Pero <nicola.pero@meta-innovation.com>
Implemented Objective-C 2.0 property accessors.
* objc-act.h (enum objc_tree_index): Added OCTI_GET_PROPERTY_DECL,
OCTI_SET_PROPERTY_DECL, OCTI_COPY_STRUCT_DECL,
OCTI_GET_PROPERTY_STRUCT_DECL and OCTI_SET_PROPERTY_STRUCT_DECL.
(objc_getProperty_decl): New.
(objc_setProperty_decl): New.
(objc_copyStruct_decl): New.
(objc_getPropertyStruct_decl): New.
(objc_setPropertyStruct_decl): New.
* objc-act.c (build_objc_property_accessor_helpers): New.
(synth_module_prologue): Call
build_objc_property_accessor_helpers.
(lookup_ivar): New.
(objc_synthesize_getter): Implemented synthesizing getters that
work with properties that are not nonatomic, assign properties.
(objc_synthesize_setter): Implemented synthesizing setters that
work with properties that are not nonatomic, assign properties.
In gcc/testsuite/:
2010-11-01 Nicola Pero <nicola.pero@meta-innovation.com>
Implemented Objective-C 2.0 property accessors.
* objc.dg/property/at-property-6.m: Use nonatomic properties to
avoid testing more complex accessors in this testcase which is not
about them.
* objc.dg/property/at-property-7.m: Same change.
* objc.dg/property/at-property-8.m: Same change.
* objc.dg/property/at-property-9.m: Same change.
* objc.dg/property/at-property-10.m: Same change.
* objc.dg/property/at-property-11.m: Same change.
* obj-c++.dg/property/at-property-6.mm: Same change.
* obj-c++.dg/property/at-property-7.mm: Same change.
* obj-c++.dg/property/at-property-8.mm: Same change.
* obj-c++.dg/property/at-property-9.mm: Same change.
* obj-c++.dg/property/at-property-10.mm: Same change.
* obj-c++.dg/property/at-property-11.mm: Same change.
* objc.dg/property/at-property-12.m: New.
* objc.dg/property/at-property-13.m: New.
* obj-c++.dg/property/at-property-12.mm: New.
* obj-c++.dg/property/at-property-13.mm: New.
From-SVN: r166143
Diffstat (limited to 'gcc/testsuite/objc.dg/property')
-rw-r--r-- | gcc/testsuite/objc.dg/property/at-property-10.m | 5 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/at-property-11.m | 5 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/at-property-12.m | 46 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/at-property-13.m | 71 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/at-property-6.m | 2 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/at-property-7.m | 2 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/at-property-8.m | 2 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/at-property-9.m | 5 |
8 files changed, 132 insertions, 6 deletions
diff --git a/gcc/testsuite/objc.dg/property/at-property-10.m b/gcc/testsuite/objc.dg/property/at-property-10.m index bc6380c..1a7a043 100644 --- a/gcc/testsuite/objc.dg/property/at-property-10.m +++ b/gcc/testsuite/objc.dg/property/at-property-10.m @@ -12,7 +12,10 @@ Class isa; int a; } -@property int a; +/* Use the simplest synthesized accessor (assign, nonatomic) as we are + not testing the synthesized accessors in this test, just the + property syntax. */ +@property (nonatomic) int a; + (id) initialize; + (id) alloc; - (id) init; diff --git a/gcc/testsuite/objc.dg/property/at-property-11.m b/gcc/testsuite/objc.dg/property/at-property-11.m index 84857e0..2526a9c 100644 --- a/gcc/testsuite/objc.dg/property/at-property-11.m +++ b/gcc/testsuite/objc.dg/property/at-property-11.m @@ -12,7 +12,10 @@ Class isa; int a; } -@property int a; +/* Use the simplest synthesized accessor (assign, nonatomic) as we are + not testing the synthesized accessors in this test, just the + property syntax. */ +@property (nonatomic) int a; + (id) initialize; + (id) alloc; - (id) init; diff --git a/gcc/testsuite/objc.dg/property/at-property-12.m b/gcc/testsuite/objc.dg/property/at-property-12.m new file mode 100644 index 0000000..e96b198 --- /dev/null +++ b/gcc/testsuite/objc.dg/property/at-property-12.m @@ -0,0 +1,46 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */ +/* { dg-do run } */ + +/* Test atomic, assign synthesized methods. */ + +#include <stdlib.h> +#include <objc/objc.h> +#include <objc/runtime.h> + +@interface MyRootClass +{ + Class isa; + int a; + id b; +} +@property int a; +@property (assign) id b; ++ (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; +@synthesize b; +@end + +int main (void) +{ + MyRootClass *object = [[MyRootClass alloc] init]; + + object.a = 40; + if (object.a != 40) + abort (); + + object.b = object; + if (object.b != object) + abort (); + + return 0; +} + + diff --git a/gcc/testsuite/objc.dg/property/at-property-13.m b/gcc/testsuite/objc.dg/property/at-property-13.m new file mode 100644 index 0000000..dfdb02f --- /dev/null +++ b/gcc/testsuite/objc.dg/property/at-property-13.m @@ -0,0 +1,71 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */ +/* { dg-do run } */ + +/* Test retain and copy synthesized methods. */ + +#include <stdlib.h> +#include <objc/objc.h> +#include <objc/runtime.h> + +@interface MyRootClass +{ + Class isa; + int copy_count; + id a; + id b; +} +@property (copy) id a; +@property (retain) id b; ++ (id) initialize; ++ (id) alloc; +- (id) init; +- (id) copyWithZone: (void *)zone; +- (int) copyCount; +- (id) autorelease; +- (oneway void) release; +- (id) retain; +@end + +/* This class implements copyWithZone, which doesn't do anything other + than increasing a counter of how many copies were made. */ +@implementation MyRootClass ++ (id) initialize { return self; } ++ (id) alloc { return class_createInstance (self, 0); } +- (id) init { return self; } +- (id) copyWithZone: (void *)zone { copy_count++; return self; } +- (int) copyCount { return copy_count; } +- (id) autorelease { return self; } +- (oneway void) release { return; } +- (id) retain { return self; } +@synthesize a; +@synthesize b; +@end + +int main (void) +{ + MyRootClass *object = [[MyRootClass alloc] init]; + MyRootClass *argument = [[MyRootClass alloc] init]; + + /* This should copy argument. */ + object.a = argument; + if (object.a != argument) + abort (); + + /* Test that it was copied. */ + if ([object.a copyCount] != 1) + abort (); + + /* We just test that the retain accessors seem to work and that they + don't copy. We don't test that retain was actually called, + because if garbage collection is enabled, it may never be + called! */ + object.b = argument; + if (object.b != argument) + abort (); + + /* Test that it was not copied. */ + if ([object.b copyCount] != 1) + abort (); + + return 0; +} diff --git a/gcc/testsuite/objc.dg/property/at-property-6.m b/gcc/testsuite/objc.dg/property/at-property-6.m index a97c0b0..079995c 100644 --- a/gcc/testsuite/objc.dg/property/at-property-6.m +++ b/gcc/testsuite/objc.dg/property/at-property-6.m @@ -13,7 +13,7 @@ Class isa; int a; } -@property int a; +@property (nonatomic) int a; + (id) initialize; + (id) alloc; - (id) init; diff --git a/gcc/testsuite/objc.dg/property/at-property-7.m b/gcc/testsuite/objc.dg/property/at-property-7.m index dce2764..6f182d0 100644 --- a/gcc/testsuite/objc.dg/property/at-property-7.m +++ b/gcc/testsuite/objc.dg/property/at-property-7.m @@ -13,7 +13,7 @@ Class isa; int a; } -@property (getter = getA) int a; +@property (getter = getA, nonatomic) int a; + (id) initialize; + (id) alloc; - (id) init; diff --git a/gcc/testsuite/objc.dg/property/at-property-8.m b/gcc/testsuite/objc.dg/property/at-property-8.m index eb15889..94ed86e 100644 --- a/gcc/testsuite/objc.dg/property/at-property-8.m +++ b/gcc/testsuite/objc.dg/property/at-property-8.m @@ -13,7 +13,7 @@ Class isa; int a; } -@property (setter = writeA:) int a; +@property (setter = writeA:, nonatomic) int a; + (id) initialize; + (id) alloc; - (id) init; diff --git a/gcc/testsuite/objc.dg/property/at-property-9.m b/gcc/testsuite/objc.dg/property/at-property-9.m index 203eb30..6e2d118 100644 --- a/gcc/testsuite/objc.dg/property/at-property-9.m +++ b/gcc/testsuite/objc.dg/property/at-property-9.m @@ -13,7 +13,10 @@ Class isa; int a; } -@property (getter = giveMeA, setter = writeA:) int a; +/* Use the simplest synthesized accessor (assign, nonatomic) as we are + not testing the synthesized accessors in this test, just the + property syntax. */ +@property (getter = giveMeA, setter = writeA:, nonatomic) int a; + (id) initialize; + (id) alloc; - (id) init; |