[ruby/yarp] Add global variables to the constant pool

https://github.com/ruby/yarp/commit/b48067b067
This commit is contained in:
Kevin Newton 2023-09-01 09:40:08 -04:00 committed by git
parent d1f83c37f8
commit c666077182
24 changed files with 111 additions and 65 deletions

View File

@ -62,7 +62,7 @@ module YARP
# #
# $foo && $foo = bar # $foo && $foo = bar
def visit_global_variable_and_write_node(node) def visit_global_variable_and_write_node(node)
desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode) desugar_and_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name])
end end
# $foo ||= bar # $foo ||= bar
@ -71,7 +71,7 @@ module YARP
# #
# defined?($foo) ? $foo : $foo = bar # defined?($foo) ? $foo : $foo = bar
def visit_global_variable_or_write_node(node) def visit_global_variable_or_write_node(node)
desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode) desugar_or_write_defined_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name])
end end
# $foo += bar # $foo += bar
@ -80,7 +80,7 @@ module YARP
# #
# $foo = $foo + bar # $foo = $foo + bar
def visit_global_variable_operator_write_node(node) def visit_global_variable_operator_write_node(node)
desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode) desugar_operator_write_node(node, GlobalVariableReadNode, GlobalVariableWriteNode, arguments: [node.name])
end end
# @foo &&= bar # @foo &&= bar

View File

