OSDN Git Service

In libobjc/:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / torture / forward-1.m
1 /* { dg-do run } */
2 /* See if -forward::/-performv:: is able to work. */
3 /* { dg-xfail-run-if "PR36610" { ! { { i?86-*-* x86_64-*-* } && ilp32 } } { "-fgnu-runtime" } { "" } } */
4 /* { dg-skip-if "Needs OBJC2 Implementation" { *-*-darwin* && { lp64 } } { "-fnext-runtime" } { "" } } */
5 /* There is no implementation of forward: in the NeXT m64 libobjc/Object
6    neither have we implemented this in our extensions - so we have to skip it
7    for now.  */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11
12 #ifndef __NEXT_RUNTIME__
13 #  include <objc/objc-api.h>
14 #endif
15 #include <objc/Object.h>
16
17 #define VALUETOUSE 1234567890
18
19 id forwarder, receiver;
20
21 @interface Forwarder: Object
22 {
23     id receiver;
24 }
25
26 -initWithReceiver:theReceiver;
27
28 @end
29
30 @interface Receiver:Object
31 {
32     int foo;
33 }
34 -display;
35 -initWithFoo:(int)theFoo;
36 @end
37 @implementation Receiver
38
39 -initWithFoo: (int)theFoo
40 {
41     foo = theFoo;
42     return self;
43 }
44
45 -display
46 {
47     /* Check to see if we are really the reciever. */
48     if (self != receiver)
49         abort ();
50     /* And the value of foo is set correctly. */
51     if (foo != VALUETOUSE)
52       abort ();
53     return self;
54 }
55
56 @end
57
58 @implementation Forwarder
59 -initWithReceiver: theReceiver
60 {
61     [super init];
62     receiver = theReceiver;
63     return self;
64 }
65 #ifdef __NEXT_RUNTIME__
66 - forward: (SEL)theSel: (marg_list)theArgFrame
67 #else
68 -(retval_t) forward: (SEL)theSel: (arglist_t)theArgFrame
69 #endif
70 {
71   /* If we have a reciever try to perform on that object */
72     if (receiver)
73         return [receiver performv: theSel: theArgFrame];
74
75     /* Normally you'd emit an error here.  */
76     printf ("Unrecognized selector\n");
77 }
78 @end
79 int main()
80 {
81     /* Init the reciever. */
82     receiver = [[Receiver alloc] initWithFoo: VALUETOUSE];
83     /* Init the fowarder. */
84     forwarder = [[Forwarder alloc] initWithReceiver: receiver];
85     /* Call display on the forwarder which in turns calls display on
86        the reciever. */
87     [forwarder display];
88     exit(0);
89 }