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

ast: clean up is_float()/is_float_valptr() (#18448)

This commit is contained in:
yuyi 2023-06-15 07:06:08 +08:00 committed by GitHub
parent bbd1027a04
commit 27b3303eeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 10 deletions

View File

@ -489,22 +489,22 @@ pub fn (typ Type) is_real_pointer() bool {
[inline] [inline]
pub fn (typ Type) is_float() bool { pub fn (typ Type) is_float() bool {
return typ.clear_flags() in ast.float_type_idxs return !typ.is_ptr() && typ.idx() in ast.float_type_idxs
} }
[inline] [inline]
pub fn (typ Type) is_int() bool { pub fn (typ Type) is_int() bool {
return typ.clear_flags() in ast.integer_type_idxs return !typ.is_ptr() && typ.idx() in ast.integer_type_idxs
} }
[inline] [inline]
pub fn (typ Type) is_int_valptr() bool { pub fn (typ Type) is_int_valptr() bool {
return typ.idx() in ast.integer_type_idxs return typ.is_ptr() && typ.idx() in ast.integer_type_idxs
} }
[inline] [inline]
pub fn (typ Type) is_float_valptr() bool { pub fn (typ Type) is_float_valptr() bool {
return typ.idx() in ast.float_type_idxs return typ.is_ptr() && typ.idx() in ast.float_type_idxs
} }
[inline] [inline]

View File

@ -821,7 +821,7 @@ fn (g &Gen) type_to_fmt(typ ast.Type) StrIntpType {
return .si_p return .si_p
} }
sym := g.table.sym(typ) sym := g.table.sym(typ)
if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) { if typ.is_int_valptr() || typ.is_float_valptr() {
return .si_s return .si_s
} else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_,
.sum_type, .function, .alias, .chan] { .sum_type, .function, .alias, .chan] {
@ -1069,8 +1069,7 @@ fn struct_auto_str_func(sym &ast.TypeSymbol, lang ast.Language, _field_type ast.
} }
if sym.kind == .bool { if sym.kind == .bool {
return '${method_str} ? _SLIT("true") : _SLIT("false")', false return '${method_str} ? _SLIT("true") : _SLIT("false")', false
} else if (field_type.is_int_valptr() || field_type.is_float_valptr()) } else if (field_type.is_int_valptr() || field_type.is_float_valptr()) && !expects_ptr {
&& field_type.is_ptr() && !expects_ptr {
// ptr int can be "nil", so this needs to be casted to a string // ptr int can be "nil", so this needs to be casted to a string
if sym.kind == .f32 { if sym.kind == .f32 {
return 'str_intp(1, _MOV((StrIntpData[]){ return 'str_intp(1, _MOV((StrIntpData[]){

View File

@ -659,7 +659,7 @@ fn (g &JsGen) type_to_fmt(typ ast.Type) StrIntpType {
return .si_s return .si_s
} }
sym := g.table.sym(typ) sym := g.table.sym(typ)
if typ.is_ptr() && (typ.is_int_valptr() || typ.is_float_valptr()) { if typ.is_int_valptr() || typ.is_float_valptr() {
return .si_s return .si_s
} else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_,
.sum_type, .function, .alias, .chan] { .sum_type, .function, .alias, .chan] {
@ -812,8 +812,7 @@ fn struct_auto_str_func(mut g JsGen, sym &ast.TypeSymbol, field_type ast.Type, f
mut method_str := 'it.${g.js_name(field_name)}' mut method_str := 'it.${g.js_name(field_name)}'
if sym.kind == .bool { if sym.kind == .bool {
method_str += ' ? new string("true") : new string("false")' method_str += ' ? new string("true") : new string("false")'
} else if (field_type.is_int_valptr() || field_type.is_float_valptr()) } else if (field_type.is_int_valptr() || field_type.is_float_valptr()) && !expects_ptr {
&& field_type.is_ptr() && !expects_ptr {
// ptr int can be "nil", so this needs to be casted to a string // ptr int can be "nil", so this needs to be casted to a string
if sym.kind == .f32 { if sym.kind == .f32 {
return 'str_intp(1, _MOV((StrIntpData[]){ return 'str_intp(1, _MOV((StrIntpData[]){