Put newly created classes into the symbol table.

This commit is contained in:
Bill Currie 2011-02-03 15:21:09 +09:00
parent 564b7b9968
commit 79df3d2cca
3 changed files with 17 additions and 7 deletions

View file

@ -110,12 +110,14 @@ get_class_name (class_type_t *class_type, int pretty)
void
class_init (void)
{
symbol_t *sym;
class_id.type = &type_id;
class_Class.type = &type_Class;
class_Protocol.type = &type_Protocol;
class_Class.super_class = get_class (new_symbol ("Object"), 1);
class_Class.super_class = get_class (sym = new_symbol ("Object"), 1);
class_Class.methods = new_methodlist ();
symtab_addsymbol (pr.symtab, sym);
}
symbol_t *
@ -165,8 +167,10 @@ get_class (symbol_t *sym, int create)
c->methods = new_methodlist ();
c->class_type.type = ct_class;
c->class_type.c.class = c;
if (sym)
if (sym) {
Hash_Add (class_hash, c);
sym->type = c->type;
}
return c;
}

View file

@ -1135,8 +1135,11 @@ classdecl
: CLASS identifier_list ';'
{
expr_t *e;
for (e = $2->e.block.head; e; e = e->next)
for (e = $2->e.block.head; e; e = e->next) {
get_class (e->e.symbol, 1);
if (!e->e.symbol->table)
symtab_addsymbol (current_symtab, e->e.symbol);
}
}
;
@ -1144,8 +1147,8 @@ class_name
: identifier %prec CLASS_NOT_CATEGORY
{
$1 = check_undefined ($1);
if (!is_class ($1->type)) {
error (0, "`%s' is not a class", $1->name);
if (!$1->type || !is_class ($1->type)) {
error (0, "`%s' is not a class %p", $1->name, $1->type);
$$ = get_class (0, 1);
} else {
$$ = $1->type->t.class;
@ -1159,9 +1162,11 @@ new_class_name
$$ = get_class ($1, 0);
if (!$$) {
$1 = check_redefined ($1);
$$ = get_class (0, 1);
$$ = get_class ($1, 1);
}
current_class = &$$->class_type;
if (!$1->table)
symtab_addsymbol (current_symtab, $1);
}
;
@ -1252,7 +1257,7 @@ classdef
(void) ($<class>9);
}
| INTERFACE new_class_name
protocolrefs { class_add_protocols ($2, $3); }
protocolrefs { class_add_protocols ($2, $3); }
{
class_add_ivars ($2, class_new_ivars ($2));
$<class>$ = $2;

View file

@ -996,6 +996,7 @@ init_types (void)
make_structure (0, 's', method_struct, &type_Method);
type = make_structure (0, 's', class_struct, 0)->type;
type->ty = ty_class;
type_Class.t.fldptr.type = type;
class_Class.ivars = type->t.symtab;