From 728344ff653abd4ef931dd9a8239bd31cb2253ca Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 25 Jan 2021 11:26:20 +0200 Subject: [PATCH] ci: fix `v test-cleancode` --- cmd/tools/vdoc/vdoc.v | 10 ++--- vlib/cli/help.v | 19 ++++---- vlib/flag/flag.v | 20 ++++----- vlib/math/big/big.v | 4 +- vlib/os/inode_test.v | 16 +++---- vlib/os/os.v | 6 +-- vlib/os/os_test.v | 30 ++++++------- vlib/os/os_windows.c.v | 7 +-- vlib/semver/parse.v | 9 ++-- vlib/semver/range.v | 14 +++--- vlib/semver/semver_test.v | 14 +++--- vlib/time/misc/misc.v | 2 +- vlib/time/time.v | 16 +++---- vlib/time/time_darwin.c.v | 12 ++--- vlib/time/time_format_test.v | 66 ++++++++++++++-------------- vlib/time/time_test.v | 24 +++++----- vlib/time/time_windows.c.v | 2 +- vlib/v/builder/cc.v | 6 +-- vlib/v/builder/msvc.v | 2 +- vlib/v/checker/checker.v | 22 +++++----- vlib/v/doc/comment.v | 4 +- vlib/v/fmt/fmt_keep_test.v | 12 ++--- vlib/v/fmt/fmt_test.v | 4 +- vlib/v/fmt/fmt_vlib_test.v | 4 +- vlib/v/gen/cgen_test.v | 6 +-- vlib/v/gen/live.v | 4 +- vlib/v/gen/sql.v | 10 ++--- vlib/v/gen/x64/elf.v | 22 +++++----- vlib/v/gen/x64/gen.v | 8 ++-- vlib/v/parser/comptime.v | 2 +- vlib/v/parser/parser.v | 2 +- vlib/v/parser/v_parser_test.v | 25 ++++------- vlib/v/pref/pref.v | 2 +- vlib/v/scanner/scanner.v | 36 +++++++-------- vlib/v/table/cflags.v | 10 ++--- vlib/v/table/cflags_test.v | 14 +++--- vlib/v/table/table.v | 22 +++++----- vlib/v/table/types.v | 68 ++++++++++++++--------------- vlib/v/util/errors.v | 8 ++-- vlib/v/util/quote.v | 2 +- vlib/v/util/util.v | 17 ++++---- vlib/v/vmod/vmod.v | 4 +- vlib/vweb/assets/assets.v | 4 +- vlib/vweb/tests/vweb_test.v | 56 ++++++++++++------------ vlib/vweb/tests/vweb_test_server.v | 4 +- vlib/vweb/tmpl/tmpl.v | 20 ++++----- vlib/vweb/vweb.v | 24 +++++----- vlib/x/websocket/message.v | 12 ++--- vlib/x/websocket/websocket_client.v | 2 +- 49 files changed, 353 insertions(+), 356 deletions(-) diff --git a/cmd/tools/vdoc/vdoc.v b/cmd/tools/vdoc/vdoc.v index 70c2324215..4984f9eda0 100644 --- a/cmd/tools/vdoc/vdoc.v +++ b/cmd/tools/vdoc/vdoc.v @@ -247,7 +247,7 @@ fn (mut vd VDoc) generate_docs_from_file() { exit(1) } dir_path := if cfg.is_vlib { - vroot + main.vroot } else if os.is_dir(cfg.input_path) { cfg.input_path } else { @@ -404,8 +404,8 @@ fn parse_arguments(args []string) Config { } '-f' { format := cmdline.option(current_args, '-f', '') - if format !in allowed_formats { - allowed_str := allowed_formats.join(', ') + if format !in main.allowed_formats { + allowed_str := main.allowed_formats.join(', ') eprintln('vdoc: "$format" is not a valid format. Only $allowed_str are allowed.') exit(1) } @@ -472,7 +472,7 @@ fn parse_arguments(args []string) Config { if cfg.input_path.trim_right('/') == 'vlib' { cfg.is_vlib = true cfg.is_multi = true - cfg.input_path = os.join_path(vroot, 'vlib') + cfg.input_path = os.join_path(main.vroot, 'vlib') } else if !is_path { // TODO vd.vprintln('Input "$cfg.input_path" is not a valid path. Looking for modules named "$cfg.input_path"...') mod_path := doc.lookup_module(cfg.input_path) or { @@ -486,7 +486,7 @@ fn parse_arguments(args []string) Config { fn main() { if os.args.len < 2 || '-h' in os.args || '--help' in os.args || os.args[1..] == ['doc', 'help'] { - os.system('$vexe help doc') + os.system('$main.vexe help doc') exit(0) } args := os.args[2..].clone() diff --git a/vlib/cli/help.v b/vlib/cli/help.v index 4a28e820f0..ed2a35e90f 100644 --- a/vlib/cli/help.v +++ b/vlib/cli/help.v @@ -75,21 +75,21 @@ fn (cmd Command) help_message() string { help += '\n$cmd.description\n' } mut abbrev_len := 0 - mut name_len := min_description_indent_len + mut name_len := cli.min_description_indent_len if cmd.flags.have_abbrev() { for flag in cmd.flags { - abbrev_len = max(abbrev_len, flag.abbrev.len + spacing + 1) // + 1 for '-' in front - name_len = max(name_len, abbrev_len + flag.name.len + spacing + 2) // + 2 for '--' in front + abbrev_len = max(abbrev_len, flag.abbrev.len + cli.spacing + 1) // + 1 for '-' in front + name_len = max(name_len, abbrev_len + flag.name.len + cli.spacing + 2) // + 2 for '--' in front } for command in cmd.commands { - name_len = max(name_len, command.name.len + spacing) + name_len = max(name_len, command.name.len + cli.spacing) } } else { for flag in cmd.flags { - name_len = max(name_len, abbrev_len + flag.name.len + spacing + 1) // + 1 for '-' in front + name_len = max(name_len, abbrev_len + flag.name.len + cli.spacing + 1) // + 1 for '-' in front } for command in cmd.commands { - name_len = max(name_len, command.name.len + spacing) + name_len = max(name_len, command.name.len + cli.spacing) } } if cmd.flags.len > 0 { @@ -109,16 +109,17 @@ fn (cmd Command) help_message() string { if flag.required { required = ' (required)' } - base_indent := ' '.repeat(base_indent_len) + base_indent := ' '.repeat(cli.base_indent_len) description_indent := ' '.repeat(name_len - flag_name.len) help += '$base_indent$flag_name$description_indent' + - pretty_description(flag.description + required, base_indent_len + name_len) + '\n' + pretty_description(flag.description + required, cli.base_indent_len + name_len) + + '\n' } } if cmd.commands.len > 0 { help += '\nCommands:\n' for command in cmd.commands { - base_indent := ' '.repeat(base_indent_len) + base_indent := ' '.repeat(cli.base_indent_len) description_indent := ' '.repeat(name_len - command.name.len) help += '$base_indent$command.name$description_indent' + pretty_description(command.description, name_len) + '\n' diff --git a/vlib/flag/flag.v b/vlib/flag/flag.v index f3f1b103d7..7ddeb269d5 100644 --- a/vlib/flag/flag.v +++ b/vlib/flag/flag.v @@ -50,7 +50,7 @@ pub const ( pub fn new_flag_parser(args []string) &FlagParser { return &FlagParser{ args: args.clone() - max_free_args: max_args_number + max_free_args: flag.max_args_number } } @@ -303,8 +303,8 @@ pub fn (mut fs FlagParser) string(name string, abbr byte, sdefault string, usage } pub fn (mut fs FlagParser) limit_free_args_to_at_least(n int) { - if n > max_args_number { - panic('flag.limit_free_args_to_at_least expect n to be smaller than $max_args_number') + if n > flag.max_args_number { + panic('flag.limit_free_args_to_at_least expect n to be smaller than $flag.max_args_number') } if n <= 0 { panic('flag.limit_free_args_to_at_least expect n to be a positive number') @@ -313,8 +313,8 @@ pub fn (mut fs FlagParser) limit_free_args_to_at_least(n int) { } pub fn (mut fs FlagParser) limit_free_args_to_exactly(n int) { - if n > max_args_number { - panic('flag.limit_free_args_to_exactly expect n to be smaller than $max_args_number') + if n > flag.max_args_number { + panic('flag.limit_free_args_to_exactly expect n to be smaller than $flag.max_args_number') } if n < 0 { panic('flag.limit_free_args_to_exactly expect n to be a non negative number') @@ -340,7 +340,7 @@ pub fn (mut fs FlagParser) arguments_description(description string) { // collect all given information and pub fn (fs FlagParser) usage() string { positive_min_arg := (fs.min_free_args > 0) - positive_max_arg := (fs.max_free_args > 0 && fs.max_free_args != max_args_number) + positive_max_arg := (fs.max_free_args > 0 && fs.max_free_args != flag.max_args_number) no_arguments := (fs.min_free_args == 0 && fs.max_free_args == 0) mut adesc := if fs.args_description.len > 0 { fs.args_description } else { '[ARGS]' } if no_arguments { @@ -349,7 +349,7 @@ pub fn (fs FlagParser) usage() string { mut use := '' if fs.application_version != '' { use += '$fs.application_name $fs.application_version\n' - use += '$underline\n' + use += '$flag.underline\n' } use += 'Usage: $fs.application_name [options] $adesc\n' use += '\n' @@ -394,10 +394,10 @@ pub fn (fs FlagParser) usage() string { } option_names := ' ' + onames.join(', ') mut xspace := '' - if option_names.len > space.len - 2 { - xspace = '\n$space' + if option_names.len > flag.space.len - 2 { + xspace = '\n$flag.space' } else { - xspace = space[option_names.len..] + xspace = flag.space[option_names.len..] } use += '$option_names$xspace$f.usage\n' } diff --git a/vlib/math/big/big.v b/vlib/math/big/big.v index 24745223c4..ccfbed1cb3 100644 --- a/vlib/math/big/big.v +++ b/vlib/math/big/big.v @@ -112,7 +112,7 @@ pub fn from_string(input string) Number { mut n := from_int(0) for _, c in input { d := from_int(int(c - `0`)) - n = (n * ten) + d + n = (n * big.ten) + d } return n } @@ -136,7 +136,7 @@ pub fn (n Number) str() string { mut x := n.clone() div := Number{} for !x.is_zero() { - mod := divmod(&x, &ten, &div) + mod := divmod(&x, &big.ten, &div) digits << byte(mod.int()) + `0` x = div } diff --git a/vlib/os/inode_test.v b/vlib/os/inode_test.v index c2b5aa781d..3dbb9be383 100644 --- a/vlib/os/inode_test.v +++ b/vlib/os/inode_test.v @@ -8,18 +8,18 @@ const ( ) fn testsuite_begin() { - eprintln('testsuite_begin, tfolder = $tfolder') - os.rmdir_all(tfolder) - assert !os.is_dir(tfolder) - os.mkdir_all(tfolder) - os.chdir(tfolder) - assert os.is_dir(tfolder) + eprintln('testsuite_begin, tfolder = $main.tfolder') + os.rmdir_all(main.tfolder) + assert !os.is_dir(main.tfolder) + os.mkdir_all(main.tfolder) + os.chdir(main.tfolder) + assert os.is_dir(main.tfolder) } fn testsuite_end() { os.chdir(os.wd_at_startup) - os.rmdir_all(tfolder) - assert !os.is_dir(tfolder) + os.rmdir_all(main.tfolder) + assert !os.is_dir(main.tfolder) } fn test_inode_file_type() { diff --git a/vlib/os/os.v b/vlib/os/os.v index 5f22717d8b..86c83baaae 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -330,11 +330,11 @@ pub fn write_file_array(path string, buffer array) ? { // It relies on path manipulation of os.args[0] and os.wd_at_startup, so it may not work properly in // all cases, but it should be better, than just using os.args[0] directly. fn executable_fallback() string { - if args.len == 0 { + if os.args.len == 0 { // we are early in the bootstrap, os.args has not been initialized yet :-| return '' } - mut exepath := args[0] + mut exepath := os.args[0] $if windows { if !exepath.contains('.exe') { exepath += '.exe' @@ -342,7 +342,7 @@ fn executable_fallback() string { } if !is_abs_path(exepath) { if exepath.contains(path_separator) { - exepath = join_path(wd_at_startup, exepath) + exepath = join_path(os.wd_at_startup, exepath) } else { // no choice but to try to walk the PATH folders :-| ... foundpath := find_abs_path_of_executable(exepath) or { '' } diff --git a/vlib/os/os_test.v b/vlib/os/os_test.v index b17f9e5ebb..5585423e73 100644 --- a/vlib/os/os_test.v +++ b/vlib/os/os_test.v @@ -12,21 +12,21 @@ const ( const args_at_start = os.args.clone() fn testsuite_begin() { - eprintln('testsuite_begin, tfolder = $tfolder') - os.rmdir_all(tfolder) - assert !os.is_dir(tfolder) - os.mkdir_all(tfolder) - os.chdir(tfolder) - assert os.is_dir(tfolder) + eprintln('testsuite_begin, tfolder = $main.tfolder') + os.rmdir_all(main.tfolder) + assert !os.is_dir(main.tfolder) + os.mkdir_all(main.tfolder) + os.chdir(main.tfolder) + assert os.is_dir(main.tfolder) // println('args_at_start: $args_at_start') - assert args_at_start.len > 0 - assert args_at_start == os.args + assert main.args_at_start.len > 0 + assert main.args_at_start == os.args } fn testsuite_end() { os.chdir(os.wd_at_startup) - os.rmdir_all(tfolder) - assert !os.is_dir(tfolder) + os.rmdir_all(main.tfolder) + assert !os.is_dir(main.tfolder) // eprintln('testsuite_end , tfolder = $tfolder removed.') } @@ -434,8 +434,8 @@ struct IntPoint { fn test_write_file_array_bytes() { fpath := './abytes.bin' - mut arr := []byte{len: maxn} - for i in 0 .. maxn { + mut arr := []byte{len: main.maxn} + for i in 0 .. main.maxn { arr[i] = 65 + byte(i) } os.write_file_array(fpath, arr) @@ -447,14 +447,14 @@ fn test_write_file_array_bytes() { fn test_write_file_array_structs() { fpath := './astructs.bin' - mut arr := []IntPoint{len: maxn} - for i in 0 .. maxn { + mut arr := []IntPoint{len: main.maxn} + for i in 0 .. main.maxn { arr[i] = IntPoint{65 + i, 65 + i + 10} } os.write_file_array(fpath, arr) rarr := os.read_file_array(fpath) assert rarr == arr - assert rarr.len == maxn + assert rarr.len == main.maxn // eprintln( rarr.str().replace('\n', ' ').replace('},', '},\n')) } diff --git a/vlib/os/os_windows.c.v b/vlib/os/os_windows.c.v index 725bbc9c6b..4804b5f055 100644 --- a/vlib/os/os_windows.c.v +++ b/vlib/os/os_windows.c.v @@ -199,11 +199,12 @@ const ( fn ptr_win_get_error_msg(code u32) voidptr { mut buf := voidptr(0) // Check for code overflow - if code > u32(max_error_code) { + if code > u32(os.max_error_code) { return buf } - C.FormatMessage(format_message_allocate_buffer | format_message_from_system | format_message_ignore_inserts, - 0, code, C.MAKELANGID(lang_neutral, sublang_default), voidptr(&buf), 0, 0) + C.FormatMessage(os.format_message_allocate_buffer | os.format_message_from_system | os.format_message_ignore_inserts, + 0, code, C.MAKELANGID(os.lang_neutral, os.sublang_default), voidptr(&buf), 0, + 0) return buf } diff --git a/vlib/semver/parse.v b/vlib/semver/parse.v index ed46859c6d..3443f59993 100644 --- a/vlib/semver/parse.v +++ b/vlib/semver/parse.v @@ -43,8 +43,9 @@ fn (ver RawVersion) is_valid() bool { if ver.raw_ints.len != 3 { return false } - return is_valid_number(ver.raw_ints[ver_major]) && is_valid_number(ver.raw_ints[ver_minor]) - && is_valid_number(ver.raw_ints[ver_patch]) && is_valid_string(ver.prerelease) + return is_valid_number(ver.raw_ints[semver.ver_major]) + && is_valid_number(ver.raw_ints[semver.ver_minor]) + && is_valid_number(ver.raw_ints[semver.ver_patch]) && is_valid_string(ver.prerelease) && is_valid_string(ver.metadata) } @@ -54,7 +55,7 @@ fn (ver RawVersion) is_missing(typ int) bool { fn (raw_ver RawVersion) coerce() ?Version { ver := raw_ver.complete() - if !is_valid_number(ver.raw_ints[ver_major]) { + if !is_valid_number(ver.raw_ints[semver.ver_major]) { return error('Invalid major version: $ver.raw_ints[ver_major]') } return ver.to_version() @@ -80,5 +81,5 @@ fn (raw_ver RawVersion) validate() ?Version { } fn (raw_ver RawVersion) to_version() Version { - return Version{raw_ver.raw_ints[ver_major].int(), raw_ver.raw_ints[ver_minor].int(), raw_ver.raw_ints[ver_patch].int(), raw_ver.prerelease, raw_ver.metadata} + return Version{raw_ver.raw_ints[semver.ver_major].int(), raw_ver.raw_ints[semver.ver_minor].int(), raw_ver.raw_ints[semver.ver_patch].int(), raw_ver.prerelease, raw_ver.metadata} } diff --git a/vlib/semver/range.v b/vlib/semver/range.v index 675b546427..eddd1b3c9e 100644 --- a/vlib/semver/range.v +++ b/vlib/semver/range.v @@ -57,7 +57,7 @@ fn (c Comparator) satisfies(ver Version) bool { } fn parse_range(input string) ?Range { - raw_comparator_sets := input.split(comparator_set_sep) + raw_comparator_sets := input.split(semver.comparator_set_sep) mut comparator_sets := []ComparatorSet{} for raw_comp_set in raw_comparator_sets { if can_expand(raw_comp_set) { @@ -72,7 +72,7 @@ fn parse_range(input string) ?Range { } fn parse_comparator_set(input string) ?ComparatorSet { - raw_comparators := input.split(comparator_sep) + raw_comparators := input.split(semver.comparator_sep) if raw_comparators.len > 2 { return error('Invalid format of comparator set for input "$input"') } @@ -113,7 +113,7 @@ fn parse_comparator(input string) ?Comparator { fn parse_xrange(input string) ?Version { mut raw_ver := parse(input).complete() for typ in versions { - if raw_ver.raw_ints[typ].index_any(x_range_symbols) == -1 { + if raw_ver.raw_ints[typ].index_any(semver.x_range_symbols) == -1 { continue } match typ { @@ -139,8 +139,8 @@ fn parse_xrange(input string) ?Version { } fn can_expand(input string) bool { - return input[0] == `~` || input[0] == `^` || input.contains(hyphen_range_sep) - || input.index_any(x_range_symbols) > -1 + return input[0] == `~` || input[0] == `^` || input.contains(semver.hyphen_range_sep) + || input.index_any(semver.x_range_symbols) > -1 } fn expand_comparator_set(input string) ?ComparatorSet { @@ -149,7 +149,7 @@ fn expand_comparator_set(input string) ?ComparatorSet { `^` { return expand_caret(input[1..]) } else {} } - if input.contains(hyphen_range_sep) { + if input.contains(semver.hyphen_range_sep) { return expand_hyphen(input) } return expand_xrange(input) @@ -178,7 +178,7 @@ fn expand_caret(raw_version string) ?ComparatorSet { } fn expand_hyphen(raw_range string) ?ComparatorSet { - raw_versions := raw_range.split(hyphen_range_sep) + raw_versions := raw_range.split(semver.hyphen_range_sep) if raw_versions.len != 2 { return none } diff --git a/vlib/semver/semver_test.v b/vlib/semver/semver_test.v index 77c8cd7f1e..d66add3dca 100644 --- a/vlib/semver/semver_test.v +++ b/vlib/semver/semver_test.v @@ -76,7 +76,7 @@ const ( ) fn test_from() { - for item in versions_to_test { + for item in main.versions_to_test { ver := semver.from(item.raw) or { assert false return @@ -87,7 +87,7 @@ fn test_from() { assert ver.metadata == item.metadata assert ver.prerelease == item.prerelease } - for ver in invalid_versions_to_test { + for ver in main.invalid_versions_to_test { semver.from(ver) or { assert true continue @@ -140,7 +140,7 @@ fn test_compare() { } fn test_satisfies() { - for item in ranges_to_test { + for item in main.ranges_to_test { ver := semver.from(item.raw_version) or { assert false return @@ -155,13 +155,13 @@ fn test_satisfies_invalid() { assert false return } - for item in invalid_ranges_to_test { + for item in main.invalid_ranges_to_test { assert ver.satisfies(item) == false } } fn test_coerce() { - for item in coerce_to_test { + for item in main.coerce_to_test { valid := semver.from(item.valid) or { assert false return @@ -183,10 +183,10 @@ fn test_coerce_invalid() { } fn test_is_valid() { - for item in versions_to_test { + for item in main.versions_to_test { assert semver.is_valid(item.raw) } - for item in invalid_versions_to_test { + for item in main.invalid_versions_to_test { assert semver.is_valid(item) == false } } diff --git a/vlib/time/misc/misc.v b/vlib/time/misc/misc.v index 122659a7cc..0ae7b94d1d 100644 --- a/vlib/time/misc/misc.v +++ b/vlib/time/misc/misc.v @@ -9,5 +9,5 @@ const ( // random returns a random time struct in *the past*. pub fn random() time.Time { - return time.unix(int(rand.u64n(start_time_unix))) + return time.unix(int(rand.u64n(misc.start_time_unix))) } diff --git a/vlib/time/time.v b/vlib/time/time.v index 6ed5dcd3d2..2711d7493b 100644 --- a/vlib/time/time.v +++ b/vlib/time/time.v @@ -13,9 +13,9 @@ const ( // but otherwise can be changed at will. absolute_zero_year = i64(-292277022399) // as i64 seconds_per_minute = 60 - seconds_per_hour = 60 * time.seconds_per_minute - seconds_per_day = 24 * time.seconds_per_hour - seconds_per_week = 7 * time.seconds_per_day + seconds_per_hour = 60 * seconds_per_minute + seconds_per_day = 24 * seconds_per_hour + seconds_per_week = 7 * seconds_per_day days_per_400_years = 365 * 400 + 97 days_per_100_years = 365 * 100 + 24 days_per_4_years = 365 * 4 + 1 @@ -392,11 +392,11 @@ pub type Duration = i64 pub const ( nanosecond = Duration(1) - microsecond = Duration(1000 * time.nanosecond) - millisecond = Duration(1000 * time.microsecond) - second = Duration(1000 * time.millisecond) - minute = Duration(60 * time.second) - hour = Duration(60 * time.minute) + microsecond = Duration(1000 * nanosecond) + millisecond = Duration(1000 * microsecond) + second = Duration(1000 * millisecond) + minute = Duration(60 * second) + hour = Duration(60 * minute) infinite = Duration(-1) ) diff --git a/vlib/time/time_darwin.c.v b/vlib/time/time_darwin.c.v index b2036075eb..7450fd61c8 100644 --- a/vlib/time/time_darwin.c.v +++ b/vlib/time/time_darwin.c.v @@ -40,10 +40,10 @@ fn init_time_base() C.mach_timebase_info_data_t { fn sys_mono_now_darwin() u64 { tm := C.mach_absolute_time() - if time_base.denom == 0 { - C.mach_timebase_info(&time_base) + if time.time_base.denom == 0 { + C.mach_timebase_info(&time.time_base) } - return (tm - start_time) * time_base.numer / time_base.denom + return (tm - time.start_time) * time.time_base.numer / time.time_base.denom } // NB: vpc_now_darwin is used by `v -profile` . @@ -51,10 +51,10 @@ fn sys_mono_now_darwin() u64 { [inline] fn vpc_now_darwin() u64 { tm := C.mach_absolute_time() - if time_base.denom == 0 { - C.mach_timebase_info(&time_base) + if time.time_base.denom == 0 { + C.mach_timebase_info(&time.time_base) } - return (tm - start_time) * time_base.numer / time_base.denom + return (tm - time.start_time) * time.time_base.numer / time.time_base.denom } // darwin_now returns a better precision current time for Darwin based operating system diff --git a/vlib/time/time_format_test.v b/vlib/time/time_format_test.v index eae8b0e6a1..175ecc3e18 100644 --- a/vlib/time/time_format_test.v +++ b/vlib/time/time_format_test.v @@ -19,70 +19,70 @@ fn test_now_format() { } fn test_format() { - assert '11.07.1980 21:23' == time_to_test.get_fmt_str(.dot, .hhmm24, .ddmmyyyy) + assert '11.07.1980 21:23' == main.time_to_test.get_fmt_str(.dot, .hhmm24, .ddmmyyyy) } fn test_hhmm() { - assert '21:23' == time_to_test.hhmm() + assert '21:23' == main.time_to_test.hhmm() } fn test_hhmm12() { - assert '9:23 p.m.' == time_to_test.hhmm12() + assert '9:23 p.m.' == main.time_to_test.hhmm12() } fn test_hhmmss() { - assert '21:23:42' == time_to_test.hhmmss() + assert '21:23:42' == main.time_to_test.hhmmss() } fn test_ymmdd() { - assert '1980-07-11' == time_to_test.ymmdd() + assert '1980-07-11' == main.time_to_test.ymmdd() } fn test_ddmmy() { - assert '11.07.1980' == time_to_test.ddmmy() + assert '11.07.1980' == main.time_to_test.ddmmy() } fn test_md() { - assert 'Jul 11' == time_to_test.md() + assert 'Jul 11' == main.time_to_test.md() } fn test_get_fmt_time_str() { - assert '21:23:42' == time_to_test.get_fmt_time_str(.hhmmss24) - assert '21:23' == time_to_test.get_fmt_time_str(.hhmm24) - assert '9:23:42 p.m.' == time_to_test.get_fmt_time_str(.hhmmss12) - assert '9:23 p.m.' == time_to_test.get_fmt_time_str(.hhmm12) + assert '21:23:42' == main.time_to_test.get_fmt_time_str(.hhmmss24) + assert '21:23' == main.time_to_test.get_fmt_time_str(.hhmm24) + assert '9:23:42 p.m.' == main.time_to_test.get_fmt_time_str(.hhmmss12) + assert '9:23 p.m.' == main.time_to_test.get_fmt_time_str(.hhmm12) } fn test_get_fmt_date_str() { - assert '11.07.1980' == time_to_test.get_fmt_date_str(.dot, .ddmmyyyy) - assert '11/07/1980' == time_to_test.get_fmt_date_str(.slash, .ddmmyyyy) - assert '11-07-1980' == time_to_test.get_fmt_date_str(.hyphen, .ddmmyyyy) - assert '11 07 1980' == time_to_test.get_fmt_date_str(.space, .ddmmyyyy) - assert '07.11.1980' == time_to_test.get_fmt_date_str(.dot, .mmddyyyy) - assert '07/11/1980' == time_to_test.get_fmt_date_str(.slash, .mmddyyyy) - assert '07-11-1980' == time_to_test.get_fmt_date_str(.hyphen, .mmddyyyy) - assert '07 11 1980' == time_to_test.get_fmt_date_str(.space, .mmddyyyy) - assert '11.07.80' == time_to_test.get_fmt_date_str(.dot, .ddmmyy) - assert '11/07/80' == time_to_test.get_fmt_date_str(.slash, .ddmmyy) - assert '11-07-80' == time_to_test.get_fmt_date_str(.hyphen, .ddmmyy) - assert '11 07 80' == time_to_test.get_fmt_date_str(.space, .ddmmyy) - assert '07.11.80' == time_to_test.get_fmt_date_str(.dot, .mmddyy) - assert '07/11/80' == time_to_test.get_fmt_date_str(.slash, .mmddyy) - assert '07-11-80' == time_to_test.get_fmt_date_str(.hyphen, .mmddyy) - assert '07 11 80' == time_to_test.get_fmt_date_str(.space, .mmddyy) - assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmd) - assert 'Jul 11' == time_to_test.get_fmt_date_str(.space, .mmmdd) - assert 'Jul 11 1980' == time_to_test.get_fmt_date_str(.space, .mmmddyyyy) - assert '1980-07-11' == time_to_test.get_fmt_date_str(.hyphen, .yyyymmdd) + assert '11.07.1980' == main.time_to_test.get_fmt_date_str(.dot, .ddmmyyyy) + assert '11/07/1980' == main.time_to_test.get_fmt_date_str(.slash, .ddmmyyyy) + assert '11-07-1980' == main.time_to_test.get_fmt_date_str(.hyphen, .ddmmyyyy) + assert '11 07 1980' == main.time_to_test.get_fmt_date_str(.space, .ddmmyyyy) + assert '07.11.1980' == main.time_to_test.get_fmt_date_str(.dot, .mmddyyyy) + assert '07/11/1980' == main.time_to_test.get_fmt_date_str(.slash, .mmddyyyy) + assert '07-11-1980' == main.time_to_test.get_fmt_date_str(.hyphen, .mmddyyyy) + assert '07 11 1980' == main.time_to_test.get_fmt_date_str(.space, .mmddyyyy) + assert '11.07.80' == main.time_to_test.get_fmt_date_str(.dot, .ddmmyy) + assert '11/07/80' == main.time_to_test.get_fmt_date_str(.slash, .ddmmyy) + assert '11-07-80' == main.time_to_test.get_fmt_date_str(.hyphen, .ddmmyy) + assert '11 07 80' == main.time_to_test.get_fmt_date_str(.space, .ddmmyy) + assert '07.11.80' == main.time_to_test.get_fmt_date_str(.dot, .mmddyy) + assert '07/11/80' == main.time_to_test.get_fmt_date_str(.slash, .mmddyy) + assert '07-11-80' == main.time_to_test.get_fmt_date_str(.hyphen, .mmddyy) + assert '07 11 80' == main.time_to_test.get_fmt_date_str(.space, .mmddyy) + assert 'Jul 11' == main.time_to_test.get_fmt_date_str(.space, .mmmd) + assert 'Jul 11' == main.time_to_test.get_fmt_date_str(.space, .mmmdd) + assert 'Jul 11 1980' == main.time_to_test.get_fmt_date_str(.space, .mmmddyyyy) + assert '1980-07-11' == main.time_to_test.get_fmt_date_str(.hyphen, .yyyymmdd) } fn test_get_fmt_str() { // Since get_fmt_time_str and get_fmt_date_str do have comprehensive // tests I don't want to exaggerate here with all possible // combinations. - assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy) + assert '11.07.1980 21:23:42' == main.time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy) } fn test_utc_string() { - assert 'Fri, 11 Jul 1980 21:23:42 UTC' == time_to_test.utc_string() + assert 'Fri, 11 Jul 1980 21:23:42 UTC' == main.time_to_test.utc_string() } diff --git a/vlib/time/time_test.v b/vlib/time/time_test.v index 19911c2e88..98d9612392 100644 --- a/vlib/time/time_test.v +++ b/vlib/time/time_test.v @@ -83,17 +83,17 @@ fn test_unix() { } fn test_format_ss() { - assert '11.07.1980 21:23:42' == time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy) + assert '11.07.1980 21:23:42' == main.time_to_test.get_fmt_str(.dot, .hhmmss24, .ddmmyyyy) } fn test_format_ss_milli() { - assert '11.07.1980 21:23:42.123' == time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy) - assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli() + assert '11.07.1980 21:23:42.123' == main.time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy) + assert '1980-07-11 21:23:42.123' == main.time_to_test.format_ss_milli() } fn test_format_ss_micro() { - assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy) - assert '1980-07-11 21:23:42.123456' == time_to_test.format_ss_micro() + assert '11.07.1980 21:23:42.123456' == main.time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy) + assert '1980-07-11 21:23:42.123456' == main.time_to_test.format_ss_micro() } fn test_smonth() { @@ -153,12 +153,12 @@ fn test_add() { d_seconds := 3 d_microseconds := 13 duration := time.Duration(d_seconds * time.second + d_microseconds * time.microsecond) - t1 := time_to_test - t2 := time_to_test.add(duration) + t1 := main.time_to_test + t2 := main.time_to_test.add(duration) assert t2.second == t1.second + d_seconds assert t2.microsecond == t1.microsecond + d_microseconds assert t2.unix == t1.unix + u64(d_seconds) - t3 := time_to_test.add(-duration) + t3 := main.time_to_test.add(-duration) assert t3.second == t1.second - d_seconds assert t3.microsecond == t1.microsecond - d_microseconds assert t3.unix == t1.unix - u64(d_seconds) @@ -166,13 +166,13 @@ fn test_add() { fn test_add_days() { num_of_days := 3 - t := time_to_test.add_days(num_of_days) - assert t.day == time_to_test.day + num_of_days - assert t.unix == time_to_test.unix + 86400 * u64(num_of_days) + t := main.time_to_test.add_days(num_of_days) + assert t.day == main.time_to_test.day + num_of_days + assert t.unix == main.time_to_test.unix + 86400 * u64(num_of_days) } fn test_str() { - assert '1980-07-11 21:23:42' == time_to_test.str() + assert '1980-07-11 21:23:42' == main.time_to_test.str() } // not optimal test but will find obvious bugs diff --git a/vlib/time/time_windows.c.v b/vlib/time/time_windows.c.v index e431f806c0..0bda65251a 100644 --- a/vlib/time/time_windows.c.v +++ b/vlib/time/time_windows.c.v @@ -75,7 +75,7 @@ fn init_win_time_start() u64 { pub fn sys_mono_now() u64 { tm := u64(0) C.QueryPerformanceCounter(&tm) // XP or later never fail - return (tm - start_time) * 1000000000 / freq_time + return (tm - time.start_time) * 1000000000 / time.freq_time } // NB: vpc_now is used by `v -profile` . diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index 882efd9a79..7c35f21e3d 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -97,7 +97,7 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) { } return } - for emsg_marker in [c_verror_message_marker, 'error: include file '] { + for emsg_marker in [builder.c_verror_message_marker, 'error: include file '] { if res.output.contains(emsg_marker) { emessage := res.output.all_after(emsg_marker).all_before('\n').all_before('\r').trim_right('\r\n') verror(emessage) @@ -121,7 +121,7 @@ fn (mut v Builder) post_process_c_compiler_output(res os.Result) { println('(Use `v -cg` to print the entire error message)\n') } } - verror(c_error_info) + verror(builder.c_error_info) } fn (mut v Builder) rebuild_cached_module(vexe string, imp_path string) string { @@ -858,7 +858,7 @@ fn (mut c Builder) cc_windows_cross() { println(os.user_os()) panic('your platform is not supported yet') } - mut cmd := '$mingw_cc $optimization_options $debug_options -std=gnu11 $args -municode' + mut cmd := '$builder.mingw_cc $optimization_options $debug_options -std=gnu11 $args -municode' // cmd := 'clang -o $obj_name -w $include -m32 -c -target x86_64-win32 ${pref.default_module_path}/$c.out_name_c' if c.pref.is_verbose || c.pref.show_cc { println(cmd) diff --git a/vlib/v/builder/msvc.v b/vlib/v/builder/msvc.v index c238182314..8a9bd0e5c1 100644 --- a/vlib/v/builder/msvc.v +++ b/vlib/v/builder/msvc.v @@ -81,7 +81,7 @@ fn find_windows_kit_root(host_arch string) ?WindowsKit { $if windows { root_key := RegKey(0) path := 'SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots' - rc := C.RegOpenKeyEx(hkey_local_machine, path.to_wide(), 0, key_query_value | key_wow64_32key | key_enumerate_sub_keys, + rc := C.RegOpenKeyEx(builder.hkey_local_machine, path.to_wide(), 0, builder.key_query_value | builder.key_wow64_32key | builder.key_enumerate_sub_keys, &root_key) // TODO: Fix defer inside ifs // defer { diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 27f37b55b7..b36815f7fc 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1284,7 +1284,7 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type { } // TODO: remove this for actual methods, use only for compiler magic // FIXME: Argument count != 1 will break these - if left_type_sym.kind == .array && method_name in array_builtin_methods { + if left_type_sym.kind == .array && method_name in checker.array_builtin_methods { mut elem_typ := table.void_type is_filter_map := method_name in ['filter', 'map'] is_sort := method_name == 'sort' @@ -2309,7 +2309,7 @@ pub fn (mut c Checker) enum_decl(decl ast.EnumDecl) { match field.expr { ast.IntegerLiteral { val := field.expr.val.i64() - if val < int_min || val > int_max { + if val < checker.int_min || val > checker.int_max { c.error('enum value `$val` overflows int', field.expr.pos) } else if !decl.is_multi_allowed && i64(val) in seen { c.error('enum value `$val` already exists', field.expr.pos) @@ -2333,7 +2333,7 @@ pub fn (mut c Checker) enum_decl(decl ast.EnumDecl) { } else { if seen.len > 0 { last := seen[seen.len - 1] - if last == int_max { + if last == checker.int_max { c.error('enum value overflows', field.pos) } seen << last + 1 @@ -2406,7 +2406,7 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) { mut is_large := right.val.len > 13 if !is_large && right.val.len > 8 { val := right.val.i64() - is_large = val > int_max || val < int_min + is_large = val > checker.int_max || val < checker.int_min } if is_large { c.error('overflow in implicit type `int`, use explicit type casting instead', @@ -4136,11 +4136,11 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym table.TypeS mut err_details := 'match must be exhaustive' if unhandled.len > 0 { err_details += ' (add match branches for: ' - if unhandled.len < match_exhaustive_cutoff_limit { + if unhandled.len < checker.match_exhaustive_cutoff_limit { err_details += unhandled.join(', ') } else { - remaining := unhandled.len - match_exhaustive_cutoff_limit - err_details += unhandled[0..match_exhaustive_cutoff_limit].join(', ') + remaining := unhandled.len - checker.match_exhaustive_cutoff_limit + err_details += unhandled[0..checker.match_exhaustive_cutoff_limit].join(', ') err_details += ', and $remaining others ...' } err_details += ' or `else {}` at the end)' @@ -4637,13 +4637,13 @@ fn (mut c Checker) comp_if_branch(cond ast.Expr, pos token.Position) bool { } } ast.Ident { - if cond.name in valid_comp_if_os { + if cond.name in checker.valid_comp_if_os { return cond.name != c.pref.os.str().to_lower() // TODO hack - } else if cond.name in valid_comp_if_compilers { + } else if cond.name in checker.valid_comp_if_compilers { return pref.cc_from_string(cond.name) != c.pref.ccompiler_type - } else if cond.name in valid_comp_if_platforms { + } else if cond.name in checker.valid_comp_if_platforms { return false // TODO - } else if cond.name in valid_comp_if_other { + } else if cond.name in checker.valid_comp_if_other { // TODO: This should probably be moved match cond.name { 'js' { return c.pref.backend != .js } diff --git a/vlib/v/doc/comment.v b/vlib/v/doc/comment.v index 91f1493d3d..37f8da00d3 100644 --- a/vlib/v/doc/comment.v +++ b/vlib/v/doc/comment.v @@ -14,10 +14,10 @@ pub mut: // is_example returns true if the contents of this comment is a doc example. // The current convention is '// Example: ' pub fn (dc DocComment) is_example() bool { - return dc.text.starts_with(example_pattern) + return dc.text.starts_with(doc.example_pattern) } // example returns the content of the example body pub fn (dc DocComment) example() string { - return dc.text.all_after(example_pattern) + return dc.text.all_after(doc.example_pattern) } diff --git a/vlib/v/fmt/fmt_keep_test.v b/vlib/v/fmt/fmt_keep_test.v index 5634da5a90..b074fc2938 100644 --- a/vlib/v/fmt/fmt_keep_test.v +++ b/vlib/v/fmt/fmt_keep_test.v @@ -21,7 +21,7 @@ fn test_fmt() { vexe := os.getenv('VEXE') if vexe.len == 0 || !os.exists(vexe) { eprintln('VEXE must be set') - exit(error_missing_vexe) + exit(main.error_missing_vexe) } vroot := os.dir(vexe) os.chdir(vroot) @@ -59,7 +59,7 @@ fn test_fmt() { if expected_ocontent != result_ocontent { fmt_bench.fail() eprintln(fmt_bench.step_message_fail('file $vrelpath after formatting, does not look as expected.')) - if ipath.ends_with(b2v_keep_path) { + if ipath.ends_with(main.b2v_keep_path) { continue } if diff_cmd == '' { @@ -79,19 +79,19 @@ fn test_fmt() { eprintln(term.h_divider('-')) eprintln(fmt_bench.total_message(fmt_message)) if fmt_bench.nfail > 0 { - exit(error_failed_tests) + exit(main.error_failed_tests) } } fn fill_bin2v_keep() ? { img0 := os.join_path('tutorials', 'img', 'hello.png') img1 := os.join_path('tutorials', 'img', 'time.png') - os.rm(b2v_keep_path) ? - os.exec('v bin2v -w $b2v_keep_path $img0 $img1') ? + os.rm(main.b2v_keep_path) ? + os.exec('v bin2v -w $main.b2v_keep_path $img0 $img1') ? } fn restore_bin2v_placeholder() ? { text := '// This is a placeholder file which will be filled with bin2v output before the test. // HINT: do NOT delete, move or rename this file!\n' - os.write_file(b2v_keep_path, text) ? + os.write_file(main.b2v_keep_path, text) ? } diff --git a/vlib/v/fmt/fmt_test.v b/vlib/v/fmt/fmt_test.v index 8cd48e7bdc..474f282685 100644 --- a/vlib/v/fmt/fmt_test.v +++ b/vlib/v/fmt/fmt_test.v @@ -19,7 +19,7 @@ fn test_fmt() { vexe := os.getenv('VEXE') if vexe.len == 0 || !os.exists(vexe) { eprintln('VEXE must be set') - exit(error_missing_vexe) + exit(main.error_missing_vexe) } vroot := os.dir(vexe) tmpfolder := os.temp_dir() @@ -69,6 +69,6 @@ fn test_fmt() { eprintln(term.h_divider('-')) eprintln(fmt_bench.total_message(fmt_message)) if fmt_bench.nfail > 0 { - exit(error_failed_tests) + exit(main.error_failed_tests) } } diff --git a/vlib/v/fmt/fmt_vlib_test.v b/vlib/v/fmt/fmt_vlib_test.v index 252053511a..51f89dbe59 100644 --- a/vlib/v/fmt/fmt_vlib_test.v +++ b/vlib/v/fmt/fmt_vlib_test.v @@ -22,7 +22,7 @@ fn test_vlib_fmt() { vexe := os.getenv('VEXE') if vexe.len == 0 || !os.exists(vexe) { eprintln('VEXE must be set') - exit(error_missing_vexe) + exit(main.error_missing_vexe) } vroot := os.dir(vexe) tmpfolder := os.temp_dir() @@ -67,6 +67,6 @@ fn test_vlib_fmt() { eprintln(term.h_divider('-')) eprintln(fmt_bench.total_message(fmt_message)) if fmt_bench.nfail > 0 { - exit(error_failed_tests) + exit(main.error_failed_tests) } } diff --git a/vlib/v/gen/cgen_test.v b/vlib/v/gen/cgen_test.v index 179a5f20ba..18d94801c6 100644 --- a/vlib/v/gen/cgen_test.v +++ b/vlib/v/gen/cgen_test.v @@ -16,7 +16,7 @@ fn test_c_files() { println('Running V => C tests') vexe := os.getenv('VEXE') vroot := os.dir(vexe) - for i in 1 .. (nr_tests + 1) { + for i in 1 .. (main.nr_tests + 1) { path := '$vroot/vlib/v/gen/tests/${i}.vv' ctext := os.read_file('$vroot/vlib/v/gen/tests/${i}.c') or { panic(err) } mut b := builder.new_builder(pref.Preferences{}) @@ -28,7 +28,7 @@ fn test_c_files() { res = res[..pos] + res[end + 15..] } if compare_texts(res, ctext, path) { - println('$term_ok $i') + println('$main.term_ok $i') } else { assert false } @@ -57,7 +57,7 @@ fn compare_texts(a string, b string, path string) bool { line_b := lines_b[i] if line_a.trim_space() != line_b.trim_space() { println('$path: Got\n$a') - println('$path:$i: $term_fail') + println('$path:$i: $main.term_fail') println(term.bold(term.bright_yellow('actual : ')) + line_a) println(term.green('expected: ') + line_b) println(lines_b[i + 1]) diff --git a/vlib/v/gen/live.v b/vlib/v/gen/live.v index fe11067bec..e96c69592b 100644 --- a/vlib/v/gen/live.v +++ b/vlib/v/gen/live.v @@ -42,12 +42,12 @@ fn (mut g Gen) generate_hotcode_reloader_code() { for so_fn in g.hotcode_fn_names { load_code << 'impl_live_$so_fn = dlsym(live_lib, "impl_live_$so_fn");' } - phd = posix_hotcode_definitions_1 + phd = gen.posix_hotcode_definitions_1 } else { for so_fn in g.hotcode_fn_names { load_code << 'impl_live_$so_fn = (void *)GetProcAddress(live_lib, "impl_live_$so_fn"); ' } - phd = windows_hotcode_definitions_1 + phd = gen.windows_hotcode_definitions_1 } g.hotcode_definitions.writeln(phd.replace('@LOAD_FNS@', load_code.join('\n'))) } diff --git a/vlib/v/gen/sql.v b/vlib/v/gen/sql.v index 0eba2568da..26f86ed922 100644 --- a/vlib/v/gen/sql.v +++ b/vlib/v/gen/sql.v @@ -22,10 +22,10 @@ fn (mut g Gen) sql_stmt(node ast.SqlStmt) { g.writeln('\n\t// sql insert') db_name := g.new_tmp_var() g.sql_stmt_name = g.new_tmp_var() - g.write('${dbtype}__DB $db_name = ') + g.write('${gen.dbtype}__DB $db_name = ') g.expr(node.db_expr) g.writeln(';') - g.write('sqlite3_stmt* $g.sql_stmt_name = ${dbtype}__DB_init_stmt($db_name, _SLIT("') + g.write('sqlite3_stmt* $g.sql_stmt_name = ${gen.dbtype}__DB_init_stmt($db_name, _SLIT("') table_name := util.strip_mod_name(g.table.get_type_symbol(node.table_expr.typ).name) if node.kind == .insert { g.write('INSERT INTO `$table_name` (') @@ -131,11 +131,11 @@ fn (mut g Gen) sql_select_expr(node ast.SqlExpr) { db_name := g.new_tmp_var() g.writeln('\n\t// sql select') // g.write('${dbtype}__DB $db_name = *(${dbtype}__DB*)${node.db_var_name}.data;') - g.write('${dbtype}__DB $db_name = ') // $node.db_var_name;') + g.write('${gen.dbtype}__DB $db_name = ') // $node.db_var_name;') g.expr(node.db_expr) g.writeln(';') // g.write('sqlite3_stmt* $g.sql_stmt_name = ${dbtype}__DB_init_stmt(*(${dbtype}__DB*)${node.db_var_name}.data, _SLIT("$sql_query') - g.write('sqlite3_stmt* $g.sql_stmt_name = ${dbtype}__DB_init_stmt($db_name, _SLIT("') + g.write('sqlite3_stmt* $g.sql_stmt_name = ${gen.dbtype}__DB_init_stmt($db_name, _SLIT("') g.write(sql_query) if node.has_where && node.where_expr is ast.InfixExpr { g.expr_to_sql(node.where_expr) @@ -170,7 +170,7 @@ fn (mut g Gen) sql_select_expr(node ast.SqlExpr) { g.writeln('if ($binding_res != SQLITE_OK) { puts(sqlite3_errmsg(${db_name}.conn)); }') // if node.is_count { - g.writeln('$cur_line ${dbtype}__get_int_from_stmt($g.sql_stmt_name);') + g.writeln('$cur_line ${gen.dbtype}__get_int_from_stmt($g.sql_stmt_name);') } else { // `user := sql db { select from User where id = 1 }` tmp := g.new_tmp_var() diff --git a/vlib/v/gen/x64/elf.v b/vlib/v/gen/x64/elf.v index c1cc34c366..1e4e3673c8 100644 --- a/vlib/v/gen/x64/elf.v +++ b/vlib/v/gen/x64/elf.v @@ -34,18 +34,18 @@ const ( ) pub fn (mut g Gen) generate_elf_header() { - g.buf << [byte(mag0), mag1, mag2, mag3] - g.buf << elfclass64 // file class - g.buf << elfdata2lsb // data encoding - g.buf << ev_current // file version + g.buf << [byte(x64.mag0), x64.mag1, x64.mag2, x64.mag3] + g.buf << x64.elfclass64 // file class + g.buf << x64.elfdata2lsb // data encoding + g.buf << x64.ev_current // file version g.buf << 1 // elf_osabi g.write64(0) // et_rel) // et_rel for .o g.write16(2) // e_type - g.write16(e_machine) // - g.write32(ev_current) // e_version + g.write16(x64.e_machine) // + g.write32(x64.ev_current) // e_version eh_size := 0x40 phent_size := 0x38 - g.write64(segment_start + eh_size + phent_size) // e_entry + g.write64(x64.segment_start + eh_size + phent_size) // e_entry g.write64(0x40) // e_phoff g.write64(0) // e_shoff g.write32(0) // e_flags @@ -59,8 +59,8 @@ pub fn (mut g Gen) generate_elf_header() { g.write32(1) // p_type g.write32(5) // p_flags g.write64(0) // p_offset - g.write64(segment_start) // p_vaddr addr:050 - g.write64(segment_start) // + g.write64(x64.segment_start) // p_vaddr addr:050 + g.write64(x64.segment_start) // g.file_size_pos = i64(g.buf.len) g.write64(0) // p_filesz PLACEHOLDER, set to file_size later // addr: 060 g.write64(0) // p_memsz @@ -70,7 +70,7 @@ pub fn (mut g Gen) generate_elf_header() { println('code_start_pos = $g.buf.len.hex()') g.code_start_pos = i64(g.buf.len) g.debug_pos = g.buf.len - g.call(placeholder) // call main function, it's not guaranteed to be the first, we don't know its address yet + g.call(x64.placeholder) // call main function, it's not guaranteed to be the first, we don't know its address yet g.println('call fn main') } @@ -84,7 +84,7 @@ pub fn (mut g Gen) generate_elf_footer() { // Strings table // Loop thru all strings and set the right addresses for i, s in g.strings { - g.write64_at(segment_start + g.buf.len, int(g.str_pos[i])) + g.write64_at(x64.segment_start + g.buf.len, int(g.str_pos[i])) g.write_string(s) g.write8(0) } diff --git a/vlib/v/gen/x64/gen.v b/vlib/v/gen/x64/gen.v index 0b4c80d25b..60cc525d95 100644 --- a/vlib/v/gen/x64/gen.v +++ b/vlib/v/gen/x64/gen.v @@ -610,16 +610,16 @@ pub fn (mut g Gen) call_fn(node ast.CallExpr) { match expr { ast.IntegerLiteral { // `foo(2)` => `mov edi,0x2` - g.mov(fn_arg_registers[i], expr.val.int()) + g.mov(x64.fn_arg_registers[i], expr.val.int()) } ast.Ident { // `foo(x)` => `mov edi,DWORD PTR [rbp-0x8]` var_offset := g.get_var_offset(expr.name) if g.pref.is_verbose { println('i=$i fn name= $name offset=$var_offset') - println(int(fn_arg_registers[i])) + println(int(x64.fn_arg_registers[i])) } - g.mov_var_to_reg(fn_arg_registers[i], var_offset) + g.mov_var_to_reg(x64.fn_arg_registers[i], var_offset) } else { verror('unhandled call_fn (name=$name) node: ' + expr.type_name()) @@ -877,7 +877,7 @@ fn (mut g Gen) fn_decl(node ast.FnDecl) { g.allocate_var(name, 4, 0) // `mov DWORD PTR [rbp-0x4],edi` offset += 4 - g.mov_reg_to_rbp(offset, fn_arg_registers[i]) + g.mov_reg_to_rbp(offset, x64.fn_arg_registers[i]) } // g.stmts(node.stmts) diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 86557f8d61..98908e7c74 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -54,7 +54,7 @@ fn (mut p Parser) comp_call() ast.ComptimeCall { p.check(.dot) } n := p.check_name() // (.name) - if n !in supported_comptime_calls { + if n !in parser.supported_comptime_calls { p.error(error_msg) return ast.ComptimeCall{} } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 58e037f482..97abf1846d 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -2048,7 +2048,7 @@ const ( fn (mut p Parser) global_decl() ast.GlobalDecl { if !p.pref.translated && !p.pref.is_livemain && !p.builtin_mod && !p.pref.building_v && p.mod != 'ui' && p.mod != 'gg2' && p.mod != 'uiold' && !p.pref.enable_globals - && !p.pref.is_fmt&& p.mod !in global_enabled_mods { + && !p.pref.is_fmt&& p.mod !in parser.global_enabled_mods { p.error('use `v --enable-globals ...` to enable globals') return ast.GlobalDecl{} } diff --git a/vlib/v/parser/v_parser_test.v b/vlib/v/parser/v_parser_test.v index e2844a64aa..40d0dde3ea 100644 --- a/vlib/v/parser/v_parser_test.v +++ b/vlib/v/parser/v_parser_test.v @@ -178,9 +178,9 @@ fn test_parse_expr() { fn test_num_literals() { inputs := [ 'a := -1', - 'b := -12.e17' - 'c := -12.' - 'd := -a' + 'b := -12.e17', + 'c := -12.', + 'd := -a', ] table := table.new_table() mut scope := &ast.Scope{ @@ -189,21 +189,13 @@ fn test_num_literals() { } mut rhs_types := []string{} for input in inputs { - stmt := parser.parse_stmt(input, table, scope) + stmt := parse_stmt(input, table, scope) r := (stmt as ast.AssignStmt).right match r[0] { - ast.IntegerLiteral { - rhs_types << 'int literal' - } - ast.FloatLiteral { - rhs_types << 'float literal' - } - ast.PrefixExpr { - rhs_types << 'prefix expression' - } - else { - rhs_types << 'something else' - } + ast.IntegerLiteral { rhs_types << 'int literal' } + ast.FloatLiteral { rhs_types << 'float literal' } + ast.PrefixExpr { rhs_types << 'prefix expression' } + else { rhs_types << 'something else' } } } mut rhs_type := rhs_types[0] @@ -216,7 +208,6 @@ fn test_num_literals() { assert rhs_type == 'prefix expression' } - /* table := &table.Table{} for s in text_expr { diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 74d01ff9bf..80807d8324 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -393,7 +393,7 @@ pub fn parse_args(args []string) (&Preferences, string) { exit(1) } if arg[0] == `-` { - if arg[1..] in list_of_flags_with_param { + if arg[1..] in pref.list_of_flags_with_param { // skip parameter i++ continue diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 8177635db1..7fe94c21d8 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -196,7 +196,7 @@ fn (s Scanner) num_lit(start int, end int) string { mut b := malloc(end - start + 1) // add a byte for the endstring 0 mut i1 := 0 for i := start; i < end; i++ { - if txt[i] != num_sep { + if txt[i] != scanner.num_sep { b[i1] = txt[i] i1++ } @@ -212,15 +212,15 @@ fn (mut s Scanner) ident_bin_number() string { mut first_wrong_digit := `\0` start_pos := s.pos s.pos += 2 // skip '0b' - if s.pos < s.text.len && s.text[s.pos] == num_sep { + if s.pos < s.text.len && s.text[s.pos] == scanner.num_sep { s.error('separator `_` is only valid between digits in a numeric literal') } for s.pos < s.text.len { c := s.text[s.pos] - if c == num_sep && s.text[s.pos - 1] == num_sep { + if c == scanner.num_sep && s.text[s.pos - 1] == scanner.num_sep { s.error('cannot use `_` consecutively') } - if !c.is_bin_digit() && c != num_sep { + if !c.is_bin_digit() && c != scanner.num_sep { if (!c.is_digit() && !c.is_letter()) || s.is_inside_string { break } else if !has_wrong_digit { @@ -231,7 +231,7 @@ fn (mut s Scanner) ident_bin_number() string { } s.pos++ } - if s.text[s.pos - 1] == num_sep { + if s.text[s.pos - 1] == scanner.num_sep { s.pos-- s.error('cannot use `_` at the end of a numeric literal') } else if start_pos + 2 == s.pos { @@ -255,15 +255,15 @@ fn (mut s Scanner) ident_hex_number() string { return '0x' } s.pos += 2 // skip '0x' - if s.pos < s.text.len && s.text[s.pos] == num_sep { + if s.pos < s.text.len && s.text[s.pos] == scanner.num_sep { s.error('separator `_` is only valid between digits in a numeric literal') } for s.pos < s.text.len { c := s.text[s.pos] - if c == num_sep && s.text[s.pos - 1] == num_sep { + if c == scanner.num_sep && s.text[s.pos - 1] == scanner.num_sep { s.error('cannot use `_` consecutively') } - if !c.is_hex_digit() && c != num_sep { + if !c.is_hex_digit() && c != scanner.num_sep { if !c.is_letter() || s.is_inside_string { break } else if !has_wrong_digit { @@ -274,7 +274,7 @@ fn (mut s Scanner) ident_hex_number() string { } s.pos++ } - if s.text[s.pos - 1] == num_sep { + if s.text[s.pos - 1] == scanner.num_sep { s.pos-- s.error('cannot use `_` at the end of a numeric literal') } else if start_pos + 2 == s.pos { @@ -295,15 +295,15 @@ fn (mut s Scanner) ident_oct_number() string { mut first_wrong_digit := `\0` start_pos := s.pos s.pos += 2 // skip '0o' - if s.pos < s.text.len && s.text[s.pos] == num_sep { + if s.pos < s.text.len && s.text[s.pos] == scanner.num_sep { s.error('separator `_` is only valid between digits in a numeric literal') } for s.pos < s.text.len { c := s.text[s.pos] - if c == num_sep && s.text[s.pos - 1] == num_sep { + if c == scanner.num_sep && s.text[s.pos - 1] == scanner.num_sep { s.error('cannot use `_` consecutively') } - if !c.is_oct_digit() && c != num_sep { + if !c.is_oct_digit() && c != scanner.num_sep { if (!c.is_digit() && !c.is_letter()) || s.is_inside_string { break } else if !has_wrong_digit { @@ -314,7 +314,7 @@ fn (mut s Scanner) ident_oct_number() string { } s.pos++ } - if s.text[s.pos - 1] == num_sep { + if s.text[s.pos - 1] == scanner.num_sep { s.pos-- s.error('cannot use `_` at the end of a numeric literal') } else if start_pos + 2 == s.pos { @@ -337,10 +337,10 @@ fn (mut s Scanner) ident_dec_number() string { // scan integer part for s.pos < s.text.len { c := s.text[s.pos] - if c == num_sep && s.text[s.pos - 1] == num_sep { + if c == scanner.num_sep && s.text[s.pos - 1] == scanner.num_sep { s.error('cannot use `_` consecutively') } - if !c.is_digit() && c != num_sep { + if !c.is_digit() && c != scanner.num_sep { if !c.is_letter() || c in [`e`, `E`] || s.is_inside_string { break } else if !has_wrong_digit { @@ -351,7 +351,7 @@ fn (mut s Scanner) ident_dec_number() string { } s.pos++ } - if s.text[s.pos - 1] == num_sep { + if s.text[s.pos - 1] == scanner.num_sep { s.pos-- s.error('cannot use `_` at the end of a numeric literal') } @@ -698,7 +698,7 @@ fn (mut s Scanner) text_scan() token.Token { `?` { return s.new_token(.question, '', 1) } - single_quote, double_quote { + scanner.single_quote, scanner.double_quote { ident_string := s.ident_string() return s.new_token(.string, ident_string, ident_string.len + 2) // + two quotes } @@ -1021,7 +1021,7 @@ fn (s &Scanner) count_symbol_before(p int, sym byte) int { fn (mut s Scanner) ident_string() string { q := s.text[s.pos] - is_quote := q == single_quote || q == double_quote + is_quote := q == scanner.single_quote || q == scanner.double_quote is_raw := is_quote && s.pos > 0 && s.text[s.pos - 1] == `r` is_cstr := is_quote && s.pos > 0 && s.text[s.pos - 1] == `c` if is_quote { diff --git a/vlib/v/table/cflags.v b/vlib/v/table/cflags.v index 282efe0a04..1f0535f468 100644 --- a/vlib/v/table/cflags.v +++ b/vlib/v/table/cflags.v @@ -6,8 +6,8 @@ module table import v.cflag // check if cflag is in table -fn (table &Table) has_cflag(flag cflag.CFlag) bool { - for cf in table.cflags { +fn (mytable &Table) has_cflag(flag cflag.CFlag) bool { + for cf in mytable.cflags { if cf.os == flag.os && cf.name == flag.name && cf.value == flag.value { return true } @@ -17,7 +17,7 @@ fn (table &Table) has_cflag(flag cflag.CFlag) bool { // parse the flags to (table.cflags) []CFlag // Note: clean up big time (joe-c) -pub fn (mut table Table) parse_cflag(cflg string, mod string, ctimedefines []string) ?bool { +pub fn (mut mytable Table) parse_cflag(cflg string, mod string, ctimedefines []string) ?bool { allowed_flags := ['framework', 'library', 'Wa', 'Wl', 'Wp', 'I', 'l', 'L'] flag_orig := cflg.trim_space() mut flag := flag_orig @@ -78,8 +78,8 @@ pub fn (mut table Table) parse_cflag(cflg string, mod string, ctimedefines []str name: name value: value } - if !table.has_cflag(cf) { - table.cflags << cf + if !mytable.has_cflag(cf) { + mytable.cflags << cf } if index == -1 { break diff --git a/vlib/v/table/cflags_test.v b/vlib/v/table/cflags_test.v index 8c7b1ed8ba..16ed78a8a0 100644 --- a/vlib/v/table/cflags_test.v +++ b/vlib/v/table/cflags_test.v @@ -14,12 +14,12 @@ fn test_parse_valid_cflags() { expected_flags := [ make_flag('freebsd', '-I', '/usr/local/include/freetype2'), make_flag('linux', '-l', 'glfw'), - make_flag('mingw', no_name, '-mwindows'), + make_flag('mingw', main.no_name, '-mwindows'), make_flag('solaris', '-L', '/opt/local/lib'), make_flag('darwin', '-framework', 'Cocoa'), make_flag('windows', '-l', 'gdi32'), - make_flag(no_os, '-l', 'mysqlclient'), - make_flag(no_os, no_name, '-test'), + make_flag(main.no_os, '-l', 'mysqlclient'), + make_flag(main.no_os, main.no_name, '-test'), ] parse_valid_flag(mut t, '-lmysqlclient') parse_valid_flag(mut t, '-test') @@ -49,22 +49,22 @@ fn test_parse_invalid_cflags() { assert_parse_invalid_flag(mut t, 'solaris') assert_parse_invalid_flag(mut t, 'windows') // Empty flag is not allowed - assert_parse_invalid_flag(mut t, no_flag) + assert_parse_invalid_flag(mut t, main.no_flag) assert t.cflags.len == 0 } fn parse_valid_flag(mut t table.Table, flag string) { - t.parse_cflag(flag, module_name, cdefines) or { } + t.parse_cflag(flag, main.module_name, main.cdefines) or { } } fn assert_parse_invalid_flag(mut t table.Table, flag string) { - t.parse_cflag(flag, module_name, cdefines) or { return } + t.parse_cflag(flag, main.module_name, main.cdefines) or { return } assert false } fn make_flag(os string, name string, value string) cflag.CFlag { return cflag.CFlag{ - mod: module_name + mod: main.module_name os: os name: name value: value diff --git a/vlib/v/table/table.v b/vlib/v/table/table.v index 9022c71348..fe3b40d7e3 100644 --- a/vlib/v/table/table.v +++ b/vlib/v/table/table.v @@ -728,19 +728,19 @@ pub fn (t &Table) mktyp(typ Type) Type { } } -pub fn (mut table Table) register_fn_gen_type(fn_name string, types []Type) { - mut a := table.fn_gen_types[fn_name] +pub fn (mut mytable Table) register_fn_gen_type(fn_name string, types []Type) { + mut a := mytable.fn_gen_types[fn_name] if types in a { return } a << types - table.fn_gen_types[fn_name] = a + mytable.fn_gen_types[fn_name] = a } // TODO: there is a bug when casting sumtype the other way if its pointer // so until fixed at least show v (not C) error `x(variant) = y(SumType*)` -pub fn (table &Table) sumtype_has_variant(parent Type, variant Type) bool { - parent_sym := table.get_type_symbol(parent) +pub fn (mytable &Table) sumtype_has_variant(parent Type, variant Type) bool { + parent_sym := mytable.get_type_symbol(parent) if parent_sym.kind == .sum_type { parent_info := parent_sym.info as SumType for v in parent_info.variants { @@ -752,14 +752,14 @@ pub fn (table &Table) sumtype_has_variant(parent Type, variant Type) bool { return false } -pub fn (table &Table) known_type_names() []string { +pub fn (mytable &Table) known_type_names() []string { mut res := []string{} - for _, idx in table.type_idxs { + for _, idx in mytable.type_idxs { // Skip `int_literal_type_idx` and `float_literal_type_idx` because they shouldn't be visible to the User. if idx in [0, int_literal_type_idx, float_literal_type_idx] { continue } - res << table.type_to_str(idx) + res << mytable.type_to_str(idx) } return res } @@ -767,11 +767,11 @@ pub fn (table &Table) known_type_names() []string { // has_deep_child_no_ref returns true if type is struct and has any child or nested child with the type of the given name // the given name consists of module and name (`mod.Name`) // it doesn't care about childs that are references -pub fn (table &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool { +pub fn (mytable &Table) has_deep_child_no_ref(ts &TypeSymbol, name string) bool { if ts.info is Struct { for _, field in ts.info.fields { - sym := table.get_type_symbol(field.typ) - if !field.typ.is_ptr() && (sym.name == name || table.has_deep_child_no_ref(sym, name)) { + sym := mytable.get_type_symbol(field.typ) + if !field.typ.is_ptr() && (sym.name == name || mytable.has_deep_child_no_ref(sym, name)) { return true } } diff --git a/vlib/v/table/types.v b/vlib/v/table/types.v index d155a4f771..8ed20e561f 100644 --- a/vlib/v/table/types.v +++ b/vlib/v/table/types.v @@ -76,10 +76,10 @@ pub fn (t ShareType) str() string { pub fn (t Type) atomic_typename() string { idx := t.idx() match idx { - u32_type_idx { return 'atomic_uint' } - int_type_idx { return 'atomic_int' } - u64_type_idx { return 'atomic_ullong' } - i64_type_idx { return 'atomic_llong' } + table.u32_type_idx { return 'atomic_uint' } + table.int_type_idx { return 'atomic_int' } + table.u64_type_idx { return 'atomic_ullong' } + table.i64_type_idx { return 'atomic_llong' } else { return 'unknown_atomic' } } } @@ -100,12 +100,12 @@ pub fn (t Type) idx() int { [inline] pub fn (t Type) is_void() bool { - return t == void_type + return t == table.void_type } [inline] pub fn (t Type) is_full() bool { - return t != 0 && t != void_type + return t != 0 && t != table.void_type } // return nr_muls for `t` @@ -240,42 +240,42 @@ pub fn new_type_ptr(idx int, nr_muls int) Type { // built in pointers (voidptr, byteptr, charptr) [inline] pub fn (typ Type) is_pointer() bool { - return typ.idx() in pointer_type_idxs + return typ.idx() in table.pointer_type_idxs } [inline] pub fn (typ Type) is_float() bool { - return typ.idx() in float_type_idxs + return typ.idx() in table.float_type_idxs } [inline] pub fn (typ Type) is_int() bool { - return typ.idx() in integer_type_idxs + return typ.idx() in table.integer_type_idxs } [inline] pub fn (typ Type) is_signed() bool { - return typ.idx() in signed_integer_type_idxs + return typ.idx() in table.signed_integer_type_idxs } [inline] pub fn (typ Type) is_unsigned() bool { - return typ.idx() in unsigned_integer_type_idxs + return typ.idx() in table.unsigned_integer_type_idxs } [inline] pub fn (typ Type) is_int_literal() bool { - return typ.idx() == int_literal_type_idx + return typ.idx() == table.int_literal_type_idx } [inline] pub fn (typ Type) is_number() bool { - return typ.idx() in number_type_idxs + return typ.idx() in table.number_type_idxs } [inline] pub fn (typ Type) is_string() bool { - return typ.idx() in string_type_idxs + return typ.idx() in table.string_type_idxs } pub const ( @@ -745,16 +745,16 @@ pub fn (table &Table) type_to_str(t Type) string { } // type name in code (for builtin) -pub fn (table &Table) type_to_code(t Type) string { +pub fn (mytable &Table) type_to_code(t Type) string { match t { - int_literal_type, float_literal_type { return table.get_type_symbol(t).kind.str() } - else { return table.type_to_str_using_aliases(t, map[string]string{}) } + table.int_literal_type, table.float_literal_type { return mytable.get_type_symbol(t).kind.str() } + else { return mytable.type_to_str_using_aliases(t, map[string]string{}) } } } // import_aliases is a map of imported symbol aliases 'module.Type' => 'Type' -pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[string]string) string { - sym := table.get_type_symbol(t) +pub fn (mytable &Table) type_to_str_using_aliases(t Type, import_aliases map[string]string) string { + sym := mytable.get_type_symbol(t) mut res := sym.name match sym.kind { .int_literal, .float_literal { @@ -766,20 +766,20 @@ pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[strin res = sym.kind.str() } .array { - if t == array_type { + if t == table.array_type { return 'array' } if t.has_flag(.variadic) { - res = table.type_to_str_using_aliases(table.value_type(t), import_aliases) + res = mytable.type_to_str_using_aliases(mytable.value_type(t), import_aliases) } else { info := sym.info as Array - elem_str := table.type_to_str_using_aliases(info.elem_type, import_aliases) + elem_str := mytable.type_to_str_using_aliases(info.elem_type, import_aliases) res = '[]$elem_str' } } .array_fixed { info := sym.info as ArrayFixed - elem_str := table.type_to_str_using_aliases(info.elem_type, import_aliases) + elem_str := mytable.type_to_str_using_aliases(info.elem_type, import_aliases) res = '[$info.size]$elem_str' } .chan { @@ -792,31 +792,31 @@ pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[strin mut_str = 'mut ' elem_type = elem_type.set_nr_muls(elem_type.nr_muls() - 1) } - elem_str := table.type_to_str_using_aliases(elem_type, import_aliases) + elem_str := mytable.type_to_str_using_aliases(elem_type, import_aliases) res = 'chan $mut_str$elem_str' } } .function { info := sym.info as FnType - if !table.is_fmt { - res = table.fn_signature(info.func, type_only: true) + if !mytable.is_fmt { + res = mytable.fn_signature(info.func, type_only: true) } else { if res.starts_with('fn (') { // fn foo () - res = table.fn_signature(info.func, type_only: true) + res = mytable.fn_signature(info.func, type_only: true) } else { // FnFoo - res = table.shorten_user_defined_typenames(res, import_aliases) + res = mytable.shorten_user_defined_typenames(res, import_aliases) } } } .map { - if int(t) == map_type_idx { + if int(t) == table.map_type_idx { return 'map' } info := sym.info as Map - key_str := table.type_to_str_using_aliases(info.key_type, import_aliases) - val_str := table.type_to_str_using_aliases(info.value_type, import_aliases) + key_str := mytable.type_to_str_using_aliases(info.key_type, import_aliases) + val_str := mytable.type_to_str_using_aliases(info.value_type, import_aliases) res = 'map[$key_str]$val_str' } .multi_return { @@ -826,7 +826,7 @@ pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[strin if i > 0 { res += ', ' } - res += table.type_to_str_using_aliases(typ, import_aliases) + res += mytable.type_to_str_using_aliases(typ, import_aliases) } res += ')' } @@ -837,7 +837,7 @@ pub fn (table &Table) type_to_str_using_aliases(t Type, import_aliases map[strin return 'void' } else { - res = table.shorten_user_defined_typenames(res, import_aliases) + res = mytable.shorten_user_defined_typenames(res, import_aliases) } } nr_muls := t.nr_muls() @@ -899,7 +899,7 @@ pub fn (t &Table) fn_signature(func &Fn, opts FnSignatureOpts) string { sb.write('$styp') } sb.write(')') - if func.return_type != void_type { + if func.return_type != table.void_type { sb.write(' ${t.type_to_str(func.return_type)}') } return sb.str() diff --git a/vlib/v/util/errors.v b/vlib/v/util/errors.v index a77dae6a9b..3b6df3e8f5 100644 --- a/vlib/v/util/errors.v +++ b/vlib/v/util/errors.v @@ -47,14 +47,14 @@ pub fn (e &EManager) set_support_color(b bool) { } pub fn bold(msg string) string { - if !emanager.support_color { + if !util.emanager.support_color { return msg } return term.bold(msg) } fn color(kind string, msg string) string { - if !emanager.support_color { + if !util.emanager.support_color { return msg } if kind.contains('error') { @@ -112,8 +112,8 @@ pub fn source_context(kind string, source string, column int, pos token.Position return clines } source_lines := source.split_into_lines() - bline := imax(0, pos.line_nr - error_context_before) - aline := imax(0, imin(source_lines.len - 1, pos.line_nr + error_context_after)) + bline := imax(0, pos.line_nr - util.error_context_before) + aline := imax(0, imin(source_lines.len - 1, pos.line_nr + util.error_context_after)) tab_spaces := ' ' for iline := bline; iline <= aline; iline++ { sline := source_lines[iline] diff --git a/vlib/v/util/quote.v b/vlib/v/util/quote.v index ec69bc9e56..c0f54cc543 100644 --- a/vlib/v/util/quote.v +++ b/vlib/v/util/quote.v @@ -58,7 +58,7 @@ pub fn smart_quote(str string, raw bool) string { skip_next = true } // keep all valid escape sequences - else if next !in invalid_escapes { + else if next !in util.invalid_escapes { toadd = '\\' + next skip_next = true } else { diff --git a/vlib/v/util/util.v b/vlib/v/util/util.v index 723b1b9034..99f191c2de 100644 --- a/vlib/v/util/util.v +++ b/vlib/v/util/util.v @@ -45,10 +45,10 @@ pub fn full_hash() string { // full_v_version() returns the full version of the V compiler pub fn full_v_version(is_verbose bool) string { if is_verbose { - return 'V $v_version $full_hash()' + return 'V $util.v_version $full_hash()' } hash := githash(false) - return 'V $v_version $hash' + return 'V $util.v_version $hash' } // githash(x) returns the current git commit hash. @@ -163,7 +163,7 @@ pub fn launch_tool(is_verbose bool, tool_name string, args []string) { println('launch_tool should_compile: $should_compile') } if should_compile { - emodules := external_module_dependencies_for_tool[tool_name] + emodules := util.external_module_dependencies_for_tool[tool_name] for emodule in emodules { check_module_is_installed(emodule, is_verbose) or { panic(err) } } @@ -411,7 +411,7 @@ and the existing module `$modulename` may still work.') } pub fn ensure_modules_for_all_tools_are_installed(is_verbose bool) { - for tool_name, tool_modules in external_module_dependencies_for_tool { + for tool_name, tool_modules in util.external_module_dependencies_for_tool { if is_verbose { eprintln('Installing modules for tool: $tool_name ...') } @@ -444,9 +444,9 @@ const ( pub fn no_cur_mod(typename string, cur_mod string) string { mut res := typename mod_prefix := cur_mod + '.' - has_map_prefix := res.starts_with(map_prefix) + has_map_prefix := res.starts_with(util.map_prefix) if has_map_prefix { - res = res.replace_once(map_prefix, '') + res = res.replace_once(util.map_prefix, '') } no_symbols := res.trim_left('&[]') should_shorten := no_symbols.starts_with(mod_prefix) @@ -454,7 +454,7 @@ pub fn no_cur_mod(typename string, cur_mod string) string { res = res.replace_once(mod_prefix, '') } if has_map_prefix { - res = map_prefix + res + res = util.map_prefix + res } return res } @@ -496,5 +496,6 @@ pub fn get_vtmp_folder() string { } pub fn should_bundle_module(mod string) bool { - return mod in bundle_modules || (mod.contains('.') && mod.all_before('.') in bundle_modules) + return mod in util.bundle_modules + || (mod.contains('.') && mod.all_before('.') in util.bundle_modules) } diff --git a/vlib/v/vmod/vmod.v b/vlib/v/vmod/vmod.v index 32831ae6a6..bec9c9c9fd 100644 --- a/vlib/v/vmod/vmod.v +++ b/vlib/v/vmod/vmod.v @@ -139,7 +139,7 @@ const ( ) fn (mcache &ModFileCacher) check_for_stop(cfolder string, files []string) bool { - for i in mod_file_stop_paths { + for i in vmod.mod_file_stop_paths { if i in files { return true } @@ -167,5 +167,5 @@ const ( ) pub fn get_cache() &ModFileCacher { - return private_file_cacher + return vmod.private_file_cacher } diff --git a/vlib/vweb/assets/assets.v b/vlib/vweb/assets/assets.v index 5605ac63ee..7dc8ee2f0c 100644 --- a/vlib/vweb/assets/assets.v +++ b/vlib/vweb/assets/assets.v @@ -159,7 +159,7 @@ fn (mut am AssetManager) add(asset_type string, file string) bool { } else if asset_type == 'js' { am.js << asset } else { - panic('$unknown_asset_type_error ($asset_type).') + panic('$assets.unknown_asset_type_error ($asset_type).') } return true } @@ -176,7 +176,7 @@ fn (am AssetManager) exists(asset_type string, file string) bool { fn (am AssetManager) get_assets(asset_type string) []Asset { if asset_type != 'css' && asset_type != 'js' { - panic('$unknown_asset_type_error ($asset_type).') + panic('$assets.unknown_asset_type_error ($asset_type).') } assets := if asset_type == 'css' { am.css } else { am.js } return assets diff --git a/vlib/vweb/tests/vweb_test.v b/vlib/vweb/tests/vweb_test.v index 4d24f68118..c03d07fb85 100644 --- a/vlib/vweb/tests/vweb_test.v +++ b/vlib/vweb/tests/vweb_test.v @@ -18,18 +18,18 @@ const ( // setup of vweb webserver fn testsuite_begin() { - os.chdir(vroot) - if os.exists(serverexe) { - os.rm(serverexe) + os.chdir(main.vroot) + if os.exists(main.serverexe) { + os.rm(main.serverexe) } } fn test_a_simple_vweb_app_can_be_compiled() { // did_server_compile := os.system('$vexe -g -o $serverexe vlib/vweb/tests/vweb_test_server.v') // TODO: find out why it does not compile with -usecache and -g - did_server_compile := os.system('$vexe -o $serverexe vlib/vweb/tests/vweb_test_server.v') + did_server_compile := os.system('$main.vexe -o $main.serverexe vlib/vweb/tests/vweb_test_server.v') assert did_server_compile == 0 - assert os.exists(serverexe) + assert os.exists(main.serverexe) } fn test_a_simple_vweb_app_runs_in_the_background() { @@ -37,10 +37,10 @@ fn test_a_simple_vweb_app_runs_in_the_background() { $if !windows { suffix = ' > /dev/null &' } - if vweb_logfile != '' { - suffix = ' 2>> $vweb_logfile >> $vweb_logfile &' + if main.vweb_logfile != '' { + suffix = ' 2>> $main.vweb_logfile >> $main.vweb_logfile &' } - server_exec_cmd := '$serverexe $sport $exit_after_time $suffix' + server_exec_cmd := '$main.serverexe $main.sport $main.exit_after_time $suffix' $if debug_net_socket_client ? { eprintln('running:\n$server_exec_cmd') } @@ -102,14 +102,14 @@ fn assert_common_http_headers(x http.Response) { } fn test_http_client_index() { - x := http.get('http://127.0.0.1:$sport/') or { panic(err) } + x := http.get('http://127.0.0.1:$main.sport/') or { panic(err) } assert_common_http_headers(x) assert x.headers['Content-Type'] == 'text/plain' assert x.text == 'Welcome to VWeb' } fn test_http_client_chunk_transfer() { - x := http.get('http://127.0.0.1:$sport/chunk') or { panic(err) } + x := http.get('http://127.0.0.1:$main.sport/chunk') or { panic(err) } assert_common_http_headers(x) assert x.headers['Transfer-Encoding'] == 'chunked' assert x.text == 'Lorem ipsum dolor sit amet, consetetur sadipscing' @@ -117,9 +117,9 @@ fn test_http_client_chunk_transfer() { fn test_http_client_404() { url_404_list := [ - 'http://127.0.0.1:$sport/zxcnbnm', - 'http://127.0.0.1:$sport/JHKAJA', - 'http://127.0.0.1:$sport/unknown', + 'http://127.0.0.1:$main.sport/zxcnbnm', + 'http://127.0.0.1:$main.sport/JHKAJA', + 'http://127.0.0.1:$main.sport/unknown', ] for url in url_404_list { res := http.get(url) or { panic(err) } @@ -128,39 +128,39 @@ fn test_http_client_404() { } fn test_http_client_simple() { - x := http.get('http://127.0.0.1:$sport/simple') or { panic(err) } + x := http.get('http://127.0.0.1:$main.sport/simple') or { panic(err) } assert_common_http_headers(x) assert x.headers['Content-Type'] == 'text/plain' assert x.text == 'A simple result' } fn test_http_client_html_page() { - x := http.get('http://127.0.0.1:$sport/html_page') or { panic(err) } + x := http.get('http://127.0.0.1:$main.sport/html_page') or { panic(err) } assert_common_http_headers(x) assert x.headers['Content-Type'] == 'text/html' assert x.text == '

ok

' } fn test_http_client_settings_page() { - x := http.get('http://127.0.0.1:$sport/bilbo/settings') or { panic(err) } + x := http.get('http://127.0.0.1:$main.sport/bilbo/settings') or { panic(err) } assert_common_http_headers(x) assert x.text == 'username: bilbo' // - y := http.get('http://127.0.0.1:$sport/kent/settings') or { panic(err) } + y := http.get('http://127.0.0.1:$main.sport/kent/settings') or { panic(err) } assert_common_http_headers(y) assert y.text == 'username: kent' } fn test_http_client_user_repo_settings_page() { - x := http.get('http://127.0.0.1:$sport/bilbo/gostamp/settings') or { panic(err) } + x := http.get('http://127.0.0.1:$main.sport/bilbo/gostamp/settings') or { panic(err) } assert_common_http_headers(x) assert x.text == 'username: bilbo | repository: gostamp' // - y := http.get('http://127.0.0.1:$sport/kent/golang/settings') or { panic(err) } + y := http.get('http://127.0.0.1:$main.sport/kent/golang/settings') or { panic(err) } assert_common_http_headers(y) assert y.text == 'username: kent | repository: golang' // - z := http.get('http://127.0.0.1:$sport/missing/golang/settings') or { panic(err) } + z := http.get('http://127.0.0.1:$main.sport/missing/golang/settings') or { panic(err) } assert z.status_code == 404 } @@ -175,7 +175,9 @@ fn test_http_client_json_post() { age: 123 } json_for_ouser := json.encode(ouser) - mut x := http.post_json('http://127.0.0.1:$sport/json_echo', json_for_ouser) or { panic(err) } + mut x := http.post_json('http://127.0.0.1:$main.sport/json_echo', json_for_ouser) or { + panic(err) + } $if debug_net_socket_client ? { eprintln('/json_echo endpoint response: $x') } @@ -184,7 +186,7 @@ fn test_http_client_json_post() { nuser := json.decode(User, x.text) or { User{} } assert '$ouser' == '$nuser' // - x = http.post_json('http://127.0.0.1:$sport/json', json_for_ouser) or { panic(err) } + x = http.post_json('http://127.0.0.1:$main.sport/json', json_for_ouser) or { panic(err) } $if debug_net_socket_client ? { eprintln('/json endpoint response: $x') } @@ -195,7 +197,7 @@ fn test_http_client_json_post() { } fn test_http_client_shutdown_does_not_work_without_a_cookie() { - x := http.get('http://127.0.0.1:$sport/shutdown') or { + x := http.get('http://127.0.0.1:$main.sport/shutdown') or { assert err == '' return } @@ -206,7 +208,7 @@ fn test_http_client_shutdown_does_not_work_without_a_cookie() { fn testsuite_end() { // This test is guaranteed to be called last. // It sends a request to the server to shutdown. - x := http.fetch('http://127.0.0.1:$sport/shutdown', + x := http.fetch('http://127.0.0.1:$main.sport/shutdown', method: .get cookies: { 'skey': 'superman' @@ -234,7 +236,7 @@ fn simple_tcp_client(config SimpleTcpClientConfig) ?string { mut tries := 0 for tries < config.retries { tries++ - client = net.dial_tcp('127.0.0.1:$sport') or { + client = net.dial_tcp('127.0.0.1:$main.sport') or { if tries > config.retries { return error(err) } @@ -243,8 +245,8 @@ fn simple_tcp_client(config SimpleTcpClientConfig) ?string { } break } - client.set_read_timeout(tcp_r_timeout) - client.set_write_timeout(tcp_w_timeout) + client.set_read_timeout(main.tcp_r_timeout) + client.set_write_timeout(main.tcp_w_timeout) defer { client.close() } diff --git a/vlib/vweb/tests/vweb_test_server.v b/vlib/vweb/tests/vweb_test_server.v index 08d2a907b0..e9447bd13f 100644 --- a/vlib/vweb/tests/vweb_test_server.v +++ b/vlib/vweb/tests/vweb_test_server.v @@ -64,7 +64,7 @@ pub fn (mut app App) chunk() vweb.Result { // the following serve custom routes ['/:user/settings'] pub fn (mut app App) settings(username string) vweb.Result { - if username !in known_users { + if username !in main.known_users { return app.not_found() } return app.html('username: $username') @@ -72,7 +72,7 @@ pub fn (mut app App) settings(username string) vweb.Result { ['/:user/:repo/settings'] pub fn (mut app App) user_repo_settings(username string, repository string) vweb.Result { - if username !in known_users { + if username !in main.known_users { return app.not_found() } return app.html('username: $username | repository: $repository') diff --git a/vlib/vweb/tmpl/tmpl.v b/vlib/vweb/tmpl/tmpl.v index fc7dbb3153..eb45e502a1 100644 --- a/vlib/vweb/tmpl/tmpl.v +++ b/vlib/vweb/tmpl/tmpl.v @@ -58,7 +58,7 @@ footer := \' \' // TODO remove _ = footer ") - s.write(str_start) + s.write(tmpl.str_start) mut state := State.html mut in_span := false // for _line in lines { @@ -99,23 +99,23 @@ _ = footer s.write(line[pos + 6..line.len - 1]) s.writeln('" rel="stylesheet" type="text/css">') } else if line.contains('@if ') { - s.writeln(str_end) + s.writeln(tmpl.str_end) pos := line.index('@if') or { continue } s.writeln('if ' + line[pos + 4..] + '{') - s.writeln(str_start) + s.writeln(tmpl.str_start) } else if line.contains('@end') { - s.writeln(str_end) + s.writeln(tmpl.str_end) s.writeln('}') - s.writeln(str_start) + s.writeln(tmpl.str_start) } else if line.contains('@else') { - s.writeln(str_end) + s.writeln(tmpl.str_end) s.writeln(' } else { ') - s.writeln(str_start) + s.writeln(tmpl.str_start) } else if line.contains('@for') { - s.writeln(str_end) + s.writeln(tmpl.str_end) pos := line.index('@for') or { continue } s.writeln('for ' + line[pos + 4..] + '{') - s.writeln(str_start) + s.writeln(tmpl.str_start) } else if state == .html && line.contains('span.') && line.ends_with('{') { // `span.header {` => `` class := line.find_between('span.', '{').trim_space() @@ -142,7 +142,7 @@ _ = footer s.writeln(line.replace('@', '$').replace("'", '"')) } } - s.writeln(str_end) + s.writeln(tmpl.str_end) s.writeln('_tmpl_res_$fn_name := sb.str() ') s.writeln('}') s.writeln('// === end of vweb html template ===') diff --git a/vlib/vweb/vweb.v b/vlib/vweb/vweb.v index 2467562266..d5d2af083c 100644 --- a/vlib/vweb/vweb.v +++ b/vlib/vweb/vweb.v @@ -106,7 +106,7 @@ pub fn (mut ctx Context) send_response_to_client(mimetype string, res string) bo } sb.write(ctx.headers) sb.write('\r\n') - sb.write(headers_close) + sb.write(vweb.headers_close) if ctx.chunked_transfer { mut i := 0 mut len := res.len @@ -163,7 +163,7 @@ pub fn (mut ctx Context) redirect(url string) Result { return Result{} } ctx.done = true - send_string(mut ctx.conn, 'HTTP/1.1 302 Found\r\nLocation: $url$ctx.headers\r\n$headers_close') or { + send_string(mut ctx.conn, 'HTTP/1.1 302 Found\r\nLocation: $url$ctx.headers\r\n$vweb.headers_close') or { return Result{} } return Result{} @@ -174,7 +174,7 @@ pub fn (mut ctx Context) not_found() Result { return Result{} } ctx.done = true - send_string(mut ctx.conn, http_404) or { } + send_string(mut ctx.conn, vweb.http_404) or { } return Result{} } @@ -317,7 +317,7 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { vals := first_line.split(' ') if vals.len < 2 { println('no vals for http') - send_string(mut conn, http_500) or { } + send_string(mut conn, vweb.http_500) or { } return } mut headers := []string{} @@ -397,7 +397,7 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { page_gen_start: page_gen_start } // } - if req.method in methods_with_form { + if req.method in vweb.methods_with_form { if ct == 'multipart/form-data' { app.parse_multipart_form(body, boundary) } else { @@ -420,7 +420,7 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { mime_type := app.static_mime_types[static_file_name] if static_file != '' && mime_type != '' { data := os.read_file(static_file) or { - send_string(mut conn, http_404) or { } + send_string(mut conn, vweb.http_404) or { } return } app.send_response_to_client(mime_type, data) @@ -516,7 +516,7 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { for route_words_ in route_words_a { // cannot move to line initialize line because of C error with map(it.filter(it != '')) route_words := route_words_.filter(it != '') - if route_words.len == 1 && route_words[0] in methods_without_first { + if route_words.len == 1 && route_words[0] in vweb.methods_without_first { req_method << route_words[0] } if url_words.len == route_words.len @@ -581,7 +581,7 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { } if action == '' { // site not found - send_string(mut conn, http_404) or { } + send_string(mut conn, vweb.http_404) or { } return } $for method in T.methods { @@ -600,7 +600,7 @@ fn handle_conn(mut conn net.TcpConn, mut app T) { } pub fn (mut ctx Context) parse_form(s string) { - if ctx.req.method !in methods_with_form { + if ctx.req.method !in vweb.methods_with_form { return } // pos := s.index('\r\n\r\n') @@ -630,7 +630,7 @@ pub fn (mut ctx Context) parse_form(s string) { [manualfree] pub fn (mut ctx Context) parse_multipart_form(s string, b string) { - if ctx.req.method !in methods_with_form { + if ctx.req.method !in vweb.methods_with_form { return } a := s.split('$b')[1..] @@ -696,8 +696,8 @@ fn (mut ctx Context) scan_static_directory(directory_path string, mount_path str ext := os.file_ext(file) // Rudimentary guard against adding files not in mime_types. // Use serve_static directly to add non-standard mime types. - if ext in mime_types { - ctx.serve_static(mount_path + '/' + file, full_path, mime_types[ext]) + if ext in vweb.mime_types { + ctx.serve_static(mount_path + '/' + file, full_path, vweb.mime_types[ext]) } } } diff --git a/vlib/x/websocket/message.v b/vlib/x/websocket/message.v index 9209ec1610..cd6d25530a 100644 --- a/vlib/x/websocket/message.v +++ b/vlib/x/websocket/message.v @@ -223,7 +223,7 @@ pub fn (mut ws Client) parse_frame_header() ?Frame { buffer[bytes_read] = rbuff[0] bytes_read++ // parses the first two header bytes to get basic frame information - if bytes_read == u64(header_len_offset) { + if bytes_read == u64(websocket.header_len_offset) { frame.fin = (buffer[0] & 0x80) == 0x80 frame.rsv1 = (buffer[0] & 0x40) == 0x40 frame.rsv2 = (buffer[0] & 0x20) == 0x20 @@ -234,11 +234,11 @@ pub fn (mut ws Client) parse_frame_header() ?Frame { // if has mask set the byte postition where mask ends if frame.has_mask { mask_end_byte = if frame.payload_len < 126 { - header_len_offset + 4 + websocket.header_len_offset + 4 } else if frame.payload_len == 126 { - header_len_offset + 6 + websocket.header_len_offset + 6 } else if frame.payload_len == 127 { - header_len_offset + 12 + websocket.header_len_offset + 12 } else { 0 } // impossible @@ -249,7 +249,7 @@ pub fn (mut ws Client) parse_frame_header() ?Frame { break } } - if frame.payload_len == 126 && bytes_read == u64(extended_payload16_end_byte) { + if frame.payload_len == 126 && bytes_read == u64(websocket.extended_payload16_end_byte) { frame.header_len += 2 frame.payload_len = 0 frame.payload_len |= buffer[2] << 8 @@ -259,7 +259,7 @@ pub fn (mut ws Client) parse_frame_header() ?Frame { break } } - if frame.payload_len == 127 && bytes_read == u64(extended_payload64_end_byte) { + if frame.payload_len == 127 && bytes_read == u64(websocket.extended_payload64_end_byte) { frame.header_len += 8 // these shift operators needs 64 bit on clang with -prod flag mut payload_len := u64(0) diff --git a/vlib/x/websocket/websocket_client.v b/vlib/x/websocket/websocket_client.v index c721ad80a3..ccd645d53e 100644 --- a/vlib/x/websocket/websocket_client.v +++ b/vlib/x/websocket/websocket_client.v @@ -360,7 +360,7 @@ fn (mut ws Client) send_control_frame(code OPCode, frame_typ string, payload []b header_len := if ws.is_server { 2 } else { 6 } frame_len := header_len + payload.len mut control_frame := []byte{len: frame_len} - mut masking_key := if !ws.is_server { create_masking_key() } else { empty_bytearr } + mut masking_key := if !ws.is_server { create_masking_key() } else { websocket.empty_bytearr } defer { unsafe { control_frame.free()