vfmt: ran `v vet vlib/v/` and fix spaces

pull/5656/head
Delyan Angelov 2020-07-04 16:19:54 +03:00
parent d2a2db7bff
commit fe50bdc164
7 changed files with 56 additions and 72 deletions

View File

@ -36,7 +36,6 @@ pub fn (mut o OrderedDepMap) add(name string, deps []string) {
if dep !in d { if dep !in d {
d << dep d << dep
} }
//
else{} else{}
} }
o.set(name, d) o.set(name, d)

View File

@ -1,6 +1,6 @@
import v.table //import v.table
import v.doc //import v.doc
import v.pref //import v.pref
// fn test_vdoc() { // fn test_vdoc() {
// mut prefs := &pref.Preferences{} // mut prefs := &pref.Preferences{}

View File

@ -59,7 +59,7 @@ fn test_fmt() {
} }
vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${ifilename}') vfmt_result_file := os.join_path(tmpfolder, 'vfmt_run_over_${ifilename}')
os.write_file(vfmt_result_file, result_ocontent) os.write_file(vfmt_result_file, result_ocontent)
eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file)) eprintln(util.color_compare_files(diff_cmd, opath, vfmt_result_file))
continue continue
} }
fmt_bench.ok() fmt_bench.ok()

View File

@ -398,9 +398,9 @@ typedef byte array_fixed_byte_300 [300];
typedef byte array_fixed_byte_400 [400]; typedef byte array_fixed_byte_400 [400];
#ifndef __cplusplus #ifndef __cplusplus
#ifndef bool #ifndef bool
typedef int bool; typedef int bool;
#define true 1 #define true 1
#define false 0 #define false 0
#endif #endif
#endif #endif

View File

