2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 Copyright 1991-1996 NeXT Software, Inc.
30 #include <winnt-pdo.h>
33 #include "objc-private.h"
34 #import <objc/Protocol.h>
36 #include <objc/objc-runtime.h>
40 #include <mach-o/dyld.h>
41 #include <mach-o/ldsyms.h>
44 /* some forward declarations */
46 static struct objc_method_description *
47 lookup_method(struct objc_method_description_list *mlist, SEL aSel);
49 static struct objc_method_description *
50 lookup_class_method(struct objc_protocol_list *plist, SEL aSel);
52 static struct objc_method_description *
53 lookup_instance_method(struct objc_protocol_list *plist, SEL aSel);
55 @implementation Protocol
58 + _fixup: (OBJC_PROTOCOL_PTR)protos numElements: (int) nentries
61 for (i = 0; i < nentries; i++)
63 /* isa has been overloaded by the compiler to indicate version info */
64 protos[i] OBJC_PROTOCOL_DEREF isa = self; // install the class descriptor.
76 hdrs = _getObjcHeaders();
78 for (hp = hdrs; *hp; hp++)
80 p = (OBJC_PROTOCOL_PTR)_getObjcProtocols((headerType*)*hp, &size);
81 if (p && size) { [self _fixup:p numElements: size]; }
88 - (BOOL) conformsTo: (Protocol *)aProtocolObj
93 if (strcmp(aProtocolObj->protocol_name, protocol_name) == 0)
95 else if (protocol_list)
99 for (i = 0; i < protocol_list->count; i++)
101 Protocol *p = protocol_list->list[i];
103 if (strcmp(aProtocolObj->protocol_name, p->protocol_name) == 0)
106 if ([p conformsTo:aProtocolObj])
115 - (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
117 struct objc_method_description *m = lookup_method(instance_methods, aSel);
119 if (!m && protocol_list)
120 m = lookup_instance_method(protocol_list, aSel);
125 - (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel
127 struct objc_method_description *m = lookup_method(class_methods, aSel);
129 if (!m && protocol_list)
130 m = lookup_class_method(protocol_list, aSel);
137 return protocol_name;
140 - (BOOL)isEqual:other
142 return [other isKindOf:[Protocol class]] && [self conformsTo: other] && [other conformsTo: self];
151 struct objc_method_description *
152 lookup_method(struct objc_method_description_list *mlist, SEL aSel)
157 for (i = 0; i < mlist->count; i++)
158 if (mlist->list[i].name == aSel)
159 return mlist->list+i;
165 struct objc_method_description *
166 lookup_instance_method(struct objc_protocol_list *plist, SEL aSel)
169 struct objc_method_description *m = 0;
171 for (i = 0; i < plist->count; i++)
173 if (plist->list[i]->instance_methods)
174 m = lookup_method(plist->list[i]->instance_methods, aSel);
176 /* depth first search */
177 if (!m && plist->list[i]->protocol_list)
178 m = lookup_instance_method(plist->list[i]->protocol_list, aSel);
187 struct objc_method_description *
188 lookup_class_method(struct objc_protocol_list *plist, SEL aSel)
191 struct objc_method_description *m = 0;
193 for (i = 0; i < plist->count; i++)
195 if (plist->list[i]->class_methods)
196 m = lookup_method(plist->list[i]->class_methods, aSel);
198 /* depth first search */
199 if (!m && plist->list[i]->protocol_list)
200 m = lookup_class_method(plist->list[i]->protocol_list, aSel);