Add some missing protocol introspection functions.

main
theraven 16 years ago
parent 52bdf1484f
commit 77d02d075b

@ -81,6 +81,19 @@ typedef void *objc_property_t;
typedef struct objc_protocol Protocol;
#endif
struct objc_method_description
{
/**
* The name of this method.
*/
SEL name;
/**
* The types of this method.
*/
const char *types;
};
#ifndef YES
#define YES ((BOOL)1)
#endif

@ -267,13 +267,68 @@ BOOL class_conformsToProtocol(Class cls, Protocol *protocol)
struct objc_method_description *protocol_copyMethodDescriptionList(Protocol *p,
BOOL isRequiredMethod, BOOL isInstanceMethod, unsigned int *count)
{
static id protocol2 = NULL;
if (NULL == protocol2)
{
protocol2 = objc_getClass("Protocol2");
}
struct objc_method_description_list *list;
*count = 0;
return NULL;
if (isRequiredMethod)
{
if (isInstanceMethod)
{
list = p->instance_methods;
}
else
{
list = p->class_methods;
}
}
else
{
if (p->isa != protocol2) { return NULL; }
if (isInstanceMethod)
{
list = ((Protocol2*)p)->optional_instance_methods;
}
else
{
list = ((Protocol2*)p)->optional_class_methods;
}
}
if (NULL == list || list->count == 0) { return NULL; }
*count = list->count;
struct objc_method_description *out =
calloc(sizeof(struct objc_method_description_list), list->count);
for (int i=0 ; i<list->count ; i++)
{
out[i].name = sel_registerTypedName_np(list->methods[i].name,
list->methods[i].types);
out[i].types = list->methods[i].types;
}
return out;
}
Protocol **protocol_copyProtocolList(Protocol *p, unsigned int *count)
{
*count = 0;
if (p->protocol_list == NULL || p->protocol_list->count ==0)
{
return NULL;
}
Protocol **out = calloc(sizeof(Protocol*), p->protocol_list->count);
for (int i=0 ; i<p->protocol_list->count ; i++)
{
out[i] = (Protocol*)p->protocol_list->list[i];
}
return NULL;
}

Loading…
Cancel
Save