@ -9,8 +9,7 @@ import os
pub enum BuildMode { pub enum BuildMode {
// `v program.v' // `v program.v'
// Build user code only, and add pre-compiled vlib (`cc program.o builtin.o os.o...`) // Build user code only, and add pre-compiled vlib (`cc program.o builtin.o os.o...`)
default_mode default_mode // `v -lib ~/v/os`
// `v -lib ~/v/os`
// build any module (generate os.o + os.vh) // build any module (generate os.o + os.vh)
build_module build_module
} }
@ -27,9 +26,9 @@ pub enum ColorOutput {
} }
pub enum Backend { pub enum Backend {
c // The (default) C backend c // The (default) C backend
js // The JavaScript backend js // The JavaScript backend
x64 // The x64 backend x64 // The x64 backend
} }
pub enum CompilerType { pub enum CompilerType {
@ -41,20 +40,18 @@ pub enum CompilerType {
} }
const ( const (
list_of_flags_with_param = [ list_of_flags_with_param = ['o', 'output', 'd', 'define', 'b', 'backend', 'cc', 'os', 'target-os',
'o' 'arch', 'csource', 'cf', 'cflags', 'path']
'output', 'd', 'define', 'b', 'backend', 'cc', 'os', 'target-os', 'arch', 'csource'
'cf', 'cflags', 'path']
) )
pub struct Preferences { pub struct Preferences {
pub mut: pub mut:
os OS // the OS to compile for os OS // the OS to compile for
backend Backend backend Backend
build_mode BuildMode build_mode BuildMode
output_mode OutputMode = .stdout output_mode OutputMode = .stdout
//verbosity VerboseLevel // verbosity VerboseLevel
is_verbose bool is_verbose bool
// nofmt bool // disable vfmt // nofmt bool // disable vfmt
is_test bool // `v test string_test.v` is_test bool // `v test string_test.v`
is_script bool // single file mode (`v program.v`), main function can be skipped is_script bool // single file mode (`v program.v`), main function can be skipped
@ -76,7 +73,7 @@ pub mut:
show_cc bool // -showcc, print cc command show_cc bool // -showcc, print cc command
// NB: passing -cg instead of -g will set is_vlines to false and is_g to true, thus making v generate cleaner C files, // NB: passing -cg instead of -g will set is_vlines to false and is_g to true, thus making v generate cleaner C files,
// which are sometimes easier to debug / inspect manually than the .tmp.c files by plain -g (when/if v line number generation breaks). // which are sometimes easier to debug / inspect manually than the .tmp.c files by plain -g (when/if v line number generation breaks).
use_cache bool // turns on v usage of the module cache to speed up compilation. use_cache bool // turns on v usage of the module cache to speed up compilation.
is_stats bool // `v -stats file_test.v` will produce more detailed statistics for the tests that were run is_stats bool // `v -stats file_test.v` will produce more detailed statistics for the tests that were run
no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers) no_auto_free bool // `v -nofree` disable automatic `free()` insertion for better performance in some applications (e.g. compilers)
// TODO Convert this into a []string // TODO Convert this into a []string
@ -100,31 +97,29 @@ pub mut:
is_vet bool is_vet bool
is_bare bool is_bare bool
no_preludes bool // Prevents V from generating preludes in resulting .c files no_preludes bool // Prevents V from generating preludes in resulting .c files
custom_prelude string // Contents of custom V prelude that will be prepended before code in resulting .c files custom_prelude string // Contents of custom V prelude that will be prepended before code in resulting .c files
lookup_path []string lookup_path []string
output_cross_c bool output_cross_c bool
prealloc bool prealloc bool
vroot string vroot string
out_name string out_name string
path string // Path to file/folder to compile path string // Path to file/folder to compile
// -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another { will NOT get here }` // -d vfmt and -d another=0 for `$if vfmt { will execute }` and `$if another { will NOT get here }`
compile_defines []string // just ['vfmt'] compile_defines []string // just ['vfmt']
compile_defines_all []string // contains both: ['vfmt','another'] compile_defines_all []string // contains both: ['vfmt','another']
run_args []string // `v run x.v 1 2 3` => `1 2 3` run_args []string // `v run x.v 1 2 3` => `1 2 3`
printfn_list []string // a list of generated function names, whose source should be shown, for debugging printfn_list []string // a list of generated function names, whose source should be shown, for debugging
print_v_files bool // when true, just print the list of all parsed .v files then stop. print_v_files bool // when true, just print the list of all parsed .v files then stop.
skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js) skip_running bool // when true, do no try to run the produced file (set by b.cc(), when -o x.c or -o x.js)
skip_warnings bool // like C's "-w" skip_warnings bool // like C's "-w"
use_color ColorOutput // whether the warnings/errors should use ANSI color escapes. use_color ColorOutput // whether the warnings/errors should use ANSI color escapes.
is_parallel bool is_parallel bool
error_limit int error_limit int
is_vweb bool // skip _ var warning in templates is_vweb bool // skip _ var warning in templates
} }
pub fn parse_args(args []string) (&Preferences, string) { pub fn parse_args(args []string) (&Preferences, string) {
mut res := &pref.Preferences{} mut res := &Preferences{}
mut command := '' mut command := ''
mut command_pos := 0 mut command_pos := 0
// for i, arg in args { // for i, arg in args {
@ -222,7 +217,7 @@ pub fn parse_args(args []string) (&Preferences, string) {
'-os' { '-os' {
target_os := cmdline.option(current_args, '-os', '') target_os := cmdline.option(current_args, '-os', '')
i++ i++
target_os_kind := pref.os_from_string(target_os) or { target_os_kind := os_from_string(target_os) or {
if target_os == 'cross' { if target_os == 'cross' {
res.output_cross_c = true res.output_cross_c = true
continue continue
@ -256,7 +251,7 @@ pub fn parse_args(args []string) (&Preferences, string) {
i++ i++
} }
'-b' { '-b' {
b := pref.backend_from_string(cmdline.option(current_args, '-b', 'c')) or { b := backend_from_string(cmdline.option(current_args, '-b', 'c')) or {
continue continue
} }
res.backend = b res.backend = b
@ -318,46 +313,37 @@ pub fn parse_args(args []string) (&Preferences, string) {
return res, command return res, command
} }
pub fn backend_from_string(s string) ?Backend { pub fn backend_from_string(s string) ?Backend {
match s { match s {
'c' { 'c' { return .c }
return .c 'js' { return .js }
} 'x64' { return .x64 }
'js' { else { return error('Unknown backend type $s') }
return .js
}
'x64' {
return .x64
}
else {
return error('Unknown backend type $s')
}
} }
} }
fn parse_define(mut prefs Preferences, define string) { fn parse_define(mut prefs Preferences, define string) {
define_parts := define.split('=') define_parts := define.split('=')
if define_parts.len == 1 { if define_parts.len == 1 {
prefs.compile_defines << define prefs.compile_defines << define
prefs.compile_defines_all << define prefs.compile_defines_all << define
return return
} }
if define_parts.len == 2 { if define_parts.len == 2 {
prefs.compile_defines_all << define_parts[0] prefs.compile_defines_all << define_parts[0]
match define_parts[1] { match define_parts[1] {
'0' {} '0' {}
'1' { '1' {
prefs.compile_defines << define_parts[0] prefs.compile_defines << define_parts[0]
} }
else { else {
println('V error: Unknown define argument value `${define_parts[1]}` for ${define_parts[0]}.' + println('V error: Unknown define argument value `${define_parts[1]}` for ${define_parts[0]}.' +
'Expected `0` or `1`.') 'Expected `0` or `1`.')
exit(1) exit(1)
} }
} }
return return
} }
println('V error: Unknown define argument: ${define}. Expected at most one `=`.') println('V error: Unknown define argument: ${define}. Expected at most one `=`.')
exit(1) exit(1)
} }

View File

@ -227,7 +227,6 @@ pub fn (mut t Table) register_builtin_type_symbol(typ TypeSymbol) int {
kind: existing_type.kind kind: existing_type.kind
} }
} }
//
else { else {
t.types[existing_idx] = typ t.types[existing_idx] = typ
} }

View File

@ -170,8 +170,8 @@ pub fn color_compare_files(diff_cmd, file1, file2 string) string {
' --show-function-line="fn " $other_options "$file1" "$file2" ' ' --show-function-line="fn " $other_options "$file1" "$file2" '
x := os.exec(full_cmd) or { x := os.exec(full_cmd) or {
return 'comparison command: `${full_cmd}` failed' return 'comparison command: `${full_cmd}` failed'
} }
return x.output.trim_right('\r\n') return x.output.trim_right('\r\n')
} }
return '' return ''
} }