source: trunk/third/gcc/libobjc/Protocol.m @ 21199

Revision 21199, 3.4 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r21198, which included commits to RCS files with non-trunk default branches.
Line 
1/* This file contains the implementation of class Protocol.
2   Copyright (C) 1993 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING.  If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA.  */
20 
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.  */
26
27#include "objc/Protocol.h"
28#include "objc/objc-api.h"
29
30/* Method description list */
31struct objc_method_description_list {
32        int count;
33        struct objc_method_description list[1];
34};
35
36
37@implementation Protocol
38{
39@private
40        char *protocol_name;
41        struct objc_protocol_list *protocol_list;
42        struct objc_method_description_list *instance_methods, *class_methods;
43}
44
45/* Obtaining attributes intrinsic to the protocol */
46
47- (const char *)name
48{
49  return protocol_name;
50}
51
52/* Testing protocol conformance */
53
54- (BOOL) conformsTo: (Protocol *)aProtocolObject
55{
56  size_t i;
57  struct objc_protocol_list* proto_list;
58
59  if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
60    return YES;
61
62  for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
63    {
64      for (i=0; i < proto_list->count; i++)
65        {
66          if ([proto_list->list[i] conformsTo: aProtocolObject])
67            return YES;
68        }
69    }
70
71  return NO;
72}
73
74/* Looking up information specific to a protocol */
75
76- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
77{
78  int i;
79  struct objc_protocol_list* proto_list;
80  const char* name = sel_get_name (aSel);
81  struct objc_method_description *result;
82
83  if (instance_methods)
84    for (i = 0; i < instance_methods->count; i++)
85      {
86        if (!strcmp ((char*)instance_methods->list[i].name, name))
87          return &(instance_methods->list[i]);
88      }
89
90  for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
91    {
92      size_t j;
93      for (j=0; j < proto_list->count; j++)
94        {
95          if ((result = [proto_list->list[j]
96                         descriptionForInstanceMethod: aSel]))
97            return result;
98        }
99    }
100
101  return NULL;
102}
103
104- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
105{
106  int i;
107  struct objc_protocol_list* proto_list;
108  const char* name = sel_get_name (aSel);
109  struct objc_method_description *result;
110
111  if (class_methods)
112    for (i = 0; i < class_methods->count; i++)
113      {
114        if (!strcmp ((char*)class_methods->list[i].name, name))
115          return &(class_methods->list[i]);
116      }
117
118  for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
119    {
120      size_t j;
121      for (j=0; j < proto_list->count; j++)
122        {
123          if ((result = [proto_list->list[j]
124                         descriptionForClassMethod: aSel]))
125            return result;
126        }
127    }
128
129  return NULL;
130}
131
132@end
Note: See TracBrowser for help on using the repository browser.