Skip to content

Commit 4083907

Browse files
committed
Refactor assignment operators and replace IfNode with UnlessNode
1 parent 2c97cf4 commit 4083907

File tree

5 files changed

+25
-40
lines changed

5 files changed

+25
-40
lines changed

spec/truffle/parsing/fixtures/operators/&&=/attribute_assignment_with_safe_navigation_operator.yaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,21 @@ ast: |
4747
SelfNode
4848
attributes:
4949
flags = 0
50-
IfNodeGen
50+
UnlessNodeGen
5151
attributes:
5252
flags = 0
5353
children:
5454
condition =
55-
NotNodeGen
55+
IsNilNode
5656
attributes:
5757
flags = 0
5858
children:
5959
child =
60-
IsNilNode
60+
ReadLocalVariableNode
6161
attributes:
6262
flags = 0
63-
children:
64-
child =
65-
ReadLocalVariableNode
66-
attributes:
67-
flags = 0
68-
frameSlot = 2 # %value_0
69-
type = FRAME_LOCAL
63+
frameSlot = 2 # %value_0
64+
type = FRAME_LOCAL
7065
thenBody =
7166
AndNodeGen
7267
attributes:

spec/truffle/parsing/fixtures/operators/+=/attribute_assignment_with_safe_navigation_operator.yaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,21 @@ ast: |
5656
SelfNode
5757
attributes:
5858
flags = 0
59-
IfNodeGen
59+
UnlessNodeGen
6060
attributes:
6161
flags = 0
6262
children:
6363
condition =
64-
NotNodeGen
64+
IsNilNode
6565
attributes:
6666
flags = 0
6767
children:
6868
child =
69-
IsNilNode
69+
ReadLocalVariableNode
7070
attributes:
7171
flags = 0
72-
children:
73-
child =
74-
ReadLocalVariableNode
75-
attributes:
76-
flags = 0
77-
frameSlot = 2 # %value_0
78-
type = FRAME_LOCAL
72+
frameSlot = 2 # %value_0
73+
type = FRAME_LOCAL
7974
thenBody =
8075
RubyCallNode
8176
attributes:

spec/truffle/parsing/fixtures/operators/||=/attribute_assignment_with_safe_navigation_operator.yaml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,21 @@ ast: |
4747
SelfNode
4848
attributes:
4949
flags = 0
50-
IfNodeGen
50+
UnlessNodeGen
5151
attributes:
5252
flags = 0
5353
children:
5454
condition =
55-
NotNodeGen
55+
IsNilNode
5656
attributes:
5757
flags = 0
5858
children:
5959
child =
60-
IsNilNode
60+
ReadLocalVariableNode
6161
attributes:
6262
flags = 0
63-
children:
64-
child =
65-
ReadLocalVariableNode
66-
attributes:
67-
flags = 0
68-
frameSlot = 2 # %value_0
69-
type = FRAME_LOCAL
63+
frameSlot = 2 # %value_0
64+
type = FRAME_LOCAL
7065
thenBody =
7166
OrNodeGen
7267
attributes:

src/main/java/org/truffleruby/parser/BodyTranslator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,8 +2229,8 @@ public RubyNode visitOpAsgnNode(OpAsgnParseNode node) {
22292229
RubyNode controlNode = isOrOperator ? OrNodeGen.create(lhs, rhs) : AndNodeGen.create(lhs, rhs);
22302230

22312231
if (node.isLazy()) {
2232-
controlNode = IfNodeGen.create(
2233-
NotNodeGen.create(new IsNilNode(receiverValue.get(sourceSection).accept(this))),
2232+
controlNode = UnlessNodeGen.create(
2233+
new IsNilNode(receiverValue.get(sourceSection).accept(this)),
22342234
controlNode);
22352235
controlNode.unsafeSetSourceSection(sourceSection);
22362236
}
@@ -2267,8 +2267,8 @@ public RubyNode visitOpAsgnNode(OpAsgnParseNode node) {
22672267
final SourceIndexLength sourceSection = pos;
22682268

22692269
if (node.isLazy()) {
2270-
body = IfNodeGen.create(
2271-
NotNodeGen.create(new IsNilNode(receiverValue.get(sourceSection).accept(this))),
2270+
body = UnlessNodeGen.create(
2271+
new IsNilNode(receiverValue.get(sourceSection).accept(this)),
22722272
body);
22732273
body.unsafeSetSourceSection(sourceSection);
22742274
}

src/main/java/org/truffleruby/parser/YARPTranslator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,9 @@ public RubyNode visitCallAndWriteNode(Nodes.CallAndWriteNode node) {
590590
final RubyNode sequence;
591591
if (node.isSafeNavigation()) {
592592
// return `nil` if receiver is `nil`
593-
final RubyNode ifNode = IfNodeGen.create(NotNodeGen.create(new IsNilNode(receiverExpression.getReadNode())),
593+
final RubyNode unlessNode = UnlessNodeGen.create(new IsNilNode(receiverExpression.getReadNode()),
594594
andNode);
595-
sequence = sequence(Arrays.asList(writeReceiveNode, ifNode));
595+
sequence = sequence(Arrays.asList(writeReceiveNode, unlessNode));
596596
} else {
597597
sequence = sequence(Arrays.asList(writeReceiveNode, andNode));
598598
}
@@ -800,9 +800,9 @@ public RubyNode visitCallOperatorWriteNode(Nodes.CallOperatorWriteNode node) {
800800

801801
if (node.isSafeNavigation()) {
802802
// return `nil` if receiver is `nil`
803-
final RubyNode ifNode = IfNodeGen.create(NotNodeGen.create(new IsNilNode(receiverExpression.getReadNode())),
803+
final RubyNode unlessNode = UnlessNodeGen.create(new IsNilNode(receiverExpression.getReadNode()),
804804
writeNode);
805-
rubyNode = sequence(Arrays.asList(writeReceiveNode, ifNode));
805+
rubyNode = sequence(Arrays.asList(writeReceiveNode, unlessNode));
806806
} else {
807807
rubyNode = sequence(Arrays.asList(writeReceiveNode, writeNode));
808808
}
@@ -830,9 +830,9 @@ public RubyNode visitCallOrWriteNode(Nodes.CallOrWriteNode node) {
830830
final RubyNode sequence;
831831
if (node.isSafeNavigation()) {
832832
// return `nil` if receiver is `nil`
833-
final RubyNode ifNode = IfNodeGen.create(NotNodeGen.create(new IsNilNode(receiverExpression.getReadNode())),
833+
final RubyNode unlessNode = UnlessNodeGen.create(new IsNilNode(receiverExpression.getReadNode()),
834834
orNode);
835-
sequence = sequence(Arrays.asList(writeReceiveNode, ifNode));
835+
sequence = sequence(Arrays.asList(writeReceiveNode, unlessNode));
836836
} else {
837837
sequence = sequence(Arrays.asList(writeReceiveNode, orNode));
838838
}

0 commit comments

Comments
 (0)