[qfcc] Add type_process for type functions

I'm not quite sure it's what I need, but it does help with resolving
types with complex expressions (eg, `@vector(bool,@width(vec))`).
This commit is contained in:
Bill Currie 2025-01-03 17:55:08 +09:00
parent bec8b290d2
commit ae4c107384
3 changed files with 36 additions and 2 deletions

View file

@ -1050,6 +1050,7 @@ expr_t *new_type_function (int op, const expr_t *params);
const expr_t *type_function (int op, const expr_t *params); const expr_t *type_function (int op, const expr_t *params);
symbol_t *type_parameter (symbol_t *sym, const expr_t *type); symbol_t *type_parameter (symbol_t *sym, const expr_t *type);
const type_t *resolve_type (const expr_t *te, rua_ctx_t *ctx); const type_t *resolve_type (const expr_t *te, rua_ctx_t *ctx);
const expr_t *process_type (const expr_t *te, rua_ctx_t *ctx);
const type_t **expand_type (const expr_t *te, rua_ctx_t *ctx); const type_t **expand_type (const expr_t *te, rua_ctx_t *ctx);
const expr_t *evaluate_type (const expr_t *te, rua_ctx_t *ctx); const expr_t *evaluate_type (const expr_t *te, rua_ctx_t *ctx);

View file

@ -571,8 +571,7 @@ static const expr_t *
proc_type (const expr_t *expr, rua_ctx_t *ctx) proc_type (const expr_t *expr, rua_ctx_t *ctx)
{ {
scoped_src_loc (expr); scoped_src_loc (expr);
auto type = resolve_type (expr, ctx); return process_type (expr, ctx);
return new_type_expr (type);
} }
static const expr_t * static const expr_t *

View file

@ -174,6 +174,9 @@ evaluate_int (const expr_t *expr, rua_ctx_t *ctx)
if (is_integral_val (expr)) { if (is_integral_val (expr)) {
return expr; return expr;
} }
if (expr->type != ex_type) {
internal_error (expr, "invalid type op");
}
int op = expr->typ.op; int op = expr->typ.op;
int ind = op - QC_GENERIC; int ind = op - QC_GENERIC;
auto type = expr->typ.type; auto type = expr->typ.type;
@ -744,6 +747,37 @@ resolve_type (const expr_t *te, rua_ctx_t *ctx)
return type_funcs[ind].resolve (arg_count, args, ctx); return type_funcs[ind].resolve (arg_count, args, ctx);
} }
const expr_t *
process_type (const expr_t *te, rua_ctx_t *ctx)
{
if (te->type != ex_type) {
internal_error (te, "not a type expression");
}
if (!te->typ.op) {
if (!te->typ.type) {
internal_error (te, "no type in reference");
}
return new_type_expr (te->typ.type);
}
int op = te->typ.op;
unsigned ind = op - QC_GENERIC;
if (ind >= sizeof (type_funcs) / sizeof (type_funcs[0])
|| !type_funcs[ind].name) {
internal_error (te, "invalid type op: %d", op);
}
int arg_count = list_count (&te->typ.params->list);
const expr_t *args[arg_count];
list_scatter (&te->typ.params->list, args);
if (type_funcs[ind].resolve) {
auto type = type_funcs[ind].resolve (arg_count, args, ctx);
return new_type_expr (type);
} else if (type_funcs[ind].evaluate) {
return type_funcs[ind].evaluate (arg_count, args, ctx);
} else {
internal_error (te, "invalid type op: %s", type_funcs[ind].name);
}
}
const type_t ** const type_t **
expand_type (const expr_t *te, rua_ctx_t *ctx) expand_type (const expr_t *te, rua_ctx_t *ctx)
{ {