Commit a9625a91 by Nicola Pero Committed by Nicola Pero

In gcc/objc/: 2010-11-05 Nicola Pero <nicola.pero@meta-innovation.com>

In gcc/objc/:
2010-11-05  Nicola Pero  <nicola.pero@meta-innovation.com>

        Fixed using the Objective-C 2.0 syntax with self and super.
        * objc-act.c (OBJC_LOOKUP_NO_INSTANCE_METHODS_OF_ROOT_CLASS): New.
        (maybe_make_artificial_property_decl): Added 'implementation'
        argument.  Use OBJC_LOOKUP_NO_INSTANCE_METHODS_OF_ROOT_CLASS when
        looking up getters or setters for a class.  If an implementation
        is specified, search it as well for a getter or setter.
        (objc_maybe_build_component_ref): Updated calls to
        maybe_make_artificial_property_decl; added code to deal with
        'self' and 'super' and with methods declared locally in the
        implementation.  Store the getter call expression in the
        PROPERTY_REF instead of throwing it away.
        (objc_build_class_component_ref): Updated calls to
        maybe_make_artificial_property_decl, and store the getter call
        expression in PROPERTY_REF instead of throwing it away.
        (lookup_method_static): Implemented
        OBJC_LOOKUP_NO_INSTANCE_METHODS_OF_ROOT_CLASS option.
        (objc_gimplify_property_ref): Do not build the getter method call
        here; instead use the one stored in the PROPERTY_REF.  If it's not
        there, produce helpful error messages.
        * objc-tree.def (PROPERTY_REF): Increased the number of operands
        from 2 to 3.  Updated comments.
        * objc-act.h (PROPERTY_REF_GETTER_CALL): New.

In gcc/testsuite/:
2010-11-05  Nicola Pero  <nicola.pero@meta-innovation.com>

        Fixed using the Objective-C 2.0 dot-syntax with self and super.
        * objc.dg/property/dotsyntax-5.m: New.
        * objc.dg/property/dotsyntax-6.m: New.
        * objc.dg/property/dotsyntax-7.m: New.
        * objc.dg/property/dotsyntax-8.m: New.
        * objc.dg/property/dotsyntax-9.m: New.
        * objc.dg/property/dotsyntax-10.m: New.
        * objc.dg/property/dotsyntax-11.m: New.
        * obj-c++.dg/property/dotsyntax-5.mm: New.
        * obj-c++.dg/property/dotsyntax-6.mm: New.
        * obj-c++.dg/property/dotsyntax-7.mm: New.
        * obj-c++.dg/property/dotsyntax-8.mm: New.
        * obj-c++.dg/property/dotsyntax-9.mm: New.
        * obj-c++.dg/property/dotsyntax-10.mm: New.
        * obj-c++.dg/property/dotsyntax-11.mm: New.

From-SVN: r166402
parent cd746c27
2010-11-06 Nicola Pero <nicola.pero@meta-innovation.com>
Fixed using the Objective-C 2.0 syntax with self and super.
* objc-act.c (OBJC_LOOKUP_NO_INSTANCE_METHODS_OF_ROOT_CLASS): New.
(maybe_make_artificial_property_decl): Added 'implementation'
argument. Use OBJC_LOOKUP_NO_INSTANCE_METHODS_OF_ROOT_CLASS when
looking up getters or setters for a class. If an implementation
is specified, search it as well for a getter or setter.
(objc_maybe_build_component_ref): Updated calls to
maybe_make_artificial_property_decl; added code to deal with
'self' and 'super' and with methods declared locally in the
implementation. Store the getter call expression in the
PROPERTY_REF instead of throwing it away.
(objc_build_class_component_ref): Updated calls to
maybe_make_artificial_property_decl, and store the getter call
expression in PROPERTY_REF instead of throwing it away.
(lookup_method_static): Implemented
OBJC_LOOKUP_NO_INSTANCE_METHODS_OF_ROOT_CLASS option.
(objc_gimplify_property_ref): Do not build the getter method call
here; instead use the one stored in the PROPERTY_REF. If it's not
there, produce helpful error messages.
* objc-tree.def (PROPERTY_REF): Increased the number of operands
from 2 to 3. Updated comments.
* objc-act.h (PROPERTY_REF_GETTER_CALL): New.
2010-11-06 Iain Sandoe <iains@gcc.gnu.org>
PR target/44981
......
......@@ -131,6 +131,15 @@ typedef enum objc_property_assign_semantics {
declared property. */
#define PROPERTY_REF_PROPERTY_DECL(NODE) TREE_OPERAND (PROPERTY_REF_CHECK (NODE), 1)
/* PROPERTY_REF_GETTER_CALL is the getter call expression, ready to
use at gimplify time if needed. Generating the getter call
requires modifying the selector table, and, in the case of
self/super, requires the context to be generated correctly. The
gimplify stage is too late to do these things, so we generate the
getter call earlier instead, and keep it here in case we need to
use it. */
#define PROPERTY_REF_GETTER_CALL(NODE) TREE_OPERAND (PROPERTY_REF_CHECK (NODE), 2)
/* CLASS_INTERFACE_TYPE, CLASS_IMPLEMENTATION_TYPE,
CATEGORY_INTERFACE_TYPE, CATEGORY_IMPLEMENTATION_TYPE,
......
......@@ -44,9 +44,11 @@ DEFTREECODE (CLASS_REFERENCE_EXPR, "class_reference_expr", tcc_expression, 1)
where 'object' is an Objective-C object and 'property' is an
Objective-C property. Operand 0 is the object (the tree
representing the expression), and Operand 1 is the property (the
PROPERTY_DECL). A PROPERTY_REF tree needs to be transformed into
'setter' and 'getter' calls at some point; at the moment this
happens in two places:
PROPERTY_DECL). Operand 2 is the 'getter' call, ready to be used;
we pregenerate it because it is hard to generate it properly later
on. A PROPERTY_REF tree needs to be transformed into 'setter' and
'getter' calls at some point; at the moment this happens in two
places:
* if we detect that a modify expression is being applied to a
PROPERTY_REF, then we transform that into a 'getter' call (this
......@@ -54,13 +56,15 @@ DEFTREECODE (CLASS_REFERENCE_EXPR, "class_reference_expr", tcc_expression, 1)
* else, it will remain as a PROPERTY_REF until we get to
gimplification; at that point, we convert each PROPERTY_REF into
a 'getter' call during ObjC/ObjC++ gimplify.
a 'getter' call during ObjC/ObjC++ gimplify. At that point, it
is quite hard to build a 'getter' call, but we have already built
it and we just need to swap Operand 2 in.
Please note that when the Objective-C 2.0 "dot-syntax" 'object.component'
is encountered, where 'component' is not a property but there are valid
setter/getter methods for it, an artificial PROPERTY_DECL is generated
and used in the PROPERTY_REF. */
DEFTREECODE (PROPERTY_REF, "property_ref", tcc_expression, 2)
DEFTREECODE (PROPERTY_REF, "property_ref", tcc_expression, 3)
/*
Local variables:
......
2010-11-06 Nicola Pero <nicola.pero@meta-innovation.com>
Fixed using the Objective-C 2.0 dot-syntax with self and super.
* objc.dg/property/dotsyntax-5.m: New.
* objc.dg/property/dotsyntax-6.m: New.
* objc.dg/property/dotsyntax-7.m: New.
* objc.dg/property/dotsyntax-8.m: New.
* objc.dg/property/dotsyntax-9.m: New.
* objc.dg/property/dotsyntax-10.m: New.
* objc.dg/property/dotsyntax-11.m: New.
* obj-c++.dg/property/dotsyntax-5.mm: New.
* obj-c++.dg/property/dotsyntax-6.mm: New.
* obj-c++.dg/property/dotsyntax-7.mm: New.
* obj-c++.dg/property/dotsyntax-8.mm: New.
* obj-c++.dg/property/dotsyntax-9.mm: New.
* obj-c++.dg/property/dotsyntax-10.mm: New.
* obj-c++.dg/property/dotsyntax-11.mm: New.
2010-11-06 Iain Sandoe <iains@gcc.gnu.org>
* obj-c++.dg/encode-3.mm: Provide a different string check for the
......
/* 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'. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (int) count;
- (void) setCount: (int)count;
+ (int) classCount;
+ (void) setClassCount: (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;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
@end
@interface MySubClass : MyRootClass
+ (int) testMe;
- (int) testMe;
@end
@implementation MySubClass
- (int) testMe
{
super.count = 400;
if (super.count != 400)
abort ();
return super.count;
}
+ (int) testMe
{
super.classCount = 4000;
if (super.classCount != 4000)
abort ();
return super.classCount;
}
@end
int main (void)
{
MySubClass *object = [[MySubClass alloc] init];
if ([object testMe] != 400)
abort ();
if ([MySubClass testMe] != 4000)
abort ();
return 0;
}
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
/* Test the error reporting for the dot-syntax in the scenario where
we have a setter, but not a getter, yet a getter is requested. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (void) setCount: (int)count;
+ (void) setClassCount: (int)count;
@end
@implementation MyRootClass
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
- (void) setCount: (int)count
{
a = count;
}
+ (void) setClassCount: (int)count
{
c = count;
}
@end
@interface MySubClass : MyRootClass
+ (int) testMe;
- (int) testMe;
@end
@implementation MySubClass
- (int) testMe
{
super.count = 400;
if (super.count != 400) /* { dg-error "no .count. getter found" } */
abort ();
return super.count; /* { dg-error "no .count. getter found" } */
}
+ (int) testMe
{
super.classCount = 4000;
if (super.classCount != 4000) /* { dg-error "no .classCount. getter found" } */
abort ();
return super.classCount; /* { dg-error "no .classCount. getter found" } */
}
@end
/* 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 the 'dot syntax' with self, both in instance and class methods. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (int) count;
- (void) setCount: (int)count;
+ (int) classCount;
+ (void) setClassCount: (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;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
- (int) testMe
{
self.count = 400;
if (self.count != 400)
abort ();
return self.count;
}
+ (int) testMe
{
self.classCount = 4000;
if (self.classCount != 4000)
abort ();
return self.classCount;
}
@end
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
if ([object testMe] != 400)
abort ();
if ([MyRootClass testMe] != 4000)
abort ();
return 0;
}
/* 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 nested 'dot syntax' (xxx.yyy.zzz or [xxx yyy].zzz). */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
@class MyRootClass;
static int c;
static MyRootClass *shared_root = nil;
@interface MyRootClass
{
Class isa;
int a;
int b;
MyRootClass *next;
}
@property int b;
@property (assign) MyRootClass *next;
+ (id) initialize;
+ (MyRootClass *)sharedInstance;
+ (id) alloc;
- (id) init;
- (MyRootClass *)same;
- (int) count;
- (void) setCount: (int)count;
@end
@implementation MyRootClass
@synthesize b;
@synthesize next;
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
+ (MyRootClass *)sharedInstance
{
if (!shared_root)
shared_root = [[self alloc] init];
return shared_root;
}
- (MyRootClass *)same
{
return self;
}
- (int) count
{
return a;
}
- (void) setCount: (int)count
{
a = count;
}
@end
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
/* Test ClassName.accessor.accessor. */
MyRootClass.sharedInstance.count = 500;
if (MyRootClass.sharedInstance.count != 500)
abort ();
/* Test object.accessor.accessor. */
object.same.count = 1000;
if (object.same.count != 1000)
abort ();
/* Test object.accessor.property. */
object.same.next = object;
if (object.same.next != object)
abort ();
/* Test lots of nesting. */
if (object.next.next.same.same.next.next.same != object)
abort ();
/* Test more nesting. */
MyRootClass.sharedInstance.next = object;
MyRootClass.sharedInstance.next.next.next.next.next.count = 2000;
if (MyRootClass.sharedInstance.next.next.next.next.next.count != 2000)
abort ();
/* Test more nesting. */
MyRootClass.sharedInstance.same.same.same.same.same.count = 3000;
if (MyRootClass.sharedInstance.same.same.same.same.same.count != 3000)
abort ();
/* Test [object method].property. */
[MyRootClass sharedInstance].count = 5000;
if ([MyRootClass sharedInstance].count != 5000)
abort ();
/* Just a final check. */
if (shared_root.count != 5000)
abort ();
return 0;
}
/* 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 of a casted expression. */
#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)
{
id object = [[MyRootClass alloc] init];
((MyRootClass *)object).count = 200;
if (((MyRootClass *)object).count != 200)
abort ();
return 0;
}
/* 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 the 'dot syntax' with typedefs. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (int) count;
- (void) setCount: (int)count;
+ (int) classCount;
+ (void) setClassCount: (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;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
@end
typedef MyRootClass MyType;
int main (void)
{
MyType *object = [[MyRootClass alloc] init];
object.count = 1974;
if (object.count != 1974)
abort ();
return 0;
}
/* 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 that setter/getters for dot-syntax are properly found even if
not declared in the @interface, but available in the local
@implementation before the current line (ie, [object name] can be
compiled in that case, so object.name should be compiled too). */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
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; }
- (int) count
{
return a;
}
- (void) setCount: (int)count
{
a = count;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
- (int) testMe
{
self.count = 400;
if (self.count != 400)
abort ();
return self.count;
}
+ (int) testMe
{
self.classCount = 4000;
if (self.classCount != 4000)
abort ();
return self.classCount;
}
@end
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
if ([object testMe] != 400)
abort ();
if ([MyRootClass testMe] != 4000)
abort ();
return 0;
}
/* 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'. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (int) count;
- (void) setCount: (int)count;
+ (int) classCount;
+ (void) setClassCount: (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;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
@end
@interface MySubClass : MyRootClass
+ (int) testMe;
- (int) testMe;
@end
@implementation MySubClass
- (int) testMe
{
super.count = 400;
if (super.count != 400)
abort ();
return super.count;
}
+ (int) testMe
{
super.classCount = 4000;
if (super.classCount != 4000)
abort ();
return super.classCount;
}
@end
int main (void)
{
MySubClass *object = [[MySubClass alloc] init];
if ([object testMe] != 400)
abort ();
if ([MySubClass testMe] != 4000)
abort ();
return 0;
}
/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
/* { dg-do compile } */
/* Test the error reporting for the dot-syntax in the scenario where
we have a setter, but not a getter, yet a getter is requested. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (void) setCount: (int)count;
+ (void) setClassCount: (int)count;
@end
@implementation MyRootClass
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
- (void) setCount: (int)count
{
a = count;
}
+ (void) setClassCount: (int)count
{
c = count;
}
@end
@interface MySubClass : MyRootClass
+ (int) testMe;
- (int) testMe;
@end
@implementation MySubClass
- (int) testMe
{
super.count = 400;
if (super.count != 400) /* { dg-error "no .count. getter found" } */
abort ();
return super.count; /* { dg-error "no .count. getter found" } */
}
+ (int) testMe
{
super.classCount = 4000;
if (super.classCount != 4000) /* { dg-error "no .classCount. getter found" } */
abort ();
return super.classCount; /* { dg-error "no .classCount. getter found" } */
}
@end
/* 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 the 'dot syntax' with self, both in instance and class methods. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (int) count;
- (void) setCount: (int)count;
+ (int) classCount;
+ (void) setClassCount: (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;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
- (int) testMe
{
self.count = 400;
if (self.count != 400)
abort ();
return self.count;
}
+ (int) testMe
{
self.classCount = 4000;
if (self.classCount != 4000)
abort ();
return self.classCount;
}
@end
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
if ([object testMe] != 400)
abort ();
if ([MyRootClass testMe] != 4000)
abort ();
return 0;
}
/* 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 nested 'dot syntax' (xxx.yyy.zzz or [xxx yyy].zzz). */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
@class MyRootClass;
static int c;
static MyRootClass *shared_root = nil;
@interface MyRootClass
{
Class isa;
int a;
int b;
MyRootClass *next;
}
@property int b;
@property (assign) MyRootClass *next;
+ (id) initialize;
+ (MyRootClass *)sharedInstance;
+ (id) alloc;
- (id) init;
- (MyRootClass *)same;
- (int) count;
- (void) setCount: (int)count;
@end
@implementation MyRootClass
@synthesize b;
@synthesize next;
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
+ (MyRootClass *)sharedInstance
{
if (!shared_root)
shared_root = [[self alloc] init];
return shared_root;
}
- (MyRootClass *)same
{
return self;
}
- (int) count
{
return a;
}
- (void) setCount: (int)count
{
a = count;
}
@end
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
/* Test ClassName.accessor.accessor. */
MyRootClass.sharedInstance.count = 500;
if (MyRootClass.sharedInstance.count != 500)
abort ();
/* Test object.accessor.accessor. */
object.same.count = 1000;
if (object.same.count != 1000)
abort ();
/* Test object.accessor.property. */
object.same.next = object;
if (object.same.next != object)
abort ();
/* Test lots of nesting. */
if (object.next.next.same.same.next.next.same != object)
abort ();
/* Test more nesting. */
MyRootClass.sharedInstance.next = object;
MyRootClass.sharedInstance.next.next.next.next.next.count = 2000;
if (MyRootClass.sharedInstance.next.next.next.next.next.count != 2000)
abort ();
/* Test more nesting. */
MyRootClass.sharedInstance.same.same.same.same.same.count = 3000;
if (MyRootClass.sharedInstance.same.same.same.same.same.count != 3000)
abort ();
/* Test [object method].property. */
[MyRootClass sharedInstance].count = 5000;
if ([MyRootClass sharedInstance].count != 5000)
abort ();
/* Just a final check. */
if (shared_root.count != 5000)
abort ();
return 0;
}
/* 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 of a casted expression. */
#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)
{
id object = [[MyRootClass alloc] init];
((MyRootClass *)object).count = 200;
if (((MyRootClass *)object).count != 200)
abort ();
return 0;
}
/* 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 the 'dot syntax' with typedefs. */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
int a;
}
+ (id) initialize;
+ (id) alloc;
- (id) init;
- (int) count;
- (void) setCount: (int)count;
+ (int) classCount;
+ (void) setClassCount: (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;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
@end
typedef MyRootClass MyType;
int main (void)
{
MyType *object = [[MyRootClass alloc] init];
object.count = 1974;
if (object.count != 1974)
abort ();
return 0;
}
/* 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 that setter/getters for dot-syntax are properly found even if
not declared in the @interface, but available in the local
@implementation before the current line (ie, [object name] can be
compiled in that case, so object.name should be compiled too). */
#include <stdlib.h>
#include <objc/objc.h>
#include <objc/runtime.h>
static int c;
@interface MyRootClass
{
Class isa;
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; }
- (int) count
{
return a;
}
- (void) setCount: (int)count
{
a = count;
}
+ (int) classCount
{
return c;
}
+ (void) setClassCount: (int)count
{
c = count;
}
- (int) testMe
{
self.count = 400;
if (self.count != 400)
abort ();
return self.count;
}
+ (int) testMe
{
self.classCount = 4000;
if (self.classCount != 4000)
abort ();
return self.classCount;
}
@end
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
if ([object testMe] != 400)
abort ();
if ([MyRootClass testMe] != 4000)
abort ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment