Java Code Examples for proguard.evaluation.value.Value

The following examples show how to use proguard.evaluation.value.Value. These examples are extracted from open source projects. 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 Project: bazel   Source File: TracedStack.java    License: Apache License 2.0 6 votes vote down vote up
public String toString()
{
    StringBuffer buffer = new StringBuffer();

    for (int index = 0; index < this.size(); index++)
    {
        Value value               = this.values[index];
        Value producerValue       = producerStack.getBottom(index);
        Value actualProducerValue = actualProducerStack.getBottom(index);
        buffer = buffer.append('[')
                       .append(producerValue == null ? "empty:" :
                                                       producerValue.equals(actualProducerValue) ? producerValue.toString() :
                                                                                                   producerValue.toString() + actualProducerValue.toString())
                       .append(value         == null ? "empty"  : value.toString())
                       .append(']');
    }

    return buffer.toString();
}
 
Example 2
/**
 * Creates a new MethodOptimizationInfo for the given method.
 */
public MethodOptimizationInfo(Clazz clazz, Method method)
{
    // Set up an array of the right size for storing information about the
    // passed parameters.
    int parameterCount =
        ClassUtil.internalMethodParameterCount(method.getDescriptor(clazz));

    if ((method.getAccessFlags() & ClassConstants.ACC_STATIC) == 0)
    {
        parameterCount++;
    }

    if (parameterCount > 0)
    {
        parameters = new Value[parameterCount];
    }
}
 
Example 3
protected Value getMethodReturnValue(Clazz       clazz,
                                     RefConstant refConstant,
                                     String      type)
{
    if (loadMethodReturnValues)
    {
        // Do we know this method?
        Member referencedMember = refConstant.referencedMember;
        if (referencedMember != null)
        {
            // Retrieve the stored method return value.
            Value value = StoringInvocationUnit.getMethodReturnValue((Method)referencedMember);
            if (value != null &&
                value.isParticular())
            {
                return value;
            }
        }
    }

    return super.getMethodReturnValue(clazz,
                                      refConstant,
                                      type);
}
 
Example 4
Source Project: java-n-IDE-for-Android   Source File: Stack.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Copies the values of the given Stack into this Stack.
 */
public void copy(Stack other)
{
    // Is the values array large enough?
    if (other.values.length > values.length)
    {
        // Create a new one.
        values = new Value[other.values.length];
    }

    // Copy the stack contents.
    System.arraycopy(other.values, 0, this.values, 0, other.currentSize);

    // Copy the sizes.
    currentSize   = other.currentSize;
    actualMaxSize = other.actualMaxSize;
}
 
Example 5
protected Value getMethodParameterValue(Clazz  clazz,
                                        Method method,
                                        int    parameterIndex,
                                        String type,
                                        Clazz  referencedClass)
{
    if (loadMethodParameterValues)
    {
        // Retrieve the stored method parameter value.
        Value value = StoringInvocationUnit.getMethodParameterValue(method, parameterIndex);
        if (value != null &&
            value.isParticular())
        {
            return value;
        }
    }

    return super.getMethodParameterValue(clazz,
                                         method,
                                         parameterIndex,
                                         type,
                                         referencedClass);
}
 
Example 6
Source Project: java-n-IDE-for-Android   Source File: Stack.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Pushes the given Value onto the stack.
 */
public void push(Value value)
{
    // Account for the extra space required by Category 2 values.
    if (value.isCategory2())
    {
        values[currentSize++] = TOP_VALUE;
    }

    // Push the value.
    values[currentSize++] = value;

    // Update the maximum actual size;
    if (actualMaxSize < currentSize)
    {
        actualMaxSize = currentSize;
    }
}
 
