⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class.c

📁 gcc的组件
💻 C
📖 第 1 页 / 共 2 页
字号:
            while (node != NULL)        {          printf ("\t%s\n", node->name);          node = node->next;        }    }}/* Debugging function - print an histogram of number of classes in   function of hash key values.  Useful to evaluate the hash function   in real cases.  */voidclass_table_print_histogram (void){  int i, j;  int counter = 0;    for (i = 0; i < CLASS_TABLE_SIZE; i++)    {      class_node_ptr node;            node = class_table_array[i];            while (node != NULL)        {          counter++;          node = node->next;        }      if (((i + 1) % 50) == 0)        {          printf ("%4d:", i + 1);          for (j = 0; j < counter; j++)            {              printf ("X");            }          printf ("\n");          counter = 0;        }    }  printf ("%4d:", i + 1);  for (j = 0; j < counter; j++)    {      printf ("X");    }  printf ("\n");}#endif /* DEBUGGING FUNCTIONS *//** ** Objective-C runtime functions **//* From now on, the only access to the class table data structure   should be via the class_table_* functions.  *//* This is a hook which is called by objc_get_class and   objc_lookup_class if the runtime is not able to find the class.     This may e.g. try to load in the class using dynamic loading.  */Class (*_objc_lookup_class) (const char *name) = 0;      /* !T:SAFE *//* True when class links has been resolved.  */     BOOL __objc_class_links_resolved = NO;                  /* !T:UNUSED */void__objc_init_class_tables (void){  /* Allocate the class hash table.  */    if (__class_table_lock)    return;    objc_mutex_lock (__objc_runtime_mutex);    class_table_setup ();  objc_mutex_unlock (__objc_runtime_mutex);}  /* This function adds a class to the class hash table, and assigns the   class a number, unless it's already known.  */void__objc_add_class_to_hash (Class class){  Class h_class;  objc_mutex_lock (__objc_runtime_mutex);  /* Make sure the table is there.  */  assert (__class_table_lock);  /* Make sure it's not a meta class.  */  assert (CLS_ISCLASS (class));  /* Check to see if the class is already in the hash table.  */  h_class = class_table_get_safe (class->name);  if (! h_class)    {      /* The class isn't in the hash table.  Add the class and assign a class         number.  */      static unsigned int class_number = 1;      CLS_SETNUMBER (class, class_number);      CLS_SETNUMBER (class->class_pointer, class_number);      ++class_number;      class_table_insert (class->name, class);    }  objc_mutex_unlock (__objc_runtime_mutex);}/* Get the class object for the class named NAME.  If NAME does not   identify a known class, the hook _objc_lookup_class is called.  If   this fails, nil is returned.  */Classobjc_lookup_class (const char *name){  Class class;  class = class_table_get_safe (name);  if (class)    return class;  if (_objc_lookup_class)    return (*_objc_lookup_class) (name);  else    return 0;}/* Get the class object for the class named NAME.  If NAME does not   identify a known class, the hook _objc_lookup_class is called.  If   this fails, an error message is issued and the system aborts.  */Classobjc_get_class (const char *name){  Class class;  class = class_table_get_safe (name);  if (class)    return class;  if (_objc_lookup_class)    class = (*_objc_lookup_class) (name);  if (class)    return class;    objc_error (nil, OBJC_ERR_BAD_CLASS,               "objc runtime: cannot find class %s\n", name);  return 0;}MetaClassobjc_get_meta_class (const char *name){  return objc_get_class (name)->class_pointer;}/* This function provides a way to enumerate all the classes in the   executable.  Pass *ENUM_STATE == NULL to start the enumeration.  The   function will return 0 when there are no more classes.     For example:        id class;        void *es = NULL;       while ((class = objc_next_class (&es)))         ... do something with class; */Classobjc_next_class (void **enum_state){  Class class;  objc_mutex_lock (__objc_runtime_mutex);    /* Make sure the table is there.  */  assert (__class_table_lock);  class = class_table_next ((struct class_table_enumerator **) enum_state);  objc_mutex_unlock (__objc_runtime_mutex);    return class;}/* Resolve super/subclass links for all classes.  The only thing we   can be sure of is that the class_pointer for class objects point to   the right meta class objects.  */void__objc_resolve_class_links (void){  struct class_table_enumerator *es = NULL;  Class object_class = objc_get_class ("Object");  Class class1;  assert (object_class);  objc_mutex_lock (__objc_runtime_mutex);  /* Assign subclass links.  */  while ((class1 = class_table_next (&es)))    {      /* Make sure we have what we think we have.  */      assert (CLS_ISCLASS (class1));      assert (CLS_ISMETA (class1->class_pointer));      /* The class_pointer of all meta classes point to Object's meta         class.  */      class1->class_pointer->class_pointer = object_class->class_pointer;      if (! CLS_ISRESOLV (class1))        {          CLS_SETRESOLV (class1);          CLS_SETRESOLV (class1->class_pointer);                        if (class1->super_class)            {                 Class a_super_class                 = objc_get_class ((char *) class1->super_class);                            assert (a_super_class);                            DEBUG_PRINTF ("making class connections for: %s\n",                            class1->name);                            /* Assign subclass links for superclass.  */              class1->sibling_class = a_super_class->subclass_list;              a_super_class->subclass_list = class1;                            /* Assign subclass links for meta class of superclass.  */              if (a_super_class->class_pointer)                {                  class1->class_pointer->sibling_class                    = a_super_class->class_pointer->subclass_list;                  a_super_class->class_pointer->subclass_list                     = class1->class_pointer;                }            }          else /* A root class, make its meta object be a subclass of                  Object.  */            {              class1->class_pointer->sibling_class                 = object_class->subclass_list;              object_class->subclass_list = class1->class_pointer;            }        }    }  /* Assign superclass links.  */   es = NULL;   while ((class1 = class_table_next (&es)))    {      Class sub_class;      for (sub_class = class1->subclass_list; sub_class;           sub_class = sub_class->sibling_class)        {          sub_class->super_class = class1;          if (CLS_ISCLASS (sub_class))            sub_class->class_pointer->super_class = class1->class_pointer;        }    }  objc_mutex_unlock (__objc_runtime_mutex);}#define CLASSOF(c) ((c)->class_pointer)Classclass_pose_as (Class impostor, Class super_class){  if (! CLS_ISRESOLV (impostor))    __objc_resolve_class_links ();  /* Preconditions */  assert (impostor);  assert (super_class);  assert (impostor->super_class == super_class);  assert (CLS_ISCLASS (impostor));  assert (CLS_ISCLASS (super_class));  assert (impostor->instance_size == super_class->instance_size);  {    Class *subclass = &(super_class->subclass_list);    /* Move subclasses of super_class to impostor.  */    while (*subclass)      {        Class nextSub = (*subclass)->sibling_class;        if (*subclass != impostor)          {            Class sub = *subclass;            /* Classes */            sub->sibling_class = impostor->subclass_list;            sub->super_class = impostor;            impostor->subclass_list = sub;            /* It will happen that SUB is not a class object if it is               the top of the meta class hierarchy chain (root               meta-class objects inherit their class object).  If               that is the case... don't mess with the meta-meta               class.  */            if (CLS_ISCLASS (sub))              {                /* Meta classes */                CLASSOF (sub)->sibling_class =                   CLASSOF (impostor)->subclass_list;                CLASSOF (sub)->super_class = CLASSOF (impostor);                CLASSOF (impostor)->subclass_list = CLASSOF (sub);              }          }        *subclass = nextSub;      }    /* Set subclasses of superclass to be impostor only.  */    super_class->subclass_list = impostor;    CLASSOF (super_class)->subclass_list = CLASSOF (impostor);        /* Set impostor to have no sibling classes.  */    impostor->sibling_class = 0;    CLASSOF (impostor)->sibling_class = 0;  }    /* Check relationship of impostor and super_class is kept.  */  assert (impostor->super_class == super_class);  assert (CLASSOF (impostor)->super_class == CLASSOF (super_class));  /* This is how to update the lookup table.  Regardless of what the     keys of the hashtable is, change all values that are superclass     into impostor.  */  objc_mutex_lock (__objc_runtime_mutex);  class_table_replace (super_class, impostor);  objc_mutex_unlock (__objc_runtime_mutex);  /* Next, we update the dispatch tables...  */  __objc_update_dispatch_table_for_class (CLASSOF (impostor));  __objc_update_dispatch_table_for_class (impostor);  return impostor;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -