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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [objc/] [execute/] [bycopy-3.m] - Blame information for rev 702

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 702 jeremybenn
/*
2
 * Contributed by Nicola Pero <nicola@brainstorm.co.uk>
3
 * Wed Feb 28 12:27:03 CET 2001
4
 */
5
 
6
/*
7
 * This test contains some no-op code which is needed to keep it
8
 * compile on broken gcc 3.x.  Anyway, the no-op code does not
9
 * interfere with what we are testing, which is that the `bycopy'
10
 * keyword generates the _F_BYCOPY qualifier for the return type.  */
11
 
12
extern int printf (const char *, ...);
13
 
14
#include <objc/objc.h>
15
#include "../../objc-obj-c++-shared/runtime.h"
16
#include "../../objc-obj-c++-shared/TestsuiteObject.m"
17
 
18
@protocol MyProtocol
19
+ (bycopy id<MyProtocol>) bycopyMethod;
20
@end
21
 
22
/* This no-op class to keep it compile under broken gcc 3.x */
23
@interface MyObject : TestsuiteObject <MyProtocol>
24
@end
25
 
26
@implementation MyObject
27
+ (bycopy id<MyProtocol>) bycopyMethod
28
{
29
  return [MyObject alloc];
30
}
31
@end
32
 
33
/* The following header, together with the implementation included below,
34
   emulate functionality provided by the GNU runtime but not available from
35
   the NeXT runtime.  */
36
#include "../../objc-obj-c++-shared/objc-test-suite-next-encode-assist.h"
37
 
38
int main (void)
39
{
40
  struct objc_method_description method;
41
  const char *method_types;
42
  unsigned qualifiers;
43
  Protocol *protocol;
44
  /* This no-op command is needed to keep the test compile on broken
45
     gcc 3.x */
46
  MyObject *object = [MyObject bycopyMethod];
47
 
48
  /* Get the protocol object */
49
  protocol = @protocol (MyProtocol);
50
 
51
  /* Ask to the protocol for the description of the method bycopyMethod */
52
  method = protocol_getMethodDescription (protocol, @selector (bycopyMethod),
53
                                          YES, NO);
54
 
55
  /* Get the method types for the method - which encode return type,
56
     arguments etc. */
57
  method_types = method.types;
58
 
59
  if (method_types == NULL)
60
    {
61
      printf ("Could not find method bycopyMethod in protocol!\n");
62
      return 1;
63
    }
64
 
65
  /* Get the qualifiers for the return type */
66
  qualifiers = objc_get_type_qualifiers (method_types);
67
 
68
  /* If _F_BYCOPY is not there, the compiler is broken */
69
  if (! (qualifiers & _F_BYCOPY))
70
    {
71
      printf ("Failed - selector does not contain _F_BYCOPY qualifier!\n");
72
      return 1;
73
    }
74
 
75
  /* Else, happy end */
76
  return 0;
77
}
78
 
79
#ifdef __NEXT_RUNTIME__
80
unsigned
81
objc_get_type_qualifiers (const char *type)
82
{
83
  unsigned res = 0;
84
  BOOL flag = YES;
85
 
86
  while (flag)
87
    switch (*type++)
88
      {
89
      case _C_CONST:    res |= _F_CONST; break;
90
      case _C_IN:       res |= _F_IN; break;
91
      case _C_INOUT:    res |= _F_INOUT; break;
92
      case _C_OUT:      res |= _F_OUT; break;
93
      case _C_BYCOPY:   res |= _F_BYCOPY; break;
94
      case _C_BYREF:  res |= _F_BYREF; break;
95
      case _C_ONEWAY:   res |= _F_ONEWAY; break;
96
      case _C_GCINVISIBLE: res |= _F_GCINVISIBLE; break;
97
      default: flag = NO;
98
    }
99
 
100
  return res;
101
}
102
#endif

powered by: WebSVN 2.1.0

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