From 7a1c497426c38c301e65c74a77b5eead98887eba Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 2 Aug 2023 10:08:59 -0400 Subject: [PATCH] [ruby/yarp] Add constant write node https://github.com/ruby/yarp/commit/a62f2f0153 --- test/yarp/snapshots/constants.txt | 6 +---- test/yarp/snapshots/methods.txt | 8 +++---- .../unparser/corpus/literal/assignment.txt | 8 +++---- test/yarp/snapshots/variables.txt | 8 +++---- .../snapshots/whitequark/casgn_unscoped.txt | 6 +---- .../snapshots/whitequark/parser_bug_490.txt | 8 +++---- yarp/yarp.c | 24 ++++++++++++++++++- 7 files changed, 41 insertions(+), 27 deletions(-) diff --git a/test/yarp/snapshots/constants.txt b/test/yarp/snapshots/constants.txt index aa97e4ba89..438f36599c 100644 --- a/test/yarp/snapshots/constants.txt +++ b/test/yarp/snapshots/constants.txt @@ -29,11 +29,7 @@ ProgramNode(0...709)( (26...27), IntegerNode(28...29)() ), - ConstantPathWriteNode(31...36)( - ConstantReadNode(31...32)(), - (33...34), - IntegerNode(35...36)() - ), + ConstantWriteNode(31...36)((31...32), IntegerNode(35...36)(), (33...34)), ConstantReadNode(38...41)(), CallNode(43...48)( nil, diff --git a/test/yarp/snapshots/methods.txt b/test/yarp/snapshots/methods.txt index 83bc7e3c5c..8d1eee8a2a 100644 --- a/test/yarp/snapshots/methods.txt +++ b/test/yarp/snapshots/methods.txt @@ -967,10 +967,10 @@ ProgramNode(0...1194)( nil, (872...875) ), - ConstantPathWriteNode(877...886)( - ConstantReadNode(877...882)(), - (883...884), - IntegerNode(885...886)() + ConstantWriteNode(877...886)( + (877...882), + IntegerNode(885...886)(), + (883...884) ), DefNode(888...903)( (898...899), diff --git a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt index 1e06024e29..2083fb361b 100644 --- a/test/yarp/snapshots/unparser/corpus/literal/assignment.txt +++ b/test/yarp/snapshots/unparser/corpus/literal/assignment.txt @@ -300,10 +300,10 @@ ProgramNode(0...719)( IntegerNode(315...316)(), (313...314) ), - ConstantPathWriteNode(317...326)( - ConstantReadNode(317...322)(), - (323...324), - IntegerNode(325...326)() + ConstantWriteNode(317...326)( + (317...322), + IntegerNode(325...326)(), + (323...324) ), ConstantPathWriteNode(327...350)( ConstantPathNode(327...346)( diff --git a/test/yarp/snapshots/variables.txt b/test/yarp/snapshots/variables.txt index 8976f74a38..73645e4e52 100644 --- a/test/yarp/snapshots/variables.txt +++ b/test/yarp/snapshots/variables.txt @@ -180,14 +180,14 @@ ProgramNode(0...293)( (260...263), (264...265) ), - ConstantPathWriteNode(272...282)( - ConstantReadNode(272...275)(), - (276...277), + ConstantWriteNode(272...282)( + (272...275), ArrayNode(278...282)( [IntegerNode(278...279)(), IntegerNode(281...282)()], nil, nil - ) + ), + (276...277) ), ParenthesesNode(284...293)( StatementsNode(285...292)( diff --git a/test/yarp/snapshots/whitequark/casgn_unscoped.txt b/test/yarp/snapshots/whitequark/casgn_unscoped.txt index 3687e38891..16c6636bb4 100644 --- a/test/yarp/snapshots/whitequark/casgn_unscoped.txt +++ b/test/yarp/snapshots/whitequark/casgn_unscoped.txt @@ -1,10 +1,6 @@ ProgramNode(0...8)( [], StatementsNode(0...8)( - [ConstantPathWriteNode(0...8)( - ConstantReadNode(0...3)(), - (4...5), - IntegerNode(6...8)() - )] + [ConstantWriteNode(0...8)((0...3), IntegerNode(6...8)(), (4...5))] ) ) diff --git a/test/yarp/snapshots/whitequark/parser_bug_490.txt b/test/yarp/snapshots/whitequark/parser_bug_490.txt index cd38544ea7..6f4c3a8442 100644 --- a/test/yarp/snapshots/whitequark/parser_bug_490.txt +++ b/test/yarp/snapshots/whitequark/parser_bug_490.txt @@ -12,10 +12,10 @@ ProgramNode(0...132)( (13...15), SelfNode(16...20)(), StatementsNode(22...29)( - [ConstantPathWriteNode(22...29)( - ConstantReadNode(22...23)(), - (24...25), - NilNode(26...29)() + [ConstantWriteNode(22...29)( + (22...23), + NilNode(26...29)(), + (24...25) )] ), (31...34) diff --git a/yarp/yarp.c b/yarp/yarp.c index 3d7fcd4595..747e6cef48 100644 --- a/yarp/yarp.c +++ b/yarp/yarp.c @@ -1699,6 +1699,27 @@ yp_constant_read_node_create(yp_parser_t *parser, const yp_token_t *name) { return node; } +// Allocate a new ConstantWriteNode node. +static yp_constant_write_node_t * +yp_constant_write_node_create(yp_parser_t *parser, yp_constant_read_node_t *target, const yp_token_t *operator, yp_node_t *value) { + yp_constant_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_write_node_t); + + *node = (yp_constant_write_node_t) { + { + .type = YP_NODE_CONSTANT_WRITE_NODE, + .location = { + .start = target->base.location.start, + .end = value != NULL ? value->location.end : target->base.location.end + }, + }, + .name_loc = YP_LOCATION_NODE_VALUE((yp_node_t *) target), + .operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator), + .value = value + }; + + return node; +} + // Allocate and initialize a new DefNode node. static yp_def_node_t * yp_def_node_create( @@ -7533,8 +7554,9 @@ parse_target(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_no return (yp_node_t *) write_node; } case YP_NODE_CONSTANT_PATH_NODE: - case YP_NODE_CONSTANT_READ_NODE: return (yp_node_t *) yp_constant_path_write_node_create(parser, target, operator, value); + case YP_NODE_CONSTANT_READ_NODE: + return (yp_node_t *) yp_constant_write_node_create(parser, (yp_constant_read_node_t *) target, operator, value); case YP_NODE_BACK_REFERENCE_READ_NODE: case YP_NODE_NUMBERED_REFERENCE_READ_NODE: yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, "Can't set variable");