From 65b4c793f011ab67ad51773273ebc4333c12bff5 Mon Sep 17 00:00:00 2001 From: Lucas Perlind Date: Sun, 27 Apr 2025 22:47:03 +1000 Subject: Add -vet-explicit-allocators This vet flag will make it so that allocators must be explicitly used in places where context.allocator and context.temp_allocator are a procedure parameter. The goal of this flag is to prevent using the context.allocator in cases where a different allocator was meant to be used. Some code bases default context.allocator to nil/panic allocator to catch this at runtime. This effectively makes it a compile time error instead. --- src/parser.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index a397585e8..ea95dac31 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -33,6 +33,10 @@ gb_internal bool ast_file_vet_deprecated(AstFile *f) { return (ast_file_vet_flags(f) & VetFlag_Deprecated) != 0; } +gb_internal bool ast_file_vet_explicit_allocators(AstFile *f) { + return (ast_file_vet_flags(f) & VetFlag_ExplicitAllocators) != 0; +} + gb_internal bool file_allow_newline(AstFile *f) { bool is_strict = build_context.strict_style || ast_file_vet_style(f); return !is_strict; @@ -6325,6 +6329,7 @@ gb_internal u64 parse_vet_tag(Token token_for_pos, String s) { error_line("\textra\n"); error_line("\tcast\n"); error_line("\ttabs\n"); + error_line("\texplicit-allocators\n"); return build_context.vet_flags; } } -- cgit v1.2.3 From 38faec757d4e4648a86fb17a1fda0e2399a3ea19 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 11 Jul 2025 18:41:40 +0100 Subject: Correct consume comment groups in both parsers --- core/odin/parser/parser.odin | 37 ++++++++++++++++++++----------------- src/parser.cpp | 37 ++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 34 deletions(-) (limited to 'src/parser.cpp') diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 27b7edbf6..18dd9aa88 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -348,27 +348,30 @@ consume_comment_group :: proc(p: ^Parser, n: int) -> (comments: ^ast.Comment_Gro } consume_comment_groups :: proc(p: ^Parser, prev: tokenizer.Token) { - if p.curr_tok.kind == .Comment { - comment: ^ast.Comment_Group - end_line := 0 - - if p.curr_tok.pos.line == prev.pos.line { - comment, end_line = consume_comment_group(p, 0) - if p.curr_tok.pos.line != end_line || p.curr_tok.kind == .EOF { - p.line_comment = comment - } - } + if p.curr_tok.kind != .Comment { + return + } + comment: ^ast.Comment_Group + end_line := 0 - end_line = -1 - for p.curr_tok.kind == .Comment { - comment, end_line = consume_comment_group(p, 1) - } - if end_line+1 >= p.curr_tok.pos.line || end_line < 0 { - p.lead_comment = comment + if p.curr_tok.pos.line == prev.pos.line { + comment, end_line = consume_comment_group(p, 0) + if p.curr_tok.pos.line != end_line || + p.curr_tok.pos.line == prev.pos.line+1 || + p.curr_tok.kind == .EOF { + p.line_comment = comment } + } - assert(p.curr_tok.kind != .Comment) + end_line = -1 + for p.curr_tok.kind == .Comment { + comment, end_line = consume_comment_group(p, 1) } + if end_line+1 >= p.curr_tok.pos.line || end_line < 0 { + p.lead_comment = comment + } + + assert(p.curr_tok.kind != .Comment) } advance_token :: proc(p: ^Parser) -> tokenizer.Token { diff --git a/src/parser.cpp b/src/parser.cpp index 942e83f29..f6871c978 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1436,27 +1436,30 @@ gb_internal CommentGroup *consume_comment_group(AstFile *f, isize n, isize *end_ } gb_internal void consume_comment_groups(AstFile *f, Token prev) { - if (f->curr_token.kind == Token_Comment) { - CommentGroup *comment = nullptr; - isize end_line = 0; - - if (f->curr_token.pos.line == prev.pos.line) { - comment = consume_comment_group(f, 0, &end_line); - if (f->curr_token.pos.line != end_line || f->curr_token.kind == Token_EOF) { - f->line_comment = comment; - } - } + if (f->curr_token.kind != Token_Comment) { + return; + } + CommentGroup *comment = nullptr; + isize end_line = 0; - end_line = -1; - while (f->curr_token.kind == Token_Comment) { - comment = consume_comment_group(f, 1, &end_line); - } - if (end_line+1 == f->curr_token.pos.line || end_line < 0) { - f->lead_comment = comment; + if (f->curr_token.pos.line == prev.pos.line) { + comment = consume_comment_group(f, 0, &end_line); + if (f->curr_token.pos.line != end_line || + f->curr_token.pos.line == prev.pos.line+1 || + f->curr_token.kind == Token_EOF) { + f->line_comment = comment; } + } - GB_ASSERT(f->curr_token.kind != Token_Comment); + end_line = -1; + while (f->curr_token.kind == Token_Comment) { + comment = consume_comment_group(f, 1, &end_line); + } + if (end_line+1 == f->curr_token.pos.line || end_line < 0) { + f->lead_comment = comment; } + + GB_ASSERT(f->curr_token.kind != Token_Comment); } gb_internal gb_inline bool ignore_newlines(AstFile *f) { -- cgit v1.2.3 From b811414ed1f014aef464d4fa5195e77cbde7ba73 Mon Sep 17 00:00:00 2001 From: Harold Brenes Date: Sun, 13 Jul 2025 15:24:53 -0400 Subject: Use fi.is_dir instead of path_is_directory() when checking if an import is a directory with a .odin extension. --- src/parser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index f6871c978..5d0a75f8a 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5797,7 +5797,7 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String path, String const for (FileInfo fi : list) { String name = fi.name; String ext = path_extension(name); - if (ext == FILE_EXT && !path_is_directory(name)) { + if (ext == FILE_EXT && !fi.is_dir) { files_with_ext += 1; } if (ext == FILE_EXT && !is_excluded_target_filename(name)) { @@ -5822,7 +5822,7 @@ gb_internal AstPackage *try_add_import_path(Parser *p, String path, String const for (FileInfo fi : list) { String name = fi.name; String ext = path_extension(name); - if (ext == FILE_EXT && !path_is_directory(name)) { + if (ext == FILE_EXT && !fi.is_dir) { if (is_excluded_target_filename(name)) { continue; } -- cgit v1.2.3 From 7c917d56e9d07a5c8940560d7f1d35c01bc5fe58 Mon Sep 17 00:00:00 2001 From: Harold Brenes Date: Wed, 16 Jul 2025 16:05:58 -0400 Subject: Check for invalid subtargets. - Add 'ios' pseudo-subtarget which triggets with either iPhone or iPhoneSimulator subtargets. - Treat an explicit 'default' subtarget as exclusive only to the default subtarget, not an other platform-compatible subtargets. - 'generic' continues to resolve to true for any platform-compatible subtarget as it names appears to imply such behavior. --- src/build_settings.cpp | 31 ++++++++++++++++++++----------- src/parser.cpp | 26 +++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 14 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/build_settings.cpp b/src/build_settings.cpp index fb88b588a..ab501fe84 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -174,8 +174,9 @@ enum Subtarget : u32 { Subtarget_iPhone, Subtarget_iPhoneSimulator, Subtarget_Android, - + Subtarget_COUNT, + Subtarget_Invalid, // NOTE(harold): Must appear after _COUNT as this is not a real subtarget }; gb_global String subtarget_strings[Subtarget_COUNT] = { @@ -859,7 +860,7 @@ gb_global NamedTargetMetrics *selected_target_metrics; gb_global Subtarget selected_subtarget; -gb_internal TargetOsKind get_target_os_from_string(String str, Subtarget *subtarget_ = nullptr) { +gb_internal TargetOsKind get_target_os_from_string(String str, Subtarget *subtarget_ = nullptr, String *subtarget_str = nullptr) { String os_name = str; String subtarget = {}; auto part = string_partition(str, str_lit(":")); @@ -876,18 +877,26 @@ gb_internal TargetOsKind get_target_os_from_string(String str, Subtarget *subtar break; } } - if (subtarget_) *subtarget_ = Subtarget_Default; - if (subtarget.len != 0) { - if (str_eq_ignore_case(subtarget, "generic") || str_eq_ignore_case(subtarget, "default")) { - if (subtarget_) *subtarget_ = Subtarget_Default; - } else { - for (isize i = 1; i < Subtarget_COUNT; i++) { - if (str_eq_ignore_case(subtarget_strings[i], subtarget)) { - if (subtarget_) *subtarget_ = cast(Subtarget)i; - break; + if (subtarget_str) *subtarget_str = subtarget; + + if (subtarget_) { + if (subtarget.len != 0) { + *subtarget_ = Subtarget_Invalid; + + if (str_eq_ignore_case(subtarget, "generic") || str_eq_ignore_case(subtarget, "default")) { + *subtarget_ = Subtarget_Default; + + } else { + for (isize i = 1; i < Subtarget_COUNT; i++) { + if (str_eq_ignore_case(subtarget_strings[i], subtarget)) { + *subtarget_ = cast(Subtarget)i; + break; + } } } + } else { + *subtarget_ = Subtarget_Default; } } diff --git a/src/parser.cpp b/src/parser.cpp index 5d0a75f8a..7a2693e29 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -6220,9 +6220,10 @@ gb_internal bool parse_build_tag(Token token_for_pos, String s) { continue; } - Subtarget subtarget = Subtarget_Default; + Subtarget subtarget = Subtarget_Invalid; + String subtarget_str = {}; - TargetOsKind os = get_target_os_from_string(p, &subtarget); + TargetOsKind os = get_target_os_from_string(p, &subtarget, &subtarget_str); TargetArchKind arch = get_target_arch_from_string(p); num_tokens += 1; @@ -6233,10 +6234,29 @@ gb_internal bool parse_build_tag(Token token_for_pos, String s) { break; } + bool is_ios_subtarget = false; + if (subtarget == Subtarget_Invalid) { + // Special case for pseudo subtarget + if (!str_eq_ignore_case(subtarget_str, "ios")) { + syntax_error(token_for_pos, "Invalid subtarget '%.*s'.", LIT(subtarget_str)); + break; + } + + is_ios_subtarget = true; + } + + if (os != TargetOs_Invalid) { this_kind_os_seen = true; - bool same_subtarget = (subtarget == Subtarget_Default) || (subtarget == selected_subtarget); + // NOTE: Only testing for 'default' and not 'generic' because the 'generic' nomenclature implies any subtarget. + bool is_explicit_default_subtarget = str_eq_ignore_case(subtarget_str, "default"); + bool same_subtarget = (subtarget == Subtarget_Default && !is_explicit_default_subtarget) || (subtarget == selected_subtarget); + + // Special case for iPhone or iPhoneSimulator + if (is_ios_subtarget && (selected_subtarget == Subtarget_iPhone || selected_subtarget == Subtarget_iPhoneSimulator)) { + same_subtarget = true; + } GB_ASSERT(arch == TargetArch_Invalid); if (is_notted) { -- cgit v1.2.3