fix type of "self"

This is an imperfect revision of history.
This commit is contained in:
Bill Currie 2004-11-02 07:13:00 +00:00 committed by Jeff Teunissen
parent a4dbdb4d06
commit a3a2dd62e3
5 changed files with 45 additions and 9 deletions

View file

@ -24,16 +24,16 @@ integer deathmatch;
local integer i;
self = [super init];
self.head = NIL;
head = NIL;
for (i = 0; i < MAX_BODIES; i++) {
local GameEntity ent = NIL;
ent = [[GameEntity alloc] init];
self.bodies[i] = ent.ent;
bodies[i] = ent.ent;
}
#if 0
for (i = 0; i < MAX_BODIES; i++) {
self.bodies[i] = [[[GameEntity alloc] init] ent];
bodies[i] = [[[GameEntity alloc] init] ent];
}
#endif
}

View file

@ -137,17 +137,35 @@ get_class (const char *name, int create)
return c;
}
static void
set_self_type (class_t *class, method_t *method)
{
if (method->instance)
method->params->type = class->type;
else
method->params->type = &type_Class;
}
static void
methods_set_self_type (class_t *class, methodlist_t *methods)
{
method_t *method;
for (method = methods->head; method; method = method->next)
set_self_type (class, method);
}
void
class_add_methods (class_t *class, methodlist_t *methods)
{
if (!methods)
return;
if (!class->methods)
class->methods = new_methodlist ();
*class->methods->tail = methods->head;
class->methods->tail = methods->tail;
free (methods);
methods_set_self_type (class, class->methods);
}
void

View file

@ -284,6 +284,12 @@ type_mismatch (expr_t *e1, expr_t *e2, int op)
t1 = extract_type (e1);
t2 = extract_type (e2);
if (1) {
print_type (get_type (e1));
print_type (get_type (e2));
printf ("\n%p %p\n", get_type (e1), get_type (e2));
}
return error (e1, "type mismatch: %s %s %s",
pr_type_name[t1], get_op_string (op), pr_type_name[t2]);
}

View file

@ -1401,14 +1401,11 @@ methodproto
: '+' methoddecl ';'
{
$2->instance = 0;
$2->params->type = &type_Class;
$$ = $2;
}
| '-' methoddecl ';'
{
$2->instance = 1;
if ($<class>-1)
$2->params->type = $<class>-1->type;
$$ = $2;
}
;

View file

@ -1,10 +1,25 @@
@interface Foo : Object
{
integer x;
}
-run;
@end
@implementation Foo
+alloc
{
print ("+alloc\n");
return class_create_instance (self);
}
-init
{
print ("-init\n");
return [super init];
}
+ (void) initialize
{
print ("+initialize\n");
@ -13,7 +28,7 @@
-run
{
print ("Hello world\n");
printf ("%i\n", self);
printf ("%i %p\n", self, &self.x);
}
@end