Java Code Examples for proguard.evaluation.value.Value#equals()

The following examples show how to use proguard.evaluation.value.Value#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Stack.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Generalizes the values of this Stack with the values of the given Stack.
 * The stacks must have the same current sizes.
 * @return whether the generalization has made any difference.
 */
public boolean generalize(Stack other)
{
    if (this.currentSize != other.currentSize)
    {
        throw new IllegalArgumentException("Stacks have different current sizes ["+this.currentSize+"] and ["+other.currentSize+"]");
    }

    boolean changed = false;

    // Generalize the stack values.
    for (int index = 0; index < currentSize; index++)
    {
        Value thisValue  = this.values[index];

        if (thisValue != null)
        {
            Value newValue = null;

            Value otherValue = other.values[index];

            if (otherValue != null)
            {
                newValue = thisValue.generalize(otherValue);
            }

            changed = changed || !thisValue.equals(newValue);

            values[index] = newValue;
        }
    }

    // Check if the other stack extends beyond this one.
    if (this.actualMaxSize < other.actualMaxSize)
    {
        this.actualMaxSize = other.actualMaxSize;
    }

    return changed;
}
 
Example 2
Source File: Stack.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object object)
{
    if (object == null ||
        this.getClass() != object.getClass())
    {
        return false;
    }

    Stack other = (Stack)object;

    if (this.currentSize != other.currentSize)
    {
        return false;
    }

    for (int index = 0; index < currentSize; index++)
    {
        Value thisValue  = this.values[index];
        Value otherValue = other.values[index];
        if (thisValue == null ? otherValue != null :
                                !thisValue.equals(otherValue))
        {
            return false;
        }
    }

    return true;
}
 
Example 3
Source File: Variables.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public boolean equals(Object object)
{
    if (object == null ||
        this.getClass() != object.getClass())
    {
        return false;
    }

    Variables other = (Variables)object;

    if (this.size != other.size)
    {
        return false;
    }

    for (int index = 0; index < size; index++)
    {
        Value thisValue  = this.values[index];
        Value otherValue = other.values[index];

        // Occasionally, two values of different types might be
        // present in the same variable in a variable frame
        // (corresponding to two local variables that share the
        // same index), at some point outside of their scopes.
        // We'll ignore these.
        if (thisValue  != null &&
            otherValue != null &&
            thisValue.computationalType() == otherValue.computationalType() &&
            !thisValue.equals(otherValue))
        {
            return false;
        }
    }

    return true;
}
 
Example 4
Source File: Variables.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Generalizes the values of this Variables object with the values of the
 * given Variables object.
 * @param clearConflictingOtherVariables specifies whether the other
 *                                       variables should be cleared too,
 *                                       in case of conflicts.
 * @return whether the generalization has made any difference.
 */
public boolean generalize(Variables other,
                          boolean   clearConflictingOtherVariables)
{
    if (this.size != other.size)
    {
        throw new IllegalArgumentException("Variable frames have different sizes ["+this.size+"] and ["+other.size+"]");
    }

    boolean changed = false;

    for (int index = 0; index < size; index++)
    {
        Value thisValue  = this.values[index];
        Value otherValue = other.values[index];

        // Occasionally, two values of different types might be present
        // in the same variable in a variable frame (corresponding to
        // two local variables that share the same index), at some point
        // outside of their scopes. Don't generalize the variable then,
        // but let it clear instead.
        if (thisValue  != null &&
            otherValue != null &&
            thisValue.computationalType() == otherValue.computationalType())
        {
            Value newValue = thisValue.generalize(otherValue);

            changed = changed || !thisValue.equals(newValue);

            this.values[index] = newValue;
        }
        else
        {
            changed = changed || thisValue != null;

            this.values[index] = null;

            if (clearConflictingOtherVariables)
            {
                other.values[index] = null;
            }
        }
    }

    return changed;
}
 
Example 5
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the integer pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceIntegerPushInstruction(Clazz       clazz,
                                           int         offset,
                                           Instruction instruction,
                                           int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        int value = pushedValue.integerValue().value();
        if (value << 16 >> 16 == value)
        {
            replaceConstantPushInstruction(clazz,
                                           offset,
                                           instruction,
                                           InstructionConstants.OP_SIPUSH,
                                           value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC,
                                        constantPoolEditor.addIntegerConstant(value)).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            if (pushedValue.equals(variables.load(variableIndex)))
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_ILOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 6
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the long pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceLongPushInstruction(Clazz       clazz,
                                        int         offset,
                                        Instruction instruction,
                                        int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        long value = pushedValue.longValue().value();
        if (value == 0L ||
            value == 1L)
        {
            replaceConstantPushInstruction(clazz,
                                   offset,
                                   instruction,
                                   InstructionConstants.OP_LCONST_0,
                                   (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC2_W,
                                        constantPoolEditor.addLongConstant(value)).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            if (pushedValue.equals(variables.load(variableIndex)))
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_LLOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 7
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the float pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceFloatPushInstruction(Clazz       clazz,
                                         int         offset,
                                         Instruction instruction,
                                         int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // Make sure to distinguish between +0.0 and -0.0.
        float value = pushedValue.floatValue().value();
        if (value == 0.0f && Float.floatToIntBits(value) == POS_ZERO_FLOAT_BITS ||
            value == 1.0f ||
            value == 2.0f)
        {
            replaceConstantPushInstruction(clazz,
                                           offset,
                                           instruction,
                                           InstructionConstants.OP_FCONST_0,
                                           (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC,
                                        constantPoolEditor.addFloatConstant(value)).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            if (pushedValue.equals(variables.load(variableIndex)))
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_FLOAD,
                                               variableIndex);
            }
        }
    }
}
 
Example 8
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Replaces the double pushing instruction at the given offset by a simpler
 * push instruction, if possible.
 */
private void replaceDoublePushInstruction(Clazz       clazz,
                                          int         offset,
                                          Instruction instruction,
                                          int         maxVariableIndex)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // Make sure to distinguish between +0.0 and -0.0.
        double value = pushedValue.doubleValue().value();
        if (value == 0.0 && Double.doubleToLongBits(value) == POS_ZERO_DOUBLE_BITS ||
            value == 1.0)
        {
            replaceConstantPushInstruction(clazz,
                                           offset,
                                           instruction,
                                           InstructionConstants.OP_DCONST_0,
                                           (int)value);
        }
        else
        {
            ConstantPoolEditor constantPoolEditor =
                new ConstantPoolEditor((ProgramClass)clazz);

            Instruction replacementInstruction =
                new ConstantInstruction(InstructionConstants.OP_LDC2_W,
                                        constantPoolEditor.addDoubleConstant(value)).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
    else if (pushedValue.isSpecific())
    {
        TracedVariables variables = partialEvaluator.getVariablesBefore(offset);
        for (int variableIndex = 0; variableIndex < maxVariableIndex; variableIndex++)
        {
            if (pushedValue.equals(variables.load(variableIndex)))
            {
                replaceVariablePushInstruction(clazz,
                                               offset,
                                               instruction,
                                               InstructionConstants.OP_DLOAD,
                                               variableIndex);
            }
        }
    }
}