cgen: c2v infix fix

Alexander Medvednikov 2022-06-01 06:14:28 +03:00 committed by Chewing_Bever
parent 2ab6ef7f0a
commit 0bdc213dc6
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
2 changed files with 9 additions and 1 deletions

View File

@ -1825,7 +1825,7 @@ fn (mut g Gen) stmt(node ast.Stmt) {
g.global_decl(node)
}
ast.GotoLabel {
g.writeln('${c_name(node.name)}: {}')
g.writeln('${c_name(node.name)}: ')
}
ast.GotoStmt {
g.write_v_source_line_info(node.pos)

View File

@ -87,6 +87,10 @@ fn (mut g Gen) infix_expr_eq_op(node ast.InfixExpr) {
right := g.unwrap(node.right_type)
has_defined_eq_operator := g.table.has_method(left.sym, '==')
has_alias_eq_op_overload := left.sym.info is ast.Alias && left.sym.has_method('==')
if g.pref.translated && !g.is_builtin_mod {
g.gen_plain_infix_expr(node)
return
}
if (left.typ.is_ptr() && right.typ.is_int()) || (right.typ.is_ptr() && left.typ.is_int()) {
g.gen_plain_infix_expr(node)
} else if (left.typ.idx() == ast.string_type_idx || (!has_defined_eq_operator
@ -291,6 +295,10 @@ fn (mut g Gen) infix_expr_cmp_op(node ast.InfixExpr) {
left := g.unwrap(node.left_type)
right := g.unwrap(node.right_type)
has_operator_overloading := g.table.has_method(left.sym, '<')
if g.pref.translated && !g.is_builtin_mod {
g.gen_plain_infix_expr(node)
return
}
if left.sym.kind == .struct_ && (left.sym.info as ast.Struct).generic_types.len > 0 {
if node.op in [.le, .ge] {
g.write('!')