diff a/src/jdk.incubator.code/share/classes/jdk/incubator/code/AbstractOp.java b/src/jdk.incubator.code/share/classes/jdk/incubator/code/AbstractOp.java --- /dev/null +++ b/src/jdk.incubator.code/share/classes/jdk/incubator/code/AbstractOp.java @@ -0,0 +1,267 @@ +/* + * Copyright (c) 2024, 2026, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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 jdk.incubator.code; + +import com.sun.tools.javac.api.JavacScope; +import com.sun.tools.javac.api.JavacTrees; +import com.sun.tools.javac.code.Symbol.ClassSymbol; +import com.sun.tools.javac.comp.Attr; +import com.sun.tools.javac.model.JavacElements; +import com.sun.tools.javac.processing.JavacProcessingEnvironment; +import com.sun.tools.javac.tree.JCTree.JCMethodDecl; +import com.sun.tools.javac.tree.TreeMaker; +import com.sun.tools.javac.util.Context; +import jdk.incubator.code.dialect.core.CoreOp.FuncOp; +import jdk.incubator.code.dialect.core.CoreType; +import jdk.incubator.code.dialect.core.FunctionType; +import jdk.incubator.code.dialect.java.JavaOp; +import jdk.incubator.code.dialect.java.MethodRef; +import jdk.incubator.code.extern.OpWriter; +import jdk.incubator.code.internal.ReflectMethods; +import jdk.internal.access.SharedSecrets; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.*; +import java.util.function.BiFunction; + +/** + * The abstract implementation of an operation. All concrete operations extend this class. + * + *
+ * A concrete operation class must satisfy the following requirements: + *
+ * A concrete operation class may additionally: + *
+ * The constructed operation's operands are the values mapped, in order, from the given operation's operands using + * the given code context. The new operation's location is the given operation's location, if any. + * + * @param that the operation + * @param cc the code context + * @throws IllegalArgumentException if an operation's operand has no context mapping + * @throws IllegalArgumentException if a mapped value's declaring block is built. + */ + protected AbstractOp(AbstractOp that, CodeContext cc) { + this(cc.getValues(that.operands)); + this.location = that.location; + } + + @Override + public final void setLocation(Location l) { + // @@@ Fail if location != null? + if (isRoot() || (result != null && result.block.isBuilt())) { + throw new IllegalStateException("Built operation"); + } + + location = l; + } + + @Override + public final Location location() { + return location; + } + + @Override + public final Block parent() { + if (isRoot() || result == null) { + return null; + } + + if (!result.block.isBuilt()) { + throw new IllegalStateException("Parent block is unobservable"); + } + + return result.block; + } + + @Override + public final List
children() { + return bodies(); + } + + /** + * {@inheritDoc} + * @implSpec this implementation returns an unmodifiable empty list. + */ + @Override + public List bodies() { + return List.of(); + } + + @Override + public final Result result() { + return result == Result.ROOT_RESULT ? null : result; + } + + @Override + public final List