diff options
author | HASUMI Hitoshi <[email protected]> | 2024-04-27 16:28:52 +0900 |
---|---|---|
committer | Yuichiro Kaneko <[email protected]> | 2024-04-28 12:08:21 +0900 |
commit | ddd8da4b6ba3dfcca21ca710e7cef2fa3b9632d7 () | |
tree | a1549d2a8b59ec0b5a7b187d804c3b594a7c0108 /ruby_parser.c | |
parent | 8ad0b2cd310b4ca5af9a24610117a05acc35bcae (diff) |
[Universal parser] Improve AST structure
This moves `ast->node_buffer->config` to `ast->config` aiming to improve readability and maintainability of the source. ## Background We could not add the `config` field to the `rb_ast_t *` due to the five-word restriction of the IMEMO object. But it is now doable by merging https://.com/ruby/ruby/pull/10618 ## About assigning `&rb_global_parser_config` to `ast->config` in `ast_alloc()` The approach of not setting `ast->config` in `ast_alloc()` means that the client, CRuby in this scenario, that directly calls `ast_alloc()` will be responsible for releasing it if a resource that is passed to AST needs to be released. However, we have put on hold whether we can guarantee the above so far, thus, this looks like that. ``` // ruby_parser.c static VALUE ast_alloc(void) { rb_ast_t *ast; VALUE vast = TypedData_Make_Struct(0, rb_ast_t, &ast_data_type, ast); #ifdef UNIVERSAL_PARSER ast = (rb_ast_t *)DATA_PTR(vast); ast->config = &rb_global_parser_config; #endif return vast; } ```
-rw-r--r-- | ruby_parser.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -758,9 +758,7 @@ static void ast_free(void *ptr) { rb_ast_t *ast = (rb_ast_t *)ptr; - if (ast) { - rb_ast_free(ast); - } } static const rb_data_type_t ast_data_type = { @@ -777,7 +775,12 @@ static VALUE ast_alloc(void) { rb_ast_t *ast; - return TypedData_Make_Struct(0, rb_ast_t, &ast_data_type, ast); } VALUE |