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

cgen: prefix with v_ keyword C fn args too

This commit is contained in:
Delyan Angelov 2020-05-04 19:54:36 +03:00
parent c9798d3918
commit 6e1825b417

View File

@ -200,6 +200,7 @@ fn (mut g Gen) fn_args(args []table.Arg, is_variadic bool) ([]string, []string)
mut fargtypes := []string{} mut fargtypes := []string{}
no_names := args.len > 0 && args[0].name == 'arg_1' no_names := args.len > 0 && args[0].name == 'arg_1'
for i, arg in args { for i, arg in args {
caname := c_name(arg.name)
arg_type_sym := g.table.get_type_symbol(arg.typ) arg_type_sym := g.table.get_type_symbol(arg.typ)
mut arg_type_name := g.typ(arg.typ) // arg_type_sym.name.replace('.', '__') mut arg_type_name := g.typ(arg.typ) // arg_type_sym.name.replace('.', '__')
is_varg := i == args.len - 1 && is_variadic is_varg := i == args.len - 1 && is_variadic
@ -214,13 +215,13 @@ fn (mut g Gen) fn_args(args []table.Arg, is_variadic bool) ([]string, []string)
info := arg_type_sym.info as table.FnType info := arg_type_sym.info as table.FnType
func := info.func func := info.func
if !info.is_anon { if !info.is_anon {
g.write(arg_type_name + ' ' + arg.name) g.write(arg_type_name + ' ' + caname)
g.definitions.write(arg_type_name + ' ' + arg.name) g.definitions.write(arg_type_name + ' ' + caname)
fargs << arg.name fargs << caname
fargtypes << arg_type_name fargtypes << arg_type_name
} else { } else {
g.write('${g.typ(func.return_type)} (*$arg.name)(') g.write('${g.typ(func.return_type)} (*$caname)(')
g.definitions.write('${g.typ(func.return_type)} (*$arg.name)(') g.definitions.write('${g.typ(func.return_type)} (*$caname)(')
g.fn_args(func.args, func.is_variadic) g.fn_args(func.args, func.is_variadic)
g.write(')') g.write(')')
g.definitions.write(')') g.definitions.write(')')
@ -232,17 +233,17 @@ fn (mut g Gen) fn_args(args []table.Arg, is_variadic bool) ([]string, []string)
fargtypes << arg_type_name fargtypes << arg_type_name
} else { } else {
mut nr_muls := arg.typ.nr_muls() mut nr_muls := arg.typ.nr_muls()
s := arg_type_name + ' ' + arg.name s := arg_type_name + ' ' + caname
if arg.is_mut { if arg.is_mut {
// mut arg needs one * // mut arg needs one *
nr_muls = 1 nr_muls = 1
} }
// if nr_muls > 0 && !is_varg { // if nr_muls > 0 && !is_varg {
// s = arg_type_name + strings.repeat(`*`, nr_muls) + ' ' + arg.name // s = arg_type_name + strings.repeat(`*`, nr_muls) + ' ' + caname
// } // }
g.write(s) g.write(s)
g.definitions.write(s) g.definitions.write(s)
fargs << arg.name fargs << caname
fargtypes << arg_type_name fargtypes << arg_type_name
} }
if i < args.len - 1 { if i < args.len - 1 {