]> git.ipfire.org Git - thirdparty/gcc.git/blame - libobjc/Protocol.m
In libobjc/: 2010-12-21 Nicola Pero <nicola.pero@meta-innovation.com>
[thirdparty/gcc.git] / libobjc / Protocol.m
CommitLineData
88e17b57 1/* This file contains the implementation of class Protocol.
ae422ccd 2 Copyright (C) 1993, 2004, 2009, 2010 Free Software Foundation, Inc.
88e17b57 3
6c82ad25 4This file is part of GCC.
88e17b57 5
6c82ad25 6GCC is free software; you can redistribute it and/or modify
88e17b57 7it under the terms of the GNU General Public License as published by
748086b7 8the Free Software Foundation; either version 3, or (at your option)
88e17b57
BE
9any later version.
10
6c82ad25 11GCC is distributed in the hope that it will be useful,
88e17b57
BE
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
748086b7
JJ
16Under Section 7 of GPL version 3, you are granted additional
17permissions described in the GCC Runtime Library Exception, version
183.1, as published by the Free Software Foundation.
19
20You should have received a copy of the GNU General Public License and
21a copy of the GCC Runtime Library Exception along with this program;
22see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23<http://www.gnu.org/licenses/>. */
88e17b57 24
6dead247 25#include "objc-private/common.h"
ae422ccd
NP
26#include "objc/runtime.h"
27#include "objc-private/module-abi-8.h"
88e17b57 28#include "objc/Protocol.h"
88e17b57 29
88e17b57 30@implementation Protocol
c06a8664
NP
31- (BOOL) isEqual: (id)obj
32{
33 return protocol_isEqual (self, obj);
34}
35@end
36
37@implementation Protocol (Deprecated)
88e17b57
BE
38
39- (const char *)name
40{
41 return protocol_name;
42}
43
88e17b57
BE
44- (BOOL) conformsTo: (Protocol *)aProtocolObject
45{
ae422ccd 46 return protocol_conformsToProtocol (self, aProtocolObject);
88e17b57
BE
47}
48
88e17b57
BE
49- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
50{
51 int i;
52 struct objc_protocol_list* proto_list;
88e17b57
BE
53 struct objc_method_description *result;
54
75d3baee
ZW
55 if (instance_methods)
56 for (i = 0; i < instance_methods->count; i++)
57 {
ae422ccd 58 if (sel_isEqual (instance_methods->list[i].name, aSel))
75d3baee
ZW
59 return &(instance_methods->list[i]);
60 }
88e17b57
BE
61
62 for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
63 {
8f8c44cb
KG
64 size_t j;
65 for (j=0; j < proto_list->count; j++)
88e17b57 66 {
8f8c44cb 67 if ((result = [proto_list->list[j]
ae422ccd 68 descriptionForInstanceMethod: aSel]))
88e17b57
BE
69 return result;
70 }
71 }
72
73 return NULL;
74}
75
76- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
77{
78 int i;
79 struct objc_protocol_list* proto_list;
88e17b57
BE
80 struct objc_method_description *result;
81
75d3baee
ZW
82 if (class_methods)
83 for (i = 0; i < class_methods->count; i++)
84 {
ae422ccd 85 if (sel_isEqual (class_methods->list[i].name, aSel))
75d3baee
ZW
86 return &(class_methods->list[i]);
87 }
88e17b57
BE
88
89 for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
90 {
8f8c44cb
KG
91 size_t j;
92 for (j=0; j < proto_list->count; j++)
88e17b57 93 {
8f8c44cb 94 if ((result = [proto_list->list[j]
ae422ccd 95 descriptionForClassMethod: aSel]))
88e17b57
BE
96 return result;
97 }
98 }
99
100 return NULL;
101}
102
435317e2
AP
103- (unsigned) hash
104{
105 /* Compute a hash of the protocol_name; use the same hash algorithm
c06a8664
NP
106 that we use for class names; protocol names and class names are
107 somewhat similar types of string spaces. */
435317e2
AP
108 int hash = 0, index;
109
110 for (index = 0; protocol_name[index] != '\0'; index++)
111 {
112 hash = (hash << 4) ^ (hash >> 28) ^ protocol_name[index];
113 }
114
115 hash = (hash ^ (hash >> 10) ^ (hash >> 20));
116
117 return hash;
118}
119
88e17b57 120@end