diff --git a/src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/core/CoreOp.java b/src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/core/CoreOp.java index 2477786cdb1..e449f1b99a0 100644 --- a/src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/core/CoreOp.java +++ b/src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/core/CoreOp.java @@ -90,7 +90,7 @@ public FuncOp body(Consumer c) { final String funcName; final Body body; - static FuncOp create(ExternalizedOp def) { + FuncOp(ExternalizedOp def) { if (!def.operands().isEmpty()) { throw new IllegalStateException("Bad op " + def.name()); } @@ -100,17 +100,14 @@ static FuncOp create(ExternalizedOp def) { case String s -> s; case null, default -> throw new UnsupportedOperationException("Unsupported func name value:" + v); }); - return new FuncOp(funcName, def.bodyDefinitions().get(0)); - } - FuncOp(FuncOp that, CopyContext cc, OpTransformer oa) { - this(that, that.funcName, cc, oa); + this(funcName, def.bodyDefinitions().get(0)); } - FuncOp(FuncOp that, String funcName, CopyContext cc, OpTransformer ot) { + FuncOp(FuncOp that, CopyContext cc, OpTransformer ot) { super(that, cc); - this.funcName = funcName; + this.funcName = that.funcName; this.body = that.body.transform(cc, ot).build(this); } @@ -123,6 +120,13 @@ public FuncOp transform(OpTransformer ot) { return new FuncOp(this, CopyContext.create(), ot); } + FuncOp(FuncOp that, String funcName, CopyContext cc, OpTransformer ot) { + super(that, cc); + + this.funcName = funcName; + this.body = that.body.transform(cc, ot).build(this); + } + public FuncOp transform(String funcName, OpTransformer ot) { return new FuncOp(this, funcName, CopyContext.create(), ot); } @@ -184,14 +188,14 @@ public static final class FuncCallOp extends CoreOp { final String funcName; final TypeElement resultType; - static FuncCallOp create(ExternalizedOp def) { + FuncCallOp(ExternalizedOp def) { String funcName = def.extractAttributeValue(ATTRIBUTE_FUNC_NAME, true, v -> switch (v) { case String s -> s; case null, default -> throw new UnsupportedOperationException("Unsupported func name value:" + v); }); - return new FuncCallOp(funcName, def.resultType(), def.operands()); + this(funcName, def.resultType(), def.operands()); } FuncCallOp(FuncCallOp that, CopyContext cc) { @@ -241,12 +245,12 @@ public static final class ModuleOp extends CoreOp final SequencedMap table; final Body body; - static ModuleOp create(ExternalizedOp def) { + ModuleOp(ExternalizedOp def) { if (!def.operands().isEmpty()) { throw new IllegalStateException("Bad op " + def.name()); } - return new ModuleOp(def.bodyDefinitions().get(0)); + this(def.bodyDefinitions().get(0)); } ModuleOp(ModuleOp that, CopyContext cc, OpTransformer ot) { @@ -759,14 +763,15 @@ public static final class ConstantOp extends CoreOp final Object value; final TypeElement type; - static ConstantOp create(ExternalizedOp def) { + ConstantOp(ExternalizedOp def) { if (!def.operands().isEmpty()) { throw new IllegalArgumentException("Operation must have zero operands"); } Object value = def.extractAttributeValue(ATTRIBUTE_CONSTANT_VALUE, true, v -> processConstantValue(def.resultType(), v)); - return new ConstantOp(def.resultType(), value); + + this(def.resultType(), value); } static Object processConstantValue(TypeElement t, Object value) { @@ -871,7 +876,7 @@ public static final class VarOp extends CoreOp final String varName; final VarType resultType; - static VarOp create(ExternalizedOp def) { + VarOp(ExternalizedOp def) { if (def.operands().size() > 1) { throw new IllegalStateException("Operation must have zero or one operand"); } @@ -882,14 +887,11 @@ static VarOp create(ExternalizedOp def) { case null -> ""; default -> throw new UnsupportedOperationException("Unsupported var name value:" + v); }); - // @@@ Cannot use canonical constructor because type is wrapped - return new VarOp(def, name); - } - VarOp(ExternalizedOp def, String varName) { + // @@@ Cannot use canonical constructor because type is wrapped super(def.operands()); - this.varName = varName; + this.varName = name; this.resultType = (VarType) def.resultType(); } @@ -1115,7 +1117,7 @@ public static final class TupleLoadOp extends CoreOp { final int index; - static TupleLoadOp create(ExternalizedOp def) { + TupleLoadOp(ExternalizedOp def) { if (def.operands().size() != 1) { throw new IllegalStateException("Operation must have one operand"); } @@ -1125,7 +1127,8 @@ static TupleLoadOp create(ExternalizedOp def) { case Integer i -> i; case null, default -> throw new UnsupportedOperationException("Unsupported tuple index value:" + v); }); - return new TupleLoadOp(def.operands().get(0), index); + + this(def.operands().get(0), index); } TupleLoadOp(TupleLoadOp that, CopyContext cc) { @@ -1172,7 +1175,7 @@ public static final class TupleWithOp extends CoreOp { final int index; - static TupleWithOp create(ExternalizedOp def) { + TupleWithOp(ExternalizedOp def) { if (def.operands().size() != 2) { throw new IllegalStateException("Operation must have two operands"); } @@ -1182,7 +1185,8 @@ static TupleWithOp create(ExternalizedOp def) { case Integer i -> i; case null, default -> throw new UnsupportedOperationException("Unsupported tuple index value:" + v); }); - return new TupleWithOp(def.operands().get(0), index, def.operands().get(1)); + + this(def.operands().get(0), index, def.operands().get(1)); } TupleWithOp(TupleWithOp that, CopyContext cc) { @@ -1230,17 +1234,17 @@ static Op createOp(ExternalizedOp def) { case "cbranch" -> new ConditionalBranchOp(def); case "closure" -> new ClosureOp(def); case "closure.call" -> new ClosureCallOp(def); - case "constant" -> ConstantOp.create(def); - case "func" -> FuncOp.create(def); - case "func.call" -> FuncCallOp.create(def); - case "module" -> ModuleOp.create(def); + case "constant" -> new ConstantOp(def); + case "func" -> new FuncOp(def); + case "func.call" -> new FuncCallOp(def); + case "module" -> new ModuleOp(def); case "quoted" -> new QuotedOp(def); case "return" -> new ReturnOp(def); case "tuple" -> new TupleOp(def); - case "tuple.load" -> TupleLoadOp.create(def); - case "tuple.with" -> TupleWithOp.create(def); + case "tuple.load" -> new TupleLoadOp(def); + case "tuple.with" -> new TupleWithOp(def); case "unreachable" -> new UnreachableOp(def); - case "var" -> VarOp.create(def); + case "var" -> new VarOp(def); case "var.load" -> new VarAccessOp.VarLoadOp(def); case "var.store" -> new VarAccessOp.VarStoreOp(def); case "yield" -> new YieldOp(def); diff --git a/src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java b/src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java index 9e867802229..334ba0de88e 100644 --- a/src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java +++ b/src/jdk.incubator.code/share/classes/jdk/incubator/code/dialect/java/JavaOp.java @@ -200,13 +200,14 @@ public Builder quotable() { final Body body; final boolean isQuotable; - static LambdaOp create(ExternalizedOp def) { + LambdaOp(ExternalizedOp def) { boolean isQuotable = def.extractAttributeValue(ATTRIBUTE_LAMBDA_IS_QUOTABLE, false, v -> switch (v) { case Boolean b -> b; case null, default -> false; }); - return new LambdaOp(def.resultType(), def.bodyDefinitions().get(0), isQuotable); + + this(def.resultType(), def.bodyDefinitions().get(0), isQuotable); } LambdaOp(LambdaOp that, CopyContext cc, OpTransformer ot) { @@ -601,7 +602,7 @@ public enum InvokeKind { final MethodRef invokeDescriptor; final TypeElement resultType; - static InvokeOp create(ExternalizedOp def) { + InvokeOp(ExternalizedOp def) { // Required attribute MethodRef invokeDescriptor = def.extractAttributeValue(ATTRIBUTE_INVOKE_DESCRIPTOR, true, v -> switch (v) { @@ -637,7 +638,7 @@ static InvokeOp create(ExternalizedOp def) { }); - return new InvokeOp(ik, isVarArgs, def.resultType(), invokeDescriptor, def.operands()); + this(ik, isVarArgs, def.resultType(), invokeDescriptor, def.operands()); } InvokeOp(InvokeOp that, CopyContext cc) { @@ -788,7 +789,7 @@ public static final class NewOp extends JavaOp final ConstructorRef constructorDescriptor; final TypeElement resultType; - static NewOp create(ExternalizedOp def) { + NewOp(ExternalizedOp def) { // Required attribute ConstructorRef constructorDescriptor = def.extractAttributeValue(ATTRIBUTE_NEW_DESCRIPTOR, true, v -> switch (v) { @@ -804,7 +805,7 @@ static NewOp create(ExternalizedOp def) { case null, default -> false; }); - return new NewOp(isVarArgs, def.resultType(), constructorDescriptor, def.operands()); + this(isVarArgs, def.resultType(), constructorDescriptor, def.operands()); } NewOp(NewOp that, CopyContext cc) { @@ -909,7 +910,7 @@ public static final class FieldLoadOp extends FieldAccessOp final TypeElement resultType; - static FieldLoadOp create(ExternalizedOp def) { + FieldLoadOp(ExternalizedOp def) { if (def.operands().size() > 1) { throw new IllegalArgumentException("Operation must accept zero or one operand"); } @@ -920,11 +921,10 @@ static FieldLoadOp create(ExternalizedOp def) { case null, default -> throw new UnsupportedOperationException("Unsupported field descriptor value:" + v); }); - if (def.operands().isEmpty()) { - return new FieldLoadOp(def.resultType(), fieldDescriptor); - } else { - return new FieldLoadOp(def.resultType(), fieldDescriptor, def.operands().get(0)); - } + + super(def.operands(), fieldDescriptor); + + this.resultType = def.resultType(); } FieldLoadOp(FieldLoadOp that, CopyContext cc) { @@ -967,7 +967,7 @@ public static final class FieldStoreOp extends FieldAccessOp implements JavaExpression, JavaStatement { static final String NAME = "field.store"; - static FieldStoreOp create(ExternalizedOp def) { + FieldStoreOp(ExternalizedOp def) { if (def.operands().isEmpty() || def.operands().size() > 2) { throw new IllegalArgumentException("Operation must accept one or two operands"); } @@ -978,11 +978,8 @@ static FieldStoreOp create(ExternalizedOp def) { case null, default -> throw new UnsupportedOperationException("Unsupported field descriptor value:" + v); }); - if (def.operands().size() == 1) { - return new FieldStoreOp(fieldDescriptor, def.operands().get(0)); - } else { - return new FieldStoreOp(fieldDescriptor, def.operands().get(0), def.operands().get(1)); - } + + super(def.operands(), fieldDescriptor); } FieldStoreOp(FieldStoreOp that, CopyContext cc) { @@ -1156,7 +1153,7 @@ public static final class InstanceOfOp extends JavaOp final TypeElement typeDescriptor; - static InstanceOfOp create(ExternalizedOp def) { + InstanceOfOp(ExternalizedOp def) { if (def.operands().size() != 1) { throw new IllegalArgumentException("Operation must have one operand " + def.name()); } @@ -1166,7 +1163,8 @@ static InstanceOfOp create(ExternalizedOp def) { case JavaType td -> td; case null, default -> throw new UnsupportedOperationException("Unsupported type descriptor value:" + v); }); - return new InstanceOfOp(typeDescriptor, def.operands().get(0)); + + this(typeDescriptor, def.operands().get(0)); } InstanceOfOp(InstanceOfOp that, CopyContext cc) { @@ -1213,7 +1211,7 @@ public static final class CastOp extends JavaOp final TypeElement resultType; final TypeElement typeDescriptor; - static CastOp create(ExternalizedOp def) { + CastOp(ExternalizedOp def) { if (def.operands().size() != 1) { throw new IllegalArgumentException("Operation must have one operand " + def.name()); } @@ -1223,7 +1221,8 @@ static CastOp create(ExternalizedOp def) { case JavaType td -> td; case null, default -> throw new UnsupportedOperationException("Unsupported type descriptor value:" + v); }); - return new CastOp(def.resultType(), type, def.operands().get(0)); + + this(def.resultType(), type, def.operands().get(0)); } CastOp(CastOp that, CopyContext cc) { @@ -3129,10 +3128,6 @@ public ForOp body(Consumer c) { final Body update; final Body body; - static ForOp create(ExternalizedOp def) { - return new ForOp(def); - } - ForOp(ExternalizedOp def) { this(def.bodyDefinitions().get(0), def.bodyDefinitions().get(1), @@ -3350,10 +3345,6 @@ public EnhancedForOp body(Consumer c) { final Body init; final Body body; - static EnhancedForOp create(ExternalizedOp def) { - return new EnhancedForOp(def); - } - EnhancedForOp(ExternalizedOp def) { this(def.bodyDefinitions().get(0), def.bodyDefinitions().get(1), @@ -4136,10 +4127,6 @@ public TryOp noFinalizer() { final List catchers; final Body finalizer; - static TryOp create(ExternalizedOp def) { - return new TryOp(def); - } - TryOp(ExternalizedOp def) { List bodies = def.bodyDefinitions(); Body.Builder first = bodies.getFirst(); @@ -4625,7 +4612,7 @@ public static final class RecordPatternOp extends PatternOp { final RecordTypeRef recordDescriptor; - static RecordPatternOp create(ExternalizedOp def) { + RecordPatternOp(ExternalizedOp def) { RecordTypeRef recordDescriptor = def.extractAttributeValue(ATTRIBUTE_RECORD_DESCRIPTOR, true, v -> switch (v) { case RecordTypeRef rtd -> rtd; @@ -4633,7 +4620,7 @@ static RecordPatternOp create(ExternalizedOp def) { throw new UnsupportedOperationException("Unsupported record type descriptor value:" + v); }); - return new RecordPatternOp(recordDescriptor, def.operands()); + this(recordDescriptor, def.operands()); } RecordPatternOp(RecordPatternOp that, CopyContext cc) { @@ -4970,7 +4957,7 @@ static Op createOp(ExternalizedOp def) { case "array.store" -> new ArrayAccessOp.ArrayStoreOp(def); case "ashr" -> new AshrOp(def); case "assert" -> new AssertOp(def); - case "cast" -> CastOp.create(def); + case "cast" -> new CastOp(def); case "compl" -> new ComplOp(def); case "concat" -> new ConcatOp(def); case "conv" -> new ConvOp(def); @@ -4978,12 +4965,12 @@ static Op createOp(ExternalizedOp def) { case "eq" -> new EqOp(def); case "exception.region.enter" -> new ExceptionRegionEnter(def); case "exception.region.exit" -> new ExceptionRegionExit(def); - case "field.load" -> FieldAccessOp.FieldLoadOp.create(def); - case "field.store" -> FieldAccessOp.FieldStoreOp.create(def); + case "field.load" -> new FieldAccessOp.FieldLoadOp(def); + case "field.store" -> new FieldAccessOp.FieldStoreOp(def); case "ge" -> new GeOp(def); case "gt" -> new GtOp(def); - case "instanceof" -> InstanceOfOp.create(def); - case "invoke" -> InvokeOp.create(def); + case "instanceof" -> new InstanceOfOp(def); + case "invoke" -> new InvokeOp(def); case "java.block" -> new BlockOp(def); case "java.break" -> new BreakOp(def); case "java.cand" -> new ConditionalAndOp(def); @@ -4991,18 +4978,18 @@ static Op createOp(ExternalizedOp def) { case "java.continue" -> new ContinueOp(def); case "java.cor" -> new ConditionalOrOp(def); case "java.do.while" -> new DoWhileOp(def); - case "java.enhancedFor" -> EnhancedForOp.create(def); - case "java.for" -> ForOp.create(def); + case "java.enhancedFor" -> new EnhancedForOp(def); + case "java.for" -> new ForOp(def); case "java.if" -> new IfOp(def); case "java.labeled" -> new LabeledOp(def); case "java.switch.expression" -> new SwitchExpressionOp(def); case "java.switch.fallthrough" -> new SwitchFallthroughOp(def); case "java.switch.statement" -> new SwitchStatementOp(def); case "java.synchronized" -> new SynchronizedOp(def); - case "java.try" -> TryOp.create(def); + case "java.try" -> new TryOp(def); case "java.while" -> new WhileOp(def); case "java.yield" -> new YieldOp(def); - case "lambda" -> LambdaOp.create(def); + case "lambda" -> new LambdaOp(def); case "le" -> new LeOp(def); case "lshl" -> new LshlOp(def); case "lshr" -> new LshrOp(def); @@ -5013,12 +5000,12 @@ static Op createOp(ExternalizedOp def) { case "mul" -> new MulOp(def); case "neg" -> new NegOp(def); case "neq" -> new NeqOp(def); - case "new" -> NewOp.create(def); + case "new" -> new NewOp(def); case "not" -> new NotOp(def); case "or" -> new OrOp(def); case "pattern.match" -> new PatternOps.MatchOp(def); case "pattern.match.all" -> new PatternOps.MatchAllPatternOp(def); - case "pattern.record" -> PatternOps.RecordPatternOp.create(def); + case "pattern.record" -> new PatternOps.RecordPatternOp(def); case "pattern.type" -> new PatternOps.TypePatternOp(def); case "sub" -> new SubOp(def); case "throw" -> new ThrowOp(def);