mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-11 20:03:11 +00:00
[qfcc] Clean up function code a little
Replace struct forward declarations and some non-locally (to use) declared locals.
This commit is contained in:
parent
99caaaa010
commit
e295a62050
2 changed files with 30 additions and 33 deletions
|
@ -54,7 +54,7 @@ typedef struct overloaded_function_s {
|
|||
const char *name; ///< source level name of function
|
||||
const char *full_name; ///< progs name of function, with type
|
||||
///< encoding
|
||||
const struct type_s *type; ///< type of this function
|
||||
const type_t *type; ///< type of this function
|
||||
int overloaded; ///< is this function overloaded
|
||||
rua_loc_t loc; ///< source location of the function
|
||||
} overloaded_function_t;
|
||||
|
@ -70,12 +70,12 @@ typedef struct function_s {
|
|||
int params_start;///< relative to locals space. 0 for v6p
|
||||
pr_string_t s_file; ///< source file with definition
|
||||
pr_string_t s_name; ///< name of function in output
|
||||
const struct type_s *type; ///< function's type without aliases
|
||||
const type_t *type; ///< function's type without aliases
|
||||
int temp_reg; ///< base register to use for temp defs
|
||||
int temp_num; ///< number for next temp var
|
||||
struct def_s *temp_defs[MAX_DEF_SIZE];///< freed temp vars (by size)
|
||||
struct def_s *def; ///< output def holding function number
|
||||
struct symbol_s *sym; ///< internal symbol for this function
|
||||
symbol_t *sym; ///< internal symbol for this function
|
||||
/** \name Local data space
|
||||
|
||||
The function parameters form the root scope for the function. Its
|
||||
|
@ -98,13 +98,13 @@ typedef struct function_s {
|
|||
parameters will be merged into the one defspace.
|
||||
*/
|
||||
///@{
|
||||
struct symtab_s *parameters; ///< Root scope symbol table
|
||||
struct symtab_s *locals; ///< Actual local variables
|
||||
symtab_t *parameters; ///< Root scope symbol table
|
||||
symtab_t *locals; ///< Actual local variables
|
||||
struct defspace_s *arguments; ///< Space for called function arguments
|
||||
///@}
|
||||
struct symtab_s *label_scope;
|
||||
symtab_t *label_scope;
|
||||
struct reloc_s *refs; ///< relocation targets for this function
|
||||
struct expr_s *var_init;
|
||||
expr_t *var_init;
|
||||
const char *name; ///< nice name for __PRETTY_FUNCTION__
|
||||
struct sblock_s *sblock; ///< initial node of function's code
|
||||
struct flowgraph_s *graph; ///< the function's flow graph
|
||||
|
@ -145,38 +145,35 @@ typedef struct expr_s expr_t;
|
|||
typedef struct symbol_s symbol_t;
|
||||
typedef struct symtab_s symtab_t;
|
||||
|
||||
param_t *new_param (const char *selector, const struct type_s *type,
|
||||
const char *name);
|
||||
param_t *new_param (const char *selector, const type_t *type, const char *name);
|
||||
param_t *new_generic_param (const expr_t *type_expr, const char *name);
|
||||
param_t *param_append_identifiers (param_t *params, struct symbol_s *idents,
|
||||
const struct type_s *type);
|
||||
const type_t *type);
|
||||
param_t *reverse_params (param_t *params);
|
||||
param_t *append_params (param_t *params, param_t *more_params);
|
||||
param_t *copy_params (param_t *params);
|
||||
const struct type_s *parse_params (const struct type_s *return_type, param_t *params);
|
||||
const type_t *parse_params (const type_t *return_type, param_t *params);
|
||||
|
||||
param_t *check_params (param_t *params);
|
||||
|
||||
enum storage_class_e;
|
||||
struct defspace_s;
|
||||
int value_too_large (const struct type_s *val_type) __attribute__((pure));
|
||||
void make_function (struct symbol_s *sym, const char *nice_name,
|
||||
int value_too_large (const type_t *val_type) __attribute__((pure));
|
||||
void make_function (symbol_t *sym, const char *nice_name,
|
||||
struct defspace_s *space, enum storage_class_e storage);
|
||||
symbol_t *function_symbol (symbol_t *sym, int overload);
|
||||
const struct expr_s *find_function (const struct expr_s *fexpr,
|
||||
const struct expr_s *params);
|
||||
const expr_t *find_function (const expr_t *fexpr, const expr_t *params);
|
||||
function_t *new_function (const char *name, const char *nice_name);
|
||||
void add_function (function_t *f);
|
||||
function_t *begin_function (struct symbol_s *sym, const char *nicename,
|
||||
struct symtab_s *parent, int far,
|
||||
function_t *begin_function (symbol_t *sym, const char *nicename,
|
||||
symtab_t *parent, int far,
|
||||
enum storage_class_e storage);
|
||||
function_t *build_code_function (struct symbol_s *fsym,
|
||||
const struct expr_s *state_expr,
|
||||
struct expr_s *statements);
|
||||
function_t *build_builtin_function (struct symbol_s *sym,
|
||||
const struct expr_s *bi_val, int far,
|
||||
function_t *build_code_function (symbol_t *fsym,
|
||||
const expr_t *state_expr, expr_t *statements);
|
||||
function_t *build_builtin_function (symbol_t *sym,
|
||||
const expr_t *bi_val, int far,
|
||||
enum storage_class_e storage);
|
||||
void emit_function (function_t *f, struct expr_s *e);
|
||||
void emit_function (function_t *f, expr_t *e);
|
||||
int function_parms (function_t *f, byte *parm_size);
|
||||
void clear_functions (void);
|
||||
|
||||
|
|
|
@ -189,7 +189,6 @@ parse_params (const type_t *return_type, param_t *parms)
|
|||
{
|
||||
param_t *p;
|
||||
type_t *new;
|
||||
type_t *ptype;
|
||||
int count = 0;
|
||||
|
||||
if (return_type && is_class (return_type)) {
|
||||
|
@ -223,7 +222,7 @@ parse_params (const type_t *return_type, param_t *parms)
|
|||
error (0, "cannot use an object as a parameter (forgot *?)");
|
||||
p->type = &type_id;
|
||||
}
|
||||
ptype = (type_t *) unalias_type (p->type); //FIXME cast
|
||||
auto ptype = unalias_type (p->type);
|
||||
new->t.func.param_types[new->t.func.num_params] = ptype;
|
||||
new->t.func.num_params++;
|
||||
}
|
||||
|
@ -367,8 +366,8 @@ set_func_symbol (const expr_t *fexpr, overloaded_function_t *f)
|
|||
const expr_t *
|
||||
find_function (const expr_t *fexpr, const expr_t *params)
|
||||
{
|
||||
int i, j, func_count, parm_count, reported = 0;
|
||||
overloaded_function_t *f, dummy, *best = 0;
|
||||
int func_count, parm_count, reported = 0;
|
||||
overloaded_function_t dummy, *best = 0;
|
||||
type_t type = {};
|
||||
void **funcs, *dummy_p = &dummy;
|
||||
|
||||
|
@ -400,7 +399,7 @@ find_function (const expr_t *fexpr, const expr_t *params)
|
|||
for (func_count = 0; funcs[func_count]; func_count++)
|
||||
;
|
||||
if (func_count < 2) {
|
||||
f = (overloaded_function_t *) funcs[0];
|
||||
auto f = (overloaded_function_t *) funcs[0];
|
||||
if (func_count && !f->overloaded) {
|
||||
free (funcs);
|
||||
return fexpr;
|
||||
|
@ -415,15 +414,15 @@ find_function (const expr_t *fexpr, const expr_t *params)
|
|||
dummy_p = bsearch (&dummy_p, funcs, func_count, sizeof (void *),
|
||||
func_compare);
|
||||
if (dummy_p) {
|
||||
f = (overloaded_function_t *) *(void **) dummy_p;
|
||||
auto f = (overloaded_function_t *) *(void **) dummy_p;
|
||||
if (f->overloaded) {
|
||||
fexpr = set_func_symbol (fexpr, f);
|
||||
}
|
||||
free (funcs);
|
||||
return fexpr;
|
||||
}
|
||||
for (i = 0; i < func_count; i++) {
|
||||
f = (overloaded_function_t *) funcs[i];
|
||||
for (int i = 0; i < func_count; i++) {
|
||||
auto f = (overloaded_function_t *) funcs[i];
|
||||
parm_count = f->type->t.func.num_params;
|
||||
if ((parm_count >= 0 && parm_count != type.t.func.num_params)
|
||||
|| (parm_count < 0 && ~parm_count > type.t.func.num_params)) {
|
||||
|
@ -432,6 +431,7 @@ find_function (const expr_t *fexpr, const expr_t *params)
|
|||
}
|
||||
if (parm_count < 0)
|
||||
parm_count = ~parm_count;
|
||||
int j;
|
||||
for (j = 0; j < parm_count; j++) {
|
||||
if (!type_assignable (f->type->t.func.param_types[j],
|
||||
type.t.func.param_types[j])) {
|
||||
|
@ -442,8 +442,8 @@ find_function (const expr_t *fexpr, const expr_t *params)
|
|||
if (j < parm_count)
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < func_count; i++) {
|
||||
f = (overloaded_function_t *) funcs[i];
|
||||
for (int i = 0; i < func_count; i++) {
|
||||
auto f = (overloaded_function_t *) funcs[i];
|
||||
if (f) {
|
||||
if (!best) {
|
||||
best = f;
|
||||
|
|
Loading…
Reference in a new issue