diff options
author | nicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-08 22:38:04 +0000 |
---|---|---|
committer | nicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-11-08 22:38:04 +0000 |
commit | 99da7d7e3f62fe5205a735f2998dafbcd83bec21 (patch) | |
tree | 6d9394924935e5c8e58b7b3ad2e852031f2886e7 /gcc/testsuite/objc.dg/property | |
parent | c84ce30ab797252d51a4e5366be0d8cc6ade7057 (diff) | |
download | gcc-99da7d7e3f62fe5205a735f2998dafbcd83bec21.tar.gz |
In gcc/objc/:
2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>
* objc-act.c (objc_add_dynamic_declaration_for_property): Do not
search for the @property declation only in the current context,
but also in inherited properties. Do not mark the original
PROPERTY_DECL in the @interface or @protocol with
PROPERTY_DYNAMIC.
(check_methods): To check if a method is associated with a
@dynamic property, search for the property in IMPL_PROPERTY_DECL.
(check_accessible_methods): Same change.
* objc-act.h: Updated comment.
In gcc/testsuite/:
2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/property/dynamic-4.m: New.
* objc.dg/property/dynamic-5.m: New.
* objc.dg/property/dynamic-6.m: New.
* obj-c++.dg/property/dynamic-4.mm: New.
* obj-c++.dg/property/dynamic-5.mm: New.
* obj-c++.dg/property/dynamic-6.mm: New.
2010-11-08 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/property/dotsyntax-13.m: New.
* objc.dg/property/dotsyntax-14.m: New.
* objc.dg/property/dotsyntax-15.m: New.
* objc.dg/property/synthesize-7.m: New.
* obj-c++.dg/property/dotsyntax-13.mm: New.
* obj-c++.dg/property/dotsyntax-14.mm: New.
* obj-c++.dg/property/dotsyntax-15.mm: New.
* obj-c++.dg/property/synthesize-7.mm: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166457 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/objc.dg/property')
-rw-r--r-- | gcc/testsuite/objc.dg/property/dotsyntax-13.m | 53 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/dotsyntax-14.m | 77 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/dotsyntax-15.m | 80 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/dynamic-4.m | 45 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/dynamic-5.m | 53 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/dynamic-6.m | 26 | ||||
-rw-r--r-- | gcc/testsuite/objc.dg/property/synthesize-7.m | 86 |
7 files changed, 420 insertions, 0 deletions
diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-13.m b/gcc/testsuite/objc.dg/property/dotsyntax-13.m new file mode 100644 index 00000000000..c5a4b3301e3 --- /dev/null +++ b/gcc/testsuite/objc.dg/property/dotsyntax-13.m @@ -0,0 +1,53 @@ +/* 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 a local variable. */ + +#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 + +int main (void) +{ + MyRootClass *object = [[MyRootClass alloc] init]; + int i; + + for (i = 0; i < 10; i++) + { + object.count = i; + + if (object.count != i) + abort (); + } + + return 0; +} + + diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-14.m b/gcc/testsuite/objc.dg/property/dotsyntax-14.m new file mode 100644 index 00000000000..0606ec4a2bb --- /dev/null +++ b/gcc/testsuite/objc.dg/property/dotsyntax-14.m @@ -0,0 +1,77 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */ +/* { dg-do compile } */ + +/* Test dot-syntax with accessors to be looked up in protocol @properties. */ + +#include <stdlib.h> +#include <objc/objc.h> +#include <objc/runtime.h> + +@protocol ProtocolA +@property int countA; +@end + +@protocol ProtocolB +@property int countB; +@end + +@protocol ProtocolC +@property int countC; +@end + +@interface MyRootClass +{ + Class isa; +} ++ (id) initialize; ++ (id) alloc; +- (id) init; +@end + +@interface MySubClass <ProtocolA, ProtocolB, ProtocolC> +@end + +int function (MySubClass *object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; + + return object.countC; +} + +int function2 (MyRootClass <ProtocolA, ProtocolB, ProtocolC> *object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; + + return object.countC; +} + +int function3 (MyRootClass <ProtocolA, ProtocolB> *object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; /* { dg-error "request for member .countC. in something not a structure or union" } */ + + return object.countC; /* { dg-error "request for member .countC. in something not a structure or union" } */ +} + +int function4 (id <ProtocolA, ProtocolB, ProtocolC> object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; + + return object.countC; +} + +int function5 (id <ProtocolA, ProtocolB> object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; /* { dg-error "request for member .countC. in something not a structure or union" } */ + + return object.countC; /* { dg-error "request for member .countC. in something not a structure or union" } */ +} diff --git a/gcc/testsuite/objc.dg/property/dotsyntax-15.m b/gcc/testsuite/objc.dg/property/dotsyntax-15.m new file mode 100644 index 00000000000..767f6a2b880 --- /dev/null +++ b/gcc/testsuite/objc.dg/property/dotsyntax-15.m @@ -0,0 +1,80 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */ +/* { dg-do compile } */ + +/* Test dot-syntax with accessors to be looked up in protocols. */ + +#include <stdlib.h> +#include <objc/objc.h> +#include <objc/runtime.h> + +@protocol ProtocolA +- (int) countA; +- (void) setCountA: (int)aNumber; +@end + +@protocol ProtocolB +- (int) countB; +- (void) setCountB: (int)aNumber; +@end + +@protocol ProtocolC +- (int) countC; +- (void) setCountC: (int)aNumber; +@end + +@interface MyRootClass +{ + Class isa; +} ++ (id) initialize; ++ (id) alloc; +- (id) init; +@end + +@interface MySubClass <ProtocolA, ProtocolB, ProtocolC> +@end + +int function (MySubClass *object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; + + return object.countC; +} + +int function2 (MyRootClass <ProtocolA, ProtocolB, ProtocolC> *object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; + + return object.countC; +} + +int function3 (MyRootClass <ProtocolA, ProtocolB> *object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; /* { dg-error "request for member .countC. in something not a structure or union" } */ + + return object.countC; /* { dg-error "request for member .countC. in something not a structure or union" } */ +} + +int function4 (id <ProtocolA, ProtocolB, ProtocolC> object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; + + return object.countC; +} + +int function5 (id <ProtocolA, ProtocolB> object, int x) +{ + object.countA = x; + object.countB = x; + object.countC = object.countB; /* { dg-error "request for member .countC. in something not a structure or union" } */ + + return object.countC; /* { dg-error "request for member .countC. in something not a structure or union" } */ +} diff --git a/gcc/testsuite/objc.dg/property/dynamic-4.m b/gcc/testsuite/objc.dg/property/dynamic-4.m new file mode 100644 index 00000000000..84998d6b407 --- /dev/null +++ b/gcc/testsuite/objc.dg/property/dynamic-4.m @@ -0,0 +1,45 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */ +/* { dg-do compile } */ + +#include <objc/objc.h> + +@interface MyRootClass +{ + Class isa; +} +@end + +@implementation MyRootClass +@end + +/* Test @property/@dynamic with protocols. */ + +@protocol MyProtocol +@property int a; +@end + + +/* This class is declared to conform to the protocol, but because of + @dynamic, no warnings are issued even if the getter/setter for the + @property are missing. */ +@interface MyClass1 : MyRootClass <MyProtocol> +@end + +@implementation MyClass1 +@dynamic a; +@end + + +/* This class is declared to conform to the protocol and warnings are + issued because the setter for the @property is missing. */ +@interface MyClass2 : MyRootClass <MyProtocol> +@end + +@implementation MyClass2 +- (int) a +{ + return 0; +} +@end /* { dg-warning "incomplete implementation" } */ +/* { dg-warning "method definition for .-setA:. not found" "" { target *-*-* } 43 } */ +/* { dg-warning "class .MyClass2. does not fully implement the .MyProtocol. protocol" "" { target *-*-* } 43 } */ diff --git a/gcc/testsuite/objc.dg/property/dynamic-5.m b/gcc/testsuite/objc.dg/property/dynamic-5.m new file mode 100644 index 00000000000..77e81411aae --- /dev/null +++ b/gcc/testsuite/objc.dg/property/dynamic-5.m @@ -0,0 +1,53 @@ +/* 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 @dynamic in the real scenario where a class declares a + @property, uses @dynamic to avoid implementing it, then subclasses + implement it. */ + +#include <objc/objc.h> +#include <objc/runtime.h> +#include <stdlib.h> + +@interface MyRootClass +{ + Class isa; +} +@property int a; ++ (id) initialize; ++ (id) alloc; +- (id) init; +@end + +@implementation MyRootClass ++ (id) initialize { return self; } ++ (id) alloc { return class_createInstance (self, 0); } +- (id) init { return self; } +@dynamic a; +@end + +@interface Test : MyRootClass +{ + int v1; +} +@end + +@implementation Test +@synthesize a = v1; +@end + +int main (void) +{ + /* Note how 'object' is declared to be of class 'MyRootClass', but + actually is of the subclass which implements the property for + real. */ + MyRootClass *object = [[Test alloc] init]; + + object.a = 40; + + if (object.a != 40) + abort (); + + return 0; +} diff --git a/gcc/testsuite/objc.dg/property/dynamic-6.m b/gcc/testsuite/objc.dg/property/dynamic-6.m new file mode 100644 index 00000000000..23a7a890582 --- /dev/null +++ b/gcc/testsuite/objc.dg/property/dynamic-6.m @@ -0,0 +1,26 @@ +/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */ +/* { dg-do compile } */ + +/* Test case when an accessor from a @property matches a method + required by a protocol. If the @property is @dynamic, then no + warning should be generated. */ + +#include <objc/objc.h> +#include <objc/runtime.h> +#include <stdlib.h> + +@protocol Count +- (int) count; +@end + +@interface MyRootClass <Count> +{ + Class isa; +} +@property int count; +@end + +@implementation MyRootClass +/* This @dynamic turns off any warnings for -count and -setCount:. */ +@dynamic count; +@end diff --git a/gcc/testsuite/objc.dg/property/synthesize-7.m b/gcc/testsuite/objc.dg/property/synthesize-7.m new file mode 100644 index 00000000000..929e3803bf9 --- /dev/null +++ b/gcc/testsuite/objc.dg/property/synthesize-7.m @@ -0,0 +1,86 @@ +/* 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 @synthesize with protocols of protocols. */ + +#include <stdlib.h> +#include <objc/objc.h> +#include <objc/runtime.h> + +@protocol ProtocolA +@property int countA; +@end + +@protocol ProtocolB <ProtocolA> +@property int countB; +@end + +@protocol ProtocolC <ProtocolB> +@property int countC; +@end + +@protocol ProtocolD +@property int countD; +@end + +@interface MyRootClass <ProtocolC> +{ + Class isa; + int countA; + int countB; + int countC; +} ++ (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 countA; +@synthesize countB; +@synthesize countC; +@end + +@interface MySubClass : MyRootClass <ProtocolD> +{ + int countD; +} +@end + +@implementation MySubClass +@synthesize countD; +@end + +int main (void) +{ + MySubClass *object = [[MySubClass alloc] init]; + int i; + + for (i = 0; i < 10; i++) + { + object.countA += i; + object.countB += i + 1; + object.countC += i + 2; + object.countD += i + 3; + } + + if (object.countA != 45) + abort (); + + if (object.countB != 55) + abort (); + + if (object.countC != 65) + abort (); + + if (object.countD != 75) + abort (); + + return 0; +} + + |