[ruby/yarp] Add constant write node

https://github.com/ruby/yarp/commit/a62f2f0153
This commit is contained in:
Kevin Newton 2023-08-02 10:08:59 -04:00 committed by Takashi Kokubun
parent 9c61e0c831
commit 7a1c497426
Notes: git 2023-08-17 00:48:09 +00:00
7 changed files with 41 additions and 27 deletions

View File

@ -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,

View File

@ -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),

View File

@ -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)(

View File

@ -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)(

View File

@ -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))]
)
)

View File

@ -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)

View File

@ -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");