From 27b3303eebd673c72c8a930a1470e10dbe6074dd Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 15 Jun 2023 07:06:08 +0800 Subject: [PATCH] ast: clean up is_float()/is_float_valptr() (#18448) --- vlib/v/ast/types.v | 8 ++++---- vlib/v/gen/c/auto_str_methods.v | 5 ++--- vlib/v/gen/js/auto_str_methods.v | 5 ++--- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/vlib/v/ast/types.v b/vlib/v/ast/types.v index e8a79dab98..7e6921bbb1 100644 --- a/vlib/v/ast/types.v +++ b/vlib/v/ast/types.v @@ -489,22 +489,22 @@ pub fn (typ Type) is_real_pointer() bool { [inline] 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] 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] 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] 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] diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index 60761ac873..4c176d9dba 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -821,7 +821,7 @@ fn (g &Gen) type_to_fmt(typ ast.Type) StrIntpType { return .si_p } 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 } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .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 { return '${method_str} ? _SLIT("true") : _SLIT("false")', false - } else if (field_type.is_int_valptr() || field_type.is_float_valptr()) - && field_type.is_ptr() && !expects_ptr { + } else if (field_type.is_int_valptr() || field_type.is_float_valptr()) && !expects_ptr { // ptr int can be "nil", so this needs to be casted to a string if sym.kind == .f32 { return 'str_intp(1, _MOV((StrIntpData[]){ diff --git a/vlib/v/gen/js/auto_str_methods.v b/vlib/v/gen/js/auto_str_methods.v index 7948f030a9..5eb3ca4fee 100644 --- a/vlib/v/gen/js/auto_str_methods.v +++ b/vlib/v/gen/js/auto_str_methods.v @@ -659,7 +659,7 @@ fn (g &JsGen) type_to_fmt(typ ast.Type) StrIntpType { return .si_s } 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 } else if sym.kind in [.struct_, .array, .array_fixed, .map, .bool, .enum_, .interface_, .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)}' if sym.kind == .bool { method_str += ' ? new string("true") : new string("false")' - } else if (field_type.is_int_valptr() || field_type.is_float_valptr()) - && field_type.is_ptr() && !expects_ptr { + } else if (field_type.is_int_valptr() || field_type.is_float_valptr()) && !expects_ptr { // ptr int can be "nil", so this needs to be casted to a string if sym.kind == .f32 { return 'str_intp(1, _MOV((StrIntpData[]){