org.qbicc.graph.CallNoSideEffects Maven / Gradle / Ivy
package org.qbicc.graph;
import java.util.List;
import java.util.Objects;
import org.qbicc.type.InvokableType;
import org.qbicc.type.ValueType;
import org.qbicc.type.definition.element.ExecutableElement;
/**
* A plain method or function call with no side-effects.
* The return value of the target is the type of this node (which may be {@link org.qbicc.type.VoidType VoidType}).
* Exceptions are considered a side-effect, thus the target must not throw exceptions (this excludes most Java methods, which can throw {@code OutOfMemoryError} among other things).
*
* @see BasicBlockBuilder#callNoSideEffects(Value, Value, List)
*/
public final class CallNoSideEffects extends AbstractValue implements InvocationNode {
private final Value target;
private final Value receiver;
private final List arguments;
private final InvokableType calleeType;
CallNoSideEffects(Node callSite, ExecutableElement element, int line, int bci, Value target, Value receiver, List arguments) {
super(callSite, element, line, bci);
this.target = target;
this.receiver = receiver;
this.arguments = arguments;
calleeType = (InvokableType) target.getPointeeType();
}
@Override
int calcHashCode() {
return Objects.hash(CallNoSideEffects.class, target, receiver, arguments);
}
@Override
String getNodeName() {
return "CallNoSideEffects";
}
@Override
public boolean equals(Object other) {
return other instanceof CallNoSideEffects && equals((CallNoSideEffects) other);
}
public boolean equals(CallNoSideEffects other) {
return this == other || other != null && target.equals(other.target) && receiver.equals(other.receiver) && arguments.equals(other.arguments);
}
@Override
StringBuilder toRValueString(StringBuilder b) {
return InvocationNode.toRValueString(this, "call", b).append(" no-side-effects");
}
public InvokableType getCalleeType() {
return calleeType;
}
@Override
public ValueType getType() {
return getCalleeType().getReturnType();
}
public List getArguments() {
return arguments;
}
@Override
public Value getTarget() {
return target;
}
@Override
public Value getReceiver() {
return receiver;
}
@Override
public R accept(ValueVisitor visitor, T param) {
return visitor.visit(param, this);
}
public boolean isConstant() {
for (Value argument : arguments) {
if (! argument.isConstant()) {
return false;
}
}
return true;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy