diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2021-04-30 18:54:46 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2021-05-07 17:02:15 +0900 |
commit | ff69ef27b06eed1ba750e7d9cab8322f351ed245 (patch) | |
tree | 84af4f4f8d99cc6a2af030230cf520e14862982b /ast.c | |
parent | 578e6416e71bcd5401bba63e9f3ef25a28258d9a (diff) |
compile.c: Pass node instead of nd_line(node) to ADD_INSN* functions
... then, new_insn_core extracts nd_line(node).
Also, if a macro "EXPERIMENTAL_ISEQ_NODE_ID" is defined, this changeset
keeps nd_node_id(node) for each instruction. This is intended for
TypeProf to identify what AST::Node corresponds to each instruction.
This patch is originally authored by @yui-knk for showing which column a
NoMethodError occurred.
https://github.com/ruby/ruby/compare/master...yui-knk:feature/node_id
Co-Authored-By: Yuichiro Kaneko <yui-knk@ruby-lang.org>
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4470
Diffstat (limited to 'ast.c')
-rw-r--r-- | ast.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -245,6 +245,17 @@ ast_node_type(rb_execution_context_t *ec, VALUE self) return rb_sym_intern_ascii_cstr(node_type_to_str(data->node)); } +#ifdef EXPERIMENTAL_ISEQ_NODE_ID +static VALUE +ast_node_node_id(VALUE self) +{ + struct ASTNodeData *data; + TypedData_Get_Struct(self, struct ASTNodeData, &rb_node_type, data); + + return INT2FIX(nd_node_id(data->node)); +} +#endif + #define NEW_CHILD(ast, node) node ? ast_new_internal(ast, node) : Qnil static VALUE @@ -695,4 +706,7 @@ Init_ast(void) rb_mAST = rb_define_module_under(rb_cRubyVM, "AbstractSyntaxTree"); rb_cNode = rb_define_class_under(rb_mAST, "Node", rb_cObject); rb_undef_alloc_func(rb_cNode); +#ifdef EXPERIMENTAL_ISEQ_NODE_ID + rb_define_method(rb_cNode, "node_id", ast_node_node_id, 0); +#endif } |