Skip to content

Commit 8925bf4

Browse files
committed
Cleanup visitMultipleAsgnNode() by consistently using local variables
1 parent 82fcec1 commit 8925bf4

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2188,13 +2188,14 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnParseNode node) {
21882188
final SourceIndexLength sourceSection = node.getPosition();
21892189

21902190
final ListParseNode preArray = node.getPre();
2191+
final ParseNode rest = node.getRest();
21912192
final ListParseNode postArray = node.getPost();
21922193
final ParseNode rhs = node.getValueNode();
21932194

21942195
RubyNode rhsTranslated;
21952196

21962197
if (rhs == null) {
2197-
throw new UnsupportedOperationException("null rhs");
2198+
throw CompilerDirectives.shouldNotReachHere("null rhs");
21982199
} else {
21992200
rhsTranslated = rhs.accept(this);
22002201
}
@@ -2203,8 +2204,7 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnParseNode node) {
22032204

22042205
// TODO CS 5-Jan-15 we shouldn't be doing this kind of low level optimisation or pattern matching - EA should do it for us
22052206

2206-
if (preArray != null && node.getPost() == null && node.getRest() == null &&
2207-
rhsTranslated instanceof ArrayLiteralNode &&
2207+
if (preArray != null && postArray == null && rest == null && rhsTranslated instanceof ArrayLiteralNode &&
22082208
((ArrayLiteralNode) rhsTranslated).getSize() == preArray.size()) {
22092209
/* We can deal with this common case be rewriting
22102210
*
@@ -2310,15 +2310,15 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnParseNode node) {
23102310
sequence.add(translateDummyAssignment(preArray.get(n), assignedValue));
23112311
}
23122312

2313-
if (node.getRest() != null) {
2313+
if (rest != null) {
23142314
RubyNode assignedValue = ArrayGetTailNodeGen
23152315
.create(preArray.size(), environment.findLocalVarNode(tempName, sourceSection));
23162316

23172317
if (postArray != null) {
23182318
assignedValue = ArrayDropTailNodeGen.create(postArray.size(), assignedValue);
23192319
}
23202320

2321-
sequence.add(translateDummyAssignment(node.getRest(), assignedValue));
2321+
sequence.add(translateDummyAssignment(rest, assignedValue));
23222322
}
23232323

23242324
if (postArray != null) {
@@ -2357,9 +2357,9 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnParseNode node) {
23572357
result = new ElidableResultNode(
23582358
sequence(sourceSection, sequence),
23592359
environment.findLocalVarNode(tempRHSName, sourceSection));
2360-
} else if (node.getPre() == null && node.getPost() == null && node.getRest() instanceof StarParseNode) {
2360+
} else if (preArray == null && postArray == null && rest instanceof StarParseNode) {
23612361
result = rhsTranslated;
2362-
} else if (node.getPre() == null && node.getPost() == null && node.getRest() != null &&
2362+
} else if (preArray == null && postArray == null && rest != null &&
23632363
!(rhs instanceof ArrayParseNode)) {
23642364
/* *a = b
23652365
*
@@ -2405,7 +2405,7 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnParseNode node) {
24052405

24062406
sequence.add(
24072407
translateDummyAssignment(
2408-
node.getRest(),
2408+
rest,
24092409
environment.findLocalVarNode(tempRHSSplattedName, sourceSection)));
24102410

24112411
final RubyNode assignmentResult;
@@ -2417,15 +2417,14 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnParseNode node) {
24172417
}
24182418

24192419
result = new ElidableResultNode(sequence(sourceSection, sequence), assignmentResult);
2420-
} else if (node.getPre() == null && node.getPost() == null && node.getRest() != null &&
2421-
rhs instanceof ArrayParseNode) {
2420+
} else if (preArray == null && postArray == null && rest != null && rhs instanceof ArrayParseNode) {
24222421
/* *a = [b, c]
24232422
*
24242423
* This seems to be the same as:
24252424
*
24262425
* a = [b, c] */
2427-
result = translateDummyAssignment(node.getRest(), rhsTranslated);
2428-
} else if (node.getPre() == null && node.getRest() != null && node.getPost() != null) {
2426+
result = translateDummyAssignment(rest, rhsTranslated);
2427+
} else if (preArray == null && rest != null && postArray != null) {
24292428
/* Something like
24302429
*
24312430
* *a,b = [1, 2, 3, 4] */
@@ -2464,11 +2463,11 @@ public RubyNode visitMultipleAsgnNode(MultipleAsgnParseNode node) {
24642463

24652464
/* Then index the temp array for each assignment on the LHS. */
24662465

2467-
if (node.getRest() != null) {
2466+
if (rest != null) {
24682467
final ArrayDropTailNode assignedValue = ArrayDropTailNodeGen
24692468
.create(postArray.size(), environment.findLocalVarNode(tempName, sourceSection));
24702469

2471-
sequence.add(translateDummyAssignment(node.getRest(), assignedValue));
2470+
sequence.add(translateDummyAssignment(rest, assignedValue));
24722471
}
24732472

24742473
final List<RubyNode> smallerSequence = new ArrayList<>();

0 commit comments

Comments
 (0)