mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
NODE markability should not change by nd_set_type
This commit is contained in:
parent
e1fee7f949
commit
c060bdc2b4
Notes:
git
2021-01-14 16:59:48 +09:00
2 changed files with 37 additions and 6 deletions
31
node.c
31
node.c
|
@ -1139,7 +1139,7 @@ void
|
||||||
rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
|
rb_node_init(NODE *n, enum node_type type, VALUE a0, VALUE a1, VALUE a2)
|
||||||
{
|
{
|
||||||
n->flags = T_NODE;
|
n->flags = T_NODE;
|
||||||
nd_set_type(n, type);
|
nd_init_type(n, type);
|
||||||
n->u1.value = a0;
|
n->u1.value = a0;
|
||||||
n->u2.value = a1;
|
n->u2.value = a1;
|
||||||
n->u3.value = a2;
|
n->u3.value = a2;
|
||||||
|
@ -1238,10 +1238,10 @@ ast_newnode_in_bucket(node_buffer_list_t *nb)
|
||||||
return &nb->head->buf[nb->idx++];
|
return &nb->head->buf[nb->idx++];
|
||||||
}
|
}
|
||||||
|
|
||||||
NODE *
|
RBIMPL_ATTR_PURE()
|
||||||
rb_ast_newnode(rb_ast_t *ast, enum node_type type)
|
static bool
|
||||||
|
nodetype_markable_p(enum node_type type)
|
||||||
{
|
{
|
||||||
node_buffer_t *nb = ast->node_buffer;
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NODE_MATCH:
|
case NODE_MATCH:
|
||||||
case NODE_LIT:
|
case NODE_LIT:
|
||||||
|
@ -1254,9 +1254,28 @@ rb_ast_newnode(rb_ast_t *ast, enum node_type type)
|
||||||
case NODE_ARGS:
|
case NODE_ARGS:
|
||||||
case NODE_ARYPTN:
|
case NODE_ARYPTN:
|
||||||
case NODE_FNDPTN:
|
case NODE_FNDPTN:
|
||||||
return ast_newnode_in_bucket(&nb->markable);
|
return true;
|
||||||
default:
|
default:
|
||||||
return ast_newnode_in_bucket(&nb->unmarkable);
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NODE *
|
||||||
|
rb_ast_newnode(rb_ast_t *ast, enum node_type type)
|
||||||
|
{
|
||||||
|
node_buffer_t *nb = ast->node_buffer;
|
||||||
|
node_buffer_list_t *bucket =
|
||||||
|
(nodetype_markable_p(type) ? &nb->markable : &nb->unmarkable);
|
||||||
|
return ast_newnode_in_bucket(bucket);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
rb_ast_node_type_change(NODE *n, enum node_type type)
|
||||||
|
{
|
||||||
|
enum node_type old_type = nd_type(n);
|
||||||
|
if (nodetype_markable_p(old_type) != nodetype_markable_p(type)) {
|
||||||
|
rb_bug("node type changed: %s -> %s",
|
||||||
|
ruby_node_name(old_type), ruby_node_name(type));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
12
node.h
12
node.h
|
@ -187,6 +187,8 @@ typedef struct RNode {
|
||||||
|
|
||||||
#define nd_type(n) ((int) (((n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
|
#define nd_type(n) ((int) (((n)->flags & NODE_TYPEMASK)>>NODE_TYPESHIFT))
|
||||||
#define nd_set_type(n,t) \
|
#define nd_set_type(n,t) \
|
||||||
|
rb_node_set_type(n, t)
|
||||||
|
#define nd_init_type(n,t) \
|
||||||
(n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
|
(n)->flags=(((n)->flags&~NODE_TYPEMASK)|((((unsigned long)(t))<<NODE_TYPESHIFT)&NODE_TYPEMASK))
|
||||||
|
|
||||||
#define NODE_LSHIFT (NODE_TYPESHIFT+7)
|
#define NODE_LSHIFT (NODE_TYPESHIFT+7)
|
||||||
|
@ -471,9 +473,19 @@ void *rb_parser_realloc(struct parser_params *, void *, size_t);
|
||||||
void *rb_parser_calloc(struct parser_params *, size_t, size_t);
|
void *rb_parser_calloc(struct parser_params *, size_t, size_t);
|
||||||
void rb_parser_free(struct parser_params *, void *);
|
void rb_parser_free(struct parser_params *, void *);
|
||||||
PRINTF_ARGS(void rb_parser_printf(struct parser_params *parser, const char *fmt, ...), 2, 3);
|
PRINTF_ARGS(void rb_parser_printf(struct parser_params *parser, const char *fmt, ...), 2, 3);
|
||||||
|
void rb_ast_node_type_change(NODE *n, enum node_type type);
|
||||||
|
|
||||||
RUBY_SYMBOL_EXPORT_END
|
RUBY_SYMBOL_EXPORT_END
|
||||||
|
|
||||||
|
static inline VALUE
|
||||||
|
rb_node_set_type(NODE *n, enum node_type t)
|
||||||
|
{
|
||||||
|
#if RUBY_DEBUG
|
||||||
|
rb_ast_node_type_change(n, t);
|
||||||
|
#endif
|
||||||
|
return nd_init_type(n, t);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
#if 0
|
#if 0
|
||||||
{ /* satisfy cc-mode */
|
{ /* satisfy cc-mode */
|
||||||
|
|
Loading…
Add table
Reference in a new issue