Example 7
public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)
{
    if (partialEvaluator.isTraced(offset) &&
        variableInstruction.isLoad())
    {
        int parameterIndex = variableInstruction.variableIndex;
        if (parameterIndex < codeAttribute.u2maxLocals)
        {
            Value producer =
                partialEvaluator.getVariablesBefore(offset).getProducerValue(parameterIndex);
            if (producer != null &&
                producer.instructionOffsetValue().contains(PartialEvaluator.AT_METHOD_ENTRY))
            {
                // Mark the variable.
                markParameterUsed(method, parameterIndex);

                // Account for Category 2 instructions, which take up two entries.
                if (variableInstruction.isCategory2())
                {
                    markParameterUsed(method, parameterIndex + 1);
                }
            }
        }
    }
}
 
Example 8
Source Project: java-n-IDE-for-Android   Source File: TracedStack.java    License: Apache License 2.0 6 votes vote down vote up
public String toString()
{
    StringBuffer buffer = new StringBuffer();

    for (int index = 0; index < this.size(); index++)
    {
        Value value         = this.values[index];
        Value producerValue = producerStack.getBottom(index);
        buffer = buffer.append('[')
                       .append(producerValue == null ? "empty:" : producerValue.toString())
                       .append(value         == null ? "empty"  : value.toString())
                       .append(']');
    }

    return buffer.toString();
}
 
Example 9
Source Project: proguard   Source File: TracedStack.java    License: GNU General Public License v2.0 6 votes vote down vote up
public String toString()
{
    StringBuffer buffer = new StringBuffer();

    for (int index = 0; index < this.size(); index++)
    {
        Value value               = this.values[index];
        Value producerValue       = producerStack.getBottom(index);
        Value actualProducerValue = actualProducerStack.getBottom(index);
        buffer = buffer.append('[')
                       .append(producerValue == null ? "empty:" :
                                                       producerValue.equals(actualProducerValue) ? producerValue.toString() :
                                                                                                   producerValue.toString() + actualProducerValue.toString())
                       .append(value         == null ? "empty"  : value.toString())
                       .append(']');
    }

    return buffer.toString();
}
 
Example 10
Source Project: java-n-IDE-for-Android   Source File: Variables.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Resets this Variables object, so that it can be reused.
 */
public void reset(int size)
{
    // Is the values array large enough?
    if (size > values.length)
    {
        // Create a new one.
        values = new Value[size];
    }
    else
    {
        // Clear the variables.
        for (int index = 0; index < values.length; index++)
        {
            values[index] = null;
        }
    }

    this.size = size;
}
 
Example 11
Source Project: java-n-IDE-for-Android   Source File: Variables.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Stores the given Value at the given variable index.
 */
public void store(int index, Value value)
{
    if (index < 0 ||
        index >= size)
    {
        throw new IndexOutOfBoundsException("Variable index ["+index+"] out of bounds ["+size+"]");
    }

    // Store the value.
    values[index] = value;

    // Account for the extra space required by Category 2 values.
    if (value.isCategory2())
    {
        values[index + 1] = TOP_VALUE;
    }
}
 
Example 12
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value parameterValue = StoringInvocationUnit.getFieldValue(programField);
    if (parameterValue.computationalType() == Value.TYPE_REFERENCE)
    {
        Clazz referencedClass = parameterValue.referenceValue().getReferencedClass();
        if (programField.referencedClass != referencedClass)
        {
            if (DEBUG)
            {
                System.out.println("MemberDescriptorSpecializer: "+programClass.getName()+"."+programField.getName(programClass)+" "+programField.getDescriptor(programClass));
                System.out.println("  "+programField.referencedClass.getName()+" -> "+referencedClass.getName());
            }

            programField.referencedClass = referencedClass;

            // Visit the field, if required.
            if (extraParameterMemberVisitor != null)
            {
                extraParameterMemberVisitor.visitProgramField(programClass, programField);
            }
        }
    }
}
 
