[qfcc] Rearrange type initialization

Fixes #6
It turned out that the problem with @zero was caused by initial type
chaining occurring before the structures had been initialized and thus
the linker's @zero type encoding string was incorrect: {?=} instead of
{tag @zero-}, thus when the actual type encoding supplied by an object
file came along (with the correct encoding string), it wasn't found.
This commit is contained in:
Bill Currie 2020-03-28 22:53:35 +09:00
parent 31ea3814bb
commit c13162e41e
2 changed files with 56 additions and 42 deletions

View file

@ -181,7 +181,6 @@ InitData (void)
clear_classes ();
clear_immediates ();
clear_selectors ();
chain_initial_types ();
}
static int
@ -384,6 +383,7 @@ compile_to_obj (const char *file, const char *obj, lang_t lang)
return !options.preprocess_only;
InitData ();
chain_initial_types ();
begin_compilation ();
pr.source_file = ReuseString (strip_path (file));
err = yyparse () || pr.error_count;
@ -549,6 +549,7 @@ separate_compile (void)
dstring_delete (extension);
if (!err && !options.compile) {
InitData ();
chain_initial_types ();
linker_begin ();
for (file = source_files; *file; file++) {
if (strncmp (*file, "-l", 2)) {
@ -726,6 +727,7 @@ progs_src_compile (void)
setup_sym_file (options.output_file);
InitData ();
chain_initial_types ();
begin_compilation ();
@ -830,6 +832,7 @@ main (int argc, char **argv)
parse_cpp_name ();
opcode_init ();
InitData ();
init_types ();
clear_immediates ();

View file

@ -1075,6 +1075,47 @@ type_size (const type_t *type)
return 0;
}
static void
chain_basic_types (void)
{
chain_type (&type_void);
chain_type (&type_string);
chain_type (&type_float);
chain_type (&type_vector);
type_entity.t.symtab = pr.entity_fields;
chain_type (&type_entity);
chain_type (&type_field);
chain_type (&type_function);
chain_type (&type_pointer);
chain_type (&type_floatfield);
if (!options.traditional) {
chain_type (&type_quaternion);
chain_type (&type_integer);
chain_type (&type_uinteger);
chain_type (&type_short);
chain_type (&type_double);
}
}
static void
chain_structural_types (void)
{
chain_type (&type_param);
chain_type (&type_zero);
chain_type (&type_type_encodings);
chain_type (&type_xdef);
chain_type (&type_xdef_pointer);
chain_type (&type_xdefs);
chain_type (&type_va_list);
}
void
chain_initial_types (void)
{
chain_basic_types ();
chain_structural_types ();
}
void
init_types (void)
{
@ -1136,6 +1177,13 @@ init_types (void)
{"num_xdefs", &type_pointer},
{0, 0}
};
static struct_def_t va_list_struct[] = {
{"count", &type_integer},
{"list", 0}, // type will be filled in at runtime
{0, 0}
};
chain_basic_types ();
type_nil = &type_quaternion;
type_default = &type_integer;
@ -1160,8 +1208,8 @@ init_types (void)
make_structure ("@xdef", 's', xdef_struct, &type_xdef);
make_structure ("@xdefs", 's', xdefs_struct, &type_xdefs);
if (options.traditional)
return;
va_list_struct[1].type = pointer_type (&type_param);
make_structure ("@va_list", 's', va_list_struct, &type_va_list);
make_structure ("@quaternion", 's', quaternion_struct, &type_quaternion);
type_quaternion.type = ev_quat;
@ -1181,43 +1229,6 @@ init_types (void)
sym->s.offset = 3;
symtab_addsymbol (type_quaternion.t.symtab, sym);
}
}
void
chain_initial_types (void)
{
static struct_def_t va_list_struct[] = {
{"count", &type_integer},
{"list", 0}, // type will be filled in at runtime
{0, 0}
};
chain_type (&type_void);
chain_type (&type_string);
chain_type (&type_float);
chain_type (&type_vector);
type_entity.t.symtab = pr.entity_fields;
chain_type (&type_entity);
chain_type (&type_field);
chain_type (&type_function);
chain_type (&type_pointer);
chain_type (&type_floatfield);
if (!options.traditional) {
chain_type (&type_quaternion);
chain_type (&type_integer);
chain_type (&type_uinteger);
chain_type (&type_short);
chain_type (&type_double);
}
chain_type (&type_param);
chain_type (&type_zero);
chain_type (&type_type_encodings);
chain_type (&type_xdef);
chain_type (&type_xdef_pointer);
chain_type (&type_xdefs);
va_list_struct[1].type = pointer_type (&type_param);
make_structure ("@va_list", 's', va_list_struct, &type_va_list);
chain_type (&type_va_list);
chain_structural_types ();
}