summaryrefslogtreecommitdiff
path: root/ast.c
diff options
context:
space:
mode:
authoryui-knk <[email protected]>2024-07-22 16:28:00 +0900
committerYuichiro Kaneko <[email protected]>2024-07-23 14:35:23 +0900
commit57b11be15ae518288b719fb36068ceb23da6e050 (patch)
tree9a772e11ab2a75c86a3df1f83e67247751b1679e /ast.c
parentf23485a8d693cb69fd7b84c1ab93cb4198ecfe4a (diff)
Implement UNLESS NODE keyword locations
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11227
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/ast.c b/ast.c
index 79458eb266..54d2ce1e11 100644
--- a/ast.c
+++ b/ast.c
@@ -747,12 +747,20 @@ ast_node_children(rb_execution_context_t *ec, VALUE self)
return node_children(data->ast_value, data->node);
}
+static int
+null_loc_p(rb_code_location_t *loc)
+{
+ return (loc->beg_pos.lineno == 0 && loc->beg_pos.column == -1 && loc->end_pos.lineno == 0 && loc->end_pos.column == -1);
+}
+
static VALUE
location_new(rb_code_location_t *loc)
{
VALUE obj;
struct ASTLocationData *data;
+ if (null_loc_p(loc)) return Qnil;
+
obj = TypedData_Make_Struct(rb_cLocation, struct ASTLocationData, &rb_location_type, data);
data->first_lineno = loc->beg_pos.lineno;
data->first_column = loc->beg_pos.column;
@@ -767,6 +775,12 @@ node_locations(VALUE ast_value, const NODE *node)
{
enum node_type type = nd_type(node);
switch (type) {
+ case NODE_UNLESS:
+ return rb_ary_new_from_args(4,
+ location_new(nd_code_loc(node)),
+ location_new(&RNODE_UNLESS(node)->keyword_loc),
+ location_new(&RNODE_UNLESS(node)->then_keyword_loc),
+ location_new(&RNODE_UNLESS(node)->end_keyword_loc));
case NODE_ARGS_AUX:
case NODE_LAST:
break;