1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: minor cleanup in return_stmt() (#15854)

This commit is contained in:
yuyi 2022-09-24 04:46:15 +08:00 committed by GitHub
parent 41fd02496a
commit c811b5343a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4324,32 +4324,26 @@ fn (mut g Gen) return_stmt(node ast.Return) {
for i, expr in node.exprs {
// Check if we are dealing with a multi return and handle it seperately
if g.expr_is_multi_return_call(expr) {
c := expr as ast.CallExpr
expr_sym := g.table.sym(c.return_type)
// Create a tmp for this call
call_expr := expr as ast.CallExpr
expr_sym := g.table.sym(call_expr.return_type)
mut tmp := g.new_tmp_var()
if !c.return_type.has_flag(.optional) {
s := g.go_before_stmt(0)
expr_styp := g.typ(c.return_type)
if !call_expr.return_type.has_flag(.optional)
&& !call_expr.return_type.has_flag(.result) {
line := g.go_before_stmt(0)
expr_styp := g.typ(call_expr.return_type)
g.write('$expr_styp $tmp=')
g.expr(expr)
g.writeln(';')
multi_unpack += g.go_before_stmt(0)
g.write(s)
g.write(line)
} else {
s := g.go_before_stmt(0)
// TODO
// I (emily) am sorry for doing this
// I cant find another way to do this so right now
// this will have to do.
line := g.go_before_stmt(0)
g.tmp_count--
g.expr(expr)
multi_unpack += g.go_before_stmt(0)
g.write(s)
// modify tmp so that it is the opt deref
// TODO copy-paste from cgen.v:2397
expr_styp := g.base_type(c.return_type)
tmp = ('/*opt*/(*($expr_styp*)${tmp}.data)')
g.write(line)
expr_styp := g.base_type(call_expr.return_type)
tmp = ('(*($expr_styp*)${tmp}.data)')
}
expr_types := expr_sym.mr_info().types
for j, _ in expr_types {