diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-08-01 00:25:14 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-08-01 00:25:14 +0200 |
| commit | 7da73a562eb017708ac89ec6658db982fc941689 (patch) | |
| tree | 0d8eeb83c8cffd337cab99a8f7f190f55fc641be /src | |
| parent | 963bdd60b8f85eabd3775cec9ce2b92609524db5 (diff) | |
odinfmt: change return formatting and fix binary expression issues.
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/visit.odin | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 895d2dd..bb0ba0b 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -853,11 +853,33 @@ visit_stmt :: proc(p: ^Printer, stmt: ^ast.Stmt, block_type: Block_Type = .Gener document = enforce_fit_if_do(v.body, document) case ^Return_Stmt: - document = cons(document, text("return")) + if v.results == nil { + document = cons(document, text("return")) + break + } + + if len(v.results) == 1 { + result := v.results[0] + + if paren, is_paren := result.derived.(^ast.Paren_Expr); is_paren { + result = paren.expr + } + + document = cons( + text("return"), + if_break("("), + break_with(" "), + visit_expr(p, result), + ) - if v.results != nil { + document = nest(document) + document = group(cons(document, if_break(" \\"), break_with(""), if_break(")"))) + } else { + document = cons(document, text("return")) document = cons_with_nopl(document, visit_exprs(p, v.results, {.Add_Comma})) } + + case ^Defer_Stmt: document = cons(document, text("defer")) document = cons_with_nopl(document, visit_stmt(p, v.stmt)) @@ -1701,7 +1723,7 @@ visit_binary_expr :: proc(p: ^Printer, binary: ast.Binary_Expr, nested := false) if b, ok := binary.right.derived.(^ast.Binary_Expr); ok { document = cons_with_opl(document, group(nest(visit_binary_expr(p, b^, true)))) } else { - document = cons_with_opl(document, group(nest(visit_expr(p, binary.right, nested ? .Binary_Expr : .Generic)))) + document = cons_with_opl(document, group(nest(visit_expr(p, binary.right, .Binary_Expr)))) } } |