parser: clean up all []

pull/2760/head
Alexander Medvednikov 2019-11-14 09:18:07 +03:00
parent 5df5f97daf
commit 4a833d8151
6 changed files with 21 additions and 14 deletions

View File

@ -1117,7 +1117,7 @@ pub fn (s string) hash() int {
pub fn (s string) bytes() []byte {
if s.len == 0 {
return []byte
return []
}
mut buf := [byte(0)].repeat(s.len)
C.memcpy(buf.data, s.str, s.len)

View File

@ -171,7 +171,7 @@ fn (p mut Parser) clear_vars() {
if p.pref.autofree {
//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.typ = _f.typ
f.is_generic = false
f.type_inst = []TypeInst
f.type_inst = []
if false {}
f.dispatch_of = ti
// println('using existing inst $f.name(${f.str_args(p.table)}) $f.typ')
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)
f.is_generic = false // the instance is a normal function
f.type_inst = []TypeInst
f.type_inst = []
if false {}
f.scope_level = 0
f.dispatch_of = ti
// TODO this is done to prevent a crash as a result of this not being
// properly initialised. This is a bug somewhere futher upstream
f.defer_text = []string
f.defer_text = []
if false {}
old_args := f.args
new_types := p.replace_type_params(f, ti)
f.args = []Var
f.args = []
for i in 0..new_types.len-1 {
mut v := old_args[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.cgen.tmp_line = ''
p.cgen.cur_line = ''
p.cgen.lines = []string
p.cgen.lines = []
unsafe { // TODO
p.cur_fn = *f
}

View File

@ -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() {
mut builtin_files := v.get_builtin_files()
if v.pref.is_bare {
builtin_files = []string
builtin_files = []
}
// Builtin cache exists? Use it.
builtin_vh := '$v_modules_path${os.path_separator}vlib${os.path_separator}builtin.vh'

View File

@ -2424,13 +2424,17 @@ fn (p mut Parser) array_init() string {
}
p.check(.rsbr)
// 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 `[]`')
}
if p.tok == .name && i == 0 {
// vals.len == 0 {
if exp_array {
p.error('use `foo = []` instead of `foo = []Type`')
}
typ = p.get_type()
} else if p.expected_type.starts_with('array_') {
} else if exp_array {
// allow `known_array = []`
typ = p.expected_type[6..]
}

View File

@ -38,8 +38,9 @@ fn (p mut Parser) select_query(fn_ph int) string {
// because we can have many queries in the _same_ scope.
qprefix := p.get_tmp().replace('tmp','sql') + '_'
p.sql_i = 0
p.sql_params = []string
p.sql_types = []string
p.sql_params = []
if false {}
p.sql_types = []
mut q := 'select '
p.check(.key_select)

View File

@ -852,7 +852,7 @@ pub fn realpath(fpath string) string {
// walk_ext returns a recursive list of all file paths ending with `ext`.
pub fn walk_ext(path, ext string) []string {
if !os.is_dir(path) {
return []string
return []
}
mut files := os.ls(path) or { panic(err) }
mut res := []string