1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vfmt: fn args fixes

This commit is contained in:
Alexander Medvednikov 2019-12-18 10:17:07 +03:00
parent 569b32bd1e
commit 67bdc2c7a9
4 changed files with 26 additions and 24 deletions

View File

@ -142,7 +142,7 @@ fn (p mut Parser) mark_var_changed(v Var) {
}
fn (p mut Parser) mark_arg_moved(v Var) {
for i,arg in p.cur_fn.args {
for i, arg in p.cur_fn.args {
if arg.name == v.name {
// println('setting f $p.cur_fn.name arg $arg.name to is_mut')
p.cur_fn.args[i].is_moved = true
@ -677,7 +677,7 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type
// wrapper(arg_struct * arg) { fn("arg->a, arg->b"); }
mut str_args := ''
mut did_gen_something := false
for i,arg in f.args {
for i, arg in f.args {
arg_struct += '$arg.typ $arg.name ;' // Add another field (arg) to the tmp struct definition
str_args += 'arg $dot_ptr $arg.name'
if i == 0 && f.is_method {
@ -801,7 +801,7 @@ fn (p mut Parser) fn_call(f mut Fn, method_ph int, receiver_var, receiver_type s
if t.cat == .interface_ {
// Find the index of the method
mut idx := 0
for i,method in t.methods {
for i, method in t.methods {
if method.name == f.name {
idx = i
}
@ -1008,7 +1008,7 @@ fn (p mut Parser) fn_call_args(f mut Fn) {
p.cgen.resetln(p.cgen.cur_line.replace('v_panic (', 'panic_debug ($p.scanner.line_nr, tos3("$file_path"), tos3("$mod_name"), tos2((byte *)"$fn_name"), '))
}
mut saved_args := []string
for i,arg in f.args {
for i, arg in f.args {
// Receiver is the first arg
// Skip the receiver, because it was already generated in the expression
if i == 0 && f.is_method {
@ -1374,7 +1374,7 @@ fn replace_generic_type(gen_type string, ti &TypeInst) string {
// replace return type & param types for a given generic function using TypeInst
fn replace_generic_type_params(f mut Fn, ti &TypeInst) {
mut args := []Var
for i,_ in f.args {
for i, _ in f.args {
mut arg := f.args[i]
arg.typ = replace_generic_type(arg.typ, ti)
args << arg
@ -1474,7 +1474,7 @@ fn (p mut Parser) register_multi_return_stuct(types []string) string {
name: typ
mod: p.mod
})
for i,t in typ.replace('_V_MulRet_', '').replace('_PTR_', '*').split('_V_') {
for i, t in typ.replace('_V_MulRet_', '').replace('_PTR_', '*').split('_V_') {
p.table.add_field(typ, 'var_$i', t, false, '', .public)
}
p.cgen.typedefs << 'typedef struct $typ $typ;'
@ -1543,7 +1543,7 @@ fn (p mut Parser) dispatch_generic_fn_instance(f mut Fn, ti &TypeInst) {
fn (f &Fn) typ_str() string {
mut sb := strings.new_builder(50)
sb.write('fn (')
for i,arg in f.args {
for i, arg in f.args {
sb.write(arg.typ)
if i < f.args.len - 1 {
sb.write(',')
@ -1559,7 +1559,7 @@ fn (f &Fn) typ_str() string {
// f.args => "int a, string b"
fn (f &Fn) str_args(table &Table) string {
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
// to all methods:
// fn handle(r Runner) { =>
@ -1640,7 +1640,7 @@ pub fn (f &Fn) v_fn_name() string {
pub fn (f &Fn) str_for_error() string {
// Build the args for the error
mut s := ''
for i,a in f.args {
for i, a in f.args {
if i == 0 {
if f.is_method {
s += a.typ + '.' + f.name + '('

View File

@ -61,6 +61,7 @@ fn (p mut Parser) for_st() {
*/
i := p.check_name()
p.check(.comma)
p.fspace()
val := p.check_name()
if i == '_' && val == '_' {
p.error('no new variables on the left side of `in`')

View File

@ -27,6 +27,7 @@ fn (p mut Parser) get_type2() Type{
break
}
p.check(.comma)
p.fspace()
}
p.check(.rpar)
// p.inside_tuple = false

View File

@ -323,7 +323,7 @@ pub fn (p &Parser) save_state() ParserState {
}
}
pub fn (p mut Parser) restore_state(state ParserState,scanner bool,cgen bool) {
pub fn (p mut Parser) restore_state(state ParserState, scanner bool, cgen bool) {
if scanner {
p.scanner.line_nr = state.scanner_line_nr
p.scanner.text = state.scanner_text
@ -345,7 +345,7 @@ pub fn (p mut Parser) restore_state(state ParserState,scanner bool,cgen bool) {
p.lit = state.lit
}
fn (p mut Parser) clear_state(scanner bool,cgen bool) {
fn (p mut Parser) clear_state(scanner bool, cgen bool) {
if scanner {
p.scanner.line_nr = 0
p.scanner.text = ''
@ -372,7 +372,7 @@ pub fn (p mut Parser) add_text(text string) {
p.scan_tokens()
}
fn (p mut Parser) statements_from_text(text string,rcbr bool) {
fn (p mut Parser) statements_from_text(text string, rcbr bool) {
saved_state := p.save_state()
p.clear_state(true, false)
p.add_text(text)
@ -711,7 +711,7 @@ fn (p mut Parser) const_decl() {
// Check to see if this constant exists, and is void. If so, try and get the type again:
if my_const:=p.v.table.find_const(name){
if my_const.typ == 'void' {
for i,v in p.v.table.consts {
for i, v in p.v.table.consts {
if v.name == name {
p.v.table.consts[i].typ = typ
break
@ -967,7 +967,7 @@ fn (p mut Parser) get_type() string {
// Register anon fn type
fn_typ := Type{
name: f.typ_str() // 'fn (int, int) string'
mod: p.mod
func: f
}
@ -1413,7 +1413,7 @@ fn (p mut Parser) statement(add_semi bool) string {
}
// is_map: are we in map assignment? (m[key] = val) if yes, dont generate '='
// this can be `user = ...` or `user.field = ...`, in both cases `v` is `user`
fn (p mut Parser) assign_statement(v Var,ph int,is_map bool) {
fn (p mut Parser) assign_statement(v Var, ph int, is_map bool) {
errtok := p.cur_tok_index()
is_vid := p.fileis('vid') // TODO remove
tok := p.tok
@ -1593,7 +1593,7 @@ fn (p mut Parser) var_decl() {
mr_fn := p.cgen.cur_line.find_between('=', '(').trim_space()
p.error_with_token_index('assignment mismatch: ${var_names.len} variables but `$mr_fn` returns $var_types.len values', var_token_idxs.last())
}
for i,var_name in var_names {
for i, var_name in var_names {
var_token_idx := var_token_idxs[i]
var_is_mut := var_mut[i]
var_type := var_types[i]
@ -1669,7 +1669,7 @@ fn (p mut Parser) var_decl() {
p.is_empty_c_struct_init = false
}
fn (p mut Parser) get_struct_type(name_ string,is_c bool,is_ptr bool) string {
fn (p mut Parser) get_struct_type(name_ string, is_c bool, is_ptr bool) string {
mut name := name_
if is_ptr {
name += '*' // `&User{}` => type `User*`
@ -1681,7 +1681,7 @@ fn (p mut Parser) get_struct_type(name_ string,is_c bool,is_ptr bool) string {
return p.struct_init(name)
}
fn (p mut Parser) get_var_type(name string,is_ptr bool,deref_nr int) string {
fn (p mut Parser) get_var_type(name string, is_ptr bool, deref_nr int) string {
v := p.find_var_check_new_var(name) or {
return ''
}
@ -1732,7 +1732,7 @@ fn (p mut Parser) get_var_type(name string,is_ptr bool,deref_nr int) string {
return typ
}
fn (p mut Parser) get_const_type(name string,is_ptr bool) string {
fn (p mut Parser) get_const_type(name string, is_ptr bool) string {
c := p.table.find_const(name) or {
return ''
}
@ -1775,7 +1775,7 @@ fn (p mut Parser) get_c_func_type(name string) string {
return cfn.typ
}
fn (p mut Parser) undefined_error(name string,orig_name string) {
fn (p mut Parser) undefined_error(name string, orig_name string) {
name_dotted := mod_gen_name_rev(name.replace('__', '.'))
// check for misspelled function / variable / module / type
suggested := p.identify_typo(name)
@ -1887,7 +1887,7 @@ fn (p mut Parser) var_expr(v Var) string {
// user.name => `str_typ` is `User`
// user.company.name => `str_typ` is `Company`
fn (p mut Parser) dot(str_typ_ string,method_ph int) string {
fn (p mut Parser) dot(str_typ_ string, method_ph int) string {
// if p.fileis('orm_test') {
// println('ORM dot $str_typ')
// }
@ -2067,7 +2067,7 @@ fn get_index_type(typ string) IndexType {
return .noindex
}
fn (p mut Parser) index_expr(typ_ string,fn_ph int) string {
fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
mut typ := typ_
// a[0]
v := p.expr_var
@ -2685,7 +2685,7 @@ fn (p mut Parser) return_st() {
expr_type = types.join(',')
cur_fn_typ_chk = cur_fn_typ_chk.replace('_V_MulRet_', '').replace('_PTR_', '*').replace('_V_', ',')
mut ret_fields := ''
for ret_val_idx,ret_val in mr_values {
for ret_val_idx, ret_val in mr_values {
if ret_val_idx > 0 {
ret_fields += ','
}
@ -2937,7 +2937,7 @@ fn (p mut Parser) check_unused_imports() {
return
}
mut output := ''
for alias,mod in p.import_table.imports {
for alias, mod in p.import_table.imports {
if !p.import_table.is_used_import(alias) {
mod_alias := if alias == mod {alias}else {'$alias ($mod)'}
output += '\n * $mod_alias'