mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-13 00:24:12 +00:00
A bit of a cleanup before fixing class type defs.
All internal structs now have "proper" names, and fit the naming convention (eg, obj_module (like objective-c's types, but obj instead of objc). Some redundant types got removed (holdovers from before proper struct tag handling). Also, it has proven to be unnecessary to build internal classes, so make_class and make_class_struct are gone, too.
This commit is contained in:
parent
dc22d06905
commit
c96718493a
7 changed files with 59 additions and 99 deletions
|
@ -1,7 +1,7 @@
|
||||||
#include "Object.h"
|
#include "Object.h"
|
||||||
#include "AutoreleasePool.h"
|
#include "AutoreleasePool.h"
|
||||||
|
|
||||||
void __obj_exec_class (obj_module_t *msg) = #0;
|
void __obj_exec_class (struct obj_module *msg) = #0;
|
||||||
void (id object, int code, string fmt, ...) obj_error = #0;
|
void (id object, int code, string fmt, ...) obj_error = #0;
|
||||||
void (id object, int code, string fmt, @va_list args) obj_verror = #0;
|
void (id object, int code, string fmt, @va_list args) obj_verror = #0;
|
||||||
//obj_error_handler (objc_error_handler func) obj_set_error_handler = #0;
|
//obj_error_handler (objc_error_handler func) obj_set_error_handler = #0;
|
||||||
|
|
|
@ -91,10 +91,10 @@ extern struct type_s type_SEL;
|
||||||
extern struct type_s type_IMP;
|
extern struct type_s type_IMP;
|
||||||
extern struct type_s type_supermsg;
|
extern struct type_s type_supermsg;
|
||||||
extern struct type_s type_obj_exec_class;
|
extern struct type_s type_obj_exec_class;
|
||||||
extern struct type_s type_Method;
|
extern struct type_s type_obj_method;
|
||||||
extern struct type_s type_Super;
|
extern struct type_s type_obj_super;
|
||||||
extern struct type_s type_method_description;
|
extern struct type_s type_obj_method_description;
|
||||||
extern struct type_s type_category;
|
extern struct type_s type_obj_category;
|
||||||
extern struct type_s type_ivar;
|
extern struct type_s type_ivar;
|
||||||
extern struct type_s type_module;
|
extern struct type_s type_module;
|
||||||
|
|
||||||
|
|
|
@ -67,28 +67,28 @@ static hashtab_t *category_hash;
|
||||||
static hashtab_t *protocol_hash;
|
static hashtab_t *protocol_hash;
|
||||||
|
|
||||||
// these will be built up further
|
// these will be built up further
|
||||||
type_t type_SEL = { ev_pointer, "SEL" };
|
type_t type_obj_selector = { ev_invalid, 0, ty_struct};
|
||||||
|
type_t type_SEL = { ev_pointer, "SEL", ty_none, {{&type_obj_selector}}};
|
||||||
type_t type_IMP = { ev_func, "IMP", ty_none,
|
type_t type_IMP = { ev_func, "IMP", ty_none,
|
||||||
{{&type_id, -3, {&type_id, &type_SEL}}}};
|
{{&type_id, -3, {&type_id, &type_SEL}}}};
|
||||||
type_t type_Super = { ev_invalid, "Super" };
|
type_t type_obj_super = { ev_invalid, 0 };
|
||||||
type_t type_SuperPtr = { ev_pointer, 0, ty_none, {{&type_Super}}};
|
type_t type_SuperPtr = { ev_pointer, 0, ty_none, {{&type_obj_super}}};
|
||||||
type_t type_supermsg = { ev_func, ".supermsg", ty_none,
|
type_t type_supermsg = { ev_func, ".supermsg", ty_none,
|
||||||
{{&type_id, -3, {&type_SuperPtr, &type_SEL}}}};
|
{{&type_id, -3, {&type_SuperPtr, &type_SEL}}}};
|
||||||
type_t type_Method = { ev_invalid, "Method" };
|
type_t type_obj_method = { ev_invalid, 0, ty_struct };
|
||||||
type_t type_method_description = { ev_invalid, "obj_method_description",
|
type_t type_obj_method_description = { ev_invalid, 0, ty_struct };
|
||||||
ty_struct };
|
type_t type_obj_category = { ev_invalid, 0, ty_struct};
|
||||||
type_t type_category = { ev_invalid, "category", ty_struct};
|
type_t type_obj_ivar = { ev_invalid, 0, ty_struct};
|
||||||
type_t type_ivar = { ev_invalid, "ivar", ty_struct};
|
type_t type_obj_module = { ev_invalid, 0, ty_struct};
|
||||||
type_t type_module = { ev_invalid, 0, ty_struct};
|
type_t type_moduleptr = { ev_pointer, 0, ty_none, {{&type_obj_module}}};
|
||||||
type_t type_moduleptr = { ev_pointer, 0, ty_none, {{&type_module}}};
|
|
||||||
type_t type_obj_exec_class = { ev_func, 0, ty_none,
|
type_t type_obj_exec_class = { ev_func, 0, ty_none,
|
||||||
{{&type_void, 1, { &type_moduleptr }}}};
|
{{&type_void, 1, { &type_moduleptr }}}};
|
||||||
|
|
||||||
type_t type_obj_object = {ev_invalid, "obj_object", ty_struct};
|
type_t type_obj_object = {ev_invalid, 0, ty_struct};
|
||||||
type_t type_id = { ev_pointer, "id", ty_none, {{&type_obj_object}}};
|
type_t type_id = { ev_pointer, "id", ty_none, {{&type_obj_object}}};
|
||||||
type_t type_obj_class = { ev_invalid, "obj_class", ty_struct};
|
type_t type_obj_class = { ev_invalid, 0, ty_struct};
|
||||||
type_t type_Class = { ev_pointer, 0, ty_none, {{&type_obj_class}}};
|
type_t type_Class = { ev_pointer, 0, ty_none, {{&type_obj_class}}};
|
||||||
type_t type_obj_protocol = { ev_invalid, "obj_protocol", ty_struct};
|
type_t type_obj_protocol = { ev_invalid, 0, ty_struct};
|
||||||
|
|
||||||
int obj_initialized = 0;
|
int obj_initialized = 0;
|
||||||
|
|
||||||
|
@ -141,7 +141,8 @@ static struct_def_t module_struct[] = {
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct_def_t class_ivars[] = {
|
static struct_def_t class_struct[] = {
|
||||||
|
{"class_pointer", &type_Class},
|
||||||
{"super_class", &type_Class},
|
{"super_class", &type_Class},
|
||||||
{"name", &type_string},
|
{"name", &type_string},
|
||||||
{"version", &type_integer},
|
{"version", &type_integer},
|
||||||
|
@ -157,7 +158,8 @@ static struct_def_t class_ivars[] = {
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct_def_t protocol_ivars[] = {
|
static struct_def_t protocol_struct[] = {
|
||||||
|
{"class_pointer", &type_Class},
|
||||||
{"protocol_name", &type_string},
|
{"protocol_name", &type_string},
|
||||||
{"protocol_list", &type_pointer},
|
{"protocol_list", &type_pointer},
|
||||||
{"instance_methods", &type_pointer},
|
{"instance_methods", &type_pointer},
|
||||||
|
@ -165,7 +167,7 @@ static struct_def_t protocol_ivars[] = {
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct_def_t object_ivars[] = {
|
static struct_def_t object_struct[] = {
|
||||||
{"class_pointer", &type_Class},
|
{"class_pointer", &type_Class},
|
||||||
{0, 0}
|
{0, 0}
|
||||||
};
|
};
|
||||||
|
@ -216,7 +218,7 @@ class_symbol (class_type_t *class_type, int external)
|
||||||
name = va ("_OBJ_CATEGORY_%s_%s",
|
name = va ("_OBJ_CATEGORY_%s_%s",
|
||||||
class_type->c.category->class->name,
|
class_type->c.category->class->name,
|
||||||
class_type->c.category->name);
|
class_type->c.category->name);
|
||||||
type = &type_category;
|
type = &type_obj_category;
|
||||||
break;
|
break;
|
||||||
case ct_class:
|
case ct_class:
|
||||||
name = va ("_OBJ_CLASS_%s", class_type->c.class->name);
|
name = va ("_OBJ_CLASS_%s", class_type->c.class->name);
|
||||||
|
@ -423,7 +425,7 @@ emit_ivars (symtab_t *ivars, const char *name)
|
||||||
if (s->sy_type == sy_var)
|
if (s->sy_type == sy_var)
|
||||||
ivar_data.count++;
|
ivar_data.count++;
|
||||||
}
|
}
|
||||||
ivar_list_struct[1].type = array_type (&type_ivar, ivar_data.count);
|
ivar_list_struct[1].type = array_type (&type_obj_ivar, ivar_data.count);
|
||||||
|
|
||||||
def = emit_structure (va ("_OBJ_INSTANCE_VARIABLES_%s", name), 's',
|
def = emit_structure (va ("_OBJ_INSTANCE_VARIABLES_%s", name), 's',
|
||||||
ivar_list_struct, 0, &ivar_data, st_static);
|
ivar_list_struct, 0, &ivar_data, st_static);
|
||||||
|
@ -1098,11 +1100,11 @@ class_finish_module (void)
|
||||||
free (data.classes);
|
free (data.classes);
|
||||||
free (data.categories);
|
free (data.categories);
|
||||||
|
|
||||||
module_sym = make_symbol ("_OBJ_MODULE", &type_module, pr.far_data,
|
module_sym = make_symbol ("_OBJ_MODULE", &type_obj_module, pr.far_data,
|
||||||
st_static);
|
st_static);
|
||||||
symtab_addsymbol (current_symtab, module_sym);
|
symtab_addsymbol (current_symtab, module_sym);
|
||||||
module = &D_STRUCT (pr_module_t, module_sym->s.def);
|
module = &D_STRUCT (pr_module_t, module_sym->s.def);
|
||||||
module->size = type_size (&type_module);
|
module->size = type_size (&type_obj_module);
|
||||||
EMIT_STRING (module_sym->s.def->space, module->name,
|
EMIT_STRING (module_sym->s.def->space, module->name,
|
||||||
GETSTR (pr.source_file));
|
GETSTR (pr.source_file));
|
||||||
EMIT_DEF (module_sym->s.def->space, module->symtab, symtab_def);
|
EMIT_DEF (module_sym->s.def->space, module->symtab, symtab_def);
|
||||||
|
@ -1346,97 +1348,51 @@ class_finish_ivar_scope (class_type_t *class_type, symtab_t *ivar_scope,
|
||||||
static void
|
static void
|
||||||
init_objective_structs (void)
|
init_objective_structs (void)
|
||||||
{
|
{
|
||||||
type_SEL.t.fldptr.type = make_structure (0, 's', sel_struct, 0)->type;
|
make_structure ("obj_selector", 's', sel_struct, &type_obj_selector);
|
||||||
|
chain_type (&type_obj_selector);
|
||||||
chain_type (&type_SEL);
|
chain_type (&type_SEL);
|
||||||
chain_type (&type_IMP);
|
chain_type (&type_IMP);
|
||||||
|
|
||||||
make_structure (0, 's', method_struct, &type_Method);
|
make_structure ("obj_method", 's', method_struct, &type_obj_method);
|
||||||
chain_type (&type_Method);
|
chain_type (&type_obj_method);
|
||||||
|
|
||||||
make_structure (0, 's', method_desc_struct, &type_method_description);
|
make_structure ("obj_method_description", 's', method_desc_struct,
|
||||||
chain_type (&type_method_description);
|
&type_obj_method_description);
|
||||||
|
chain_type (&type_obj_method_description);
|
||||||
|
|
||||||
make_structure (0, 's', category_struct, &type_category);
|
make_structure ("obj_category", 's', category_struct, &type_obj_category);
|
||||||
chain_type (&type_category);
|
chain_type (&type_obj_category);
|
||||||
|
|
||||||
make_structure (0, 's', ivar_struct, &type_ivar);
|
make_structure ("obj_ivar", 's', ivar_struct, &type_obj_ivar);
|
||||||
chain_type (&type_ivar);
|
chain_type (&type_obj_ivar);
|
||||||
|
|
||||||
make_structure (0, 's', super_struct, &type_Super);
|
make_structure ("obj_super", 's', super_struct, &type_obj_super);
|
||||||
chain_type (&type_Super);
|
chain_type (&type_obj_super);
|
||||||
chain_type (&type_SuperPtr);
|
chain_type (&type_SuperPtr);
|
||||||
chain_type (&type_supermsg);
|
chain_type (&type_supermsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class_t *
|
|
||||||
make_class (const char *name, struct_def_t *ivar_defs, class_t *super)
|
|
||||||
{
|
|
||||||
symbol_t *class_sym;
|
|
||||||
symtab_t *ivars;
|
|
||||||
class_t *class;
|
|
||||||
|
|
||||||
class_sym = new_symbol (name);
|
|
||||||
class = get_class (class_sym, 1);
|
|
||||||
symtab_addsymbol (pr.symtab, class_sym);
|
|
||||||
class->super_class = super;
|
|
||||||
|
|
||||||
ivars = class_new_ivars (class);
|
|
||||||
while (ivar_defs->name) {
|
|
||||||
symbol_t *iv;
|
|
||||||
iv = new_symbol_type (ivar_defs->name, ivar_defs->type);
|
|
||||||
if (!symtab_addsymbol (ivars, iv))
|
|
||||||
internal_error (0, "duplicate ivar: %s", ivar_defs->name);
|
|
||||||
ivar_defs++;
|
|
||||||
}
|
|
||||||
class_add_ivars (class, ivars);
|
|
||||||
|
|
||||||
return class;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
make_class_struct (class_t *class, type_t *type)
|
|
||||||
{
|
|
||||||
symbol_t *struct_sym;
|
|
||||||
|
|
||||||
struct_sym = find_struct ('s', new_symbol (type->name), 0);
|
|
||||||
symtab_addsymbol (pr.symtab, struct_sym);
|
|
||||||
build_struct ('s', struct_sym,
|
|
||||||
class_to_struct (class, new_symtab (0, stab_local)), type);
|
|
||||||
chain_type (type);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_classes (void)
|
init_classes (void)
|
||||||
{
|
{
|
||||||
class_t *object;
|
make_structure ("obj_class", 's', class_struct, &type_obj_class);
|
||||||
class_t *class;
|
chain_type (&type_obj_class);
|
||||||
|
|
||||||
object = make_class ("Object", object_ivars, 0);
|
|
||||||
class = make_class (".Class", class_ivars, object);
|
|
||||||
|
|
||||||
make_class_struct (class, &type_obj_class);
|
|
||||||
chain_type (&type_Class);
|
chain_type (&type_Class);
|
||||||
make_class_struct (object, &type_obj_object);
|
make_structure ("obj_object", 's', object_struct, &type_obj_object);
|
||||||
|
chain_type (&type_obj_object);
|
||||||
chain_type (&type_id);
|
chain_type (&type_id);
|
||||||
|
make_structure ("obj_protocol", 's', protocol_struct, &type_obj_protocol);
|
||||||
class = make_class ("Protocol", protocol_ivars, object);
|
chain_type (&type_obj_protocol);
|
||||||
make_class_struct (class, &type_obj_protocol);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
class_init_obj_module (void)
|
class_init_obj_module (void)
|
||||||
{
|
{
|
||||||
symbol_t *sym;
|
make_structure ("obj_module", 's', module_struct, &type_obj_module);
|
||||||
|
|
||||||
make_structure ("obj_module_s", 's', module_struct, &type_module);
|
chain_type (&type_obj_module);
|
||||||
|
|
||||||
chain_type (&type_module);
|
|
||||||
chain_type (&type_moduleptr);
|
chain_type (&type_moduleptr);
|
||||||
chain_type (&type_obj_exec_class);
|
chain_type (&type_obj_exec_class);
|
||||||
|
|
||||||
sym = new_symbol_type ("obj_module_t", &type_module);
|
|
||||||
sym->sy_type = sy_type;
|
|
||||||
symtab_addsymbol (pr.symtab, sym);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -2767,7 +2767,8 @@ super_expr (class_type_t *class_type)
|
||||||
sym = symtab_lookup (current_symtab, ".super");
|
sym = symtab_lookup (current_symtab, ".super");
|
||||||
if (!sym || sym->table != current_symtab) {
|
if (!sym || sym->table != current_symtab) {
|
||||||
sym = new_symbol (".super");
|
sym = new_symbol (".super");
|
||||||
initialize_def (sym, &type_Super, 0, current_symtab->space, st_local);
|
initialize_def (sym, &type_obj_super, 0, current_symtab->space,
|
||||||
|
st_local);
|
||||||
}
|
}
|
||||||
super = new_symbol_expr (sym);
|
super = new_symbol_expr (sym);
|
||||||
|
|
||||||
|
|
|
@ -859,6 +859,8 @@ process_loose_relocs (qfo_t *qfo)
|
||||||
}
|
}
|
||||||
if (reloc->space == qfo_type_defs - qfo->spaces) {
|
if (reloc->space == qfo_type_defs - qfo->spaces) {
|
||||||
// loose relocs in the type space become invalid
|
// loose relocs in the type space become invalid
|
||||||
|
if (reloc->type != rel_def_string)
|
||||||
|
printf ("%d\n", reloc->type);
|
||||||
reloc->type = rel_none;
|
reloc->type = rel_none;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,7 +431,7 @@ emit_methods_list_item (def_t *def, void *data, int index)
|
||||||
method_t *m;
|
method_t *m;
|
||||||
pr_method_t *meth;
|
pr_method_t *meth;
|
||||||
|
|
||||||
if (!is_array (def->type) || def->type->t.array.type != &type_Method)
|
if (!is_array (def->type) || def->type->t.array.type != &type_obj_method)
|
||||||
internal_error (0, "%s: expected array of method def",
|
internal_error (0, "%s: expected array of method def",
|
||||||
__FUNCTION__);
|
__FUNCTION__);
|
||||||
if (index < 0 || index >= methods->count)
|
if (index < 0 || index >= methods->count)
|
||||||
|
@ -487,7 +487,7 @@ emit_methods (methodlist_t *methods, const char *name, int instance)
|
||||||
methods->count = count;
|
methods->count = count;
|
||||||
methods->instance = instance;
|
methods->instance = instance;
|
||||||
|
|
||||||
methods_struct[2].type = array_type (&type_Method, count);
|
methods_struct[2].type = array_type (&type_obj_method, count);
|
||||||
return emit_structure (va ("_OBJ_%s_METHODS_%s", type, name), 's',
|
return emit_structure (va ("_OBJ_%s_METHODS_%s", type, name), 's',
|
||||||
methods_struct, 0, methods, st_static);
|
methods_struct, 0, methods, st_static);
|
||||||
}
|
}
|
||||||
|
@ -509,7 +509,7 @@ emit_method_list_item (def_t *def, void *data, int index)
|
||||||
method_t *m;
|
method_t *m;
|
||||||
pr_method_description_t *desc;
|
pr_method_description_t *desc;
|
||||||
|
|
||||||
if (def->type != &type_method_description)
|
if (def->type != &type_obj_method_description)
|
||||||
internal_error (0, "%s: expected method_descripting def",
|
internal_error (0, "%s: expected method_descripting def",
|
||||||
__FUNCTION__);
|
__FUNCTION__);
|
||||||
if (index < 0 || index >= methods->count)
|
if (index < 0 || index >= methods->count)
|
||||||
|
@ -553,7 +553,8 @@ emit_method_descriptions (methodlist_t *methods, const char *name,
|
||||||
methods->count = count;
|
methods->count = count;
|
||||||
methods->instance = instance;
|
methods->instance = instance;
|
||||||
|
|
||||||
method_list_struct[1].type = array_type (&type_method_description, count);
|
method_list_struct[1].type = array_type (&type_obj_method_description,
|
||||||
|
count);
|
||||||
return emit_structure (va ("_OBJ_%s_METHODS_%s", type, name), 's',
|
return emit_structure (va ("_OBJ_%s_METHODS_%s", type, name), 's',
|
||||||
method_list_struct, 0, methods, st_static);
|
method_list_struct, 0, methods, st_static);
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,8 +274,8 @@ static keyword_t keywords[] = {
|
||||||
{"id", TYPE, &type_id, 0, PROG_VERSION, 1},
|
{"id", TYPE, &type_id, 0, PROG_VERSION, 1},
|
||||||
{"Class", TYPE, &type_Class, 0, PROG_VERSION, 1},
|
{"Class", TYPE, &type_Class, 0, PROG_VERSION, 1},
|
||||||
// {"Protocol", TYPE, &type_Protocol, 0, PROG_VERSION, 0},
|
// {"Protocol", TYPE, &type_Protocol, 0, PROG_VERSION, 0},
|
||||||
{"Method", TYPE, &type_Method, 0, PROG_VERSION, 1},
|
{"Method", TYPE, &type_obj_method, 0, PROG_VERSION, 1},
|
||||||
{"Super", TYPE, &type_Super, 0, PROG_VERSION, 1},
|
{"Super", TYPE, &type_obj_super, 0, PROG_VERSION, 1},
|
||||||
{"SEL", TYPE, &type_SEL, 0, PROG_VERSION, 1},
|
{"SEL", TYPE, &type_SEL, 0, PROG_VERSION, 1},
|
||||||
{"IMP", TYPE, &type_IMP, 0, PROG_VERSION, 1},
|
{"IMP", TYPE, &type_IMP, 0, PROG_VERSION, 1},
|
||||||
{"local", LOCAL, 0, 2, PROG_ID_VERSION, 0},
|
{"local", LOCAL, 0, 2, PROG_ID_VERSION, 0},
|
||||||
|
|
Loading…
Reference in a new issue