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
|
cut_pos int
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_cgen(out_name_c string) *CGen {
|
fn new_cgen(out_name_c string) &CGen {
|
||||||
path := out_name_c
|
path := out_name_c
|
||||||
out := os.create(path) or {
|
out := os.create(path) or {
|
||||||
println('failed to create $path')
|
println('failed to create $path')
|
||||||
|
@ -103,7 +103,7 @@ fn (p mut Parser) is_sig() bool {
|
|||||||
(p.file_path.contains(ModPath))
|
(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 {
|
return &Fn {
|
||||||
mod: mod
|
mod: mod
|
||||||
local_vars: [Var{} ; MaxLocalVars]
|
local_vars: [Var{} ; MaxLocalVars]
|
||||||
@ -756,7 +756,7 @@ fn (p mut Parser) fn_args(f mut Fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// foo *(1, 2, 3, mut bar)*
|
// 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('(')
|
// p.gen('(')
|
||||||
// println('fn_call_args() name=$f.name args.len=$f.args.len')
|
// println('fn_call_args() name=$f.name args.len=$f.args.len')
|
||||||
// C func. # of args is not known
|
// C func. # of args is not known
|
||||||
@ -977,7 +977,7 @@ fn (f Fn) typ_str() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// f.args => "int a, string b"
|
// f.args => "int a, string b"
|
||||||
fn (f &Fn) str_args(table *Table) string {
|
fn (f &Fn) str_args(table &Table) string {
|
||||||
mut s := ''
|
mut s := ''
|
||||||
for i, arg in f.args {
|
for i, arg in f.args {
|
||||||
// Interfaces are a special case. We need to pass the object + pointers
|
// 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
|
out_name_c string // name of the temporary C file
|
||||||
files []string // all V files that need to be parsed and compiled
|
files []string // all V files that need to be parsed and compiled
|
||||||
dir string // directory (or file) being compiled (TODO rename to path?)
|
dir string // directory (or file) being compiled (TODO rename to path?)
|
||||||
table *Table // table with types, vars, functions etc
|
table &Table // table with types, vars, functions etc
|
||||||
cgen *CGen // C code generator
|
cgen &CGen // C code generator
|
||||||
pref *Preferences // all the prefrences and settings extracted to a struct for reusability
|
pref &Preferences // all the prefrences and settings extracted to a struct for reusability
|
||||||
lang_dir string // "~/code/v"
|
lang_dir string // "~/code/v"
|
||||||
out_name string // "program.exe"
|
out_name string // "program.exe"
|
||||||
vroot string
|
vroot string
|
||||||
@ -651,7 +651,7 @@ fn (v &V) log(s string) {
|
|||||||
println(s)
|
println(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_v(args[]string) *V {
|
fn new_v(args[]string) &V {
|
||||||
joined_args := args.join(' ')
|
joined_args := args.join(' ')
|
||||||
target_os := get_arg(joined_args, 'os', '')
|
target_os := get_arg(joined_args, 'os', '')
|
||||||
mut out_name := get_arg(joined_args, 'o', 'a.out')
|
mut out_name := get_arg(joined_args, 'o', 'a.out')
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
module main
|
module main
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
struct ModDepGraphNode {
|
struct ModDepGraphNode {
|
||||||
mut:
|
mut:
|
||||||
@ -21,7 +21,7 @@ pub:
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct DepSet {
|
struct DepSet {
|
||||||
mut:
|
mut:
|
||||||
items []string
|
items []string
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ pub fn(dset &DepSet) size() int {
|
|||||||
return dset.items.len
|
return dset.items.len
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_mod_dep_graph() *ModDepGraph {
|
pub fn new_mod_dep_graph() &ModDepGraph {
|
||||||
return &ModDepGraph{
|
return &ModDepGraph{
|
||||||
acyclic: true
|
acyclic: true
|
||||||
}
|
}
|
||||||
@ -66,9 +66,9 @@ pub fn(graph mut ModDepGraph) add(mod string, deps []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn(graph &ModDepGraph) resolve() *ModDepGraph {
|
pub fn(graph &ModDepGraph) resolve() &ModDepGraph {
|
||||||
mut node_names := map[string]ModDepGraphNode
|
mut node_names := map[string]ModDepGraphNode
|
||||||
mut node_deps := map[string]DepSet
|
mut node_deps := map[string]DepSet
|
||||||
|
|
||||||
for _, node in graph.nodes {
|
for _, node in graph.nodes {
|
||||||
node_names[node.name] = node
|
node_names[node.name] = node
|
||||||
@ -148,24 +148,24 @@ pub fn(graph &ModDepGraph) display() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 'strings' => 'VROOT/vlib/strings'
|
// 'strings' => 'VROOT/vlib/strings'
|
||||||
// 'installed_mod' => '~/.vmodules/installed_mod'
|
// 'installed_mod' => '~/.vmodules/installed_mod'
|
||||||
// 'local_mod' => '/path/to/current/dir/local_mod'
|
// 'local_mod' => '/path/to/current/dir/local_mod'
|
||||||
fn (v &V) find_module_path(mod string) string {
|
fn (v &V) find_module_path(mod string) string {
|
||||||
mod_path := v.module_path(mod)
|
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'
|
mut import_path := os.getwd() + '/$mod_path'
|
||||||
// Now search in vlib/
|
// Now search in vlib/
|
||||||
if !os.dir_exists(import_path) {
|
if !os.dir_exists(import_path) {
|
||||||
import_path = '$v.lang_dir/vlib/$mod_path'
|
import_path = '$v.lang_dir/vlib/$mod_path'
|
||||||
}
|
}
|
||||||
//println('ip=$import_path')
|
//println('ip=$import_path')
|
||||||
// Finally try modules installed with vpm (~/.vmodules)
|
// Finally try modules installed with vpm (~/.vmodules)
|
||||||
if !os.dir_exists(import_path) {
|
if !os.dir_exists(import_path) {
|
||||||
import_path = '$ModPath/$mod_path'
|
import_path = '$ModPath/$mod_path'
|
||||||
if !os.dir_exists(import_path){
|
if !os.dir_exists(import_path){
|
||||||
cerror('module "$mod" not found')
|
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
|
// C ifdef guard clause that must be put before
|
||||||
// the #include directives in the parsed .v file
|
// the #include directives in the parsed .v file
|
||||||
mut:
|
mut:
|
||||||
v *V
|
v &V
|
||||||
scanner *Scanner
|
scanner &Scanner
|
||||||
// tokens []Token // TODO cache all tokens, right now they have to be scanned twice
|
// tokens []Token // TODO cache all tokens, right now they have to be scanned twice
|
||||||
token_idx int
|
token_idx int
|
||||||
tok Token
|
tok Token
|
||||||
prev_tok Token
|
prev_tok Token
|
||||||
prev_tok2 Token // TODO remove these once the tokens are cached
|
prev_tok2 Token // TODO remove these once the tokens are cached
|
||||||
lit string
|
lit string
|
||||||
cgen *CGen
|
cgen &CGen
|
||||||
table *Table
|
table &Table
|
||||||
import_table *FileImportTable // Holds imports for just the file being parsed
|
import_table &FileImportTable // Holds imports for just the file being parsed
|
||||||
pass Pass
|
pass Pass
|
||||||
os OS
|
os OS
|
||||||
mod string
|
mod string
|
||||||
@ -40,7 +40,7 @@ mut:
|
|||||||
expected_type string
|
expected_type string
|
||||||
tmp_cnt int
|
tmp_cnt int
|
||||||
is_script bool
|
is_script bool
|
||||||
pref *Preferences // Setting and Preferences shared from V struct
|
pref &Preferences // Setting and Preferences shared from V struct
|
||||||
builtin_mod bool
|
builtin_mod bool
|
||||||
vh_lines []string
|
vh_lines []string
|
||||||
inside_if_expr bool
|
inside_if_expr bool
|
||||||
@ -50,7 +50,7 @@ mut:
|
|||||||
for_expr_cnt int // to detect whether `continue` can be used
|
for_expr_cnt int // to detect whether `continue` can be used
|
||||||
ptr_cast bool
|
ptr_cast bool
|
||||||
calling_c bool
|
calling_c bool
|
||||||
cur_fn *Fn
|
cur_fn &Fn
|
||||||
returns bool
|
returns bool
|
||||||
vroot string
|
vroot string
|
||||||
is_c_struct_init bool
|
is_c_struct_init bool
|
||||||
@ -867,7 +867,9 @@ fn (p mut Parser) get_type() string {
|
|||||||
}
|
}
|
||||||
//
|
//
|
||||||
for p.tok == .mul {
|
for p.tok == .mul {
|
||||||
p.warn('use `&Foo` instead of `*Foo`')
|
if p.first_pass() {
|
||||||
|
p.warn('use `&Foo` instead of `*Foo`')
|
||||||
|
}
|
||||||
mul = true
|
mul = true
|
||||||
nr_muls++
|
nr_muls++
|
||||||
p.check(.mul)
|
p.check(.mul)
|
||||||
|
@ -26,7 +26,7 @@ mut:
|
|||||||
prev_tok Token
|
prev_tok Token
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_scanner(file_path string) *Scanner {
|
fn new_scanner(file_path string) &Scanner {
|
||||||
if !os.file_exists(file_path) {
|
if !os.file_exists(file_path) {
|
||||||
cerror('"$file_path" doesn\'t exist')
|
cerror('"$file_path" doesn\'t exist')
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ fn is_primitive_type(typ string) bool {
|
|||||||
return is_number_type(typ) || typ == 'string'
|
return is_number_type(typ) || typ == 'string'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_table(obfuscate bool) *Table {
|
fn new_table(obfuscate bool) &Table {
|
||||||
mut t := &Table {
|
mut t := &Table {
|
||||||
obfuscate: obfuscate
|
obfuscate: obfuscate
|
||||||
}
|
}
|
||||||
@ -857,7 +857,7 @@ fn (table &Table) qualify_module(mod string, file_path string) string {
|
|||||||
return mod
|
return mod
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_file_import_table(file_path string) *FileImportTable {
|
fn new_file_import_table(file_path string) &FileImportTable {
|
||||||
return &FileImportTable{
|
return &FileImportTable{
|
||||||
file_path: file_path
|
file_path: file_path
|
||||||
imports: map[string]string
|
imports: map[string]string
|
||||||
|
@ -260,7 +260,7 @@ pub fn copy(dst, src []byte) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_ints(a, b *int) int {
|
fn compare_ints(a, b &int) int {
|
||||||
if a < b {
|
if a < b {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
@ -8,14 +8,14 @@ import strings
|
|||||||
|
|
||||||
struct map {
|
struct map {
|
||||||
element_size int
|
element_size int
|
||||||
root *mapnode
|
root &mapnode
|
||||||
pub:
|
pub:
|
||||||
size int
|
size int
|
||||||
}
|
}
|
||||||
|
|
||||||
struct mapnode {
|
struct mapnode {
|
||||||
left *mapnode
|
left &mapnode
|
||||||
right *mapnode
|
right &mapnode
|
||||||
is_empty bool
|
is_empty bool
|
||||||
key string
|
key string
|
||||||
val voidptr
|
val voidptr
|
||||||
@ -30,7 +30,7 @@ fn new_map(cap, elm_size int) map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// `m := { 'one': 1, 'two': 2 }`
|
// `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 {
|
mut res := map {
|
||||||
element_size: elm_size
|
element_size: elm_size
|
||||||
root: 0
|
root: 0
|
||||||
@ -41,7 +41,7 @@ fn new_map_init(cap, elm_size int, keys *string, vals voidptr) map {
|
|||||||
return res
|
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 {
|
new_e := &mapnode {
|
||||||
key: key
|
key: key
|
||||||
val: malloc(element_size)
|
val: malloc(element_size)
|
||||||
|
@ -639,7 +639,7 @@ pub fn (s string) trim_right(cutset string) string {
|
|||||||
// fn print_cur_thread() {
|
// fn print_cur_thread() {
|
||||||
// //C.printf("tid = %08x \n", pthread_self());
|
// //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) {
|
if a.lt(b) {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@ -649,7 +649,7 @@ fn compare_strings(a, b *string) int {
|
|||||||
return 0
|
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 {
|
if a.len < b.len {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@ -659,7 +659,7 @@ fn compare_strings_by_len(a, b *string) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compare_lower_strings(a, b *string) int {
|
fn compare_lower_strings(a, b &string) int {
|
||||||
aa := a.to_lower()
|
aa := a.to_lower()
|
||||||
bb := b.to_lower()
|
bb := b.to_lower()
|
||||||
return compare_strings(aa, bb)
|
return compare_strings(aa, bb)
|
||||||
|
@ -34,7 +34,7 @@ struct C.FILE {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct File {
|
struct File {
|
||||||
cfile *FILE
|
cfile &FILE
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FileInfo {
|
struct FileInfo {
|
||||||
@ -87,7 +87,7 @@ fn C.sigaction(int, voidptr, int)
|
|||||||
|
|
||||||
fn todo_remove(){}
|
fn todo_remove(){}
|
||||||
|
|
||||||
fn init_os_args(argc int, argv *byteptr) []string {
|
fn init_os_args(argc int, argv &byteptr) []string {
|
||||||
mut args := []string
|
mut args := []string
|
||||||
$if windows {
|
$if windows {
|
||||||
mut args_list := &voidptr(0)
|
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.
|
// 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 {
|
$if windows {
|
||||||
mode := 'rb'
|
mode := 'rb'
|
||||||
wpath := path.to_wide()
|
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 {
|
$if windows {
|
||||||
return C._pclose(f)
|
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
|
fn remove_me_when_c_bug_is_fixed() { // TODO
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user