2010-06-02 22:25:12 +00:00
|
|
|
#ifndef __OBJC_CLASS_H_INCLUDED
|
|
|
|
#define __OBJC_CLASS_H_INCLUDED
|
2011-07-26 17:39:13 +00:00
|
|
|
#include "visibility.h"
|
2011-07-12 15:48:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Overflow bitfield. Used for bitfields that are more than 63 bits.
|
|
|
|
*/
|
|
|
|
struct objc_bitfield
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The number of elements in the values array.
|
|
|
|
*/
|
|
|
|
int32_t length;
|
|
|
|
/**
|
|
|
|
* An array of values. Each 32 bits is stored in the native endian for the
|
|
|
|
* platform.
|
|
|
|
*/
|
|
|
|
int32_t values[0];
|
|
|
|
};
|
|
|
|
|
2010-05-13 22:29:56 +00:00
|
|
|
struct objc_class
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Pointer to the metaclass for this class. The metaclass defines the
|
|
|
|
* methods use when a message is sent to the class, rather than an
|
|
|
|
* instance.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
struct objc_class *isa;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* Pointer to the superclass. The compiler will set this to the name of
|
|
|
|
* the superclass, the runtime will initialize it to point to the real
|
|
|
|
* class.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
struct objc_class *super_class;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* The name of this class. Set to the same value for both the class and
|
|
|
|
* its associated metaclass.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
const char *name;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* The version of this class. This is not used by the language, but may be
|
|
|
|
* set explicitly at class load time.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
long version;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
2010-05-13 23:27:17 +00:00
|
|
|
* A bitfield containing various flags. See the objc_class_flags
|
2010-06-01 19:41:07 +00:00
|
|
|
* enumerated type for possible values.
|
2010-05-13 22:29:56 +00:00
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
unsigned long info;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* The size of this class. For classes using the non-fragile ABI, the
|
|
|
|
* compiler will set this to a negative value The absolute value will be
|
|
|
|
* the size of the instance variables defined on just this class. When
|
|
|
|
* using the fragile ABI, the instance size is the size of instances of
|
|
|
|
* this class, including any instance variables defined on superclasses.
|
|
|
|
*
|
|
|
|
* In both cases, this will be set to the size of an instance of the class
|
|
|
|
* after the class is registered with the runtime.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
long instance_size;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* Metadata describing the instance variables in this class.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
struct objc_ivar_list *ivars;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* Metadata for for defining the mappings from selectors to IMPs. Linked
|
|
|
|
* list of method list structures, one per class and one per category.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
struct objc_method_list *methods;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* The dispatch table for this class. Intialized and maintained by the
|
|
|
|
* runtime.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
void *dtable;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* A pointer to the first subclass for this class. Filled in by the
|
|
|
|
* runtime.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
struct objc_class *subclass_list;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* A pointer to the next sibling class to this. You may find all
|
|
|
|
* subclasses of a given class by following the subclass_list pointer and
|
|
|
|
* then subsequently following the sibling_class pointers in the
|
|
|
|
* subclasses.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
struct objc_class *sibling_class;
|
2010-05-13 22:29:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Metadata describing the protocols adopted by this class. Not used by
|
|
|
|
* the runtime.
|
|
|
|
*/
|
|
|
|
struct objc_protocol_list *protocols;
|
|
|
|
/**
|
2011-04-15 11:20:37 +00:00
|
|
|
* Linked list of extra data attached to this class.
|
2010-05-13 22:29:56 +00:00
|
|
|
*/
|
2011-04-17 17:31:56 +00:00
|
|
|
struct reference_list *extra_data;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* New ABI. The following fields are only available with classes compiled to
|
|
|
|
* support the new ABI. You may test whether any given class supports this
|
|
|
|
* ABI by using the CLS_ISNEW_ABI() macro.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2011-07-12 15:48:40 +00:00
|
|
|
* The version of the ABI used for this class. Zero indicates the ABI first
|
|
|
|
* implemented by clang 1.0. One indicates the presence of bitmaps
|
|
|
|
* indicating the offsets of strong, weak, and unretained ivars.
|
2010-05-13 22:29:56 +00:00
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
long abi_version;
|
2010-05-13 22:29:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of pointers to variables where the runtime will store the ivar
|
|
|
|
* offset. These may be used for faster access to non-fragile ivars if all
|
|
|
|
* of the code is compiled for the new ABI. Each of these pointers should
|
|
|
|
* have the mangled name __objc_ivar_offset_value_{class name}.{ivar name}
|
|
|
|
*
|
|
|
|
* When using the compatible non-fragile ABI, this faster form should only be
|
|
|
|
* used for classes declared in the same compilation unit.
|
|
|
|
*
|
|
|
|
* The compiler should also emit symbols of the form
|
|
|
|
* __objc_ivar_offset_{class name}.{ivar name} which are pointers to the
|
|
|
|
* offset values. These should be emitted as weak symbols in every module
|
|
|
|
* where they are used. The legacy-compatible ABI uses these with a double
|
|
|
|
* layer of indirection.
|
|
|
|
*/
|
2010-06-01 19:41:07 +00:00
|
|
|
int **ivar_offsets;
|
2010-05-13 22:29:56 +00:00
|
|
|
/**
|
|
|
|
* List of declared properties on this class (NULL if none). This contains
|
|
|
|
* the accessor methods for each property.
|
|
|
|
*/
|
|
|
|
struct objc_property_list *properties;
|
2011-07-12 15:48:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GC / ARC ABI: Fields below this point only exist if abi_version is >= 1.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The location of all strong pointer ivars declared by this class.
|
|
|
|
*
|
|
|
|
* If the low bit of this field is 0, then this is a pointer to an
|
|
|
|
* objc_bitfield structure. If the low bit is 1, then the remaining 63
|
|
|
|
* bits are set, from low to high, for each ivar in the object that is a
|
|
|
|
* strong pointer.
|
|
|
|
*/
|
2011-11-09 21:21:57 +00:00
|
|
|
intptr_t strong_pointers;
|
2011-07-12 15:48:40 +00:00
|
|
|
/**
|
|
|
|
* The location of all zeroing weak pointer ivars declared by this class.
|
|
|
|
* The format of this field is the same as the format of the
|
|
|
|
* strong_pointers field.
|
|
|
|
*/
|
2011-11-09 21:21:57 +00:00
|
|
|
intptr_t weak_pointers;
|
2010-05-13 22:29:56 +00:00
|
|
|
};
|
2011-02-22 00:31:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Structure representing the old ABI class structure. This is only ever
|
|
|
|
* required so that we can take its size - struct objc_class begins with the
|
|
|
|
* same fields, and you can test the new abi flag to tell whether it is safe to
|
|
|
|
* access the subsequent fields.
|
|
|
|
*/
|
|
|
|
struct legacy_abi_objc_class
|
|
|
|
{
|
|
|
|
struct objc_class *isa;
|
|
|
|
struct objc_class *super_class;
|
|
|
|
const char *name;
|
|
|
|
long version;
|
|
|
|
unsigned long info;
|
|
|
|
long instance_size;
|
|
|
|
struct objc_ivar_list *ivars;
|
|
|
|
struct objc_method_list *methods;
|
|
|
|
void *dtable;
|
|
|
|
struct objc_class *subclass_list;
|
|
|
|
struct objc_class *sibling_class;
|
|
|
|
struct objc_protocol_list *protocols;
|
|
|
|
void *gc_object_type;
|
|
|
|
};
|
|
|
|
|
2010-05-13 23:27:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An enumerated type describing all of the valid flags that may be used in the
|
|
|
|
* info field of a class.
|
|
|
|
*/
|
|
|
|
enum objc_class_flags
|
|
|
|
{
|
|
|
|
/** This class structure represents a class. */
|
|
|
|
objc_class_flag_class = (1<<0),
|
|
|
|
/** This class structure represents a metaclass. */
|
|
|
|
objc_class_flag_meta = (1<<1),
|
|
|
|
/**
|
|
|
|
* This class has been sent a +initalize message. This message is sent
|
|
|
|
* exactly once to every class that is sent a message by the runtime, just
|
|
|
|
* before the first other message is sent.
|
|
|
|
*/
|
|
|
|
objc_class_flag_initialized = (1<<2),
|
|
|
|
/**
|
|
|
|
* The class has been initialized by the runtime. Its super_class pointer
|
|
|
|
* should now point to a class, rather than a C string containing the class
|
|
|
|
* name, and its subclass and sibling class links will have been assigned,
|
|
|
|
* if applicable.
|
|
|
|
*/
|
|
|
|
objc_class_flag_resolved = (1<<3),
|
|
|
|
/**
|
|
|
|
* The class uses the new, Objective-C 2, runtime ABI. This ABI defines an
|
|
|
|
* ABI version field inside the class, and so will be used for all
|
|
|
|
* subsequent versions that retain some degree of compatibility.
|
|
|
|
*/
|
|
|
|
objc_class_flag_new_abi = (1<<4),
|
|
|
|
/**
|
|
|
|
* This class was created at run time and may be freed.
|
|
|
|
*/
|
|
|
|
objc_class_flag_user_created = (1<<5),
|
|
|
|
/**
|
2011-07-03 11:14:29 +00:00
|
|
|
* Instances of this class are provide ARC-safe retain / release /
|
|
|
|
* autorelease implementations.
|
2010-05-13 23:27:17 +00:00
|
|
|
*/
|
2011-07-03 11:14:29 +00:00
|
|
|
objc_class_flag_fast_arc = (1<<6),
|
2010-10-04 17:44:17 +00:00
|
|
|
/**
|
|
|
|
* This class is a hidden class (should not be registered in the class
|
|
|
|
* table nor returned from object_getClass()).
|
|
|
|
*/
|
|
|
|
objc_class_flag_hidden_class = (1<<7),
|
|
|
|
/**
|
2011-04-15 11:20:37 +00:00
|
|
|
* This class is a hidden class used to store associated values.
|
2010-10-04 17:44:17 +00:00
|
|
|
*/
|
2011-04-15 11:20:37 +00:00
|
|
|
objc_class_flag_assoc_class = (1<<8)
|
2010-05-13 23:27:17 +00:00
|
|
|
};
|
|
|
|
|
2011-07-03 11:14:29 +00:00
|
|
|
/**
|
|
|
|
* Sets the specific class flag. Note: This is not atomic.
|
|
|
|
*/
|
2010-05-13 23:27:17 +00:00
|
|
|
static inline void objc_set_class_flag(struct objc_class *aClass,
|
|
|
|
enum objc_class_flags flag)
|
|
|
|
{
|
2010-09-26 09:28:04 +00:00
|
|
|
aClass->info |= (unsigned long)flag;
|
2010-05-13 23:27:17 +00:00
|
|
|
}
|
2011-07-03 11:14:29 +00:00
|
|
|
/**
|
|
|
|
* Unsets the specific class flag. Note: This is not atomic.
|
|
|
|
*/
|
2010-06-06 21:11:25 +00:00
|
|
|
static inline void objc_clear_class_flag(struct objc_class *aClass,
|
|
|
|
enum objc_class_flags flag)
|
|
|
|
{
|
2010-09-26 09:28:04 +00:00
|
|
|
aClass->info &= ~(unsigned long)flag;
|
2010-06-06 21:11:25 +00:00
|
|
|
}
|
2011-07-03 11:14:29 +00:00
|
|
|
/**
|
|
|
|
* Checks whether a specific class flag is set.
|
|
|
|
*/
|
2010-05-13 23:27:17 +00:00
|
|
|
static inline BOOL objc_test_class_flag(struct objc_class *aClass,
|
|
|
|
enum objc_class_flags flag)
|
|
|
|
{
|
2010-09-26 09:28:04 +00:00
|
|
|
return (aClass->info & (unsigned long)flag) == (unsigned long)flag;
|
2010-05-13 23:27:17 +00:00
|
|
|
}
|
2010-06-06 21:11:25 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a class to the class table.
|
|
|
|
*/
|
|
|
|
void class_table_insert(Class class);
|
2011-07-26 17:39:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of classes used for small objects. Small objects are embedded in
|
|
|
|
* their pointer. In 32-bit mode, we have one small object class (typically
|
|
|
|
* used for storing 31-bit signed integers. In 64-bit mode then we can have 7,
|
|
|
|
* because classes are guaranteed to be word aligned.
|
|
|
|
*/
|
2011-08-14 18:04:51 +00:00
|
|
|
extern Class SmallObjectClasses[7];
|
2011-07-26 17:39:13 +00:00
|
|
|
|
2011-08-13 18:54:28 +00:00
|
|
|
static BOOL isSmallObject(id obj)
|
|
|
|
{
|
|
|
|
uintptr_t addr = ((uintptr_t)obj);
|
|
|
|
return (addr & OBJC_SMALL_OBJECT_MASK) != 0;
|
|
|
|
}
|
|
|
|
|
2011-07-26 17:39:13 +00:00
|
|
|
__attribute__((always_inline))
|
|
|
|
static inline Class classForObject(id obj)
|
|
|
|
{
|
2011-08-13 18:54:28 +00:00
|
|
|
if (UNLIKELY(isSmallObject(obj)))
|
2011-07-26 17:39:13 +00:00
|
|
|
{
|
|
|
|
if (sizeof(Class) == 4)
|
|
|
|
{
|
2011-10-23 16:07:22 +00:00
|
|
|
return SmallObjectClasses[0];
|
2011-07-26 17:39:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-13 18:54:28 +00:00
|
|
|
uintptr_t addr = ((uintptr_t)obj);
|
2011-08-14 18:04:51 +00:00
|
|
|
return SmallObjectClasses[(addr & OBJC_SMALL_OBJECT_MASK)];
|
2011-07-26 17:39:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return obj->isa;
|
|
|
|
}
|
|
|
|
|
2010-06-02 22:25:12 +00:00
|
|
|
#endif //__OBJC_CLASS_H_INCLUDED
|