mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ci: fix vlib/v/tests/str_gen_test.v (all of v test-self
is ok now)
This commit is contained in:
parent
abbb08b28c
commit
5bc29492fd
@ -150,6 +150,8 @@ pub fn (t Type) nr_muls() int {
|
||||
// return true if `t` is a pointer (nr_muls>0)
|
||||
[inline]
|
||||
pub fn (t Type) is_ptr() bool {
|
||||
// any normal pointer, i.e. &Type, &&Type etc;
|
||||
// NB: voidptr, charptr and byteptr are NOT included!
|
||||
return (int(t) >> 16) & 0xff > 0
|
||||
}
|
||||
|
||||
@ -270,9 +272,9 @@ pub fn new_type_ptr(idx int, nr_muls int) Type {
|
||||
return (nr_muls << 16) | u16(idx)
|
||||
}
|
||||
|
||||
// built in pointers (voidptr, byteptr, charptr)
|
||||
[inline]
|
||||
pub fn (typ Type) is_pointer() bool {
|
||||
// builtin pointer types (voidptr, byteptr, charptr)
|
||||
return typ.idx() in ast.pointer_type_idxs
|
||||
}
|
||||
|
||||
@ -286,6 +288,26 @@ pub fn (typ Type) is_int() bool {
|
||||
return typ.clear_flags() in ast.integer_type_idxs
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (typ Type) is_int_valptr() bool {
|
||||
return typ.idx() in ast.integer_type_idxs
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (typ Type) is_float_valptr() bool {
|
||||
return typ.idx() in ast.float_type_idxs
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (typ Type) is_pure_int() bool {
|
||||
return int(typ) in ast.integer_type_idxs
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (typ Type) is_pure_float() bool {
|
||||
return int(typ) in ast.float_type_idxs
|
||||
}
|
||||
|
||||
[inline]
|
||||
pub fn (typ Type) is_signed() bool {
|
||||
return typ.idx() in ast.signed_integer_type_idxs
|
||||
|
@ -42,7 +42,7 @@ fn (mut g Gen) gen_str_default(sym ast.TypeSymbol, styp string, str_fn_name stri
|
||||
|
||||
fn (g &Gen) type_to_fmt(typ ast.Type) string {
|
||||
sym := g.table.get_type_symbol(typ)
|
||||
if typ.is_ptr() && (typ.is_int() || typ.is_float()) {
|
||||
if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) {
|
||||
return '%.*s\\000'
|
||||
} else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_,
|
||||
.sum_type, .function, .alias] {
|
||||
@ -512,7 +512,8 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, styp string, str_fn_name stri
|
||||
g.auto_str_funcs.write_string('isnil(it.${c_name(field.name)})')
|
||||
g.auto_str_funcs.write_string(' ? _SLIT("nil") : ')
|
||||
// struct, floats and ints have a special case through the _str function
|
||||
if sym.kind != .struct_ && !field.typ.is_int() && !field.typ.is_float() {
|
||||
if sym.kind != .struct_ && !field.typ.is_int_valptr()
|
||||
&& !field.typ.is_float_valptr() {
|
||||
g.auto_str_funcs.write_string('*')
|
||||
}
|
||||
}
|
||||
@ -558,8 +559,8 @@ fn struct_auto_str_func(sym &ast.TypeSymbol, field_type ast.Type, fn_name string
|
||||
mut method_str := 'it.${c_name(field_name)}'
|
||||
if sym.kind == .bool {
|
||||
method_str += ' ? _SLIT("true") : _SLIT("false")'
|
||||
} else if (field_type.is_int() || field_type.is_float()) && field_type.is_ptr()
|
||||
&& !expects_ptr {
|
||||
} else if (field_type.is_int_valptr() || field_type.is_float_valptr())
|
||||
&& field_type.is_ptr() && !expects_ptr {
|
||||
// ptr int can be "nil", so this needs to be castet to a string
|
||||
fmt := if sym.kind in [.f32, .f64] {
|
||||
'%g\\000'
|
||||
|
Loading…
Reference in New Issue
Block a user