From 1252cb447a4e35d3140278e2ce71eb82345b35a0 Mon Sep 17 00:00:00 2001 From: Lukas Stadler <lukas.stadler@oracle.com> Date: Thu, 14 Jul 2016 17:49:54 +0200 Subject: [PATCH] reduce the number of Arguments subclasses --- .../r/nodes/builtin/base/FrameFunctions.java | 4 +- .../r/nodes/function/ArgumentMatcher.java | 33 ++++++++--- .../r/nodes/function/CallArgumentsNode.java | 56 +++++++++---------- .../r/nodes/function/InlinedArguments.java | 37 ------------ .../r/nodes/function/MatchedArguments.java | 49 ---------------- .../truffle/r/nodes/function/RCallNode.java | 2 +- .../function/UnrolledVariadicArguments.java | 54 ------------------ .../nodes/function/call/PrepareArguments.java | 10 ++-- .../oracle/truffle/r/runtime/Arguments.java | 23 ++++++-- .../oracle/truffle/r/runtime/RDeparse.java | 3 +- 10 files changed, 75 insertions(+), 196 deletions(-) delete mode 100644 com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/InlinedArguments.java delete mode 100644 com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/MatchedArguments.java delete mode 100644 com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/UnrolledVariadicArguments.java diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java index e315573201..3b17aa2d14 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/FrameFunctions.java @@ -53,7 +53,6 @@ import com.oracle.truffle.r.nodes.function.PromiseNode; import com.oracle.truffle.r.nodes.function.PromiseNode.VarArgNode; import com.oracle.truffle.r.nodes.function.PromiseNode.VarArgsPromiseNode; import com.oracle.truffle.r.nodes.function.RCallNode; -import com.oracle.truffle.r.nodes.function.UnmatchedArguments; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.HasSignature; import com.oracle.truffle.r.runtime.RArguments; @@ -234,8 +233,7 @@ public class FrameFunctions { RCallNode callNode = (RCallNode) RASTUtils.unwrap(call.getRep()); CallArgumentsNode callArgs = callNode.createArguments(null, false, false); ArgumentsSignature inputVarArgSignature = callArgs.containsVarArgsSymbol() ? CallArgumentsNode.getVarargsAndNames(cframe).getSignature() : null; - UnmatchedArguments executeFlatten = callArgs.unrollArguments(inputVarArgSignature); - RNode[] matchedArgNodes = ArgumentMatcher.matchArguments((RRootNode) definition.getRootNode(), executeFlatten, null, null, true).getArguments(); + RNode[] matchedArgNodes = ArgumentMatcher.matchArguments((RRootNode) definition.getRootNode(), callArgs, inputVarArgSignature, null, null, true).getArguments(); ArgumentsSignature sig = ((HasSignature) definition.getRootNode()).getSignature(); // expand any varargs ArrayList<RNode> nodes = new ArrayList<>(); diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java index aa919f2e6f..1023abc190 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/ArgumentMatcher.java @@ -37,6 +37,7 @@ import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.r.nodes.RRootNode; import com.oracle.truffle.r.nodes.access.ConstantNode; import com.oracle.truffle.r.nodes.function.PromiseNode.VarArgNode; +import com.oracle.truffle.r.runtime.Arguments; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.RArguments; import com.oracle.truffle.r.runtime.RArguments.S3DefaultArguments; @@ -62,8 +63,8 @@ import com.oracle.truffle.r.runtime.nodes.RNode; * <p> * {@link ArgumentMatcher} serves the purpose of matching {@link CallArgumentsNode} to * {@link FormalArguments} of a specific function, see - * {@link #matchArguments(RRootNode, UnmatchedArguments, S3DefaultArguments, RBaseNode, boolean)} . - * The other match functions are used for special cases, where builtins make it necessary to + * {@link #matchArguments(RRootNode, CallArgumentsNode, ArgumentsSignature, S3DefaultArguments, RBaseNode, boolean)} + * . The other match functions are used for special cases, where builtins make it necessary to * re-match parameters, e.g.: * {@link #matchArgumentsEvaluated(RRootNode, RArgsValuesAndNames, S3DefaultArguments, boolean, RBaseNode)} * for 'UseMethod'. @@ -132,13 +133,27 @@ public class ArgumentMatcher { * in {@link PromiseNode}s. Used for calls to all functions parsed from R code * * @param target The function which is to be called - * @param suppliedArgs The arguments supplied to the call + * @param arguments The arguments supplied to the call * @param callingNode The {@link RBaseNode} invoking the match - * @return A fresh {@link MatchedArguments} containing the arguments in correct order and - * wrapped in {@link PromiseNode}s + * @return A fresh {@link Arguments} containing the arguments in correct order and wrapped in + * {@link PromiseNode}s */ - public static MatchedArguments matchArguments(RRootNode target, UnmatchedArguments suppliedArgs, S3DefaultArguments s3DefaultArguments, RBaseNode callingNode, boolean noOpt) { - return matchNodes(target, suppliedArgs.getArguments(), suppliedArgs.getSignature(), s3DefaultArguments, callingNode, suppliedArgs, noOpt); + public static Arguments<RNode> matchArguments(RRootNode target, CallArgumentsNode arguments, ArgumentsSignature varArgSignature, S3DefaultArguments s3DefaultArguments, RBaseNode callingNode, + boolean noOpt) { + CompilerAsserts.neverPartOfCompilation(); + assert arguments.containsVarArgsSymbol() == (varArgSignature != null); + + RNode[] argNodes; + ArgumentsSignature signature; + if (!arguments.containsVarArgsSymbol()) { + argNodes = arguments.getArguments(); + signature = arguments.getSignature(); + } else { + Arguments<RNode> suppliedArgs = arguments.unrollArguments(varArgSignature); + argNodes = suppliedArgs.getArguments(); + signature = suppliedArgs.getSignature(); + } + return ArgumentMatcher.matchNodes(target, argNodes, signature, s3DefaultArguments, callingNode, arguments, noOpt); } public static MatchPermutation matchArguments(ArgumentsSignature supplied, ArgumentsSignature formal, RBaseNode callingNode, boolean forNextMethod, RBuiltinDescriptor builtin) { @@ -286,7 +301,7 @@ public class ArgumentMatcher { * and wrapped into the proper {@link PromiseNode}s and the supplied signature reordered * accordingly. */ - private static MatchedArguments matchNodes(RRootNode target, RNode[] suppliedArgs, ArgumentsSignature suppliedSignature, S3DefaultArguments s3DefaultArguments, RBaseNode callingNode, + private static Arguments<RNode> matchNodes(RRootNode target, RNode[] suppliedArgs, ArgumentsSignature suppliedSignature, S3DefaultArguments s3DefaultArguments, RBaseNode callingNode, ClosureCache closureCache, boolean noOpt) { CompilerAsserts.neverPartOfCompilation(); assert suppliedArgs.length == suppliedSignature.getLength(); @@ -382,7 +397,7 @@ public class ArgumentMatcher { resArgs[formalIndex] = wrapMatched(formals, builtin, closureCache, suppliedArgs[suppliedIndex], formalIndex, noOpt, fastPath); } } - return MatchedArguments.create(resArgs, match.resultSignature); + return Arguments.create(resArgs, match.resultSignature); } /** diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallArgumentsNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallArgumentsNode.java index a9fbc9be4e..6359e94caa 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallArgumentsNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/CallArgumentsNode.java @@ -37,6 +37,7 @@ import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.r.nodes.access.FrameSlotNode; import com.oracle.truffle.r.nodes.access.variables.ReadVariableNode; import com.oracle.truffle.r.nodes.function.PromiseHelperNode.PromiseCheckHelperNode; +import com.oracle.truffle.r.runtime.Arguments; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.Utils; @@ -127,42 +128,37 @@ public final class CallArgumentsNode extends RBaseNode implements UnmatchedArgum * This methods unrolls all "..." in the argument list. The result varies if the number of * arguments in the varargs or their names change. */ - public UnmatchedArguments unrollArguments(ArgumentsSignature varArgSignature) { - CompilerAsserts.neverPartOfCompilation(); - assert containsVarArgsSymbol() == (varArgSignature != null); - if (!containsVarArgsSymbol()) { - return this; - } else { - RNode[] values = new RNode[arguments.length]; - String[] newNames = new String[arguments.length]; + public Arguments<RNode> unrollArguments(ArgumentsSignature varArgSignature) { + assert containsVarArgsSymbol(); + RNode[] values = new RNode[arguments.length]; + String[] newNames = new String[arguments.length]; - int vargsSymbolsIndex = 0; - int index = 0; - for (int i = 0; i < arguments.length; i++) { - if (vargsSymbolsIndex < varArgsSymbolIndices.length && varArgsSymbolIndices[vargsSymbolsIndex] == i) { - if (varArgSignature.isEmpty()) { - // An empty "..." vanishes - values = Utils.resizeArray(values, values.length - 1); - newNames = Utils.resizeArray(newNames, newNames.length - 1); - continue; - } + int vargsSymbolsIndex = 0; + int index = 0; + for (int i = 0; i < arguments.length; i++) { + if (vargsSymbolsIndex < varArgsSymbolIndices.length && varArgsSymbolIndices[vargsSymbolsIndex] == i) { + if (varArgSignature.isEmpty()) { + // An empty "..." vanishes + values = Utils.resizeArray(values, values.length - 1); + newNames = Utils.resizeArray(newNames, newNames.length - 1); + continue; + } - values = Utils.resizeArray(values, values.length + varArgSignature.getLength() - 1); - newNames = Utils.resizeArray(newNames, newNames.length + varArgSignature.getLength() - 1); - for (int j = 0; j < varArgSignature.getLength(); j++) { - values[index] = PromiseNode.createVarArg(j); - newNames[index] = varArgSignature.getName(j); - index++; - } - vargsSymbolsIndex++; - } else { - values[index] = arguments[i]; - newNames[index] = signature.getName(i); + values = Utils.resizeArray(values, values.length + varArgSignature.getLength() - 1); + newNames = Utils.resizeArray(newNames, newNames.length + varArgSignature.getLength() - 1); + for (int j = 0; j < varArgSignature.getLength(); j++) { + values[index] = PromiseNode.createVarArg(j); + newNames[index] = varArgSignature.getName(j); index++; } + vargsSymbolsIndex++; + } else { + values[index] = arguments[i]; + newNames[index] = signature.getName(i); + index++; } - return UnrolledVariadicArguments.create(values, ArgumentsSignature.get(newNames), this); } + return Arguments.create(values, ArgumentsSignature.get(newNames)); } private ArgumentsSignature cachedVarArgsSignature; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/InlinedArguments.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/InlinedArguments.java deleted file mode 100644 index 13239ec317..0000000000 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/InlinedArguments.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.r.nodes.function; - -import com.oracle.truffle.r.runtime.Arguments; -import com.oracle.truffle.r.runtime.ArgumentsSignature; -import com.oracle.truffle.r.runtime.nodes.RNode; - -/** - * Simple container class for holding arguments which are going to be inlined into FastR built-ins. - */ -public final class InlinedArguments extends Arguments<RNode> { - - InlinedArguments(RNode[] evaluatedArgs, ArgumentsSignature signature) { - super(evaluatedArgs, signature); - } -} diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/MatchedArguments.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/MatchedArguments.java deleted file mode 100644 index fe8d480d0b..0000000000 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/MatchedArguments.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.r.nodes.function; - -import com.oracle.truffle.r.runtime.Arguments; -import com.oracle.truffle.r.runtime.ArgumentsSignature; -import com.oracle.truffle.r.runtime.nodes.RNode; - -/** - * <p> - * This class denotes a list of name/argument pairs which are in the order of the - * {@link FormalArguments} of a function. Each argument is either filled with the supplied argument, - * the default argument or <code>null</code>, if neither is provided. - * </p> - */ -public final class MatchedArguments extends Arguments<RNode> { - - private MatchedArguments(RNode[] arguments, ArgumentsSignature signature) { - super(arguments, signature); - } - - /** - * @return A fresh {@link MatchedArguments}; arguments may contain <code>null</code> iff there - * is neither a supplied argument nor a default argument - */ - static MatchedArguments create(RNode[] arguments, ArgumentsSignature signature) { - return new MatchedArguments(arguments, signature); - } -} diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallNode.java index 0801bd6736..4b98031ad8 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/RCallNode.java @@ -236,7 +236,7 @@ public abstract class RCallNode extends RCallBaseNode implements RSyntaxNode, RS } public Arguments<RSyntaxNode> getArguments() { - return new Arguments<>(arguments, signature); + return Arguments.create(arguments, signature); } private RArgsValuesAndNames lookupVarArgs(VirtualFrame frame) { diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/UnrolledVariadicArguments.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/UnrolledVariadicArguments.java deleted file mode 100644 index b671bfe682..0000000000 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/UnrolledVariadicArguments.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package com.oracle.truffle.r.nodes.function; - -import java.util.IdentityHashMap; - -import com.oracle.truffle.r.runtime.Arguments; -import com.oracle.truffle.r.runtime.ArgumentsSignature; -import com.oracle.truffle.r.runtime.data.RPromise.Closure; -import com.oracle.truffle.r.runtime.nodes.RNode; - -/** - * This is a simple container class for arguments whose "..." have been unrolled and inserted into - * the original arguments, as it happens in - * {@link CallArgumentsNode#unrollArguments(ArgumentsSignature)}. - */ -public final class UnrolledVariadicArguments extends Arguments<RNode> implements UnmatchedArguments { - - private final IdentityHashMap<RNode, Closure> closureCache; - - private UnrolledVariadicArguments(RNode[] arguments, ArgumentsSignature signature, ClosureCache closureCache) { - super(arguments, signature); - this.closureCache = closureCache.getContent(); - } - - static UnrolledVariadicArguments create(RNode[] arguments, ArgumentsSignature signature, ClosureCache closureCache) { - return new UnrolledVariadicArguments(arguments, signature, closureCache); - } - - @Override - public IdentityHashMap<RNode, Closure> getContent() { - return closureCache; - } -} diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareArguments.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareArguments.java index 329266ab35..ee7c56dace 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareArguments.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/function/call/PrepareArguments.java @@ -31,9 +31,8 @@ import com.oracle.truffle.r.nodes.function.ArgumentMatcher; import com.oracle.truffle.r.nodes.function.ArgumentMatcher.MatchPermutation; import com.oracle.truffle.r.nodes.function.CallArgumentsNode; import com.oracle.truffle.r.nodes.function.FormalArguments; -import com.oracle.truffle.r.nodes.function.MatchedArguments; import com.oracle.truffle.r.nodes.function.RCallNode; -import com.oracle.truffle.r.nodes.function.UnmatchedArguments; +import com.oracle.truffle.r.runtime.Arguments; import com.oracle.truffle.r.runtime.ArgumentsSignature; import com.oracle.truffle.r.runtime.RArguments.S3DefaultArguments; import com.oracle.truffle.r.runtime.RError; @@ -73,7 +72,7 @@ public abstract class PrepareArguments extends Node { return new RArgsValuesAndNames(result, suppliedSignature); } - private static RArgsValuesAndNames executeArgs(MatchedArguments matched, VirtualFrame frame) { + private static RArgsValuesAndNames executeArgs(Arguments<RNode> matched, VirtualFrame frame) { return executeArgs(matched.getArguments(), matched.getSignature(), frame); } @@ -115,7 +114,7 @@ public abstract class PrepareArguments extends Node { boolean noOpt) { this.next = next; cachedVarArgSignature = varArgSignature; - MatchedArguments matched = ArgumentMatcher.matchArguments(target, args.unrollArguments(varArgSignature), s3DefaultArguments, call, noOpt); + Arguments<RNode> matched = ArgumentMatcher.matchArguments(target, args, varArgSignature, s3DefaultArguments, call, noOpt); this.matchedArguments = matched.getArguments(); this.matchedSuppliedSignature = matched.getSignature(); this.cachedS3DefaultArguments = s3DefaultArguments; @@ -146,8 +145,7 @@ public abstract class PrepareArguments extends Node { public RArgsValuesAndNames execute(VirtualFrame frame, RArgsValuesAndNames varArgs, S3DefaultArguments s3DefaultArguments, RCallNode call) { CompilerDirectives.transferToInterpreter(); ArgumentsSignature varArgSignature = varArgs == null ? null : varArgs.getSignature(); - UnmatchedArguments argsValuesAndNames = args.unrollArguments(varArgSignature); - MatchedArguments matchedArgs = ArgumentMatcher.matchArguments(target, argsValuesAndNames, s3DefaultArguments, RError.ROOTNODE, true); + Arguments<RNode> matchedArgs = ArgumentMatcher.matchArguments(target, args, varArgSignature, s3DefaultArguments, RError.ROOTNODE, true); return executeArgs(matchedArgs, frame); } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Arguments.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Arguments.java index ddbb852fe3..e599ec89e5 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Arguments.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/Arguments.java @@ -23,16 +23,29 @@ package com.oracle.truffle.r.runtime; import com.oracle.truffle.api.CompilerDirectives.CompilationFinal; -import com.oracle.truffle.api.nodes.Node; +import com.oracle.truffle.r.runtime.nodes.RNode; +import com.oracle.truffle.r.runtime.nodes.RSyntaxElement; +import com.oracle.truffle.r.runtime.nodes.RSyntaxNode; /** - * Simple generic base class for pairs of {@link #values} and {@link #signature} (that are not - * {@link Node}s). + * Simple generic base class for pairs of values and signature. * - * @param <T> The type of {@link #values} + * @param <T> The type of values */ public class Arguments<T> { + public static Arguments<RNode> create(RNode[] arguments, ArgumentsSignature signature) { + return new Arguments<>(arguments, signature); + } + + public static Arguments<RSyntaxNode> create(RSyntaxNode[] arguments, ArgumentsSignature signature) { + return new Arguments<>(arguments, signature); + } + + public static Arguments<RSyntaxElement> create(RSyntaxElement[] arguments, ArgumentsSignature signature) { + return new Arguments<>(arguments, signature); + } + /** * Array of arguments; semantics have to be specified by child classes. */ @@ -43,7 +56,7 @@ public class Arguments<T> { */ private final ArgumentsSignature signature; - public Arguments(T[] arguments, ArgumentsSignature signature) { + protected Arguments(T[] arguments, ArgumentsSignature signature) { this.values = arguments; this.signature = signature; } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java index d5b830702d..cbe8a82173 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RDeparse.java @@ -847,8 +847,7 @@ public class RDeparse { } RSyntaxElement[] arguments = argElements.toArray(new RSyntaxElement[argElements.size()]); ArgumentsSignature signature = ArgumentsSignature.get(argNames.toArray(new String[argNames.size()])); - Arguments<RSyntaxElement> arg = new Arguments<>(arguments, signature); - return arg; + return Arguments.create(arguments, signature); } private static RPairList next(RPairList pairlist) { -- GitLab