cgen: minor cleanup of infix_expr.v (#14070)

master
yuyi 2022-04-18 20:05:19 +08:00 committed by GitHub
parent 379b638b57
commit d0a11f50ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 8 deletions

View File

@ -495,14 +495,14 @@ fn (mut g Gen) infix_expr_in_optimization(left ast.Expr, right ast.ArrayInit) {
// infix_expr_is_op generates code for `is` and `!is` // infix_expr_is_op generates code for `is` and `!is`
fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) { fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) {
mut sym := g.table.sym(node.left_type) mut left_sym := g.table.sym(node.left_type)
is_aggregate := sym.kind == .aggregate is_aggregate := left_sym.kind == .aggregate
if is_aggregate { if is_aggregate {
parent_left_type := (sym.info as ast.Aggregate).sum_type parent_left_type := (left_sym.info as ast.Aggregate).sum_type
sym = g.table.sym(parent_left_type) left_sym = g.table.sym(parent_left_type)
} }
right_sym := g.table.sym(node.right_type) right_sym := g.table.sym(node.right_type)
if sym.kind == .interface_ && right_sym.kind == .interface_ { if left_sym.kind == .interface_ && right_sym.kind == .interface_ {
g.gen_interface_is_op(node) g.gen_interface_is_op(node)
return return
} }
@ -520,7 +520,7 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) {
} else { } else {
g.write('.') g.write('.')
} }
if sym.kind == .interface_ { if left_sym.kind == .interface_ {
g.write('_typ $cmp_op ') g.write('_typ $cmp_op ')
// `_Animal_Dog_index` // `_Animal_Dog_index`
sub_type := match node.right { sub_type := match node.right {
@ -535,9 +535,9 @@ fn (mut g Gen) infix_expr_is_op(node ast.InfixExpr) {
} }
} }
sub_sym := g.table.sym(sub_type) sub_sym := g.table.sym(sub_type)
g.write('_${sym.cname}_${sub_sym.cname}_index') g.write('_${left_sym.cname}_${sub_sym.cname}_index')
return return
} else if sym.kind == .sum_type { } else if left_sym.kind == .sum_type {
g.write('_typ $cmp_op ') g.write('_typ $cmp_op ')
} }
g.expr(node.right) g.expr(node.right)