From 628e3d2aed93b4cb1df86b3ce7d20667b6b655ba Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 7 Jul 2024 15:17:06 +0900 Subject: [PATCH] [qfcc] Make function type return type more clear No more guessing if that's the functions return type or something else. --- tools/qfcc/include/type.h | 2 +- tools/qfcc/source/dot_type.c | 2 +- tools/qfcc/source/expr.c | 8 ++++---- tools/qfcc/source/expr_obj.c | 2 +- tools/qfcc/source/function.c | 11 +++++++---- tools/qfcc/source/obj_type.c | 2 +- tools/qfcc/source/qp-parse.y | 4 ++-- tools/qfcc/source/statements.c | 2 +- tools/qfcc/source/type.c | 14 +++++++------- 9 files changed, 25 insertions(+), 22 deletions(-) diff --git a/tools/qfcc/include/type.h b/tools/qfcc/include/type.h index a39cd558a..5b3b3d7d4 100644 --- a/tools/qfcc/include/type.h +++ b/tools/qfcc/include/type.h @@ -36,7 +36,7 @@ #include "specifier.h" typedef struct ty_func_s { - const struct type_s *type; + const struct type_s *ret_type; int num_params; const struct type_s **param_types; union { diff --git a/tools/qfcc/source/dot_type.c b/tools/qfcc/source/dot_type.c index d5ed7d33c..45d9d37ab 100644 --- a/tools/qfcc/source/dot_type.c +++ b/tools/qfcc/source/dot_type.c @@ -82,7 +82,7 @@ print_function (dstring_t *dstr, const type_t *t, int level, int id) { int indent = level * 2 + 2; const ty_func_t *func = &t->t.func; - const type_t *ret = func->type; + const type_t *ret = func->ret_type; const type_t *param; dot_print_type (dstr, ret, level + 1, id); diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 843c90aa5..85cc50d45 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2314,7 +2314,7 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par arg_exprs[arg_expr_count - 1][0]); append_expr (call, e); } - auto ret_type = ftype->t.func.type; + auto ret_type = ftype->t.func.ret_type; call->block.result = call_expr (fexpr, args, ret_type); return call; } @@ -2429,7 +2429,7 @@ const expr_t * return_expr (function_t *f, const expr_t *e) { const type_t *t; - const type_t *ret_type = unalias_type (f->type->t.func.type); + const type_t *ret_type = unalias_type (f->type->t.func.ret_type); e = convert_name (e); if (!e) { @@ -2499,7 +2499,7 @@ return_expr (function_t *f, const expr_t *e) } else { if (ret_type != t) { e = cast_expr ((type_t *) ret_type, e);//FIXME cast - t = f->sym->type->t.func.type; + t = f->sym->type->t.func.ret_type; } } if (e->type == ex_vector) { @@ -2514,7 +2514,7 @@ return_expr (function_t *f, const expr_t *e) const expr_t * at_return_expr (function_t *f, const expr_t *e) { - const type_t *ret_type = unalias_type (f->type->t.func.type); + const type_t *ret_type = unalias_type (f->type->t.func.ret_type); if (!is_void(ret_type)) { return error (e, "use of @return in non-void function"); diff --git a/tools/qfcc/source/expr_obj.c b/tools/qfcc/source/expr_obj.c index 7ca3c7ee2..c0bc7f676 100644 --- a/tools/qfcc/source/expr_obj.c +++ b/tools/qfcc/source/expr_obj.c @@ -226,7 +226,7 @@ message_expr (const expr_t *receiver, keywordarg_t *message) return_type = &type_id; method = class_message_response (rec_type, class_msg, selector); if (method) - return_type = method->type->t.func.type; + return_type = method->type->t.func.ret_type; scoped_src_loc (receiver); expr_t *args = new_list_expr (0); diff --git a/tools/qfcc/source/function.c b/tools/qfcc/source/function.c index 6f00af5a0..a876e26d2 100644 --- a/tools/qfcc/source/function.c +++ b/tools/qfcc/source/function.c @@ -201,7 +201,7 @@ parse_params (const type_t *return_type, param_t *parms) new->alignment = 1; new->width = 1; new->columns = 1; - new->t.func.type = return_type; + new->t.func.ret_type = return_type; new->t.func.num_params = 0; for (p = parms; p; p = p->next) { @@ -405,7 +405,10 @@ find_function (const expr_t *fexpr, const expr_t *params) return fexpr; } } - type.t.func.type = ((overloaded_function_t *) funcs[0])->type->t.func.type; + { + auto f = (overloaded_function_t *) funcs[0]; + type.t.func.ret_type = f->type->t.func.ret_type; + } dummy.type = find_type (&type); qsort (funcs, func_count, sizeof (void *), func_compare); @@ -491,11 +494,11 @@ check_function (symbol_t *fsym) param_t *p; int i; - if (!type_size (fsym->type->t.func.type)) { + if (!type_size (fsym->type->t.func.ret_type)) { error (0, "return type is an incomplete type"); //fsym->type->t.func.type = &type_void;//FIXME better type? } - if (value_too_large (fsym->type->t.func.type)) { + if (value_too_large (fsym->type->t.func.ret_type)) { error (0, "return value too large to be passed by value (%d)", type_size (&type_param)); //fsym->type->t.func.type = &type_void;//FIXME better type? diff --git a/tools/qfcc/source/obj_type.c b/tools/qfcc/source/obj_type.c index f504a201d..c8c14cf09 100644 --- a/tools/qfcc/source/obj_type.c +++ b/tools/qfcc/source/obj_type.c @@ -110,7 +110,7 @@ qfo_encode_func (const type_t *type, defspace_t *space) if (param_count < 0) param_count = ~param_count; param_type_defs = alloca (param_count * sizeof (def_t *)); - return_type_def = qfo_encode_type (type->t.func.type, space); + return_type_def = qfo_encode_type (type->t.func.ret_type, space); for (i = 0; i < param_count; i++) param_type_defs[i] = qfo_encode_type (type->t.func.param_types[i], space); diff --git a/tools/qfcc/source/qp-parse.y b/tools/qfcc/source/qp-parse.y index 2960ef9af..8ceb07230 100644 --- a/tools/qfcc/source/qp-parse.y +++ b/tools/qfcc/source/qp-parse.y @@ -186,10 +186,10 @@ static symbol_t * function_value (function_t *func) { symbol_t *ret = 0; - if (func->type->t.func.type) { + if (func->type->t.func.ret_type) { ret = symtab_lookup (func->locals, ".ret"); if (!ret || ret->table != func->locals) { - ret = new_symbol_type (".ret", func->type->t.func.type); + ret = new_symbol_type (".ret", func->type->t.func.ret_type); initialize_def (ret, 0, func->locals->space, sc_local, func->locals); } diff --git a/tools/qfcc/source/statements.c b/tools/qfcc/source/statements.c index 8261772ec..974e1eb54 100644 --- a/tools/qfcc/source/statements.c +++ b/tools/qfcc/source/statements.c @@ -2627,7 +2627,7 @@ check_final_block (sblock_t *sblock) if (statement_is_return (s)) return; } - if (!is_void(current_func->sym->type->t.func.type)) + if (!is_void(current_func->sym->type->t.func.ret_type)) warning (0, "control reaches end of non-void function"); if (s && s->type >= st_func) { // func and flow end blocks, so we need to add a new block to take the diff --git a/tools/qfcc/source/type.c b/tools/qfcc/source/type.c index b5c1718b8..8189c52cc 100644 --- a/tools/qfcc/source/type.c +++ b/tools/qfcc/source/type.c @@ -309,7 +309,7 @@ free_type (type_t *type) free_type ((type_t *) type->t.fldptr.type); break; case ev_func: - free_type ((type_t *) type->t.func.type); + free_type ((type_t *) type->t.func.ret_type); break; case ev_invalid: if (type->meta == ty_array) @@ -354,8 +354,8 @@ copy_chain (type_t *type, type_t *append) type = (type_t *) type->t.fldptr.type; break; case ev_func: - n = (type_t **) &(*n)->t.func.type; - type = (type_t *) type->t.func.type; + n = (type_t **) &(*n)->t.func.ret_type; + type = (type_t *) type->t.func.ret_type; break; case ev_invalid: internal_error (0, "invalid basic type"); @@ -414,7 +414,7 @@ append_type (const type_t *type, const type_t *new) ((type_t *) type)->columns = 1; break; case ev_func: - t = (const type_t **) &(*t)->t.func.type; + t = (const type_t **) &(*t)->t.func.ret_type; ((type_t *) type)->alignment = 1; ((type_t *) type)->width = 1; ((type_t *) type)->columns = 1; @@ -557,7 +557,7 @@ find_type (const type_t *type) ((type_t *) type)->t.fldptr.type = find_type (type->t.fldptr.type); break; case ev_func: - ((type_t *) type)->t.func.type = find_type (type->t.func.type); + ((type_t *) type)->t.func.ret_type = find_type (type->t.func.ret_type); count = type->t.func.num_params; if (count < 0) count = ~count; // param count is one's complement @@ -935,7 +935,7 @@ print_type_str (dstring_t *str, const type_t *type) dasprintf (str, ")"); return; case ev_func: - print_type_str (str, type->t.func.type); + print_type_str (str, type->t.func.ret_type); if (type->t.func.num_params == -1) { dasprintf (str, "(...)"); } else { @@ -1168,7 +1168,7 @@ encode_type (dstring_t *encoding, const type_t *type) return; case ev_func: dasprintf (encoding, "("); - encode_type (encoding, type->t.func.type); + encode_type (encoding, type->t.func.ret_type); dasprintf (encoding, "%s)", encode_params (type)); return; case ev_ptr: