Protocol.m
上传用户:shenzhenrh
上传日期:2013-05-12
资源大小:2904k
文件大小:3k
源码类别:

信息检索与抽取

开发平台:

Unix_Linux

  1. /* This file contains the implementation of class Protocol.
  2.    Copyright (C) 1993 Free Software Foundation, Inc.
  3. This file is part of GNU CC. 
  4. GNU CC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU CC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU CC; see the file COPYING.  If not, write to
  14. the Free Software Foundation, 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.  */
  16.  
  17. /* As a special exception, if you link this library with files
  18.    compiled with GCC to produce an executable, this does not cause
  19.    the resulting executable to be covered by the GNU General Public License.
  20.    This exception does not however invalidate any other reasons why
  21.    the executable file might be covered by the GNU General Public License.  */
  22. #include "objc/Protocol.h"
  23. #include "objc/objc-api.h"
  24. /* Method description list */
  25. struct objc_method_description_list {
  26.         int count;
  27.         struct objc_method_description list[1];
  28. };
  29. @implementation Protocol
  30. {
  31. @private
  32.         char *protocol_name;
  33.         struct objc_protocol_list *protocol_list;
  34.         struct objc_method_description_list *instance_methods, *class_methods; 
  35. }
  36. /* Obtaining attributes intrinsic to the protocol */
  37. - (const char *)name
  38. {
  39.   return protocol_name;
  40. }
  41. /* Testing protocol conformance */
  42. - (BOOL) conformsTo: (Protocol *)aProtocolObject
  43. {
  44.   int i;
  45.   struct objc_protocol_list* proto_list;
  46.   if (!strcmp(aProtocolObject->protocol_name, self->protocol_name))
  47.     return YES;
  48.   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
  49.     {
  50.       for (i=0; i < proto_list->count; i++)
  51. {
  52.   if ([proto_list->list[i] conformsTo: aProtocolObject])
  53.     return YES;
  54. }
  55.     }
  56.   return NO;
  57. }
  58. /* Looking up information specific to a protocol */
  59. - (struct objc_method_description *) descriptionForInstanceMethod:(SEL)aSel
  60. {
  61.   int i;
  62.   struct objc_protocol_list* proto_list;
  63.   const char* name = sel_get_name (aSel);
  64.   struct objc_method_description *result;
  65.   for (i = 0; i < instance_methods->count; i++)
  66.     {
  67.       if (!strcmp ((char*)instance_methods->list[i].name, name))
  68. return &(instance_methods->list[i]);
  69.     }
  70.   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
  71.     {
  72.       for (i=0; i < proto_list->count; i++)
  73. {
  74.   if ((result = [proto_list->list[i]
  75.  descriptionForInstanceMethod: aSel]))
  76.     return result;
  77. }
  78.     }
  79.   return NULL;
  80. }
  81. - (struct objc_method_description *) descriptionForClassMethod:(SEL)aSel;
  82. {
  83.   int i;
  84.   struct objc_protocol_list* proto_list;
  85.   const char* name = sel_get_name (aSel);
  86.   struct objc_method_description *result;
  87.   for (i = 0; i < class_methods->count; i++)
  88.     {
  89.       if (!strcmp ((char*)class_methods->list[i].name, name))
  90. return &(class_methods->list[i]);
  91.     }
  92.   for (proto_list = protocol_list; proto_list; proto_list = proto_list->next)
  93.     {
  94.       for (i=0; i < proto_list->count; i++)
  95. {
  96.   if ((result = [proto_list->list[i]
  97.  descriptionForClassMethod: aSel]))
  98.     return result;
  99. }
  100.     }
  101.   return NULL;
  102. }
  103. @end