| author | |
| committer | |
| log | 8ef7f6febb7132d7a1ee44199fd22006f326de5c |
| tree | 4ce5c3a8c7a54a344cee9a0e72de8fad1dd701fd |
| parent | fb2acaff067dd6b385de7f2bd2726bdfebbf841f |
Closes: #216511 files changed, 15 insertions(+), 66 deletions(-)
src/analyze.cpp+1-1| ... | ... | @@ -6072,7 +6072,7 @@ Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents) { |
| 6072 | 6072 | if (g->enable_cache) { |
| 6073 | 6073 | return cache_add_file_fetch(&g->cache_hash, resolved_path, contents); |
| 6074 | 6074 | } else { |
| 6075 | return os_fetch_file_path(resolved_path, contents, false); | |
| 6075 | return os_fetch_file_path(resolved_path, contents); | |
| 6076 | 6076 | } |
| 6077 | 6077 | } |
| 6078 | 6078 |
src/cache_hash.cpp+1-1| ... | ... | @@ -469,7 +469,7 @@ Error cache_add_file(CacheHash *ch, Buf *path) { |
| 469 | 469 | Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) { |
| 470 | 470 | Error err; |
| 471 | 471 | Buf *contents = buf_alloc(); |
| 472 | if ((err = os_fetch_file_path(dep_file_path, contents, false))) { | |
| 472 | if ((err = os_fetch_file_path(dep_file_path, contents))) { | |
| 473 | 473 | if (verbose) { |
| 474 | 474 | fprintf(stderr, "unable to read .d file: %s\n", err_str(err)); |
| 475 | 475 | } |
src/codegen.cpp+3-3| ... | ... | @@ -7870,7 +7870,7 @@ static Error define_builtin_compile_vars(CodeGen *g) { |
| 7870 | 7870 | Buf *contents; |
| 7871 | 7871 | if (hit) { |
| 7872 | 7872 | contents = buf_alloc(); |
| 7873 | if ((err = os_fetch_file_path(builtin_zig_path, contents, false))) { | |
| 7873 | if ((err = os_fetch_file_path(builtin_zig_path, contents))) { | |
| 7874 | 7874 | fprintf(stderr, "Unable to open '%s': %s\n", buf_ptr(builtin_zig_path), err_str(err)); |
| 7875 | 7875 | exit(1); |
| 7876 | 7876 | } |
| ... | ... | @@ -8299,7 +8299,7 @@ static void gen_root_source(CodeGen *g) { |
| 8299 | 8299 | Error err; |
| 8300 | 8300 | // No need for using the caching system for this file fetch because it is handled |
| 8301 | 8301 | // separately. |
| 8302 | if ((err = os_fetch_file_path(resolved_path, source_code, true))) { | |
| 8302 | if ((err = os_fetch_file_path(resolved_path, source_code))) { | |
| 8303 | 8303 | fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(resolved_path), err_str(err)); |
| 8304 | 8304 | exit(1); |
| 8305 | 8305 | } |
| ... | ... | @@ -8374,7 +8374,7 @@ static void gen_global_asm(CodeGen *g) { |
| 8374 | 8374 | Buf *asm_file = g->assembly_files.at(i); |
| 8375 | 8375 | // No need to use the caching system for these fetches because they |
| 8376 | 8376 | // are handled separately. |
| 8377 | if ((err = os_fetch_file_path(asm_file, &contents, false))) { | |
| 8377 | if ((err = os_fetch_file_path(asm_file, &contents))) { | |
| 8378 | 8378 | zig_panic("Unable to read %s: %s", buf_ptr(asm_file), err_str(err)); |
| 8379 | 8379 | } |
| 8380 | 8380 | buf_append_buf(&g->global_asm, &contents); |
src/libc_installation.cpp+1-1| ... | ... | @@ -45,7 +45,7 @@ Error zig_libc_parse(ZigLibCInstallation *libc, Buf *libc_file, const ZigTarget |
| 45 | 45 | bool found_keys[array_length(zig_libc_keys)] = {}; |
| 46 | 46 | |
| 47 | 47 | Buf *contents = buf_alloc(); |
| 48 | if ((err = os_fetch_file_path(libc_file, contents, false))) { | |
| 48 | if ((err = os_fetch_file_path(libc_file, contents))) { | |
| 49 | 49 | if (err != ErrorFileNotFound && verbose) { |
| 50 | 50 | fprintf(stderr, "Unable to read '%s': %s\n", buf_ptr(libc_file), err_str(err)); |
| 51 | 51 | } |
src/main.cpp+2-2| ... | ... | @@ -331,7 +331,7 @@ int main(int argc, char **argv) { |
| 331 | 331 | os_path_split(cwd, nullptr, cwd_basename); |
| 332 | 332 | |
| 333 | 333 | Buf *build_zig_contents = buf_alloc(); |
| 334 | if ((err = os_fetch_file_path(build_zig_path, build_zig_contents, false))) { | |
| 334 | if ((err = os_fetch_file_path(build_zig_path, build_zig_contents))) { | |
| 335 | 335 | fprintf(stderr, "Unable to read %s: %s\n", buf_ptr(build_zig_path), err_str(err)); |
| 336 | 336 | return EXIT_FAILURE; |
| 337 | 337 | } |
| ... | ... | @@ -346,7 +346,7 @@ int main(int argc, char **argv) { |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | Buf *main_zig_contents = buf_alloc(); |
| 349 | if ((err = os_fetch_file_path(main_zig_path, main_zig_contents, false))) { | |
| 349 | if ((err = os_fetch_file_path(main_zig_path, main_zig_contents))) { | |
| 350 | 350 | fprintf(stderr, "Unable to read %s: %s\n", buf_ptr(main_zig_path), err_str(err)); |
| 351 | 351 | return EXIT_FAILURE; |
| 352 | 352 | } |
src/os.cpp+5-30| ... | ... | @@ -751,39 +751,15 @@ Buf os_path_resolve(Buf **paths_ptr, size_t paths_len) { |
| 751 | 751 | #endif |
| 752 | 752 | } |
| 753 | 753 | |
| 754 | Error os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) { | |
| 754 | Error os_fetch_file(FILE *f, Buf *out_buf) { | |
| 755 | 755 | static const ssize_t buf_size = 0x2000; |
| 756 | 756 | buf_resize(out_buf, buf_size); |
| 757 | 757 | ssize_t actual_buf_len = 0; |
| 758 | 758 | |
| 759 | bool first_read = true; | |
| 760 | ||
| 761 | 759 | for (;;) { |
| 762 | 760 | size_t amt_read = fread(buf_ptr(out_buf) + actual_buf_len, 1, buf_size, f); |
| 763 | 761 | actual_buf_len += amt_read; |
| 764 | 762 | |
| 765 | if (skip_shebang && first_read && buf_starts_with_str(out_buf, "#!")) { | |
| 766 | size_t i = 0; | |
| 767 | while (true) { | |
| 768 | if (i > buf_len(out_buf)) { | |
| 769 | zig_panic("shebang line exceeded %zd characters", buf_size); | |
| 770 | } | |
| 771 | ||
| 772 | size_t current_pos = i; | |
| 773 | i += 1; | |
| 774 | ||
| 775 | if (out_buf->list.at(current_pos) == '\n') { | |
| 776 | break; | |
| 777 | } | |
| 778 | } | |
| 779 | ||
| 780 | ZigList<char> *list = &out_buf->list; | |
| 781 | memmove(list->items, list->items + i, list->length - i); | |
| 782 | list->length -= i; | |
| 783 | ||
| 784 | actual_buf_len -= i; | |
| 785 | } | |
| 786 | ||
| 787 | 763 | if (amt_read != buf_size) { |
| 788 | 764 | if (feof(f)) { |
| 789 | 765 | buf_resize(out_buf, actual_buf_len); |
| ... | ... | @@ -794,7 +770,6 @@ Error os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) { |
| 794 | 770 | } |
| 795 | 771 | |
| 796 | 772 | buf_resize(out_buf, actual_buf_len + buf_size); |
| 797 | first_read = false; | |
| 798 | 773 | } |
| 799 | 774 | zig_unreachable(); |
| 800 | 775 | } |
| ... | ... | @@ -864,8 +839,8 @@ static Error os_exec_process_posix(const char *exe, ZigList<const char *> &args, |
| 864 | 839 | |
| 865 | 840 | FILE *stdout_f = fdopen(stdout_pipe[0], "rb"); |
| 866 | 841 | FILE *stderr_f = fdopen(stderr_pipe[0], "rb"); |
| 867 | Error err1 = os_fetch_file(stdout_f, out_stdout, false); | |
| 868 | Error err2 = os_fetch_file(stderr_f, out_stderr, false); | |
| 842 | Error err1 = os_fetch_file(stdout_f, out_stdout); | |
| 843 | Error err2 = os_fetch_file(stderr_f, out_stderr); | |
| 869 | 844 | |
| 870 | 845 | fclose(stdout_f); |
| 871 | 846 | fclose(stderr_f); |
| ... | ... | @@ -1097,7 +1072,7 @@ Error os_copy_file(Buf *src_path, Buf *dest_path) { |
| 1097 | 1072 | } |
| 1098 | 1073 | } |
| 1099 | 1074 | |
| 1100 | Error os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) { | |
| 1075 | Error os_fetch_file_path(Buf *full_path, Buf *out_contents) { | |
| 1101 | 1076 | FILE *f = fopen(buf_ptr(full_path), "rb"); |
| 1102 | 1077 | if (!f) { |
| 1103 | 1078 | switch (errno) { |
| ... | ... | @@ -1116,7 +1091,7 @@ Error os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) { |
| 1116 | 1091 | return ErrorFileSystem; |
| 1117 | 1092 | } |
| 1118 | 1093 | } |
| 1119 | Error result = os_fetch_file(f, out_contents, skip_shebang); | |
| 1094 | Error result = os_fetch_file(f, out_contents); | |
| 1120 | 1095 | fclose(f); |
| 1121 | 1096 | return result; |
| 1122 | 1097 | } |
src/os.hpp+2-2| ... | ... | @@ -126,8 +126,8 @@ void os_file_close(OsFile *file); |
| 126 | 126 | Error ATTRIBUTE_MUST_USE os_write_file(Buf *full_path, Buf *contents); |
| 127 | 127 | Error ATTRIBUTE_MUST_USE os_copy_file(Buf *src_path, Buf *dest_path); |
| 128 | 128 | |
| 129 | Error ATTRIBUTE_MUST_USE os_fetch_file(FILE *file, Buf *out_contents, bool skip_shebang); | |
| 130 | Error ATTRIBUTE_MUST_USE os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang); | |
| 129 | Error ATTRIBUTE_MUST_USE os_fetch_file(FILE *file, Buf *out_contents); | |
| 130 | Error ATTRIBUTE_MUST_USE os_fetch_file_path(Buf *full_path, Buf *out_contents); | |
| 131 | 131 | |
| 132 | 132 | Error ATTRIBUTE_MUST_USE os_get_cwd(Buf *out_cwd); |
| 133 | 133 |
std/zig/ast.zig-3| ... | ... | @@ -479,7 +479,6 @@ pub const Node = struct { |
| 479 | 479 | doc_comments: ?*DocComment, |
| 480 | 480 | decls: DeclList, |
| 481 | 481 | eof_token: TokenIndex, |
| 482 | shebang: ?TokenIndex, | |
| 483 | 482 | |
| 484 | 483 | pub const DeclList = SegmentedList(*Node, 4); |
| 485 | 484 | |
| ... | ... | @@ -491,7 +490,6 @@ pub const Node = struct { |
| 491 | 490 | } |
| 492 | 491 | |
| 493 | 492 | pub fn firstToken(self: *const Root) TokenIndex { |
| 494 | if (self.shebang) |shebang| return shebang; | |
| 495 | 493 | return if (self.decls.len == 0) self.eof_token else (self.decls.at(0).*).firstToken(); |
| 496 | 494 | } |
| 497 | 495 | |
| ... | ... | @@ -2235,7 +2233,6 @@ test "iterate" { |
| 2235 | 2233 | .doc_comments = null, |
| 2236 | 2234 | .decls = Node.Root.DeclList.init(std.debug.global_allocator), |
| 2237 | 2235 | .eof_token = 0, |
| 2238 | .shebang = null, | |
| 2239 | 2236 | }; |
| 2240 | 2237 | var base = &root.base; |
| 2241 | 2238 | testing.expect(base.iterate(0) == null); |
std/zig/parse.zig-10| ... | ... | @@ -22,7 +22,6 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 22 | 22 | .base = ast.Node{ .id = ast.Node.Id.Root }, |
| 23 | 23 | .decls = ast.Node.Root.DeclList.init(arena), |
| 24 | 24 | .doc_comments = null, |
| 25 | .shebang = null, | |
| 26 | 25 | // initialized when we get the eof token |
| 27 | 26 | .eof_token = undefined, |
| 28 | 27 | }; |
| ... | ... | @@ -43,15 +42,6 @@ pub fn parse(allocator: *mem.Allocator, source: []const u8) !ast.Tree { |
| 43 | 42 | } |
| 44 | 43 | var tok_it = tree.tokens.iterator(0); |
| 45 | 44 | |
| 46 | // skip over shebang line | |
| 47 | shebang: { | |
| 48 | const shebang_tok_index = tok_it.index; | |
| 49 | const shebang_tok_ptr = tok_it.peek() orelse break :shebang; | |
| 50 | if (shebang_tok_ptr.id != Token.Id.ShebangLine) break :shebang; | |
| 51 | root_node.shebang = shebang_tok_index; | |
| 52 | _ = tok_it.next(); | |
| 53 | } | |
| 54 | ||
| 55 | 45 | // skip over line comments at the top of the file |
| 56 | 46 | while (true) { |
| 57 | 47 | const next_tok = tok_it.peek() orelse break; |
std/zig/parser_test.zig-8| ... | ... | @@ -50,14 +50,6 @@ test "zig fmt: linksection" { |
| 50 | 50 | ); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | test "zig fmt: shebang line" { | |
| 54 | try testCanonical( | |
| 55 | \\#!/usr/bin/env zig | |
| 56 | \\pub fn main() void {} | |
| 57 | \\ | |
| 58 | ); | |
| 59 | } | |
| 60 | ||
| 61 | 53 | test "zig fmt: correctly move doc comments on struct fields" { |
| 62 | 54 | try testTransform( |
| 63 | 55 | \\pub const section_64 = extern struct { |
std/zig/render.zig-5| ... | ... | @@ -73,11 +73,6 @@ fn renderRoot( |
| 73 | 73 | ) (@typeOf(stream).Child.Error || Error)!void { |
| 74 | 74 | var tok_it = tree.tokens.iterator(0); |
| 75 | 75 | |
| 76 | // render the shebang line | |
| 77 | if (tree.root_node.shebang) |shebang| { | |
| 78 | try stream.write(tree.tokenSlice(shebang)); | |
| 79 | } | |
| 80 | ||
| 81 | 76 | // render all the line comments at the beginning of the file |
| 82 | 77 | while (tok_it.next()) |token| { |
| 83 | 78 | if (token.id != Token.Id.LineComment) break; |