mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
replace *Foo with &Foo everywhere
This commit is contained in:
parent
aaab24dcf8
commit
0e2c41e0f9
@ -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')
|
||||
|
@ -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
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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')
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user