vfmt: keep `vproto.Name`, when current module is `proto`
							parent
							
								
									3c3a91697e
								
							
						
					
					
						commit
						7248d8422e
					
				|  | @ -46,7 +46,7 @@ pub struct string { | ||||||
| pub: | pub: | ||||||
| 	str byteptr // points to a C style 0 terminated string of bytes.
 | 	str byteptr // points to a C style 0 terminated string of bytes.
 | ||||||
| 	len int // the length of the .str field, excluding the ending 0 byte. It is always equal to strlen(.str).
 | 	len int // the length of the .str field, excluding the ending 0 byte. It is always equal to strlen(.str).
 | ||||||
| mut:     | mut: | ||||||
| 	is_lit int | 	is_lit int | ||||||
| } | } | ||||||
| // mut:
 | // mut:
 | ||||||
|  | @ -157,7 +157,7 @@ pub fn cstring_to_vstring(cstr byteptr) string { | ||||||
| 
 | 
 | ||||||
| pub fn (s string) replace_once(rep, with string) string { | pub fn (s string) replace_once(rep, with string) string { | ||||||
| 	index := s.index(rep) or { | 	index := s.index(rep) or { | ||||||
| 		return s | 		return s.clone() | ||||||
| 	} | 	} | ||||||
| 	return s.substr(0, index) + with + s.substr(index + rep.len, s.len) | 	return s.substr(0, index) + with + s.substr(index + rep.len, s.len) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -676,6 +676,15 @@ 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 + '.' | ||||||
|  | 	has_map_prefix := res.starts_with(map_prefix) | ||||||
|  | 	if has_map_prefix { | ||||||
|  | 		res = res.replace(map_prefix, '') | ||||||
|  | 	} | ||||||
|  | 	no_symbols := res.trim_left('&[]') | ||||||
|  | 	should_shorten := no_symbols.starts_with(cur_mod) | ||||||
|  | 	//
 | ||||||
| 	for res.ends_with('_ptr') { | 	for res.ends_with('_ptr') { | ||||||
| 		// type_ptr => &type
 | 		// type_ptr => &type
 | ||||||
| 		res = res[0..res.len - 4] | 		res = res[0..res.len - 4] | ||||||
|  | @ -686,12 +695,18 @@ pub fn (f &Fmt) type_to_str(t table.Type) string { | ||||||
| 		prefix := '[]fixed_' | 		prefix := '[]fixed_' | ||||||
| 		res = res[prefix.len..] | 		res = res[prefix.len..] | ||||||
| 		last_underscore_idx := res.last_index('_') or { | 		last_underscore_idx := res.last_index('_') or { | ||||||
| 			return '[]' + res.replace(f.cur_mod + '.', '') | 			return '[]' + if should_shorten { res.replace_once(cur_mod, '') } else { res } | ||||||
| 		} | 		} | ||||||
| 		limit := res[last_underscore_idx + 1..] | 		limit := res[last_underscore_idx + 1..] | ||||||
| 		res = '[' + limit + ']' + res[..last_underscore_idx] | 		res = '[' + limit + ']' + res[..last_underscore_idx] | ||||||
| 	} | 	} | ||||||
| 	return res.replace(f.cur_mod + '.', '') | 	if should_shorten { | ||||||
|  | 		res = res.replace_once(cur_mod, '') | ||||||
|  | 	} | ||||||
|  | 	if has_map_prefix { | ||||||
|  | 		res = map_prefix + res | ||||||
|  | 	} | ||||||
|  | 	return res | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn (mut f Fmt) expr(node ast.Expr) { | pub fn (mut f Fmt) expr(node ast.Expr) { | ||||||
|  |  | ||||||
|  | @ -0,0 +1,23 @@ | ||||||
|  | module proto | ||||||
|  | 
 | ||||||
|  | import vproto | ||||||
|  | 
 | ||||||
|  | struct Xyz { | ||||||
|  | 	x int | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | struct Abcde { | ||||||
|  | 	f1 vproto.Xyz | ||||||
|  | 	f2 &vproto.Xyz | ||||||
|  | 	f3 []vproto.Xyz | ||||||
|  | 	f4 []&vproto.Xyz | ||||||
|  | 	f5 map[string]vproto.Xyz | ||||||
|  | 	f6 map[string]&vproto.Xyz | ||||||
|  | 	//
 | ||||||
|  | 	p1 Xyz | ||||||
|  | 	p2 &Xyz | ||||||
|  | 	p3 []Xyz | ||||||
|  | 	p4 []&Xyz | ||||||
|  | 	p5 map[string]Xyz | ||||||
|  | 	p6 map[string]&Xyz | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue