vfmt: support `x chan Name` in fn args

pull/6243/head
Delyan Angelov 2020-08-28 01:54:16 +03:00
parent 8f5ca29fcd
commit 0975f3bd4c
3 changed files with 30 additions and 6 deletions

View File

@ -725,12 +725,20 @@ pub fn (mut f Fmt) prefix_expr_cast_expr(fexpr ast.Expr) {
pub fn (f &Fmt) type_to_str(t table.Type) string { pub fn (f &Fmt) type_to_str(t table.Type) string {
mut res := f.table.type_to_str(t) mut res := f.table.type_to_str(t)
map_prefix := 'map[string]'
cur_mod := f.cur_mod + '.' cur_mod := f.cur_mod + '.'
//
map_prefix := 'map[string]'
has_map_prefix := res.starts_with(map_prefix) has_map_prefix := res.starts_with(map_prefix)
if has_map_prefix { if has_map_prefix {
res = res.replace(map_prefix, '') res = res.replace(map_prefix, '')
} }
//
chan_prefix := 'chan '
has_chan_prefix := res.starts_with(chan_prefix)
if has_chan_prefix {
res = res.replace(chan_prefix, '')
}
//
no_symbols := res.trim_left('&[]') no_symbols := res.trim_left('&[]')
should_shorten := no_symbols.starts_with(cur_mod) should_shorten := no_symbols.starts_with(cur_mod)
// //
@ -752,6 +760,9 @@ pub fn (f &Fmt) type_to_str(t table.Type) string {
if should_shorten { if should_shorten {
res = res.replace_once(cur_mod, '') res = res.replace_once(cur_mod, '')
} }
if has_chan_prefix {
res = chan_prefix + res
}
if has_map_prefix { if has_map_prefix {
res = map_prefix + res res = map_prefix + res
} }

View File

@ -4,6 +4,18 @@ struct FSMEvent {
x int x int
} }
fn abc(n FSMEvent) {
}
fn (e FSMEvent) abc(n FSMEvent) {
}
fn (e FSMEvent) x(ch chan FSMEvent) {
}
fn produce_events(ch chan FSMEvent) {
}
fn main() { fn main() {
ch_fsm_events := chan FSMEvent{cap: 1000} ch_fsm_events := chan FSMEvent{cap: 1000}
eprintln('ch_fsm_events.len: $ch_fsm_events.len') eprintln('ch_fsm_events.len: $ch_fsm_events.len')

View File

@ -810,6 +810,9 @@ pub fn (table &Table) type_to_str(t Type) string {
res = res.replace('map_string_', 'map[string]') res = res.replace('map_string_', 'map[string]')
map_start = 'map[string]' map_start = 'map[string]'
} }
if sym.kind == .chan || 'chan_' in res {
res = res.replace('chan_', '')
}
// mod.submod.submod2.Type => submod2.Type // mod.submod.submod2.Type => submod2.Type
if res.contains('.') { if res.contains('.') {
vals := res.split('.') vals := res.split('.')
@ -826,6 +829,9 @@ pub fn (table &Table) type_to_str(t Type) string {
if sym.kind == .map && !res.starts_with('map') { if sym.kind == .map && !res.starts_with('map') {
res = map_start + res res = map_start + res
} }
if sym.kind == .chan && !res.starts_with('chan') {
res = 'chan ' + res
}
} }
nr_muls := t.nr_muls() nr_muls := t.nr_muls()
if nr_muls > 0 { if nr_muls > 0 {
@ -838,11 +844,6 @@ pub fn (table &Table) type_to_str(t Type) string {
res = '?' + res res = '?' + res
} }
} }
/*
if res.starts_with(cur_mod +'.') {
res = res[cur_mod.len+1.. ]
}
*/
return res return res
} }