@ -1006,8 +1006,8 @@ module YARP
expected = BeginNode( expected = BeginNode(
Location(), Location(),
StatementsNode([ StatementsNode([
GlobalVariableWriteNode(Location(), NilNode(), Location()), GlobalVariableWriteNode(:$+, Location(), NilNode(), Location()),
GlobalVariableWriteNode(Location(), NilNode(), Location()) GlobalVariableWriteNode(:$1466, Location(), NilNode(), Location())
]), ]),
nil, nil,
nil, nil,

View File

@ -31,7 +31,7 @@ ProgramNode(0...199)(
(61...66) (61...66)
), ),
AliasNode(86...97)( AliasNode(86...97)(
GlobalVariableReadNode(92...94)(), GlobalVariableReadNode(92...94)(:$a),
BackReferenceReadNode(95...97)(), BackReferenceReadNode(95...97)(),
(86...91) (86...91)
), ),
@ -41,8 +41,8 @@ ProgramNode(0...199)(
(99...104) (99...104)
), ),
AliasNode(114...129)( AliasNode(114...129)(
GlobalVariableReadNode(120...124)(), GlobalVariableReadNode(120...124)(:$foo),
GlobalVariableReadNode(125...129)(), GlobalVariableReadNode(125...129)(:$bar),
(114...119) (114...119)
), ),
AliasNode(131...143)( AliasNode(131...143)(

View File

@ -1,30 +1,30 @@
ProgramNode(0...349)( ProgramNode(0...349)(
[], [],
StatementsNode(0...349)( StatementsNode(0...349)(
[GlobalVariableReadNode(0...16)(), [GlobalVariableReadNode(0...16)(:$global_variable),
GlobalVariableReadNode(18...20)(), GlobalVariableReadNode(18...20)(:$_),
GlobalVariableReadNode(22...25)(), GlobalVariableReadNode(22...25)(:$-w),
GlobalVariableReadNode(27...37)(), GlobalVariableReadNode(27...37)(:$LOAD_PATH),
GlobalVariableReadNode(39...45)(), GlobalVariableReadNode(39...45)(:$stdin),
GlobalVariableReadNode(47...54)(), GlobalVariableReadNode(47...54)(:$stdout),
GlobalVariableReadNode(56...63)(), GlobalVariableReadNode(56...63)(:$stderr),
GlobalVariableReadNode(65...67)(), GlobalVariableReadNode(65...67)(:$!),
GlobalVariableReadNode(69...71)(), GlobalVariableReadNode(69...71)(:$?),
GlobalVariableReadNode(73...75)(), GlobalVariableReadNode(73...75)(:$~),
BackReferenceReadNode(77...79)(), BackReferenceReadNode(77...79)(),
BackReferenceReadNode(81...83)(), BackReferenceReadNode(81...83)(),
BackReferenceReadNode(85...87)(), BackReferenceReadNode(85...87)(),
BackReferenceReadNode(89...91)(), BackReferenceReadNode(89...91)(),
GlobalVariableReadNode(93...95)(), GlobalVariableReadNode(93...95)(:$:),
GlobalVariableReadNode(97...99)(), GlobalVariableReadNode(97...99)(:$;),
GlobalVariableReadNode(101...103)(), GlobalVariableReadNode(101...103)(:$,),
GlobalVariableReadNode(105...111)(), GlobalVariableReadNode(105...111)(:$DEBUG),
GlobalVariableReadNode(113...122)(), GlobalVariableReadNode(113...122)(:$FILENAME),
GlobalVariableReadNode(124...126)(), GlobalVariableReadNode(124...126)(:$0),
GlobalVariableReadNode(128...131)(), GlobalVariableReadNode(128...131)(:$-0),
GlobalVariableReadNode(133...149)(), GlobalVariableReadNode(133...149)(:$LOADED_FEATURES),
GlobalVariableReadNode(151...159)(), GlobalVariableReadNode(151...159)(:$VERBOSE),
GlobalVariableReadNode(161...164)(), GlobalVariableReadNode(161...164)(:$-K),
SymbolNode(166...183)((166...167), (167...183), nil, "$global_variable"), SymbolNode(166...183)((166...167), (167...183), nil, "$global_variable"),
SymbolNode(185...188)((185...186), (186...188), nil, "$_"), SymbolNode(185...188)((185...186), (186...188), nil, "$_"),
SymbolNode(190...194)((190...191), (191...194), nil, "$-w"), SymbolNode(190...194)((190...191), (191...194), nil, "$-w"),

View File

@ -173,7 +173,7 @@ ProgramNode(0...1194)(
), ),
DefNode(161...175)( DefNode(161...175)(
(170...171), (170...171),
GlobalVariableReadNode(165...169)(), GlobalVariableReadNode(165...169)(:$var),
nil, nil,
nil, nil,
[], [],

View File

@ -959,7 +959,7 @@ ProgramNode(0...3743)(
"foo" "foo"
), ),
PinnedVariableNode(988...993)( PinnedVariableNode(988...993)(
GlobalVariableReadNode(989...993)(), GlobalVariableReadNode(989...993)(:$bar),
(988...989) (988...989)
), ),
(985...987) (985...987)

View File

@ -21,7 +21,7 @@ ProgramNode(0...293)(
[StringNode(29...33)(nil, (29...33), nil, "aaa "), [StringNode(29...33)(nil, (29...33), nil, "aaa "),
EmbeddedVariableNode(33...38)( EmbeddedVariableNode(33...38)(
(33...34), (33...34),
GlobalVariableReadNode(34...38)() GlobalVariableReadNode(34...38)(:$bbb)
)], )],
(38...39), (38...39),
0 0

View File

@ -2,7 +2,7 @@ ProgramNode(0...15)(
[], [],
StatementsNode(0...15)( StatementsNode(0...15)(
[AliasNode(0...15)( [AliasNode(0...15)(
GlobalVariableReadNode(6...12)(), GlobalVariableReadNode(6...12)(:$MATCH),
BackReferenceReadNode(13...15)(), BackReferenceReadNode(13...15)(),
(0...5) (0...5)
)] )]

View File

@ -1,7 +1,12 @@
ProgramNode(0...22)( ProgramNode(0...22)(
[:测试], [:测试],
StatementsNode(0...22)( StatementsNode(0...22)(
[GlobalVariableWriteNode(0...11)((0...7), IntegerNode(10...11)(), (8...9)), [GlobalVariableWriteNode(0...11)(
:$测试,
(0...7),
IntegerNode(10...11)(),
(8...9)
),
LocalVariableWriteNode(12...22)( LocalVariableWriteNode(12...22)(
:测试, :测试,
0, 0,

View File

@ -498,7 +498,7 @@ ProgramNode(0...747)(
(628...629) (628...629)
), ),
PinnedVariableNode(633...636)( PinnedVariableNode(633...636)(
GlobalVariableReadNode(634...636)(), GlobalVariableReadNode(634...636)(:$b),
(633...634) (633...634)
), ),
PinnedVariableNode(638...642)( PinnedVariableNode(638...642)(

View File

@ -177,7 +177,7 @@ ProgramNode(0...498)(
(405...406), (405...406),
[EmbeddedVariableNode(406...411)( [EmbeddedVariableNode(406...411)(
(406...407), (406...407),
GlobalVariableReadNode(407...411)() GlobalVariableReadNode(407...411)(:$foo)
)], )],
(411...412) (411...412)
), ),

View File

@ -2,8 +2,8 @@ ProgramNode(0...31)(
[], [],
StatementsNode(0...31)( StatementsNode(0...31)(
[AliasNode(0...15)( [AliasNode(0...15)(
GlobalVariableReadNode(6...10)(), GlobalVariableReadNode(6...10)(:$foo),
GlobalVariableReadNode(11...15)(), GlobalVariableReadNode(11...15)(:$bar),
(0...5) (0...5)
), ),
AliasNode(16...31)( AliasNode(16...31)(

View File

@ -1,10 +1,15 @@
ProgramNode(0...704)( ProgramNode(0...704)(
[:a, :b, :foo, :c, :x], [:a, :b, :foo, :c, :x],
StatementsNode(0...704)( StatementsNode(0...704)(
[GlobalVariableWriteNode(0...6)((0...2), IntegerNode(5...6)(), (3...4)), [GlobalVariableWriteNode(0...6)(
:$a,
(0...2),
IntegerNode(5...6)(),
(3...4)
),
MultiWriteNode(7...24)( MultiWriteNode(7...24)(
[GlobalVariableTargetNode(8...10)(), [GlobalVariableTargetNode(8...10)(:$a),
GlobalVariableTargetNode(12...14)()], GlobalVariableTargetNode(12...14)(:$b)],
(16...17), (16...17),
ArrayNode(18...24)( ArrayNode(18...24)(
[IntegerNode(19...20)(), IntegerNode(22...23)()], [IntegerNode(19...20)(), IntegerNode(22...23)()],

View File

@ -66,7 +66,7 @@ ProgramNode(0...299)(
[StringNode(153...154)(nil, (153...154), nil, "a"), [StringNode(153...154)(nil, (153...154), nil, "a"),
EmbeddedVariableNode(154...157)( EmbeddedVariableNode(154...157)(
(154...155), (154...155),
GlobalVariableReadNode(155...157)() GlobalVariableReadNode(155...157)(:$a)
)], )],
(157...158) (157...158)
), ),

View File

@ -163,7 +163,7 @@ ProgramNode(0...916)(
StringNode(215...216)(nil, (215...216), nil, " "), StringNode(215...216)(nil, (215...216), nil, " "),
EmbeddedVariableNode(216...219)( EmbeddedVariableNode(216...219)(
(216...217), (216...217),
GlobalVariableReadNode(217...219)() GlobalVariableReadNode(217...219)(:$a)
)], )],
(219...220) (219...220)
), ),

View File

@ -4,7 +4,7 @@ ProgramNode(0...66)(
[CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"), [CallNode(0...1)(nil, nil, (0...1), nil, nil, nil, nil, 2, "a"),
InstanceVariableReadNode(2...4)(:@a), InstanceVariableReadNode(2...4)(:@a),
ClassVariableReadNode(5...8)(:@@a), ClassVariableReadNode(5...8)(:@@a),
GlobalVariableReadNode(9...11)(), GlobalVariableReadNode(9...11)(:$a),
NumberedReferenceReadNode(12...14)(1), NumberedReferenceReadNode(12...14)(1),
BackReferenceReadNode(15...17)(), BackReferenceReadNode(15...17)(),
ConstantReadNode(18...23)(), ConstantReadNode(18...23)(),

View File

@ -234,7 +234,7 @@ ProgramNode(0...608)(
[StringNode(587...588)(nil, (587...588), nil, "a"), [StringNode(587...588)(nil, (587...588), nil, "a"),
EmbeddedVariableNode(588...591)( EmbeddedVariableNode(588...591)(
(588...589), (588...589),
GlobalVariableReadNode(589...591)() GlobalVariableReadNode(589...591)(:$a)
)], )],
(591...592) (591...592)
), ),

View File

@ -27,11 +27,12 @@ ProgramNode(0...293)(
(42...43) (42...43)
), ),
GlobalVariableWriteNode(50...58)( GlobalVariableWriteNode(50...58)(
:$abc,
(50...54), (50...54),
IntegerNode(57...58)(), IntegerNode(57...58)(),
(55...56) (55...56)
), ),
GlobalVariableReadNode(60...64)(), GlobalVariableReadNode(60...64)(:$abc),
InstanceVariableReadNode(66...70)(:@abc), InstanceVariableReadNode(66...70)(:@abc),
InstanceVariableWriteNode(72...80)( InstanceVariableWriteNode(72...80)(
:@abc, :@abc,
@ -48,14 +49,15 @@ ProgramNode(0...293)(
(89...90) (89...90)
), ),
MultiWriteNode(94...108)( MultiWriteNode(94...108)(
[GlobalVariableTargetNode(94...98)(), [GlobalVariableTargetNode(94...98)(:$foo),
GlobalVariableTargetNode(100...104)()], GlobalVariableTargetNode(100...104)(:$bar)],
(105...106), (105...106),
IntegerNode(107...108)(), IntegerNode(107...108)(),
nil, nil,
nil nil
), ),
GlobalVariableWriteNode(110...121)( GlobalVariableWriteNode(110...121)(
:$foo,
(110...114), (110...114),
ArrayNode(117...121)( ArrayNode(117...121)(
[IntegerNode(117...118)(), IntegerNode(120...121)()], [IntegerNode(117...118)(), IntegerNode(120...121)()],

View File

@ -2,13 +2,13 @@ ProgramNode(0...24)(
[], [],
StatementsNode(0...24)( StatementsNode(0...24)(
[AliasNode(0...11)( [AliasNode(0...11)(
GlobalVariableReadNode(6...8)(), GlobalVariableReadNode(6...8)(:$a),
BackReferenceReadNode(9...11)(), BackReferenceReadNode(9...11)(),
(0...5) (0...5)
), ),
AliasNode(13...24)( AliasNode(13...24)(
GlobalVariableReadNode(19...21)(), GlobalVariableReadNode(19...21)(:$a),
GlobalVariableReadNode(22...24)(), GlobalVariableReadNode(22...24)(:$b),
(13...18) (13...18)
)] )]
) )

View File

@ -1,4 +1,4 @@
ProgramNode(0...4)( ProgramNode(0...4)(
[], [],
StatementsNode(0...4)([GlobalVariableReadNode(0...4)()]) StatementsNode(0...4)([GlobalVariableReadNode(0...4)(:$foo)])
) )

View File

@ -1,6 +1,11 @@
ProgramNode(0...9)( ProgramNode(0...9)(
[], [],
StatementsNode(0...9)( StatementsNode(0...9)(
[GlobalVariableWriteNode(0...9)((0...4), IntegerNode(7...9)(), (5...6))] [GlobalVariableWriteNode(0...9)(
:$var,
(0...4),
IntegerNode(7...9)(),
(5...6)
)]
) )
) )

View File

@ -15,7 +15,7 @@ ProgramNode(0...14)(
StringNode(9...10)(nil, (9...10), nil, " "), StringNode(9...10)(nil, (9...10), nil, " "),
EmbeddedVariableNode(10...13)( EmbeddedVariableNode(10...13)(
(10...11), (10...11),
GlobalVariableReadNode(11...13)() GlobalVariableReadNode(11...13)(:$a)
)], )],
(13...14) (13...14)
)] )]

View File

@ -1166,6 +1166,8 @@ nodes:
^^^^^ ^^^^^
- name: GlobalVariableAndWriteNode - name: GlobalVariableAndWriteNode
fields: fields:
- name: name
type: constant
- name: name_loc - name: name_loc
type: location type: location
- name: operator_loc - name: operator_loc
@ -1179,6 +1181,8 @@ nodes:
^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
- name: GlobalVariableOperatorWriteNode - name: GlobalVariableOperatorWriteNode
fields: fields:
- name: name
type: constant
- name: name_loc - name: name_loc
type: location type: location
- name: operator_loc - name: operator_loc
@ -1194,6 +1198,8 @@ nodes:
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
- name: GlobalVariableOrWriteNode - name: GlobalVariableOrWriteNode
fields: fields:
- name: name
type: constant
- name: name_loc - name: name_loc
type: location type: location
- name: operator_loc - name: operator_loc
@ -1206,12 +1212,18 @@ nodes:
$target ||= value $target ||= value
^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^
- name: GlobalVariableReadNode - name: GlobalVariableReadNode
fields:
- name: name
type: constant
comment: | comment: |
Represents referencing a global variable. Represents referencing a global variable.
$foo $foo
^^^^ ^^^^
- name: GlobalVariableTargetNode - name: GlobalVariableTargetNode
fields:
- name: name
type: constant
comment: | comment: |
Represents writing to a global variable in a context that doesn't have an explicit value. Represents writing to a global variable in a context that doesn't have an explicit value.
@ -1219,6 +1231,8 @@ nodes:
^^^^ ^^^^ ^^^^ ^^^^
- name: GlobalVariableWriteNode - name: GlobalVariableWriteNode
fields: fields:
- name: name
type: constant
- name: name_loc - name: name_loc
type: location type: location
- name: value - name: value

View File

@ -2310,10 +2310,23 @@ yp_hash_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *assoc
return node; return node;
} }
// Retrieve the name from a node that will become a global variable write node.
static yp_constant_id_t
yp_global_variable_write_name(yp_parser_t *parser, yp_node_t *target) {
if (YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE)) {
return ((yp_global_variable_read_node_t *) target)->name;
}
assert(YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE));
// This will only ever happen in the event of a syntax error, but we
// still need to provide something for the node.
return yp_parser_constant_id_location(parser, target->location.start, target->location.end);
}
// Allocate and initialize a new GlobalVariableAndWriteNode node. // Allocate and initialize a new GlobalVariableAndWriteNode node.
static yp_global_variable_and_write_node_t * static yp_global_variable_and_write_node_t *
yp_global_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_global_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE));
assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL); assert(operator->type == YP_TOKEN_AMPERSAND_AMPERSAND_EQUAL);
yp_global_variable_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_and_write_node_t); yp_global_variable_and_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_and_write_node_t);
@ -2325,6 +2338,7 @@ yp_global_variable_and_write_node_create(yp_parser_t *parser, yp_node_t *target,
.end = value->location.end .end = value->location.end
} }
}, },
.name = yp_global_variable_write_name(parser, target),
.name_loc = target->location, .name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value .value = value
@ -2346,6 +2360,7 @@ yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *ta
.end = value->location.end .end = value->location.end
} }
}, },
.name = yp_global_variable_write_name(parser, target),
.name_loc = target->location, .name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value, .value = value,
@ -2358,7 +2373,6 @@ yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *ta
// Allocate and initialize a new GlobalVariableOrWriteNode node. // Allocate and initialize a new GlobalVariableOrWriteNode node.
static yp_global_variable_or_write_node_t * static yp_global_variable_or_write_node_t *
yp_global_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) { yp_global_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
assert(YP_NODE_TYPE_P(target, YP_NODE_GLOBAL_VARIABLE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_BACK_REFERENCE_READ_NODE) || YP_NODE_TYPE_P(target, YP_NODE_NUMBERED_REFERENCE_READ_NODE));
assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL); assert(operator->type == YP_TOKEN_PIPE_PIPE_EQUAL);
yp_global_variable_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_or_write_node_t); yp_global_variable_or_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_or_write_node_t);
@ -2370,6 +2384,7 @@ yp_global_variable_or_write_node_create(yp_parser_t *parser, yp_node_t *target,
.end = value->location.end .end = value->location.end
} }
}, },
.name = yp_global_variable_write_name(parser, target),
.name_loc = target->location, .name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator), .operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value .value = value
@ -2387,7 +2402,8 @@ yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name)
{ {
.type = YP_NODE_GLOBAL_VARIABLE_READ_NODE, .type = YP_NODE_GLOBAL_VARIABLE_READ_NODE,
.location = YP_LOCATION_TOKEN_VALUE(name), .location = YP_LOCATION_TOKEN_VALUE(name),
} },
.name = yp_parser_constant_id_location(parser, name->start, name->end)
}; };
return node; return node;
@ -2395,18 +2411,19 @@ yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name)
// Allocate a new GlobalVariableWriteNode node. // Allocate a new GlobalVariableWriteNode node.
static yp_global_variable_write_node_t * static yp_global_variable_write_node_t *
yp_global_variable_write_node_create(yp_parser_t *parser, const yp_location_t *name_loc, const yp_token_t *operator, yp_node_t *value) { yp_global_variable_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_global_variable_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_write_node_t); yp_global_variable_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_write_node_t);
*node = (yp_global_variable_write_node_t) { *node = (yp_global_variable_write_node_t) {
{ {
.type = YP_NODE_GLOBAL_VARIABLE_WRITE_NODE, .type = YP_NODE_GLOBAL_VARIABLE_WRITE_NODE,
.location = { .location = {
.start = name_loc->start, .start = target->location.start,
.end = value->location.end .end = value->location.end
}, },
}, },
.name_loc = *name_loc, .name = yp_global_variable_write_name(parser, target),
.name_loc = YP_LOCATION_NODE_VALUE(target),
.operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator), .operator_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(operator),
.value = value .value = value
}; };
@ -8068,16 +8085,15 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod
case YP_NODE_MISSING_NODE: case YP_NODE_MISSING_NODE:
return target; return target;
case YP_NODE_CLASS_VARIABLE_READ_NODE: { case YP_NODE_CLASS_VARIABLE_READ_NODE: {
yp_class_variable_write_node_t *write_node = yp_class_variable_write_node_create(parser, (yp_class_variable_read_node_t *) target, operator, value); yp_class_variable_write_node_t *node = yp_class_variable_write_node_create(parser, (yp_class_variable_read_node_t *) target, operator, value);
yp_node_destroy(parser, target); yp_node_destroy(parser, target);
return (yp_node_t *) write_node; return (yp_node_t *) node;
} }
case YP_NODE_CONSTANT_PATH_NODE: case YP_NODE_CONSTANT_PATH_NODE:
return (yp_node_t *) yp_constant_path_write_node_create(parser, (yp_constant_path_node_t *) target, operator, value); return (yp_node_t *) yp_constant_path_write_node_create(parser, (yp_constant_path_node_t *) target, operator, value);
case YP_NODE_CONSTANT_READ_NODE: { case YP_NODE_CONSTANT_READ_NODE: {
yp_constant_write_node_t *node = yp_constant_write_node_create(parser, &target->location, operator, value); yp_constant_write_node_t *node = yp_constant_write_node_create(parser, &target->location, operator, value);
yp_node_destroy(parser, target); yp_node_destroy(parser, target);
return (yp_node_t *) node; return (yp_node_t *) node;
} }
case YP_NODE_BACK_REFERENCE_READ_NODE: case YP_NODE_BACK_REFERENCE_READ_NODE:
@ -8085,10 +8101,9 @@ parse_write(yp_parser_t *parser, yp_node_t *target, yp_token_t *operator, yp_nod
yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, "Can't set variable"); yp_diagnostic_list_append(&parser->error_list, target->location.start, target->location.end, "Can't set variable");
/* fallthrough */ /* fallthrough */
case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { case YP_NODE_GLOBAL_VARIABLE_READ_NODE: {
yp_global_variable_write_node_t *result = yp_global_variable_write_node_create(parser, &target->location, operator, value); yp_global_variable_write_node_t *node = yp_global_variable_write_node_create(parser, target, operator, value);
yp_node_destroy(parser, target); yp_node_destroy(parser, target);
return (yp_node_t *) node;
return (yp_node_t *) result;
} }
case YP_NODE_LOCAL_VARIABLE_READ_NODE: { case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
yp_local_variable_read_node_t *local_read = (yp_local_variable_read_node_t *) target; yp_local_variable_read_node_t *local_read = (yp_local_variable_read_node_t *) target;