mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-23 10:54:07 +08:00
435317e25c
2004-05-25 Andrew Pinski <pinskia@physics.uc.edu> Merge from the libobjc-branch 2004-02-09 Andrew Pinski <pinskia@physics.uc.edu> * Makefile.in (OBJC_H): Change objc-deps.h to objc-decls.h. 2004-02-03 Andrew Pinski <pinskia@physics.uc.edu> * Makefile.in (OBJC_H): Add objc-deps.h. 2004-01-27 Nicola Pero <n.pero@mi.flashnet.it> * Protocol.m ([-conformsTo:]): If the argument is nil, return NO. ([-hash], [-isEqual:]): New methods. 2004-01-27 Richard Frith-Macdonald <rfm@gnu.org> * sarray.c (sarray_free): Add a better comment. 2004-01-27 Adam Fedor <fedor@gnu.org> * hash.c (hash_add): Cast cachep to int. * selector.c (__sel_register_typed_name): Cast soffset_decode to int. 2004-01-27 Alexander Malmberg <alexander@malmberg.org> * selector.c: Rename register_selectors_from_list to __objc_register_selectors_from_list. Update caller. (__objc_register_selectors_from_list): Lock __objc_runtime_mutex while registering selectors. Use __sel_register_typed_name instead of sel_register_typed_name. Check for NULL method_name:s. (pool_alloc_selector): New function. (__sel_register_typed_name): Use pool_alloc_selector to allocate selector structures. * sendmsg.c (class_add_method_list): Use __objc_register_selectors_from_list. * objc/runtime.h: Add __objc_register_selectors_from_list. 2004-01-25 Adam Fedor <fedor@gnu.org> Nicola Pero <n.pero@mi.flashnet.it> Andrew Pinski <pinskia@physics.uc.edu> * objc/objc-decls.h: New file. * objc/objc-api.h (_objc_lookup_class): Mark as export. (_objc_load_callback): Likewise. (_objc_object_alloc): Likewise. (_objc_object_copy): Likewise. (_objc_object_dispose): Likewise. 2004-01-25 Andrew Pinski <pinskia@physics.uc.edu> * archive.c: s/__inline__/inline * sendmsg.c: Likewise. * encoding.c: Remove FIXME about the warning about unused variable. * sendmsg.c: Add a FIXME comment saying that this should be using libffi. * Makefile.in (LIBTOOL): Use @LIBTOOL@ now as it works. From-SVN: r82253
161 lines
4.0 KiB
Objective-C
161 lines
4.0 KiB
Objective-C
/* This file contains the implementation of class Protocol.
|
|
Copyright (C) 1993, 2004 Free Software Foundation, Inc.
|
|
|
|
This file is part of GCC.
|
|
|
|
GCC is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
GCC is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with GCC; see the file COPYING. If not, write to
|
|
the Free Software Foundation, 59 Temple Place - Suite 330,
|
|
Boston, MA 02111-1307, USA. */
|
|
|
|
/* As a special exception, if you link this library with files
|
|
compiled with GCC to produce an executable, this does not cause
|
|
the resulting executable to be covered by the GNU General Public License.
|
|
This exception does not however invalidate any other reasons why
|
|
the executable file might be covered by the GNU General Public License. */
|
|
|
|
#include "objc/Protocol.h"
|
|
#include "objc/objc-api.h"
|
|
|
|
/* Method description list */
|
|
struct objc_method_description_list {
|
|
int count;
|
|
struct objc_method_description list[1];
|
|
};
|
|
|
|
|
|
@implementation Protocol
|
|
{
|
|
@private
|
|
char *protocol_name;
|
|
struct objc_protocol_list *protocol_list;
|
|
struct objc_method_description_list *instance_methods, *class_methods;
|
|
}
|
|
|
|
/* Obtaining attributes intrinsic to the protocol */
|
|
|
|
- (const char *)name
|
|
{
|
|
return protocol_name;
|
|
}
|
|
|
|
/* Testing protocol conformance */
|
|
|
|
- (BOOL) conformsTo: (Protocol *)aProtocolObject
|
|
{
|
|
size_t i;
|
|
struct objc_protocol_list* proto_list;
|
|
|
|
if (aProtocolObject == nil)
|
|
return NO;
|
|
|
|
if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
|
|
return YES;
|
|
|
|
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
|
|
{
|
|
for (i=0; i < proto_list->count; i++)
|
|
{
|
|
if ([proto_list->list[i] conformsTo: aProtocolObject])
|
|
return YES;
|
|
}
|
|
}
|
|
|
|
return NO;
|
|
}
|
|
|
|
/* Looking up information specific to a protocol */
|
|
|
|
- (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
|
|
{
|
|
int i;
|
|
struct objc_protocol_list* proto_list;
|
|
const char* name = sel_get_name (aSel);
|
|
struct objc_method_description *result;
|
|
|
|
if (instance_methods)
|
|
for (i = 0; i < instance_methods->count; i++)
|
|
{
|
|
if (!strcmp ((char*)instance_methods->list[i].name, name))
|
|
return &(instance_methods->list[i]);
|
|
}
|
|
|
|
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
|
|
{
|
|
size_t j;
|
|
for (j=0; j < proto_list->count; j++)
|
|
{
|
|
if ((result = [proto_list->list[j]
|
|
descriptionForInstanceMethod: aSel]))
|
|
return result;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
- (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
|
|
{
|
|
int i;
|
|
struct objc_protocol_list* proto_list;
|
|
const char* name = sel_get_name (aSel);
|
|
struct objc_method_description *result;
|
|
|
|
if (class_methods)
|
|
for (i = 0; i < class_methods->count; i++)
|
|
{
|
|
if (!strcmp ((char*)class_methods->list[i].name, name))
|
|
return &(class_methods->list[i]);
|
|
}
|
|
|
|
for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
|
|
{
|
|
size_t j;
|
|
for (j=0; j < proto_list->count; j++)
|
|
{
|
|
if ((result = [proto_list->list[j]
|
|
descriptionForClassMethod: aSel]))
|
|
return result;
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
- (unsigned) hash
|
|
{
|
|
/* Compute a hash of the protocol_name; use the same hash algorithm
|
|
* that we use for class names; protocol names and class names are
|
|
* somewhat similar types of string spaces.
|
|
*/
|
|
int hash = 0, index;
|
|
|
|
for (index = 0; protocol_name[index] != '\0'; index++)
|
|
{
|
|
hash = (hash << 4) ^ (hash >> 28) ^ protocol_name[index];
|
|
}
|
|
|
|
hash = (hash ^ (hash >> 10) ^ (hash >> 20));
|
|
|
|
return hash;
|
|
}
|
|
|
|
- (BOOL) isEqual: (id)obj
|
|
{
|
|
if (strcmp (protocol_name, [obj name]) == 0)
|
|
return YES;
|
|
|
|
return NO;
|
|
}
|
|
@end
|