Skip to content
  • HASUMI Hitoshi's avatar
    ddd8da4b
    [Universal parser] Improve AST structure · ddd8da4b
    HASUMI Hitoshi authored
    This patch 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://github.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 patch 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;
    }
    ```
    ddd8da4b
    [Universal parser] Improve AST structure
    HASUMI Hitoshi authored
    This patch 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://github.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 patch 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;
    }
    ```
Loading