Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jruby.ir.operands;
 
 
public abstract class Operand {
    public static final Operand[] EMPTY_ARRAY = new Operand[0];

    
Do we know the value of this operand at compile-time? If we do then it may be possible to constant propagate (one case: We also know it is also an ImmutableLiteral).

Returns:
true if a known compile-time value.
    public boolean hasKnownValue() {
        return false;
    }

    
Can we replace every use of a variable 'v' that contains the value of this operand with the operand itself? This takes importance when there are at least two uses of 'v' within this scope. Ex: v = [1,2,3]; x = v; y = v In this case, we cannot replace the occurences of 'v' because we would then get x = [1,2,3]; y = [1,2,3] which would then result in two different array objects being constructed instead of a single one.

Returns:
true if it is safe to copy-propagate the operand.
    public boolean canCopyPropagate() {
        return false;
    }
    // SSS: HUH? Use better names than this .. The distinction is not very clear!
    //
    // getValue returns the value of this operand, fully simplified
    // getSimplifiedOperand returns the operand in a form that can be materialized into bytecode, if it cannot be completely optimized away
    //
    // The value is used during optimizations and propagated through the IR.  But, it is thrown away after that.
    // But, the operand form is used for constructing the compound objects represented by the operand.
    //
    // Example: a = 1, b = [3,4], c = [a,b], d = [2,c]
    //   -- getValue(c) = [1,[3,4]];     getSimplifiedOperand(c) = [1, b]
    //   -- getValue(d) = [2,[1,[3,4]]]; getSimplifiedOperand(d) = [2, c]
    //
    // Note that b,c,d are all compound objects, and c has a reference to objects a and b, and d has a reference to c.
    // So, if contents of b is modified, the "simplified value"s of c and d also change!  This difference
    // is captured by these two methods.
    public Operand getSimplifiedOperand(Map<OperandOperandvalueMapboolean force) {
        return this;
    }
    public Operand getValue(Map<OperandOperandvalueMap) {
        return this;
    }
    // if (getSubArray) is false, returns the 'index' element of the array, else returns the subarray starting at that element
    public Operand fetchCompileTimeArrayElement(int indexboolean getSubArray) {
        return null;
    }

    
Append the list of variables used in this operand to the input list -- force every operand to implement this because a missing implementation can cause bad failures.
    public abstract void addUsedVariables(List<Variablel);
    public abstract Operand cloneForInlining(InlinerInfo ii);
    @Interp
    public Object retrieve(ThreadContext contextIRubyObject selfDynamicScope currDynScopeObject[] temp) {
        throw new RuntimeException(this.getClass().getSimpleName() + " should not be directly retrieved.");
    }
    public void visit(IRVisitor visitor) {
        throw new RuntimeException("operand " + this.getClass().getSimpleName() + " has no visit logic.");
    }
New to GrepCode? Check out our FAQ X