From 289908e0b8a42dfe215555245d2291c2aaa41f4f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 15 Oct 2020 16:25:57 +0100 Subject: [PATCH] Add `+build ignore` tag --- src/parser.cpp | 49 ++++++++++++++++++++++++++++--------------------- src/parser.hpp | 1 + 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/parser.cpp b/src/parser.cpp index 2fb7572c7..b0ef534a9 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -4507,12 +4507,14 @@ bool try_add_import_path(Parser *p, String const &path, String const &rel_path, // NOTE(bill): Single file initial package if (kind == Package_Init && string_ends_with(path, FILE_EXT)) { + FileInfo fi = {}; fi.name = filename_from_path(path); fi.fullpath = path; fi.size = get_file_size(path); fi.is_dir = false; + pkg->is_single_file = true; parser_add_file_to_process(p, pkg, fi, pos); parser_add_package(p, pkg); return true; @@ -4866,28 +4868,34 @@ bool parse_build_tag(Token token_for_pos, String s) { } } - if (p.len > 0) { - TargetOsKind os = get_target_os_from_string(p); - TargetArchKind arch = get_target_arch_from_string(p); - if (os != TargetOs_Invalid) { - GB_ASSERT(arch == TargetArch_Invalid); - if (is_notted) { - this_kind_correct = this_kind_correct && (os != build_context.metrics.os); - } else { - this_kind_correct = this_kind_correct && (os == build_context.metrics.os); - } - } else if (arch != TargetArch_Invalid) { - if (is_notted) { - this_kind_correct = this_kind_correct && (arch != build_context.metrics.arch); - } else { - this_kind_correct = this_kind_correct && (arch == build_context.metrics.arch); - } + if (p.len == 0) { + continue; + } + if (p == "ignore") { + this_kind_correct = false; + continue; + } + + TargetOsKind os = get_target_os_from_string(p); + TargetArchKind arch = get_target_arch_from_string(p); + if (os != TargetOs_Invalid) { + GB_ASSERT(arch == TargetArch_Invalid); + if (is_notted) { + this_kind_correct = this_kind_correct && (os != build_context.metrics.os); + } else { + this_kind_correct = this_kind_correct && (os == build_context.metrics.os); } - if (os == TargetOs_Invalid && arch == TargetArch_Invalid) { - syntax_error(token_for_pos, "Invalid build tag platform: %.*s", LIT(p)); - break; + } else if (arch != TargetArch_Invalid) { + if (is_notted) { + this_kind_correct = this_kind_correct && (arch != build_context.metrics.arch); + } else { + this_kind_correct = this_kind_correct && (arch == build_context.metrics.arch); } } + if (os == TargetOs_Invalid && arch == TargetArch_Invalid) { + syntax_error(token_for_pos, "Invalid build tag platform: %.*s", LIT(p)); + break; + } } while (s.len > 0); any_correct = any_correct || this_kind_correct; @@ -4942,7 +4950,7 @@ bool parse_file(Parser *p, AstFile *f) { } f->package_name = package_name.string; - if (docs != nullptr && docs->list.count > 0) { + if (!f->pkg->is_single_file && docs != nullptr && docs->list.count > 0) { for_array(i, docs->list) { Token tok = docs->list[i]; GB_ASSERT(tok.kind == Token_Comment); String str = tok.string; @@ -4996,7 +5004,6 @@ ParseFileError process_imported_file(Parser *p, ImportedFile const &imported_fil AstFile *file = gb_alloc_item(heap_allocator(), AstFile); file->pkg = pkg; - file->id = imported_file.index+1; TokenPos err_pos = {0}; diff --git a/src/parser.hpp b/src/parser.hpp index c123cee0e..9e20ffc1b 100644 --- a/src/parser.hpp +++ b/src/parser.hpp @@ -128,6 +128,7 @@ struct AstPackage { String name; String fullpath; Array files; + bool is_single_file; // NOTE(bill): Created/set in checker Scope * scope;