From 0e2c41e0f972f1d3c066a0c63e7f428ab94a5ee5 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 1 Sep 2019 22:51:16 +0300 Subject: [PATCH] replace *Foo with &Foo everywhere --- compiler/cgen.v | 2 +- compiler/fn.v | 6 +++--- compiler/main.v | 8 ++++---- compiler/modules.v | 34 +++++++++++++++++----------------- compiler/parser.v | 18 ++++++++++-------- compiler/scanner.v | 2 +- compiler/table.v | 4 ++-- vlib/builtin/array.v | 2 +- vlib/builtin/map.v | 10 +++++----- vlib/builtin/string.v | 6 +++--- vlib/os/os.v | 8 ++++---- vlib/time/time.v | 2 +- 12 files changed, 52 insertions(+), 50 deletions(-) diff --git a/compiler/cgen.v b/compiler/cgen.v index 54d156b549..22892a5324 100644 --- a/compiler/cgen.v +++ b/compiler/cgen.v @@ -39,7 +39,7 @@ mut: cut_pos int } -fn new_cgen(out_name_c string) *CGen { +fn new_cgen(out_name_c string) &CGen { path := out_name_c out := os.create(path) or { println('failed to create $path') diff --git a/compiler/fn.v b/compiler/fn.v index 94ae1f54c9..cbd873940d 100644 --- a/compiler/fn.v +++ b/compiler/fn.v @@ -103,7 +103,7 @@ fn (p mut Parser) is_sig() bool { (p.file_path.contains(ModPath)) } -fn new_fn(mod string, is_public bool) *Fn { +fn new_fn(mod string, is_public bool) &Fn { return &Fn { mod: mod local_vars: [Var{} ; MaxLocalVars] @@ -756,7 +756,7 @@ fn (p mut Parser) fn_args(f mut Fn) { } // foo *(1, 2, 3, mut bar)* -fn (p mut Parser) fn_call_args(f mut Fn) *Fn { +fn (p mut Parser) fn_call_args(f mut Fn) &Fn { // p.gen('(') // println('fn_call_args() name=$f.name args.len=$f.args.len') // C func. # of args is not known @@ -977,7 +977,7 @@ fn (f Fn) typ_str() string { } // f.args => "int a, string b" -fn (f &Fn) str_args(table *Table) string { +fn (f &Fn) str_args(table &Table) string { mut s := '' for i, arg in f.args { // Interfaces are a special case. We need to pass the object + pointers diff --git a/compiler/main.v b/compiler/main.v index 6b78752136..aa163cf1e2 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -62,9 +62,9 @@ mut: out_name_c string // name of the temporary C file files []string // all V files that need to be parsed and compiled dir string // directory (or file) being compiled (TODO rename to path?) - table *Table // table with types, vars, functions etc - cgen *CGen // C code generator - pref *Preferences // all the prefrences and settings extracted to a struct for reusability + table &Table // table with types, vars, functions etc + cgen &CGen // C code generator + pref &Preferences // all the prefrences and settings extracted to a struct for reusability lang_dir string // "~/code/v" out_name string // "program.exe" vroot string @@ -651,7 +651,7 @@ fn (v &V) log(s string) { println(s) } -fn new_v(args[]string) *V { +fn new_v(args[]string) &V { joined_args := args.join(' ') target_os := get_arg(joined_args, 'os', '') mut out_name := get_arg(joined_args, 'o', 'a.out') diff --git a/compiler/modules.v b/compiler/modules.v index ab4c06840f..b36e8e74e8 100644 --- a/compiler/modules.v +++ b/compiler/modules.v @@ -4,7 +4,7 @@ module main -import os +import os struct ModDepGraphNode { mut: @@ -21,7 +21,7 @@ pub: } struct DepSet { - mut: + mut: items []string } @@ -43,7 +43,7 @@ pub fn(dset &DepSet) size() int { return dset.items.len } -pub fn new_mod_dep_graph() *ModDepGraph { +pub fn new_mod_dep_graph() &ModDepGraph { return &ModDepGraph{ acyclic: true } @@ -66,9 +66,9 @@ pub fn(graph mut ModDepGraph) add(mod string, deps []string) { } } -pub fn(graph &ModDepGraph) resolve() *ModDepGraph { - mut node_names := map[string]ModDepGraphNode - mut node_deps := map[string]DepSet +pub fn(graph &ModDepGraph) resolve() &ModDepGraph { + mut node_names := map[string]ModDepGraphNode + mut node_deps := map[string]DepSet for _, node in graph.nodes { node_names[node.name] = node @@ -148,24 +148,24 @@ pub fn(graph &ModDepGraph) display() { } } -// 'strings' => 'VROOT/vlib/strings' -// 'installed_mod' => '~/.vmodules/installed_mod' -// 'local_mod' => '/path/to/current/dir/local_mod' +// 'strings' => 'VROOT/vlib/strings' +// 'installed_mod' => '~/.vmodules/installed_mod' +// 'local_mod' => '/path/to/current/dir/local_mod' fn (v &V) find_module_path(mod string) string { mod_path := v.module_path(mod) - // First check for local modules in the same directory + // First check for local modules in the same directory mut import_path := os.getwd() + '/$mod_path' - // Now search in vlib/ + // Now search in vlib/ if !os.dir_exists(import_path) { import_path = '$v.lang_dir/vlib/$mod_path' - } - //println('ip=$import_path') - // Finally try modules installed with vpm (~/.vmodules) + } + //println('ip=$import_path') + // Finally try modules installed with vpm (~/.vmodules) if !os.dir_exists(import_path) { import_path = '$ModPath/$mod_path' if !os.dir_exists(import_path){ cerror('module "$mod" not found') - } + } } - return import_path -} + return import_path +} diff --git a/compiler/parser.v b/compiler/parser.v index 4e741c739d..85a264f122 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -18,17 +18,17 @@ struct Parser { // C ifdef guard clause that must be put before // the #include directives in the parsed .v file mut: - v *V - scanner *Scanner + v &V + scanner &Scanner // tokens []Token // TODO cache all tokens, right now they have to be scanned twice token_idx int tok Token prev_tok Token prev_tok2 Token // TODO remove these once the tokens are cached lit string - cgen *CGen - table *Table - import_table *FileImportTable // Holds imports for just the file being parsed + cgen &CGen + table &Table + import_table &FileImportTable // Holds imports for just the file being parsed pass Pass os OS mod string @@ -40,7 +40,7 @@ mut: expected_type string tmp_cnt int is_script bool - pref *Preferences // Setting and Preferences shared from V struct + pref &Preferences // Setting and Preferences shared from V struct builtin_mod bool vh_lines []string inside_if_expr bool @@ -50,7 +50,7 @@ mut: for_expr_cnt int // to detect whether `continue` can be used ptr_cast bool calling_c bool - cur_fn *Fn + cur_fn &Fn returns bool vroot string is_c_struct_init bool @@ -867,7 +867,9 @@ fn (p mut Parser) get_type() string { } // for p.tok == .mul { - p.warn('use `&Foo` instead of `*Foo`') + if p.first_pass() { + p.warn('use `&Foo` instead of `*Foo`') + } mul = true nr_muls++ p.check(.mul) diff --git a/compiler/scanner.v b/compiler/scanner.v index a93d832202..f96917eac4 100644 --- a/compiler/scanner.v +++ b/compiler/scanner.v @@ -26,7 +26,7 @@ mut: prev_tok Token } -fn new_scanner(file_path string) *Scanner { +fn new_scanner(file_path string) &Scanner { if !os.file_exists(file_path) { cerror('"$file_path" doesn\'t exist') } diff --git a/compiler/table.v b/compiler/table.v index 4277e1c6f3..cb760f6d28 100644 --- a/compiler/table.v +++ b/compiler/table.v @@ -211,7 +211,7 @@ fn is_primitive_type(typ string) bool { return is_number_type(typ) || typ == 'string' } -fn new_table(obfuscate bool) *Table { +fn new_table(obfuscate bool) &Table { mut t := &Table { obfuscate: obfuscate } @@ -857,7 +857,7 @@ fn (table &Table) qualify_module(mod string, file_path string) string { return mod } -fn new_file_import_table(file_path string) *FileImportTable { +fn new_file_import_table(file_path string) &FileImportTable { return &FileImportTable{ file_path: file_path imports: map[string]string diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index fe58962fad..b2d949625f 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -260,7 +260,7 @@ pub fn copy(dst, src []byte) int { return 0 } -fn compare_ints(a, b *int) int { +fn compare_ints(a, b &int) int { if a < b { return -1 } diff --git a/vlib/builtin/map.v b/vlib/builtin/map.v index 91d29f65ef..7b8f601b39 100644 --- a/vlib/builtin/map.v +++ b/vlib/builtin/map.v @@ -8,14 +8,14 @@ import strings struct map { element_size int - root *mapnode + root &mapnode pub: size int } struct mapnode { - left *mapnode - right *mapnode + left &mapnode + right &mapnode is_empty bool key string val voidptr @@ -30,7 +30,7 @@ fn new_map(cap, elm_size int) map { } // `m := { 'one': 1, 'two': 2 }` -fn new_map_init(cap, elm_size int, keys *string, vals voidptr) map { +fn new_map_init(cap, elm_size int, keys &string, vals voidptr) map { mut res := map { element_size: elm_size root: 0 @@ -41,7 +41,7 @@ fn new_map_init(cap, elm_size int, keys *string, vals voidptr) map { return res } -fn new_node(key string, val voidptr, element_size int) *mapnode { +fn new_node(key string, val voidptr, element_size int) &mapnode { new_e := &mapnode { key: key val: malloc(element_size) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 81d5cc1dbb..503a3380e2 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -639,7 +639,7 @@ pub fn (s string) trim_right(cutset string) string { // fn print_cur_thread() { // //C.printf("tid = %08x \n", pthread_self()); // } -fn compare_strings(a, b *string) int { +fn compare_strings(a, b &string) int { if a.lt(b) { return -1 } @@ -649,7 +649,7 @@ fn compare_strings(a, b *string) int { return 0 } -fn compare_strings_by_len(a, b *string) int { +fn compare_strings_by_len(a, b &string) int { if a.len < b.len { return -1 } @@ -659,7 +659,7 @@ fn compare_strings_by_len(a, b *string) int { return 0 } -fn compare_lower_strings(a, b *string) int { +fn compare_lower_strings(a, b &string) int { aa := a.to_lower() bb := b.to_lower() return compare_strings(aa, bb) diff --git a/vlib/os/os.v b/vlib/os/os.v index bcb75fc933..dee8454af5 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -34,7 +34,7 @@ struct C.FILE { } struct File { - cfile *FILE + cfile &FILE } struct FileInfo { @@ -87,7 +87,7 @@ fn C.sigaction(int, voidptr, int) fn todo_remove(){} -fn init_os_args(argc int, argv *byteptr) []string { +fn init_os_args(argc int, argv &byteptr) []string { mut args := []string $if windows { mut args_list := &voidptr(0) @@ -308,7 +308,7 @@ pub fn (f File) close() { // system starts the specified command, waits for it to complete, and returns its code. -fn popen(path string) *FILE { +fn popen(path string) &FILE { $if windows { mode := 'rb' wpath := path.to_wide() @@ -320,7 +320,7 @@ fn popen(path string) *FILE { } } -fn pclose(f *FILE) int { +fn pclose(f &FILE) int { $if windows { return C._pclose(f) } diff --git a/vlib/time/time.v b/vlib/time/time.v index 18ae0d48c7..c216da13a1 100644 --- a/vlib/time/time.v +++ b/vlib/time/time.v @@ -24,7 +24,7 @@ pub: } -fn C.localtime(int) *C.tm +fn C.localtime(int) &C.tm fn remove_me_when_c_bug_is_fixed() { // TODO }