Skip to content

Commit acfe785

Browse files
authored
all: clean up with is_any_kind_of_pointer() (#18467)
1 parent dbd2517 commit acfe785

File tree

14 files changed

+30
-32
lines changed

14 files changed

+30
-32
lines changed

vlib/v/ast/ast.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,8 +2400,7 @@ pub fn (expr Expr) is_literal() bool {
24002400
return expr.expr.is_literal()
24012401
}
24022402
CastExpr {
2403-
return !expr.has_arg && expr.expr.is_literal()
2404-
&& (expr.typ.is_ptr() || expr.typ.is_pointer()
2403+
return !expr.has_arg && expr.expr.is_literal() && (expr.typ.is_any_kind_of_pointer()
24052404
|| expr.typ in [i8_type, i16_type, int_type, i64_type, u8_type, u16_type, u32_type, u64_type, f32_type, f64_type, char_type, bool_type, rune_type])
24062405
}
24072406
SizeOf, IsRefType {

vlib/v/checker/assign.v

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -507,13 +507,12 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
507507
c.error('cannot copy map: call `move` or `clone` method (or use a reference)',
508508
right.pos())
509509
}
510-
left_is_ptr := left_type.is_ptr() || left_sym.is_pointer()
511-
if left_is_ptr && !left.is_auto_deref_var() {
510+
if left_type.is_any_kind_of_pointer() && !left.is_auto_deref_var() {
512511
if !c.inside_unsafe && node.op !in [.assign, .decl_assign] {
513512
// ptr op=
514513
c.warn('pointer arithmetic is only allowed in `unsafe` blocks', node.pos)
515514
}
516-
right_is_ptr := right_type.is_ptr() || right_sym.is_pointer()
515+
right_is_ptr := right_type.is_any_kind_of_pointer()
517516
if !right_is_ptr && node.op == .assign && right_type_unwrapped.is_number() {
518517
c.error('cannot assign to `${left}`: ' +
519518
c.expected_msg(right_type_unwrapped, left_type_unwrapped), right.pos())
@@ -701,7 +700,7 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
701700
}
702701
if left_sym.kind == .interface_ {
703702
if c.type_implements(right_type, left_type, right.pos()) {
704-
if !right_type.is_ptr() && !right_type.is_pointer() && right_sym.kind != .interface_
703+
if !right_type.is_any_kind_of_pointer() && right_sym.kind != .interface_
705704
&& !c.inside_unsafe {
706705
c.mark_as_referenced(mut &node.right[i], true)
707706
}

vlib/v/checker/check_types.v

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
126126
if exp_idx == ast.voidptr_type_idx || exp_idx == ast.nil_type_idx
127127
|| exp_idx == ast.byteptr_type_idx
128128
|| (expected.is_ptr() && expected.deref().idx() == ast.u8_type_idx) {
129-
if got.is_ptr() || got.is_pointer() {
129+
if got.is_any_kind_of_pointer() {
130130
return true
131131
}
132132
}
@@ -140,7 +140,7 @@ fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
140140
if got_idx == ast.voidptr_type_idx || got_idx == ast.nil_type_idx
141141
|| got_idx == ast.byteptr_type_idx
142142
|| (got_idx == ast.u8_type_idx && got.is_ptr()) {
143-
if expected.is_ptr() || expected.is_pointer() {
143+
if expected.is_any_kind_of_pointer() {
144144
return true
145145
}
146146
}
@@ -375,7 +375,7 @@ fn (mut c Checker) check_basic(got ast.Type, expected ast.Type) bool {
375375
}
376376
}
377377
if !unalias_got.is_ptr() && got_sym.kind == .array_fixed
378-
&& (unalias_expected.is_pointer() || unalias_expected.is_ptr()) {
378+
&& unalias_expected.is_any_kind_of_pointer() {
379379
// fixed array needs to be a struct, not a pointer
380380
return false
381381
}
@@ -440,8 +440,8 @@ fn (mut c Checker) check_matching_function_symbols(got_type_sym &ast.TypeSymbol,
440440
exp_arg := exp_fn.params[i]
441441
exp_arg_typ := c.unwrap_generic(exp_arg.typ)
442442
got_arg_typ := c.unwrap_generic(got_arg.typ)
443-
exp_arg_is_ptr := exp_arg_typ.is_ptr() || exp_arg_typ.is_pointer()
444-
got_arg_is_ptr := got_arg_typ.is_ptr() || got_arg_typ.is_pointer()
443+
exp_arg_is_ptr := exp_arg_typ.is_any_kind_of_pointer()
444+
got_arg_is_ptr := got_arg_typ.is_any_kind_of_pointer()
445445
if exp_arg.is_mut && !got_arg.is_mut {
446446
return false
447447
}
@@ -671,13 +671,13 @@ fn (c &Checker) expected_msg(got ast.Type, expected ast.Type) string {
671671
fn (mut c Checker) symmetric_check(left ast.Type, right ast.Type) bool {
672672
// allow direct int-literal assignment for pointers for now
673673
// maybe in the future options should be used for that
674-
if right.is_ptr() || right.is_pointer() {
674+
if right.is_any_kind_of_pointer() {
675675
if left == ast.int_literal_type {
676676
return true
677677
}
678678
}
679679
// allow direct int-literal assignment for pointers for now
680-
if left.is_ptr() || left.is_pointer() {
680+
if left.is_any_kind_of_pointer() {
681681
if right == ast.int_literal_type {
682682
return true
683683
}

vlib/v/checker/checker.v

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,15 +2921,15 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
29212921
// TODO make this an error
29222922
c.warn('cannot cast voidptr to a struct outside `unsafe`', node.pos)
29232923
}
2924-
if !from_type.is_int() && final_from_sym.kind != .enum_ && !from_type.is_pointer()
2925-
&& !from_type.is_ptr() {
2924+
if !from_type.is_int() && final_from_sym.kind != .enum_
2925+
&& !from_type.is_any_kind_of_pointer() {
29262926
ft := c.table.type_to_str(from_type)
29272927
tt := c.table.type_to_str(to_type)
29282928
c.error('cannot cast `${ft}` to `${tt}`', node.pos)
29292929
}
29302930
} else if to_sym.kind == .interface_ {
29312931
if c.type_implements(from_type, to_type, node.pos) {
2932-
if !from_type.is_ptr() && !from_type.is_pointer() && from_sym.kind != .interface_
2932+
if !from_type.is_any_kind_of_pointer() && from_sym.kind != .interface_
29332933
&& !c.inside_unsafe {
29342934
c.mark_as_referenced(mut &node.expr, true)
29352935
}
@@ -2959,8 +2959,8 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
29592959
type_name := c.table.type_to_str(to_type)
29602960
c.error('cannot cast struct `${from_type_name}` to `${type_name}`', node.pos)
29612961
}
2962-
} else if to_sym.kind == .u8 && !final_from_sym.is_number() && !final_from_sym.is_pointer()
2963-
&& !from_type.is_ptr() && final_from_sym.kind !in [.char, .enum_, .bool] {
2962+
} else if to_sym.kind == .u8 && !final_from_sym.is_number()
2963+
&& !from_type.is_any_kind_of_pointer() && final_from_sym.kind !in [.char, .enum_, .bool] {
29642964
ft := c.table.type_to_str(from_type)
29652965
tt := c.table.type_to_str(to_type)
29662966
c.error('cannot cast type `${ft}` to `${tt}`', node.pos)

vlib/v/checker/containers.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn (mut c Checker) array_init(mut node ast.ArrayInit) ast.Type {
164164
c.expected_type = elem_type
165165
c.type_implements(typ, elem_type, expr.pos())
166166
}
167-
if !typ.is_ptr() && !typ.is_pointer() && !c.inside_unsafe {
167+
if !typ.is_any_kind_of_pointer() && !c.inside_unsafe {
168168
typ_sym := c.table.sym(typ)
169169
if typ_sym.kind != .interface_ {
170170
c.mark_as_referenced(mut &expr, true)

vlib/v/checker/fn.v

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
11541154
// Handle expected interface
11551155
if final_param_sym.kind == .interface_ {
11561156
if c.type_implements(arg_typ, final_param_typ, call_arg.expr.pos()) {
1157-
if !arg_typ.is_ptr() && !arg_typ.is_pointer() && !c.inside_unsafe
1157+
if !arg_typ.is_any_kind_of_pointer() && !c.inside_unsafe
11581158
&& arg_typ_sym.kind != .interface_ {
11591159
c.mark_as_referenced(mut &call_arg.expr, true)
11601160
}
@@ -1307,7 +1307,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
13071307
unwrap_sym := c.table.sym(unwrap_typ)
13081308
if unwrap_sym.kind == .interface_ {
13091309
if c.type_implements(utyp, unwrap_typ, call_arg.expr.pos()) {
1310-
if !utyp.is_ptr() && !utyp.is_pointer() && !c.inside_unsafe
1310+
if !utyp.is_any_kind_of_pointer() && !c.inside_unsafe
13111311
&& c.table.sym(utyp).kind != .interface_ {
13121312
c.mark_as_referenced(mut &call_arg.expr, true)
13131313
}
@@ -2031,7 +2031,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
20312031
// Handle expected interface
20322032
if final_arg_sym.kind == .interface_ {
20332033
if c.type_implements(got_arg_typ, final_arg_typ, arg.expr.pos()) {
2034-
if !got_arg_typ.is_ptr() && !got_arg_typ.is_pointer() && !c.inside_unsafe {
2034+
if !got_arg_typ.is_any_kind_of_pointer() && !c.inside_unsafe {
20352035
got_arg_typ_sym := c.table.sym(got_arg_typ)
20362036
if got_arg_typ_sym.kind != .interface_ {
20372037
c.mark_as_referenced(mut &arg.expr, true)

vlib/v/checker/infix.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
485485
if right_final_sym.kind != .array {
486486
// []Animal << Cat
487487
if c.type_implements(right_type, left_value_type, right_pos) {
488-
if !right_type.is_ptr() && !right_type.is_pointer() && !c.inside_unsafe
488+
if !right_type.is_any_kind_of_pointer() && !c.inside_unsafe
489489
&& right_sym.kind != .interface_ {
490490
c.mark_as_referenced(mut &node.right, true)
491491
}

vlib/v/checker/match.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fn (mut c Checker) match_exprs(mut node ast.MatchExpr, cond_type_sym ast.TypeSym
290290
// c.type_implements(expr_type, c.expected_type, expr.pos())
291291
expr_pos := expr.pos()
292292
if c.type_implements(expr_type, c.expected_type, expr_pos) {
293-
if !expr_type.is_ptr() && !expr_type.is_pointer() && !c.inside_unsafe {
293+
if !expr_type.is_any_kind_of_pointer() && !c.inside_unsafe {
294294
if expr_type_sym.kind != .interface_ {
295295
c.mark_as_referenced(mut &branch.exprs[k], true)
296296
}

vlib/v/checker/postfix.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import v.ast
55
fn (mut c Checker) postfix_expr(mut node ast.PostfixExpr) ast.Type {
66
typ := c.unwrap_generic(c.expr(node.expr))
77
typ_sym := c.table.sym(typ)
8-
is_non_void_pointer := (typ.is_ptr() || typ.is_pointer()) && typ_sym.kind != .voidptr
8+
is_non_void_pointer := typ.is_any_kind_of_pointer() && typ_sym.kind != .voidptr
99

1010
if node.op in [.inc, .dec] && !node.expr.is_lvalue() {
1111
op_kind, bin_op_alt := if node.op == .inc {

vlib/v/checker/return.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ fn (mut c Checker) return_stmt(mut node ast.Return) {
195195
} else {
196196
if exp_type_sym.kind == .interface_ {
197197
if c.type_implements(got_type, exp_type, node.pos) {
198-
if !got_type.is_ptr() && !got_type.is_pointer()
199-
&& got_type_sym.kind != .interface_ && !c.inside_unsafe {
198+
if !got_type.is_any_kind_of_pointer() && got_type_sym.kind != .interface_
199+
&& !c.inside_unsafe {
200200
c.mark_as_referenced(mut &node.exprs[expr_idxs[i]], true)
201201
}
202202
}

0 commit comments

Comments
 (0)