1 /* This file contains the implementation of class Protocol.
2 Copyright (C) 1993 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* As a special exception, if you link this library with files
22 compiled with GCC to produce an executable, this does not cause
23 the resulting executable to be covered by the GNU General Public License.
24 This exception does not however invalidate any other reasons why
25 the executable file might be covered by the GNU General Public License. */
27 #include "objc/Protocol.h"
28 #include "objc/objc-api.h"
30 /* Method description list */
31 struct objc_method_description_list {
33 struct objc_method_description list[1];
37 @implementation Protocol
41 struct objc_protocol_list *protocol_list;
42 struct objc_method_description_list *instance_methods, *class_methods;
45 /* Obtaining attributes intrinsic to the protocol */
52 /* Testing protocol conformance */
54 - (BOOL) conformsTo: (Protocol *)aProtocolObject
57 struct objc_protocol_list* proto_list;
59 if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
62 for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
64 for (i=0; i < proto_list->count; i++)
66 if ([proto_list->list[i] conformsTo: aProtocolObject])
74 /* Looking up information specific to a protocol */
76 - (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
79 struct objc_protocol_list* proto_list;
80 const char* name = sel_get_name (aSel);
81 struct objc_method_description *result;
83 for (i = 0; i < instance_methods->count; i++)
85 if (!strcmp ((char*)instance_methods->list[i].name, name))
86 return &(instance_methods->list[i]);
89 for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
91 for (i=0; i < proto_list->count; i++)
93 if ((result = [proto_list->list[i]
94 descriptionForInstanceMethod: aSel]))
102 - (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
105 struct objc_protocol_list* proto_list;
106 const char* name = sel_get_name (aSel);
107 struct objc_method_description *result;
109 for (i = 0; i < class_methods->count; i++)
111 if (!strcmp ((char*)class_methods->list[i].name, name))
112 return &(class_methods->list[i]);
115 for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
117 for (i=0; i < proto_list->count; i++)
119 if ((result = [proto_list->list[i]
120 descriptionForClassMethod: aSel]))