Update naming of enum const.

This commit is contained in:
Christoffer Lerno
2025-03-10 00:15:50 +01:00
parent 25bccf4883
commit ff75f2c21f
13 changed files with 37 additions and 37 deletions

View File

@@ -155,7 +155,7 @@ typedef struct
} bytes;
Expr *expr_ref;
Decl *global_ref;
Decl *enum_err_val;
Decl *enum_val;
Decl *fault;
Type *typeid;
ConstInitializer *initializer;

View File

@@ -266,7 +266,7 @@ INLINE Expr *copy_const_expr(CopyStruct *c, Expr *expr)
fixup_decl(c, &expr->const_expr.fault);
break;
case CONST_ENUM:
fixup_decl(c, &expr->const_expr.enum_err_val);
fixup_decl(c, &expr->const_expr.enum_val);
break;
case CONST_BYTES:
case CONST_STRING:

View File

@@ -139,7 +139,7 @@ bool expr_is_zero(Expr *expr)
case CONST_BOOL:
return !expr->const_expr.b;
case CONST_ENUM:
return !expr->const_expr.enum_err_val->enum_constant.ordinal;
return !expr->const_expr.enum_val->enum_constant.ordinal;
case CONST_BYTES:
case CONST_STRING:
{
@@ -652,7 +652,7 @@ void expr_rewrite_to_const_zero(Expr *expr, Type *type)
case TYPE_ENUM:
expr->const_expr.const_kind = CONST_ENUM;
ASSERT(canonical->decl->resolve_status == RESOLVE_DONE);
expr->const_expr.enum_err_val = canonical->decl->enums.values[0];
expr->const_expr.enum_val = canonical->decl->enums.values[0];
expr->resolve_status = RESOLVE_DONE;
break;
case TYPE_FUNC_RAW:

View File

@@ -650,7 +650,7 @@ static void header_gen_global_var(HeaderContext *c, Decl *decl, bool fn_globals,
PRINTF("\"\n");
return;
case CONST_ENUM:
PRINTF("%s\n", decl_get_extname(init->const_expr.enum_err_val));
PRINTF("%s\n", decl_get_extname(init->const_expr.enum_val));
return;
case CONST_FAULT:
PRINTF("%s\n", decl_get_extname(init->const_expr.fault));

View File

@@ -4752,7 +4752,7 @@ static void llvm_emit_const_expr(GenContext *c, BEValue *be_value, Expr *expr)
return;
}
case CONST_ENUM:
llvm_value_set(be_value, llvm_const_int(c, type, expr->const_expr.enum_err_val->enum_constant.ordinal), type);
llvm_value_set(be_value, llvm_const_int(c, type, expr->const_expr.enum_val->enum_constant.ordinal), type);
return;
case CONST_MEMBER:
case CONST_UNTYPED_LIST:

View File

@@ -794,10 +794,10 @@ static void llvm_set_jump_table_values(ExprId from, ExprId to, Int *from_ref, In
if (type_flat->type_kind == TYPE_ENUM)
{
Type *low = type_lowering(type_flat);
*from_ref = (Int) { .i.low = from_expr->const_expr.enum_err_val->enum_constant.ordinal, .type = low->type_kind };
*from_ref = (Int) { .i.low = from_expr->const_expr.enum_val->enum_constant.ordinal, .type = low->type_kind };
if (to)
{
*to_ref = (Int) { .i.low = to_expr->const_expr.enum_err_val->enum_constant.ordinal, .type = low->type_kind };
*to_ref = (Int) { .i.low = to_expr->const_expr.enum_val->enum_constant.ordinal, .type = low->type_kind };
}
else
{

View File

@@ -168,13 +168,13 @@ bool expr_const_compare(const ExprConst *left, const ExprConst *right, BinaryOp
goto RETURN;
case CONST_ENUM:
{
Decl *left_decl = left->enum_err_val;
Decl *left_decl = left->enum_val;
// The error case
ASSERT(right->const_kind == left->const_kind);
Decl *right_decl = right->enum_err_val;
Decl *right_decl = right->enum_val;
// Non-matching cannot be compared.
if (right_decl->type != left_decl->type) return false;
int64_t right_ordinal = right->enum_err_val->enum_constant.ordinal;
int64_t right_ordinal = right->enum_val->enum_constant.ordinal;
switch (op)
{
case BINARYOP_GT:
@@ -273,7 +273,7 @@ bool expr_const_will_overflow(const ExprConst *expr, TypeKind kind)
return false;
case CONST_ENUM:
{
Int i = { .i = { .low = expr->enum_err_val->var.index }, .type = type_flatten(expr->enum_err_val->type)->type_kind };
Int i = { .i = { .low = expr->enum_val->var.index }, .type = type_flatten(expr->enum_val->type)->type_kind };
return !int_fits(i, kind);
}
case CONST_FAULT:
@@ -315,7 +315,7 @@ const char *expr_const_to_error_string(const ExprConst *expr)
case CONST_FAULT:
return expr->fault->name;
case CONST_ENUM:
return expr->enum_err_val->name;
return expr->enum_val->name;
case CONST_TYPEID:
return type_to_error_string(expr->typeid);
case CONST_MEMBER:

View File

@@ -507,7 +507,7 @@ static bool sema_error_const_int_out_of_range(CastContext *cc, Expr *expr, Expr
if (expr->const_expr.const_kind == CONST_ENUM)
{
RETURN_CAST_ERROR(problem, "The ordinal '%d' is out of range for %s, so you need an explicit cast to truncate the value.",
expr->const_expr.enum_err_val->var.index,
expr->const_expr.enum_val->var.index,
type_quoted_error_string(to_type));
}
const char *error_value = expr->const_expr.is_hex ? int_to_str(expr->const_expr.ixx, 16, true)
@@ -1707,7 +1707,7 @@ static void cast_enum_to_value(Expr* expr, Type *to_type)
}
if (expr_is_const_enum(expr))
{
expr_replace(expr, copy_expr_single(expr->const_expr.enum_err_val->enum_constant.args[decl->enums.inline_index]));
expr_replace(expr, copy_expr_single(expr->const_expr.enum_val->enum_constant.args[decl->enums.inline_index]));
if (expr->type != to_type)
{
cast_no_check(expr, to_type, false);
@@ -1886,7 +1886,7 @@ static void cast_anyfault_to_fault(Expr *expr, Type *type)
return;
}
ASSERT(expr_is_const_fault(expr));
Decl *value = expr->const_expr.enum_err_val;
Decl *value = expr->const_expr.enum_val;
ASSERT(value->type != type);
expr->type = type;
}

View File

@@ -4349,7 +4349,7 @@ static bool sema_generate_parameterized_name_to_scratch(SemaContext *context, Mo
}
else if (type->type_kind == TYPE_ENUM)
{
Decl *enumm = param->const_expr.enum_err_val;
Decl *enumm = param->const_expr.enum_val;
type_mangle_introspect_name_to_buffer(enumm->type->canonical);
scratch_buffer_append(mangled ? "_" : ":");
scratch_buffer_append(enumm->name);

View File

@@ -284,10 +284,10 @@ Expr *sema_enter_inline_member(Expr *parent, CanonicalType *type)
if (decl->enums.inline_value)
{
expr = expr_new_expr(EXPR_CONST, parent);
expr_rewrite_const_int(expr, decl->enums.type_info->type, parent->const_expr.enum_err_val->enum_constant.ordinal);
expr_rewrite_const_int(expr, decl->enums.type_info->type, parent->const_expr.enum_val->enum_constant.ordinal);
return expr;
}
expr = copy_expr_single(parent->const_expr.enum_err_val->enum_constant.args[decl->enums.inline_index]);
expr = copy_expr_single(parent->const_expr.enum_val->enum_constant.args[decl->enums.inline_index]);
break;
}
if (decl->enums.inline_value)
@@ -993,7 +993,7 @@ static inline bool sema_expr_analyse_enum_constant(SemaContext *context, Expr *e
expr->expr_kind = EXPR_CONST;
expr->const_expr.const_kind = CONST_ENUM;
expr->const_expr.enum_err_val = enum_constant;
expr->const_expr.enum_val = enum_constant;
expr->resolve_status = RESOLVE_DONE;
return true;
}
@@ -2526,7 +2526,7 @@ void sema_expr_convert_enum_to_int(Expr *expr)
if (sema_cast_const(expr))
{
ASSERT(expr->const_expr.const_kind == CONST_ENUM);
expr_rewrite_const_int(expr, underlying_type, expr->const_expr.enum_err_val->enum_constant.ordinal);
expr_rewrite_const_int(expr, underlying_type, expr->const_expr.enum_val->enum_constant.ordinal);
}
if (expr->expr_kind == EXPR_ENUM_FROM_ORD)
{
@@ -2600,7 +2600,7 @@ INLINE bool sema_expr_analyse_from_ordinal(SemaContext *context, Expr *expr, Exp
}
expr->expr_kind = EXPR_CONST;
expr->const_expr = (ExprConst) {
.enum_err_val = decl->enums.values[to_convert.i.low],
.enum_val = decl->enums.values[to_convert.i.low],
.const_kind = CONST_ENUM
};
expr->type = decl->type;
@@ -3804,7 +3804,7 @@ static inline bool sema_expr_replace_with_enum_array(SemaContext *context, Expr
Expr *expr = expr_new(EXPR_CONST, span);
expr->const_expr.const_kind = const_kind;
ASSERT_SPAN(enum_array_expr, enum_decl->resolve_status == RESOLVE_DONE);
expr->const_expr.enum_err_val = decl;
expr->const_expr.enum_val = decl;
ASSERT_SPAN(enum_array_expr, decl_ok(decl));
expr->type = kind;
expr->resolve_status = RESOLVE_DONE;
@@ -4126,7 +4126,7 @@ static inline bool sema_create_const_kind(SemaContext *context, Expr *expr, Type
ASSERT_SPAN(expr, type_kind->resolve_status == RESOLVE_DONE);
expr->const_expr = (ExprConst) {
.const_kind = CONST_ENUM,
.enum_err_val = values[val]
.enum_val = values[val]
};
return true;
}
@@ -5185,7 +5185,7 @@ CHECK_DEEPER:
{
if (sema_cast_const(current_parent))
{
expr_rewrite_const_string(expr, current_parent->const_expr.enum_err_val->name);
expr_rewrite_const_string(expr, current_parent->const_expr.enum_val->name);
return true;
}
expr_rewrite_to_builtin_access(expr, current_parent, ACCESS_ENUMNAME, type_string);
@@ -5242,7 +5242,7 @@ CHECK_DEEPER:
if (member && decl->decl_kind == DECL_ENUM && member->decl_kind == DECL_VAR && sema_cast_const(parent))
{
if (!sema_analyse_decl(context, decl)) return false;
Decl *ref = current_parent->const_expr.enum_err_val;
Decl *ref = current_parent->const_expr.enum_val;
if (!sema_analyse_decl(context, ref)) return false;
ASSERT_SPAN(expr, parent->const_expr.const_kind == CONST_ENUM);
Expr *copy_init = copy_expr_single(ref->enum_constant.args[member->var.index]);
@@ -6267,7 +6267,7 @@ static bool sema_expr_analyse_enum_add_sub(SemaContext *context, Expr *expr, Exp
return false;
}
ASSERT_SPAN(expr, left_type->decl->resolve_status == RESOLVE_DONE);
expr->const_expr = (ExprConst) { .const_kind = CONST_ENUM, .enum_err_val = enums[int_to_i64(i)] };
expr->const_expr = (ExprConst) { .const_kind = CONST_ENUM, .enum_val = enums[int_to_i64(i)] };
expr->expr_kind = EXPR_CONST;
expr->resolve_status = RESOLVE_DONE;
}

View File

@@ -379,7 +379,7 @@ RETRY:
sema_trace_decl_liveness(expr->const_expr.fault);
return;
case CONST_ENUM:
sema_trace_decl_liveness(expr->const_expr.enum_err_val);
sema_trace_decl_liveness(expr->const_expr.enum_val);
return;
case CONST_REF:
sema_trace_decl_liveness(expr->const_expr.global_ref);

View File

@@ -204,7 +204,7 @@ static bool exec_arg_append_to_scratch(Expr *arg)
scratch_buffer_append(arg->const_expr.fault->name);
return true;
case CONST_ENUM:
scratch_buffer_append(arg->const_expr.enum_err_val->name);
scratch_buffer_append(arg->const_expr.enum_val->name);
return true;
case CONST_TYPEID:
if (!arg->const_expr.typeid->name)

View File

@@ -446,7 +446,7 @@ static inline bool sema_check_return_matches_opt_returns(SemaContext *context, E
// Here we have a const optional return.
ASSERT(ret_expr->inner_expr->const_expr.const_kind == CONST_FAULT);
Decl *fault = ret_expr->inner_expr->const_expr.enum_err_val;
Decl *fault = ret_expr->inner_expr->const_expr.enum_val;
// Check that we find it.
FOREACH(Decl *, opt, context->call_env.opt_returns)
@@ -2208,15 +2208,15 @@ static inline bool sema_check_value_case(SemaContext *context, Type *switch_type
{
if (is_enum)
{
uint32_t ord1 = const_expr->enum_err_val->enum_constant.ordinal;
uint32_t ord2 = to_const_expr->enum_err_val->enum_constant.ordinal;
uint32_t ord1 = const_expr->enum_val->enum_constant.ordinal;
uint32_t ord2 = to_const_expr->enum_val->enum_constant.ordinal;
if (ord1 > ord2)
{
sema_error_at(context, extend_span_with_token(expr->span, to_expr->span),
"The range is not valid because the first enum (%s) has a lower ordinal than the second (%s). "
"It would work if you swapped their order.",
const_expr->enum_err_val->name,
to_const_expr->enum_err_val->name);
const_expr->enum_val->name,
to_const_expr->enum_val->name);
return false;
}
(*actual_cases_ref) += ord2 - ord1;
@@ -2285,8 +2285,8 @@ INLINE const char *create_missing_enums_in_switch_error(Ast **cases, unsigned fo
Expr *e = exprptr(cases[j]->case_stmt.expr);
Expr *e_to = exprptrzero(cases[j]->case_stmt.to_expr);
ASSERT_SPAN(e, expr_is_const_enum(e));
uint32_t ordinal_from = e->const_expr.enum_err_val->enum_constant.ordinal;
uint32_t ordinal_to = e_to ? e_to->const_expr.enum_err_val->enum_constant.ordinal : ordinal_from;
uint32_t ordinal_from = e->const_expr.enum_val->enum_constant.ordinal;
uint32_t ordinal_to = e_to ? e_to->const_expr.enum_val->enum_constant.ordinal : ordinal_from;
if (i >= ordinal_from && i <= ordinal_to) goto CONTINUE;
}
if (++printed != 1)
@@ -2824,7 +2824,7 @@ bool sema_analyse_ct_echo_stmt(SemaContext *context, Ast *statement)
puts(message->const_expr.fault->name);
break;
case CONST_ENUM:
puts(message->const_expr.enum_err_val->name);
puts(message->const_expr.enum_val->name);
break;
case CONST_STRING:
printf("%.*s\n", EXPAND_EXPR_STRING(message));