From 4d552ae44d8f1674a76a0fbe15ca6f81f7266b21 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 12 Jun 2023 18:44:29 +0200 Subject: [PATCH] Update $include syntax and behaviour. Remove top level $if completely. --- releasenotes.md | 2 + src/build/build_options.h | 1 + src/compiler/ast.c | 15 - src/compiler/compiler_internal.h | 30 +- src/compiler/context.c | 12 +- src/compiler/copying.c | 24 +- src/compiler/enums.h | 14 +- src/compiler/llvm_codegen.c | 5 - src/compiler/llvm_codegen_function.c | 8 - src/compiler/llvm_codegen_internal.h | 1 - src/compiler/llvm_codegen_stmt.c | 10 +- src/compiler/parse_global.c | 228 ++------------ src/compiler/parse_stmt.c | 2 - src/compiler/parser.c | 25 ++ src/compiler/parser_internal.h | 17 -- src/compiler/sema_casts.c | 2 - src/compiler/sema_decls.c | 12 +- src/compiler/sema_expr.c | 15 - src/compiler/sema_internal.h | 1 - src/compiler/sema_liveness.c | 5 - src/compiler/sema_passes.c | 282 ++++++------------ src/compiler/sema_types.c | 5 - src/compiler/semantic_analyser.c | 8 - src/compiler/symtab.c | 1 - src/compiler/tokens.c | 4 - test/test_suite/cast/cast_subarray.c3t | 2 +- test/test_suite/clang/2002-01_02.c3t | 2 +- test/test_suite/clang/2002-07.c3t | 2 +- .../compile_time_access_subscript.c3t | 2 +- test/test_suite/enumerations/enum_add_sub.c3t | 4 +- .../errors/general_error_regression.c3t | 2 +- .../expressions/bool_conversions.c3t | 2 +- test/test_suite/expressions/enum_ct_sub.c3t | 2 +- .../from_docs/examples_functionpointer.c3t | 2 +- .../functions/c_vararg_expansion.c3t | 2 +- .../functions/func_ptr_conversion_alias.c3t | 8 +- .../func_ptr_conversions_and_names.c3t | 6 +- test/test_suite/functions/test_regression.c3t | 16 +- .../functions/test_regression_mingw.c3t | 16 +- test/test_suite/generic/enum_set_test.c3t | 2 +- test/test_suite/generic/generic_recursion.c3t | 2 +- test/test_suite/lambda/lambda_in_macro.c3t | 4 +- test/test_suite/lambda/nested_lambda_def.c3t | 2 +- test/test_suite/lambda/simple_lambda.c3t | 2 +- test/test_suite/macros/type_params.c3t | 2 +- .../methods/enum_distinct_err_methods.c3t | 2 +- test/test_suite/overloading/set_overload.c3t | 2 +- test/test_suite/stdlib/map.c3t | 4 +- test/test_suite/stdlib/priorityqueue.c3t | 2 +- 49 files changed, 196 insertions(+), 625 deletions(-) diff --git a/releasenotes.md b/releasenotes.md index 1386a8681..b8d904698 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -3,6 +3,7 @@ ## 0.5.0 Change List ### Changes / improvements +- `@if` introduced, other top level conditional compilation removed. - `@dynamic` and `@interface` for dynamic dispatch. - `$if` now uses `$if :` syntax. - `$assert` now uses `$assert : ` @@ -24,6 +25,7 @@ - Allow getting the underlying type of anyfault. - De-duplicate string constants. - Change @extname => @extern. +- `define` and `typedef` removed. - `define` is replaced by `def`. - LLVM "wrapper" library compilation is exception free. - `private` is replaced by attribute `@private`. diff --git a/src/build/build_options.h b/src/build/build_options.h index 84d3cf2b6..0efc48a9a 100644 --- a/src/build/build_options.h +++ b/src/build/build_options.h @@ -9,6 +9,7 @@ #define MAX_LIB_DIRS 1024 #define MAX_FILES 2048 +#define MAX_INCLUDES 2048 #define MAX_THREADS 0xFFFF diff --git a/src/compiler/ast.c b/src/compiler/ast.c index 6b4cf865e..cec339c5e 100644 --- a/src/compiler/ast.c +++ b/src/compiler/ast.c @@ -81,13 +81,8 @@ Decl *decl_new_with_type(const char *name, SourceSpan loc, DeclKind decl_type) case DECL_FAULTVALUE: case DECL_IMPORT: case DECL_MACRO: - case DECL_CT_IF: - case DECL_CT_ELSE: - case DECL_CT_ELIF: case DECL_ATTRIBUTE: case DECL_LABEL: - case DECL_CT_SWITCH: - case DECL_CT_CASE: case DECL_DEFINE: case DECL_CT_ASSERT: case DECL_DECLARRAY: @@ -132,16 +127,6 @@ const char *decl_to_a_name(Decl *decl) return "a compile time assert"; case DECL_CT_ECHO: return "a compile time echo"; - case DECL_CT_CASE: - return "a compile time case"; - case DECL_CT_ELIF: - return "a compile time else if"; - case DECL_CT_ELSE: - return "a compile time else"; - case DECL_CT_IF: - return "a compile time if"; - case DECL_CT_SWITCH: - return "a compile time switch"; case DECL_IMPORT: return "an import"; case DECL_LABEL: diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index f9c6bb27b..4e283cdf3 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -400,8 +400,7 @@ typedef struct typedef struct { - File *file; - Decl **decls; + Expr *filename; } IncludeDecl; typedef struct @@ -483,25 +482,6 @@ typedef struct VarDecl_ } VarDecl; -typedef struct -{ - Expr *expr; - Decl **then; - Decl *elif; -} CtIfDecl; - -typedef struct -{ - Expr *expr; - Decl **cases; -} CtSwitchDecl; - -typedef struct -{ - Expr *expr; - Expr *to_expr; - Decl **body; -} CtCaseDecl; typedef struct { @@ -734,10 +714,6 @@ typedef struct Decl_ Decl** decls; TypedefDecl typedef_decl; DefineDecl define_decl; - CtIfDecl ct_if_decl; - CtIfDecl ct_elif_decl; - CtSwitchDecl ct_switch_decl; - CtCaseDecl ct_case_decl; Ast *ct_assert_decl; Ast *ct_echo_decl; Decl** ct_else_decl; @@ -1587,9 +1563,9 @@ struct CompilationUnit_ bool is_interface_file; bool test_by_default; Decl **generic_defines; - Decl **ct_ifs; Decl **ct_asserts; Decl **ct_echos; + Decl **ct_includes; Decl **xxlizers; Decl **vars; Decl **macros; @@ -1698,6 +1674,7 @@ typedef struct bool in_test_mode : 1; unsigned errors_found; unsigned warnings_found; + unsigned includes_used; bool suppress_errors; Decl ***locals_list; HTable compiler_defines; @@ -2202,6 +2179,7 @@ Decl *module_find_symbol(Module *module, const char *symbol); const char *module_create_object_file_name(Module *module); bool parse_file(File *file); +Decl **parse_include_file(File *file, CompilationUnit *unit); bool parse_stdin(void); Path *path_create_from_string(const char *string, uint32_t len, SourceSpan span); diff --git a/src/compiler/context.c b/src/compiler/context.c index 7ce06d083..ccc843512 100644 --- a/src/compiler/context.c +++ b/src/compiler/context.c @@ -125,11 +125,6 @@ void decl_register(Decl *decl) case DECL_INITIALIZE: case DECL_FINALIZE: case DECL_POISONED: - case DECL_CT_CASE: - case DECL_CT_ELIF: - case DECL_CT_ELSE: - case DECL_CT_IF: - case DECL_CT_SWITCH: case DECL_CT_ASSERT: case DECL_CT_ECHO: case DECL_ENUM_CONSTANT: @@ -232,18 +227,13 @@ void unit_register_global_decl(CompilationUnit *unit, Decl *decl) case DECL_FAULTVALUE: case DECL_ENUM_CONSTANT: case DECL_IMPORT: - case DECL_CT_ELSE: - case DECL_CT_ELIF: case DECL_LABEL: - case DECL_CT_CASE: case DECL_DECLARRAY: case DECL_BODYPARAM: case DECL_GLOBALS: UNREACHABLE - case DECL_CT_IF: - case DECL_CT_SWITCH: case DECL_CT_INCLUDE: - vec_add(unit->ct_ifs, decl); + vec_add(unit->ct_includes, decl); return; case DECL_CT_ECHO: vec_add(unit->ct_echos, decl); diff --git a/src/compiler/copying.c b/src/compiler/copying.c index 178f1b9cd..a0c0d2e60 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -860,7 +860,9 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) case DECL_POISONED: break; case DECL_ERASED: + break; case DECL_CT_INCLUDE: + MACRO_COPY_EXPR(copy->include.filename); break; case DECL_INITIALIZE: case DECL_FINALIZE: @@ -938,25 +940,12 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) } MACRO_COPY_TYPE(copy->distinct_decl.typedef_decl.type_info); break; - case DECL_CT_IF: - MACRO_COPY_EXPR(decl->ct_if_decl.expr); - MACRO_COPY_DECL(decl->ct_if_decl.elif); - MACRO_COPY_DECL_LIST(decl->ct_if_decl.then); - break; case DECL_CT_ECHO: MACRO_COPY_AST(decl->ct_echo_decl); break; case DECL_CT_ASSERT: MACRO_COPY_AST(decl->ct_assert_decl); break; - case DECL_CT_ELSE: - MACRO_COPY_DECL_LIST(decl->ct_else_decl); - break; - case DECL_CT_ELIF: - MACRO_COPY_EXPR(decl->ct_elif_decl.expr); - MACRO_COPY_DECL(decl->ct_elif_decl.elif); - MACRO_COPY_DECL_LIST(decl->ct_elif_decl.then); - break; case DECL_IMPORT: break; case DECL_MACRO: @@ -966,15 +955,6 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) MACRO_COPY_ASTID(decl->func_decl.body); MACRO_COPY_DECLID(decl->func_decl.body_param); break; - case DECL_CT_SWITCH: - MACRO_COPY_DECL_LIST(decl->ct_switch_decl.cases); - MACRO_COPY_EXPR(decl->ct_switch_decl.expr); - break; - case DECL_CT_CASE: - MACRO_COPY_EXPR(decl->ct_case_decl.expr); - MACRO_COPY_EXPR(decl->ct_case_decl.to_expr); - MACRO_COPY_DECL_LIST(decl->ct_case_decl.body); - break; case DECL_ATTRIBUTE: MACRO_COPY_DECL_LIST(decl->attr_decl.params); decl->attr_decl.attrs = copy_attributes(c, decl->attr_decl.attrs); diff --git a/src/compiler/enums.h b/src/compiler/enums.h index 39568adf9..ccfcd36bc 100644 --- a/src/compiler/enums.h +++ b/src/compiler/enums.h @@ -129,11 +129,6 @@ typedef enum DECL_ERASED, DECL_ATTRIBUTE, DECL_BITSTRUCT, - DECL_CT_CASE, - DECL_CT_ELIF, - DECL_CT_ELSE, - DECL_CT_IF, - DECL_CT_SWITCH, DECL_CT_ASSERT, DECL_CT_ECHO, DECL_DEFINE, @@ -159,8 +154,7 @@ typedef enum } DeclKind; #define NON_TYPE_DECLS DECL_IMPORT: case DECL_MACRO: \ - case DECL_DECLARRAY: case DECL_CT_IF: case DECL_CT_ELSE: case DECL_CT_ELIF: \ - case DECL_CT_SWITCH: case DECL_CT_CASE: case DECL_ATTRIBUTE: case DECL_LABEL: \ + case DECL_DECLARRAY: case DECL_ATTRIBUTE: case DECL_LABEL: \ case DECL_DEFINE: case DECL_CT_ASSERT: case DECL_INITIALIZE: \ case DECL_FINALIZE: case DECL_CT_ECHO: case DECL_CT_INCLUDE: case DECL_GLOBALS @@ -302,8 +296,6 @@ typedef enum typedef enum { TYPEID_INFO_KIND, - TYPEID_INFO_MIN, - TYPEID_INFO_MAX, TYPEID_INFO_INNER, TYPEID_INFO_LEN, TYPEID_INFO_SIZEOF, @@ -520,7 +512,6 @@ typedef enum TOKEN_CONST, TOKEN_CONTINUE, TOKEN_DEF, - TOKEN_DEFINE, TOKEN_DEFAULT, TOKEN_DEFER, TOKEN_DISTINCT, @@ -548,7 +539,6 @@ typedef enum TOKEN_SWITCH, TOKEN_TRUE, TOKEN_TRY, - TOKEN_TYPEDEF, TOKEN_UNION, TOKEN_VAR, TOKEN_WHILE, @@ -766,7 +756,6 @@ typedef enum ATTRIBUTE_DYNAMIC, ATTRIBUTE_EXPORT, ATTRIBUTE_EXTERN, - ATTRIBUTE_EXTNAME, ATTRIBUTE_IF, ATTRIBUTE_INLINE, ATTRIBUTE_INTERFACE, @@ -819,7 +808,6 @@ typedef enum ANALYSIS_REGISTER_GLOBAL_DECLARATIONS, ANALYSIS_REGISTER_CONDITIONAL_UNITS, ANALYSIS_REGISTER_CONDITIONAL_DECLARATIONS, - ANALYSIS_CONDITIONAL_COMPILATION, ANALYSIS_DECLS, ANALYSIS_CT_ECHO, ANALYSIS_CT_ASSERT, diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 1957975c8..a06cac113 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -1080,11 +1080,6 @@ LLVMValueRef llvm_get_ref(GenContext *c, Decl *decl) case DECL_POISONED: case DECL_ATTRIBUTE: case DECL_BITSTRUCT: - case DECL_CT_CASE: - case DECL_CT_ELIF: - case DECL_CT_ELSE: - case DECL_CT_IF: - case DECL_CT_SWITCH: case DECL_CT_ASSERT: case DECL_DISTINCT: case DECL_ENUM: diff --git a/src/compiler/llvm_codegen_function.c b/src/compiler/llvm_codegen_function.c index 5123e4b99..19920c3fe 100644 --- a/src/compiler/llvm_codegen_function.c +++ b/src/compiler/llvm_codegen_function.c @@ -623,14 +623,6 @@ void llvm_emit_xxlizer(GenContext *c, Decl *decl) body); } -static void llvm_generate_dyn_proto(GenContext *c, LLVMValueRef proto_ref) -{ - LLVMBuilderRef builder = LLVMCreateBuilderInContext(c->context); - LLVMBasicBlockRef entry = LLVMAppendBasicBlockInContext(c->context, proto_ref, "never"); - LLVMPositionBuilderAtEnd(builder, entry); - LLVMBuildUnreachable(builder); - LLVMDisposeBuilder(builder); -} void llvm_emit_dynamic_functions(GenContext *c, Decl **funcs) { diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h index e3b790011..d05e9021f 100644 --- a/src/compiler/llvm_codegen_internal.h +++ b/src/compiler/llvm_codegen_internal.h @@ -114,7 +114,6 @@ typedef struct GenContext_ FunctionPrototype *prototype; Type *rtype; } cur_func; - TypeInfo *current_return_type; int block_global_unique_count; int ast_alloca_addr_space; BreakContinue return_block; diff --git a/src/compiler/llvm_codegen_stmt.c b/src/compiler/llvm_codegen_stmt.c index 7b0c6fd7d..eeb9224aa 100644 --- a/src/compiler/llvm_codegen_stmt.c +++ b/src/compiler/llvm_codegen_stmt.c @@ -111,15 +111,7 @@ void llvm_emit_local_decl(GenContext *c, Decl *decl, BEValue *value) } } -void llvm_emit_decl_expr_list_ignore_result(GenContext *context, Expr *expr) -{ - assert(expr->expr_kind == EXPR_COND); - VECEACH(expr->cond_expr, i) - { - BEValue value; - llvm_emit_expr(context, &value, expr->cond_expr[i]); - } -} + static void llvm_emit_decl_expr_list(GenContext *context, BEValue *be_value, Expr *expr, bool bool_cast) { diff --git a/src/compiler/parse_global.c b/src/compiler/parse_global.c index f6932198b..574c0ed82 100644 --- a/src/compiler/parse_global.c +++ b/src/compiler/parse_global.c @@ -45,9 +45,7 @@ void recover_top_level(ParseContext *c) case TOKEN_IMPORT: case TOKEN_EXTERN: case TOKEN_ENUM: - case TOKEN_DEFINE: case TOKEN_DEF: - case TOKEN_TYPEDEF: case TOKEN_FAULT: return; case TOKEN_IDENT: // Incr arrays only @@ -83,108 +81,6 @@ INLINE bool parse_decl_initializer(ParseContext *c, Decl *decl) return true; } -// --- Parse CT conditional code - -/** - * A general CT block contains 0 - n number of declarations, and may be terminated - * by 1-3 different tokens. We don't accept imports or modules inside. - */ -static inline bool parse_top_level_block(ParseContext *c, Decl ***decls, TokenType end1, TokenType end2, TokenType end3) -{ - // Check whether we reached a terminating token or EOF - while (!tok_is(c, end1) && !tok_is(c, end2) && !tok_is(c, end3) && !tok_is(c, TOKEN_EOF)) - { - // Otherwise, try to parse it, passing in NULL ensures modules/imports are prohibited. - Decl *decl = parse_top_level_statement(c, NULL); - // Decl may be null only on import/module, which we prohibit - assert(decl && "Should never happen."); - // Bad decl? - if (!decl_ok(decl)) return false; - // Otherwise add it to the list. - add_decl_to_list(decls, decl); - } - return true; -} - -/** - * ct_if_top_level ::= CT_IF const_paren_expr top_level_block (CT_ELSE top_level_block)? CT_ENDIF - * @return the declaration if successfully parsed, poisoned_decl otherwise. - */ -static inline Decl *parse_ct_if_top_level(ParseContext *c) -{ - Decl *ct = decl_new_ct(DECL_CT_IF, c->span); - advance_and_verify(c, TOKEN_CT_IF); - ASSIGN_EXPR_OR_RET(ct->ct_if_decl.expr, parse_expr(c), poisoned_decl); - CONSUME_OR_RET(TOKEN_COLON, poisoned_decl); - if (!parse_top_level_block(c, &ct->ct_if_decl.then, TOKEN_CT_ENDIF, TOKEN_CT_ENDIF, TOKEN_CT_ELSE)) return poisoned_decl; - CtIfDecl *ct_if_decl = &ct->ct_if_decl; - - // final else - if (tok_is(c, TOKEN_CT_ELSE)) - { - Decl *ct_else = decl_new_ct(DECL_CT_ELSE, c->span); - advance_and_verify(c, TOKEN_CT_ELSE); - ct_if_decl->elif = ct_else; - if (!parse_top_level_block(c, &ct_else->ct_else_decl, TOKEN_CT_ENDIF, TOKEN_CT_ENDIF, TOKEN_CT_ENDIF)) return poisoned_decl; - } - CONSUME_OR_RET(TOKEN_CT_ENDIF, poisoned_decl); - return ct; -} - -/** - * ct_case ::= (CT_DEFAULT | CT_CASE constant_expr) ':' top_level_statement* - * - * @return poisoned decl if parsing fails. - */ -static inline Decl *parse_ct_case(ParseContext *c) -{ - Decl *decl; - // Parse the $case expr / $default - switch (c->tok) - { - case TOKEN_CT_DEFAULT: - decl = decl_new_ct(DECL_CT_CASE, c->span); - advance(c); - break; - case TOKEN_CT_CASE: - decl = decl_new_ct(DECL_CT_CASE, c->span); - advance(c); - ASSIGN_EXPR_OR_RET(decl->ct_case_decl.expr, parse_constant_expr(c), poisoned_decl); - break; - default: - SEMA_ERROR_HERE("Expected a $case or $default statement here."); - return poisoned_decl; - } - // Parse the body - if (!try_consume(c, TOKEN_COLON)) - { - sema_error_at_after(c->prev_span, "Expected a ':' here."); - return poisoned_decl; - } - if (!parse_top_level_block(c, &decl->ct_case_decl.body, TOKEN_CT_DEFAULT, TOKEN_CT_CASE, TOKEN_CT_ENDSWITCH)) return poisoned_decl; - return decl; -} - -/** - * ct_switch_top_level ::= CT_SWITCH const_paren_expr? ct_case* CT_ENDSWITCH - * @return the declaration if successfully parsed, NULL otherwise. - */ -static inline Decl *parse_ct_switch_top_level(ParseContext *c) -{ - Decl *ct = decl_new_ct(DECL_CT_SWITCH, c->span); - advance_and_verify(c, TOKEN_CT_SWITCH); - if (!tok_is(c, TOKEN_CT_CASE) && !tok_is(c, TOKEN_CT_DEFAULT) && !tok_is(c, TOKEN_CT_ENDSWITCH)) - { - ASSIGN_EXPR_OR_RET(ct->ct_switch_decl.expr, parse_const_paren_expr(c), poisoned_decl); - } - while (!try_consume(c, TOKEN_CT_ENDSWITCH)) - { - ASSIGN_DECL_OR_RET(Decl *result, parse_ct_case(c), poisoned_decl); - vec_add(ct->ct_switch_decl.cases, result); - } - return ct; -} - // --- Parse paths @@ -1754,21 +1650,17 @@ static inline void decl_add_type(Decl *decl, TypeKind kind) decl->type = type; } /** - * typedef_declaration ::= TYPEDEF TYPE_IDENT '=' 'distinct'? typedef_type ';' + * typedef_declaration ::= DEF TYPE_IDENT '=' 'distinct'? typedef_type ';' * * typedef_type ::= func_typedef | type generic_params? * func_typedef ::= 'fn' optional_type parameter_type_list */ -static inline Decl *parse_typedef_declaration(ParseContext *c) +static inline Decl *parse_def_type(ParseContext *c) { - if (!try_consume(c, TOKEN_DEF)) - { - sema_warning_at(c->span, "The use of 'typedef' is deprecated, please use 'def'."); - advance_and_verify(c, TOKEN_TYPEDEF); - } + advance_and_verify(c, TOKEN_DEF); Decl *decl = decl_new(DECL_POISONED, symstr(c), c->span); - DEBUG_LOG("Parse typedef %s", decl->name); + DEBUG_LOG("Parse def %s", decl->name); if (!try_consume(c, TOKEN_TYPE_IDENT)) { if (token_is_any_type(c->tok)) @@ -1870,14 +1762,10 @@ static inline Decl *parse_typedef_declaration(ParseContext *c) * * identifier_alias ::= path? (IDENT | CONST_IDENT | AT_IDENT) */ -static inline Decl *parse_define_ident(ParseContext *c) +static inline Decl *parse_def_ident(ParseContext *c) { // 1. Store the beginning of the "define". - if (!try_consume(c, TOKEN_DEF)) - { - sema_warning_at(c->span, "The use of 'define' is deprecated, please use 'def'."); - advance_and_verify(c, TOKEN_DEFINE); - } + advance_and_verify(c, TOKEN_DEF); // 2. At this point we expect an ident or a const token. // since the Type is handled. @@ -1969,12 +1857,12 @@ static inline Decl *parse_define_ident(ParseContext *c) } /** - * define_attribute ::= 'define' AT_TYPE_IDENT '(' parameter_list ')' opt_attributes '=' '{' attributes? '}' ';' + * define_attribute ::= 'def' AT_TYPE_IDENT '(' parameter_list ')' opt_attributes '=' '{' attributes? '}' ';' */ -static inline Decl *parse_define_attribute(ParseContext *c) +static inline Decl *parse_def_attribute(ParseContext *c) { - // 1. Store the beginning of the "define". - if (!try_consume(c, TOKEN_DEF)) advance_and_verify(c, TOKEN_DEFINE); + // 1. Store the beginning of the "def". + advance_and_verify(c, TOKEN_DEF); Decl *decl = decl_new(DECL_ATTRIBUTE, symstr(c), c->span); @@ -2007,34 +1895,19 @@ static inline Decl *parse_define_attribute(ParseContext *c) } /** - * define_decl ::= DEFINE define_type_body | - */ -static inline Decl *parse_define(ParseContext *c) -{ - switch (peek(c)) - { - case TOKEN_AT_TYPE_IDENT: - // define @Foo = @inline, @noreturn - return parse_define_attribute(c); - default: - return parse_define_ident(c); - } -} - -/** - * define_decl ::= DEFINE define_type_body | + * define_decl ::= DEF define_type_body | */ static inline Decl *parse_def(ParseContext *c) { switch (peek(c)) { case TOKEN_TYPE_IDENT: - return parse_typedef_declaration(c); + return parse_def_type(c); case TOKEN_AT_TYPE_IDENT: // define @Foo = @inline, @noreturn - return parse_define_attribute(c); + return parse_def_attribute(c); default: - return parse_define_ident(c); + return parse_def_ident(c); } } @@ -2709,60 +2582,9 @@ static Decl *parse_include(ParseContext *c) SourceSpan loc = c->span; Decl *decl = decl_new(DECL_CT_INCLUDE, NULL, loc); advance_and_verify(c, TOKEN_CT_INCLUDE); - CONSUME_OR_RET(TOKEN_LPAREN, poisoned_decl); - const char *str = symstr(c); - CONSUME_OR_RET(TOKEN_STRING, poisoned_decl); - CONSUME_OR_RET(TOKEN_RPAREN, poisoned_decl); + ASSIGN_EXPR_OR_RET(decl->include.filename, parse_constant_expr(c), poisoned_decl); + if (!parse_attributes_for_global(c, decl)) return poisoned_decl; CONSUME_EOS_OR_RET(poisoned_decl); - bool loaded; - const char *error; - char *path; - char *name; - if (file_namesplit(c->unit->file->full_path, &name, &path)) - { - str = file_append_path(path, str); - } - File *file = source_file_load(str, &loaded, &error); - if (!file) - { - sema_error_at(loc, "Failed to load file %s: %s", str, error); - return poisoned_decl; - } - decl->include.file = file; - if (global_context.errors_found) return poisoned_decl; - - Lexer current_lexer = c->lexer; - File *current_file = c->unit->file; - TokenType old_tok = c->tok; - TokenData old_data = c->data; - SourceSpan old_prev = c->prev_span; - SourceSpan old_span = c->span; - c->tok = TOKEN_INVALID_TOKEN; - c->lexer = (Lexer){ .file = decl->include.file, .context = c }; - lexer_init(&c->lexer); - // Prime everything - advance(c); - advance(c); - Decl **list = NULL; - while (!tok_is(c, TOKEN_EOF)) - { - Decl *inner = parse_top_level_statement(c, &c); - if (!inner) continue; - if (!decl_ok(inner)) - { - decl_poison(inner); - goto END; - } - add_decl_to_list(&list, inner); - } - decl->include.decls = list; -END: - c->lexer = current_lexer; - c->tok = old_tok; - c->data = old_data; - c->prev_span = old_prev; - c->span = old_span; - c->unit->file = current_file; return decl; } @@ -2818,7 +2640,7 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **c_ref) case TOKEN_MODULE: if (!c_ref) { - SEMA_ERROR_HERE("'module' cannot appear inside of conditional compilation."); + SEMA_ERROR_HERE("'module' is not valid inside an include."); return poisoned_decl; } advance(c); @@ -2835,18 +2657,10 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **c_ref) case TOKEN_DOCS_START: SEMA_ERROR_HERE("There are more than one doc comment in a row, that is not allowed."); return poisoned_decl; - case TOKEN_TYPEDEF: - if (contracts) goto CONTRACT_NOT_ALLOWED; - decl = parse_typedef_declaration(c); - break; case TOKEN_DEF: if (contracts) goto CONTRACT_NOT_ALLOWED; decl = parse_def(c); break; - case TOKEN_DEFINE: - if (contracts) goto CONTRACT_NOT_ALLOWED; - decl = parse_define(c); - break; case TOKEN_FN: decl = parse_func_definition(c, contracts, c->unit->is_interface_file); break; @@ -2878,10 +2692,6 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **c_ref) decl->ct_echo_decl = ast; break; } - case TOKEN_CT_IF: - if (contracts) goto CONTRACT_NOT_ALLOWED; - decl = parse_ct_if_top_level(c); - break; case TOKEN_IMPORT: if (contracts) goto CONTRACT_NOT_ALLOWED; if (!c_ref) @@ -2891,10 +2701,6 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **c_ref) } if (!parse_import(c)) return poisoned_decl; return NULL; - case TOKEN_CT_SWITCH: - if (contracts) goto CONTRACT_NOT_ALLOWED; - decl = parse_ct_switch_top_level(c); - break; case TOKEN_CT_INCLUDE: if (contracts) goto CONTRACT_NOT_ALLOWED; decl = parse_include(c); diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 13bf25105..95733ecbe 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -1287,9 +1287,7 @@ Ast *parse_stmt(ParseContext *c) case TOKEN_STRUCT: case TOKEN_FAULT: case TOKEN_UNION: - case TOKEN_DEFINE: case TOKEN_DEF: - case TOKEN_TYPEDEF: case TOKEN_DOCS_START: case TOKEN_DOCS_END: case TOKEN_DOC_COMMENT: diff --git a/src/compiler/parser.c b/src/compiler/parser.c index 0f41d6b0c..44d2ba67b 100644 --- a/src/compiler/parser.c +++ b/src/compiler/parser.c @@ -107,6 +107,31 @@ bool parse_file(File *file) return !global_context.errors_found; } +Decl **parse_include_file(File *file, CompilationUnit *unit) +{ + ParseContext parse_context = { .tok = TOKEN_INVALID_TOKEN }; + ParseContext *c = &parse_context; + c->unit = unit; + parse_context.lexer = (Lexer){ .file = file, .context = c }; + lexer_init(&parse_context.lexer); + // Prime everything + advance(c); + advance(c); + Decl **list = NULL; + while (!tok_is(c, TOKEN_EOF)) + { + Decl *inner = parse_top_level_statement(c, NULL); + if (!inner) continue; + if (!decl_ok(inner)) + { + decl_poison(inner); + return NULL; + } + add_decl_to_list(&list, inner); + } + return list; +} + File stdin_file; /** diff --git a/src/compiler/parser_internal.h b/src/compiler/parser_internal.h index 6f47eb992..d52e1b67e 100644 --- a/src/compiler/parser_internal.h +++ b/src/compiler/parser_internal.h @@ -131,11 +131,6 @@ INLINE bool token_is_some_ident(TokenType token_type) } } -INLINE bool token_is_keyword(TokenType token_type) -{ - return token_type >= TOKEN_FIRST_KEYWORD && token_type <= TOKEN_LAST_KEYWORD; -} - INLINE bool token_is_keyword_ident(TokenType token_type) { return token_type >= TOKEN_FIRST_KEYWORD && token_type <= TOKEN_LAST_NON_CT_KEYWORD; @@ -165,18 +160,6 @@ static inline Expr *parse_const_paren_expr(ParseContext *c) return expr; } -INLINE bool parse_next_may_be_type(ParseContext *c) -{ - switch (c->tok) - { - case TOKEN_IDENT: - case TYPELIKE_TOKENS: - return true; - default: - return false; - } -} - static inline bool parse_next_may_be_type_or_ident(ParseContext *c) { switch (c->tok) diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index a9b407ef1..cc1bffdbd 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -22,8 +22,6 @@ static bool bitstruct_cast(Expr *expr, Type *from_type, Type *to, Type *to_type) static void sema_error_const_int_out_of_range(Expr *expr, Expr *problem, Type *to_type); static Expr *recursive_may_narrow(Expr *expr, Type *type); static void expr_recursively_rewrite_untyped_list(Expr *expr, Expr **list); -static inline bool cast_may_implicit_ptr(Type *from_pointee, Type *to_pointee); -static inline bool cast_to_array_is_valid(Type *from, Type *to); static inline bool insert_cast(Expr *expr, CastKind kind, Type *type); static bool pointer_to_integer(Expr *expr, Type *type); static bool pointer_to_bool(Expr *expr, Type *type); diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index cde6dccfb..6e054110b 100644 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -1557,7 +1557,6 @@ static bool sema_analyse_attribute(SemaContext *context, Decl *decl, Attr *attr, [ATTRIBUTE_DYNAMIC] = ATTR_FUNC, [ATTRIBUTE_EXPORT] = ATTR_FUNC | ATTR_GLOBAL | ATTR_CONST | EXPORTED_USER_DEFINED_TYPES, [ATTRIBUTE_EXTERN] = (AttributeDomain)~(ATTR_CALL | ATTR_BITSTRUCT | ATTR_DEFINE | ATTR_MACRO | ATTR_XXLIZER), - [ATTRIBUTE_EXTNAME] = (AttributeDomain)~(ATTR_CALL | ATTR_BITSTRUCT | ATTR_DEFINE | ATTR_MACRO | ATTR_XXLIZER), [ATTRIBUTE_IF] = (AttributeDomain)~(ATTR_CALL | ATTR_LOCAL), [ATTRIBUTE_INLINE] = ATTR_FUNC | ATTR_CALL, [ATTRIBUTE_INTERFACE] = ATTR_FUNC, @@ -1760,7 +1759,6 @@ static bool sema_analyse_attribute(SemaContext *context, Decl *decl, Attr *attr, } if (!expr->const_expr.b) *erase_decl = true; return true; - case ATTRIBUTE_EXTNAME: case ATTRIBUTE_SECTION: case ATTRIBUTE_EXTERN: if (context->unit->module->is_generic) @@ -1785,9 +1783,6 @@ static bool sema_analyse_attribute(SemaContext *context, Decl *decl, Attr *attr, if (!sema_check_section(context, attr)) return false; decl->section = expr->const_expr.string.chars; break; - case ATTRIBUTE_EXTNAME: - sema_warning_at(attr->span, "'@extname' is deprecated, please use '@extern' instead."); - FALLTHROUGH; case ATTRIBUTE_EXTERN: decl->has_extname = true; decl->extname = expr->const_expr.string.chars; @@ -2957,7 +2952,7 @@ static CompilationUnit *unit_copy(Module *module, CompilationUnit *unit) copy->global_decls = copy_decl_list_single(unit->global_decls); copy->global_cond_decls = copy_decl_list_single(unit->global_cond_decls); copy->module = module; - assert(!unit->functions && !unit->macro_methods && !unit->methods && !unit->enums && !unit->ct_ifs && !unit->types); + assert(!unit->functions && !unit->macro_methods && !unit->methods && !unit->enums && !unit->ct_includes && !unit->types); return copy; } @@ -3374,12 +3369,7 @@ bool sema_analyse_decl(SemaContext *context, Decl *decl) case DECL_POISONED: case DECL_IMPORT: case DECL_ENUM_CONSTANT: - case DECL_CT_ELSE: - case DECL_CT_ELIF: case DECL_LABEL: - case DECL_CT_SWITCH: - case DECL_CT_CASE: - case DECL_CT_IF: case DECL_CT_ASSERT: case DECL_CT_ECHO: case DECL_FAULTVALUE: diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 94d7079db..9de81892a 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -692,11 +692,6 @@ static inline bool sema_cast_ident_rvalue(SemaContext *context, Expr *expr) SEMA_ERROR(expr, "Expected fault name followed by '.' and a fault value."); return expr_poison(expr); case DECL_IMPORT: - case DECL_CT_IF: - case DECL_CT_ELSE: - case DECL_CT_ELIF: - case DECL_CT_SWITCH: - case DECL_CT_CASE: case DECL_ATTRIBUTE: case DECL_CT_ASSERT: case DECL_DEFINE: @@ -7596,16 +7591,6 @@ bool sema_analyse_expr(SemaContext *context, Expr *expr) return sema_analyse_expr_lvalue(context, expr) && sema_cast_rvalue(context, expr); } -bool sema_analyse_expr_require_const(SemaContext *context, Expr *expr) -{ - if (!sema_analyse_expr(context, expr)) return false; - if (!expr_is_const(expr)) - { - SEMA_ERROR(expr, "Expected a constant expression."); - return false; - } - return true; -} static inline int64_t expr_get_index_max(Expr *expr) { diff --git a/src/compiler/sema_internal.h b/src/compiler/sema_internal.h index f881ae04b..a1e5b2661 100644 --- a/src/compiler/sema_internal.h +++ b/src/compiler/sema_internal.h @@ -56,7 +56,6 @@ void sema_analysis_pass_process_imports(Module *module); void sema_analysis_pass_register_global_declarations(Module *module); void sema_analysis_pass_register_conditional_units(Module *module); void sema_analysis_pass_register_conditional_declarations(Module *module); -void sema_analysis_pass_conditional_compilation(Module *module); void sema_analysis_pass_decls(Module *module); void sema_analysis_pass_ct_assert(Module *module); void sema_analysis_pass_ct_echo(Module *module); diff --git a/src/compiler/sema_liveness.c b/src/compiler/sema_liveness.c index 15397e800..37d9ad715 100644 --- a/src/compiler/sema_liveness.c +++ b/src/compiler/sema_liveness.c @@ -543,11 +543,6 @@ RETRY: case DECL_ENUM_CONSTANT: case DECL_FAULTVALUE: return; - case DECL_CT_CASE: - case DECL_CT_ELIF: - case DECL_CT_ELSE: - case DECL_CT_IF: - case DECL_CT_SWITCH: case DECL_CT_ASSERT: case DECL_CT_ECHO: case DECL_IMPORT: diff --git a/src/compiler/sema_passes.c b/src/compiler/sema_passes.c index 348e0ea1f..a2f89a378 100644 --- a/src/compiler/sema_passes.c +++ b/src/compiler/sema_passes.c @@ -119,6 +119,82 @@ INLINE void register_global_decls(CompilationUnit *unit, Decl **decls) vec_resize(decls, 0); } +Decl **sema_load_include(CompilationUnit *unit, Decl *decl) +{ + SemaContext context; + sema_context_init(&context, unit); + FOREACH_BEGIN(Attr *attr, decl->attributes) + if (attr->attr_kind != ATTRIBUTE_IF) + { + SEMA_ERROR(attr, "Invalid attribute for '$include'."); + return NULL; + } + FOREACH_END(); + Expr *filename = decl->include.filename; + bool success = sema_analyse_ct_expr(&context, filename); + sema_context_destroy(&context); + if (!success) return NULL; + if (!expr_is_const_string(filename)) + { + SEMA_ERROR(decl->include.filename, "A compile time string was expected."); + return NULL; + } + const char *string = filename->const_expr.string.chars; + bool loaded; + const char *error; + char *path; + char *name; + if (file_namesplit(unit->file->full_path, &name, &path)) + { + string = file_append_path(path, string); + } + File *file = source_file_load(string, &loaded, &error); + if (!file) + { + SEMA_ERROR(decl, "Failed to load file %s: %s", string, error); + return NULL; + } + if (global_context.errors_found) return NULL; + if (global_context.includes_used++ > MAX_INCLUDES) + { + SEMA_ERROR(decl, "This $include would cause the maximum number of includes (%d) to be exceeded.", MAX_INCLUDES); + return NULL; + } + + return parse_include_file(file, unit); +} + +INLINE void register_includes(CompilationUnit *unit, Decl **decls) +{ + FOREACH_BEGIN(Decl *include, decls) + Decl **include_decls = sema_load_include(unit, include); + VECEACH(include_decls, i) + { + Decl *decl = include_decls[i]; + if (decl->is_cond) + { + vec_add(unit->global_cond_decls, decl); + } + else + { + unit_register_global_decl(unit, decl); + } + } + FOREACH_END(); +} + +void sema_process_includes(CompilationUnit *unit) +{ + while (1) + { + Decl **includes = unit->ct_includes; + if (!includes) break; + DEBUG_LOG("Processing includes in %s.", unit->file->name); + unit->ct_includes = NULL; + register_includes(unit, includes); + } +} + void sema_analysis_pass_register_global_declarations(Module *module) { DEBUG_LOG("Pass: Register globals for module '%s'.", module->name->module); @@ -126,9 +202,14 @@ void sema_analysis_pass_register_global_declarations(Module *module) { CompilationUnit *unit = module->units[index]; if (unit->if_attr) continue; + assert(!unit->ct_includes); unit->module = module; DEBUG_LOG("Processing %s.", unit->file->name); register_global_decls(unit, unit->global_decls); + + // Process all includes + sema_process_includes(unit); + assert(vec_size(unit->ct_includes) == 0); } DEBUG_LOG("Pass finished with %d error(s).", global_context.errors_found); @@ -140,6 +221,9 @@ void sema_analysis_pass_register_conditional_units(Module *module) VECEACH(module->units, index) { CompilationUnit *unit = module->units[index]; + // All ct_includes should already be registered. + assert(!unit->ct_includes); + Attr *if_attr = unit->if_attr; if (!if_attr) continue; if (vec_size(if_attr->exprs) != 1) @@ -165,6 +249,8 @@ void sema_analysis_pass_register_conditional_units(Module *module) continue; } register_global_decls(unit, unit->global_decls); + // There may be includes, add those. + sema_process_includes(unit); } DEBUG_LOG("Pass finished with %d error(s).", global_context.errors_found); } @@ -177,6 +263,7 @@ void sema_analysis_pass_register_conditional_declarations(Module *module) CompilationUnit *unit = module->units[index]; unit->module = module; DEBUG_LOG("Processing %s.", unit->file->name); +RETRY:; Decl **decls = unit->global_cond_decls; VECEACH(decls, i) { @@ -190,197 +277,18 @@ void sema_analysis_pass_register_conditional_declarations(Module *module) sema_context_destroy(&context); } vec_resize(decls, 0); +RETRY_INCLUDES: + decls = unit->ct_includes; + unit->ct_includes = NULL; + register_includes(unit, decls); + if (unit->ct_includes) goto RETRY_INCLUDES; + + // We might have gotten more declarations. + if (vec_size(unit->global_cond_decls) > 0) goto RETRY; } DEBUG_LOG("Pass finished with %d error(s).", global_context.errors_found); } -static inline void sema_append_decls(CompilationUnit *unit, Decl **decls) -{ - VECEACH(decls, i) - { - unit_register_global_decl(unit, decls[i]); - } -} - -static inline bool sema_analyse_top_level_if(SemaContext *context, Decl *ct_if) -{ - int res = sema_check_comp_time_bool(context, ct_if->ct_if_decl.expr); - if (res == -1) return false; - if (res) - { - // Append declarations - sema_append_decls(context->unit, ct_if->ct_if_decl.then); - return true; - } - - // False, so check elifs - Decl *ct_elif = ct_if->ct_if_decl.elif; - while (ct_elif) - { - if (ct_elif->decl_kind == DECL_CT_ELIF) - { - res = sema_check_comp_time_bool(context, ct_elif->ct_elif_decl.expr); - if (res == -1) return false; - if (res) - { - sema_append_decls(context->unit, ct_elif->ct_elif_decl.then); - return true; - } - ct_elif = ct_elif->ct_elif_decl.elif; - } - else - { - assert(ct_elif->decl_kind == DECL_CT_ELSE); - sema_append_decls(context->unit, ct_elif->ct_else_decl); - return true; - } - } - return true; -} - - -static inline bool sema_analyse_top_level_switch(SemaContext *context, Decl *ct_switch) -{ - Expr *cond = ct_switch->ct_switch_decl.expr; - if (cond && !sema_analyse_ct_expr(context, cond)) return false; - Type *type = cond ? cond->type : type_bool; - bool is_type = type == type_typeid; - ExprConst *switch_expr_const = cond ? &cond->const_expr : NULL; - Decl **cases = ct_switch->ct_switch_decl.cases; - - unsigned case_count = vec_size(cases); - int matched_case = (int)case_count; - int default_case = (int)case_count; - for (unsigned i = 0; i < case_count; i++) - { - Decl *kase = cases[i]; - Expr *expr = kase->ct_case_decl.expr; - Expr *to_expr = kase->ct_case_decl.to_expr; - if (expr) - { - if (is_type) - { - if (!sema_analyse_ct_expr(context, expr)) return false; - if (expr->type != type_typeid) - { - SEMA_ERROR(expr, "A type was expected here not %s.", type_quoted_error_string(expr->type)); - return false; - } - } - else - { - if (!sema_analyse_expr_rhs(context, type, expr, false)) return false; - if (to_expr && !sema_analyse_expr_rhs(context, type, to_expr, false)) return false; - } - if (expr->expr_kind != EXPR_CONST) - { - SEMA_ERROR(expr, "The $case must have a constant expression."); - return false; - } - if (!cond) - { - if (!expr->const_expr.b) continue; - if (matched_case == case_count) matched_case = (int)i; - continue; - } - if (to_expr && to_expr->expr_kind != EXPR_CONST) - { - SEMA_ERROR(to_expr, "The $case must have a constant expression."); - return false; - } - ExprConst *const_expr = &expr->const_expr; - ExprConst *const_to_expr = to_expr ? &to_expr->const_expr : const_expr; - if (to_expr && expr_const_compare(const_expr, const_to_expr, BINARYOP_GT)) - { - SEMA_ERROR(to_expr, "The end of a range must be less or equal to the beginning."); - return false; - } - // Check that it is unique. - for (unsigned j = 0; j < i; j++) - { - Decl *other_case = cases[j]; - - // Default. - if (!other_case->ct_case_decl.expr) continue; - ExprConst *other_const = &other_case->ct_case_decl.expr->const_expr; - ExprConst *other_const_to = other_case->ct_case_decl.to_expr - ? &other_case->ct_case_decl.to_expr->const_expr : other_const; - if (expr_const_in_range(const_expr, other_const, other_const_to)) - { - SEMA_ERROR(kase, "'%s' appears more than once.", expr_const_to_error_string(const_expr)); - SEMA_NOTE(cases[j]->ct_case_decl.expr, "The previous $case was here."); - return false; - } - } - if (expr_const_in_range(switch_expr_const, const_expr, const_to_expr)) - { - matched_case = (int)i; - } - } - else - { - if (default_case < case_count) - { - SEMA_ERROR(kase, "More than one $default is not allowed."); - SEMA_NOTE(cases[default_case], "The previous $default was here."); - return false; - } - default_case = (int)i; - continue; - } - } - - if (matched_case == case_count) matched_case = default_case; - - for (int i = matched_case; i < case_count; i++) - { - Decl **body = cases[i]->ct_case_decl.body; - if (body) - { - sema_append_decls(context->unit, body); - break; - } - } - return true; -} - -void sema_analysis_pass_conditional_compilation(Module *module) -{ - - DEBUG_LOG("Pass: Top level conditionals %s", module->name->module); - VECEACH(module->units, index) - { - CompilationUnit *unit = module->units[index]; - for (unsigned i = 0; i < vec_size(unit->ct_ifs); i++) - { - // Also handle switch! - SemaContext context; - sema_context_init(&context, unit); - Decl *decl = unit->ct_ifs[i]; - bool success; - switch (decl->decl_kind) - { - case DECL_CT_IF: - success = sema_analyse_top_level_if(&context, decl); - break; - case DECL_CT_SWITCH: - success = sema_analyse_top_level_switch(&context, decl); - break; - case DECL_CT_INCLUDE: - sema_append_decls(context.unit, decl->include.decls); - success = true; - break; - default: - UNREACHABLE - } - sema_context_destroy(&context); - if (!success) goto END; - } - } -END: - DEBUG_LOG("Pass finished with %d error(s).", global_context.errors_found); -} - void sema_analysis_pass_ct_assert(Module *module) { DEBUG_LOG("Pass: $assert checks %s", module->name->module); diff --git a/src/compiler/sema_types.c b/src/compiler/sema_types.c index d66820343..c71163350 100644 --- a/src/compiler/sema_types.c +++ b/src/compiler/sema_types.c @@ -228,11 +228,6 @@ static bool sema_resolve_type_identifier(SemaContext *context, TypeInfo *type_in return type_info_poison(type_info); case DECL_INITIALIZE: case DECL_FINALIZE: - case DECL_CT_ELSE: - case DECL_CT_IF: - case DECL_CT_ELIF: - case DECL_CT_SWITCH: - case DECL_CT_CASE: case DECL_CT_ASSERT: case DECL_CT_ECHO: case DECL_DECLARRAY: diff --git a/src/compiler/semantic_analyser.c b/src/compiler/semantic_analyser.c index a742fdd72..b24e90f2e 100644 --- a/src/compiler/semantic_analyser.c +++ b/src/compiler/semantic_analyser.c @@ -147,9 +147,6 @@ void sema_analyze_stage(Module *module, AnalysisStage stage) case ANALYSIS_REGISTER_CONDITIONAL_DECLARATIONS: sema_analysis_pass_register_conditional_declarations(module); break; - case ANALYSIS_CONDITIONAL_COMPILATION: - sema_analysis_pass_conditional_compilation(module); - break; case ANALYSIS_DECLS: sema_analysis_pass_decls(module); break; @@ -185,15 +182,10 @@ static void register_generic_decls(CompilationUnit *unit, Decl **decls) case DECL_DECLARRAY: case DECL_INITIALIZE: case DECL_FINALIZE: - case DECL_CT_IF: - case DECL_CT_SWITCH: case DECL_ERASED: continue; case DECL_ATTRIBUTE: break; - case DECL_CT_CASE: - case DECL_CT_ELIF: - case DECL_CT_ELSE: case DECL_BODYPARAM: case DECL_CT_INCLUDE: case DECL_GLOBALS: diff --git a/src/compiler/symtab.c b/src/compiler/symtab.c index 3a9f73a3a..9cfd4acd5 100644 --- a/src/compiler/symtab.c +++ b/src/compiler/symtab.c @@ -300,7 +300,6 @@ void symtab_init(uint32_t capacity) attribute_list[ATTRIBUTE_DYNAMIC] = KW_DEF("@dynamic"); attribute_list[ATTRIBUTE_EXPORT] = KW_DEF("@export"); attribute_list[ATTRIBUTE_EXTERN] = KW_DEF("@extern"); - attribute_list[ATTRIBUTE_EXTNAME] = KW_DEF("@extname"); attribute_list[ATTRIBUTE_IF] = KW_DEF("@if"); attribute_list[ATTRIBUTE_INLINE] = KW_DEF("@inline"); attribute_list[ATTRIBUTE_INTERFACE] = KW_DEF("@interface"); diff --git a/src/compiler/tokens.c b/src/compiler/tokens.c index f3e7ca97c..360283ffb 100644 --- a/src/compiler/tokens.c +++ b/src/compiler/tokens.c @@ -207,8 +207,6 @@ const char *token_type_to_string(TokenType type) return "default"; case TOKEN_DEFER: return "defer"; - case TOKEN_DEFINE: - return "define"; case TOKEN_DISTINCT: return "distinct"; case TOKEN_DO: @@ -259,8 +257,6 @@ const char *token_type_to_string(TokenType type) return "true"; case TOKEN_TRY: return "try"; - case TOKEN_TYPEDEF: - return "typedef"; case TOKEN_TYPEID: return "typeid"; case TOKEN_UNION: diff --git a/test/test_suite/cast/cast_subarray.c3t b/test/test_suite/cast/cast_subarray.c3t index 89e6fd1dc..1e50a18f1 100644 --- a/test/test_suite/cast/cast_subarray.c3t +++ b/test/test_suite/cast/cast_subarray.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; -typedef Foo = distinct int; +def Foo = distinct int; fn void main() { int*[] abc = { }; diff --git a/test/test_suite/clang/2002-01_02.c3t b/test/test_suite/clang/2002-01_02.c3t index c7d368bc4..7b136a9a3 100644 --- a/test/test_suite/clang/2002-01_02.c3t +++ b/test/test_suite/clang/2002-01_02.c3t @@ -52,7 +52,7 @@ struct Edge_rec int more_data; } -typedef QuadEdge = Edge_rec*; +def QuadEdge = Edge_rec*; struct EdgePair { QuadEdge left, right; diff --git a/test/test_suite/clang/2002-07.c3t b/test/test_suite/clang/2002-07.c3t index 85536403b..491063a19 100644 --- a/test/test_suite/clang/2002-07.c3t +++ b/test/test_suite/clang/2002-07.c3t @@ -143,7 +143,7 @@ struct Quad { Quad globalQuad = { 4, {1, 2}, null, 3, 156 }; -typedef FuncPtr = fn int(int); +def FuncPtr = fn int(int); fn uint ptrFunc(FuncPtr func, int x) { return func(x); diff --git a/test/test_suite/compile_time/compile_time_access_subscript.c3t b/test/test_suite/compile_time/compile_time_access_subscript.c3t index 21789e452..3d675d83e 100644 --- a/test/test_suite/compile_time/compile_time_access_subscript.c3t +++ b/test/test_suite/compile_time/compile_time_access_subscript.c3t @@ -22,7 +22,7 @@ macro check_type($Type) enum Blurb { FOO } -typedef Bdd = distinct Abc; +def Bdd = distinct Abc; fn void main() { var $i = int[4] { 1, 2, 3, 4 }; diff --git a/test/test_suite/enumerations/enum_add_sub.c3t b/test/test_suite/enumerations/enum_add_sub.c3t index 9496709bc..bec428891 100644 --- a/test/test_suite/enumerations/enum_add_sub.c3t +++ b/test/test_suite/enumerations/enum_add_sub.c3t @@ -4,8 +4,8 @@ enum Foo { ABC } -typedef Abc = distinct Foo; -typedef BarInt = distinct int; +def Abc = distinct Foo; +def BarInt = distinct int; enum Bar : BarInt { ABC diff --git a/test/test_suite/errors/general_error_regression.c3t b/test/test_suite/errors/general_error_regression.c3t index ccf9f3924..d1afe0e48 100644 --- a/test/test_suite/errors/general_error_regression.c3t +++ b/test/test_suite/errors/general_error_regression.c3t @@ -19,7 +19,7 @@ fault Foob Y2 } -typedef Bar = distinct int; +def Bar = distinct int; enum MyEnum { diff --git a/test/test_suite/expressions/bool_conversions.c3t b/test/test_suite/expressions/bool_conversions.c3t index 67b32e3ee..86fefb622 100644 --- a/test/test_suite/expressions/bool_conversions.c3t +++ b/test/test_suite/expressions/bool_conversions.c3t @@ -4,7 +4,7 @@ fn bool f0_0(void* a0) @private { return (bool)a0; } fn int f0() { return (int)f0_0((void*)0x2); } -typedef Test = fn void(); +def Test = fn void(); fn bool f1() { return (bool){| Test x @noinit; return x = (Test)0; |}; } diff --git a/test/test_suite/expressions/enum_ct_sub.c3t b/test/test_suite/expressions/enum_ct_sub.c3t index 5fb1993ce..f32d27d41 100644 --- a/test/test_suite/expressions/enum_ct_sub.c3t +++ b/test/test_suite/expressions/enum_ct_sub.c3t @@ -3,7 +3,7 @@ enum Foo : char ABC, BCD } -typedef Abc = distinct int; +def Abc = distinct int; fn void main() { $assert (Foo.ABC - Foo.BCD) == 255; diff --git a/test/test_suite/from_docs/examples_functionpointer.c3t b/test/test_suite/from_docs/examples_functionpointer.c3t index 0aee28f13..83eabb787 100644 --- a/test/test_suite/from_docs/examples_functionpointer.c3t +++ b/test/test_suite/from_docs/examples_functionpointer.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module demo; -typedef Callback = fn int(char* text, int value); +def Callback = fn int(char* text, int value); fn int my_callback(char* text, int value) { diff --git a/test/test_suite/functions/c_vararg_expansion.c3t b/test/test_suite/functions/c_vararg_expansion.c3t index 26eb87ee6..db9304df8 100644 --- a/test/test_suite/functions/c_vararg_expansion.c3t +++ b/test/test_suite/functions/c_vararg_expansion.c3t @@ -1,7 +1,7 @@ // #target: macos-x64 module test; extern fn void printf(char*,...); -typedef Foo = distinct float; +def Foo = distinct float; fn void main() { Foo a = 12.3; diff --git a/test/test_suite/functions/func_ptr_conversion_alias.c3t b/test/test_suite/functions/func_ptr_conversion_alias.c3t index ab398991a..f9434f330 100644 --- a/test/test_suite/functions/func_ptr_conversion_alias.c3t +++ b/test/test_suite/functions/func_ptr_conversion_alias.c3t @@ -1,10 +1,10 @@ // #target: macos-x64 module test; -typedef Callback = fn void(); -typedef Callback2 = fn void(); +def Callback = fn void(); +def Callback2 = fn void(); -typedef GetCallback = fn Callback2**[][123]*(); +def GetCallback = fn Callback2**[][123]*(); fn Callback**[][123]* tester() { @@ -14,7 +14,7 @@ fn Callback**[][123]* tester() GetCallback x = &tester; -typedef GetCallbackOpt = fn Callback2!(); +def GetCallbackOpt = fn Callback2!(); fn Callback2! tester2() => null; diff --git a/test/test_suite/functions/func_ptr_conversions_and_names.c3t b/test/test_suite/functions/func_ptr_conversions_and_names.c3t index 66a6c3099..c24098a1a 100644 --- a/test/test_suite/functions/func_ptr_conversions_and_names.c3t +++ b/test/test_suite/functions/func_ptr_conversions_and_names.c3t @@ -1,9 +1,9 @@ // #target: macos-x64 module test; import std::io; -typedef Func = fn int(int y); -typedef FuncOther = fn bool(char*); -typedef FuncSame = fn int(int z = 444); +def Func = fn int(int y); +def FuncOther = fn bool(char*); +def FuncSame = fn int(int z = 444); fn int test(int a) { return a; } fn int test2(int b = 3) { return b; } diff --git a/test/test_suite/functions/test_regression.c3t b/test/test_suite/functions/test_regression.c3t index 60612b30c..f207aa1c6 100644 --- a/test/test_suite/functions/test_regression.c3t +++ b/test/test_suite/functions/test_regression.c3t @@ -67,8 +67,8 @@ fn int Foo2.mutate(Foo2 *foo) def oopsInt = test2::argh; def oopsDouble = test2::argh; -typedef Argh = fn int(double, Bobo); -typedef Argh2 = fn int(double, Bobo); +def Argh = fn int(double, Bobo); +def Argh2 = fn int(double, Bobo); @@ -80,7 +80,7 @@ fn int sum_us(int... x) return sum; } -typedef Frob = long; +def Frob = long; fn int sumd(int[] x) { @@ -97,13 +97,13 @@ struct Foo def getValueInt = test2::getValue; def getValueDouble = test2::getValue; -typedef IntBlob = test2::Blob; -typedef DoubleBlob = Blob; +def IntBlob = test2::Blob; +def DoubleBlob = Blob; def getMultInt = test2::getMult; def getMultDouble = test2::getMult; -typedef IntArray = List; -typedef IntList = LinkedList; +def IntArray = List; +def IntList = LinkedList; enum MyEnum : int { @@ -218,7 +218,7 @@ macro Hello wut() return Hello.FOO; } -typedef Bye = Hello; +def Bye = Hello; def wat = wut; def byebye = hello; diff --git a/test/test_suite/functions/test_regression_mingw.c3t b/test/test_suite/functions/test_regression_mingw.c3t index b8f01bd71..717997775 100644 --- a/test/test_suite/functions/test_regression_mingw.c3t +++ b/test/test_suite/functions/test_regression_mingw.c3t @@ -69,8 +69,8 @@ fn int Foo2.mutate(Foo2 *foo) def oopsInt = test2::argh; def oopsDouble = test2::argh; -typedef Argh = fn int(double, Bobo); -typedef Argh2 = fn int(double, Bobo); +def Argh = fn int(double, Bobo); +def Argh2 = fn int(double, Bobo); @@ -82,7 +82,7 @@ fn int sum_us(int... x) return sum; } -typedef Frob = long; +def Frob = long; fn int sumd(int[] x) { @@ -99,13 +99,13 @@ struct Foo def getValueInt = test2::getValue; def getValueDouble = test2::getValue; -typedef IntBlob = test2::Blob; -typedef DoubleBlob = Blob; +def IntBlob = test2::Blob; +def DoubleBlob = Blob; def getMultInt = test2::getMult; def getMultDouble = test2::getMult; -typedef IntArray = List; -typedef IntList = LinkedList; +def IntArray = List; +def IntList = LinkedList; enum MyEnum : int { @@ -220,7 +220,7 @@ macro Hello wut() return Hello.FOO; } -typedef Bye = Hello; +def Bye = Hello; def wat = wut; def byebye = hello; diff --git a/test/test_suite/generic/enum_set_test.c3t b/test/test_suite/generic/enum_set_test.c3t index 594472988..ae687bf93 100644 --- a/test/test_suite/generic/enum_set_test.c3t +++ b/test/test_suite/generic/enum_set_test.c3t @@ -3,7 +3,7 @@ module test; import std::io; import std::collections::enumset; -typedef AbcEnumSet = EnumSet; +def AbcEnumSet = EnumSet; enum Abc { diff --git a/test/test_suite/generic/generic_recursion.c3t b/test/test_suite/generic/generic_recursion.c3t index 8bd0e12f2..167026fe1 100644 --- a/test/test_suite/generic/generic_recursion.c3t +++ b/test/test_suite/generic/generic_recursion.c3t @@ -3,7 +3,7 @@ module test; import std::io; import std::collections::list; -typedef TreeNodeList = List; +def TreeNodeList = List; struct TreeNode { diff --git a/test/test_suite/lambda/lambda_in_macro.c3t b/test/test_suite/lambda/lambda_in_macro.c3t index 8e057ab3b..17fbc52c7 100644 --- a/test/test_suite/lambda/lambda_in_macro.c3t +++ b/test/test_suite/lambda/lambda_in_macro.c3t @@ -2,8 +2,8 @@ module test; import std::io; -typedef Callback1 = fn double(double x); -typedef Callback2 = fn int(int y); +def Callback1 = fn double(double x); +def Callback2 = fn int(int y); macro test2(y) { diff --git a/test/test_suite/lambda/nested_lambda_def.c3t b/test/test_suite/lambda/nested_lambda_def.c3t index 8f05043df..20eccf82e 100644 --- a/test/test_suite/lambda/nested_lambda_def.c3t +++ b/test/test_suite/lambda/nested_lambda_def.c3t @@ -32,7 +32,7 @@ macro Callback get_callback2() module bar; import foo; -typedef Callback = fn int(); +def Callback = fn int(); macro Callback get_callback() { diff --git a/test/test_suite/lambda/simple_lambda.c3t b/test/test_suite/lambda/simple_lambda.c3t index 0c8c4d21e..c910880a1 100644 --- a/test/test_suite/lambda/simple_lambda.c3t +++ b/test/test_suite/lambda/simple_lambda.c3t @@ -3,7 +3,7 @@ import std::io; import std::math::vector; import std::math; -typedef Callback = fn int(); +def Callback = fn int(); fn int xy(Callback a) => a(); diff --git a/test/test_suite/macros/type_params.c3t b/test/test_suite/macros/type_params.c3t index e57c6abbd..df1aaad78 100644 --- a/test/test_suite/macros/type_params.c3t +++ b/test/test_suite/macros/type_params.c3t @@ -5,7 +5,7 @@ macro foo($Foo) return a; } -typedef Bar = short; +def Bar = short; fn void test() { int x = foo(int); diff --git a/test/test_suite/methods/enum_distinct_err_methods.c3t b/test/test_suite/methods/enum_distinct_err_methods.c3t index 933524f6c..cb4350936 100644 --- a/test/test_suite/methods/enum_distinct_err_methods.c3t +++ b/test/test_suite/methods/enum_distinct_err_methods.c3t @@ -8,7 +8,7 @@ fault Foo X } -typedef Bar = distinct int; +def Bar = distinct int; enum MyEnum { diff --git a/test/test_suite/overloading/set_overload.c3t b/test/test_suite/overloading/set_overload.c3t index 044edd099..da55c75c8 100644 --- a/test/test_suite/overloading/set_overload.c3t +++ b/test/test_suite/overloading/set_overload.c3t @@ -3,7 +3,7 @@ module test; import std::collections::map; -typedef IntMap = HashMap; +def IntMap = HashMap; fn void main() { diff --git a/test/test_suite/stdlib/map.c3t b/test/test_suite/stdlib/map.c3t index 2c1b4dd56..bddfdca31 100644 --- a/test/test_suite/stdlib/map.c3t +++ b/test/test_suite/stdlib/map.c3t @@ -6,8 +6,8 @@ import std::collections::map; struct Foo { int x; void* bar; } -typedef IntFooMap = HashMap; -typedef IntDoubleMap = HashMap; +def IntFooMap = HashMap; +def IntDoubleMap = HashMap; fn String Foo.to_string(Foo* foo, Allocator* allocator = mem::heap()) @dynamic { diff --git a/test/test_suite/stdlib/priorityqueue.c3t b/test/test_suite/stdlib/priorityqueue.c3t index 47bd459c2..2e9980ac5 100644 --- a/test/test_suite/stdlib/priorityqueue.c3t +++ b/test/test_suite/stdlib/priorityqueue.c3t @@ -4,7 +4,7 @@ import std::io; import std::math; import std::collections::priorityqueue; -typedef FooPriorityQueue = PriorityQueue; +def FooPriorityQueue = PriorityQueue; fn void main() {