mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: clean up all []
This commit is contained in:
parent
5df5f97daf
commit
4a833d8151
@ -1117,7 +1117,7 @@ pub fn (s string) hash() int {
|
|||||||
|
|
||||||
pub fn (s string) bytes() []byte {
|
pub fn (s string) bytes() []byte {
|
||||||
if s.len == 0 {
|
if s.len == 0 {
|
||||||
return []byte
|
return []
|
||||||
}
|
}
|
||||||
mut buf := [byte(0)].repeat(s.len)
|
mut buf := [byte(0)].repeat(s.len)
|
||||||
C.memcpy(buf.data, s.str, s.len)
|
C.memcpy(buf.data, s.str, s.len)
|
||||||
|
@ -171,7 +171,7 @@ fn (p mut Parser) clear_vars() {
|
|||||||
if p.pref.autofree {
|
if p.pref.autofree {
|
||||||
//p.local_vars.free()
|
//p.local_vars.free()
|
||||||
}
|
}
|
||||||
p.local_vars = []Var
|
p.local_vars = []
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1408,7 +1408,8 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti TypeInst) {
|
|||||||
f.args = _f.args
|
f.args = _f.args
|
||||||
f.typ = _f.typ
|
f.typ = _f.typ
|
||||||
f.is_generic = false
|
f.is_generic = false
|
||||||
f.type_inst = []TypeInst
|
f.type_inst = []
|
||||||
|
if false {}
|
||||||
f.dispatch_of = ti
|
f.dispatch_of = ti
|
||||||
// println('using existing inst $f.name(${f.str_args(p.table)}) $f.typ')
|
// println('using existing inst $f.name(${f.str_args(p.table)}) $f.typ')
|
||||||
return
|
return
|
||||||
@ -1431,17 +1432,18 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti TypeInst) {
|
|||||||
|
|
||||||
p.rename_generic_fn_instance(mut f, ti)
|
p.rename_generic_fn_instance(mut f, ti)
|
||||||
f.is_generic = false // the instance is a normal function
|
f.is_generic = false // the instance is a normal function
|
||||||
f.type_inst = []TypeInst
|
f.type_inst = []
|
||||||
|
if false {}
|
||||||
f.scope_level = 0
|
f.scope_level = 0
|
||||||
f.dispatch_of = ti
|
f.dispatch_of = ti
|
||||||
|
|
||||||
// TODO this is done to prevent a crash as a result of this not being
|
// TODO this is done to prevent a crash as a result of this not being
|
||||||
// properly initialised. This is a bug somewhere futher upstream
|
// properly initialised. This is a bug somewhere futher upstream
|
||||||
f.defer_text = []string
|
f.defer_text = []
|
||||||
|
if false {}
|
||||||
old_args := f.args
|
old_args := f.args
|
||||||
new_types := p.replace_type_params(f, ti)
|
new_types := p.replace_type_params(f, ti)
|
||||||
f.args = []Var
|
f.args = []
|
||||||
for i in 0..new_types.len-1 {
|
for i in 0..new_types.len-1 {
|
||||||
mut v := old_args[i]
|
mut v := old_args[i]
|
||||||
v.typ = new_types[i]
|
v.typ = new_types[i]
|
||||||
@ -1465,7 +1467,7 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti TypeInst) {
|
|||||||
p.returns = false
|
p.returns = false
|
||||||
p.cgen.tmp_line = ''
|
p.cgen.tmp_line = ''
|
||||||
p.cgen.cur_line = ''
|
p.cgen.cur_line = ''
|
||||||
p.cgen.lines = []string
|
p.cgen.lines = []
|
||||||
unsafe { // TODO
|
unsafe { // TODO
|
||||||
p.cur_fn = *f
|
p.cur_fn = *f
|
||||||
}
|
}
|
||||||
|
@ -570,7 +570,7 @@ pub fn (v &V) v_files_from_dir(dir string) []string {
|
|||||||
pub fn (v mut V) add_v_files_to_compile() {
|
pub fn (v mut V) add_v_files_to_compile() {
|
||||||
mut builtin_files := v.get_builtin_files()
|
mut builtin_files := v.get_builtin_files()
|
||||||
if v.pref.is_bare {
|
if v.pref.is_bare {
|
||||||
builtin_files = []string
|
builtin_files = []
|
||||||
}
|
}
|
||||||
// Builtin cache exists? Use it.
|
// Builtin cache exists? Use it.
|
||||||
builtin_vh := '$v_modules_path${os.path_separator}vlib${os.path_separator}builtin.vh'
|
builtin_vh := '$v_modules_path${os.path_separator}vlib${os.path_separator}builtin.vh'
|
||||||
|
@ -2424,13 +2424,17 @@ fn (p mut Parser) array_init() string {
|
|||||||
}
|
}
|
||||||
p.check(.rsbr)
|
p.check(.rsbr)
|
||||||
// type after `]`? (e.g. "[]string")
|
// type after `]`? (e.g. "[]string")
|
||||||
if p.tok != .name && i == 0 && !p.expected_type.starts_with('array_') {
|
exp_array := p.expected_type.starts_with('array_')
|
||||||
|
if p.tok != .name && i == 0 && !exp_array {
|
||||||
p.error('specify array type: `[]typ` instead of `[]`')
|
p.error('specify array type: `[]typ` instead of `[]`')
|
||||||
}
|
}
|
||||||
if p.tok == .name && i == 0 {
|
if p.tok == .name && i == 0 {
|
||||||
// vals.len == 0 {
|
// vals.len == 0 {
|
||||||
|
if exp_array {
|
||||||
|
p.error('use `foo = []` instead of `foo = []Type`')
|
||||||
|
}
|
||||||
typ = p.get_type()
|
typ = p.get_type()
|
||||||
} else if p.expected_type.starts_with('array_') {
|
} else if exp_array {
|
||||||
// allow `known_array = []`
|
// allow `known_array = []`
|
||||||
typ = p.expected_type[6..]
|
typ = p.expected_type[6..]
|
||||||
}
|
}
|
||||||
|
@ -38,8 +38,9 @@ fn (p mut Parser) select_query(fn_ph int) string {
|
|||||||
// because we can have many queries in the _same_ scope.
|
// because we can have many queries in the _same_ scope.
|
||||||
qprefix := p.get_tmp().replace('tmp','sql') + '_'
|
qprefix := p.get_tmp().replace('tmp','sql') + '_'
|
||||||
p.sql_i = 0
|
p.sql_i = 0
|
||||||
p.sql_params = []string
|
p.sql_params = []
|
||||||
p.sql_types = []string
|
if false {}
|
||||||
|
p.sql_types = []
|
||||||
|
|
||||||
mut q := 'select '
|
mut q := 'select '
|
||||||
p.check(.key_select)
|
p.check(.key_select)
|
||||||
|
@ -852,7 +852,7 @@ pub fn realpath(fpath string) string {
|
|||||||
// walk_ext returns a recursive list of all file paths ending with `ext`.
|
// walk_ext returns a recursive list of all file paths ending with `ext`.
|
||||||
pub fn walk_ext(path, ext string) []string {
|
pub fn walk_ext(path, ext string) []string {
|
||||||
if !os.is_dir(path) {
|
if !os.is_dir(path) {
|
||||||
return []string
|
return []
|
||||||
}
|
}
|
||||||
mut files := os.ls(path) or { panic(err) }
|
mut files := os.ls(path) or { panic(err) }
|
||||||
mut res := []string
|
mut res := []string
|
||||||
|
Loading…
Reference in New Issue
Block a user