[ruby/yarp] Consolidate operator write nodes

https://github.com/ruby/yarp/commit/22b287e2b1
This commit is contained in:
Kevin Newton 2023-08-18 15:18:34 -04:00 committed by git
parent ec47fc9539
commit 07833049df
19 changed files with 166 additions and 433 deletions

View File

@ -209,10 +209,6 @@ module YARP
assert_location(ClassNode, "class Foo < Bar end") assert_location(ClassNode, "class Foo < Bar end")
end end
def test_ClassVariableOperatorWriteNode
assert_location(ClassVariableOperatorWriteNode, "@@foo += bar")
end
def test_ClassVariableReadNode def test_ClassVariableReadNode
assert_location(ClassVariableReadNode, "@@foo") assert_location(ClassVariableReadNode, "@@foo")
end end
@ -233,14 +229,6 @@ module YARP
assert_location(ConstantPathWriteNode, "::Foo::Bar = baz") assert_location(ConstantPathWriteNode, "::Foo::Bar = baz")
end end
def test_ConstantPathOperatorWriteNode
assert_location(ConstantPathOperatorWriteNode, "Parent::Child += bar")
end
def test_ConstantOperatorWriteNode
assert_location(ConstantOperatorWriteNode, "Foo += bar")
end
def test_ConstantReadNode def test_ConstantReadNode
assert_location(ConstantReadNode, "Foo") assert_location(ConstantReadNode, "Foo")
assert_location(ConstantReadNode, "Foo::Bar", 5...8, &:child) assert_location(ConstantReadNode, "Foo::Bar", 5...8, &:child)
@ -314,10 +302,6 @@ module YARP
assert_location(ForwardingSuperNode, "super {}") assert_location(ForwardingSuperNode, "super {}")
end end
def test_GlobalVariableOperatorWriteNode
assert_location(GlobalVariableOperatorWriteNode, "$foo += bar")
end
def test_GlobalVariableReadNode def test_GlobalVariableReadNode
assert_location(GlobalVariableReadNode, "$foo") assert_location(GlobalVariableReadNode, "$foo")
end end
@ -352,10 +336,6 @@ module YARP
end end
end end
def test_InstanceVariableOperatorWriteNode
assert_location(InstanceVariableOperatorWriteNode, "@foo += bar")
end
def test_InstanceVariableReadNode def test_InstanceVariableReadNode
assert_location(InstanceVariableReadNode, "@foo") assert_location(InstanceVariableReadNode, "@foo")
end end
@ -422,12 +402,6 @@ module YARP
assert_location(LambdaNode, "-> do foo end") assert_location(LambdaNode, "-> do foo end")
end end
def test_LocalVariableOperatorWriteNode
assert_location(LocalVariableOperatorWriteNode, "foo += bar")
assert_location(LocalVariableOperatorWriteNode, "foo = 1; foo += bar", 9...19)
end
def test_LocalVariableReadNode def test_LocalVariableReadNode
assert_location(LocalVariableReadNode, "foo = 1; foo", 9...12) assert_location(LocalVariableReadNode, "foo = 1; foo", 9...12)
end end
@ -471,6 +445,16 @@ module YARP
assert_location(NumberedReferenceReadNode, "$1") assert_location(NumberedReferenceReadNode, "$1")
end end
def test_OperatorWriteNode
assert_location(OperatorWriteNode, "@@foo += bar")
assert_location(OperatorWriteNode, "Parent::Child += bar")
assert_location(OperatorWriteNode, "Foo += bar")
assert_location(OperatorWriteNode, "$foo += bar")
assert_location(OperatorWriteNode, "@foo += bar")
assert_location(OperatorWriteNode, "foo += bar")
assert_location(OperatorWriteNode, "foo = 1; foo += bar", 9...19)
end
def test_OptionalParameterNode def test_OptionalParameterNode
assert_location(OptionalParameterNode, "def foo(bar = nil); end", 8...17) do |node| assert_location(OptionalParameterNode, "def foo(bar = nil); end", 8...17) do |node|
node.parameters.optionals.first node.parameters.optionals.first

View File

