mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-26 10:11:03 +00:00
(behavior_class_add_class): Function renamed from class_add_behavior.
Add more explanation to NSCAssert(). (class_add_behavior): New function, calling above function. (behavior_class_add_category): New function. (behavior_class_add_methods): Function renamed from class_add_methods_if_not_there. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@1325 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ff771f9d6b
commit
c20c905fe0
1 changed files with 35 additions and 13 deletions
|
@ -25,8 +25,8 @@
|
||||||
"Class without any instance variables". A key feature of behaviors
|
"Class without any instance variables". A key feature of behaviors
|
||||||
is that they give a degree of multiple inheritance.
|
is that they give a degree of multiple inheritance.
|
||||||
|
|
||||||
Behavior methods override the class's superclass methods, but not
|
Behavior methods, when added to a class, override the class's
|
||||||
the class's methods.
|
superclass methods, but not the class's methods.
|
||||||
|
|
||||||
xxx not necessarily on the "no instance vars". The behavior just has
|
xxx not necessarily on the "no instance vars". The behavior just has
|
||||||
to have the same layout as the class.
|
to have the same layout as the class.
|
||||||
|
@ -49,6 +49,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <objects/stdobjects.h>
|
#include <objects/stdobjects.h>
|
||||||
|
#include <objects/behavior.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
|
|
||||||
|
@ -64,8 +65,6 @@ static void __objc_class_add_protocols (Class class,
|
||||||
static BOOL class_is_kind_of(Class self, Class class);
|
static BOOL class_is_kind_of(Class self, Class class);
|
||||||
static void check_class_methods(Class class);
|
static void check_class_methods(Class class);
|
||||||
|
|
||||||
void class_add_methods_if_not_there(Class class, Class behavior);
|
|
||||||
|
|
||||||
/* The uninstalled dispatch table, declared in gcc/objc/sendmsg.c. */
|
/* The uninstalled dispatch table, declared in gcc/objc/sendmsg.c. */
|
||||||
extern struct sarray* __objc_uninstalled_dtable;
|
extern struct sarray* __objc_uninstalled_dtable;
|
||||||
|
|
||||||
|
@ -73,13 +72,13 @@ extern struct sarray* __objc_uninstalled_dtable;
|
||||||
but, I think it will be slower than the current method. */
|
but, I think it will be slower than the current method. */
|
||||||
|
|
||||||
void
|
void
|
||||||
set_behavior_debug(int i)
|
behavior_set_debug(int i)
|
||||||
{
|
{
|
||||||
behavior_debug = i;
|
behavior_debug = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
class_add_behavior (Class class, Class behavior)
|
behavior_class_add_class (Class class, Class behavior)
|
||||||
{
|
{
|
||||||
Class behavior_super_class = class_get_super_class(behavior);
|
Class behavior_super_class = class_get_super_class(behavior);
|
||||||
|
|
||||||
|
@ -98,7 +97,8 @@ class_add_behavior (Class class, Class behavior)
|
||||||
@"have subclassed the class. There are two solutions:\n"
|
@"have subclassed the class. There are two solutions:\n"
|
||||||
@"(1) Don't subclass it; (2) Add placeholder instance\n"
|
@"(1) Don't subclass it; (2) Add placeholder instance\n"
|
||||||
@"variables to the class, so the behavior-addition code\n"
|
@"variables to the class, so the behavior-addition code\n"
|
||||||
@"will not have to increase the instance size.");
|
@"will not have to increase the instance size, (see\n"
|
||||||
|
@"Foundation/NSNotification.h for a clean way to do this).");
|
||||||
class->instance_size = behavior->instance_size;
|
class->instance_size = behavior->instance_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ class_add_behavior (Class class, Class behavior)
|
||||||
fprintf(stderr, "Adding instance methods from %s\n",
|
fprintf(stderr, "Adding instance methods from %s\n",
|
||||||
behavior->name);
|
behavior->name);
|
||||||
}
|
}
|
||||||
class_add_methods_if_not_there(class, behavior);
|
behavior_class_add_methods (class, behavior->methods);
|
||||||
|
|
||||||
/* Add class methods */
|
/* Add class methods */
|
||||||
if (behavior_debug)
|
if (behavior_debug)
|
||||||
|
@ -126,20 +126,42 @@ class_add_behavior (Class class, Class behavior)
|
||||||
fprintf(stderr, "Adding class methods from %s\n",
|
fprintf(stderr, "Adding class methods from %s\n",
|
||||||
behavior->class_pointer->name);
|
behavior->class_pointer->name);
|
||||||
}
|
}
|
||||||
class_add_methods_if_not_there(class->class_pointer,
|
behavior_class_add_methods (class->class_pointer,
|
||||||
behavior->class_pointer);
|
behavior->class_pointer->methods);
|
||||||
|
|
||||||
/* Add behavior's superclass, if not already there. */
|
/* Add behavior's superclass, if not already there. */
|
||||||
{
|
{
|
||||||
if (!class_is_kind_of(class, behavior_super_class))
|
if (!class_is_kind_of(class, behavior_super_class))
|
||||||
class_add_behavior(class, behavior_super_class);
|
behavior_class_add_class (class, behavior_super_class);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* The old interface */
|
||||||
void
|
void
|
||||||
class_add_methods_if_not_there(Class class, Class behavior)
|
class_add_behavior (Class class, Class behavior)
|
||||||
|
{
|
||||||
|
behavior_class_add_class (class, behavior);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Need objc_lookup_class_category (const char *class_name
|
||||||
|
const char *category_name)
|
||||||
|
*/
|
||||||
|
|
||||||
|
void
|
||||||
|
behavior_class_add_category (Class class, struct objc_category *category)
|
||||||
|
{
|
||||||
|
behavior_class_add_methods (class,
|
||||||
|
category->instance_methods);
|
||||||
|
behavior_class_add_methods (class->class_pointer,
|
||||||
|
category->class_methods);
|
||||||
|
/* xxx Add the protocols (category->protocols) too. */
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
behavior_class_add_methods (Class class,
|
||||||
|
struct objc_method_list *methods)
|
||||||
{
|
{
|
||||||
static SEL initialize_sel = 0;
|
static SEL initialize_sel = 0;
|
||||||
MethodList_t mlist;
|
MethodList_t mlist;
|
||||||
|
@ -148,7 +170,7 @@ class_add_methods_if_not_there(Class class, Class behavior)
|
||||||
initialize_sel = sel_register_name ("initialize");
|
initialize_sel = sel_register_name ("initialize");
|
||||||
|
|
||||||
/* Add methods to class->dtable and class->methods */
|
/* Add methods to class->dtable and class->methods */
|
||||||
for (mlist = behavior->methods; mlist; mlist = mlist->method_next)
|
for (mlist = methods; mlist; mlist = mlist->method_next)
|
||||||
{
|
{
|
||||||
int counter;
|
int counter;
|
||||||
MethodList_t new_list;
|
MethodList_t new_list;
|
||||||
|
|
Loading…
Reference in a new issue