1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
/* Compatibility code between APIs and ABIs for the objc test suite.
Copyright (C) 2010, 2011 Free Software Foundation, Inc.
Contributed by Iain Sandoe
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/*
* Implementation of a compatibility layer for the ObjC* test-suite.
*
* Four cases:
* GNU
* Uses the 'old' Object with API and ABI = 0.
* Compatibility methods are added.
* NeXT pre-Darwin9
* Uses the 'old' Object with API and ABI = 0.
* NeXT Darwin >= 9 with no implementation of ABI 2
* Uses API 2 and ABI 0 for m32, uses the 'old' Object'
* Uses API 2 for m64 but only compile tests can be expected to work.
* NeXT Darwin >= 9 with __OBJC2__
* Uses API 2 and ABI 0 for m32, uses the 'old' Object'
* Uses API 2 and ABI 2 - the libobjc implementation of Object is very
* basic, and we add a category to expand this for test-suite use.
*/
#ifndef _OBJC_OBJECT1_IMPLEMENTATION_H_
#define _OBJC_OBJECT1_IMPLEMENTATION_H_
#include "Object1.h"
#ifndef __NEXT_RUNTIME__
/* Save us from repeating this. */
@implementation Object (TEST_SUITE_ADDITIONS)
+ initialize
{
return self;
}
@end
#else
/* For NeXT pre-Darwin 9 or m32 we need do nothing. */
# if NEXT_OBJC_ABI_VERSION >= 2
/* Pick up the API=2 header. */
# include <objc/runtime.h>
# ifndef __OBJC2__
/* On a Darwin system >= 9 when there is no __OBJC2__ compiler, the testcases
will not link. So we provide a dummy Object for this purpose. */
@implementation Object
+ (Class) class
{
return self;
}
- (BOOL)isEqual: (id)anObject
{
return self == anObject;
}
@end
# endif /* __OBJC2__ */
/* In any case, since the library does not provide a complete (enough)
implementation we need to provide the additions. */
@implementation Object (TEST_SUITE_ADDITIONS)
+ initialize
{
return self;
}
- init
{
return self;
}
- (Class) class
{
return isa;
}
+ (Class) superclass
{
return class_getSuperclass(object_getClass(self));
}
+ new
{
return [[self alloc] init];
}
+ free
{
return nil;
}
- free
{
return object_dispose(self);
}
+ alloc
{
return class_createInstance (self, 0);
}
- (Class) superclass {
return class_getSuperclass([self class]);
}
- (const char *) name {
return class_getName([self class]);
}
-(BOOL)conformsTo:(Protocol *)protocol {
Class cls;
for (cls = [self class]; cls; cls = [cls superclass])
{
if (class_conformsToProtocol(cls, protocol))
return YES;
}
return NO;
}
#ifdef __cplusplus
extern "C" {
#endif
extern int printf (const char *, ...);
extern void abort (void);
#ifdef __cplusplus
}
#endif
/* This is a helper to catch cases where we need to add more functionality
to our test-suite category - more informative than fail with 'does not
respond to forward:' */
- forward: (SEL)sel : (marg_list)args
{
const char * onam = object_getClassName (self);
const char * snam = sel_getName (sel);
printf ("%s: tried to forward: %s\n", onam, snam);
abort ();
}
@end
# endif /* NEXT_OBJC_ABI_VERSION >= 2 */
# endif /* __NEXT_RUNTIME__ */
#endif /* _OBJC_OBJECT1_IMPLEMENTATION_H_ */
|