mirror of
https://github.com/vlang/v.git
synced 2025-09-18 20:07:02 -04:00
cgen: cleanup in comptime_if_conds() (#19432)
This commit is contained in:
parent
7e08a50ea5
commit
b30426aafb
@ -501,10 +501,9 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) (bool, bool) {
|
|||||||
return if cond.op == .and { l && r } else { l || r }, d1 && d1 == d2
|
return if cond.op == .and { l && r } else { l || r }, d1 && d1 == d2
|
||||||
}
|
}
|
||||||
.key_is, .not_is {
|
.key_is, .not_is {
|
||||||
left := cond.left
|
if cond.left in [ast.TypeNode, ast.Ident, ast.SelectorExpr]
|
||||||
if left in [ast.TypeNode, ast.Ident, ast.SelectorExpr]
|
|
||||||
&& cond.right in [ast.ComptimeType, ast.TypeNode] {
|
&& cond.right in [ast.ComptimeType, ast.TypeNode] {
|
||||||
exp_type := g.get_expr_type(left)
|
exp_type := g.get_expr_type(cond.left)
|
||||||
if cond.right is ast.ComptimeType {
|
if cond.right is ast.ComptimeType {
|
||||||
is_true := g.table.is_comptime_type(exp_type, cond.right)
|
is_true := g.table.is_comptime_type(exp_type, cond.right)
|
||||||
if cond.op == .key_is {
|
if cond.op == .key_is {
|
||||||
@ -652,28 +651,24 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) (bool, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.gt, .lt, .ge, .le {
|
.gt, .lt, .ge, .le {
|
||||||
if cond.left is ast.SelectorExpr && cond.right is ast.IntegerLiteral {
|
if cond.left is ast.SelectorExpr && cond.right is ast.IntegerLiteral
|
||||||
if g.is_comptime_selector_field_name(cond.left as ast.SelectorExpr,
|
&& g.is_comptime_selector_field_name(cond.left, 'indirections') {
|
||||||
'indirections')
|
is_true := match cond.op {
|
||||||
{
|
.gt { g.comptime_for_field_type.nr_muls() > cond.right.val.i64() }
|
||||||
is_true := match cond.op {
|
.lt { g.comptime_for_field_type.nr_muls() < cond.right.val.i64() }
|
||||||
.gt { g.comptime_for_field_type.nr_muls() > cond.right.val.i64() }
|
.ge { g.comptime_for_field_type.nr_muls() >= cond.right.val.i64() }
|
||||||
.lt { g.comptime_for_field_type.nr_muls() < cond.right.val.i64() }
|
.le { g.comptime_for_field_type.nr_muls() <= cond.right.val.i64() }
|
||||||
.ge { g.comptime_for_field_type.nr_muls() >= cond.right.val.i64() }
|
else { false }
|
||||||
.le { g.comptime_for_field_type.nr_muls() <= cond.right.val.i64() }
|
|
||||||
else { false }
|
|
||||||
}
|
|
||||||
if is_true {
|
|
||||||
g.write('1')
|
|
||||||
} else {
|
|
||||||
g.write('0')
|
|
||||||
}
|
|
||||||
return is_true, true
|
|
||||||
} else {
|
|
||||||
return true, false
|
|
||||||
}
|
}
|
||||||
|
if is_true {
|
||||||
|
g.write('1')
|
||||||
|
} else {
|
||||||
|
g.write('0')
|
||||||
|
}
|
||||||
|
return is_true, true
|
||||||
|
} else {
|
||||||
|
return true, false
|
||||||
}
|
}
|
||||||
return true, false
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return true, false
|
return true, false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user