Skip to content

Commit e3a161e

Browse files
committed
v2: transformer fixes; cgen: auto str fixes
1 parent 737163c commit e3a161e

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

vlib/v/gen/c/auto_str_methods.v

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,18 +1133,17 @@ fn (mut g Gen) gen_str_for_struct(info ast.Struct, lang ast.Language, styp strin
11331133
caller_should_free = false
11341134
}
11351135
} else if ftyp_noshared.is_ptr() {
1136-
// reference types can be "nil"
11371136
if ftyp_noshared.has_flag(.option) {
1138-
funcprefix += '${it_field_name}.state != 0'
1137+
// optional pointer types: let the option auto-str function handle the none case
11391138
} else {
1139+
// reference types can be "nil"
11401140
funcprefix += 'builtin__isnil(${it_field_name})'
1141-
}
1142-
funcprefix += ' ? _S("nil") : '
1143-
// struct, floats and ints have a special case through the _str function
1144-
if !ftyp_noshared.has_flag(.option)
1145-
&& sym.kind !in [.struct, .alias, .enum, .sum_type, .map, .interface, .bool]
1146-
&& !field.typ.is_int_valptr() && !field.typ.is_float_valptr() {
1147-
funcprefix += '*'
1141+
funcprefix += ' ? _S("nil") : '
1142+
// struct, floats and ints have a special case through the _str function
1143+
if sym.kind !in [.struct, .alias, .enum, .sum_type, .map, .interface, .bool]
1144+
&& !field.typ.is_int_valptr() && !field.typ.is_float_valptr() {
1145+
funcprefix += '*'
1146+
}
11481147
}
11491148
}
11501149
mut is_field_array := false

vlib/v/gen/c/infix.v

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,7 +1541,7 @@ fn (mut g Gen) infix_expr_and_or_op(node ast.InfixExpr) {
15411541
cur_line := g.go_before_last_stmt().trim_space()
15421542
g.empty_line = true
15431543
if g.infix_left_var_name.len > 0 {
1544-
g.write('bool ${tmp} = ((${g.infix_left_var_name}) ${node.op.str()} ')
1544+
g.write('bool ${tmp} = ((${g.infix_left_var_name}) && ')
15451545
} else {
15461546
g.write('bool ${tmp} = (')
15471547
}
@@ -1558,7 +1558,11 @@ fn (mut g Gen) infix_expr_and_or_op(node ast.InfixExpr) {
15581558
tmp := g.new_tmp_var()
15591559
cur_line := g.go_before_last_stmt().trim_space()
15601560
g.empty_line = true
1561-
g.write('bool ${tmp} = (')
1561+
if g.infix_left_var_name.len > 0 {
1562+
g.write('bool ${tmp} = ((${g.infix_left_var_name}) && ')
1563+
} else {
1564+
g.write('bool ${tmp} = (')
1565+
}
15621566
g.expr(node.left)
15631567
g.writeln(');')
15641568
g.set_current_pos_as_last_stmt_pos()

vlib/v2/transformer/fn.v

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,10 +1442,6 @@ fn (mut t Transformer) transform_call_expr(expr ast.CallExpr) ast.Expr {
14421442
// specialization suffix so cleanc can later substitute concrete types.
14431443
if expr.lhs is ast.GenericArgOrIndexExpr {
14441444
gai := expr.lhs as ast.GenericArgOrIndexExpr
1445-
if t.cur_fn_name_str == 'get' || t.cur_fn_name_str == 'get_or_panic' {
1446-
is_sel := gai.lhs is ast.SelectorExpr
1447-
eprintln('[DBG GAOI in call] fn=${t.cur_fn_name_str} gai.lhs_name=${gai.lhs.name()} is_sel=${is_sel} gai.expr=${gai.expr.name()}')
1448-
}
14491445
if gai.lhs is ast.SelectorExpr {
14501446
sel := gai.lhs as ast.SelectorExpr
14511447
is_module_call := sel.lhs is ast.Ident && t.lookup_var_type(sel.lhs.name) == none

0 commit comments

Comments
 (0)