| 1 |
/* Wrapper around <objc/runtime.h> |
| 2 |
Copyright (C) 2011 Free Software Foundation, Inc. |
| 3 |
Contributed by Nicola Pero |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 7 |
GCC is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3, or (at your option) |
| 10 |
any later version. |
| 11 |
|
| 12 |
GCC is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with GCC; see the file COPYING3. If not see |
| 19 |
<http://www.gnu.org/licenses/>. */ |
| 20 |
|
| 21 |
#ifndef _TESTSUITE_RUNTIME_H_ |
| 22 |
#define _TESTSUITE_RUNTIME_H_ |
| 23 |
|
| 24 |
/* Include this file where you'd normally include <objc/runtime.h>. |
| 25 |
|
| 26 |
Older versions of the NeXT runtime do not have <objc/runtime.h> and |
| 27 |
you need to include <objc/objc-runtime.h> instead. This file takes |
| 28 |
care of figuring out if that's the case. */ |
| 29 |
|
| 30 |
#ifndef __NEXT_RUNTIME__ |
| 31 |
|
| 32 |
/* |
| 33 |
GNU Objective-C runtime (libobjc). |
| 34 |
*/ |
| 35 |
# include <objc/runtime.h> |
| 36 |
|
| 37 |
#else |
| 38 |
|
| 39 |
/* |
| 40 |
NeXT Objective-C runtime. |
| 41 |
*/ |
| 42 |
|
| 43 |
/* Include next-abi.h to determine which version of the runtime we are |
| 44 |
dealing with. TODO: If this is the only place including it, maybe |
| 45 |
it could be copied here ? */ |
| 46 |
# include "next-abi.h" |
| 47 |
|
| 48 |
# ifdef NEXT_OBJC_USE_NEW_INTERFACE |
| 49 |
|
| 50 |
/* New NeXT runtime, with an API that should be basically identical to |
| 51 |
the GNU Objective-C one. */ |
| 52 |
# include <objc/runtime.h> |
| 53 |
|
| 54 |
# else |
| 55 |
|
| 56 |
/* Old NeXT runtime, with an API similar, but not identical to the new |
| 57 |
one. To start with, different headers need to be included. */ |
| 58 |
# include <objc/objc-class.h> |
| 59 |
# include <objc/objc-runtime.h> |
| 60 |
|
| 61 |
/* Not all functions are available in the old NeXT runtime. A few |
| 62 |
that we need are not, and here we provide an implementation on top |
| 63 |
of the old NeXT API. */ |
| 64 |
|
| 65 |
# define class_isMetaClass(C) (CLS_GETINFO((struct objc_class *)C, CLS_META)? YES: NO) |
| 66 |
# define class_getName(C) object_getClassName(C) |
| 67 |
# define class_getSuperclass(C) (((struct objc_class *)C)->super_class) |
| 68 |
# define method_getImplementation(M) (((Method)M)->method_imp) |
| 69 |
# define method_getTypeEncoding(M) (((Method)M)->method_types) |
| 70 |
# define object_getClass(O) (*(struct objc_class **)O) |
| 71 |
|
| 72 |
#include <objc/Protocol.h> |
| 73 |
BOOL class_conformsToProtocol (Class class_, Protocol *protocol) |
| 74 |
{ |
| 75 |
struct objc_protocol_list *p; |
| 76 |
int i; |
| 77 |
for (p = class_->protocols; p; p = p->next) |
| 78 |
for (i = 0; i < p->count; i++) |
| 79 |
if ([p->list[i] conformsTo: protocol]) |
| 80 |
return YES; |
| 81 |
return NO; |
| 82 |
} |
| 83 |
|
| 84 |
#define protocol_getName(P) [P name] |
| 85 |
#define protocol_isEqual(P,Q) [P isEqual: Q] |
| 86 |
|
| 87 |
struct objc_method_description protocol_getMethodDescription (Protocol *protocol, |
| 88 |
SEL selector, |
| 89 |
BOOL requiredMethod, |
| 90 |
BOOL instanceMethod) |
| 91 |
{ |
| 92 |
struct objc_method_description *tmp; |
| 93 |
struct objc_method_description result; |
| 94 |
|
| 95 |
if (instanceMethod) |
| 96 |
tmp = [protocol descriptionForInstanceMethod: selector]; |
| 97 |
else |
| 98 |
tmp = [protocol descriptionForClassMethod: selector]; |
| 99 |
|
| 100 |
if (tmp) |
| 101 |
result = *tmp; |
| 102 |
else |
| 103 |
{ |
| 104 |
result.name = (SEL)0; |
| 105 |
result.types = (char *)0; |
| 106 |
} |
| 107 |
|
| 108 |
return result; |
| 109 |
} |
| 110 |
|
| 111 |
# endif /* NEXT_OBJC_USE_NEW_INTERFACE */ |
| 112 |
|
| 113 |
# endif /* __NEXT_RUNTIME__ */ |
| 114 |
|
| 115 |
#endif /* _TESTSUITE_RUNTIME_H_ */ |
| 116 |
|