8000 Remove not used fields from MATCH by yui-knk · Pull Request #8620 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Remove not used fields from MATCH #8620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Stop updating node type from NODE_LIT to NODE_MATCH
Update node type introduces structure dependency between nodes.
Create new node instead of updating node type.
  • Loading branch information
yui-knk committed Oct 10, 2023
commit 68878e9b331bc276268f26fcd3943733cf3c7653
23 changes: 22 additions & 1 deletion parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ 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 *lit2match(struct parser_params*, NODE*);
static NODE *splat_array(NODE*);
static void mark_lvar_used(struct parser_params *p, NODE *rhs);

Expand Down Expand Up @@ -12521,6 +12522,26 @@ 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 *
lit2match(struct parser_params *p, NODE *node)
{
NODE *new_node = (NODE *)NODE_NEW_INTERNAL(NODE_MATCH, rb_node_match_t);
nd_copy_flag(new_node, node);
RNODE_MATCH(new_node)->nd_lit = RNODE_LIT(node)->nd_lit;
RNODE_LIT(node)->nd_lit = 0;

return new_node;
}

static NODE *
evstr2dstr(struct parser_params *p, NODE *node)
{
Expand Down Expand Up @@ -14135,7 +14156,7 @@ cond0(struct parser_params *p, NODE *node, enum cond_type type, const YYLTYPE *l
case NODE_LIT:
if (RB_TYPE_P(RNODE_LIT(node)->nd_lit, T_REGEXP)) {
if (!e_option_supplied(p)) SWITCH_BY_COND_TYPE(type, warn, "regex ")
nd_set_type(node, NODE_MATCH);
node = lit2match(p, node);
}
else if (RNODE_LIT(node)->nd_lit == Qtrue ||
RNODE_LIT(node)->nd_lit == Qfalse) {
Expand Down
0