Annotation of GNUtools/cc/objc/Protocol.m, revision 1.1.1.1

1.1       root        1: /* This file contains the implementation of class Protocol.
                      2:    Copyright (C) 1993 Free Software Foundation, Inc.
                      3: 
                      4: This file is part of GNU CC. 
                      5: 
                      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)
                      9: any later version.
                     10: 
                     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.
                     15: 
                     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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
                     19:  
                     20: /* As a special exception, if you link this library with files
                     21:    compiled with GCC to produce an executable, this does not cause
                     22:    the resulting executable to be covered by the GNU General Public License.
                     23:    This exception does not however invalidate any other reasons why
                     24:    the executable file might be covered by the GNU General Public License.  */
                     25: 
                     26: #include "objc/Protocol.h"
                     27: #include "objc/objc-api.h"
                     28: 
                     29: /* Method description list */
                     30: struct objc_method_description_list {
                     31:         int count;
                     32:         struct objc_method_description list[1];
                     33: };
                     34: 
                     35: 
                     36: @implementation Protocol
                     37: {
                     38: @private
                     39:         char *protocol_name;
                     40:         struct objc_protocol_list *protocol_list;
                     41:         struct objc_method_description_list *instance_methods, *class_methods; 
                     42: }
                     43: 
                     44: /* Obtaining attributes intrinsic to the protocol */
                     45: 
                     46: - (const char *)name
                     47: {
                     48:   return protocol_name;
                     49: }
                     50: 
                     51: /* Testing protocol conformance */
                     52: 
                     53: - (BOOL) conformsTo: (Protocol *)aProtocolObject
                     54: {
                     55:   int i;
                     56:   struct objc_protocol_list* proto_list;
                     57: 
                     58:   if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
                     59:     return YES;
                     60: 
                     61:   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
                     62:     {
                     63:       for (i=0; i < proto_list->count; i++)
                     64:        {
                     65:          if ([proto_list->list[i] conformsTo: aProtocolObject])
                     66:            return YES;
                     67:        }
                     68:     }
                     69: 
                     70:   return NO;
                     71: }
                     72: 
                     73: /* Looking up information specific to a protocol */
                     74: 
                     75: - (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
                     76: {
                     77:   int i;
                     78:   struct objc_protocol_list* proto_list;
                     79:   const char* name = sel_get_name (aSel);
                     80:   struct objc_method_description *result;
                     81: 
                     82:   for (i = 0; i < instance_methods->count; i++)
                     83:     {
                     84:       if (!strcmp ((char*)instance_methods->list[i].name, name))
                     85:        return &(instance_methods->list[i]);
                     86:     }
                     87: 
                     88:   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
                     89:     {
                     90:       for (i=0; i < proto_list->count; i++)
                     91:        {
                     92:          if ((result = [proto_list->list[i]
                     93:                         descriptionForInstanceMethod: aSel]))
                     94:            return result;
                     95:        }
                     96:     }
                     97: 
                     98:   return NULL;
                     99: }
                    100: 
                    101: - (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
                    102: {
                    103:   int i;
                    104:   struct objc_protocol_list* proto_list;
                    105:   const char* name = sel_get_name (aSel);
                    106:   struct objc_method_description *result;
                    107: 
                    108:   for (i = 0; i < class_methods->count; i++)
                    109:     {
                    110:       if (!strcmp ((char*)class_methods->list[i].name, name))
                    111:        return &(class_methods->list[i]);
                    112:     }
                    113: 
                    114:   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
                    115:     {
                    116:       for (i=0; i < proto_list->count; i++)
                    117:        {
                    118:          if ((result = [proto_list->list[i]
                    119:                         descriptionForClassMethod: aSel]))
                    120:            return result;
                    121:        }
                    122:     }
                    123: 
                    124:   return NULL;
                    125: }
                    126: 
                    127: @end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.