Skip to content

Commit a33da8e

Browse files
committed
Reuse translateArgumentsAndBlock() in visitYieldNode()
* Removes duplication to handle the various call site argument variants.
1 parent fc9735a commit a33da8e

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

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

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ protected ArgumentsAndBlockTranslation translateArgumentsAndBlock(SourceIndexLen
690690
isSplatted = true;
691691
arguments = new ParseNode[]{ argsNode };
692692
} else {
693-
throw new UnsupportedOperationException("Unknown argument node type: " + argsNode.getClass());
693+
throw CompilerDirectives.shouldNotReachHere("Unknown argument node type: " + argsNode.getClass());
694694
}
695695

696696
ArgumentsDescriptor keywordDescriptor = getKeywordArgumentsDescriptor(language, arguments);
@@ -3020,37 +3020,18 @@ public RubyNode visitXStrNode(XStrParseNode node) {
30203020
@Override
30213021
public RubyNode visitYieldNode(YieldParseNode node) {
30223022
final ParseNode argsNode = node.getArgsNode();
3023-
boolean unsplat = false;
30243023

3025-
final ParseNode[] arguments;
3026-
if (argsNode == null) {
3027-
// No arguments
3028-
arguments = EMPTY_ARGUMENTS;
3029-
} else if (argsNode instanceof ArrayParseNode) {
3030-
// Multiple arguments
3031-
arguments = ((ArrayParseNode) argsNode).children();
3032-
} else if (argsNode instanceof SplatParseNode || argsNode instanceof ArgsCatParseNode ||
3033-
argsNode instanceof ArgsPushParseNode) {
3034-
unsplat = true;
3035-
arguments = new ParseNode[]{ argsNode };
3036-
} else {
3037-
arguments = new ParseNode[]{ node.getArgsNode() };
3038-
}
3039-
3040-
ArgumentsDescriptor keywordDescriptor = getKeywordArgumentsDescriptor(language, arguments);
3024+
final ArgumentsAndBlockTranslation argumentsAndBlock = translateArgumentsAndBlock(
3025+
node.getPosition(), null, argsNode, "<yield>");
30413026

3042-
final RubyNode[] argumentsTranslated = createArray(arguments.length);
3043-
3044-
for (int i = 0; i < arguments.length; i++) {
3045-
argumentsTranslated[i] = arguments[i].accept(this);
3046-
}
3027+
final RubyNode[] argumentsTranslated = argumentsAndBlock.getArguments();
30473028

30483029
RubyNode readBlock = environment
30493030
.findLocalVarOrNilNode(TranslatorEnvironment.METHOD_BLOCK_NAME, node.getPosition());
30503031

30513032
final RubyNode ret = new YieldExpressionNode(
3052-
unsplat,
3053-
keywordDescriptor,
3033+
argumentsAndBlock.isSplatted(),
3034+
argumentsAndBlock.getArgumentsDescriptor(),
30543035
argumentsTranslated,
30553036
readBlock,
30563037
environment.shouldWarnYieldInModuleBody());

0 commit comments

Comments
 (0)