From 3ccabd625cb7ea69aada56046a3802032b7ccd6e Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 22 Sep 2025 23:08:11 +0200 Subject: [PATCH] Renaming --- src/compiler/abi/c_abi_x86.c | 4 +- src/compiler/ast.c | 12 ++-- src/compiler/c_codegen.c | 12 ++-- src/compiler/codegen_internal.h | 4 +- src/compiler/compiler_internal.h | 62 ++++++++++---------- src/compiler/context.c | 8 +-- src/compiler/copying.c | 4 +- src/compiler/enums.h | 18 +++--- src/compiler/expr.c | 4 +- src/compiler/headers.c | 10 ++-- src/compiler/json_output.c | 10 ++-- src/compiler/llvm_codegen.c | 8 +-- src/compiler/llvm_codegen_debug_info.c | 4 +- src/compiler/llvm_codegen_expr.c | 4 +- src/compiler/llvm_codegen_module.c | 2 +- src/compiler/llvm_codegen_type.c | 10 ++-- src/compiler/parse_global.c | 14 ++--- src/compiler/sema_casts.c | 14 ++--- src/compiler/sema_decls.c | 46 +++++++-------- src/compiler/sema_expr.c | 30 +++++----- src/compiler/sema_initializers.c | 8 +-- src/compiler/sema_internal.h | 4 +- src/compiler/sema_liveness.c | 4 +- src/compiler/sema_name_resolution.c | 14 ++--- src/compiler/sema_passes.c | 6 +- src/compiler/sema_stmts.c | 4 +- src/compiler/sema_types.c | 10 ++-- src/compiler/semantic_analyser.c | 4 +- src/compiler/types.c | 78 +++++++++++++------------- 29 files changed, 206 insertions(+), 206 deletions(-) diff --git a/src/compiler/abi/c_abi_x86.c b/src/compiler/abi/c_abi_x86.c index 1697d5e29..81175aa29 100644 --- a/src/compiler/abi/c_abi_x86.c +++ b/src/compiler/abi/c_abi_x86.c @@ -110,14 +110,14 @@ static bool x86_should_return_type_in_reg(Type *type) case CT_TYPES: case TYPE_ANYFAULT: case TYPE_BITSTRUCT: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_ENUM: case TYPE_FLEXIBLE_ARRAY: case TYPE_FUNC_RAW: case TYPE_INTERFACE: case TYPE_OPTIONAL: case TYPE_CONST_ENUM: - case TYPE_TYPEDEF: + case TYPE_ALIAS: case TYPE_TYPEID: case TYPE_VECTOR: case TYPE_VOID: diff --git a/src/compiler/ast.c b/src/compiler/ast.c index 697c6388d..51ac6ba60 100644 --- a/src/compiler/ast.c +++ b/src/compiler/ast.c @@ -67,12 +67,12 @@ Decl *decl_new_with_type(const char *name, SourceSpan loc, DeclKind decl_type) case DECL_CONST_ENUM: kind = TYPE_CONST_ENUM; break; - case DECL_DISTINCT: - kind = TYPE_DISTINCT; - break; case DECL_TYPEDEF: kind = TYPE_TYPEDEF; break; + case DECL_TYPE_ALIAS: + kind = TYPE_ALIAS; + break; case DECL_BITSTRUCT: kind = TYPE_BITSTRUCT; break; @@ -114,8 +114,8 @@ const char *decl_to_a_name(Decl *decl) case DECL_CT_EXEC: return "compile time exec include"; case DECL_CT_INCLUDE: return "an include"; case DECL_DECLARRAY: return "a declarray"; - case DECL_ALIAS: case DECL_ALIAS_PATH: case DECL_TYPEDEF: return "an alias"; - case DECL_DISTINCT: return "a distinct type"; + case DECL_ALIAS: case DECL_ALIAS_PATH: case DECL_TYPE_ALIAS: return "an alias"; + case DECL_TYPEDEF: return "a distinct type"; case DECL_ENUM: return "an enum"; case DECL_CONST_ENUM: return "a raw enum"; case DECL_ENUM_CONSTANT: return "an enum value"; @@ -429,7 +429,7 @@ Decl *decl_find_enum_constant(Decl *decl, const char *name) AlignSize decl_find_member_offset(Decl *decl, Decl *member) { static const AlignSize NO_MATCH = ~(AlignSize)0; - while (decl->decl_kind == DECL_DISTINCT) decl = decl->distinct->type->decl; + while (decl->decl_kind == DECL_TYPEDEF) decl = decl->distinct->type->decl; Decl **members = NULL; switch (decl->decl_kind) { diff --git a/src/compiler/c_codegen.c b/src/compiler/c_codegen.c index 1f5309e11..1be39325b 100644 --- a/src/compiler/c_codegen.c +++ b/src/compiler/c_codegen.c @@ -91,9 +91,9 @@ static const char *c_type_name(GenContext *c, Type *type) case TYPE_ANYFAULT: case TYPE_TYPEID: case TYPE_INTERFACE: - case TYPE_DISTINCT: - case TYPE_FUNC_RAW: case TYPE_TYPEDEF: + case TYPE_FUNC_RAW: + case TYPE_ALIAS: case TYPE_ENUM: case TYPE_CONST_ENUM: case TYPE_UNTYPED_LIST: @@ -144,9 +144,9 @@ static bool c_emit_type_decl(GenContext *c, Type *type) case ALL_FLOATS: case TYPE_POINTER: return false; - case TYPE_DISTINCT: - case TYPE_FUNC_RAW: case TYPE_TYPEDEF: + case TYPE_FUNC_RAW: + case TYPE_ALIAS: case TYPE_ENUM: case TYPE_CONST_ENUM: case TYPE_UNTYPED_LIST: @@ -649,11 +649,11 @@ static void c_emit_local_decl(GenContext *c, Decl *decl, CValue *value) break; case TYPE_POISONED: case TYPE_VOID: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_CONST_ENUM: case TYPE_FUNC_RAW: case TYPE_BITSTRUCT: - case TYPE_TYPEDEF: + case TYPE_ALIAS: case TYPE_UNTYPED_LIST: case TYPE_FLEXIBLE_ARRAY: case TYPE_INFERRED_ARRAY: diff --git a/src/compiler/codegen_internal.h b/src/compiler/codegen_internal.h index a9e9b8e86..b4242d098 100644 --- a/src/compiler/codegen_internal.h +++ b/src/compiler/codegen_internal.h @@ -24,12 +24,12 @@ static inline Type *type_lowering(Type *type) type = type->canonical; switch (type->type_kind) { - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE case TYPE_OPTIONAL: type = type->optional; continue; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; continue; case TYPE_CONST_ENUM: diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index f2619beec..6c7418176 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -2693,7 +2693,7 @@ INLINE bool type_is_pointer_sized(Type *type) #define DECL_TYPE_KIND_REAL(k_, t_) \ TypeKind k_ = (t_)->type_kind; \ - if (k_ == TYPE_TYPEDEF) k_ = (t_)->canonical->type_kind; + if (k_ == TYPE_ALIAS) k_ = (t_)->canonical->type_kind; INLINE Type *type_add_optional(Type *type, bool make_optional) @@ -2732,7 +2732,7 @@ INLINE bool type_len_is_inferred(Type *type) { switch (type->type_kind) { - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; continue; case TYPE_OPTIONAL: @@ -2798,7 +2798,7 @@ INLINE bool type_may_implement_interface(Type *type) case TYPE_UNION: case TYPE_ENUM: case TYPE_CONST_ENUM: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_BITSTRUCT: return true; default: @@ -2867,7 +2867,7 @@ static inline Type *type_flat_distinct_inline(Type *type); static inline bool type_is_pointer_like(Type *type) { TypeKind kind = type->type_kind; - if (kind == TYPE_DISTINCT) + if (kind == TYPE_TYPEDEF) { type = type_flat_distinct_inline(type); kind = type->type_kind; @@ -2941,10 +2941,10 @@ INLINE bool type_may_negate(Type *type) case ALL_FLOATS: case ALL_INTS: return true; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; case TYPE_OPTIONAL: @@ -3057,7 +3057,7 @@ INLINE Type *type_flatten_for_bitstruct(Type *type) { type = type->canonical; RETRY: - while (type->type_kind == TYPE_DISTINCT) + while (type->type_kind == TYPE_TYPEDEF) { type = type->decl->distinct->type; } @@ -3116,7 +3116,7 @@ static inline Type *type_base(Type *type) type = type->canonical; switch (type->type_kind) { - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; break; case TYPE_ENUM: @@ -3126,7 +3126,7 @@ static inline Type *type_base(Type *type) case TYPE_OPTIONAL: type = type->optional; break; - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE default: return type; @@ -3138,7 +3138,7 @@ static inline Type *type_base(Type *type) static const bool is_distinct_like[TYPE_LAST + 1] = { [TYPE_ENUM] = true, [TYPE_CONST_ENUM] = true, - [TYPE_DISTINCT] = true + [TYPE_TYPEDEF] = true }; INLINE bool typekind_is_distinct_like(TypeKind kind) @@ -3159,7 +3159,7 @@ static bool type_has_inline(Type *type) static inline Type *type_inline(Type *type) { assert(type_is_distinct_like(type)); - return type->type_kind == TYPE_DISTINCT ? type->decl->distinct->type : type->decl->enums.type_info->type; + return type->type_kind == TYPE_TYPEDEF ? type->decl->distinct->type : type->decl->enums.type_info->type; } @@ -3189,7 +3189,7 @@ static inline Type *type_flatten_and_inline(Type *type) case TYPE_OPTIONAL: type = type->optional; continue; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; continue; case TYPE_CONST_ENUM: @@ -3219,7 +3219,7 @@ static inline Type *type_flat_distinct_enum_inline(Type *type) Decl *decl; switch (type->type_kind) { - case TYPE_DISTINCT: + case TYPE_TYPEDEF: decl = type->decl; if (!decl->is_substruct) return type;; type = decl->distinct->type; @@ -3248,15 +3248,15 @@ static inline Type *type_flat_distinct_enum_inline(Type *type) INLINE bool type_is_user_defined(Type *type) { static const bool user_defined_types[TYPE_LAST + 1] = { - [TYPE_ENUM] = true, + [TYPE_ENUM] = true, [TYPE_CONST_ENUM] = true, - [TYPE_STRUCT] = true, - [TYPE_FUNC_RAW] = true, - [TYPE_UNION] = true, - [TYPE_DISTINCT] = true, - [TYPE_BITSTRUCT] = true, - [TYPE_TYPEDEF] = true, - [TYPE_INTERFACE] = true, + [TYPE_STRUCT] = true, + [TYPE_FUNC_RAW] = true, + [TYPE_UNION] = true, + [TYPE_TYPEDEF] = true, + [TYPE_BITSTRUCT] = true, + [TYPE_ALIAS] = true, + [TYPE_INTERFACE] = true, }; return user_defined_types[type->type_kind]; } @@ -3282,7 +3282,7 @@ static inline Type *type_flatten_to_int(Type *type) type = type->canonical; switch (type->type_kind) { - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; break; case TYPE_OPTIONAL: @@ -3299,7 +3299,7 @@ static inline Type *type_flatten_to_int(Type *type) case TYPE_VECTOR: ASSERT(type_is_integer(type->array.base)); return type; - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE default: ASSERT(type_is_integer(type)); @@ -3321,13 +3321,13 @@ static inline CanonicalType *type_distinct_inline(Type *type) case TYPE_CONST_ENUM: type = enum_inner_type(type); break; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; break; case TYPE_OPTIONAL: type = type->optional; break; - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE default: return type; @@ -3344,13 +3344,13 @@ static inline CanonicalType *type_flatten(Type *type) case TYPE_CONST_ENUM: type = enum_inner_type(type); break; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; break; case TYPE_OPTIONAL: type = type->optional; break; - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE default: return type; @@ -3364,11 +3364,11 @@ static inline Type *type_flatten_no_export(Type *type) { switch (type->type_kind) { - case TYPE_TYPEDEF: + case TYPE_ALIAS: if (type->decl->is_export) return type; type = type->canonical; break; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: if (type->decl->is_export) return type; type = type->decl->distinct->type; break; @@ -3462,7 +3462,7 @@ static inline Type *type_flat_for_arithmethics(Type *type) type = type->optional; continue; case TYPE_CONST_ENUM: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: inner = type_inline(type); if (type->decl->is_substruct) { @@ -3563,7 +3563,7 @@ INLINE bool decl_is_user_defined_type(Decl *decl) { DeclKind kind = decl->decl_kind; return (kind == DECL_UNION) | (kind == DECL_STRUCT) | (kind == DECL_BITSTRUCT) - | (kind == DECL_ENUM) | (kind == DECL_TYPEDEF) | (kind == DECL_DISTINCT) + | (kind == DECL_ENUM) | (kind == DECL_TYPE_ALIAS) | (kind == DECL_TYPEDEF) | (kind == DECL_INTERFACE) ; } diff --git a/src/compiler/context.c b/src/compiler/context.c index fa2a0cbc2..2c34c2228 100644 --- a/src/compiler/context.c +++ b/src/compiler/context.c @@ -171,11 +171,11 @@ void decl_register(Decl *decl) UNREACHABLE_VOID case DECL_ATTRIBUTE: case DECL_BITSTRUCT: - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_ENUM: case DECL_CONST_ENUM: case DECL_STRUCT: - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: case DECL_UNION: case DECL_ALIAS: case DECL_FUNC: @@ -236,10 +236,10 @@ void unit_register_global_decl(CompilationUnit *unit, Decl *decl) decl_register(decl); break; case DECL_INTERFACE: - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_STRUCT: case DECL_UNION: - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: case DECL_BITSTRUCT: ASSERT(decl->name); vec_add(unit->types, decl); diff --git a/src/compiler/copying.c b/src/compiler/copying.c index cf085cdf8..56712fb7e 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -1140,7 +1140,7 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) MACRO_COPY_EXPR_LIST(copy->enum_constant.associated); } break; - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: copy_decl_type(copy); if (copy->type_alias_decl.is_func) { @@ -1149,7 +1149,7 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) } MACRO_COPY_TYPE(copy->type_alias_decl.type_info); break; - case DECL_DISTINCT: + case DECL_TYPEDEF: copy_decl_type(copy); MACRO_COPY_TYPE_LIST(copy->interfaces); MACRO_COPY_DECL_METHODS(copy->method_table); diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 6d9a4cf4f..9b6d22583 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -251,7 +251,7 @@ typedef enum FLAG_ATTR ATTR_CALL = 1 << 12, ATTR_BITSTRUCT = 1 << 13, ATTR_MACRO = 1 << 14, - ATTR_DISTINCT = 1 << 15, + ATTR_TYPEDEF = 1 << 15, ATTR_ENUM_VALUE = 1 << 16, ATTR_INTERFACE_METHOD = 1 << 17, ATTR_PARAM = 1 << 18, @@ -260,7 +260,7 @@ typedef enum FLAG_ATTR #define EXPORTED_USER_DEFINED_TYPES (ATTR_ENUM | ATTR_UNION | ATTR_STRUCT | ATTR_FAULT) #define CALLABLE_TYPE (ATTR_FUNC | ATTR_INTERFACE_METHOD | ATTR_MACRO | ATTR_FNTYPE) -#define USER_DEFINED_TYPES (EXPORTED_USER_DEFINED_TYPES | ATTR_BITSTRUCT | ATTR_DISTINCT) +#define USER_DEFINED_TYPES (EXPORTED_USER_DEFINED_TYPES | ATTR_BITSTRUCT | ATTR_TYPEDEF) typedef enum { @@ -672,7 +672,7 @@ typedef enum DECL_DECLARRAY, DECL_ALIAS, DECL_ALIAS_PATH, - DECL_DISTINCT, + DECL_TYPEDEF, DECL_ENUM, DECL_ENUM_CONSTANT, DECL_ERASED, @@ -686,7 +686,7 @@ typedef enum DECL_INTERFACE, DECL_CONST_ENUM, DECL_STRUCT, - DECL_TYPEDEF, + DECL_TYPE_ALIAS, DECL_UNION, DECL_VAR, } DeclKind; @@ -1383,14 +1383,14 @@ typedef enum TYPE_TYPEID, TYPE_FUNC_PTR, TYPE_POINTER, - TYPE_DISTINCT, + TYPE_TYPEDEF, TYPE_CONST_ENUM, TYPE_ENUM, TYPE_FUNC_RAW, TYPE_STRUCT, TYPE_UNION, TYPE_BITSTRUCT, - TYPE_TYPEDEF, + TYPE_ALIAS, TYPE_UNTYPED_LIST, TYPE_SLICE, TYPE_ARRAY, @@ -1703,13 +1703,13 @@ static_assert(EXPR_LAST < 128, "Too many expression types"); #define TYPELIKE_TOKENS TYPE_TOKENS: case TOKEN_TYPE_IDENT: case CT_TYPE_TOKENS // -- Types helper macros -#define FLATTENED_TYPES TYPE_DISTINCT: case TYPE_OPTIONAL: case TYPE_TYPEDEF +#define FLATTENED_TYPES TYPE_TYPEDEF: case TYPE_OPTIONAL: case TYPE_ALIAS #define ALL_SIGNED_INTS TYPE_I8: case TYPE_I16: case TYPE_I32: case TYPE_I64: case TYPE_I128 #define ALL_UNSIGNED_INTS TYPE_U8: case TYPE_U16: case TYPE_U32: case TYPE_U64: case TYPE_U128 #define ALL_FLOATS TYPE_BF16: case TYPE_F16: case TYPE_F32: case TYPE_F64: case TYPE_F128 -#define LOWERED_TYPES CT_TYPES: case TYPE_ENUM: case TYPE_TYPEDEF: case TYPE_TYPEID: \ - case TYPE_DISTINCT: case TYPE_ANYFAULT: case TYPE_BITSTRUCT: \ +#define LOWERED_TYPES CT_TYPES: case TYPE_ENUM: case TYPE_ALIAS: case TYPE_TYPEID: \ + case TYPE_TYPEDEF: case TYPE_ANYFAULT: case TYPE_BITSTRUCT: \ case TYPE_OPTIONAL: case TYPE_INTERFACE: case TYPE_CONST_ENUM #define CT_TYPES TYPE_TYPEINFO: case TYPE_INFERRED_ARRAY: case TYPE_INFERRED_VECTOR: case TYPE_UNTYPED_LIST: \ diff --git a/src/compiler/expr.c b/src/compiler/expr.c index 9c404fc20..a52e262c0 100644 --- a/src/compiler/expr.c +++ b/src/compiler/expr.c @@ -696,7 +696,7 @@ void expr_rewrite_to_const_zero(Expr *expr, Type *type) expr->resolve_status = RESOLVE_DONE; break; case TYPE_FUNC_RAW: - case TYPE_TYPEDEF: + case TYPE_ALIAS: case TYPE_OPTIONAL: case TYPE_TYPEINFO: case TYPE_MEMBER: @@ -714,7 +714,7 @@ void expr_rewrite_to_const_zero(Expr *expr, Type *type) case TYPE_ARRAY: expr_rewrite_const_initializer(expr, type, const_init_new_zero(type)); return; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: expr_rewrite_to_const_zero(expr, canonical->decl->distinct->type); break; } diff --git a/src/compiler/headers.c b/src/compiler/headers.c index bf64b9c95..16aa743da 100644 --- a/src/compiler/headers.c +++ b/src/compiler/headers.c @@ -66,7 +66,7 @@ INLINE const char *decl_get_extname(Decl *decl) static bool type_is_func_pointer(Type *type) { - if (type->type_kind != TYPE_DISTINCT && type->type_kind != TYPE_TYPEDEF) return false; + if (type->type_kind != TYPE_TYPEDEF && type->type_kind != TYPE_ALIAS) return false; type = type_flatten(type); return type->type_kind == TYPE_FUNC_PTR; } @@ -178,7 +178,7 @@ static void header_print_type(HeaderContext *c, Type *type) case TYPE_ANYFAULT: PRINTF("c3fault_t"); return; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: if (type->decl->is_export) { PRINTF("%s", decl_get_extname(type->decl)); @@ -186,7 +186,7 @@ static void header_print_type(HeaderContext *c, Type *type) } header_print_type(c, type->decl->distinct->type); return; - case TYPE_TYPEDEF: + case TYPE_ALIAS: if (type == type_usz) { PRINTF("size_t"); return; } if (type == type_isz) { PRINTF("ptrdiff_t"); return; } if (type == type_iptr) { PRINTF("intptr_t"); return; } @@ -511,7 +511,7 @@ RETRY: case TYPE_ANY: case TYPE_INTERFACE: return; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: { if (!header_try_gen_both(c, type)) return; Type *underlying_type = type->decl->distinct->type; @@ -521,7 +521,7 @@ RETRY: PRINTF(" %s;\n", decl_get_extname(type->decl)); return; } - case TYPE_TYPEDEF: + case TYPE_ALIAS: { if (!header_try_gen_both(c, type)) return; Type *underlying_type = type->canonical; diff --git a/src/compiler/json_output.c b/src/compiler/json_output.c index 43ff4f491..229c5aa5e 100644 --- a/src/compiler/json_output.c +++ b/src/compiler/json_output.c @@ -88,7 +88,7 @@ static inline const char *decl_type_to_string(Decl *type) case DECL_CT_EXEC: return "$exec"; case DECL_CT_INCLUDE: return "$include"; case DECL_ALIAS: return "alias"; - case DECL_DISTINCT: return "typedef"; + case DECL_TYPEDEF: return "typedef"; case DECL_ENUM: return "enum"; case DECL_ENUM_CONSTANT: return "enum_const"; case DECL_FAULT: return "fault"; @@ -101,7 +101,7 @@ static inline const char *decl_type_to_string(Decl *type) case DECL_INTERFACE: return "interface"; case DECL_STRUCT: return "struct"; case DECL_UNION: return "union"; - case DECL_TYPEDEF: return "typedef"; + case DECL_TYPE_ALIAS: return "type_alias"; case DECL_CONST_ENUM: return "raw_enum"; case DECL_BODYPARAM: case DECL_DECLARRAY: @@ -292,7 +292,7 @@ static inline void emit_type_data(FILE *file, Module *module, Decl *type) emit_members(file, type->strukt.members, 0); fputs("\n\t\t\t]", file); break; - case DECL_DISTINCT: + case DECL_TYPEDEF: PRINT(",\n\t\t\t\"type\": \""); print_type(file, type->distinct); PRINTF("\",\n\t\t\t\"inline\": \"%s\"", type->is_substruct ? "true" : "false"); @@ -402,7 +402,7 @@ static inline void emit_types(FILE *file) { bool first = true; FOREACH_DECL(Decl *type, compiler.context.module_list) - if (!decl_is_user_defined_type(type) && type->decl_kind != DECL_TYPEDEF) continue; + if (!decl_is_user_defined_type(type) && type->decl_kind != DECL_TYPE_ALIAS) continue; if (decl_is_hidden(type)) continue; INSERT_COMMA; emit_type_data(file, module, type); @@ -414,7 +414,7 @@ static inline void emit_types(FILE *file) { bool first = true; FOREACH_DECL(Decl *type, compiler.context.generic_module_list) - if (!decl_is_user_defined_type(type) && type->decl_kind != DECL_TYPEDEF) continue; + if (!decl_is_user_defined_type(type) && type->decl_kind != DECL_TYPE_ALIAS) continue; if (decl_is_hidden(type)) continue; INSERT_COMMA; emit_type_data(file, module, type); diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index fcafb5b27..1da53bbb5 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -989,7 +989,7 @@ static void llvm_emit_type_decls(GenContext *context, Decl *decl) case DECL_ERASED: case DECL_FNTYPE: UNREACHABLE_VOID; - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: if (decl->type_alias_decl.is_func) { REMINDER("Emit func typeid"); @@ -1000,7 +1000,7 @@ static void llvm_emit_type_decls(GenContext *context, Decl *decl) UNREACHABLE_VOID case DECL_INTERFACE: break; - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_STRUCT: case DECL_UNION: case DECL_ENUM: @@ -1360,7 +1360,7 @@ LLVMValueRef llvm_get_ref(GenContext *c, Decl *decl) case DECL_ATTRIBUTE: case DECL_BITSTRUCT: case DECL_CT_ASSERT: - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_ENUM: case DECL_CONST_ENUM: case DECL_ENUM_CONSTANT: @@ -1369,7 +1369,7 @@ LLVMValueRef llvm_get_ref(GenContext *c, Decl *decl) case DECL_LABEL: case DECL_MACRO: case DECL_STRUCT: - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: case DECL_UNION: case DECL_DECLARRAY: case DECL_BODYPARAM: diff --git a/src/compiler/llvm_codegen_debug_info.c b/src/compiler/llvm_codegen_debug_info.c index 674671589..c452475ca 100644 --- a/src/compiler/llvm_codegen_debug_info.c +++ b/src/compiler/llvm_codegen_debug_info.c @@ -536,7 +536,7 @@ static LLVMMetadataRef llvm_debug_typedef_type(GenContext *c, Type *type) NULL, 0, NULL, 0); } - Type *original_type = type->type_kind == TYPE_TYPEDEF ? type->canonical : decl->distinct->type; + Type *original_type = type->type_kind == TYPE_ALIAS ? type->canonical : decl->distinct->type; // Use forward references in case we haven't resolved the original type, since we could have this: if (!type->canonical->backend_debug_type) @@ -667,8 +667,8 @@ static inline LLVMMetadataRef llvm_get_debug_type_internal(GenContext *c, Type * case TYPE_STRUCT: case TYPE_UNION: return type->backend_debug_type = llvm_debug_structlike_type(c, type, scope); - case TYPE_DISTINCT: case TYPE_TYPEDEF: + case TYPE_ALIAS: return type->backend_debug_type = llvm_debug_typedef_type(c, type); case TYPE_FLEXIBLE_ARRAY: case TYPE_ARRAY: diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index ade14fe1f..7333644e2 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -3597,9 +3597,9 @@ MEMCMP: break; case TYPE_POISONED: case TYPE_VOID: - case TYPE_DISTINCT: - case TYPE_FUNC_RAW: case TYPE_TYPEDEF: + case TYPE_FUNC_RAW: + case TYPE_ALIAS: case TYPE_INFERRED_ARRAY: case TYPE_INFERRED_VECTOR: case TYPE_UNTYPED_LIST: diff --git a/src/compiler/llvm_codegen_module.c b/src/compiler/llvm_codegen_module.c index cab62fc51..52affa562 100644 --- a/src/compiler/llvm_codegen_module.c +++ b/src/compiler/llvm_codegen_module.c @@ -95,7 +95,7 @@ void gencontext_begin_module(GenContext *c) } case TYPE_STRUCT: case TYPE_UNION: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type->decl->backend_ref = NULL; break; case TYPE_FUNC_RAW: diff --git a/src/compiler/llvm_codegen_type.c b/src/compiler/llvm_codegen_type.c index 55887d3fb..747d131cd 100644 --- a/src/compiler/llvm_codegen_type.c +++ b/src/compiler/llvm_codegen_type.c @@ -23,11 +23,11 @@ static inline LLVMTypeRef llvm_type_from_decl(GenContext *c, Decl *decl) return llvm_get_type(c, decl->strukt.container_type->type); case DECL_FUNC: UNREACHABLE_VOID - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: return llvm_get_type(c, decl->type); case DECL_CONST_ENUM: return llvm_get_type(c, decl->enums.type_info->type); - case DECL_DISTINCT: + case DECL_TYPEDEF: return llvm_get_type(c, decl->distinct->type); case DECL_STRUCT: { @@ -100,7 +100,7 @@ static void param_expand(GenContext *context, LLVMTypeRef** params_ref, Type *ty { switch (type->type_kind) { - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE_VOID case TYPE_ARRAY: for (ArraySize i = type->array.len; i > 0; i--) @@ -620,7 +620,7 @@ LLVMValueRef llvm_get_typeid(GenContext *c, Type *type) return llvm_generate_introspection_global(c, NULL, type, INTROSPECT_TYPE_INTERFACE, NULL, 0, NULL, false); case TYPE_POINTER: return llvm_generate_introspection_global(c, NULL, type, INTROSPECT_TYPE_POINTER, type->pointer, 0, NULL, false); - case TYPE_DISTINCT: + case TYPE_TYPEDEF: return llvm_generate_introspection_global(c, NULL, type, INTROSPECT_TYPE_DISTINCT, type_inline(type), 0, NULL, false); case TYPE_ENUM: return llvm_get_introspection_for_enum(c, type); @@ -644,7 +644,7 @@ LLVMValueRef llvm_get_typeid(GenContext *c, Type *type) LLVMValueRef ref = llvm_generate_temp_introspection_global(c, type); return llvm_generate_introspection_global(c, ref, type, INTROSPECT_TYPE_BITSTRUCT, type->decl->strukt.container_type->type, 0, NULL, false); } - case TYPE_TYPEDEF: + case TYPE_ALIAS: return llvm_get_typeid(c, type->canonical); case CT_TYPES: UNREACHABLE_VOID diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 907e406c3..31db08bd0 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -1896,15 +1896,15 @@ static inline Decl *parse_typedef_declaration(ParseContext *c) { advance_and_verify(c, TOKEN_TYPEDEF); - Decl *decl = decl_new_with_type(symstr(c), c->span, DECL_DISTINCT); + Decl *decl = decl_new_with_type(symstr(c), c->span, DECL_TYPEDEF); if (!consume_type_name(c, "distinct type")) return poisoned_decl; if (!parse_interface_impls(c, &decl->interfaces)) return poisoned_decl; if (!parse_attributes_for_global(c, decl)) return poisoned_decl; - decl->type->type_kind = TYPE_DISTINCT; - decl->decl_kind = DECL_DISTINCT; + decl->type->type_kind = TYPE_TYPEDEF; + decl->decl_kind = DECL_TYPEDEF; CONSUME_OR_RET(TOKEN_EQ, poisoned_decl); @@ -2175,8 +2175,8 @@ static inline Decl *parse_alias_type(ParseContext *c) // 1. Did we have `fn`? In that case it's a function pointer. if (try_consume(c, TOKEN_FN)) { - decl->decl_kind = DECL_TYPEDEF; - decl_add_type(decl, TYPE_TYPEDEF); + decl->decl_kind = DECL_TYPE_ALIAS; + decl_add_type(decl, TYPE_ALIAS); decl->type_alias_decl.is_func = true; Decl *decl_type = decl_new(DECL_FNTYPE, decl->name, c->prev_span); decl->type_alias_decl.decl = decl_type; @@ -2220,8 +2220,8 @@ static inline Decl *parse_alias_type(ParseContext *c) decl->type_alias_decl.type_info = type_info; decl->type_alias_decl.is_func = false; - decl->decl_kind = DECL_TYPEDEF; - decl_add_type(decl, TYPE_TYPEDEF); + decl->decl_kind = DECL_TYPE_ALIAS; + decl_add_type(decl, TYPE_ALIAS); if (type_info->kind == TYPE_INFO_IDENTIFIER && type_info->resolve_status == RESOLVE_NOT_DONE && type_info->unresolved.name == decl->name) { diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index b35404908..e20cfc78f 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -729,8 +729,8 @@ static bool report_cast_error(CastContext *cc, bool may_cast_explicit) { Type *typeto = type_no_optional(to); Type *from = type_no_optional(expr->type); - if (expr->type->canonical->type_kind == TYPE_DISTINCT - && type_no_optional(to)->canonical->type_kind == TYPE_DISTINCT) + if (expr->type->canonical->type_kind == TYPE_TYPEDEF + && type_no_optional(to)->canonical->type_kind == TYPE_TYPEDEF) { RETURN_CAST_ERROR(expr, "Implicitly casting %s to %s is not permitted. It's possible to do an explicit cast by placing '(%s)' before the expression. However, explicit casts between distinct types are usually not intended and are not safe.", @@ -1191,7 +1191,7 @@ RETRY:; Type *inner; switch (decl->decl_kind) { - case DECL_DISTINCT: + case DECL_TYPEDEF: inner = decl->distinct->type->canonical; break; case DECL_STRUCT: @@ -1617,7 +1617,7 @@ static bool rule_bits_to_int(CastContext *cc, bool is_explicit, bool is_silent) RETRY: if (base_type != to) { - if (base_type->type_kind == TYPE_DISTINCT && (base_type->decl->is_substruct || is_explicit)) + if (base_type->type_kind == TYPE_TYPEDEF && (base_type->decl->is_substruct || is_explicit)) { base_type = base_type->decl->distinct->type->canonical; goto RETRY; @@ -2540,13 +2540,13 @@ static ConvGroup group_from_type[TYPE_LAST + 1] = { [TYPE_TYPEID] = CONV_TYPEID, [TYPE_POINTER] = CONV_POINTER, [TYPE_ENUM] = CONV_ENUM, - [TYPE_CONST_ENUM] = CONV_RAW_ENUM, + [TYPE_CONST_ENUM] = CONV_RAW_ENUM, [TYPE_FUNC_PTR] = CONV_FUNC, [TYPE_STRUCT] = CONV_STRUCT, [TYPE_UNION] = CONV_UNION, [TYPE_BITSTRUCT] = CONV_BITSTRUCT, - [TYPE_TYPEDEF] = CONV_NO, - [TYPE_DISTINCT] = CONV_DISTINCT, + [TYPE_ALIAS] = CONV_NO, + [TYPE_TYPEDEF] = CONV_DISTINCT, [TYPE_ARRAY] = CONV_ARRAY, [TYPE_SLICE] = CONV_SLICE, [TYPE_FLEXIBLE_ARRAY] = CONV_NO, diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index d0ef096de..98c8dde76 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -44,7 +44,7 @@ static inline bool sema_analyse_attribute_decl(SemaContext *context, SemaContext static inline bool sema_analyse_type_alias(SemaContext *context, Decl *decl, bool *erase_decl); static bool sema_analyse_variable_type(SemaContext *context, Type *type, SourceSpan span); static inline bool sema_analyse_alias(SemaContext *context, Decl *decl, bool *erase_decl); -static inline bool sema_analyse_distinct(SemaContext *context, Decl *decl, bool *erase_decl); +static inline bool sema_analyse_typedef(SemaContext *context, Decl *decl, bool *erase_decl); static CompilationUnit *unit_copy(Module *module, CompilationUnit *unit); @@ -408,9 +408,9 @@ RETRY:; type = type_flatten(type); switch (type->type_kind) { - case TYPE_DISTINCT: - case TYPE_POISONED: case TYPE_TYPEDEF: + case TYPE_POISONED: + case TYPE_ALIAS: case TYPE_UNTYPED_LIST: case TYPE_OPTIONAL: case TYPE_WILDCARD: @@ -1022,7 +1022,7 @@ RETRY: case TYPE_STRUCT: case TYPE_UNION: case TYPE_BITSTRUCT: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_VECTOR: case TYPE_INFERRED_VECTOR: case TYPE_UNTYPED_LIST: @@ -1030,7 +1030,7 @@ RETRY: case TYPE_TYPEINFO: case TYPE_MEMBER: return true; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; case TYPE_POINTER: @@ -1504,10 +1504,10 @@ static inline bool sema_analyse_type_alias(SemaContext *context, Decl *decl, boo /** * Analyse a distinct type. */ -static inline bool sema_analyse_distinct(SemaContext *context, Decl *decl, bool *erase_decl) +static inline bool sema_analyse_typedef(SemaContext *context, Decl *decl, bool *erase_decl) { // Check the attributes on the distinct type. - if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_DISTINCT, erase_decl)) return false; + if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_TYPEDEF, erase_decl)) return false; // Erase it? if (*erase_decl) return true; @@ -2644,10 +2644,10 @@ static inline Decl *sema_find_interface_for_method(SemaContext *context, Canonic { case TYPE_STRUCT: case TYPE_UNION: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_ENUM: break; - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE default: return NULL; @@ -2864,7 +2864,7 @@ static inline bool sema_analyse_method(SemaContext *context, Decl *decl) case TYPE_FUNC_RAW: case TYPE_UNTYPED_LIST: case TYPE_BITSTRUCT: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: break; case TYPE_TYPEID: if (type_property_by_name(kw) != TYPE_PROPERTY_NONE) @@ -2872,7 +2872,7 @@ static inline bool sema_analyse_method(SemaContext *context, Decl *decl) RETURN_SEMA_ERROR(decl, "\"%s\" is not a valid method name for a typeid as this is the name of a type property.", decl->name); } break; - case TYPE_TYPEDEF: + case TYPE_ALIAS: case TYPE_OPTIONAL: case TYPE_WILDCARD: case TYPE_TYPEINFO: @@ -2963,8 +2963,8 @@ static const char *attribute_domain_to_string(AttributeDomain domain) return "alias"; case ATTR_CALL: return "call"; - case ATTR_DISTINCT: - return "distinct"; + case ATTR_TYPEDEF: + return "typedef"; case ATTR_INTERFACE_METHOD: return "interface method"; case ATTR_FNTYPE: @@ -3088,7 +3088,7 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ [ATTRIBUTE_SAFEMACRO] = ATTR_MACRO, [ATTRIBUTE_SAFEINFER] = ATTR_GLOBAL | ATTR_LOCAL, [ATTRIBUTE_SECTION] = ATTR_FUNC | ATTR_CONST | ATTR_GLOBAL, - [ATTRIBUTE_STRUCTLIKE] = ATTR_DISTINCT, + [ATTRIBUTE_STRUCTLIKE] = ATTR_TYPEDEF, [ATTRIBUTE_TAG] = ATTR_BITSTRUCT_MEMBER | ATTR_MEMBER | USER_DEFINED_TYPES | CALLABLE_TYPE, [ATTRIBUTE_TEST] = ATTR_FUNC, [ATTRIBUTE_UNUSED] = (AttributeDomain)~(ATTR_CALL), @@ -3514,7 +3514,7 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ case ATTRIBUTE_WEAK: if (domain == ATTR_ALIAS) { - if (decl->decl_kind != DECL_TYPEDEF) RETURN_SEMA_ERROR(attr, "'@weak' can only be used on type aliases."); + if (decl->decl_kind != DECL_TYPE_ALIAS) RETURN_SEMA_ERROR(attr, "'@weak' can only be used on type aliases."); if (!decl->type_alias_decl.is_redef) { RETURN_SEMA_ERROR(attr, "'@weak' is only allowed on type aliases with the same name, eg 'def Foo = bar::def::Foo @weak'."); @@ -4915,7 +4915,7 @@ static Module *module_instantiate_generic(SemaContext *context, Module *module, if (is_value) RETURN_NULL_SEMA_ERROR(param, "Expected a value, not a type."); TypeInfo *type_info = param->type_expr; if (!sema_resolve_type_info(context, type_info, RESOLVE_TYPE_DEFAULT)) return NULL; - Decl *decl = decl_new_with_type(param_name, params[i]->span, DECL_TYPEDEF); + Decl *decl = decl_new_with_type(param_name, params[i]->span, DECL_TYPE_ALIAS); decl->resolve_status = RESOLVE_DONE; ASSERT(type_info->resolve_status == RESOLVE_DONE); decl->type_alias_decl.type_info = type_info; @@ -5003,7 +5003,7 @@ static bool sema_generate_parameterized_name_to_scratch(SemaContext *context, Mo { if (!sema_analyse_ct_expr(context, param)) return false; Type *type = param->type->canonical; - if (type->type_kind == TYPE_DISTINCT) type = type_flatten(type); + if (type->type_kind == TYPE_TYPEDEF) type = type_flatten(type); bool is_enum_or_fault = type_kind_is_enum_or_fault(type->type_kind); if (!type_is_integer_or_bool_kind(type) && !is_enum_or_fault) @@ -5037,7 +5037,7 @@ static bool sema_generate_parameterized_name_to_scratch(SemaContext *context, Mo else { Type *type = param->type->canonical; - if (type->type_kind == TYPE_DISTINCT) + if (type->type_kind == TYPE_TYPEDEF) { mangle_type_param(type, mangled); scratch_buffer_append(mangled ? "$" : ", "); @@ -5329,10 +5329,10 @@ RETRY: case TYPE_FUNC_PTR: type = type->pointer; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: if (!sema_analyse_decl(context, type->decl)) return false; type = type->decl->distinct->type; goto RETRY; @@ -5414,10 +5414,10 @@ bool sema_analyse_decl(SemaContext *context, Decl *decl) case DECL_ATTRIBUTE: if (!sema_analyse_attribute_decl(context, context, decl, &erase_decl)) goto FAILED; break; - case DECL_DISTINCT: - if (!sema_analyse_distinct(context, decl, &erase_decl)) goto FAILED; - break; case DECL_TYPEDEF: + if (!sema_analyse_typedef(context, decl, &erase_decl)) goto FAILED; + break; + case DECL_TYPE_ALIAS: if (!sema_analyse_type_alias(context, decl, &erase_decl)) goto FAILED; break; case DECL_ENUM: diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index a0dba2342..70db49119 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -248,7 +248,7 @@ Expr *sema_enter_inline_member(Expr *parent, CanonicalType *type) expr = expr_access_inline_member(parent, decl); break; } - case TYPE_DISTINCT: + case TYPE_TYPEDEF: { Decl *decl = type->decl; if (!decl->is_substruct) return NULL; @@ -942,11 +942,11 @@ static inline bool sema_cast_ident_rvalue(SemaContext *context, Expr *expr) case DECL_CT_EXEC: case DECL_CT_INCLUDE: case DECL_DECLARRAY: - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_ERASED: case DECL_GROUP: case DECL_IMPORT: - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: UNREACHABLE case DECL_POISONED: return expr_poison(expr); @@ -4592,7 +4592,7 @@ static inline bool sema_expr_analyse_slice(SemaContext *context, Expr *expr, Che // Retain the original type when doing distinct slices. Type *result_type = type_get_slice(inner_type); Type *original_type_canonical = original_type->canonical; - if (original_type_canonical->type_kind == TYPE_DISTINCT && type_base(original_type_canonical) == result_type) + if (original_type_canonical->type_kind == TYPE_TYPEDEF && type_base(original_type_canonical) == result_type) { result_type = original_type; } @@ -4823,7 +4823,7 @@ static inline bool sema_expr_analyse_type_access(SemaContext *context, Expr *exp break; case DECL_UNION: case DECL_STRUCT: - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_BITSTRUCT: case DECL_INTERFACE: break; @@ -5065,7 +5065,7 @@ static inline bool sema_create_const_inner(SemaContext *context, Expr *expr, Typ case TYPE_OPTIONAL: inner = type->optional; break; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: inner = type->decl->distinct->type->canonical; break; case TYPE_CONST_ENUM: @@ -5628,7 +5628,7 @@ static bool sema_type_property_is_valid_for_type(CanonicalType *original_type, T { case TYPE_POINTER: case TYPE_OPTIONAL: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_ENUM: case TYPE_CONST_ENUM: case TYPE_BITSTRUCT: @@ -5693,7 +5693,7 @@ static bool sema_type_property_is_valid_for_type(CanonicalType *original_type, T case TYPE_POISONED: case TYPE_VOID: case TYPE_FUNC_RAW: - case TYPE_TYPEDEF: + case TYPE_ALIAS: case TYPE_UNTYPED_LIST: case TYPE_FLEXIBLE_ARRAY: case TYPE_OPTIONAL: @@ -8233,7 +8233,7 @@ BoolErr sema_type_can_check_equality_with_overload(SemaContext *context, Type *t return sema_type_has_equality_overload(context, type); case TYPE_BITSTRUCT: return true; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; case TYPE_SLICE: @@ -8241,7 +8241,7 @@ BoolErr sema_type_can_check_equality_with_overload(SemaContext *context, Type *t // Arrays are comparable if elements are type = type->array.base; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_CONST_ENUM: if (sema_type_has_equality_overload(context, type)) return true; type = type_inline(type); @@ -9573,16 +9573,16 @@ static inline bool sema_expr_analyse_rethrow(SemaContext *context, Expr *expr, T } +// Analyse x!! static inline bool sema_expr_analyse_force_unwrap(SemaContext *context, Expr *expr) { Expr *inner = expr->inner_expr; if (!sema_analyse_expr(context, inner)) return false; - expr->type = type_no_optional(inner->type); if (!IS_OPTIONAL(inner)) { - SEMA_ERROR(expr, "No optional to rethrow before '!!' in the expression, please remove '!!'."); - return false; + RETURN_SEMA_ERROR(expr, "No optional to rethrow before '!!' in the expression, please remove '!!'."); } + expr->type = type_no_optional(inner->type); return true; } @@ -10097,7 +10097,7 @@ static inline bool sema_expr_analyse_ct_nameof(SemaContext *context, Expr *expr, case DECL_FAULT: goto RETURN_CT; case DECL_BITSTRUCT: - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_ENUM: case DECL_CONST_ENUM: case DECL_ENUM_CONSTANT: @@ -10105,7 +10105,7 @@ static inline bool sema_expr_analyse_ct_nameof(SemaContext *context, Expr *expr, case DECL_FUNC: case DECL_INTERFACE: case DECL_STRUCT: - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: case DECL_UNION: // TODO verify that all of these are correct goto RETURN_CT; // NOLINT diff --git a/src/compiler/sema_initializers.c b/src/compiler/sema_initializers.c index 314dddd80..0f86b9c3a 100644 --- a/src/compiler/sema_initializers.c +++ b/src/compiler/sema_initializers.c @@ -330,9 +330,9 @@ static inline bool sema_expr_analyse_array_plain_initializer(SemaContext *contex // We have the case where "Foo = int[*]" if (inferred_len && !type_len_is_inferred(assigned)) { - ASSERT(assigned->type_kind == TYPE_TYPEDEF); - ASSERT(assigned->decl->decl_kind == DECL_TYPEDEF); - while (assigned->type_kind == TYPE_TYPEDEF) assigned = assigned->decl->type; + ASSERT(assigned->type_kind == TYPE_ALIAS); + ASSERT(assigned->decl->decl_kind == DECL_TYPE_ALIAS); + while (assigned->type_kind == TYPE_ALIAS) assigned = assigned->decl->type; ASSERT(type_len_is_inferred(assigned)); } // Prefer the typedef index: define Bar = int; Bar[1] => Bar and not int @@ -859,7 +859,7 @@ bool sema_expr_analyse_initializer_list(SemaContext *context, Type *to, Expr *ex case TYPE_VOID: case TYPE_POISONED: case TYPE_FUNC_RAW: - case TYPE_TYPEDEF: + case TYPE_ALIAS: case TYPE_OPTIONAL: case TYPE_TYPEINFO: case TYPE_MEMBER: diff --git a/src/compiler/sema_internal.h b/src/compiler/sema_internal.h index a286b0fe8..a40d4f524 100644 --- a/src/compiler/sema_internal.h +++ b/src/compiler/sema_internal.h @@ -266,11 +266,11 @@ static inline StorageType sema_resolve_storage_type(SemaContext *context, Type * case TYPE_OPTIONAL: type = type->optional; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: if (!sema_analyse_decl(context, type->decl)) return false; type = type->canonical; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: is_distinct = true; if (!sema_analyse_decl(context, type->decl)) return false; type = type->decl->distinct->type; diff --git a/src/compiler/sema_liveness.c b/src/compiler/sema_liveness.c index 075b806fe..2ec944f0a 100644 --- a/src/compiler/sema_liveness.c +++ b/src/compiler/sema_liveness.c @@ -587,7 +587,7 @@ RETRY: { case DECL_ERASED: return; - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: sema_trace_type_liveness(decl->type); return; case DECL_ALIAS: @@ -597,7 +597,7 @@ RETRY: sema_trace_decl_dynamic_methods(decl); sema_trace_enum_associated(decl); return; - case DECL_DISTINCT: + case DECL_TYPEDEF: sema_trace_type_liveness(decl->distinct->type); FALLTHROUGH; case DECL_CONST_ENUM: diff --git a/src/compiler/sema_name_resolution.c b/src/compiler/sema_name_resolution.c index ba1edc9f5..70865fc48 100644 --- a/src/compiler/sema_name_resolution.c +++ b/src/compiler/sema_name_resolution.c @@ -83,7 +83,7 @@ static bool add_interface_to_decl_stack(SemaContext *context, Decl *decl) static bool add_members_to_decl_stack(SemaContext *context, Decl *decl, FindMember find) { if (find != FIELDS_ONLY) sema_add_methods_to_decl_stack(context, decl); - while (decl->decl_kind == DECL_DISTINCT) + while (decl->decl_kind == DECL_TYPEDEF) { Type *type = decl->distinct->type->canonical; if (!type_is_user_defined(type)) break; @@ -269,7 +269,7 @@ INLINE Type *sema_fold_weak(SemaContext *context, Decl *decl) if (!sema_analyse_decl(context, decl)) return NULL; } Type *type = decl->type_alias_decl.type_info->type; - if (type->type_kind != TYPE_TYPEDEF) return type; + if (type->type_kind != TYPE_ALIAS) return type; decl = type->decl; } return decl->type; @@ -292,7 +292,7 @@ static BoolErr sema_first_is_preferred(SemaContext *context, Decl *decl, Decl *d if ((decl->is_autoimport && !decl2->is_autoimport) || (decl2->unit->module->generic_module && !decl->unit->module->generic_module)) return BOOL_TRUE; // Now analyse common parents, we only check if this is a redef. - if (decl2->decl_kind != DECL_TYPEDEF || !decl2->is_weak) return BOOL_FALSE; + if (decl2->decl_kind != DECL_TYPE_ALIAS || !decl2->is_weak) return BOOL_FALSE; Type *weak2 = sema_fold_weak(context, decl2); if (!weak2) return BOOL_ERR; @@ -301,7 +301,7 @@ static BoolErr sema_first_is_preferred(SemaContext *context, Decl *decl, Decl *d if (weak2 == decl->type) return BOOL_TRUE; // If we can't fold the decl then we're done. - if (decl->decl_kind != DECL_TYPEDEF || !decl->is_weak) return BOOL_FALSE; + if (decl->decl_kind != DECL_TYPE_ALIAS || !decl->is_weak) return BOOL_FALSE; Type *weak = sema_fold_weak(context, decl); if (!weak) return BOOL_ERR; @@ -980,9 +980,9 @@ bool sema_resolve_type_decl(SemaContext *context, Type *type) return sema_resolve_type_decl(context, type->optional); case TYPE_TYPEINFO: UNREACHABLE - case TYPE_TYPEDEF: + case TYPE_ALIAS: return sema_resolve_type_decl(context, type->canonical); - case TYPE_DISTINCT: + case TYPE_TYPEDEF: if (!sema_analyse_decl(context, type->decl)) return false; return sema_resolve_type_decl(context, type->decl->distinct->type); case TYPE_FUNC_RAW: @@ -1031,7 +1031,7 @@ Decl *sema_resolve_type_method(SemaContext *context, CanonicalType *type, const case TYPE_STRUCT: type = type_decl->strukt.members[0]->type->canonical; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type_decl->distinct->type->canonical; goto RETRY; case TYPE_ENUM: diff --git a/src/compiler/sema_passes.c b/src/compiler/sema_passes.c index b399ea119..3c437dbd0 100644 --- a/src/compiler/sema_passes.c +++ b/src/compiler/sema_passes.c @@ -625,10 +625,10 @@ INLINE void sema_analyse_inner_func_ptr(SemaContext *c, Decl *decl) Type *inner; switch (decl->decl_kind) { - case DECL_DISTINCT: + case DECL_TYPEDEF: inner = decl->distinct->type; break; - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: inner = decl->type->canonical; break; default: @@ -777,7 +777,7 @@ void sema_analysis_pass_interface(Module *module) { switch (decl->decl_kind) { - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_STRUCT: case DECL_UNION: case DECL_ENUM: diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 58364a790..4b9368e0d 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -1563,7 +1563,7 @@ static inline bool sema_analyse_foreach_stmt(SemaContext *context, Ast *statemen // However, if we have something distinct, that flattens to a pointer, we should never take the // the underlying pointee type. - if (canonical->type_kind == TYPE_DISTINCT && type_flatten(canonical)->type_kind == TYPE_POINTER) + if (canonical->type_kind == TYPE_TYPEDEF && type_flatten(canonical)->type_kind == TYPE_POINTER) { value_type = NULL; } @@ -1578,7 +1578,7 @@ static inline bool sema_analyse_foreach_stmt(SemaContext *context, Ast *statemen bool need_deref = false; // Now we lower the foreach... // If we can't find a value, or this is distinct, then we assume there is an overload. - if (!value_type || canonical->type_kind == TYPE_DISTINCT) + if (!value_type || canonical->type_kind == TYPE_TYPEDEF) { // Get the overload for .len len = sema_find_untyped_operator(enumerator->type, OVERLOAD_LEN, NULL); diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index 96c96408c..b142ef6a3 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -235,7 +235,7 @@ static bool sema_resolve_type_identifier(SemaContext *context, TypeInfo *type_in type_info->resolve_status = RESOLVE_DONE; return true; case DECL_CONST_ENUM: - case DECL_DISTINCT: + case DECL_TYPEDEF: if (resolve_type_kind & RESOLVE_TYPE_NO_CHECK_DISTINCT) { type_info->type = decl->type; @@ -243,10 +243,10 @@ static bool sema_resolve_type_identifier(SemaContext *context, TypeInfo *type_in return true; } FALLTHROUGH; - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: if (!sema_analyse_decl(context, decl)) return type_info_poison(type_info); type_info->type = decl->type; - assert (type_info->type->canonical->type_kind != TYPE_TYPEDEF); + assert (type_info->type->canonical->type_kind != TYPE_ALIAS); type_info->resolve_status = RESOLVE_DONE; return true; case DECL_POISONED: @@ -423,7 +423,7 @@ bool sema_unresolved_type_is_generic(SemaContext *context, TypeInfo *type_info) if (type_info->subtype != TYPE_COMPRESSED_NONE) return false; Decl *decl = sema_find_path_symbol(context, type_info->unresolved.name, type_info->unresolved.path); if (!decl) return false; - if (decl->decl_kind != DECL_TYPEDEF) return false; + if (decl->decl_kind != DECL_TYPE_ALIAS) return false; if (decl->resolve_status == RESOLVE_DONE) return false; if (decl->type_alias_decl.is_func) return false; type_info = decl->type_alias_decl.type_info; @@ -619,7 +619,7 @@ static Type *flatten_raw_function_type(Type *type) Type *current; switch (type->type_kind) { - case TYPE_TYPEDEF: + case TYPE_ALIAS: return flatten_raw_function_type(type->canonical); case TYPE_FUNC_RAW: return type->function.prototype->raw_type; diff --git a/src/compiler/semantic_analyser.c b/src/compiler/semantic_analyser.c index 242290690..7676e9dce 100644 --- a/src/compiler/semantic_analyser.c +++ b/src/compiler/semantic_analyser.c @@ -269,11 +269,11 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls) case DECL_ATTRIBUTE: case DECL_BITSTRUCT: case DECL_CONST_ENUM: - case DECL_DISTINCT: + case DECL_TYPEDEF: case DECL_ENUM: case DECL_INTERFACE: case DECL_STRUCT: - case DECL_TYPEDEF: + case DECL_TYPE_ALIAS: case DECL_UNION: case DECL_VAR: break; diff --git a/src/compiler/types.c b/src/compiler/types.c index a178b45da..46ee543ca 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -138,13 +138,13 @@ void type_append_name_to_scratch(Type *type) switch (type->type_kind) { case TYPE_POISONED: - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE_VOID; case TYPE_ENUM: case TYPE_CONST_ENUM: case TYPE_STRUCT: case TYPE_UNION: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_BITSTRUCT: case TYPE_INTERFACE: scratch_buffer_append(type->decl->name); @@ -277,10 +277,10 @@ const char *type_to_error_string(Type *type) return type->name; case TYPE_ENUM: case TYPE_CONST_ENUM: - case TYPE_TYPEDEF: + case TYPE_ALIAS: case TYPE_STRUCT: case TYPE_UNION: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_BITSTRUCT: case TYPE_INTERFACE: { @@ -344,10 +344,10 @@ static const char *type_to_error_string_with_path(Type *type) return type->name; case TYPE_ENUM: case TYPE_CONST_ENUM: - case TYPE_TYPEDEF: + case TYPE_ALIAS: case TYPE_STRUCT: case TYPE_UNION: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_BITSTRUCT: case TYPE_INTERFACE: { @@ -418,7 +418,7 @@ RETRY: ASSERT(type->decl->resolve_status == RESOLVE_DONE); type = type->decl->strukt.container_type->type; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: ASSERT(type->decl->resolve_status == RESOLVE_DONE); type = type->decl->distinct->type; goto RETRY; @@ -436,7 +436,7 @@ RETRY: case TYPE_OPTIONAL: type = type->optional; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; case TYPE_ENUM: @@ -525,10 +525,10 @@ bool type_is_abi_aggregate(Type *type) case TYPE_OPTIONAL: type = type->optional; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; case CT_TYPES: @@ -588,10 +588,10 @@ bool type_is_ordered(Type *type) case TYPE_ENUM: case TYPE_CONST_ENUM: return true; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; goto RETRY; default: @@ -620,7 +620,7 @@ bool type_is_comparable(Type *type) case TYPE_BITSTRUCT: type = type->decl->strukt.container_type->type; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; case TYPE_SLICE: @@ -628,7 +628,7 @@ bool type_is_comparable(Type *type) // Arrays are comparable if elements are type = type->array.base; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_CONST_ENUM: type = type_inline(type); goto RETRY; @@ -735,11 +735,11 @@ void type_mangle_introspect_name_to_buffer(Type *type) case TYPE_STRUCT: case TYPE_UNION: case TYPE_BITSTRUCT: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_INTERFACE: scratch_buffer_set_extern_decl_name(type->decl, false); return; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type_mangle_introspect_name_to_buffer(type->canonical); return; } @@ -801,10 +801,10 @@ AlignSize type_abi_alignment(Type *type) case TYPE_OPTIONAL: type = type->optional; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; case TYPE_ENUM: @@ -1170,13 +1170,13 @@ Type *type_get_indexed_type(Type *type) case TYPE_FLEXIBLE_ARRAY: case TYPE_VECTOR: return type->array.base->canonical; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; goto RETRY; case TYPE_OPTIONAL: type = type->optional; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; default: @@ -1251,11 +1251,11 @@ bool type_is_valid_for_vector(Type *type) case TYPE_TYPEID: case TYPE_ANYFAULT: return true; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: ASSERT(type->decl->resolve_status == RESOLVE_DONE); type = type->decl->distinct->type; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; default: @@ -1268,7 +1268,7 @@ bool type_is_valid_for_array(Type *type) RETRY: switch (type->type_kind) { - case TYPE_DISTINCT: + case TYPE_TYPEDEF: ASSERT(type->decl->resolve_status == RESOLVE_DONE); type = type->decl->distinct->type; goto RETRY; @@ -1291,7 +1291,7 @@ bool type_is_valid_for_array(Type *type) case TYPE_SLICE: case TYPE_VECTOR: return true; - case TYPE_TYPEDEF: + case TYPE_ALIAS: ASSERT(type->decl->resolve_status == RESOLVE_DONE); type = type->canonical; goto RETRY; @@ -1364,14 +1364,14 @@ static void type_init(const char *name, Type *location, TypeKind kind, unsigned static void type_create_alias(const char *name, Type *location, Type *canonical) { - Decl *decl = decl_new(DECL_TYPEDEF, name, INVALID_SPAN); + Decl *decl = decl_new(DECL_TYPE_ALIAS, name, INVALID_SPAN); decl->resolve_status = RESOLVE_DONE; decl->type_alias_decl.type_info = type_info_new_base(canonical, INVALID_SPAN); decl->unit = compiler.context.core_unit; decl->is_export = true; *location = (Type) { .decl = decl, - .type_kind = TYPE_TYPEDEF, + .type_kind = TYPE_ALIAS, .name = name, .canonical = canonical }; @@ -1476,7 +1476,7 @@ void type_setup(PlatformTarget *target) type_init("fault", &t.fault, TYPE_ANYFAULT, target->width_pointer, target->align_pointer); type_chars = type_get_slice(type_char); type_wildcard_optional = type_get_optional(type_wildcard); - Decl *string_decl = decl_new_with_type(symtab_preset("String", TOKEN_TYPE_IDENT), INVALID_SPAN, DECL_DISTINCT); + Decl *string_decl = decl_new_with_type(symtab_preset("String", TOKEN_TYPE_IDENT), INVALID_SPAN, DECL_TYPEDEF); string_decl->unit = compiler.context.core_unit; string_decl->extname = string_decl->name; string_decl->is_substruct = true; @@ -1551,14 +1551,14 @@ bool type_is_scalar(Type *type) case TYPE_BITSTRUCT: type = type->decl->strukt.container_type->type; goto RETRY; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: type = type->decl->distinct->type; goto RETRY; case TYPE_OPTIONAL: type = type->optional; if (!type) return false; goto RETRY; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; } @@ -1570,7 +1570,7 @@ Type *type_find_parent_type(Type *type) ASSERT(type->canonical); switch (type->type_kind) { - case TYPE_DISTINCT: + case TYPE_TYPEDEF: { Decl *decl = type->decl; return decl->is_substruct ? decl->distinct->type : NULL; @@ -1806,7 +1806,7 @@ bool type_may_have_method(Type *type) DECL_TYPE_KIND_REAL(kind, type) switch (kind) { - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_UNION: case TYPE_STRUCT: case TYPE_ENUM: @@ -1826,7 +1826,7 @@ bool type_may_have_method(Type *type) case TYPE_BOOL: case TYPE_INTERFACE: return true; - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE case TYPE_POINTER: return type == type_voidptr; @@ -1849,7 +1849,7 @@ bool type_may_have_sub_elements(Type *type) DECL_TYPE_KIND_REAL(kind, type) switch (kind) { - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_UNION: case TYPE_STRUCT: case TYPE_ENUM: @@ -2158,7 +2158,7 @@ RETRY_DISTINCT: if (other->type_kind != TYPE_FUNC_PTR) return NULL; if (other->pointer->function.prototype->raw_type != type->pointer->function.prototype->raw_type) return NULL; return type; - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_CONST_ENUM: if (type_is_distinct_like(other)) { @@ -2188,7 +2188,7 @@ RETRY_DISTINCT: // even if the struct has an inline type, this should not // be implicit return NULL; - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE // Should only handle canonical types case TYPE_UNTYPED_LIST: if (other->type_kind == TYPE_ARRAY) return other; @@ -2281,9 +2281,9 @@ unsigned type_get_introspection_kind(TypeKind kind) case TYPE_BITSTRUCT: return INTROSPECT_TYPE_BITSTRUCT; case TYPE_FUNC_RAW: - case TYPE_TYPEDEF: + case TYPE_ALIAS: UNREACHABLE - case TYPE_DISTINCT: + case TYPE_TYPEDEF: return INTROSPECT_TYPE_DISTINCT; case TYPE_ARRAY: case TYPE_INFERRED_ARRAY: @@ -2334,10 +2334,10 @@ Module *type_base_module(Type *type) case TYPE_STRUCT: case TYPE_UNION: case TYPE_BITSTRUCT: - case TYPE_DISTINCT: + case TYPE_TYPEDEF: case TYPE_INTERFACE: return type->decl->unit ? type->decl->unit->module : NULL; - case TYPE_TYPEDEF: + case TYPE_ALIAS: type = type->canonical; goto RETRY; case TYPE_ARRAY: