From 7bf46c36bb01891b21fab0b8425cd58be2f11203 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 27 Dec 2020 17:15:26 +0200 Subject: [PATCH] vfmt: add a comment about the role of the .is_worker field --- cmd/tools/vfmt.v | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/cmd/tools/vfmt.v b/cmd/tools/vfmt.v index f489998c98..a5b33c4a47 100644 --- a/cmd/tools/vfmt.v +++ b/cmd/tools/vfmt.v @@ -24,8 +24,7 @@ struct FormatOptions { is_debug bool is_noerror bool is_verify bool // exit(1) if the file is not vfmt'ed -mut: - is_worker bool + is_worker bool // true *only* in the worker processes. NB: workers can crash. } const ( @@ -137,11 +136,7 @@ fn main() { wresult := worker_result.output.split(formatted_file_token) formatted_warn_errs := wresult[0] formatted_file_path := wresult[1].trim_right('\n\r') - foptions.is_worker = true - foptions.post_process_file(fpath, formatted_file_path) or { - errors = errors + 1 - } - foptions.is_worker = false + foptions.post_process_file(fpath, formatted_file_path) or { errors = errors + 1 } if formatted_warn_errs.len > 0 { eprintln(formatted_warn_errs) } @@ -251,9 +246,7 @@ fn (foptions &FormatOptions) post_process_file(file string, formatted_file_path } if foptions.is_w { if is_formatted_different { - os.mv_by_cp(formatted_file_path, file) or { - panic(err) - } + os.mv_by_cp(formatted_file_path, file) or { panic(err) } eprintln('Reformatted file: $file') } else { eprintln('Already formatted file: $file') @@ -283,9 +276,7 @@ fn file_to_target_os(file string) string { fn file_to_mod_name_and_is_module_file(file string) (string, bool) { mut mod_name := 'main' mut is_module_file := false - flines := read_source_lines(file) or { - return mod_name, is_module_file - } + flines := read_source_lines(file) or { return mod_name, is_module_file } for fline in flines { line := fline.trim_space() if line.starts_with('module ') { @@ -300,9 +291,7 @@ fn file_to_mod_name_and_is_module_file(file string) (string, bool) { } fn read_source_lines(file string) ?[]string { - source_lines := os.read_lines(file) or { - return error('can not read $file') - } + source_lines := os.read_lines(file) or { return error('can not read $file') } return source_lines } @@ -313,9 +302,7 @@ fn get_compile_name_of_potential_v_project(file string) string { pfolder := os.real_path(os.dir(file)) // a .v project has many 'module main' files in one folder // if there is only one .v file, then it must be a standalone - all_files_in_pfolder := os.ls(pfolder) or { - panic(err) - } + all_files_in_pfolder := os.ls(pfolder) or { panic(err) } mut vfiles := []string{} for f in all_files_in_pfolder { vf := os.join_path(pfolder, f) @@ -335,9 +322,7 @@ fn get_compile_name_of_potential_v_project(file string) string { // a project folder, that should be compiled with `v pfolder`. mut main_fns := 0 for f in vfiles { - slines := read_source_lines(f) or { - panic(err) - } + slines := read_source_lines(f) or { panic(err) } for line in slines { if line.contains('fn main()') { main_fns++