aboutsummaryrefslogtreecommitdiffstats
path: root/parse.y
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2023-10-14 10:53:44 +0900
committerYuichiro Kaneko <spiketeika@gmail.com>2023-10-15 16:16:06 +0900
commite7e31d77848797703de60ea4aa095a3ec9e6c762 (patch)
tree6d1b205f1cacd50eec7455bc084ac54cef066eb6 /parse.y
parenta4e3d595cd9e656630030619235c42c48b0a1446 (diff)
downloadruby-e7e31d77848797703de60ea4aa095a3ec9e6c762.tar.gz
Stop updating node type from NODE_STR to NODE_DSTR
This is a preparation for removing not_used members from STR NODE. Once not_used members are removed from STR NODE, STR NODE is smaller than DSTR NODE. Therefore allocate NODE_DSTR instead of reusing NODE_STR.
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y32
1 files changed, 27 insertions, 5 deletions
diff --git a/parse.y b/parse.y
index 164893f757..09356ce596 100644
--- a/parse.y
+++ b/parse.y
@@ -1202,6 +1202,7 @@ static NODE *rest_arg_append(struct parser_params *p, NODE *args, NODE *rest_arg
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 *str2dstr(struct parser_params*,NODE*);
static NODE *evstr2dstr(struct parser_params*,NODE*);
static NODE *splat_array(NODE*);
static void mark_lvar_used(struct parser_params *p, NODE *rhs);
@@ -5898,7 +5899,7 @@ regexp_contents: /* none */
else {
switch (nd_type(head)) {
case NODE_STR:
- nd_set_type(head, NODE_DSTR);
+ head = str2dstr(p, head);
break;
case NODE_DSTR:
break;
@@ -12461,7 +12462,7 @@ literal_concat(struct parser_params *p, NODE *head, NODE *tail, const YYLTYPE *l
if (p->heredoc_indent > 0) {
switch (htype) {
case NODE_STR:
- nd_set_type(head, NODE_DSTR);
+ head = str2dstr(p, head);
case NODE_DSTR:
return list_append(p, head, tail);
default:
@@ -12523,7 +12524,7 @@ literal_concat(struct parser_params *p, NODE *head, NODE *tail, const YYLTYPE *l
case NODE_EVSTR:
if (htype == NODE_STR) {
- nd_set_type(head, NODE_DSTR);
+ head = str2dstr(p, head);
RNODE_DSTR(head)->as.nd_alen = 1;
}
list_append(p, head, tail);
@@ -12532,6 +12533,28 @@ literal_concat(struct parser_params *p, NODE *head, NODE *tail, const YYLTYPE *l
return head;
}
+static void
+nd_copy_flag(NODE *new_node, NODE *old_node)
+{
+ if (nd_fl_newline(old_node)) nd_set_fl_newline(new_node);
+ nd_set_line(new_node, nd_line(old_node));
+ new_node->nd_loc = old_node->nd_loc;
+ new_node->node_id = old_node->node_id;
+}
+
+static NODE *
+str2dstr(struct parser_params *p, NODE *node)
+{
+ NODE *new_node = (NODE *)NODE_NEW_INTERNAL(NODE_DSTR, rb_node_dstr_t);
+ nd_copy_flag(new_node, node);
+ RNODE_DSTR(new_node)->nd_lit = RNODE_STR(node)->nd_lit;
+ RNODE_DSTR(new_node)->as.nd_alen = 0;
+ RNODE_DSTR(new_node)->nd_next = 0;
+ RNODE_STR(node)->nd_lit = 0;
+
+ return new_node;
+}
+
static NODE *
evstr2dstr(struct parser_params *p, NODE *node)
{
@@ -12549,8 +12572,7 @@ new_evstr(struct parser_params *p, NODE *node, const YYLTYPE *loc)
if (node) {
switch (nd_type(node)) {
case NODE_STR:
- nd_set_type(node, NODE_DSTR);
- return node;
+ return str2dstr(p, node);
case NODE_DSTR:
break;
case NODE_EVSTR: