Extract NODE_FL_NEWLINE access to macro

This commit is contained in:
yui-knk 2023-10-10 21:24:39 +09:00 коммит произвёл Yuichiro Kaneko
Родитель b17ae88894
Коммит f9fe7aeef4
4 изменённых файлов: 15 добавлений и 11 удалений

Просмотреть файл

@ -9534,7 +9534,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no
/* ignore */ /* ignore */
} }
else { else {
if (node->flags & NODE_FL_NEWLINE) { if (nd_fl_newline(node)) {
int event = RUBY_EVENT_LINE; int event = RUBY_EVENT_LINE;
ISEQ_COMPILE_DATA(iseq)->last_line = line; ISEQ_COMPILE_DATA(iseq)->last_line = line;
if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) { if (ISEQ_COVERAGE(iseq) && ISEQ_LINE_COVERAGE(iseq)) {

Просмотреть файл

@ -30,7 +30,7 @@
ruby_node_name(nd_type(node)), nd_node_id(node), nd_line(node), \ ruby_node_name(nd_type(node)), nd_node_id(node), nd_line(node), \
nd_first_lineno(node), nd_first_column(node), \ nd_first_lineno(node), nd_first_column(node), \
nd_last_lineno(node), nd_last_column(node), \ nd_last_lineno(node), nd_last_column(node), \
(node->flags & NODE_FL_NEWLINE ? "*" : "")) (nd_fl_newline(node) ? "*" : ""))
#define A_FIELD_HEADER(len, name, term) \ #define A_FIELD_HEADER(len, name, term) \
rb_str_catf(buf, "+- %.*s:"term, (len), (name)) rb_str_catf(buf, "+- %.*s:"term, (len), (name))
#define D_FIELD_HEADER(len, name, term) (A_INDENT, A_FIELD_HEADER(len, name, term)) #define D_FIELD_HEADER(len, name, term) (A_INDENT, A_FIELD_HEADER(len, name, term))

18
parse.y
Просмотреть файл

@ -5985,7 +5985,7 @@ string_content : tSTRING_CONTENT
p->heredoc_indent = $<num>indent; p->heredoc_indent = $<num>indent;
p->heredoc_line_indent = -1; p->heredoc_line_indent = -1;
/*%%%*/ /*%%%*/
if ($compstmt) $compstmt->flags &= ~NODE_FL_NEWLINE; if ($compstmt) nd_unset_fl_newline($compstmt);
$$ = new_evstr(p, $compstmt, &@$); $$ = new_evstr(p, $compstmt, &@$);
/*% %*/ /*% %*/
/*% ripper: string_embexpr!($compstmt) %*/ /*% ripper: string_embexpr!($compstmt) %*/
@ -8790,7 +8790,7 @@ heredoc_dedent(struct parser_params *p, NODE *root)
while (str_node) { while (str_node) {
VALUE lit = RNODE_LIT(str_node)->nd_lit; VALUE lit = RNODE_LIT(str_node)->nd_lit;
if (str_node->flags & NODE_FL_NEWLINE) { if (nd_fl_newline(str_node)) {
dedent_string(p, lit, indent); dedent_string(p, lit, indent);
} }
if (!prev_lit) { if (!prev_lit) {
@ -9097,7 +9097,7 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
flush_str: flush_str:
set_yylval_str(str); set_yylval_str(str);
#ifndef RIPPER #ifndef RIPPER
if (bol) yylval.node->flags |= NODE_FL_NEWLINE; if (bol) nd_set_fl_newline(yylval.node);
#endif #endif
flush_string_content(p, enc); flush_string_content(p, enc);
return tSTRING_CONTENT; return tSTRING_CONTENT;
@ -9122,7 +9122,7 @@ here_document(struct parser_params *p, rb_strterm_heredoc_t *here)
p->lex.strterm = NEW_STRTERM(func | STR_FUNC_TERM, 0, 0); p->lex.strterm = NEW_STRTERM(func | STR_FUNC_TERM, 0, 0);
set_yylval_str(str); set_yylval_str(str);
#ifndef RIPPER #ifndef RIPPER
if (bol) yylval.node->flags |= NODE_FL_NEWLINE; if (bol) nd_set_fl_newline(yylval.node);
#endif #endif
return tSTRING_CONTENT; return tSTRING_CONTENT;
} }
@ -12275,7 +12275,7 @@ newline_node(NODE *node)
{ {
if (node) { if (node) {
node = remove_begin(node); node = remove_begin(node);
node->flags |= NODE_FL_NEWLINE; nd_set_fl_newline(node);
} }
return node; return node;
} }
@ -13963,7 +13963,7 @@ reduce_nodes(struct parser_params *p, NODE **body)
(reduce_nodes(p, &type(node)->n1), body = &type(node)->n2, 1)) (reduce_nodes(p, &type(node)->n1), body = &type(node)->n2, 1))
while (node) { while (node) {
int newline = (int)(node->flags & NODE_FL_NEWLINE); int newline = (int)(nd_fl_newline(node));
switch (nd_type(node)) { switch (nd_type(node)) {
end: end:
case NODE_NIL: case NODE_NIL:
@ -13971,11 +13971,11 @@ reduce_nodes(struct parser_params *p, NODE **body)
return; return;
case NODE_RETURN: case NODE_RETURN:
*body = node = RNODE_RETURN(node)->nd_stts; *body = node = RNODE_RETURN(node)->nd_stts;
if (newline && node) node->flags |= NODE_FL_NEWLINE; if (newline && node) nd_set_fl_newline(node);
continue; continue;
case NODE_BEGIN: case NODE_BEGIN:
*body = node = RNODE_BEGIN(node)->nd_body; *body = node = RNODE_BEGIN(node)->nd_body;
if (newline && node) node->flags |= NODE_FL_NEWLINE; if (newline && node) nd_set_fl_newline(node);
continue; continue;
case NODE_BLOCK: case NODE_BLOCK:
body = &RNODE_BLOCK(RNODE_BLOCK(node)->nd_end)->nd_head; body = &RNODE_BLOCK(RNODE_BLOCK(node)->nd_end)->nd_head;
@ -14005,7 +14005,7 @@ reduce_nodes(struct parser_params *p, NODE **body)
return; return;
} }
node = *body; node = *body;
if (newline && node) node->flags |= NODE_FL_NEWLINE; if (newline && node) nd_set_fl_newline(node);
} }
#undef subnodes #undef subnodes

Просмотреть файл

@ -1059,6 +1059,10 @@ typedef struct RNode_RIPPER_VALUES {
#define NODE_TYPESHIFT 8 #define NODE_TYPESHIFT 8
#define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT) #define NODE_TYPEMASK (((VALUE)0x7f)<<NODE_TYPESHIFT)
#define nd_fl_newline(n) (n)->flags & NODE_FL_NEWLINE
#define nd_set_fl_newline(n) (n)->flags |= NODE_FL_NEWLINE
#define nd_unset_fl_newline(n) (n)->flags &= ~NODE_FL_NEWLINE
#define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT)) #define nd_type(n) ((int) ((RNODE(n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
#define nd_set_type(n,t) \ #define nd_set_type(n,t) \
rb_node_set_type(n, t) rb_node_set_type(n, t)