Example 13
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    int firstParameterIndex =
        (programMethod.getAccessFlags() & ClassConstants.ACC_STATIC) != 0 ?
            0 : 1;

    int parameterCount =
        ClassUtil.internalMethodParameterCount(programMethod.getDescriptor(programClass));

    for (int index = firstParameterIndex; index < parameterCount; index++)
    {
        Value value = StoringInvocationUnit.getMethodParameterValue(programMethod, index);
        if (value != null &&
            value.isParticular())
        {
            constantParameterVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 14
Source Project: java-n-IDE-for-Android   Source File: Processor.java    License: Apache License 2.0 6 votes vote down vote up
public void visitLookUpSwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, LookUpSwitchInstruction lookUpSwitchInstruction)
{
    IntegerValue indexValue = stack.ipop();

    // If there is no definite branch in any of the cases below,
    // branch to the default offset.
    branchUnit.branch(clazz, codeAttribute,
                      offset,
                      offset + lookUpSwitchInstruction.defaultOffset);

    for (int index = 0; index < lookUpSwitchInstruction.jumpOffsets.length; index++)
    {
        int conditional = indexValue.equal(valueFactory.createIntegerValue(
            lookUpSwitchInstruction.cases[index]));
        branchUnit.branchConditionally(clazz, codeAttribute,
                                       offset,
                                       offset + lookUpSwitchInstruction.jumpOffsets[index],
                                       conditional);

        // If this branch is always taken, we can skip the rest.
        if (conditional == Value.ALWAYS)
        {
            break;
        }
    }
}
 
Example 15
/**
 * Creates a new MethodOptimizationInfo for the given method.
 */
public MethodOptimizationInfo(Clazz clazz, Method method)
{
    // Set up an array of the right size for storing information about the
    // passed parameters.
    int parameterCount =
        ClassUtil.internalMethodParameterCount(method.getDescriptor(clazz));

    if ((method.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) == 0)
    {
        parameterCount++;
    }

    if (parameterCount > 0)
    {
        parameters = new Value[parameterCount];
    }
}
 
Example 16
public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)
{
    if (partialEvaluator.isTraced(offset) &&
        variableInstruction.isLoad())
    {
        int parameterIndex = variableInstruction.variableIndex;
        if (parameterIndex < codeAttribute.u2maxLocals)
        {
            Value producer =
                partialEvaluator.getVariablesBefore(offset).getProducerValue(parameterIndex);
            if (producer != null &&
                producer.instructionOffsetValue().contains(PartialEvaluator.AT_METHOD_ENTRY))
            {
                // Mark the variable.
                markParameterUsed(method, parameterIndex);

                // Account for Category 2 instructions, which take up two entries.
                if (variableInstruction.isCategory2())
                {
                    markParameterUsed(method, parameterIndex + 1);
                }
            }
        }
    }
}
 
Example 17
Source Project: bazel   Source File: ConstantParameterFilter.java    License: Apache License 2.0 6 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // All parameters of non-static methods are shifted by one in the local
    // variable frame.
    int firstParameterIndex =
        (programMethod.getAccessFlags() & ClassConstants.ACC_STATIC) != 0 ?
            0 : 1;

    int parameterCount =
        ClassUtil.internalMethodParameterCount(programMethod.getDescriptor(programClass));

    for (int index = firstParameterIndex; index < parameterCount; index++)
    {
        Value value = StoringInvocationUnit.getMethodParameterValue(programMethod, index);
        if (value != null &&
            value.isParticular())
        {
            constantParameterVisitor.visitProgramMethod(programClass, programMethod);
        }
    }
}
 
Example 18
Source Project: java-n-IDE-for-Android   Source File: TracedBranchUnit.java    License: Apache License 2.0 6 votes vote down vote up
public void branchConditionally(Clazz         clazz,
                                CodeAttribute codeAttribute,
                                int           offset,
                                int           branchTarget,
                                int           conditional)
{
    if      (conditional == Value.ALWAYS)
    {
        // Always branch.
        super.branch(clazz, codeAttribute, offset, branchTarget);
    }
    else if (conditional != Value.NEVER)
    {
        // Maybe branch.
        super.branchConditionally(clazz, codeAttribute, offset, branchTarget, conditional);
    }
    else
    {
        super.setCalled();
    }
}
 
