OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [objc.dg/] [torture/] [forward-1.m] - Blame information for rev 708

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 704 jeremybenn
/* { dg-do run } */
2
/* See if -forward:: is able to work. */
3
/* { dg-skip-if "Needs OBJC2 Implementation" { *-*-darwin8* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
4
 
5
#include <stdio.h>
6
#include <stdlib.h>
7
 
8
#include "../../objc-obj-c++-shared/TestsuiteObject.m"
9
 
10
#define VALUETOUSE 1234567890
11
 
12
id forwarder, receiver;
13
 
14
@interface Forwarder: TestsuiteObject
15
{
16
    id receiver;
17
}
18
 
19
-initWithReceiver:theReceiver;
20
 
21
@end
22
 
23
@interface Receiver:TestsuiteObject
24
{
25
    int foo;
26
}
27
-display;
28
-initWithFoo:(int)theFoo;
29
@end
30
@implementation Receiver
31
 
32
-initWithFoo: (int)theFoo
33
{
34
    foo = theFoo;
35
    return self;
36
}
37
 
38
-display
39
{
40
  printf ("Executing display\n");
41
    /* Check to see if we are really the reciever. */
42
    if (self != receiver)
43
        abort ();
44
    /* And the value of foo is set correctly. */
45
    if (foo != VALUETOUSE)
46
      abort ();
47
    return self;
48
}
49
 
50
@end
51
 
52
@implementation Forwarder
53
-initWithReceiver: theReceiver
54
{
55
    [super init];
56
    receiver = theReceiver;
57
    return self;
58
}
59
-(void *) forward: (SEL)theSel: (void *)theArgFrame
60
{
61
  /* If we have a reciever try to perform on that object */
62
    if (receiver)
63
      {
64
        /* Simple forward that works for methods with no
65
           arguments.  */
66
        typedef id (*method_with_no_args) (id receiver, SEL _cmd);
67
        Method method = class_getInstanceMethod (object_getClass (receiver),
68
                                                 theSel);
69
        method_with_no_args imp = (method_with_no_args)(method_getImplementation
70
                                                        (method));
71
        return (*imp)(receiver, theSel);
72
      }
73
 
74
    /* Normally you'd emit an error here.  */
75
    printf ("Unrecognized selector\n");
76
    return NULL;
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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.