From c29b643a58d3d31cae55a58a3efbbe2df5a111ad Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sat, 24 Apr 2021 15:00:01 +0100 Subject: Move out some intrinsics into separate procedures in llvm_backend.cpp; Rename `InlineRangeStmt` to `UnrollRangeStmt` (eventually merge the two AST nodes) --- src/parser.cpp | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 18a4ba9d2..c3bfc4dab 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -58,7 +58,7 @@ Token ast_token(Ast *node) { case Ast_ReturnStmt: return node->ReturnStmt.token; case Ast_ForStmt: return node->ForStmt.token; case Ast_RangeStmt: return node->RangeStmt.token; - case Ast_InlineRangeStmt: return node->InlineRangeStmt.inline_token; + case Ast_UnrollRangeStmt: return node->UnrollRangeStmt.unroll_token; case Ast_CaseClause: return node->CaseClause.token; case Ast_SwitchStmt: return node->SwitchStmt.token; case Ast_TypeSwitchStmt: return node->TypeSwitchStmt.token; @@ -319,11 +319,11 @@ Ast *clone_ast(Ast *node) { n->RangeStmt.expr = clone_ast(n->RangeStmt.expr); n->RangeStmt.body = clone_ast(n->RangeStmt.body); break; - case Ast_InlineRangeStmt: - n->InlineRangeStmt.val0 = clone_ast(n->InlineRangeStmt.val0); - n->InlineRangeStmt.val1 = clone_ast(n->InlineRangeStmt.val1); - n->InlineRangeStmt.expr = clone_ast(n->InlineRangeStmt.expr); - n->InlineRangeStmt.body = clone_ast(n->InlineRangeStmt.body); + case Ast_UnrollRangeStmt: + n->UnrollRangeStmt.val0 = clone_ast(n->UnrollRangeStmt.val0); + n->UnrollRangeStmt.val1 = clone_ast(n->UnrollRangeStmt.val1); + n->UnrollRangeStmt.expr = clone_ast(n->UnrollRangeStmt.expr); + n->UnrollRangeStmt.body = clone_ast(n->UnrollRangeStmt.body); break; case Ast_CaseClause: n->CaseClause.list = clone_ast_array(n->CaseClause.list); @@ -851,15 +851,15 @@ Ast *ast_range_stmt(AstFile *f, Token token, Slice vals, Token in_token, return result; } -Ast *ast_inline_range_stmt(AstFile *f, Token inline_token, Token for_token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) { - Ast *result = alloc_ast_node(f, Ast_InlineRangeStmt); - result->InlineRangeStmt.inline_token = inline_token; - result->InlineRangeStmt.for_token = for_token; - result->InlineRangeStmt.val0 = val0; - result->InlineRangeStmt.val1 = val1; - result->InlineRangeStmt.in_token = in_token; - result->InlineRangeStmt.expr = expr; - result->InlineRangeStmt.body = body; +Ast *ast_unroll_range_stmt(AstFile *f, Token unroll_token, Token for_token, Ast *val0, Ast *val1, Token in_token, Ast *expr, Ast *body) { + Ast *result = alloc_ast_node(f, Ast_UnrollRangeStmt); + result->UnrollRangeStmt.unroll_token = unroll_token; + result->UnrollRangeStmt.for_token = for_token; + result->UnrollRangeStmt.val0 = val0; + result->UnrollRangeStmt.val1 = val1; + result->UnrollRangeStmt.in_token = in_token; + result->UnrollRangeStmt.expr = expr; + result->UnrollRangeStmt.body = body; return result; } @@ -4258,9 +4258,9 @@ Ast *parse_attribute(AstFile *f, Token token, TokenKind open_kind, TokenKind clo } -Ast *parse_unrolled_for_loop(AstFile *f, Token inline_token) { - if (inline_token.kind == Token_inline) { - syntax_warning(inline_token, "'inline for' is deprecated in favour of `#unroll for'"); +Ast *parse_unrolled_for_loop(AstFile *f, Token unroll_token) { + if (unroll_token.kind == Token_inline) { + syntax_warning(unroll_token, "'inline for' is deprecated in favour of `#unroll for'"); } Token for_token = expect_token(f, Token_for); Ast *val0 = nullptr; @@ -4308,9 +4308,9 @@ Ast *parse_unrolled_for_loop(AstFile *f, Token inline_token) { body = parse_block_stmt(f, false); } if (bad_stmt) { - return ast_bad_stmt(f, inline_token, f->curr_token); + return ast_bad_stmt(f, unroll_token, f->curr_token); } - return ast_inline_range_stmt(f, inline_token, for_token, val0, val1, in_token, expr, body); + return ast_unroll_range_stmt(f, unroll_token, for_token, val0, val1, in_token, expr, body); } Ast *parse_stmt(AstFile *f) { @@ -4320,8 +4320,8 @@ Ast *parse_stmt(AstFile *f) { // Operands case Token_inline: if (peek_token_kind(f, Token_for)) { - Token inline_token = expect_token(f, Token_inline); - return parse_unrolled_for_loop(f, inline_token); + Token unroll_token = expect_token(f, Token_inline); + return parse_unrolled_for_loop(f, unroll_token); } /* fallthrough */ case Token_no_inline: -- cgit v1.2.3 From 898245431f147c9f31207f855c47d7fb54f5c53c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 26 Apr 2021 21:07:58 +0100 Subject: Make -strict-style the default #871 --- src/build_settings.cpp | 1 - src/main.cpp | 8 ++------ src/parser.cpp | 15 +++++---------- 3 files changed, 7 insertions(+), 17 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 72b72a738..5fbf75126 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -201,7 +201,6 @@ struct BuildContext { bool keep_object_files; bool disallow_do; bool insert_semicolon; - bool strict_style; bool ignore_warnings; bool warnings_as_errors; diff --git a/src/main.cpp b/src/main.cpp index c34377bfa..fbce4838c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1216,8 +1216,8 @@ bool parse_build_flags(Array args) { break; case BuildFlag_StrictStyle: - build_context.insert_semicolon = true; - build_context.strict_style = true; + gb_printf_err("-strict-style flag is not required any more\n"); + bad_flags = true; break; @@ -1802,10 +1802,6 @@ void print_show_help(String const arg0, String const &command) { print_usage_line(2, "Inserts semicolons on newlines during tokenization using a basic rule"); print_usage_line(0, ""); - print_usage_line(1, "-strict-style"); - print_usage_line(2, "Enforces code style stricter whilst parsing, requiring such things as trailing commas"); - print_usage_line(0, ""); - print_usage_line(1, "-ignore-warnings"); print_usage_line(2, "Ignores warning messages"); print_usage_line(0, ""); diff --git a/src/parser.cpp b/src/parser.cpp index c3bfc4dab..7ee710d6a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1232,13 +1232,10 @@ void comsume_comment_groups(AstFile *f, Token prev) { } bool ignore_newlines(AstFile *f) { - if (build_context.strict_style) { - if (f->allow_newline) { - return f->expr_level > 0; - } - return f->expr_level >= 0; + if (f->allow_newline) { + return f->expr_level > 0; } - return false; + return f->expr_level >= 0; } @@ -1556,7 +1553,7 @@ bool is_semicolon_optional_for_node(AstFile *f, Ast *s) { } void expect_semicolon_newline_error(AstFile *f, Token const &token, Ast *s) { - if (build_context.strict_style && token.string == "\n") { + if (token.string == "\n") { switch (token.kind) { case Token_CloseBrace: case Token_CloseParen: @@ -4556,9 +4553,7 @@ ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) { return ParseFile_WrongExtension; } TokenizerFlags tokenizer_flags = TokenizerFlag_None; - if (build_context.insert_semicolon) { - tokenizer_flags = TokenizerFlag_InsertSemicolon; - } + tokenizer_flags = TokenizerFlag_InsertSemicolon; zero_item(&f->tokenizer); f->tokenizer.curr_file_id = f->id; -- cgit v1.2.3 From 6d1eb473cf43c02e5dc7c928d5588f88b8755354 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 26 Apr 2021 21:25:44 +0100 Subject: Correct `\n` ignore rules --- core/sys/windows/types.odin | 2 +- src/parser.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'src/parser.cpp') diff --git a/core/sys/windows/types.odin b/core/sys/windows/types.odin index f42d11cd4..61ed343fe 100644 --- a/core/sys/windows/types.odin +++ b/core/sys/windows/types.odin @@ -848,7 +848,7 @@ SID_TYPE :: enum SID_NAME_USE { Unknown, Computer, Label, - LogonSession + LogonSession, } SECURITY_MAX_SID_SIZE :: 68; diff --git a/src/parser.cpp b/src/parser.cpp index 7ee710d6a..237199739 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1553,7 +1553,7 @@ bool is_semicolon_optional_for_node(AstFile *f, Ast *s) { } void expect_semicolon_newline_error(AstFile *f, Token const &token, Ast *s) { - if (token.string == "\n") { + if (!build_context.insert_semicolon && token.string == "\n") { switch (token.kind) { case Token_CloseBrace: case Token_CloseParen: @@ -2109,12 +2109,15 @@ Ast *parse_operand(AstFile *f, bool lhs) { return ast_proc_group(f, token, open, close, args); } + Ast *type = parse_proc_type(f, token); Token where_token = {}; Array where_clauses = {}; u64 tags = 0; + skip_possible_newline_for_literal(f); + if (f->curr_token.kind == Token_where) { where_token = expect_token(f, Token_where); isize prev_level = f->expr_level; @@ -2875,6 +2878,9 @@ Ast *parse_expr(AstFile *f, bool lhs) { Array parse_expr_list(AstFile *f, bool lhs) { + bool allow_newline = f->allow_newline; + f->allow_newline = true; + auto list = array_make(heap_allocator()); for (;;) { Ast *e = parse_expr(f, lhs); @@ -2886,6 +2892,8 @@ Array parse_expr_list(AstFile *f, bool lhs) { advance_token(f); } + f->allow_newline = allow_newline; + return list; } @@ -4552,8 +4560,7 @@ ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) { if (!string_ends_with(f->fullpath, str_lit(".odin"))) { return ParseFile_WrongExtension; } - TokenizerFlags tokenizer_flags = TokenizerFlag_None; - tokenizer_flags = TokenizerFlag_InsertSemicolon; + TokenizerFlags tokenizer_flags = TokenizerFlag_InsertSemicolon; zero_item(&f->tokenizer); f->tokenizer.curr_file_id = f->id; -- cgit v1.2.3 From 7e0c78eae72791e0da5cd9c279677c505eb8ead7 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 26 Apr 2021 21:39:49 +0100 Subject: Fix logic for `\n` ignoring --- src/parser.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 237199739..aff7c6bc7 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1971,12 +1971,21 @@ Ast *parse_operand(AstFile *f, bool lhs) { break; case Token_OpenParen: { + bool allow_newline; Token open, close; // NOTE(bill): Skip the Paren Expression open = expect_token(f, Token_OpenParen); + allow_newline = f->allow_newline; + if (f->expr_level < 0) { + f->allow_newline = false; + } + f->expr_level++; operand = parse_expr(f, false); f->expr_level--; + + f->allow_newline = allow_newline; + close = expect_token(f, Token_CloseParen); return ast_paren_expr(f, operand, open, close); } -- cgit v1.2.3 From 04535b291310ff53c19fdc96817f2a651b540907 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 26 Apr 2021 22:36:20 +0100 Subject: Fix constant aliasing for debug information --- src/check_decl.cpp | 2 +- src/llvm_backend.cpp | 8 ++++++-- src/parser.cpp | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/check_decl.cpp b/src/check_decl.cpp index 218dce2ee..f008317ad 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -359,7 +359,7 @@ void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { } if (original_entity->identifier != nullptr && original_entity->identifier->kind == Ast_Ident) { - original_entity->identifier->Ident.entity = new_entity; + original_entity->identifier->Ident.entity = nullptr; } original_entity->flags |= EntityFlag_Overridden; diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 0fd778b9c..758f8e5d1 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -3544,7 +3544,9 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { Ast *ident = vd->names[i]; GB_ASSERT(ident->kind == Ast_Ident); Entity *e = entity_of_node(ident); - GB_ASSERT(e != nullptr); + if (e == nullptr) { + continue; + } if (e->kind != Entity_TypeName) { continue; } @@ -3573,7 +3575,9 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { Ast *ident = vd->names[i]; GB_ASSERT(ident->kind == Ast_Ident); Entity *e = entity_of_node(ident); - GB_ASSERT(e != nullptr); + if (e == nullptr) { + continue; + } if (e->kind != Entity_Procedure) { continue; } diff --git a/src/parser.cpp b/src/parser.cpp index aff7c6bc7..c81827aa3 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1502,6 +1502,10 @@ bool is_semicolon_optional_for_node(AstFile *f, Ast *s) { return false; } + if (build_context.insert_semicolon) { + return true; + } + switch (s->kind) { case Ast_EmptyStmt: case Ast_BlockStmt: -- cgit v1.2.3 From c07ab5f9adae9a2783b4f4999a599b0d644922fb Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 26 Apr 2021 23:02:00 +0100 Subject: Change expr_level increment rules within a compound literal --- src/parser.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index c81827aa3..07ecf10f8 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1719,11 +1719,9 @@ Array parse_element_list(AstFile *f) { Ast *parse_literal_value(AstFile *f, Ast *type) { Array elems = {}; Token open = expect_token(f, Token_OpenBrace); - f->expr_level++; if (f->curr_token.kind != Token_CloseBrace) { elems = parse_element_list(f); } - f->expr_level--; Token close = expect_closing(f, Token_CloseBrace, str_lit("compound literal")); return ast_compound_lit(f, type, elems, open, close); -- cgit v1.2.3 From 94fd59e6f0e509f823edd3c90130841510cceb70 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Mon, 26 Apr 2021 23:05:00 +0100 Subject: Make compound literals require trailing commas if followed by a newline --- src/parser.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 07ecf10f8..a7e4c9162 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1719,9 +1719,12 @@ Array parse_element_list(AstFile *f) { Ast *parse_literal_value(AstFile *f, Ast *type) { Array elems = {}; Token open = expect_token(f, Token_OpenBrace); + isize expr_level = f->expr_level; + f->expr_level = 0; if (f->curr_token.kind != Token_CloseBrace) { elems = parse_element_list(f); } + f->expr_level = expr_level; Token close = expect_closing(f, Token_CloseBrace, str_lit("compound literal")); return ast_compound_lit(f, type, elems, open, close); -- cgit v1.2.3