summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/ast.c b/ast.c
index 05bfc755a3..e180213ef7 100644
--- a/ast.c
+++ b/ast.c
@@ -196,14 +196,15 @@ static VALUE
ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script_lines)
{
VALUE path, node, lines = Qnil;
+ const rb_iseq_t *iseq;
int node_id;
if (rb_frame_info_p(body)) {
- rb_frame_info_get(body, &path, &lines, &node_id);
- if (NIL_P(path) && NIL_P(lines)) return Qnil;
+ iseq = rb_get_iseq_from_frame_info(body);
+ node_id = rb_get_node_id_from_frame_info(body);
}
else {
- const rb_iseq_t *iseq = NULL;
+ iseq = NULL;
if (rb_obj_is_proc(body)) {
iseq = vm_proc_iseq(body);
@@ -213,17 +214,20 @@ ast_s_of(rb_execution_context_t *ec, VALUE module, VALUE body, VALUE keep_script
else {
iseq = rb_method_iseq(body);
}
- if (!iseq) {
- return Qnil;
+ if (iseq) {
+ node_id = iseq->body->location.node_id;
}
- if (rb_iseq_from_eval_p(iseq)) {
- rb_raise(rb_eArgError, "cannot get AST for method defined in eval");
- }
- path = rb_iseq_path(iseq);
- lines = iseq->body->variable.script_lines;
- node_id = iseq->body->location.node_id;
}
+ if (!iseq) {
+ return Qnil;
+ }
+ if (rb_iseq_from_eval_p(iseq)) {
+ rb_raise(rb_eArgError, "cannot get AST for method defined in eval");
+ }
+ path = rb_iseq_path(iseq);
+ lines = iseq->body->variable.script_lines;
+
if (!NIL_P(lines) || !NIL_P(lines = script_lines(path))) {
node = rb_ast_parse_array(lines, keep_script_lines);
}