Skip to content

Commit

Permalink
ast: clean up is_float()/is_float_valptr() (#18448)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 committed Jun 14, 2023
1 parent bbd1027 commit 27b3303
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
8 changes: 4 additions & 4 deletions vlib/v/ast/types.v
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions vlib/v/gen/c/auto_str_methods.v
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -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[]){
Expand Down
5 changes: 2 additions & 3 deletions vlib/v/gen/js/auto_str_methods.v
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down Expand Up @@ -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[]){
Expand Down

0 comments on commit 27b3303

Please sign in to comment.