mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-08 10:21:40 +00:00
[qfcc] Make function type return type more clear
No more guessing if that's the functions return type or something else.
This commit is contained in:
parent
c681d3ee28
commit
628e3d2aed
9 changed files with 25 additions and 22 deletions
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue