Search in sources :

Example 1 with In

use of com.intellij.codeInspection.bytecodeAnalysis.Direction.In 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;
}
Also used : Frame(org.jetbrains.org.objectweb.asm.tree.analysis.Frame) Type(org.jetbrains.org.objectweb.asm.Type) In(com.intellij.codeInspection.bytecodeAnalysis.Direction.In) InOut(com.intellij.codeInspection.bytecodeAnalysis.Direction.InOut) BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)

Example 2 with In

use of com.intellij.codeInspection.bytecodeAnalysis.Direction.In in project intellij-community by JetBrains.

the class NullableInterpreter method naryOperation.

@Override
public BasicValue naryOperation(AbstractInsnNode insn, List<? extends BasicValue> values) throws AnalyzerException {
    int opcode = insn.getOpcode();
    boolean isStaticInvoke = opcode == INVOKESTATIC;
    int shift = isStaticInvoke ? 0 : 1;
    if ((opcode == INVOKESPECIAL || opcode == INVOKEINTERFACE || opcode == INVOKEVIRTUAL) && values.get(0) instanceof ParamValue) {
        subResult = NPE;
    }
    switch(opcode) {
        case INVOKEINTERFACE:
            if (nullableAnalysis) {
                for (int i = shift; i < values.size(); i++) {
                    if (values.get(i) instanceof ParamValue) {
                        top = true;
                        return super.naryOperation(insn, values);
                    }
                }
            }
            break;
        case INVOKESTATIC:
        case INVOKESPECIAL:
        case INVOKEVIRTUAL:
            boolean stable = opcode == INVOKESTATIC || opcode == INVOKESPECIAL;
            MethodInsnNode methodNode = (MethodInsnNode) insn;
            Method method = new Method(methodNode.owner, methodNode.name, methodNode.desc);
            for (int i = shift; i < values.size(); i++) {
                BasicValue value = values.get(i);
                if (value instanceof ParamValue || (NullValue == value && nullityMask == In.NULLABLE_MASK && "<init>".equals(methodNode.name))) {
                    subResult = combine(subResult, new ConditionalNPE(new Key(method, new In(i - shift, nullityMask), stable)));
                }
            }
            break;
        default:
    }
    return super.naryOperation(insn, values);
}
Also used : In(com.intellij.codeInspection.bytecodeAnalysis.Direction.In) MethodInsnNode(org.jetbrains.org.objectweb.asm.tree.MethodInsnNode) BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)

Aggregations

In (com.intellij.codeInspection.bytecodeAnalysis.Direction.In)2 BasicValue (org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue)2 InOut (com.intellij.codeInspection.bytecodeAnalysis.Direction.InOut)1 Type (org.jetbrains.org.objectweb.asm.Type)1 MethodInsnNode (org.jetbrains.org.objectweb.asm.tree.MethodInsnNode)1 Frame (org.jetbrains.org.objectweb.asm.tree.analysis.Frame)1