1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: add a comment about the role of the .is_worker field

This commit is contained in:
Delyan Angelov 2020-12-27 17:15:26 +02:00
parent aac8520838
commit 7bf46c36bb
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED

View File

@ -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++