Example 19
Source Project: proguard   Source File: TracedBranchUnit.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void branchConditionally(Clazz         clazz,
                                CodeAttribute codeAttribute,
                                int           offset,
                                int           branchTarget,
                                int           conditional)
{
    if      (conditional == Value.ALWAYS)
    {
        // Always branch.
        super.branch(clazz, codeAttribute, offset, branchTarget);
    }
    else if (conditional != Value.NEVER)
    {
        // Maybe branch.
        super.branchConditionally(clazz, codeAttribute, offset, branchTarget, conditional);
    }
    else
    {
        super.setCalled();
    }
}
 
Example 20
/**
 * Creates a new MethodOptimizationInfo for the given method.
 */
public ProgramMethodOptimizationInfo(Clazz clazz, Method method)
{
    // Set up an array of the right size for storing information about the
    // passed parameters (including 'this', for non-static methods).
    int parameterCount =
        ClassUtil.internalMethodParameterCount(method.getDescriptor(clazz),
                                               method.getAccessFlags());

    parameters = parameterCount == 0 ?
        EMPTY_PARAMETERS :
        new Value[parameterCount];
}
 
Example 21
public static Value getMethodParameterValue(Method method, int parameterIndex)
{
    MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method);
    return info != null ?
        info.getParameter(parameterIndex) :
        null;
}
 
Example 22
public static Value getMethodReturnValue(Method method)
{
    MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method);
    return info != null ?
        info.getReturnValue() :
        null;
}
 
Example 23
/**
 * Sets the value of the specified field.
 */
protected void setFieldValue(Clazz       clazz,
                             RefConstant refConstant,
                             Value value)
{
    // We don't care about the new field value.
}
 
Example 24
/**
 * Returns the value of the specified field.
 */
protected Value getFieldValue(Clazz       clazz,
                              RefConstant refConstant,
                              String      type)
{
    // Try to figure out the class of the return type.
    returnTypeClass = null;
    refConstant.referencedMemberAccept(this);

    return valueFactory.createValue(type,
                                    returnTypeClass,
                                    true);
}
 
Example 25
/**
 * Sets the value of the specified method parameter.
 */
protected void setMethodParameterValue(Clazz       clazz,
                                       RefConstant refConstant,
                                       int         parameterIndex,
                                       Value value)
{
    // We don't care about the parameter value.
}
 
Example 26
Source Project: bazel   Source File: ConstantMemberFilter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
    Value value = StoringInvocationUnit.getFieldValue(programField);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramField(programClass, programField);
    }
}
 
Example 27
/**
 * Returns the return value of the specified method.
 */
protected Value getMethodReturnValue(Clazz       clazz,
                                     RefConstant refConstant,
                                     String      type)
{
    // Try to figure out the class of the return type.
    returnTypeClass = null;
    refConstant.referencedMemberAccept(this);

    return valueFactory.createValue(type,
                                    returnTypeClass,
                                    true);
}
 
Example 28
Source Project: bazel   Source File: TracedVariables.java    License: Apache License 2.0 5 votes vote down vote up
public void store(int index, Value value)
{
    // Store the value itself in the variable.
    super.store(index, value);

    // Store the producer value in its producer variable.
    producerVariables.store(index, producerValue);

    // Account for the extra space required by Category 2 values.
    if (value.isCategory2())
    {
        producerVariables.store(index+1, producerValue);
    }
}
 
Example 29
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    Value value = StoringInvocationUnit.getMethodReturnValue(programMethod);
    if (value != null &&
        value.isParticular())
    {
        constantMemberVisitor.visitProgramMethod(programClass, programMethod);
    }
}
 
Example 30
Source Project: java-n-IDE-for-Android   Source File: Stack.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Pops the top Value from the stack.
 */
public Value pop()
{
    Value value = values[--currentSize];

    values[currentSize] = null;

    // Account for the extra space required by Category 2 values.
    if (value.isCategory2())
    {
        values[--currentSize] = null;
    }

    return value;
}