Skip to content
Snippets Groups Projects
Commit 8f717baa authored by stepan's avatar stepan
Browse files

Use newCastBuilder() API in more places

parent 3b05010a
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.logicalValue
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.size;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.toBoolean;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.typeName;
import static com.oracle.truffle.r.nodes.builtin.casts.fluent.CastNodeBuilder.newCastBuilder;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
......@@ -36,7 +37,6 @@ import com.oracle.truffle.api.nodes.ExplodeLoop;
import com.oracle.truffle.api.profiles.BranchProfile;
import com.oracle.truffle.api.profiles.ValueProfile;
import com.oracle.truffle.r.nodes.builtin.CastBuilder;
import com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef;
import com.oracle.truffle.r.nodes.builtin.RBuiltinNode;
import com.oracle.truffle.r.nodes.unary.CastNode;
import com.oracle.truffle.r.runtime.RError;
......@@ -84,10 +84,12 @@ public abstract class Quantifier extends RBuiltinNode {
}
private void createArgCast(int index) {
CastBuilder argCastBuilder = new CastBuilder();
argCastBuilder.arg(0).allowNull().shouldBe(integerValue().or(logicalValue()).or(instanceOf(RAbstractVector.class).and(size(0))), RError.Message.COERCING_ARGUMENT, typeName(),
"logical").asLogicalVector();
argCastNodes[index] = insert(new ProfileCastNode(argCastBuilder.getCasts()[0]));
// @formatter:off
argCastNodes[index] = insert(newCastBuilder().allowNull().
shouldBe(integerValue().or(logicalValue()).or(instanceOf(RAbstractVector.class).and(size(0))),
RError.Message.COERCING_ARGUMENT, typeName(), "logical").
asLogicalVector().buildCastNode());
// @formatter:on
}
protected boolean emptyVectorResult() {
......
......@@ -15,6 +15,7 @@ package com.oracle.truffle.r.nodes.builtin.base;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.instanceOf;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.lengthGt;
import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.stringValue;
import static com.oracle.truffle.r.nodes.builtin.casts.fluent.CastNodeBuilder.newCastBuilder;
import static com.oracle.truffle.r.runtime.RVisibility.CUSTOM;
import static com.oracle.truffle.r.runtime.builtins.RBehavior.COMPLEX;
import static com.oracle.truffle.r.runtime.builtins.RBuiltinKind.PRIMITIVE;
......@@ -72,11 +73,8 @@ public abstract class StandardGeneric extends RBuiltinNode {
@Child private CastNode castIntScalar;
@Child private CastNode castStringScalar;
{
CastBuilder builder = new CastBuilder(2);
builder.arg(0).asIntegerVector().findFirst(RRuntime.INT_NA);
builder.arg(1).asStringVector().findFirst(RRuntime.STRING_NA);
castIntScalar = builder.getCasts()[0];
castStringScalar = builder.getCasts()[1];
castIntScalar = newCastBuilder().asIntegerVector().findFirst(RRuntime.INT_NA).buildCastNode();
castStringScalar = newCastBuilder().asStringVector().findFirst(RRuntime.STRING_NA).buildCastNode();
}
private final BranchProfile noGenFunFound = BranchProfile.create();
......
......@@ -12,6 +12,8 @@
*/
package com.oracle.truffle.r.nodes.objects;
import static com.oracle.truffle.r.nodes.builtin.casts.fluent.CastNodeBuilder.newCastBuilder;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.r.nodes.access.AccessSlotNode;
......@@ -41,11 +43,8 @@ public abstract class NewObject extends RExternalBuiltinNode.Arg1 {
@Child private CastNode castStringScalar;
@Child private CastNode castLogicalScalar;
{
CastBuilder builder = new CastBuilder();
builder.arg(0).asStringVector().findFirst(RRuntime.STRING_NA);
builder.arg(1).asLogicalVector().findFirst(RRuntime.LOGICAL_NA);
castStringScalar = builder.getCasts()[0];
castLogicalScalar = builder.getCasts()[1];
castStringScalar = newCastBuilder().asStringVector().findFirst(RRuntime.STRING_NA).buildCastNode();
castLogicalScalar = newCastBuilder().asLogicalVector().findFirst(RRuntime.LOGICAL_NA).buildCastNode();
}
@Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment