use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.
the class Analysis method createStartFrame.
final Frame<BasicValue> createStartFrame() {
Frame<BasicValue> frame = new Frame<>(methodNode.maxLocals, methodNode.maxStack);
Type returnType = Type.getReturnType(methodNode.desc);
BasicValue returnValue = Type.VOID_TYPE.equals(returnType) ? null : new BasicValue(returnType);
frame.setReturn(returnValue);
Type[] args = Type.getArgumentTypes(methodNode.desc);
int local = 0;
if ((methodNode.access & Opcodes.ACC_STATIC) == 0) {
frame.setLocal(local++, new AbstractValues.NotNullValue(Type.getObjectType(controlFlow.className)));
}
for (int i = 0; i < args.length; i++) {
BasicValue value;
if (direction instanceof InOut && ((InOut) direction).paramIndex == i || direction instanceof In && ((In) direction).paramIndex == i) {
value = new AbstractValues.ParamValue(args[i]);
} else {
value = new BasicValue(args[i]);
}
frame.setLocal(local++, value);
if (args[i].getSize() == 2) {
frame.setLocal(local++, BasicValue.UNINITIALIZED_VALUE);
}
}
while (local < methodNode.maxLocals) {
frame.setLocal(local++, BasicValue.UNINITIALIZED_VALUE);
}
return frame;
}
use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.
the class NegationInterpreter method analyze.
final void analyze() throws AnalyzerException, NegationAnalysisFailure {
Frame<BasicValue> frame = createStartFrame();
int insnIndex = 0;
while (true) {
AbstractInsnNode insnNode = methodNode.instructions.get(insnIndex);
switch(insnNode.getType()) {
case AbstractInsnNode.LABEL:
case AbstractInsnNode.LINE:
case AbstractInsnNode.FRAME:
insnIndex = controlFlow.transitions[insnIndex][0];
break;
default:
switch(insnNode.getOpcode()) {
case IFEQ:
case IFNE:
BasicValue conValue = popValue(frame);
checkAssertion(conValue instanceof TrackableCallValue);
frame.execute(insnNode, interpreter);
conditionValue = (TrackableCallValue) conValue;
int jumpIndex = methodNode.instructions.indexOf(((JumpInsnNode) insnNode).label);
int nextIndex = insnIndex + 1;
proceedBranch(frame, jumpIndex, IFNE == insnNode.getOpcode());
proceedBranch(frame, nextIndex, IFEQ == insnNode.getOpcode());
checkAssertion(FalseValue == trueBranchValue);
checkAssertion(TrueValue == falseBranchValue);
return;
default:
frame.execute(insnNode, interpreter);
insnIndex = controlFlow.transitions[insnIndex][0];
}
}
}
}
use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.
the class NegationInterpreter method proceedBranch.
private void proceedBranch(Frame<BasicValue> startFrame, int startIndex, boolean branchValue) throws NegationAnalysisFailure, AnalyzerException {
Frame<BasicValue> frame = new Frame<>(startFrame);
int insnIndex = startIndex;
while (true) {
AbstractInsnNode insnNode = methodNode.instructions.get(insnIndex);
switch(insnNode.getType()) {
case AbstractInsnNode.LABEL:
case AbstractInsnNode.LINE:
case AbstractInsnNode.FRAME:
insnIndex = controlFlow.transitions[insnIndex][0];
break;
default:
switch(insnNode.getOpcode()) {
case IRETURN:
BasicValue returnValue = frame.pop();
if (branchValue) {
trueBranchValue = returnValue;
} else {
falseBranchValue = returnValue;
}
return;
default:
checkAssertion(controlFlow.transitions[insnIndex].length == 1);
frame.execute(insnNode, interpreter);
insnIndex = controlFlow.transitions[insnIndex][0];
}
}
}
}
use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.
the class NegationInterpreter method createStartFrame.
final Frame<BasicValue> createStartFrame() {
Frame<BasicValue> frame = new Frame<>(methodNode.maxLocals, methodNode.maxStack);
Type returnType = Type.getReturnType(methodNode.desc);
BasicValue returnValue = Type.VOID_TYPE.equals(returnType) ? null : new BasicValue(returnType);
frame.setReturn(returnValue);
Type[] args = Type.getArgumentTypes(methodNode.desc);
int local = 0;
if ((methodNode.access & ACC_STATIC) == 0) {
frame.setLocal(local++, ThisValue);
}
for (int i = 0; i < args.length; i++) {
BasicValue value = new NthParamValue(args[i], i);
frame.setLocal(local++, value);
if (args[i].getSize() == 2) {
frame.setLocal(local++, BasicValue.UNINITIALIZED_VALUE);
}
}
while (local < methodNode.maxLocals) {
frame.setLocal(local++, BasicValue.UNINITIALIZED_VALUE);
}
return frame;
}
use of org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue in project intellij-community by JetBrains.
the class NegationInterpreter method contractEquation.
final Equation contractEquation(int i, Value inValue, boolean stable) {
final Key key = new Key(method, new InOut(i, inValue), stable);
final Result result;
if (exception || (inValue == Value.Null && interpreter.dereferencedParams[i])) {
result = new Final(Value.Bot);
} else if (FalseValue == returnValue) {
result = new Final(Value.False);
} else if (TrueValue == returnValue) {
result = new Final(Value.True);
} else if (returnValue instanceof TrackableNullValue) {
result = new Final(Value.Null);
} else if (returnValue instanceof NotNullValue || ThisValue == returnValue) {
result = new Final(Value.NotNull);
} else if (returnValue instanceof NthParamValue && ((NthParamValue) returnValue).n == i) {
result = new Final(inValue);
} else if (returnValue instanceof TrackableCallValue) {
TrackableCallValue call = (TrackableCallValue) returnValue;
HashSet<Key> keys = new HashSet<>();
for (int argI = 0; argI < call.args.size(); argI++) {
BasicValue arg = call.args.get(argI);
if (arg instanceof NthParamValue) {
NthParamValue npv = (NthParamValue) arg;
if (npv.n == i) {
keys.add(new Key(call.method, new InOut(argI, inValue), call.stableCall));
}
}
}
if (ASMUtils.isReferenceType(call.getType())) {
keys.add(new Key(call.method, Out, call.stableCall));
}
if (keys.isEmpty()) {
result = new Final(Value.Top);
} else {
result = new Pending(new SingletonSet<>(new Product(Value.Top, keys)));
}
} else {
result = new Final(Value.Top);
}
return new Equation(key, result);
}
Aggregations