package org.jruby.ir.operands;
import org.jruby.ir.IRVisitor;
import org.jruby.ir.persistence.IRReaderDecoder;
import org.jruby.ir.persistence.IRWriterEncoder;
import org.jruby.ir.transformations.inlining.CloneInfo;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.DynamicScope;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import java.util.List;
import java.util.Map;
public class Splat extends Operand implements DepthCloneable {
final private Operand array;
public Splat(Operand array) {
super();
this.array = array;
}
@Override
public OperandType getOperandType() {
return OperandType.SPLAT;
}
@Override
public String toString() {
return "*(unsplat)" + array;
}
@Override
public boolean hasKnownValue() {
return false;
}
public Operand getArray() {
return array;
}
@Override
public Operand getSimplifiedOperand(Map<Operand, Operand> valueMap, boolean force) {
Operand newArray = array.getSimplifiedOperand(valueMap, force);
return (newArray == array) ? this : new Splat(newArray);
}
@Override
public void addUsedVariables(List<Variable> l) {
array.addUsedVariables(l);
}
public Operand cloneForDepth(int n) {
return array instanceof LocalVariable ? new Splat(((LocalVariable) array).cloneForDepth(n)) : this;
}
@Override
public Operand cloneForInlining(CloneInfo ii) {
return hasKnownValue() ? this : new Splat(array.cloneForInlining(ii));
}
@Override
public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) {
return array.retrieve(context, self, currScope, currDynScope, temp);
}
@Override
public void encode(IRWriterEncoder e) {
super.encode(e);
e.encode(getArray());
}
public static Splat decode(IRReaderDecoder d) {
return new Splat(d.decodeOperand());
}
@Override
public void visit(IRVisitor visitor) {
visitor.Splat(this);
}
}