From d01d8d36633ead091fc319a6619bc43500dddf3d Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 20 Oct 2023 12:42:36 +0200 Subject: [PATCH] "protocol" => "interface" --- lib/std/core/mem_allocator.c3 | 2 +- lib/std/io/formatter.c3 | 2 +- lib/std/math/math.random.c3 | 2 +- releasenotes.md | 2 +- resources/grammar/c3.l | 4 +- resources/grammar/grammar.y | 49 +++--- src/compiler/abi/c_abi_x64.c | 4 +- src/compiler/abi/c_abi_x86.c | 6 +- src/compiler/ast.c | 6 +- src/compiler/codegen_general.c | 2 +- src/compiler/codegen_internal.h | 2 +- src/compiler/compiler_internal.h | 16 +- src/compiler/context.c | 4 +- src/compiler/copying.c | 14 +- src/compiler/enums.h | 18 +-- src/compiler/expr.c | 4 +- src/compiler/headers.c | 10 +- src/compiler/json_output.c | 2 +- src/compiler/llvm_codegen.c | 6 +- src/compiler/llvm_codegen_debug_info.c | 4 +- src/compiler/llvm_codegen_expr.c | 8 +- src/compiler/llvm_codegen_function.c | 2 +- src/compiler/llvm_codegen_internal.h | 2 +- src/compiler/llvm_codegen_type.c | 10 +- src/compiler/parse_global.c | 54 +++---- src/compiler/parse_stmt.c | 2 +- src/compiler/sema_casts.c | 58 +++---- src/compiler/sema_decls.c | 152 +++++++++--------- src/compiler/sema_expr.c | 30 ++-- src/compiler/sema_initializers.c | 2 +- src/compiler/sema_internal.h | 2 +- src/compiler/sema_liveness.c | 4 +- src/compiler/sema_name_resolution.c | 24 +-- src/compiler/sema_passes.c | 24 +-- src/compiler/sema_types.c | 8 +- src/compiler/semantic_analyser.c | 6 +- src/compiler/tokens.c | 4 +- src/compiler/types.c | 66 ++++---- src/version.h | 2 +- test/test_suite/dynamic/any_cast.c3 | 6 +- .../dynamic/duplicate_definition.c3 | 2 +- test/test_suite/dynamic/dynamic_mismatch.c3 | 2 +- .../dynamic/dynamic_with_default.c3t | 2 +- test/test_suite/dynamic/inherit.c3t | 6 +- test/test_suite/dynamic/null_and_protocol.c3t | 2 +- .../dynamic/overlapping_function.c3t | 4 +- test/test_suite/dynamic/same_method_twice.c3 | 2 +- test/unit/regression/liveness_any.c3 | 2 +- 48 files changed, 322 insertions(+), 325 deletions(-) diff --git a/lib/std/core/mem_allocator.c3 b/lib/std/core/mem_allocator.c3 index 1b81c49b8..4f4fa1374 100644 --- a/lib/std/core/mem_allocator.c3 +++ b/lib/std/core/mem_allocator.c3 @@ -3,7 +3,7 @@ module std::core::mem::allocator; const DEFAULT_SIZE_PREFIX = usz.sizeof; const DEFAULT_SIZE_PREFIX_ALIGNMENT = usz.alignof; -protocol Allocator +interface Allocator { fn void reset(usz mark) @optional; fn usz mark() @optional; diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index 1cfd29ca0..42676229a 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -4,7 +4,7 @@ import libc; const int PRINTF_NTOA_BUFFER_SIZE = 256; -protocol Printable +interface Printable { fn String to_string(Allocator *using) @optional; fn usz! to_format(Formatter* formatter) @optional; diff --git a/lib/std/math/math.random.c3 b/lib/std/math/math.random.c3 index ce1bc6bd4..d95c8097d 100644 --- a/lib/std/math/math.random.c3 +++ b/lib/std/math/math.random.c3 @@ -1,6 +1,6 @@ module std::math::random; -protocol Random +interface Random { fn void set_seed(char[] input); fn char next_byte(); diff --git a/releasenotes.md b/releasenotes.md index f31dfe32a..39209db28 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -36,7 +36,7 @@ - Delete object files after successful linking. - Compile time subscript of constant strings and bytes. - `@if` introduced, other top level conditional compilation removed. -- Dynamically dispatched protocols with optional methods. +- Dynamically dispatched interfaces with optional methods. - `$if` now uses `$if :` syntax. - `$assert` now uses `$assert : ` - `$error` is syntax sugar for `$assert false : "Some message"` diff --git a/resources/grammar/c3.l b/resources/grammar/c3.l index 77f44f40e..5c0c02af0 100644 --- a/resources/grammar/c3.l +++ b/resources/grammar/c3.l @@ -107,7 +107,6 @@ int comment_level = 0; "extern" { count(); return(EXTERN); } "false" { count(); return(FALSE); } "fault" { count(); return(FAULT); } -"finalize" { count(); return(FINALIZE); } "float" { count(); return(FLOAT); } "bfloat16" { count(); return(BFLOAT16); } "float16" { count(); return(FLOAT16); } @@ -119,10 +118,10 @@ int comment_level = 0; "ichar" { count(); return(ICHAR); } "if" { count(); return(IF); } "import" { count(); return(IMPORT); } -"initialize" { count(); return(INITIALIZE); } "inline" { count(); return(INLINE); } "int" { count(); return(INT); } "int128" { count(); return(INT128); } +"interface" { count(); return(INTERFACE); } "iptr" { count(); return(IPTR); } "isz" { count(); return(ISZ); } "long" { count(); return(LONG); } @@ -130,7 +129,6 @@ int comment_level = 0; "module" { count(); return(MODULE); } "nextcase" { count(); return(NEXTCASE); } "null" { count(); return(NUL); } -"protocol" { count(); return(PROTOCOL); } "return" { count(); return(RETURN); } "short" { count(); return(SHORT); } "struct" { count(); return(STRUCT); } diff --git a/resources/grammar/grammar.y b/resources/grammar/grammar.y index 3499130b4..d87af8566 100644 --- a/resources/grammar/grammar.y +++ b/resources/grammar/grammar.y @@ -25,9 +25,9 @@ void yyerror(char *s); %token STRUCT UNION ENUM ELLIPSIS DOTDOT BYTES %token CT_ERROR -%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR CONTINUE BREAK RETURN FOREACH_R FOREACH PROTOCOL +%token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR CONTINUE BREAK RETURN FOREACH_R FOREACH INTERFACE %token FN FAULT MACRO CT_IF CT_ENDIF CT_ELSE CT_SWITCH CT_CASE CT_DEFAULT CT_FOR CT_FOREACH CT_ENDFOREACH -%token CT_ENDFOR CT_ENDSWITCH BUILTIN IMPLIES INITIALIZE FINALIZE CT_ECHO CT_ASSERT CT_EVALTYPE CT_VATYPE +%token CT_ENDFOR CT_ENDSWITCH BUILTIN IMPLIES CT_ECHO CT_ASSERT CT_EVALTYPE CT_VATYPE %token TRY CATCH SCOPE DEFER LVEC RVEC OPTELSE CT_TYPEFROM CT_TYPEOF TLOCAL %token CT_VASPLAT INLINE DISTINCT CT_VACONST CT_NAMEOF CT_VAREF CT_VACOUNT CT_VAARG %token CT_SIZEOF CT_STRINGIFY CT_QNAMEOF CT_OFFSETOF CT_VAEXPR CT_FEATURE @@ -454,13 +454,13 @@ opt_arg_list_trailing | empty ; -protocols +interfaces : TYPE_IDENT opt_generic_parameters - | protocols ',' TYPE_IDENT opt_generic_parameters + | interfaces ',' TYPE_IDENT opt_generic_parameters ; -opt_protocol_impl - : '(' protocols ')' +opt_interface_impl + : '(' interfaces ')' | '(' ')' | empty ; @@ -901,7 +901,7 @@ ct_echo_stmt : CT_ECHO constant_expr ';' bitstruct_declaration - : BITSTRUCT TYPE_IDENT opt_protocol_impl ':' type opt_attributes bitstruct_body + : BITSTRUCT TYPE_IDENT opt_interface_impl ':' type opt_attributes bitstruct_body bitstruct_body : '{' '}' @@ -924,10 +924,6 @@ bitstruct_def | base_type IDENT ':' constant_expr ';' ; -static_declaration - : STATIC INITIALIZE opt_attributes compound_statement - | STATIC FINALIZE opt_attributes compound_statement - ; attribute_name : AT_IDENT @@ -994,7 +990,7 @@ struct_or_union ; struct_declaration - : struct_or_union TYPE_IDENT opt_protocol_impl opt_attributes struct_body + : struct_or_union TYPE_IDENT opt_interface_impl opt_attributes struct_body ; struct_body @@ -1034,7 +1030,7 @@ enum_spec ; enum_declaration - : ENUM TYPE_IDENT opt_protocol_impl enum_spec opt_attributes '{' enum_list '}' + : ENUM TYPE_IDENT opt_interface_impl enum_spec opt_attributes '{' enum_list '}' ; faults @@ -1043,8 +1039,8 @@ faults ; fault_declaration - : FAULT TYPE_IDENT opt_protocol_impl opt_attributes '{' faults '}' - | FAULT TYPE_IDENT opt_protocol_impl opt_attributes '{' faults ',' '}' + : FAULT TYPE_IDENT opt_interface_impl opt_attributes '{' faults '}' + | FAULT TYPE_IDENT opt_interface_impl opt_attributes '{' faults ',' '}' ; func_macro_name @@ -1186,23 +1182,27 @@ define_declaration | DEF TYPE_IDENT opt_attributes '=' typedef_type opt_attributes ';' ; -protocol_body +interface_body : func_typedef - | protocol_body func_typedef + | interface_body func_typedef ; -protocol_declaration - : PROTOCOL TYPE_IDENT '{' '}' - | PROTOCOL TYPE_IDENT '{' protocol_body '}' +interface_declaration + : INTERFACE TYPE_IDENT '{' '}' + | INTERFACE TYPE_IDENT '{' interface_body '}' ; distinct_declaration - : DISTINCT TYPE_IDENT opt_protocol_impl opt_attributes '=' opt_inline type opt_generic_parameters ';' + : DISTINCT TYPE_IDENT opt_interface_impl opt_attributes '=' opt_inline type opt_generic_parameters ';' ; tl_ct_if - : CT_IF constant_expr ':' opt_tl_stmts CT_ENDIF - | CT_IF constant_expr ':' opt_tl_stmts CT_ELSE opt_tl_stmts CT_ENDIF + : CT_IF constant_expr ':' opt_tl_stmts tl_ct_if_tail + ; + +tl_ct_if_tail + : CT_ENDIF + | CT_ELSE opt_tl_stmts CT_ENDIF ; tl_ct_switch @@ -1264,10 +1264,9 @@ top_level | enum_declaration | macro_declaration | define_declaration - | static_declaration | bitstruct_declaration | distinct_declaration - | protocol_declaration + | interface_declaration ; diff --git a/src/compiler/abi/c_abi_x64.c b/src/compiler/abi/c_abi_x64.c index 1b88308b5..2a65f330b 100644 --- a/src/compiler/abi/c_abi_x64.c +++ b/src/compiler/abi/c_abi_x64.c @@ -383,7 +383,7 @@ static void x64_classify(Type *type, ByteSize offset_base, X64Class *lo_class, X case LOWERED_TYPES: case TYPE_FUNC: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: UNREACHABLE case TYPE_VOID: *current = CLASS_NO_CLASS; @@ -566,7 +566,7 @@ AbiType x64_get_int_type_at_offset(Type *type, unsigned offset, Type *source_typ case TYPE_VOID: case TYPE_FUNC: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: UNREACHABLE case TYPE_U64: case TYPE_I64: diff --git a/src/compiler/abi/c_abi_x86.c b/src/compiler/abi/c_abi_x86.c index 8387ec499..4c04d87ce 100644 --- a/src/compiler/abi/c_abi_x86.c +++ b/src/compiler/abi/c_abi_x86.c @@ -120,9 +120,9 @@ static bool x86_should_return_type_in_reg(Type *type) case CT_TYPES: case TYPE_OPTIONAL: case TYPE_FLEXIBLE_ARRAY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: - case TYPE_PROPTR: + case TYPE_INFPTR: UNREACHABLE case ALL_INTS: case ALL_FLOATS: @@ -460,7 +460,7 @@ static ABIArgInfo *x86_classify_argument(CallABI call, Regs *regs, Type *type) case TYPE_VOID: case TYPE_FUNC: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_FLEXIBLE_ARRAY: UNREACHABLE case ALL_FLOATS: diff --git a/src/compiler/ast.c b/src/compiler/ast.c index 73be2bcbe..fe287e673 100644 --- a/src/compiler/ast.c +++ b/src/compiler/ast.c @@ -54,8 +54,8 @@ Decl *decl_new_with_type(const char *name, SourceSpan loc, DeclKind decl_type) case DECL_FNTYPE: case DECL_FUNC: UNREACHABLE - case DECL_PROTOCOL: - kind = TYPE_PROTOCOL; + case DECL_INTERFACE: + kind = TYPE_INTERFACE; break; case DECL_UNION: kind = TYPE_UNION; @@ -122,7 +122,7 @@ const char *decl_to_a_name(Decl *decl) case DECL_LABEL: return "a label"; case DECL_MACRO: return "a macro"; case DECL_POISONED: return "a poisoned decl"; - case DECL_PROTOCOL: return "a protocol"; + case DECL_INTERFACE: return "an interface"; case DECL_STRUCT: return "a struct"; case DECL_UNION: return "a union"; case DECL_VAR: diff --git a/src/compiler/codegen_general.c b/src/compiler/codegen_general.c index 521a088ca..4b4ae6e35 100644 --- a/src/compiler/codegen_general.c +++ b/src/compiler/codegen_general.c @@ -173,7 +173,7 @@ bool type_is_homogenous_aggregate(Type *type, Type **base, unsigned *elements) { case LOWERED_TYPES: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: UNREACHABLE; case TYPE_VOID: case TYPE_FUNC: diff --git a/src/compiler/codegen_internal.h b/src/compiler/codegen_internal.h index 0b79e7c06..83266ff63 100644 --- a/src/compiler/codegen_internal.h +++ b/src/compiler/codegen_internal.h @@ -36,7 +36,7 @@ static inline Type *type_lowering(Type *type) case TYPE_ENUM: type = type->decl->enums.type_info->type; continue; - case TYPE_PROPTR: + case TYPE_INFPTR: return type_anyptr; case TYPE_ANYFAULT: case TYPE_TYPEID: diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 34989314e..8ab1a318a 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -561,14 +561,14 @@ typedef struct bool attr_optional : 1; bool attr_init : 1; bool attr_finalizer : 1; - bool attr_protocol_method : 1; + bool attr_interface_method : 1; bool attr_dynamic : 1; bool attr_default : 1; bool is_lambda : 1; union { uint32_t priority; - DeclId protocol_method; + DeclId interface_method; DeclId default_method; Decl **generated_lambda; Decl **lambda_ct_parameters; @@ -696,7 +696,7 @@ typedef struct Decl_ Decl** decl_list; struct { - TypeInfo **protocols; + TypeInfo **interfaces; Decl **methods; union { @@ -706,7 +706,7 @@ typedef struct Decl_ TypeInfo *distinct; // Unions, Struct use strukt StructDecl strukt; - Decl **protocol_methods; + Decl **interface_methods; }; }; AttrDecl attr_decl; @@ -2588,19 +2588,19 @@ INLINE bool type_is_any_raw(Type *type) switch (type->type_kind) { case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: return true; default: return false; } } -INLINE bool type_is_any_protocol_ptr(Type *type) +INLINE bool type_is_any_interface_ptr(Type *type) { switch (type->canonical->type_kind) { case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: return true; default: return false; @@ -2623,7 +2623,7 @@ INLINE bool type_is_optional(Type *type) return kind == TYPE_OPTIONAL; } -INLINE bool type_may_implement_protocol(Type *type) +INLINE bool type_may_implement_interface(Type *type) { DECL_TYPE_KIND_REAL(kind, type); switch (kind) diff --git a/src/compiler/context.c b/src/compiler/context.c index 9e1777fda..4529ade3c 100644 --- a/src/compiler/context.c +++ b/src/compiler/context.c @@ -148,7 +148,7 @@ void decl_register(Decl *decl) case DECL_MACRO: case DECL_VAR: case DECL_FNTYPE: - case DECL_PROTOCOL: + case DECL_INTERFACE: global_context_add_decl(decl); break; } @@ -198,7 +198,7 @@ void unit_register_global_decl(CompilationUnit *unit, Decl *decl) decl_set_external_name(decl); decl_register(decl); break; - case DECL_PROTOCOL: + case DECL_INTERFACE: case DECL_DISTINCT: case DECL_STRUCT: case DECL_UNION: diff --git a/src/compiler/copying.c b/src/compiler/copying.c index 157354a8b..fe7b8c4aa 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -879,10 +879,10 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) break; case DECL_ERASED: break; - case DECL_PROTOCOL: - MACRO_COPY_TYPE_LIST(copy->protocols); + case DECL_INTERFACE: + MACRO_COPY_TYPE_LIST(copy->interfaces); MACRO_COPY_DECL_LIST(copy->methods); - MACRO_COPY_DECL_LIST(copy->protocol_methods); + MACRO_COPY_DECL_LIST(copy->interface_methods); break; case DECL_CT_EXEC: MACRO_COPY_EXPR(copy->exec_decl.filename); @@ -897,7 +897,7 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) case DECL_UNION: case DECL_STRUCT: copy_decl_type(copy); - MACRO_COPY_TYPE_LIST(copy->protocols); + MACRO_COPY_TYPE_LIST(copy->interfaces); MACRO_COPY_DECL_LIST(copy->strukt.members); MACRO_COPY_DECL_LIST(copy->methods); break; @@ -906,7 +906,7 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) UNREACHABLE case DECL_BITSTRUCT: copy_decl_type(copy); - MACRO_COPY_TYPE_LIST(copy->protocols); + MACRO_COPY_TYPE_LIST(copy->interfaces); MACRO_COPY_DECL_LIST(copy->bitstruct.members); MACRO_COPY_TYPE(copy->bitstruct.base_type); MACRO_COPY_DECL_LIST(copy->methods); @@ -914,7 +914,7 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) case DECL_ENUM: case DECL_FAULT: copy_decl_type(copy); - MACRO_COPY_TYPE_LIST(copy->protocols); + MACRO_COPY_TYPE_LIST(copy->interfaces); MACRO_COPY_DECL_LIST(copy->methods); MACRO_COPY_DECL_LIST(copy->enums.parameters); MACRO_COPY_TYPE(copy->enums.type_info); @@ -970,7 +970,7 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) break; case DECL_DISTINCT: copy_decl_type(copy); - MACRO_COPY_TYPE_LIST(copy->protocols); + MACRO_COPY_TYPE_LIST(copy->interfaces); MACRO_COPY_DECL_LIST(copy->methods); MACRO_COPY_TYPE(copy->distinct); break; diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 8085f897d..087b8810b 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -147,7 +147,7 @@ typedef enum DECL_IMPORT, DECL_LABEL, DECL_MACRO, - DECL_PROTOCOL, + DECL_INTERFACE, DECL_STRUCT, DECL_TYPEDEF, DECL_UNION, @@ -200,7 +200,7 @@ typedef enum INTROSPECT_TYPE_VECTOR = 17, INTROSPECT_TYPE_DISTINCT = 18, INTROSPECT_TYPE_POINTER = 19, - INTROSPECT_TYPE_PROTOCOL = 20, + INTROSPECT_TYPE_INTERFACE = 20, } IntrospectType; typedef enum @@ -547,7 +547,7 @@ typedef enum TOKEN_MODULE, TOKEN_NEXTCASE, TOKEN_NULL, - TOKEN_PROTOCOL, + TOKEN_INTERFACE, TOKEN_RETURN, TOKEN_STATIC, TOKEN_STRUCT, @@ -655,7 +655,7 @@ typedef enum TYPE_NUM_LAST = TYPE_FLOAT_LAST, TYPE_ANY, TYPE_ANYPTR, - TYPE_PROPTR, + TYPE_INFPTR, TYPE_ANYFAULT, TYPE_TYPEID, TYPE_POINTER, @@ -663,7 +663,7 @@ typedef enum TYPE_FUNC, TYPE_STRUCT, TYPE_UNION, - TYPE_PROTOCOL, + TYPE_INTERFACE, TYPE_BITSTRUCT, TYPE_FAULTTYPE, TYPE_TYPEDEF, @@ -687,7 +687,7 @@ typedef enum #define FLATTENED_TYPES TYPE_DISTINCT: case TYPE_OPTIONAL: case TYPE_TYPEDEF #define LOWERED_TYPES CT_TYPES: case TYPE_ENUM: case TYPE_TYPEDEF: case TYPE_TYPEID: \ case TYPE_DISTINCT: case TYPE_ANYFAULT: case TYPE_FAULTTYPE: case TYPE_BITSTRUCT: \ - case TYPE_OPTIONAL: case TYPE_PROPTR + case TYPE_OPTIONAL: case TYPE_INFPTR #define CT_TYPES TYPE_TYPEINFO: case TYPE_INFERRED_ARRAY: case TYPE_INFERRED_VECTOR: case TYPE_UNTYPED_LIST: \ case TYPE_POISONED: case TYPE_MEMBER: case TYPE_WILDCARD #define ALL_INTS TYPE_I8: case TYPE_I16: case TYPE_I32: case TYPE_I64: case TYPE_I128: \ @@ -758,7 +758,7 @@ typedef enum ATTR_MACRO = 1 << 14, ATTR_DISTINCT = 1 << 15, ATTR_ENUM_VALUE = 1 << 16, - ATTR_PROTOCOL_METHOD = 1 << 17 + ATTR_INTERFACE_METHOD = 1 << 17 } AttributeDomain; typedef enum @@ -836,7 +836,7 @@ typedef enum ANALYSIS_CT_ECHO, ANALYSIS_CT_ASSERT, ANALYSIS_FUNCTIONS, - ANALYSIS_PROTOCOL, + ANALYSIS_INTERFACE, ANALYSIS_FINALIZE, ANALYSIS_LAST = ANALYSIS_FINALIZE } AnalysisStage; @@ -1066,7 +1066,7 @@ typedef enum CONV_STRUCT, CONV_UNION, CONV_ANY, - CONV_PROTOCOL, + CONV_INTERFACE, CONV_FAULT, CONV_ENUM, CONV_TYPEID, diff --git a/src/compiler/expr.c b/src/compiler/expr.c index 86ef7c39e..a241befa1 100644 --- a/src/compiler/expr.c +++ b/src/compiler/expr.c @@ -564,7 +564,7 @@ void expr_rewrite_to_const_zero(Expr *expr, Type *type) case TYPE_INFERRED_VECTOR: case TYPE_WILDCARD: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: UNREACHABLE case ALL_INTS: expr_rewrite_const_int(expr, type, 0); @@ -578,7 +578,7 @@ void expr_rewrite_to_const_zero(Expr *expr, Type *type) case TYPE_POINTER: case TYPE_FAULTTYPE: case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_ANYFAULT: case TYPE_TYPEID: expr_rewrite_const_null(expr, type); diff --git a/src/compiler/headers.c b/src/compiler/headers.c index b2d389425..d66ed3bbf 100644 --- a/src/compiler/headers.c +++ b/src/compiler/headers.c @@ -47,7 +47,7 @@ static void header_print_type(FILE *file, Type *type) { case CT_TYPES: case TYPE_OPTIONAL: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: UNREACHABLE case TYPE_VOID: @@ -136,7 +136,7 @@ static void header_print_type(FILE *file, Type *type) OUTPUT(" arr[%d]; }", type->array.len); return; case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: OUTPUT("c3any_t"); return; case TYPE_SUBARRAY: @@ -314,7 +314,7 @@ static void header_gen_type_decl(FILE *file, int indent, Decl *decl) return; case DECL_TYPEDEF: case DECL_DISTINCT: - case DECL_PROTOCOL: + case DECL_INTERFACE: // Ignore return; case DECL_STRUCT: @@ -370,7 +370,7 @@ RETRY: case TYPE_MEMBER: case TYPE_INFERRED_VECTOR: case TYPE_WILDCARD: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: UNREACHABLE case TYPE_VOID: @@ -383,7 +383,7 @@ RETRY: case TYPE_FAULTTYPE: case TYPE_SUBARRAY: case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: return; case TYPE_POINTER: type = type->pointer; diff --git a/src/compiler/json_output.c b/src/compiler/json_output.c index 1e5e99f44..ca2ae27d1 100644 --- a/src/compiler/json_output.c +++ b/src/compiler/json_output.c @@ -52,7 +52,7 @@ static inline const char *decl_type_to_string(Decl *type) case DECL_GLOBALS: return "global"; case DECL_IMPORT: return "import"; case DECL_MACRO: return "macro"; - case DECL_PROTOCOL: return "protocol"; + case DECL_INTERFACE: return "interface"; case DECL_STRUCT: return "struct"; case DECL_UNION: return "union"; case DECL_TYPEDEF: return "typedef"; diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 91837a789..a67f41f4d 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -842,7 +842,7 @@ static void llvm_emit_type_decls(GenContext *context, Decl *decl) case DECL_FUNC: // Never directly invoked. UNREACHABLE - case DECL_PROTOCOL: + case DECL_INTERFACE: break; case DECL_DISTINCT: case DECL_STRUCT: @@ -1098,7 +1098,7 @@ LLVMValueRef llvm_get_ref(GenContext *c, Decl *decl) } return decl->backend_ref; case DECL_FUNC: - if (decl->func_decl.attr_protocol_method) + if (decl->func_decl.attr_interface_method) { return decl->backend_ref = llvm_get_selector(c, decl->name); } @@ -1143,7 +1143,7 @@ LLVMValueRef llvm_get_ref(GenContext *c, Decl *decl) case DECL_CT_EXEC: case DECL_CT_INCLUDE: case DECL_GLOBALS: - case DECL_PROTOCOL: + case DECL_INTERFACE: UNREACHABLE; } UNREACHABLE diff --git a/src/compiler/llvm_codegen_debug_info.c b/src/compiler/llvm_codegen_debug_info.c index e59bb93e8..c8c383c4a 100644 --- a/src/compiler/llvm_codegen_debug_info.c +++ b/src/compiler/llvm_codegen_debug_info.c @@ -554,7 +554,7 @@ static inline LLVMMetadataRef llvm_get_debug_type_internal(GenContext *c, Type * switch (type->type_kind) { case CT_TYPES: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: UNREACHABLE case TYPE_BITSTRUCT: @@ -609,7 +609,7 @@ static inline LLVMMetadataRef llvm_get_debug_type_internal(GenContext *c, Type * return type->backend_debug_type = llvm_debug_subarray_type(c, type); case TYPE_ANYFAULT: return type->backend_debug_type = llvm_debug_errunion_type(c, type); - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_ANYPTR: return type->backend_debug_type = llvm_debug_any_type(c, type); } diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index a233eae7d..313b82161 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -2607,7 +2607,7 @@ static void llvm_emit_unary_expr(GenContext *c, BEValue *value, Expr *expr) llvm_value = LLVMBuildIsNull(c->builder, value->value, "not"); break; case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: llvm_emit_any_pointer(c, value, value); llvm_value_rvalue(c, value); llvm_value = LLVMBuildIsNull(c->builder, value->value, "not"); @@ -3796,7 +3796,7 @@ void llvm_emit_comp(GenContext *c, BEValue *result, BEValue *lhs, BEValue *rhs, return; case LOWERED_TYPES: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_STRUCT: case TYPE_UNION: case TYPE_FLEXIBLE_ARRAY: @@ -4906,7 +4906,7 @@ static void llvm_expand_type_to_args(GenContext *context, Type *param_type, LLVM case TYPE_VOID: case TYPE_FUNC: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_FLEXIBLE_ARRAY: UNREACHABLE break; @@ -5923,7 +5923,7 @@ static void llvm_emit_call_expr(GenContext *c, BEValue *result_value, Expr *expr LLVMValueRef cmp = LLVMBuildICmp(c->builder, LLVMIntEQ, func, LLVMConstNull(c->ptr_type), ""); llvm_emit_cond_br_raw(c, cmp, missing_function, match); llvm_emit_block(c, missing_function); - Decl *default_method = declptrzero(dyn_fn->func_decl.protocol_method); + Decl *default_method = declptrzero(dyn_fn->func_decl.interface_method); if (default_method) { LLVMBasicBlockRef after = llvm_basic_block_new(c, "after_call"); diff --git a/src/compiler/llvm_codegen_function.c b/src/compiler/llvm_codegen_function.c index 91c631034..0862891af 100644 --- a/src/compiler/llvm_codegen_function.c +++ b/src/compiler/llvm_codegen_function.c @@ -692,7 +692,7 @@ void llvm_emit_dynamic_functions(GenContext *c, Decl **funcs) scratch_buffer_append("$ct.dyn."); scratch_buffer_append(decl_get_extname(decl)); LLVMValueRef global = llvm_add_global_raw(c, scratch_buffer_to_string(), c->dtable_type, 0); - Decl *proto = declptrzero(decl->func_decl.protocol_method); + Decl *proto = declptrzero(decl->func_decl.interface_method); LLVMValueRef proto_ref = proto ? llvm_get_ref(c, proto) : llvm_get_selector(c, decl->name); LLVMValueRef vals[3] = { llvm_get_ref(c, decl), proto_ref, LLVMConstNull(c->ptr_type) }; LLVMSetInitializer(global, LLVMConstNamedStruct(c->dtable_type, vals, 3)); diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h index a48c79e40..b8980396c 100644 --- a/src/compiler/llvm_codegen_internal.h +++ b/src/compiler/llvm_codegen_internal.h @@ -491,7 +491,7 @@ static inline LLVMCallConv llvm_call_convention_from_call(CallABI abi); void llvm_emit_raw_call(GenContext *c, BEValue *result_value, FunctionPrototype *prototype, LLVMTypeRef func_type, LLVMValueRef func, LLVMValueRef *args, unsigned arg_count, int inline_flag, LLVMValueRef error_var, bool sret_return, BEValue *synthetic_return_param); void llvm_emit_parameter(GenContext *c, LLVMValueRef *args, unsigned *arg_count_ref, ABIArgInfo *info, BEValue *be_value, Type *type); -// -- Dynamic protocol -- +// -- Dynamic interface -- LLVMValueRef llvm_get_selector(GenContext *c, const char *name); // -- C3 Lowering -- diff --git a/src/compiler/llvm_codegen_type.c b/src/compiler/llvm_codegen_type.c index eec389a76..8f8d9aff1 100644 --- a/src/compiler/llvm_codegen_type.c +++ b/src/compiler/llvm_codegen_type.c @@ -17,7 +17,7 @@ static inline LLVMTypeRef llvm_type_from_decl(GenContext *c, Decl *decl) case DECL_ERASED: case NON_TYPE_DECLS: case DECL_FNTYPE: - case DECL_PROTOCOL: + case DECL_INTERFACE: UNREACHABLE case DECL_BITSTRUCT: return llvm_get_type(c, decl->bitstruct.base_type->type); @@ -316,7 +316,7 @@ LLVMTypeRef llvm_get_type(GenContext *c, Type *any_type) // If this is reachable, then we're not doing the proper lowering. UNREACHABLE case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: UNREACHABLE case TYPE_STRUCT: case TYPE_UNION: @@ -644,8 +644,8 @@ LLVMValueRef llvm_get_typeid(GenContext *c, Type *type) return llvm_generate_introspection_global(c, NULL, type, INTROSPECT_TYPE_SUBARRAY, type->array.base, 0, NULL, false); case TYPE_ANYPTR: return llvm_generate_introspection_global(c, NULL, type, INTROSPECT_TYPE_ANY, NULL, 0, NULL, false); - case TYPE_PROPTR: - return llvm_generate_introspection_global(c, NULL, type, INTROSPECT_TYPE_PROTOCOL, NULL, 0, NULL, false); + case TYPE_INFPTR: + 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: @@ -673,7 +673,7 @@ LLVMValueRef llvm_get_typeid(GenContext *c, Type *type) return llvm_get_typeid(c, type->canonical); case CT_TYPES: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: UNREACHABLE case TYPE_VOID: return llvm_get_introspection_for_builtin_type(c, type, INTROSPECT_TYPE_VOID, 0); diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index 68a2be328..c901fea92 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -695,21 +695,21 @@ TypeInfo *parse_optional_type(ParseContext *c) // --- Decl parsing -bool parse_protocol_impls(ParseContext *c, TypeInfo ***protocols_ref) +bool parse_interface_impls(ParseContext *c, TypeInfo ***interfaces_ref) { if (!try_consume(c, TOKEN_LPAREN)) return true; - TypeInfo **protocols = NULL; + TypeInfo **interfaces = NULL; while (!try_consume(c, TOKEN_RPAREN)) { - ASSIGN_TYPE_OR_RET(TypeInfo *protocol, parse_type(c), false); - vec_add(protocols, protocol); + ASSIGN_TYPE_OR_RET(TypeInfo *interface, parse_type(c), false); + vec_add(interfaces, interface); if (!try_consume(c, TOKEN_COMMA)) { CONSUME_OR_RET(TOKEN_RPAREN, false); break; } } - *protocols_ref = protocols; + *interfaces_ref = interfaces; return true; } @@ -1535,7 +1535,7 @@ bool parse_struct_body(ParseContext *c, Decl *parent) /** - * distinct_declaration ::= 'distinct' TYPE_IDENT opt_protocols '=' 'inline'? type ';' + * distinct_declaration ::= 'distinct' TYPE_IDENT opt_interfaces '=' 'inline'? type ';' */ static inline Decl *parse_distinct_declaration(ParseContext *c) { @@ -1544,7 +1544,7 @@ static inline Decl *parse_distinct_declaration(ParseContext *c) Decl *decl = decl_new_with_type(symstr(c), c->span, DECL_DISTINCT); if (!consume_type_name(c, "distinct type")) return poisoned_decl; - if (!parse_protocol_impls(c, &decl->protocols)) return poisoned_decl; + if (!parse_interface_impls(c, &decl->interfaces)) return poisoned_decl; if (!parse_attributes_for_global(c, decl)) return poisoned_decl; @@ -1566,7 +1566,7 @@ static inline Decl *parse_distinct_declaration(ParseContext *c) } /** - * struct_declaration ::= struct_or_union TYPE_IDENT opt_protocols opt_attributes struct_body + * struct_declaration ::= struct_or_union TYPE_IDENT opt_interfaces opt_attributes struct_body */ static inline Decl *parse_struct_declaration(ParseContext *c) { @@ -1578,7 +1578,7 @@ static inline Decl *parse_struct_declaration(ParseContext *c) Decl *decl = decl_new_with_type(symstr(c), c->span, decl_from_token(type)); if (!consume_type_name(c, type_name)) return poisoned_decl; - if (!parse_protocol_impls(c, &decl->protocols)) return poisoned_decl; + if (!parse_interface_impls(c, &decl->interfaces)) return poisoned_decl; if (!parse_attributes_for_global(c, decl)) return poisoned_decl; if (!parse_struct_body(c, decl)) return poisoned_decl; @@ -1654,7 +1654,7 @@ static inline bool parse_bitstruct_body(ParseContext *c, Decl *decl) return true; } -INLINE bool parse_protocol_body(ParseContext *c, Decl *protocol) +INLINE bool parse_interface_body(ParseContext *c, Decl *interface) { CONSUME_OR_RET(TOKEN_LBRACE, false); Decl **fns = NULL; @@ -1662,20 +1662,20 @@ INLINE bool parse_protocol_body(ParseContext *c, Decl *protocol) { AstId contracts = 0; if (!parse_contracts(c, &contracts)) return poisoned_decl; - ASSIGN_DECL_OR_RET(Decl *protocol_fn, parse_func_definition(c, contracts, true), false); - vec_add(fns, protocol_fn); + ASSIGN_DECL_OR_RET(Decl *interface_fn, parse_func_definition(c, contracts, true), false); + vec_add(fns, interface_fn); } - protocol->protocol_methods = fns; + interface->interface_methods = fns; return true; } /** - * protocol_declaration ::= 'protocol' TYPE_IDENT ':' (TYPE_IDENT (',' TYPE_IDENT) protocol_body + * interface_declaration ::= 'interface' TYPE_IDENT ':' (TYPE_IDENT (',' TYPE_IDENT) interface_body */ -static inline Decl *parse_protocol_declaration(ParseContext *c) +static inline Decl *parse_interface_declaration(ParseContext *c) { - advance_and_verify(c, TOKEN_PROTOCOL); - Decl *decl = decl_new_with_type(symstr(c), c->span, DECL_PROTOCOL); - if (!consume_type_name(c, "protocol")) return poisoned_decl; + advance_and_verify(c, TOKEN_INTERFACE); + Decl *decl = decl_new_with_type(symstr(c), c->span, DECL_INTERFACE); + if (!consume_type_name(c, "interface")) return poisoned_decl; TypeInfo **parents = NULL; if (try_consume(c, TOKEN_COLON)) { @@ -1685,8 +1685,8 @@ static inline Decl *parse_protocol_declaration(ParseContext *c) vec_add(parents, type); } while (try_consume(c, TOKEN_COMMA)); } - decl->protocols = parents; - if (!parse_protocol_body(c, decl)) return poisoned_decl; + decl->interfaces = parents; + if (!parse_interface_body(c, decl)) return poisoned_decl; return decl; } /** @@ -2111,7 +2111,7 @@ static inline Decl *parse_macro_declaration(ParseContext *c, AstId docs) /** - * fault_declaration ::= FAULT TYPE_IDENT opt_protocols opt_attributes '{' faults ','? '}' + * fault_declaration ::= FAULT TYPE_IDENT opt_interfaces opt_attributes '{' faults ','? '}' */ static inline Decl *parse_fault_declaration(ParseContext *c) { @@ -2119,7 +2119,7 @@ static inline Decl *parse_fault_declaration(ParseContext *c) Decl *decl = decl_new_with_type(symstr(c), c->span, DECL_FAULT); if (!consume_type_name(c, "fault")) return poisoned_decl; - if (!parse_protocol_impls(c, &decl->protocols)) return poisoned_decl; + if (!parse_interface_impls(c, &decl->interfaces)) return poisoned_decl; if (!parse_attributes_for_global(c, decl)) return poisoned_decl; @@ -2190,7 +2190,7 @@ static inline bool parse_enum_param_list(ParseContext *c, Decl*** parameters_ref /** * Parse an enum declaration (after "enum") * - * enum ::= ENUM TYPE_IDENT opt_protocols (':' type enum_param_list)? opt_attributes '{' enum_body '}' + * enum ::= ENUM TYPE_IDENT opt_interfaces (':' type enum_param_list)? opt_attributes '{' enum_body '}' * enum_body ::= enum_def (',' enum_def)* ','? * enum_def ::= CONST_IDENT ('(' arg_list ')')? */ @@ -2200,7 +2200,7 @@ static inline Decl *parse_enum_declaration(ParseContext *c) Decl *decl = decl_new_with_type(symstr(c), c->span, DECL_ENUM); if (!consume_type_name(c, "enum")) return poisoned_decl; - if (!parse_protocol_impls(c, &decl->protocols)) return poisoned_decl; + if (!parse_interface_impls(c, &decl->interfaces)) return poisoned_decl; TypeInfo *type = NULL; // Parse the spec @@ -2681,7 +2681,7 @@ static Decl *parse_exec(ParseContext *c) * top_level_statement ::= struct_declaration | enum_declaration | fault_declaration | const_declaration * | global_declaration | macro_declaration | func_definition | typedef_declaration * | conditional_compilation | define_declaration | import_declaration | module_declaration - * | distinct_declaration | protocol_declaration + * | distinct_declaration | interface_declaration * | static_declaration | ct_assert_declaration | ct_echo_declaration | bitstruct_declaration * * @return Decl* or a poison value if parsing failed @@ -2799,9 +2799,9 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **c_ref) if (contracts) goto CONTRACT_NOT_ALLOWED; decl = parse_bitstruct_declaration(c); break; - case TOKEN_PROTOCOL: + case TOKEN_INTERFACE: if (contracts) goto CONTRACT_NOT_ALLOWED; - decl = parse_protocol_declaration(c); + decl = parse_interface_declaration(c); break; case TOKEN_DISTINCT: if (contracts) goto CONTRACT_NOT_ALLOWED; diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 3228436f7..9cff262f0 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -1363,7 +1363,7 @@ Ast *parse_stmt(ParseContext *c) case TOKEN_CT_INCLUDE: case TOKEN_CT_EXEC: case TOKEN_LGENPAR: - case TOKEN_PROTOCOL: + case TOKEN_INTERFACE: SEMA_ERROR_HERE("Unexpected '%s' found when expecting a statement.", token_type_to_string(c->tok)); advance(c); diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index 69fa2dcf7..abedbf3a5 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -345,7 +345,7 @@ CastKind cast_to_bool_kind(Type *type) case TYPE_POINTER: return CAST_PTRBOOL; case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: return CAST_ANYBOOL; case TYPE_INFERRED_ARRAY: case TYPE_INFERRED_VECTOR: @@ -366,7 +366,7 @@ CastKind cast_to_bool_kind(Type *type) case TYPE_ENUM: case TYPE_MEMBER: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: // Everything else is an error return CAST_ERROR; } @@ -958,39 +958,39 @@ static bool rule_vecarr_to_infer(CastContext *cc, bool is_explicit, bool is_sile return cast_is_allowed(cc, is_explicit, is_silent); } -static bool rule_ptr_to_protocol(CastContext *cc, bool is_explicit, bool is_silent) +static bool rule_ptr_to_interface(CastContext *cc, bool is_explicit, bool is_silent) { if (is_explicit) return true; Type *pointee = cc->from_type->pointer; - if (type_may_implement_protocol(pointee)) + if (type_may_implement_interface(pointee)) { - Type *protocol = cc->to->pointer; + Type *interface = cc->to->pointer; Decl *pointee_decl = pointee->decl; - FOREACH_BEGIN(TypeInfo *protocol_type, pointee_decl->protocols) - if (!sema_resolve_type_info(cc->context, protocol_type, RESOLVE_TYPE_ALLOW_ANY)) return false; - if (protocol_type->type == protocol) return true; + FOREACH_BEGIN(TypeInfo *interface_type, pointee_decl->interfaces) + if (!sema_resolve_type_info(cc->context, interface_type, RESOLVE_TYPE_ALLOW_ANY)) return false; + if (interface_type->type == interface) return true; FOREACH_END(); } if (is_silent) return false; RETURN_SEMA_ERROR(cc->expr, "%s cannot be implicitly cast to %s, but you can use an explicit " - "cast to (unsafely) assume the protocol is implemented.", + "cast to (unsafely) assume the interface is implemented.", type_quoted_error_string(cc->expr->type), type_quoted_error_string(cc->to_type)); } -static bool rule_protocol_to_protocol(CastContext *cc, bool is_explicit, bool is_silent) +static bool rule_interface_to_interface(CastContext *cc, bool is_explicit, bool is_silent) { if (is_explicit) return true; - Type *from_protocol = cc->from_type->pointer; - Type *protocol = cc->to->pointer->canonical; - if (!sema_resolve_type_decl(cc->context, from_protocol)) return false; - FOREACH_BEGIN(TypeInfo *parent, from_protocol->decl->protocols) - if (parent->type->canonical == protocol) return true; + Type *from_interface = cc->from_type->pointer; + Type *interface = cc->to->pointer->canonical; + if (!sema_resolve_type_decl(cc->context, from_interface)) return false; + FOREACH_BEGIN(TypeInfo *parent, from_interface->decl->interfaces) + if (parent->type->canonical == interface) return true; FOREACH_END(); if (is_silent) return false; - RETURN_SEMA_ERROR(cc->expr, "%s is not a parent protocol of %s, but you can insert an explicit cast '(%s)value' to enforce the (unsafe) conversion.", - type_quoted_error_string(cc->to->pointer), type_quoted_error_string(from_protocol), + RETURN_SEMA_ERROR(cc->expr, "%s is not a parent interface of %s, but you can insert an explicit cast '(%s)value' to enforce the (unsafe) conversion.", + type_quoted_error_string(cc->to->pointer), type_quoted_error_string(from_interface), type_to_error_string(cc->to_type)); } @@ -1926,7 +1926,7 @@ static void cast_typeid_to_bool(Expr *expr, Type *to_type) #define RXXDI &rule_to_distinct /* Type -> distinct (match + is explicit) */ #define REXPL &rule_explicit_ok /* Is explicit */ #define _NA__ &rule_not_applicable /* "Not applicable" - should not be seen. */ -#define RIFIF &rule_widen_narrow /* Widen / narrow conversion of int/float */ +#define RWIDE &rule_widen_narrow /* Widen / narrow conversion of int/float */ #define RINFL &rule_int_to_float /* Simple expressions, check sizes */ #define ROKOK &rule_all_ok /* Always works */ #define RINPT &rule_int_to_ptr /* Int -> ptr (explicit + size match) */ @@ -1951,16 +1951,16 @@ static void cast_typeid_to_bool(Expr *expr, Type *to_type) #define RSAFE &rule_sa_to_infer /* Subarray -> infer (only if subarray is constant or can infer) */ #define RVAFE &rule_vecarr_to_infer /* Vec/arr -> infer (if base matches) */ #define RPTFE &rule_ptr_to_infer /* Ptr -> infer (if pointee may infer) */ -#define RPTPC &rule_ptr_to_protocol /* Ptr -> Protocol if the pointee implements it */ -#define RPCPC &rule_protocol_to_protocol /* Protocol -> Protocol if the latter implements all of the former */ +#define RPTIF &rule_ptr_to_interface /* Ptr -> Interface if the pointee implements it */ +#define RIFIF &rule_interface_to_interface/* Interface -> Interface if the latter implements all of the former */ CastRule cast_rules[CONV_LAST + 1][CONV_LAST + 1] = { -// void, wildc, bool, int, float, ptr, sarr, vec, bitst, distc, array, strct, union, any, prot, fault, enum, typid, afaul, voidp, arrpt, infer (to) +// void, wildc, bool, int, float, ptr, sarr, vec, bitst, distc, array, strct, union, any, infc, fault, enum, typid, afaul, voidp, arrpt, infer (to) {_NA__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // VOID (from) {ROKOK, _NA__, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, ROKOK, _NO__}, // WILDCARD {REXPL, _NO__, _NA__, REXPL, REXPL, _NO__, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // BOOL - {REXPL, _NO__, REXPL, RIFIF, RINFL, RINPT, _NO__, ROKOK, RINBS, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, RINEN, _NO__, _NO__, RINPT, RINPT, _NO__}, // INT - {REXPL, _NO__, REXPL, REXPL, RIFIF, _NO__, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // FLOAT - {REXPL, _NO__, REXPL, RPTIN, _NO__, RPTPT, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, ROKOK, RPTPC, _NO__, _NO__, _NO__, _NO__, ROKOK, RPTPT, RPTFE}, // PTR + {REXPL, _NO__, REXPL, RWIDE, RINFL, RINPT, _NO__, ROKOK, RINBS, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, RINEN, _NO__, _NO__, RINPT, RINPT, _NO__}, // INT + {REXPL, _NO__, REXPL, REXPL, RWIDE, _NO__, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // FLOAT + {REXPL, _NO__, REXPL, RPTIN, _NO__, RPTPT, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, ROKOK, RPTIF, _NO__, _NO__, _NO__, _NO__, ROKOK, RPTPT, RPTFE}, // PTR {REXPL, _NO__, REXPL, _NO__, _NO__, RSAPT, RSASA, RSAVA, _NO__, RXXDI, RSAVA, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, ROKOK, RSAPT, RSAFE}, // SARRAY {REXPL, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, RVCVC, _NO__, RXXDI, RVCAR, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, RVAFE}, // VECTOR {REXPL, _NO__, _NO__, RBSIN, _NO__, _NO__, _NO__, _NO__, _NO__, RXXDI, RBSAR, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // BITSTRUCT @@ -1969,7 +1969,7 @@ CastRule cast_rules[CONV_LAST + 1][CONV_LAST + 1] = { {REXPL, _NO__, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTDI, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, _NO__}, // STRUCT {REXPL, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // UNION {REXPL, _NO__, REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, _NA__, REXPL, _NO__, _NO__, _NO__, _NO__, ROKOK, REXPL, _NO__}, // ANY - {REXPL, _NO__, REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, ROKOK, RPCPC, _NO__, _NO__, _NO__, _NO__, ROKOK, REXPL, _NO__}, // PROTOCOL + {REXPL, _NO__, REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, ROKOK, RIFIF, _NO__, _NO__, _NO__, _NO__, ROKOK, REXPL, _NO__}, // INTERFACE {REXPL, _NO__, REXPL, RPTIN, _NO__, REXPL, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, ROKOK, REXPL, REXPL, _NO__}, // FAULT {REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // ENUM {REXPL, _NO__, REXPL, RPTIN, _NO__, REXPL, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NA__, _NO__, REXPL, REXPL, _NO__}, // TYPEID @@ -1980,7 +1980,7 @@ CastRule cast_rules[CONV_LAST + 1][CONV_LAST + 1] = { }; CastFunction cast_function[CONV_LAST + 1][CONV_LAST + 1] = { -//void, wildcd, bool, int, float, ptr, sarr, vec, bitst, dist, array, struct,union, any, prot, fault, enum, typeid,anyfa, vptr, aptr, ulist, infer(to) +//void, wildcd, bool, int, float, ptr, sarr, vec, bitst, dist, array, struct,union, any, infc, fault, enum, typeid,anyfa, vptr, aptr, ulist, infer(to) {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // VOID (from) {XX2XX, 0, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, 0, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, XX2XX, 0 }, // WILDCARD {XX2VO, 0, 0, BO2IN, BO2FP, 0, 0, EX2VC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // BOOL @@ -1995,7 +1995,7 @@ CastFunction cast_function[CONV_LAST + 1][CONV_LAST + 1] = { {XX2VO, 0, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, 0, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, ST2LN, 0 }, // STRUCT {XX2VO, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // UNION {XX2VO, 0, AY2BO, 0, 0, AY2PT, 0, 0, 0, 0, 0, 0, 0, PT2PT, PT2PT, 0, 0, 0, 0, AY2PT, AY2PT, 0 }, // ANY - {XX2VO, 0, AY2BO, 0, 0, AY2PT, 0, 0, 0, 0, 0, 0, 0, PT2PT, PT2PT, 0, 0, 0, 0, AY2PT, AY2PT, 0 }, // PROTOCOL + {XX2VO, 0, AY2BO, 0, 0, AY2PT, 0, 0, 0, 0, 0, 0, 0, PT2PT, PT2PT, 0, 0, 0, 0, AY2PT, AY2PT, 0 }, // INTERFACE {XX2VO, 0, AF2BO, FA2IN, 0, FA2PT, 0, EX2VC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FA2AF, FA2PT, FA2PT, 0 }, // FAULT {XX2VO, 0, 0, EN2IN, 0, 0, 0, EX2VC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, // ENUM {XX2VO, 0, TI2BO, TI2IN, 0, TI2PT, 0, EX2VC, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, TI2PT, TI2PT, 0 }, // TYPEID @@ -2025,7 +2025,7 @@ static ConvGroup group_from_type[TYPE_LAST + 1] = { [TYPE_F64] = CONV_FLOAT, [TYPE_F128] = CONV_FLOAT, [TYPE_ANY] = CONV_NO, - [TYPE_PROTOCOL] = CONV_NO, + [TYPE_INTERFACE] = CONV_NO, [TYPE_ANYFAULT] = CONV_ANYFAULT, [TYPE_TYPEID] = CONV_TYPEID, [TYPE_POINTER] = CONV_POINTER, @@ -2038,7 +2038,7 @@ static ConvGroup group_from_type[TYPE_LAST + 1] = { [TYPE_TYPEDEF] = CONV_NO, [TYPE_DISTINCT] = CONV_DISTINCT, [TYPE_ARRAY] = CONV_ARRAY, - [TYPE_PROPTR] = CONV_PROTOCOL, + [TYPE_INFPTR] = CONV_INTERFACE, [TYPE_ANYPTR] = CONV_ANY, [TYPE_SUBARRAY] = CONV_SUBARRAY, [TYPE_FLEXIBLE_ARRAY] = CONV_NO, diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index 2d3e5eb90..7bb3a775d 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -132,27 +132,27 @@ static inline bool sema_check_param_uniqueness_and_type(Decl **decls, Decl *curr return true; } -static inline bool sema_resolve_implemented_protocols(SemaContext *context, Decl *decl, bool deep) +static inline bool sema_resolve_implemented_interfaces(SemaContext *context, Decl *decl, bool deep) { - TypeInfo **protocols = decl->protocols; - unsigned count = vec_size(protocols); + TypeInfo **interfaces = decl->interfaces; + unsigned count = vec_size(interfaces); for (unsigned i = 0; i < count; i++) { - TypeInfo *proto = protocols[i]; + TypeInfo *proto = interfaces[i]; if (!sema_resolve_type_info(context, proto, RESOLVE_TYPE_ALLOW_ANY)) return false; - Type *proto_type = proto->type->canonical; - if (proto_type->type_kind != TYPE_PROTOCOL) + Type *inf_type = proto->type->canonical; + if (inf_type->type_kind != TYPE_INTERFACE) { - RETURN_SEMA_ERROR(proto, "Expected a protocol name."); + RETURN_SEMA_ERROR(proto, "Expected an interface name."); } for (unsigned j = 0; j < i; j++) { - if (protocols[j]->type->canonical == proto_type) + if (interfaces[j]->type->canonical == inf_type) { - RETURN_SEMA_ERROR(proto, "Included protocol '%s' more than once, please remove duplicates.", proto_type->name); + RETURN_SEMA_ERROR(proto, "Included interface '%s' more than once, please remove duplicates.", inf_type->name); } } - if (deep && !sema_resolve_type_decl(context, proto_type)) return false; + if (deep && !sema_resolve_type_decl(context, inf_type)) return false; } return true; } @@ -493,7 +493,7 @@ static bool sema_analyse_struct_union(SemaContext *context, Decl *decl, bool *er if (!sema_analyse_attributes(context, decl, decl->attributes, domain, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; - if (!sema_resolve_implemented_protocols(context, decl, false)) return decl_poison(decl); + if (!sema_resolve_implemented_interfaces(context, decl, false)) return decl_poison(decl); DEBUG_LOG("Beginning analysis of %s.", decl->name ? decl->name : ".anon"); bool success; @@ -715,12 +715,12 @@ AFTER_BIT_CHECK: member->resolve_status = RESOLVE_DONE; return true; } -static bool sema_analyse_protocol(SemaContext *context, Decl *decl, bool *erase_decl) +static bool sema_analyse_interface(SemaContext *context, Decl *decl, bool *erase_decl) { if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_INTERFACE, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; - if (!sema_resolve_implemented_protocols(context, decl, true)) return false; - Decl **functions = decl->protocol_methods; + if (!sema_resolve_implemented_interfaces(context, decl, true)) return false; + Decl **functions = decl->interface_methods; unsigned count = vec_size(functions); for (unsigned i = 0; i < count; i++) { @@ -733,10 +733,10 @@ static bool sema_analyse_protocol(SemaContext *context, Decl *decl, bool *erase_ } if (method->func_decl.type_parent) { - SEMA_ERROR(type_infoptr(method->func_decl.type_parent), "Protocols should not be declared as methods."); + SEMA_ERROR(type_infoptr(method->func_decl.type_parent), "Interfaces should not be declared as methods."); return decl_poison(decl); } - method->func_decl.attr_protocol_method = true; + method->func_decl.attr_interface_method = true; bool erase = false; Decl *first = decl_new_var(kw_self, decl->span, NULL, VARDECL_PARAM); first->type = type_voidptr; @@ -778,7 +778,7 @@ static bool sema_analyse_protocol(SemaContext *context, Decl *decl, bool *erase_ static bool sema_analyse_bitstruct(SemaContext *context, Decl *decl, bool *erase_decl) { if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_BITSTRUCT, erase_decl)) return decl_poison(decl); - if (!sema_resolve_implemented_protocols(context, decl, false)) return decl_poison(decl); + if (!sema_resolve_implemented_interfaces(context, decl, false)) return decl_poison(decl); if (*erase_decl) return true; DEBUG_LOG("Beginning analysis of %s.", decl->name ? decl->name : ".anon"); if (!sema_resolve_type_info(context, decl->bitstruct.base_type, RESOLVE_TYPE_DEFAULT)) return false; @@ -925,7 +925,7 @@ static inline bool sema_analyse_signature(SemaContext *context, Signature *sig, } if (i == 0 && param->resolve_status == RESOLVE_DONE) { - assert(param->type == type_voidptr && "Expected the first parameter of a protocol method."); + assert(param->type == type_voidptr && "Expected the first parameter of an interface method."); continue; } @@ -945,7 +945,7 @@ static inline bool sema_analyse_signature(SemaContext *context, Signature *sig, switch (var_kind) { case VARDECL_PARAM_REF: - if (type_info && !type_is_pointer(param->type) && !type_is_any_protocol_ptr(param->type)) + if (type_info && !type_is_pointer(param->type) && !type_is_any_interface_ptr(param->type)) { RETURN_SEMA_ERROR(type_info, "A pointer type was expected for a ref argument, did you mean %s?", type_quoted_error_string(type_get_ptr(param->type))); @@ -1117,7 +1117,7 @@ static inline bool sema_analyse_distinct(SemaContext *context, Decl *decl, bool { if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_DISTINCT, erase)) return false; if (*erase) return true; - if (!sema_resolve_implemented_protocols(context, decl, false)) return decl_poison(decl); + if (!sema_resolve_implemented_interfaces(context, decl, false)) return decl_poison(decl); TypeInfo *info = decl->distinct; if (!sema_resolve_type_info(context, info, RESOLVE_TYPE_DEFAULT)) return false; @@ -1135,7 +1135,7 @@ static inline bool sema_analyse_distinct(SemaContext *context, Decl *decl, bool case CT_TYPES: case TYPE_FLEXIBLE_ARRAY: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: UNREACHABLE return false; case TYPE_OPTIONAL: @@ -1146,8 +1146,8 @@ static inline bool sema_analyse_distinct(SemaContext *context, Decl *decl, bool case TYPE_ANYFAULT: SEMA_ERROR(decl, "You cannot create a distinct type from an error union."); return false; - case TYPE_PROPTR: - SEMA_ERROR(decl, "You cannot create a distinct type from a protocol pointer."); + case TYPE_INFPTR: + SEMA_ERROR(decl, "You cannot create a distinct type from an interface pointer."); return false; case TYPE_ANYPTR: SEMA_ERROR(decl, "You cannot create a distinct type from an 'any*'."); @@ -1232,7 +1232,7 @@ static inline bool sema_analyse_enum(SemaContext *context, Decl *decl, bool *era { if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_ENUM, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; - if (!sema_resolve_implemented_protocols(context, decl, false)) return decl_poison(decl); + if (!sema_resolve_implemented_interfaces(context, decl, false)) return decl_poison(decl); // Resolve the type of the enum. if (!sema_resolve_type_info(context, decl->enums.type_info, RESOLVE_TYPE_DEFAULT)) return false; @@ -1380,7 +1380,7 @@ static inline bool sema_analyse_error(SemaContext *context, Decl *decl, bool *er { if (!sema_analyse_attributes(context, decl, decl->attributes, ATTR_FAULT, erase_decl)) return decl_poison(decl); if (*erase_decl) return true; - if (!sema_resolve_implemented_protocols(context, decl, false)) return decl_poison(decl); + if (!sema_resolve_implemented_interfaces(context, decl, false)) return decl_poison(decl); bool success = true; unsigned enums = vec_size(decl->enums.values); @@ -1639,7 +1639,7 @@ static inline bool unit_add_method_like(CompilationUnit *unit, Type *parent_type Decl *ambiguous = NULL; Decl *private = NULL; method = sema_resolve_method(unit, parent, name, &ambiguous, &private); - if (method && !method->func_decl.attr_protocol_method) + if (method && !method->func_decl.attr_interface_method) { SEMA_ERROR(method_like, "This %s is already defined for '%s'.", method_name_by_decl(method_like), parent_type->name); @@ -1678,21 +1678,21 @@ static inline bool unit_add_method_like(CompilationUnit *unit, Type *parent_type } -static Decl *sema_protocol_method_by_name(Decl *protocol, const char *name) +static Decl *sema_interface_method_by_name(Decl *interface, const char *name) { - FOREACH_BEGIN(Decl *method, protocol->protocol_methods) + FOREACH_BEGIN(Decl *method, interface->interface_methods) if (method->name == name) return method; FOREACH_END(); - FOREACH_BEGIN(TypeInfo *parent_type, protocol->protocols) - Decl *res = sema_protocol_method_by_name(parent_type->type->decl, name); + FOREACH_BEGIN(TypeInfo *parent_type, interface->interfaces) + Decl *res = sema_interface_method_by_name(parent_type->type->decl, name); if (res) return res; FOREACH_END(); return NULL; } -static inline Decl *sema_find_protocol_for_method(SemaContext *context, Type *parent_type, Decl *method) +static inline Decl *sema_find_interface_for_method(SemaContext *context, Type *parent_type, Decl *method) { - // Can the parent even implement a protocol? + // Can the parent even implement a interface? switch (parent_type->type_kind) { case TYPE_STRUCT: @@ -1706,44 +1706,44 @@ static inline Decl *sema_find_protocol_for_method(SemaContext *context, Type *pa } const char *name = method->name; Decl *first_match = NULL; - Decl *first_protocol = NULL; - FOREACH_BEGIN(TypeInfo *proto, parent_type->decl->protocols) - Decl *protocol = proto->type->decl; - Decl *match = sema_protocol_method_by_name(protocol, name); + Decl *first_interface = NULL; + FOREACH_BEGIN(TypeInfo *proto, parent_type->decl->interfaces) + Decl *interface = proto->type->decl; + Decl *match = sema_interface_method_by_name(interface, name); if (!match) continue; if (first_match) { if (first_match->type->function.prototype->raw_type == match->type->function.prototype->raw_type) continue; SEMA_ERROR(method, - "Both '%s' and '%s' protocols have a method matching '%s' but their signatures are different, " + "Both '%s' and '%s' interfaces have a method matching '%s' but their signatures are different, " "which prevents it from being implemented.", - first_protocol->name, protocol->name, name); + first_interface->name, interface->name, name); return NULL; } first_match = match; - first_protocol = protocol; + first_interface = interface; FOREACH_END(); if (!first_match) { return NULL; } - if (!sema_analyse_decl(context, first_protocol)) return poisoned_decl; + if (!sema_analyse_decl(context, first_interface)) return poisoned_decl; return first_match; } -static inline bool sema_compare_method_with_protocol(SemaContext *context, Decl *decl, Decl *implemented_method) +static inline bool sema_compare_method_with_interface(SemaContext *context, Decl *decl, Decl *implemented_method) { - Signature protocol_sig = implemented_method->func_decl.signature; + Signature interface_sig = implemented_method->func_decl.signature; Signature this_sig = decl->func_decl.signature; - Type *any_rtype = typeget(protocol_sig.rtype); + Type *any_rtype = typeget(interface_sig.rtype); Type *this_rtype = typeget(this_sig.rtype); if (any_rtype->canonical != this_rtype->canonical) { SEMA_ERROR(type_infoptr(this_sig.rtype), "The prototype method has a return type %s, but this function returns %s, they need to match.", type_quoted_error_string(any_rtype), type_quoted_error_string(this_rtype)); - SEMA_NOTE(type_infoptr(protocol_sig.rtype), "The interface definition is here."); + SEMA_NOTE(type_infoptr(interface_sig.rtype), "The interface definition is here."); return false; } - Decl **any_params = protocol_sig.params; + Decl **any_params = interface_sig.params; Decl **this_params = this_sig.params; unsigned any_param_count = vec_size(any_params); unsigned this_param_count = vec_size(this_params); @@ -1801,41 +1801,41 @@ static inline bool sema_analyse_method(SemaContext *context, Decl *decl) if (decl->func_decl.attr_default) { - if (par_type->type_kind != TYPE_PROTOCOL) + if (par_type->type_kind != TYPE_INTERFACE) { - RETURN_SEMA_ERROR(decl, "Only protocols may have @default methods."); + RETURN_SEMA_ERROR(decl, "Only interfaces may have @default methods."); } - Decl *implemented_method = sema_protocol_method_by_name(par_type->decl, decl->name); + Decl *implemented_method = sema_interface_method_by_name(par_type->decl, decl->name); if (!implemented_method) { - RETURN_SEMA_ERROR(decl, "No matching protocol method could be found for the '%s' method.", decl->name); + RETURN_SEMA_ERROR(decl, "No matching interface method could be found for the '%s' method.", decl->name); } if (!implemented_method->func_decl.attr_optional) { - SEMA_ERROR(decl, "Only @optional protocol methods may have @default implementations.", decl->name); - SEMA_NOTE(implemented_method, "The definition of the protocol method is here."); + SEMA_ERROR(decl, "Only @optional interface methods may have @default implementations.", decl->name); + SEMA_NOTE(implemented_method, "The definition of the interface method is here."); return false; } - if (!sema_compare_method_with_protocol(context, decl, implemented_method)) return false; + if (!sema_compare_method_with_interface(context, decl, implemented_method)) return false; implemented_method->func_decl.default_method = declid(decl); - decl->func_decl.protocol_method = declid(implemented_method); + decl->func_decl.interface_method = declid(implemented_method); } if (is_dynamic) { - if (par_type->type_kind == TYPE_PROTOCOL) + if (par_type->type_kind == TYPE_INTERFACE) { - RETURN_SEMA_ERROR(decl, "Protocols may not implement @dynamic methods."); + RETURN_SEMA_ERROR(decl, "Interfaces may not implement @dynamic methods."); } - Decl *implemented_method = sema_find_protocol_for_method(context, par_type, decl); + Decl *implemented_method = sema_find_interface_for_method(context, par_type, decl); if (!decl_ok(implemented_method)) return false; if (implemented_method) { - if (!sema_compare_method_with_protocol(context, decl, implemented_method)) return false; - decl->func_decl.protocol_method = declid(implemented_method); + if (!sema_compare_method_with_interface(context, decl, implemented_method)) return false; + decl->func_decl.interface_method = declid(implemented_method); } else { - decl->func_decl.protocol_method = 0; + decl->func_decl.interface_method = 0; } } return unit_add_method_like(context->unit, par_type, decl); @@ -1879,8 +1879,8 @@ static const char *attribute_domain_to_string(AttributeDomain domain) return "call"; case ATTR_DISTINCT: return "distinct"; - case ATTR_PROTOCOL_METHOD: - return "protocol method"; + case ATTR_INTERFACE_METHOD: + return "interface method"; } UNREACHABLE } @@ -1927,7 +1927,7 @@ static bool update_call_abi_from_string(Decl *decl, Expr *expr) } #define EXPORTED_USER_DEFINED_TYPES (ATTR_ENUM | ATTR_UNION | ATTR_STRUCT | ATTR_FAULT) -#define CALLABLE_TYPE (ATTR_FUNC | ATTR_PROTOCOL_METHOD | ATTR_MACRO) +#define CALLABLE_TYPE (ATTR_FUNC | ATTR_INTERFACE_METHOD | ATTR_MACRO) #define USER_DEFINED_TYPES EXPORTED_USER_DEFINED_TYPES | ATTR_BITSTRUCT | ATTR_DISTINCT static bool sema_analyse_attribute(SemaContext *context, Decl *decl, Attr *attr, AttributeDomain domain, bool *erase_decl) { @@ -1938,7 +1938,7 @@ static bool sema_analyse_attribute(SemaContext *context, Decl *decl, Attr *attr, [ATTRIBUTE_BENCHMARK] = ATTR_FUNC, [ATTRIBUTE_BIGENDIAN] = ATTR_BITSTRUCT, [ATTRIBUTE_BUILTIN] = ATTR_MACRO | ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST, - [ATTRIBUTE_CALLCONV] = ATTR_FUNC | ATTR_PROTOCOL_METHOD, + [ATTRIBUTE_CALLCONV] = ATTR_FUNC | ATTR_INTERFACE_METHOD, [ATTRIBUTE_DEFAULT] = ATTR_FUNC | ATTR_MACRO, [ATTRIBUTE_DEPRECATED] = USER_DEFINED_TYPES | CALLABLE_TYPE | ATTR_CONST | ATTR_GLOBAL | ATTR_MEMBER | ATTR_BITSTRUCT_MEMBER, [ATTRIBUTE_DYNAMIC] = ATTR_FUNC, @@ -1959,7 +1959,7 @@ static bool sema_analyse_attribute(SemaContext *context, Decl *decl, Attr *attr, [ATTRIBUTE_NOSTRIP] = ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST | EXPORTED_USER_DEFINED_TYPES, [ATTRIBUTE_OBFUSCATE] = ATTR_ENUM | ATTR_FAULT, [ATTRIBUTE_OPERATOR] = ATTR_MACRO | ATTR_FUNC, - [ATTRIBUTE_OPTIONAL] = ATTR_PROTOCOL_METHOD, + [ATTRIBUTE_OPTIONAL] = ATTR_INTERFACE_METHOD, [ATTRIBUTE_OVERLAP] = ATTR_BITSTRUCT, [ATTRIBUTE_PACKED] = ATTR_STRUCT | ATTR_UNION, [ATTRIBUTE_PRIVATE] = ATTR_FUNC | ATTR_MACRO | ATTR_GLOBAL | ATTR_CONST | USER_DEFINED_TYPES | ATTR_DEF, @@ -2401,7 +2401,7 @@ static inline bool sema_analyse_doc_header(AstId doc, Decl **params, Decl **extr NEXT:; Type *type = param->type; if (type) type = type_flatten(type); - bool may_be_pointer = !type || type_is_pointer(type) || type_is_any_protocol_ptr(type); + bool may_be_pointer = !type || type_is_pointer(type) || type_is_any_interface_ptr(type); if (directive->contract_stmt.param.by_ref) { if (!may_be_pointer) @@ -2739,8 +2739,8 @@ static inline bool sema_analyse_func(SemaContext *context, Decl *decl, bool *era { DEBUG_LOG("----Analysing function %s", decl->name); - bool is_protocol_method = decl->func_decl.attr_protocol_method; - if (!sema_analyse_func_macro(context, decl, is_protocol_method ? ATTR_PROTOCOL_METHOD : ATTR_FUNC, erase_decl)) return false; + bool is_interface_method = decl->func_decl.attr_interface_method; + if (!sema_analyse_func_macro(context, decl, is_interface_method ? ATTR_INTERFACE_METHOD : ATTR_FUNC, erase_decl)) return false; if (*erase_decl) return true; bool is_test = decl->func_decl.attr_test; @@ -2753,7 +2753,7 @@ static inline bool sema_analyse_func(SemaContext *context, Decl *decl, bool *era } if (is_test || is_benchmark || is_init_finalizer) { - assert(!is_protocol_method); + assert(!is_interface_method); if (vec_size(sig->params)) { SEMA_ERROR(sig->params[0], "%s functions may not take any parameters.", @@ -2810,11 +2810,11 @@ static inline bool sema_analyse_func(SemaContext *context, Decl *decl, bool *era { if (!sema_analyse_method(context, decl)) return decl_poison(decl); } - else if (!is_protocol_method) + else if (!is_interface_method) { if (decl->func_decl.attr_dynamic) { - SEMA_ERROR(decl, "Only methods may implement protocols."); + SEMA_ERROR(decl, "Only methods may implement interfaces."); return decl_poison(decl); } if (decl->name == kw_main) @@ -2830,7 +2830,7 @@ static inline bool sema_analyse_func(SemaContext *context, Decl *decl, bool *era } // Do we have fn void any.foo(void*) { ... }? - if (!decl->func_decl.body && !decl->is_extern && !decl->unit->is_interface_file && !is_protocol_method) + if (!decl->func_decl.body && !decl->is_extern && !decl->unit->is_interface_file && !is_interface_method) { SEMA_ERROR(decl, "Expected a function body, if you want to declare an extern function use 'extern' or place it in an .c3i file."); return false; @@ -2867,7 +2867,7 @@ static inline bool sema_is_valid_method_param(SemaContext *context, Decl *param, switch (param_type->type_kind) { case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_POINTER: if (param_type->pointer == parent_type) return true; break; @@ -3674,7 +3674,7 @@ bool sema_resolve_type_structure(SemaContext *context, Type *type, SourceSpan sp RETRY: switch (type->type_kind) { - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: case TYPE_POISONED: case TYPE_VOID: @@ -3698,7 +3698,7 @@ RETRY: case TYPE_BITSTRUCT: case TYPE_FAULTTYPE: return sema_analyse_decl(context, type->decl); - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_POINTER: type = type->pointer; goto RETRY; @@ -3746,8 +3746,8 @@ bool sema_analyse_decl(SemaContext *context, Decl *decl) { case DECL_ERASED: break; - case DECL_PROTOCOL: - if (!sema_analyse_protocol(context, decl, &erase_decl)) goto FAILED; + case DECL_INTERFACE: + if (!sema_analyse_interface(context, decl, &erase_decl)) goto FAILED; set_external_name = true; break; case DECL_BITSTRUCT: diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index f9c722e6f..f985213a6 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -696,8 +696,8 @@ static inline bool sema_cast_ident_rvalue(SemaContext *context, Expr *expr) case DECL_STRUCT: SEMA_ERROR(expr, "Expected struct followed by {...} or '.'."); return expr_poison(expr); - case DECL_PROTOCOL: - SEMA_ERROR(expr, "Expected a protocol to be followed by '.' when used as an expression."); + case DECL_INTERFACE: + SEMA_ERROR(expr, "Expected an interface to be followed by '.' when used as an expression."); return expr_poison(expr); case DECL_UNION: SEMA_ERROR(expr, "Expected union followed by {...} or '.'."); @@ -1546,7 +1546,7 @@ static inline bool sema_call_analyse_invocation(SemaContext *context, Expr *call // &foo if (!sema_analyse_expr_lvalue(context, arg)) return false; if (!sema_arg_is_pass_through_ref(arg) && !sema_expr_check_assign(context, arg)) return false; - if (!type_is_any_protocol_ptr(arg->type)) expr_insert_addr(arg); + if (!type_is_any_interface_ptr(arg->type)) expr_insert_addr(arg); *optional |= IS_OPTIONAL(arg); if (!sema_call_check_contract_param_match(context, param, arg)) return false; if (type_is_invalid_storage_type(type) || type == type_void) @@ -1783,7 +1783,7 @@ static inline bool sema_expr_analyse_func_call(SemaContext *context, Expr *expr, sema_display_deprecated_warning_on_use(context, decl, expr->span); // Tag dynamic dispatch. - if (struct_var && decl->func_decl.attr_protocol_method) expr->call_expr.is_dynamic_dispatch = true; + if (struct_var && decl->func_decl.attr_interface_method) expr->call_expr.is_dynamic_dispatch = true; return sema_call_analyse_func_invocation(context, decl->type, @@ -4063,13 +4063,13 @@ CHECK_DEEPER: } } - // 9. At this point we may only have distinct, struct, union, error, enum, protocol + // 9. At this point we may only have distinct, struct, union, error, enum, interface if (!type_may_have_sub_elements(type)) { Decl *ambiguous = NULL; Decl *private = NULL; - // We look at any for any* and protocol for protocol* - Type *actual = type_is_any_protocol_ptr(type) ? type->pointer : type; + // We look at any for any* and interface for interface* + Type *actual = type_is_any_interface_ptr(type) ? type->pointer : type; Decl *method = sema_resolve_type_method(context->unit, actual, kw, &ambiguous, &private); if (private) { @@ -4093,7 +4093,7 @@ CHECK_DEEPER: } // 10. Dump all members and methods into the scope. - Decl *decl = type->type_kind == TYPE_PROPTR ? type->pointer->decl : type->decl; + Decl *decl = type->type_kind == TYPE_INFPTR ? type->pointer->decl : type->decl; Decl *member = sema_decl_stack_find_decl_member(decl, kw); @@ -4111,11 +4111,11 @@ CHECK_DEEPER: { Decl *ambiguous = NULL; member = sema_resolve_method(context->unit, decl, kw, &ambiguous, &private); - // Look at protocol parents - if (!member && decl->decl_kind == DECL_PROTOCOL) + // Look at interface parents + if (!member && decl->decl_kind == DECL_INTERFACE) { - FOREACH_BEGIN(TypeInfo *parent_protocol, decl->protocols) - member = sema_resolve_method(context->unit, parent_protocol->type->decl, kw, &ambiguous, &private); + FOREACH_BEGIN(TypeInfo *parent_interface, decl->interfaces) + member = sema_resolve_method(context->unit, parent_interface->type->decl, kw, &ambiguous, &private); if (member) break; FOREACH_END(); } @@ -4158,9 +4158,9 @@ CHECK_DEEPER: SEMA_ERROR(expr, "The method '%s' has private visibility.", kw); return false; } - if (parent->type->canonical->type_kind == TYPE_PROPTR) + if (parent->type->canonical->type_kind == TYPE_INFPTR) { - RETURN_SEMA_ERROR(expr, "The '%s' protocol has no method '%s', did you spell it correctly?", parent->type->canonical->pointer->canonical->name, kw); + RETURN_SEMA_ERROR(expr, "The '%s' interface has no method '%s', did you spell it correctly?", parent->type->canonical->pointer->canonical->name, kw); } RETURN_SEMA_ERROR(expr, "There is no field or method '%s.%s'.", type_to_error_string(parent->type), kw); return false; @@ -5964,7 +5964,7 @@ static const char *sema_addr_check_may_take(Expr *inner) Decl *decl = inner->access_expr.ref; if (decl->decl_kind == DECL_FUNC) { - if (decl->func_decl.attr_protocol_method) return NULL; + if (decl->func_decl.attr_interface_method) return NULL; return "Taking the address of a method should be done through the type e.g. '&Foo.method' not through the value."; } return sema_addr_check_may_take(inner->access_expr.parent); diff --git a/src/compiler/sema_initializers.c b/src/compiler/sema_initializers.c index dad487d5d..7669bc68e 100644 --- a/src/compiler/sema_initializers.c +++ b/src/compiler/sema_initializers.c @@ -536,7 +536,7 @@ bool sema_expr_analyse_initializer_list(SemaContext *context, Type *to, Expr *ex switch (flattened->type_kind) { case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: UNREACHABLE case TYPE_UNTYPED_LIST: case TYPE_STRUCT: diff --git a/src/compiler/sema_internal.h b/src/compiler/sema_internal.h index 90205aae1..e65af1c72 100644 --- a/src/compiler/sema_internal.h +++ b/src/compiler/sema_internal.h @@ -59,7 +59,7 @@ void sema_analysis_pass_decls(Module *module); void sema_analysis_pass_ct_assert(Module *module); void sema_analysis_pass_ct_echo(Module *module); void sema_analysis_pass_functions(Module *module); -void sema_analysis_pass_protocol(Module *module); +void sema_analysis_pass_interface(Module *module); void sema_analysis_pass_lambda(Module *module); void sema_analyze_stage(Module *module, AnalysisStage stage); diff --git a/src/compiler/sema_liveness.c b/src/compiler/sema_liveness.c index 849737aa1..6a73fdd3e 100644 --- a/src/compiler/sema_liveness.c +++ b/src/compiler/sema_liveness.c @@ -17,7 +17,7 @@ RETRY: type = type->canonical; switch (type->type_kind) { - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_POINTER: type = type->pointer; goto RETRY; @@ -573,7 +573,7 @@ RETRY: case DECL_FAULT: case DECL_STRUCT: case DECL_UNION: - case DECL_PROTOCOL: + case DECL_INTERFACE: sema_trace_decl_dynamic_methods(decl); return; case DECL_POISONED: diff --git a/src/compiler/sema_name_resolution.c b/src/compiler/sema_name_resolution.c index 29e118c64..61388a429 100644 --- a/src/compiler/sema_name_resolution.c +++ b/src/compiler/sema_name_resolution.c @@ -87,15 +87,15 @@ static void add_members_to_decl_stack(Decl *decl) sema_decl_stack_push(members[i]); } } - if (decl->decl_kind == DECL_PROTOCOL) + if (decl->decl_kind == DECL_INTERFACE) { - FOREACH_BEGIN(TypeInfo *parent_protocol, decl->protocols) - FOREACH_BEGIN(Decl *protocol, parent_protocol->type->decl->protocol_methods) - sema_decl_stack_push(protocol); + FOREACH_BEGIN(TypeInfo *parent_interface, decl->interfaces) + FOREACH_BEGIN(Decl *interface, parent_interface->type->decl->interface_methods) + sema_decl_stack_push(interface); FOREACH_END(); FOREACH_END(); - FOREACH_BEGIN(Decl *protocol, decl->protocol_methods) - sema_decl_stack_push(protocol); + FOREACH_BEGIN(Decl *interface, decl->interface_methods) + sema_decl_stack_push(interface); FOREACH_END(); } if (decl_is_struct_type(decl) || decl->decl_kind == DECL_BITSTRUCT) @@ -661,10 +661,10 @@ Decl *sema_resolve_method_in_module(Module *module, Type *actual_type, const cha Decl *sema_resolve_method(CompilationUnit *unit, Decl *type, const char *method_name, Decl **ambiguous_ref, Decl **private_ref) { - // Protocol, prefer protocol methods. - if (type->decl_kind == DECL_PROTOCOL) + // Interface, prefer interface methods. + if (type->decl_kind == DECL_INTERFACE) { - FOREACH_BEGIN(Decl *method, type->protocol_methods) + FOREACH_BEGIN(Decl *method, type->interface_methods) if (method_name == method->name) return method; FOREACH_END(); } @@ -734,9 +734,9 @@ bool sema_resolve_type_decl(SemaContext *context, Type *type) case TYPE_INFERRED_VECTOR: case TYPE_VECTOR: case TYPE_SUBARRAY: - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: return true; case TYPE_OPTIONAL: return sema_resolve_type_decl(context, type->optional); @@ -767,7 +767,7 @@ bool sema_resolve_type_decl(SemaContext *context, Type *type) Decl *sema_resolve_type_method(CompilationUnit *unit, Type *type, const char *method_name, Decl **ambiguous_ref, Decl **private_ref) { assert(type == type->canonical); - if (type->type_kind == TYPE_PROPTR) + if (type->type_kind == TYPE_INFPTR) { type = type->pointer; } diff --git a/src/compiler/sema_passes.c b/src/compiler/sema_passes.c index 5f3f9cda3..3e751d0f3 100644 --- a/src/compiler/sema_passes.c +++ b/src/compiler/sema_passes.c @@ -603,35 +603,35 @@ void sema_analysis_pass_lambda(Module *module) DEBUG_LOG("Pass finished with %d error(s).", global_context.errors_found); } -static inline bool sema_check_protocols(Decl *decl) +static inline bool sema_check_interfaces(Decl *decl) { Decl **store = sema_decl_stack_store(); FOREACH_BEGIN(Decl *method, decl->methods) sema_decl_stack_push(method); FOREACH_END(); - FOREACH_BEGIN(TypeInfo *protocol_type, decl->protocols) - Decl *protocol = protocol_type->type->decl; - FOREACH_BEGIN(Decl *method, protocol->protocol_methods) + FOREACH_BEGIN(TypeInfo *interface_type, decl->interfaces) + Decl *interface = interface_type->type->decl; + FOREACH_BEGIN(Decl *method, interface->interface_methods) if (method->func_decl.attr_optional) continue; Decl *matching_method = sema_decl_stack_resolve_symbol(method->name); if (!matching_method) { - SEMA_ERROR(protocol_type, "'%s' was not fully implemented, required method '%s' needs to be implemented, did you forget it?", - protocol->name, method->name); + SEMA_ERROR(interface_type, "'%s' was not fully implemented, required method '%s' needs to be implemented, did you forget it?", + interface->name, method->name); sema_decl_stack_restore(store); return false; } if (matching_method->decl_kind != DECL_FUNC) { SEMA_ERROR(matching_method, "'%s' was not fully implemented, it requires '%s' to be a function marked '@dynamic'.", - protocol->name, method->name); + interface->name, method->name); sema_decl_stack_restore(store); return false; } if (!matching_method->func_decl.attr_dynamic) { SEMA_ERROR(matching_method, "'%s' was not fully implemented, you need to mark '%s' as '@dynamic'.", - protocol->name, method->name); + interface->name, method->name); sema_decl_stack_restore(store); return false; } @@ -641,9 +641,9 @@ static inline bool sema_check_protocols(Decl *decl) return true; } -void sema_analysis_pass_protocol(Module *module) +void sema_analysis_pass_interface(Module *module) { - DEBUG_LOG("Pass: Protocol analysis %s", module->name->module); + DEBUG_LOG("Pass: Interface analysis %s", module->name->module); VECEACH(module->units, index) { @@ -663,9 +663,9 @@ void sema_analysis_pass_protocol(Module *module) default: continue; } - if (decl->protocols) + if (decl->interfaces) { - sema_check_protocols(decl); + sema_check_interfaces(decl); } } sema_context_destroy(&context); diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index ba5b58cc5..7fb07efea 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -230,7 +230,7 @@ static bool sema_resolve_type_identifier(SemaContext *context, TypeInfo *type_in case DECL_UNION: case DECL_FAULT: case DECL_ENUM: - case DECL_PROTOCOL: + case DECL_INTERFACE: type_info->type = decl->type; type_info->resolve_status = RESOLVE_DONE; DEBUG_LOG("Resolved %s.", type_info->unresolved.name); @@ -385,7 +385,7 @@ static inline bool sema_resolve_type(SemaContext *context, TypeInfo *type_info, switch (type_no_optional(type_info->type)->canonical->type_kind) { case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: RETURN_SEMA_ERROR(type_info, "%s has no valid runtime size, you should use '%s' instead.", type_quoted_error_string(type_no_optional(type_info->type)), type_quoted_error_string(type_get_ptr(type_no_optional(type_info->type)))); @@ -489,10 +489,10 @@ APPEND_QUALIFIERS: return type_info_poison(type_info); } break; - case TYPE_PROTOCOL: + case TYPE_INTERFACE: if (!(resolve_type_kind & RESOLVE_TYPE_ALLOW_ANY)) { - SEMA_ERROR(type_info, "%s is a protocol and has undefined size, please use %s instead.", + SEMA_ERROR(type_info, "%s is an interface and has undefined size, please use %s instead.", type_quoted_error_string(type_info->type), type_quoted_error_string(type_get_ptr(type_info->type))); return type_info_poison(type_info); diff --git a/src/compiler/semantic_analyser.c b/src/compiler/semantic_analyser.c index 4c9d18d7e..3b7df3cc7 100644 --- a/src/compiler/semantic_analyser.c +++ b/src/compiler/semantic_analyser.c @@ -163,8 +163,8 @@ void sema_analyze_stage(Module *module, AnalysisStage stage) case ANALYSIS_FUNCTIONS: sema_analysis_pass_functions(module); break; - case ANALYSIS_PROTOCOL: - sema_analysis_pass_protocol(module); + case ANALYSIS_INTERFACE: + sema_analysis_pass_interface(module); break; case ANALYSIS_FINALIZE: break; @@ -211,7 +211,7 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls) case DECL_UNION: case DECL_VAR: case DECL_BITSTRUCT: - case DECL_PROTOCOL: + case DECL_INTERFACE: break; } htable_set(&unit->module->symbols, (void *)decl->name, decl); diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index 5622509c9..e7a9b26ae 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -237,6 +237,8 @@ const char *token_type_to_string(TokenType type) return "if"; case TOKEN_INLINE: return "inline"; + case TOKEN_INTERFACE: + return "interface"; case TOKEN_IMPORT: return "import"; case TOKEN_MACRO: @@ -247,8 +249,6 @@ const char *token_type_to_string(TokenType type) return "nextcase"; case TOKEN_NULL: return "null"; - case TOKEN_PROTOCOL: - return "protocol"; case TOKEN_RETURN: return "return"; case TOKEN_STATIC: diff --git a/src/compiler/types.c b/src/compiler/types.c index 41ca8a2e5..57b72e01b 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -121,10 +121,10 @@ static void type_append_name_to_scratch(Type *type) case TYPE_UNION: case TYPE_DISTINCT: case TYPE_BITSTRUCT: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: scratch_buffer_append(type->decl->name); break; - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_ANYPTR: case TYPE_POINTER: type_append_name_to_scratch(type->pointer); @@ -223,7 +223,7 @@ const char *type_to_error_string(Type *type) case TYPE_UNION: case TYPE_DISTINCT: case TYPE_BITSTRUCT: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: { Decl *decl = type->decl; if (!decl || !decl->unit || !decl->unit->module->generic_suffix) return type->name; @@ -246,7 +246,7 @@ const char *type_to_error_string(Type *type) return "typeinfo"; case TYPE_TYPEID: return "typeid"; - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_POINTER: if (type->pointer->type_kind == TYPE_FUNC) { @@ -313,7 +313,7 @@ RETRY: assert(type->decl->resolve_status == RESOLVE_DONE); return type->decl->strukt.size; case TYPE_VOID: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: return 1; case TYPE_BOOL: @@ -322,7 +322,7 @@ RETRY: case ALL_FLOATS: case TYPE_ANYFAULT: return type->builtin.bytesize; - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_ANYPTR: return t.iptr.canonical->builtin.bytesize * 2; case TYPE_FUNC: @@ -413,14 +413,14 @@ bool type_is_abi_aggregate(Type *type) case TYPE_ANYFAULT: case TYPE_FAULTTYPE: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: return false; case TYPE_STRUCT: case TYPE_UNION: case TYPE_SUBARRAY: case TYPE_ARRAY: case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: return true; case CT_TYPES: case TYPE_FLEXIBLE_ARRAY: @@ -488,7 +488,7 @@ bool type_is_comparable(Type *type) case TYPE_OPTIONAL: case TYPE_MEMBER: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: return false; case TYPE_TYPEDEF: type = type->canonical; @@ -505,7 +505,7 @@ bool type_is_comparable(Type *type) case ALL_INTS: case ALL_FLOATS: case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_ANYFAULT: case TYPE_TYPEID: case TYPE_POINTER: @@ -539,7 +539,7 @@ void type_mangle_introspect_name_to_buffer(Type *type) case TYPE_TYPEID: scratch_buffer_append(type->name); return; - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_POINTER: scratch_buffer_append("p$"); type_mangle_introspect_name_to_buffer(type->pointer); @@ -606,7 +606,7 @@ void type_mangle_introspect_name_to_buffer(Type *type) case TYPE_BITSTRUCT: case TYPE_FAULTTYPE: case TYPE_DISTINCT: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: scratch_buffer_append(type->decl->extname); return; case TYPE_TYPEDEF: @@ -665,7 +665,7 @@ AlignSize type_abi_alignment(Type *type) return alignment; } case TYPE_VOID: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: return 1; case TYPE_OPTIONAL: @@ -692,7 +692,7 @@ AlignSize type_abi_alignment(Type *type) case TYPE_ANYFAULT: return type->builtin.abi_alignment; case TYPE_FUNC: - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_ANYPTR: case TYPE_POINTER: case TYPE_TYPEID: @@ -727,7 +727,7 @@ static Type *type_generate_ptr(Type *ptr_type, bool canonical) Type *ptr = ptr_type->type_cache[PTR_OFFSET]; if (ptr == NULL) { - ptr = type_new(ptr_type->type_kind == TYPE_PROTOCOL ? TYPE_PROPTR : TYPE_POINTER, str_printf("%s*", ptr_type->name)); + ptr = type_new(ptr_type->type_kind == TYPE_INTERFACE ? TYPE_INFPTR : TYPE_POINTER, str_printf("%s*", ptr_type->name)); ptr->pointer = ptr_type; ptr_type->type_cache[PTR_OFFSET] = ptr; if (ptr_type == ptr_type->canonical) @@ -1022,7 +1022,7 @@ bool type_is_user_defined(Type *type) case TYPE_DISTINCT: case TYPE_BITSTRUCT: case TYPE_TYPEDEF: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: return type->decl != NULL; default: return false; @@ -1146,7 +1146,7 @@ bool type_is_valid_for_array(Type *type) type = type->decl->distinct->type; goto RETRY; case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_ANYFAULT: case TYPE_TYPEID: case TYPE_POINTER: @@ -1180,7 +1180,7 @@ bool type_is_valid_for_array(Type *type) case TYPE_POISONED: case TYPE_VOID: case TYPE_ANY: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: return false; } UNREACHABLE @@ -1598,7 +1598,7 @@ bool type_is_scalar(Type *type) switch (type->type_kind) { case CT_TYPES: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: UNREACHABLE case TYPE_VOID: @@ -1609,7 +1609,7 @@ bool type_is_scalar(Type *type) case TYPE_SUBARRAY: case TYPE_VECTOR: case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_FLEXIBLE_ARRAY: return false; case TYPE_BOOL: @@ -1875,7 +1875,7 @@ bool type_may_have_method(Type *type) case TYPE_FLEXIBLE_ARRAY: case TYPE_VECTOR: case TYPE_BOOL: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: return true; case TYPE_TYPEDEF: UNREACHABLE @@ -1889,7 +1889,7 @@ bool type_may_have_method(Type *type) case TYPE_MEMBER: case TYPE_WILDCARD: case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: return false; } UNREACHABLE @@ -1906,7 +1906,7 @@ bool type_may_have_sub_elements(Type *type) case TYPE_ENUM: case TYPE_FAULTTYPE: case TYPE_BITSTRUCT: - case TYPE_PROPTR: + case TYPE_INFPTR: return true; default: return false; @@ -2068,7 +2068,7 @@ Type *type_find_max_type(Type *type, Type *other) case TYPE_OPTIONAL: case TYPE_WILDCARD: UNREACHABLE - case TYPE_PROTOCOL: + case TYPE_INTERFACE: case TYPE_ANY: return NULL; case TYPE_VOID: @@ -2087,11 +2087,11 @@ Type *type_find_max_type(Type *type, Type *other) if (other->type_kind == TYPE_VECTOR) return other; return type_find_max_num_type(type, other); case TYPE_ANYPTR: - // any + protocol => any + // any + interface => any if (other == type_voidptr) return other; - return other->type_kind == TYPE_PROPTR ? type : NULL; - case TYPE_PROPTR: - // protocol + void* => void* + return other->type_kind == TYPE_INFPTR ? type : NULL; + case TYPE_INFPTR: + // interface + void* => void* return other == type_voidptr ? type_voidptr : NULL; case TYPE_POINTER: if (type->pointer->type_kind == TYPE_ARRAY) @@ -2247,13 +2247,13 @@ unsigned type_get_introspection_kind(TypeKind kind) return INTROSPECT_TYPE_ANY; case TYPE_ANYFAULT: return INTROSPECT_TYPE_ANYFAULT; - case TYPE_PROTOCOL: - return INTROSPECT_TYPE_PROTOCOL; + case TYPE_INTERFACE: + return INTROSPECT_TYPE_INTERFACE; case TYPE_TYPEID: return INTROSPECT_TYPE_TYPEID; case TYPE_POINTER: case TYPE_ANYPTR: - case TYPE_PROPTR: + case TYPE_INFPTR: return INTROSPECT_TYPE_POINTER; case TYPE_ENUM: return INTROSPECT_TYPE_ENUM; @@ -2307,7 +2307,7 @@ Module *type_base_module(Type *type) case TYPE_TYPEID: case TYPE_WILDCARD: return NULL; - case TYPE_PROPTR: + case TYPE_INFPTR: case TYPE_POINTER: type = type->pointer; goto RETRY; @@ -2319,7 +2319,7 @@ Module *type_base_module(Type *type) case TYPE_BITSTRUCT: case TYPE_FAULTTYPE: case TYPE_DISTINCT: - case TYPE_PROTOCOL: + case TYPE_INTERFACE: return type->decl->unit ? type->decl->unit->module : NULL; case TYPE_TYPEDEF: type = type->canonical; diff --git a/src/version.h b/src/version.h index b45154c7e..a249fe791 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.684" +#define COMPILER_VERSION "0.4.685" diff --git a/test/test_suite/dynamic/any_cast.c3 b/test/test_suite/dynamic/any_cast.c3 index c75cfa213..930bfdef0 100644 --- a/test/test_suite/dynamic/any_cast.c3 +++ b/test/test_suite/dynamic/any_cast.c3 @@ -1,9 +1,9 @@ module test; -protocol Abc : Def +interface Abc : Def {} -protocol Def +interface Def {} fn void! test() @@ -18,5 +18,5 @@ fn void! test2() Abc* x; any* d = x; Def* e = x; - x = e; // #error: is not a parent protocol of 'Def' + x = e; // #error: is not a parent interface of 'Def' } diff --git a/test/test_suite/dynamic/duplicate_definition.c3 b/test/test_suite/dynamic/duplicate_definition.c3 index c77fef44f..139d90658 100644 --- a/test/test_suite/dynamic/duplicate_definition.c3 +++ b/test/test_suite/dynamic/duplicate_definition.c3 @@ -1,6 +1,6 @@ module test; -protocol Abc +interface Abc { fn void abc(); fn void abc(); // #error: Duplicate definition diff --git a/test/test_suite/dynamic/dynamic_mismatch.c3 b/test/test_suite/dynamic/dynamic_mismatch.c3 index f64fddecf..b259a872a 100644 --- a/test/test_suite/dynamic/dynamic_mismatch.c3 +++ b/test/test_suite/dynamic/dynamic_mismatch.c3 @@ -1,4 +1,4 @@ -protocol TestProto +interface TestProto { fn int test(int ag); } diff --git a/test/test_suite/dynamic/dynamic_with_default.c3t b/test/test_suite/dynamic/dynamic_with_default.c3t index 8dd89c985..0ac897252 100644 --- a/test/test_suite/dynamic/dynamic_with_default.c3t +++ b/test/test_suite/dynamic/dynamic_with_default.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; -protocol Abc +interface Abc { fn int[<2>] test() @optional; fn int bye(); diff --git a/test/test_suite/dynamic/inherit.c3t b/test/test_suite/dynamic/inherit.c3t index 6520b4eb1..2d7631bdd 100644 --- a/test/test_suite/dynamic/inherit.c3t +++ b/test/test_suite/dynamic/inherit.c3t @@ -2,16 +2,16 @@ module inherit; import std::io; -protocol Base +interface Base { fn void tesT(); } -protocol TestProto2 : Base +interface TestProto2 : Base { } -protocol TestProto : Base +interface TestProto : Base { fn void hello(); } diff --git a/test/test_suite/dynamic/null_and_protocol.c3t b/test/test_suite/dynamic/null_and_protocol.c3t index 2e69ee053..31d20be91 100644 --- a/test/test_suite/dynamic/null_and_protocol.c3t +++ b/test/test_suite/dynamic/null_and_protocol.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; -protocol Test {} +interface Test {} fn void main() { diff --git a/test/test_suite/dynamic/overlapping_function.c3t b/test/test_suite/dynamic/overlapping_function.c3t index e81e3a07f..102fc39c0 100644 --- a/test/test_suite/dynamic/overlapping_function.c3t +++ b/test/test_suite/dynamic/overlapping_function.c3t @@ -2,12 +2,12 @@ module overlap; import std::io; -protocol TestProto +interface TestProto { fn void tesT(); } -protocol TestProto2 +interface TestProto2 { fn void tesT(); } diff --git a/test/test_suite/dynamic/same_method_twice.c3 b/test/test_suite/dynamic/same_method_twice.c3 index f105f1973..e8061986f 100644 --- a/test/test_suite/dynamic/same_method_twice.c3 +++ b/test/test_suite/dynamic/same_method_twice.c3 @@ -1,7 +1,7 @@ module test; import std::io; -protocol Abc +interface Abc { fn void test(); } diff --git a/test/unit/regression/liveness_any.c3 b/test/unit/regression/liveness_any.c3 index f652fa34b..f471b9885 100644 --- a/test/unit/regression/liveness_any.c3 +++ b/test/unit/regression/liveness_any.c3 @@ -1,6 +1,6 @@ module liveness; -protocol TestProto +interface TestProto { fn void tesT(); }