Java源码示例:proguard.evaluation.value.Value
示例1
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();
}
示例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];
}
}
示例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);
}
示例4
/**
* 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;
}
示例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);
}
示例6
/**
* 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;
}
}
示例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);
}
}
}
}
}
示例8
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();
}
示例9
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();
}
示例10
/**
* 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;
}
示例11
/**
* 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;
}
}
示例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);
}
}
}
}
示例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);
}
}
}
示例14
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;
}
}
}
示例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];
}
}
示例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);
}
}
}
}
}
示例17
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);
}
}
}
示例18
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();
}
}
示例19
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();
}
}
示例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];
}
示例21
public static Value getMethodParameterValue(Method method, int parameterIndex)
{
MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method);
return info != null ?
info.getParameter(parameterIndex) :
null;
}
示例22
public static Value getMethodReturnValue(Method method)
{
MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method);
return info != null ?
info.getReturnValue() :
null;
}
示例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.
}
示例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);
}
示例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.
}
示例26
public void visitProgramField(ProgramClass programClass, ProgramField programField)
{
Value value = StoringInvocationUnit.getFieldValue(programField);
if (value != null &&
value.isParticular())
{
constantMemberVisitor.visitProgramField(programClass, programField);
}
}
示例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);
}
示例28
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);
}
}
示例29
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
Value value = StoringInvocationUnit.getMethodReturnValue(programMethod);
if (value != null &&
value.isParticular())
{
constantMemberVisitor.visitProgramMethod(programClass, programMethod);
}
}
示例30
/**
* 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;
}