From 93b78abd774109d1333d59eaf439b2e69ed0fe00 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Wed, 2 Sep 2020 12:45:11 +0900 Subject: [PATCH] new_dstr: hoisted out from literal_concat and evstr2dstr --- parse.y | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/parse.y b/parse.y index 83e6d20ea6..2a7d985356 100644 --- a/parse.y +++ b/parse.y @@ -481,6 +481,7 @@ static NODE *last_arg_append(struct parser_params *p, NODE *args, NODE *last_arg static NODE *rest_arg_append(struct parser_params *p, NODE *args, NODE *rest_arg, const YYLTYPE *loc); static NODE *literal_concat(struct parser_params*,NODE*,NODE*,const YYLTYPE*); static NODE *new_evstr(struct parser_params*,NODE*,const YYLTYPE*); +static NODE *new_dstr(struct parser_params*,NODE*,const YYLTYPE*); static NODE *evstr2dstr(struct parser_params*,NODE*); static NODE *splat_array(NODE*); static void mark_lvar_used(struct parser_params *p, NODE *rhs); @@ -9882,9 +9883,7 @@ literal_concat(struct parser_params *p, NODE *head, NODE *tail, const YYLTYPE *l htype = nd_type(head); if (htype == NODE_EVSTR) { - NODE *node = NEW_DSTR(STR_NEW0(), loc); - RB_OBJ_WRITTEN(p->ast, Qnil, node->nd_lit); - head = list_append(p, node, head); + head = new_dstr(p, head, loc); htype = NODE_DSTR; } if (p->heredoc_indent > 0) { @@ -9964,9 +9963,7 @@ static NODE * evstr2dstr(struct parser_params *p, NODE *node) { if (nd_type(node) == NODE_EVSTR) { - NODE * dstr = NEW_DSTR(STR_NEW0(), &node->nd_loc); - RB_OBJ_WRITTEN(p->ast, Qnil, dstr->nd_lit); - node = list_append(p, dstr, node); + node = new_dstr(p, node, &node->nd_loc); } return node; } @@ -9985,6 +9982,15 @@ new_evstr(struct parser_params *p, NODE *node, const YYLTYPE *loc) return NEW_EVSTR(head, loc); } +static NODE * +new_dstr(struct parser_params *p, NODE *node, const YYLTYPE *loc) +{ + VALUE lit = STR_NEW0(); + NODE *dstr = NEW_DSTR(lit, loc); + RB_OBJ_WRITTEN(p->ast, Qnil, lit); + return list_append(p, dstr, node); +} + static NODE * call_bin_op(struct parser_params *p, NODE *recv, ID id, NODE *arg1, const YYLTYPE *op_loc, const YYLTYPE *loc)