Skip to content

Commit 605c43d

Browse files
authored
checker: change comptime_if_branch() to comptime_if_cond() (#21774)
1 parent 65ff74b commit 605c43d

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

vlib/v/checker/comptime.v

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ fn (mut c Checker) eval_comptime_const_expr(expr ast.Expr, nlevel int) ?ast.Comp
550550
for i in 0 .. expr.branches.len {
551551
mut branch := expr.branches[i]
552552
if !expr.has_else || i < expr.branches.len - 1 {
553-
if c.comptime_if_branch(mut branch.cond, branch.pos) == .eval {
553+
if c.comptime_if_cond(mut branch.cond, branch.pos) == .eval {
554554
last_stmt := branch.stmts.last()
555555
if last_stmt is ast.ExprStmt {
556556
return c.eval_comptime_const_expr(last_stmt.expr, nlevel + 1)
@@ -665,7 +665,7 @@ fn (mut c Checker) evaluate_once_comptime_if_attribute(mut node ast.Attr) bool {
665665
}
666666
}
667667
c.inside_ct_attr = true
668-
node.ct_skip = if c.comptime_if_branch(mut node.ct_expr, node.pos) == .skip {
668+
node.ct_skip = if c.comptime_if_cond(mut node.ct_expr, node.pos) == .skip {
669669
true
670670
} else {
671671
false
@@ -681,9 +681,9 @@ enum ComptimeBranchSkipState {
681681
unknown
682682
}
683683

684-
// comptime_if_branch checks the condition of a compile-time `if` branch. It returns `true`
684+
// comptime_if_cond checks the condition of a compile-time `if` branch. It returns `true`
685685
// if that branch's contents should be skipped (targets a different os for example)
686-
fn (mut c Checker) comptime_if_branch(mut cond ast.Expr, pos token.Pos) ComptimeBranchSkipState {
686+
fn (mut c Checker) comptime_if_cond(mut cond ast.Expr, pos token.Pos) ComptimeBranchSkipState {
687687
mut should_record_ident := false
688688
mut is_user_ident := false
689689
mut ident_name := ''
@@ -702,13 +702,13 @@ fn (mut c Checker) comptime_if_branch(mut cond ast.Expr, pos token.Pos) Comptime
702702
return if cond.val { .eval } else { .skip }
703703
}
704704
ast.ParExpr {
705-
return c.comptime_if_branch(mut cond.expr, pos)
705+
return c.comptime_if_cond(mut cond.expr, pos)
706706
}
707707
ast.PrefixExpr {
708708
if cond.op != .not {
709709
c.error('invalid `\$if` condition', cond.pos)
710710
}
711-
reversed := c.comptime_if_branch(mut cond.right, cond.pos)
711+
reversed := c.comptime_if_cond(mut cond.right, cond.pos)
712712
return if reversed == .eval {
713713
.skip
714714
} else if reversed == .skip {
@@ -732,16 +732,16 @@ fn (mut c Checker) comptime_if_branch(mut cond ast.Expr, pos token.Pos) Comptime
732732
ast.InfixExpr {
733733
match cond.op {
734734
.and {
735-
l := c.comptime_if_branch(mut cond.left, cond.pos)
736-
r := c.comptime_if_branch(mut cond.right, cond.pos)
735+
l := c.comptime_if_cond(mut cond.left, cond.pos)
736+
r := c.comptime_if_cond(mut cond.right, cond.pos)
737737
if l == .unknown || r == .unknown {
738738
return .unknown
739739
}
740740
return if l == .eval && r == .eval { .eval } else { .skip }
741741
}
742742
.logical_or {
743-
l := c.comptime_if_branch(mut cond.left, cond.pos)
744-
r := c.comptime_if_branch(mut cond.right, cond.pos)
743+
l := c.comptime_if_cond(mut cond.left, cond.pos)
744+
r := c.comptime_if_cond(mut cond.right, cond.pos)
745745
if l == .unknown || r == .unknown {
746746
return .unknown
747747
}

vlib/v/checker/if.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn (mut c Checker) if_expr(mut node ast.IfExpr) ast.Type {
5959
}
6060
if !node.has_else || i < node.branches.len - 1 {
6161
if node.is_comptime {
62-
skip_state = c.comptime_if_branch(mut branch.cond, branch.pos)
62+
skip_state = c.comptime_if_cond(mut branch.cond, branch.pos)
6363
node.branches[i].pkg_exist = if skip_state == .eval { true } else { false }
6464
} else {
6565
// check condition type is boolean

0 commit comments

Comments
 (0)