diff options
author | Yusuke Endoh <[email protected]> | 2021-11-18 03:40:49 +0900 |
---|---|---|
committer | Yusuke Endoh <[email protected]> | 2021-11-21 08:59:24 +0900 |
commit | feda058531c0bdd5b673180accb4407dcc798c79 () | |
tree | 7a9e59021282949f551b690feee031919ddd8a5a /node.c | |
parent | 86ad878e6a0781749c73574112a0fac4f088e2c9 (diff) |
Refactor hacky ID tables to struct rb_ast_id_table_t
The implementation of a local variable tables was represented as `ID*`, but it was very hacky: the first element is not an ID but the size of the table, and, the last element is (sometimes) a link to the next local table only when the id tables are a linked list. This change converts the hacky implementation to a normal struct.
Notes: Merged: https://.com/ruby/ruby/pull/5136
-rw-r--r-- | node.c | 47 |
1 files changed, 35 insertions, 12 deletions
@@ -1043,12 +1043,12 @@ dump_node(VALUE buf, VALUE indent, int comment, const NODE * node) ANN("new scope"); ANN("format: [nd_tbl]: local table, [nd_args]: arguments, [nd_body]: body"); F_CUSTOM1(nd_tbl, "local table") { - ID *tbl = node->nd_tbl; int i; - int size = tbl ? (int)*tbl++ : 0; if (size == 0) A("(empty)"); for (i = 0; i < size; i++) { - A_ID(tbl[i]); if (i < size - 1) A(","); } } F_NODE(nd_args, "arguments"); @@ -1162,7 +1162,7 @@ typedef struct { struct node_buffer_struct { node_buffer_list_t unmarkable; node_buffer_list_t markable; - ID *local_tables; VALUE mark_hash; }; @@ -1205,15 +1205,22 @@ node_buffer_list_free(node_buffer_list_t * nb) } } static void rb_node_buffer_free(node_buffer_t *nb) { node_buffer_list_free(&nb->unmarkable); node_buffer_list_free(&nb->markable); - ID * local_table = nb->local_tables; while (local_table) { - unsigned int size = (unsigned int)*local_table; - ID * next_table = (ID *)local_table[size + 1]; xfree(local_table); local_table = next_table; } @@ -1277,12 +1284,28 @@ rb_ast_node_type_change(NODE *n, enum node_type type) } } -void -rb_ast_add_local_table(rb_ast_t *ast, ID *buf) { - unsigned int size = (unsigned int)*buf; - buf[size + 1] = (ID)ast->node_buffer->local_tables; - ast->node_buffer->local_tables = buf; } void |