From 52eb34718862928b5d83c58990d5d7a6b07e20e2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 8 Jun 2019 01:16:19 -0400 Subject: [PATCH] hook up result locs for `try` --- src/all_types.hpp | 2 +- src/analyze.cpp | 2 +- src/ast_render.cpp | 6 +++--- src/ir.cpp | 10 +++++----- src/parser.cpp | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/all_types.hpp b/src/all_types.hpp index df7b8b549..0061b5999 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -430,7 +430,7 @@ enum NodeType { NodeTypeVariableDeclaration, NodeTypeTestDecl, NodeTypeBinOpExpr, - NodeTypeUnwrapErrorExpr, + NodeTypeCatchExpr, NodeTypeFloatLiteral, NodeTypeIntLiteral, NodeTypeStringLiteral, diff --git a/src/analyze.cpp b/src/analyze.cpp index 24c81d2a3..771e11e93 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2993,7 +2993,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { case NodeTypeBlock: case NodeTypeGroupedExpr: case NodeTypeBinOpExpr: - case NodeTypeUnwrapErrorExpr: + case NodeTypeCatchExpr: case NodeTypeFnCallExpr: case NodeTypeArrayAccessExpr: case NodeTypeSliceExpr: diff --git a/src/ast_render.cpp b/src/ast_render.cpp index 95ae216f7..078cd61ed 100644 --- a/src/ast_render.cpp +++ b/src/ast_render.cpp @@ -165,8 +165,8 @@ static const char *node_type_str(NodeType node_type) { return "Parens"; case NodeTypeBinOpExpr: return "BinOpExpr"; - case NodeTypeUnwrapErrorExpr: - return "UnwrapErrorExpr"; + case NodeTypeCatchExpr: + return "CatchExpr"; case NodeTypeFnCallExpr: return "FnCallExpr"; case NodeTypeArrayAccessExpr: @@ -1100,7 +1100,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) { fprintf(ar->f, "]"); break; } - case NodeTypeUnwrapErrorExpr: + case NodeTypeCatchExpr: { render_node_ungrouped(ar, node->data.unwrap_err_expr.op1); fprintf(ar->f, " catch "); diff --git a/src/ir.cpp b/src/ir.cpp index 34d3c2fb5..7f5b7da6e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3383,7 +3383,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode return ir_build_cond_br(irb, scope, node, is_canceled_bool, irb->exec->coro_final_cleanup_block, irb->exec->coro_early_final, is_comptime); } -static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { +static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval, ResultLoc *result_loc) { assert(node->type == NodeTypeReturnExpr); ZigFn *fn_entry = exec_fn_entry(irb->exec); @@ -3508,7 +3508,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, if (lval == LValPtr) return unwrapped_ptr; else - return ir_build_load_ptr(irb, scope, node, unwrapped_ptr); + return ir_expr_wrap(irb, scope, ir_build_load_ptr(irb, scope, node, unwrapped_ptr), result_loc); } } zig_unreachable(); @@ -7083,7 +7083,7 @@ static IrInstruction *ir_gen_slice(IrBuilder *irb, Scope *scope, AstNode *node) static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode *node, LVal lval, ResultLoc *result_loc) { - assert(node->type == NodeTypeUnwrapErrorExpr); + assert(node->type == NodeTypeCatchExpr); AstNode *op1_node = node->data.unwrap_err_expr.op1; AstNode *op2_node = node->data.unwrap_err_expr.op2; @@ -7895,7 +7895,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop case NodeTypeArrayAccessExpr: return ir_gen_array_access(irb, scope, node, lval, result_loc); case NodeTypeReturnExpr: - return ir_gen_return(irb, scope, node, lval); + return ir_gen_return(irb, scope, node, lval, result_loc); case NodeTypeFieldAccessExpr: { IrInstruction *ptr_instruction = ir_gen_field_access(irb, scope, node); @@ -7968,7 +7968,7 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop return ir_lval_wrap(irb, scope, ir_gen_defer(irb, scope, node), lval, result_loc); case NodeTypeSliceExpr: return ir_lval_wrap(irb, scope, ir_gen_slice(irb, scope, node), lval, result_loc); - case NodeTypeUnwrapErrorExpr: + case NodeTypeCatchExpr: return ir_gen_catch(irb, scope, node, lval, result_loc); case NodeTypeContainerDecl: return ir_lval_wrap(irb, scope, ir_gen_container_decl(irb, scope, node), lval, result_loc); diff --git a/src/parser.cpp b/src/parser.cpp index 3d7bbf780..43af34756 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -341,7 +341,7 @@ static AstNode *ast_parse_bin_op_expr( op->data.bin_op_expr.op1 = left; op->data.bin_op_expr.op2 = right; break; - case NodeTypeUnwrapErrorExpr: + case NodeTypeCatchExpr: op->data.unwrap_err_expr.op1 = left; op->data.unwrap_err_expr.op2 = right; break; @@ -2377,7 +2377,7 @@ static AstNode *ast_parse_bitwise_op(ParseContext *pc) { Token *catch_token = eat_token_if(pc, TokenIdKeywordCatch); if (catch_token != nullptr) { Token *payload = ast_parse_payload(pc); - AstNode *res = ast_create_node(pc, NodeTypeUnwrapErrorExpr, catch_token); + AstNode *res = ast_create_node(pc, NodeTypeCatchExpr, catch_token); if (payload != nullptr) res->data.unwrap_err_expr.symbol = token_symbol(pc, payload); @@ -2864,7 +2864,7 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont visit_field(&node->data.bin_op_expr.op1, visit, context); visit_field(&node->data.bin_op_expr.op2, visit, context); break; - case NodeTypeUnwrapErrorExpr: + case NodeTypeCatchExpr: visit_field(&node->data.unwrap_err_expr.op1, visit, context); visit_field(&node->data.unwrap_err_expr.symbol, visit, context); visit_field(&node->data.unwrap_err_expr.op2, visit, context);