@ -88,12 +88,11 @@ ProgramNode(0...402)(
(61...62) (61...62)
), ),
StatementsNode(63...72)( StatementsNode(63...72)(
[LocalVariableOperatorWriteNode(63...72)( [OperatorWriteNode(63...72)(
(63...67), LocalVariableReadNode(63...67)(:memo, 0),
(68...70), (68...70),
LocalVariableReadNode(71...72)(:x, 0), :+,
:memo, LocalVariableReadNode(71...72)(:x, 0)
:+
)] )]
), ),
(51...52), (51...52),

View File

@ -6,12 +6,11 @@ ProgramNode(0...24)(
CallNode(6...7)(nil, nil, (6...7), nil, nil, nil, nil, 2, "b"), CallNode(6...7)(nil, nil, (6...7), nil, nil, nil, nil, 2, "b"),
(2...5) (2...5)
), ),
LocalVariableOperatorWriteNode(9...15)( OperatorWriteNode(9...15)(
(9...10), LocalVariableReadNode(9...10)(:a, 0),
(11...13), (11...13),
CallNode(14...15)(nil, nil, (14...15), nil, nil, nil, nil, 2, "b"), :+,
:a, CallNode(14...15)(nil, nil, (14...15), nil, nil, nil, nil, 2, "b")
:+
), ),
OrWriteNode(17...24)( OrWriteNode(17...24)(
LocalVariableReadNode(17...18)(:a, 0), LocalVariableReadNode(17...18)(:a, 0),

View File

@ -8,12 +8,11 @@ ProgramNode(0...78)(
), ),
DefinedNode(27...43)( DefinedNode(27...43)(
(35...36), (35...36),
LocalVariableOperatorWriteNode(36...42)( OperatorWriteNode(36...42)(
(36...37), LocalVariableReadNode(36...37)(:x, 0),
(38...40), (38...40),
IntegerNode(41...42)(), :%,
:x, IntegerNode(41...42)()
:%
), ),
(42...43), (42...43),
(27...35) (27...35)

View File

@ -1,11 +1,11 @@
ProgramNode(0...8)( ProgramNode(0...8)(
[], [],
StatementsNode(0...8)( StatementsNode(0...8)(
[ConstantPathOperatorWriteNode(0...8)( [OperatorWriteNode(0...8)(
ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
(4...6), (4...6),
IntegerNode(7...8)(), :&,
:& IntegerNode(7...8)()
)] )]
) )
) )

View File

@ -9,13 +9,14 @@ ProgramNode(0...15)(
ArgumentsNode(2...15)( ArgumentsNode(2...15)(
[ParenthesesNode(2...15)( [ParenthesesNode(2...15)(
StatementsNode(3...14)( StatementsNode(3...14)(
[ConstantPathOperatorWriteNode(3...14)( [OperatorWriteNode(3...14)(
ConstantPathNode(3...7)( ConstantPathNode(3...7)(
ConstantReadNode(3...4)(), ConstantReadNode(3...4)(),
ConstantReadNode(6...7)(), ConstantReadNode(6...7)(),
(4...6) (4...6)
), ),
(8...10), (8...10),
:*,
CallNode(11...14)( CallNode(11...14)(
nil, nil,
nil, nil,
@ -38,8 +39,7 @@ ProgramNode(0...15)(
nil, nil,
0, 0,
"d" "d"
), )
:*
)] )]
), ),
(2...3), (2...3),

View File

@ -1,13 +1,14 @@
ProgramNode(0...11)( ProgramNode(0...11)(
[], [],
StatementsNode(0...11)( StatementsNode(0...11)(
[ConstantPathOperatorWriteNode(0...11)( [OperatorWriteNode(0...11)(
ConstantPathNode(0...4)( ConstantPathNode(0...4)(
ConstantReadNode(0...1)(), ConstantReadNode(0...1)(),
ConstantReadNode(3...4)(), ConstantReadNode(3...4)(),
(1...3) (1...3)
), ),
(5...7), (5...7),
:*,
CallNode(8...11)( CallNode(8...11)(
nil, nil,
nil, nil,
@ -20,8 +21,7 @@ ProgramNode(0...11)(
nil, nil,
0, 0,
"c" "c"
), )
:*
)] )]
) )
) )

View File

@ -25,12 +25,11 @@ ProgramNode(0...40)(
0, 0,
"p" "p"
), ),
LocalVariableOperatorWriteNode(18...24)( OperatorWriteNode(18...24)(
(18...19), LocalVariableReadNode(18...19)(:y, 0),
(20...22), (20...22),
IntegerNode(23...24)(), :*,
:y, IntegerNode(23...24)()
:*
), ),
ReturnNode(27...35)( ReturnNode(27...35)(
(27...33), (27...33),

View File

@ -1,12 +1,11 @@
ProgramNode(6...34)( ProgramNode(6...34)(
[:foo], [:foo],
StatementsNode(6...34)( StatementsNode(6...34)(
[LocalVariableOperatorWriteNode(6...24)( [OperatorWriteNode(6...24)(
(6...9), LocalVariableReadNode(6...9)(:foo, 0),
(10...12), (10...12),
CallNode(21...24)(nil, nil, (21...24), nil, nil, nil, nil, 2, "bar"), :+,
:foo, CallNode(21...24)(nil, nil, (21...24), nil, nil, nil, nil, 2, "bar")
:+
), ),
CallNode(31...34)(nil, nil, (31...34), nil, nil, nil, nil, 2, "baz")] CallNode(31...34)(nil, nil, (31...34), nil, nil, nil, nil, 2, "baz")]
) )

View File

@ -1,40 +1,35 @@
ProgramNode(0...233)( ProgramNode(0...233)(
[:a, :h], [:a, :h],
StatementsNode(0...233)( StatementsNode(0...233)(
[LocalVariableOperatorWriteNode(0...6)( [OperatorWriteNode(0...6)(
(0...1), LocalVariableReadNode(0...1)(:a, 0),
(2...4), (2...4),
IntegerNode(5...6)(), :+,
:a, IntegerNode(5...6)()
:+
), ),
LocalVariableOperatorWriteNode(7...13)( OperatorWriteNode(7...13)(
(7...8), LocalVariableReadNode(7...8)(:a, 0),
(9...11), (9...11),
IntegerNode(12...13)(), :-,
:a, IntegerNode(12...13)()
:-
), ),
LocalVariableOperatorWriteNode(14...21)( OperatorWriteNode(14...21)(
(14...15), LocalVariableReadNode(14...15)(:a, 0),
(16...19), (16...19),
IntegerNode(20...21)(), :**,
:a, IntegerNode(20...21)()
:**
), ),
LocalVariableOperatorWriteNode(22...28)( OperatorWriteNode(22...28)(
(22...23), LocalVariableReadNode(22...23)(:a, 0),
(24...26), (24...26),
IntegerNode(27...28)(), :*,
:a, IntegerNode(27...28)()
:*
), ),
LocalVariableOperatorWriteNode(29...35)( OperatorWriteNode(29...35)(
(29...30), LocalVariableReadNode(29...30)(:a, 0),
(31...33), (31...33),
IntegerNode(34...35)(), :/,
:a, IntegerNode(34...35)()
:/
), ),
AndWriteNode(36...43)( AndWriteNode(36...43)(
LocalVariableReadNode(36...37)(:a, 0), LocalVariableReadNode(36...37)(:a, 0),

View File

@ -1,27 +1,27 @@
ProgramNode(0...77)( ProgramNode(0...77)(
[], [],
StatementsNode(0...77)( StatementsNode(0...77)(
[ConstantPathOperatorWriteNode(0...8)( [OperatorWriteNode(0...8)(
ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)), ConstantPathNode(0...3)(nil, ConstantReadNode(2...3)(), (0...2)),
(4...6), (4...6),
IntegerNode(7...8)(), :+,
:+ IntegerNode(7...8)()
), ),
ConstantOperatorWriteNode(10...16)( OperatorWriteNode(10...16)(
(10...11), ConstantReadNode(10...11)(),
(12...14), (12...14),
IntegerNode(15...16)(), :+,
:+ IntegerNode(15...16)()
), ),
ConstantPathOperatorWriteNode(18...27)( OperatorWriteNode(18...27)(
ConstantPathNode(18...22)( ConstantPathNode(18...22)(
ConstantReadNode(18...19)(), ConstantReadNode(18...19)(),
ConstantReadNode(21...22)(), ConstantReadNode(21...22)(),
(19...21) (19...21)
), ),
(23...25), (23...25),
IntegerNode(26...27)(), :+,
:+ IntegerNode(26...27)()
), ),
DefNode(29...50)( DefNode(29...50)(
(33...34), (33...34),

View File

@ -77,13 +77,14 @@ ProgramNode(0...64)(
), ),
:+ :+
), ),
ConstantPathOperatorWriteNode(32...47)( OperatorWriteNode(32...47)(
ConstantPathNode(32...38)( ConstantPathNode(32...38)(
CallNode(32...35)(nil, nil, (32...35), nil, nil, nil, nil, 2, "foo"), CallNode(32...35)(nil, nil, (32...35), nil, nil, nil, nil, 2, "foo"),
ConstantReadNode(37...38)(), ConstantReadNode(37...38)(),
(35...37) (35...37)
), ),
(39...41), (39...41),
:+,
CallNode(42...47)( CallNode(42...47)(
nil, nil,
nil, nil,
@ -106,8 +107,7 @@ ProgramNode(0...64)(
nil, nil,
0, 0,
"m" "m"
), )
:+
), ),
CallOperatorWriteNode(49...64)( CallOperatorWriteNode(49...64)(
CallNode(49...55)( CallNode(49...55)(

View File

@ -1,16 +1,15 @@
ProgramNode(0...22)( ProgramNode(0...22)(
[:foo], [:foo],
StatementsNode(0...22)( StatementsNode(0...22)(
[LocalVariableOperatorWriteNode(0...22)( [OperatorWriteNode(0...22)(
(0...3), LocalVariableReadNode(0...3)(:foo, 0),
(4...6), (4...6),
:+,
RescueModifierNode(7...22)( RescueModifierNode(7...22)(
CallNode(7...11)(nil, nil, (7...11), nil, nil, nil, nil, 2, "meth"), CallNode(7...11)(nil, nil, (7...11), nil, nil, nil, nil, 2, "meth"),
(12...18), (12...18),
CallNode(19...22)(nil, nil, (19...22), nil, nil, nil, nil, 2, "bar") CallNode(19...22)(nil, nil, (19...22), nil, nil, nil, nil, 2, "bar")
), )
:foo,
:+
)] )]
) )
) )

View File

@ -1,9 +1,10 @@
ProgramNode(0...437)( ProgramNode(0...437)(
[:foo], [:foo],
StatementsNode(0...437)( StatementsNode(0...437)(
[LocalVariableOperatorWriteNode(0...27)( [OperatorWriteNode(0...27)(
(0...3), LocalVariableReadNode(0...3)(:foo, 0),
(4...6), (4...6),
:+,
CallNode(7...27)( CallNode(7...27)(
nil, nil,
nil, nil,
@ -30,13 +31,12 @@ ProgramNode(0...437)(
nil, nil,
0, 0,
"raise" "raise"
)
), ),
:foo, OperatorWriteNode(29...57)(
:+ LocalVariableReadNode(29...32)(:foo, 0),
),
LocalVariableOperatorWriteNode(29...57)(
(29...32),
(33...35), (33...35),
:+,
RescueModifierNode(36...57)( RescueModifierNode(36...57)(
CallNode(36...46)( CallNode(36...46)(
nil, nil,
@ -63,9 +63,7 @@ ProgramNode(0...437)(
), ),
(47...53), (47...53),
NilNode(54...57)() NilNode(54...57)()
), )
:foo,
:+
), ),
LocalVariableWriteNode(59...85)( LocalVariableWriteNode(59...85)(
:foo, :foo,

View File

@ -1,12 +1,14 @@
ProgramNode(0...74)( ProgramNode(0...74)(
[:a, :b], [:a, :b],
StatementsNode(0...74)( StatementsNode(0...74)(
[LocalVariableOperatorWriteNode(0...18)( [OperatorWriteNode(0...18)(
(0...1), LocalVariableReadNode(0...1)(:a, 0),
(2...4), (2...4),
LocalVariableOperatorWriteNode(5...18)( :+,
(5...6), OperatorWriteNode(5...18)(
LocalVariableReadNode(5...6)(:b, 0),
(7...9), (7...9),
:+,
CallNode(10...18)( CallNode(10...18)(
nil, nil,
nil, nil,
@ -19,16 +21,13 @@ ProgramNode(0...74)(
nil, nil,
0, 0,
"raise" "raise"
)
)
), ),
:b, OperatorWriteNode(20...37)(
:+ LocalVariableReadNode(20...21)(:a, 0),
),
:a,
:+
),
LocalVariableOperatorWriteNode(20...37)(
(20...21),
(22...24), (22...24),
:+,
LocalVariableWriteNode(25...37)( LocalVariableWriteNode(25...37)(
:b, :b,
0, 0,
@ -47,16 +46,15 @@ ProgramNode(0...74)(
), ),
(25...26), (25...26),
(27...28) (27...28)
), )
:a,
:+
), ),
LocalVariableWriteNode(39...56)( LocalVariableWriteNode(39...56)(
:a, :a,
0, 0,
LocalVariableOperatorWriteNode(43...56)( OperatorWriteNode(43...56)(
(43...44), LocalVariableReadNode(43...44)(:b, 0),
(45...47), (45...47),
:+,
CallNode(48...56)( CallNode(48...56)(
nil, nil,
nil, nil,
@ -69,9 +67,7 @@ ProgramNode(0...74)(
nil, nil,
0, 0,
"raise" "raise"
), )
:b,
:+
), ),
(39...40), (39...40),
(41...42) (41...42)

View File

@ -1,35 +1,34 @@
ProgramNode(0...53)( ProgramNode(0...53)(
[:a], [:a],
StatementsNode(0...53)( StatementsNode(0...53)(
[ClassVariableOperatorWriteNode(0...11)( [OperatorWriteNode(0...11)(
(0...5), ClassVariableReadNode(0...5)(),
(6...8), (6...8),
IntegerNode(9...11)(), :|,
:| IntegerNode(9...11)()
), ),
InstanceVariableOperatorWriteNode(13...20)( OperatorWriteNode(13...20)(
(13...15), InstanceVariableReadNode(13...15)(),
(16...18), (16...18),
IntegerNode(19...20)(), :|,
:| IntegerNode(19...20)()
), ),
LocalVariableOperatorWriteNode(22...28)( OperatorWriteNode(22...28)(
(22...23), LocalVariableReadNode(22...23)(:a, 0),
(24...26), (24...26),
IntegerNode(27...28)(), :+,
:a, IntegerNode(27...28)()
:+
), ),
DefNode(30...53)( DefNode(30...53)(
(34...35), (34...35),
nil, nil,
nil, nil,
StatementsNode(37...48)( StatementsNode(37...48)(
[ClassVariableOperatorWriteNode(37...48)( [OperatorWriteNode(37...48)(
(37...42), ClassVariableReadNode(37...42)(),
(43...45), (43...45),
IntegerNode(46...48)(), :|,
:| IntegerNode(46...48)()
)] )]
), ),
[], [],

View File

@ -1,9 +1,10 @@
ProgramNode(0...12)( ProgramNode(0...12)(
[:foo], [:foo],
StatementsNode(0...12)( StatementsNode(0...12)(
[LocalVariableOperatorWriteNode(0...12)( [OperatorWriteNode(0...12)(
(0...3), LocalVariableReadNode(0...3)(:foo, 0),
(4...6), (4...6),
:+,
CallNode(7...12)( CallNode(7...12)(
nil, nil,
nil, nil,
@ -14,9 +15,7 @@ ProgramNode(0...12)(
nil, nil,
0, 0,
"m" "m"
), )
:foo,
:+
)] )]
) )
) )

View File

@ -736,21 +736,6 @@ nodes:
class Foo end class Foo end
^^^^^^^^^^^^^ ^^^^^^^^^^^^^
- name: ClassVariableOperatorWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to a class variable using an operator that isn't `=`.
@@target += value
^^^^^^^^^^^^^^^^^
- name: ClassVariableReadNode - name: ClassVariableReadNode
comment: | comment: |
Represents referencing a class variable. Represents referencing a class variable.
@ -770,21 +755,6 @@ nodes:
@@foo = 1 @@foo = 1
^^^^^^^^^ ^^^^^^^^^
- name: ConstantOperatorWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to a constant using an operator that isn't `=`.
Target += value
^^^^^^^^^^^^^^^
- name: ConstantPathNode - name: ConstantPathNode
child_nodes: child_nodes:
- name: parent - name: parent
@ -798,22 +768,6 @@ nodes:
Foo::Bar Foo::Bar
^^^^^^^^ ^^^^^^^^
- name: ConstantPathOperatorWriteNode
child_nodes:
- name: target
type: node
kind: ConstantPathNode
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to a constant path using an operator that isn't `=`.
Parent::Child += value
^^^^^^^^^^^^^^^^^^^^^^
- name: ConstantPathWriteNode - name: ConstantPathWriteNode
child_nodes: child_nodes:
- name: target - name: target
@ -1056,21 +1010,6 @@ nodes:
super super
^^^^^ ^^^^^
- name: GlobalVariableOperatorWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to a global variable using an operator that isn't `=`.
$target += value
^^^^^^^^^^^^^^^^
- name: GlobalVariableReadNode - name: GlobalVariableReadNode
comment: | comment: |
Represents referencing a global variable. Represents referencing a global variable.
@ -1170,21 +1109,6 @@ nodes:
case a; in b then c end case a; in b then c end
^^^^^^^^^^^ ^^^^^^^^^^^
- name: InstanceVariableOperatorWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: operator
type: constant
comment: |
Represents assigning to an instance variable using an operator that isn't `=`.
@target += value
^^^^^^^^^^^^^^^^
- name: InstanceVariableReadNode - name: InstanceVariableReadNode
comment: | comment: |
Represents referencing an instance variable. Represents referencing an instance variable.
@ -1322,23 +1246,6 @@ nodes:
->(value) { value * 2 } ->(value) { value * 2 }
^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^
- name: LocalVariableOperatorWriteNode
child_nodes:
- name: name_loc
type: location
- name: operator_loc
type: location
- name: value
type: node
- name: constant_id
type: constant
- name: operator_id
type: constant
comment: |
Represents assigning to a local variable using an operator that isn't `=`.
target += value
^^^^^^^^^^^^^^^
- name: LocalVariableReadNode - name: LocalVariableReadNode
child_nodes: child_nodes:
- name: constant_id - name: constant_id
@ -1469,6 +1376,21 @@ nodes:
$1 $1
^^ ^^
- name: OperatorWriteNode
child_nodes:
- name: target
type: node
- name: operator_loc
type: location
- name: operator
type: constant
- name: value
type: node
comment: |
Represents the use of an operator on a write.
target += value
^^^^^^^^^^^^^^^
- name: OptionalParameterNode - name: OptionalParameterNode
child_nodes: child_nodes:
- name: constant_id - name: constant_id

View File

@ -1506,28 +1506,6 @@ yp_class_node_create(yp_parser_t *parser, yp_constant_id_list_t *locals, const y
return node; return node;
} }
// Allocate and initialize a new ClassVariableOperatorWriteNode node.
static yp_class_variable_operator_write_node_t *
yp_class_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_class_variable_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_class_variable_operator_write_node_t);
*node = (yp_class_variable_operator_write_node_t) {
{
.type = YP_NODE_CLASS_VARIABLE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new ClassVariableReadNode node. // Allocate and initialize a new ClassVariableReadNode node.
static yp_class_variable_read_node_t * static yp_class_variable_read_node_t *
yp_class_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) { yp_class_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) {
@ -1558,28 +1536,6 @@ yp_class_variable_read_node_to_class_variable_write_node(yp_parser_t *parser, yp
return node; return node;
} }
// Allocate and initialize a new ConstantPathOperatorWriteNode node.
static yp_constant_path_operator_write_node_t *
yp_constant_path_operator_write_node_create(yp_parser_t *parser, yp_constant_path_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_constant_path_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_path_operator_write_node_t);
*node = (yp_constant_path_operator_write_node_t) {
{
.type = YP_NODE_CONSTANT_PATH_OPERATOR_WRITE_NODE,
.location = {
.start = target->base.location.start,
.end = value->location.end
}
},
.target = target,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new ConstantPathNode node. // Allocate and initialize a new ConstantPathNode node.
static yp_constant_path_node_t * static yp_constant_path_node_t *
yp_constant_path_node_create(yp_parser_t *parser, yp_node_t *parent, const yp_token_t *delimiter, yp_node_t *child) { yp_constant_path_node_create(yp_parser_t *parser, yp_node_t *parent, const yp_token_t *delimiter, yp_node_t *child) {
@ -1622,28 +1578,6 @@ yp_constant_path_write_node_create(yp_parser_t *parser, yp_constant_path_node_t
return node; return node;
} }
// Allocate and initialize a new ConstantOperatorWriteNode node.
static yp_constant_operator_write_node_t *
yp_constant_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_constant_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_constant_operator_write_node_t);
*node = (yp_constant_operator_write_node_t) {
{
.type = YP_NODE_CONSTANT_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new ConstantReadNode node. // Allocate and initialize a new ConstantReadNode node.
static yp_constant_read_node_t * static yp_constant_read_node_t *
yp_constant_read_node_create(yp_parser_t *parser, const yp_token_t *name) { yp_constant_read_node_create(yp_parser_t *parser, const yp_token_t *name) {
@ -2078,28 +2012,6 @@ yp_hash_pattern_node_node_list_create(yp_parser_t *parser, yp_node_list_t *assoc
return node; return node;
} }
// Allocate and initialize a new GlobalVariableOperatorWriteNode node.
static yp_global_variable_operator_write_node_t *
yp_global_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_global_variable_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_global_variable_operator_write_node_t);
*node = (yp_global_variable_operator_write_node_t) {
{
.type = YP_NODE_GLOBAL_VARIABLE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate a new GlobalVariableReadNode node. // Allocate a new GlobalVariableReadNode node.
static yp_global_variable_read_node_t * static yp_global_variable_read_node_t *
yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name) { yp_global_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name) {
@ -2390,28 +2302,6 @@ yp_in_node_create(yp_parser_t *parser, yp_node_t *pattern, yp_statements_node_t
return node; return node;
} }
// Allocate and initialize a new InstanceVariableOperatorWriteNode node.
static yp_instance_variable_operator_write_node_t *
yp_instance_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_instance_variable_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_instance_variable_operator_write_node_t);
*node = (yp_instance_variable_operator_write_node_t) {
{
.type = YP_NODE_INSTANCE_VARIABLE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate and initialize a new InstanceVariableReadNode node. // Allocate and initialize a new InstanceVariableReadNode node.
static yp_instance_variable_read_node_t * static yp_instance_variable_read_node_t *
yp_instance_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) { yp_instance_variable_read_node_create(yp_parser_t *parser, const yp_token_t *token) {
@ -2685,29 +2575,6 @@ yp_lambda_node_create(
return node; return node;
} }
// Allocate and initialize a new LocalVariableOperatorWriteNode node.
static yp_local_variable_operator_write_node_t *
yp_local_variable_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value, yp_constant_id_t constant_id) {
yp_local_variable_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_local_variable_operator_write_node_t);
*node = (yp_local_variable_operator_write_node_t) {
{
.type = YP_NODE_LOCAL_VARIABLE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
}
},
.name_loc = target->location,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.value = value,
.constant_id = constant_id,
.operator_id = yp_parser_constant_id_location(parser, operator->start, operator->end - 1)
};
return node;
}
// Allocate a new LocalVariableReadNode node. // Allocate a new LocalVariableReadNode node.
static yp_local_variable_read_node_t * static yp_local_variable_read_node_t *
yp_local_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name, uint32_t depth) { yp_local_variable_read_node_create(yp_parser_t *parser, const yp_token_t *name, uint32_t depth) {
@ -2941,6 +2808,28 @@ yp_numbered_reference_read_node_create(yp_parser_t *parser, const yp_token_t *na
return node; return node;
} }
// Allocate and initialize a new OperatorWriteNode.
static yp_operator_write_node_t *
yp_operator_write_node_create(yp_parser_t *parser, yp_node_t *target, const yp_token_t *operator, yp_node_t *value) {
yp_operator_write_node_t *node = YP_ALLOC_NODE(parser, yp_operator_write_node_t);
*node = (yp_operator_write_node_t) {
{
.type = YP_NODE_OPERATOR_WRITE_NODE,
.location = {
.start = target->location.start,
.end = value->location.end
},
},
.target = target,
.operator_loc = YP_LOCATION_TOKEN_VALUE(operator),
.operator = yp_parser_constant_id_location(parser, operator->start, operator->end - 1),
.value = value
};
return node;
}
// Allocate a new OptionalParameterNode node. // Allocate a new OptionalParameterNode node.
static yp_optional_parameter_node_t * static yp_optional_parameter_node_t *
yp_optional_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, const yp_token_t *operator, yp_node_t *value) { yp_optional_parameter_node_create(yp_parser_t *parser, const yp_token_t *name, const yp_token_t *operator, yp_node_t *value) {
@ -12351,14 +12240,16 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
case YP_NODE_NUMBERED_REFERENCE_READ_NODE: case YP_NODE_NUMBERED_REFERENCE_READ_NODE:
yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable"); yp_diagnostic_list_append(&parser->error_list, node->location.start, node->location.end, "Can't set variable");
/* fallthrough */ /* fallthrough */
case YP_NODE_GLOBAL_VARIABLE_READ_NODE: { case YP_NODE_CLASS_VARIABLE_READ_NODE:
case YP_NODE_CONSTANT_PATH_NODE:
case YP_NODE_CONSTANT_READ_NODE:
case YP_NODE_GLOBAL_VARIABLE_READ_NODE:
case YP_NODE_INSTANCE_VARIABLE_READ_NODE:
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
parser_lex(parser); parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator"); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator");
yp_node_t *result = (yp_node_t *) yp_global_variable_operator_write_node_create(parser, node, &token, value); return (yp_node_t *) yp_operator_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
} }
case YP_NODE_CALL_NODE: { case YP_NODE_CALL_NODE: {
yp_call_node_t *call_node = (yp_call_node_t *) node; yp_call_node_t *call_node = (yp_call_node_t *) node;
@ -12375,13 +12266,11 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
} }
parser_lex(parser); parser_lex(parser);
yp_node_t *target = (yp_node_t *) yp_local_variable_read_node_create(parser, &(yp_token_t) { .type = YP_TOKEN_IDENTIFIER, .start = message_loc.start, .end = message_loc.end }, 0);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&="); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after &&=");
yp_constant_id_t constant_id = yp_parser_constant_id_location(parser, message_loc.start, message_loc.end);
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_write_node_create(parser, node, &token, value, constant_id);
yp_node_destroy(parser, node); yp_node_destroy(parser, node);
return result; return (yp_node_t *) yp_operator_write_node_create(parser, target, &token, value);
} }
yp_token_t operator = not_provided(parser); yp_token_t operator = not_provided(parser);
@ -12391,49 +12280,6 @@ parse_expression_infix(yp_parser_t *parser, yp_node_t *node, yp_binding_power_t
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator."); yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
return (yp_node_t *) yp_call_operator_write_node_create(parser, (yp_call_node_t *) node, &token, value); return (yp_node_t *) yp_call_operator_write_node_create(parser, (yp_call_node_t *) node, &token, value);
} }
case YP_NODE_CLASS_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
yp_node_t *result = (yp_node_t *) yp_class_variable_operator_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_CONSTANT_PATH_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
return (yp_node_t *) yp_constant_path_operator_write_node_create(parser, (yp_constant_path_node_t *) node, &token, value);
}
case YP_NODE_CONSTANT_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
yp_node_t *result = (yp_node_t *) yp_constant_operator_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_INSTANCE_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
yp_node_t *result = (yp_node_t *) yp_instance_variable_operator_write_node_create(parser, node, &token, value);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_LOCAL_VARIABLE_READ_NODE: {
parser_lex(parser);
yp_node_t *value = parse_expression(parser, binding_power, "Expected a value after the operator.");
yp_constant_id_t constant_id = ((yp_local_variable_read_node_t *) node)->constant_id;
yp_node_t *result = (yp_node_t *) yp_local_variable_operator_write_node_create(parser, node, &token, value, constant_id);
yp_node_destroy(parser, node);
return result;
}
case YP_NODE_MULTI_WRITE_NODE: { case YP_NODE_MULTI_WRITE_NODE: {
parser_lex(parser); parser_lex(parser);
yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Unexpected operator."); yp_diagnostic_list_append(&parser->error_list, token.start, token.end, "Unexpected operator.");