Search in sources :

Example 46 with Type

use of org.jetbrains.org.objectweb.asm.Type in project intellij-community by JetBrains.

the class GridBagLayoutCodeGenerator method checkSetSize.

private static void checkSetSize(final GeneratorAdapter generator, final int componentLocal, final String methodName, final Dimension dimension) {
    if (dimension != null) {
        generator.loadLocal(componentLocal);
        AsmCodeGenerator.pushPropValue(generator, "java.awt.Dimension", dimension);
        generator.invokeVirtual(Type.getType(Component.class), new Method(methodName, Type.VOID_TYPE, new Type[] { Type.getType(Dimension.class) }));
    }
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) Method(org.jetbrains.org.objectweb.asm.commons.Method) LwComponent(com.intellij.uiDesigner.lw.LwComponent)

Example 47 with Type

use of org.jetbrains.org.objectweb.asm.Type 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 48 with Type

use of org.jetbrains.org.objectweb.asm.Type in project intellij-community by JetBrains.

the class LiteAnalyzer method analyze.

public Frame<V>[] analyze(final String owner, final MethodNode m) throws AnalyzerException {
    if ((m.access & (ACC_ABSTRACT | ACC_NATIVE)) != 0 || m.instructions.size() == 0) {
        frames = (Frame<V>[]) new Frame<?>[0];
        return frames;
    }
    int n = m.instructions.size();
    InsnList insns = m.instructions;
    List<TryCatchBlockNode>[] handlers = (List<TryCatchBlockNode>[]) new List<?>[n];
    frames = (Frame<V>[]) new Frame<?>[n];
    queued = new boolean[n];
    queue = new int[n];
    top = 0;
    // computes exception handlers for each instruction
    for (int i = 0; i < m.tryCatchBlocks.size(); ++i) {
        TryCatchBlockNode tcb = m.tryCatchBlocks.get(i);
        int begin = insns.indexOf(tcb.start);
        int end = insns.indexOf(tcb.end);
        for (int j = begin; j < end; ++j) {
            List<TryCatchBlockNode> insnHandlers = handlers[j];
            if (insnHandlers == null) {
                insnHandlers = new ArrayList<>();
                handlers[j] = insnHandlers;
            }
            insnHandlers.add(tcb);
        }
    }
    // initializes the data structures for the control flow analysis
    Frame<V> current = new Frame<>(m.maxLocals, m.maxStack);
    Frame<V> handler = new Frame<>(m.maxLocals, m.maxStack);
    current.setReturn(interpreter.newValue(Type.getReturnType(m.desc)));
    Type[] args = Type.getArgumentTypes(m.desc);
    int local = 0;
    if ((m.access & ACC_STATIC) == 0) {
        Type ctype = Type.getObjectType(owner);
        current.setLocal(local++, interpreter.newValue(ctype));
    }
    for (int i = 0; i < args.length; ++i) {
        current.setLocal(local++, interpreter.newValue(args[i]));
        if (args[i].getSize() == 2) {
            current.setLocal(local++, interpreter.newValue(null));
        }
    }
    while (local < m.maxLocals) {
        current.setLocal(local++, interpreter.newValue(null));
    }
    merge(0, current);
    // control flow analysis
    while (top > 0) {
        int insn = queue[--top];
        Frame<V> f = frames[insn];
        queued[insn] = false;
        AbstractInsnNode insnNode = null;
        try {
            insnNode = m.instructions.get(insn);
            int insnOpcode = insnNode.getOpcode();
            int insnType = insnNode.getType();
            if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) {
                merge(insn + 1, f);
            } else {
                current.init(f).execute(insnNode, interpreter);
                if (insnNode instanceof JumpInsnNode) {
                    JumpInsnNode j = (JumpInsnNode) insnNode;
                    if (insnOpcode != GOTO && insnOpcode != JSR) {
                        merge(insn + 1, current);
                    }
                    int jump = insns.indexOf(j.label);
                    merge(jump, current);
                } else if (insnNode instanceof LookupSwitchInsnNode) {
                    LookupSwitchInsnNode lsi = (LookupSwitchInsnNode) insnNode;
                    int jump = insns.indexOf(lsi.dflt);
                    merge(jump, current);
                    for (int j = 0; j < lsi.labels.size(); ++j) {
                        LabelNode label = lsi.labels.get(j);
                        jump = insns.indexOf(label);
                        merge(jump, current);
                    }
                } else if (insnNode instanceof TableSwitchInsnNode) {
                    TableSwitchInsnNode tsi = (TableSwitchInsnNode) insnNode;
                    int jump = insns.indexOf(tsi.dflt);
                    merge(jump, current);
                    for (int j = 0; j < tsi.labels.size(); ++j) {
                        LabelNode label = tsi.labels.get(j);
                        jump = insns.indexOf(label);
                        merge(jump, current);
                    }
                } else if (insnOpcode != ATHROW && (insnOpcode < IRETURN || insnOpcode > RETURN)) {
                    merge(insn + 1, current);
                }
            }
            List<TryCatchBlockNode> insnHandlers = handlers[insn];
            if (insnHandlers != null) {
                for (int i = 0; i < insnHandlers.size(); ++i) {
                    TryCatchBlockNode tcb = insnHandlers.get(i);
                    int jump = insns.indexOf(tcb.handler);
                    handler.init(f);
                    handler.clearStack();
                    handler.push(interpreter.newValue(ASMUtils.THROWABLE_TYPE));
                    merge(jump, handler);
                }
            }
        } catch (AnalyzerException e) {
            throw new AnalyzerException(e.node, "Error at instruction " + insn + ": " + e.getMessage(), e);
        } catch (Exception e) {
            throw new AnalyzerException(insnNode, "Error at instruction " + insn + ": " + e.getMessage(), e);
        }
    }
    return frames;
}
Also used : Frame(org.jetbrains.org.objectweb.asm.tree.analysis.Frame) AnalyzerException(org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException) AnalyzerException(org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException) Type(org.jetbrains.org.objectweb.asm.Type) List(java.util.List) ArrayList(java.util.ArrayList)

Example 49 with Type

use of org.jetbrains.org.objectweb.asm.Type in project intellij-community by JetBrains.

the class LiteAnalyzerExt method analyze.

public Frame<V>[] analyze(final String owner, final MethodNode m) throws AnalyzerException {
    if ((m.access & (ACC_ABSTRACT | ACC_NATIVE)) != 0) {
        frames = (Frame<V>[]) new Frame<?>[0];
        return frames;
    }
    final V refV = (V) BasicValue.REFERENCE_VALUE;
    int n = m.instructions.size();
    InsnList insns = m.instructions;
    List<TryCatchBlockNode>[] handlers = (List<TryCatchBlockNode>[]) new List<?>[n];
    frames = (Frame<V>[]) new Frame<?>[n];
    queued = new boolean[n];
    queue = new int[n];
    top = 0;
    // computes exception handlers for each instruction
    for (int i = 0; i < m.tryCatchBlocks.size(); ++i) {
        TryCatchBlockNode tcb = m.tryCatchBlocks.get(i);
        int begin = insns.indexOf(tcb.start);
        int end = insns.indexOf(tcb.end);
        for (int j = begin; j < end; ++j) {
            List<TryCatchBlockNode> insnHandlers = handlers[j];
            if (insnHandlers == null) {
                insnHandlers = new ArrayList<>();
                handlers[j] = insnHandlers;
            }
            insnHandlers.add(tcb);
        }
    }
    // initializes the data structures for the control flow analysis
    Frame<V> current = newFrame(m.maxLocals, m.maxStack);
    Frame<V> handler = newFrame(m.maxLocals, m.maxStack);
    current.setReturn(interpreter.newValue(Type.getReturnType(m.desc)));
    Type[] args = Type.getArgumentTypes(m.desc);
    int local = 0;
    if ((m.access & ACC_STATIC) == 0) {
        Type ctype = Type.getObjectType(owner);
        current.setLocal(local++, interpreter.newValue(ctype));
    }
    for (int i = 0; i < args.length; ++i) {
        current.setLocal(local++, interpreter.newValue(args[i]));
        if (args[i].getSize() == 2) {
            current.setLocal(local++, interpreter.newValue(null));
        }
    }
    while (local < m.maxLocals) {
        current.setLocal(local++, interpreter.newValue(null));
    }
    interpreter.init(data[0]);
    merge(0, current);
    // control flow analysis
    while (top > 0) {
        int insn = queue[--top];
        Frame<V> f = frames[insn];
        queued[insn] = false;
        AbstractInsnNode insnNode = null;
        try {
            insnNode = m.instructions.get(insn);
            int insnOpcode = insnNode.getOpcode();
            int insnType = insnNode.getType();
            if (insnType == AbstractInsnNode.LABEL || insnType == AbstractInsnNode.LINE || insnType == AbstractInsnNode.FRAME) {
                interpreter.init(data[insn]);
                merge(insn + 1, f);
            } else {
                // delta
                interpreter.init(data[insn]);
                current.init(f).execute(insnNode, interpreter);
                if (insnNode instanceof JumpInsnNode) {
                    JumpInsnNode j = (JumpInsnNode) insnNode;
                    if (insnOpcode != GOTO && insnOpcode != JSR) {
                        merge(insn + 1, current);
                    }
                    int jump = insns.indexOf(j.label);
                    merge(jump, current);
                } else if (insnNode instanceof LookupSwitchInsnNode) {
                    LookupSwitchInsnNode lsi = (LookupSwitchInsnNode) insnNode;
                    int jump = insns.indexOf(lsi.dflt);
                    merge(jump, current);
                    for (int j = 0; j < lsi.labels.size(); ++j) {
                        LabelNode label = lsi.labels.get(j);
                        jump = insns.indexOf(label);
                        merge(jump, current);
                    }
                } else if (insnNode instanceof TableSwitchInsnNode) {
                    TableSwitchInsnNode tsi = (TableSwitchInsnNode) insnNode;
                    int jump = insns.indexOf(tsi.dflt);
                    merge(jump, current);
                    for (int j = 0; j < tsi.labels.size(); ++j) {
                        LabelNode label = tsi.labels.get(j);
                        jump = insns.indexOf(label);
                        merge(jump, current);
                    }
                } else if (insnOpcode != ATHROW && (insnOpcode < IRETURN || insnOpcode > RETURN)) {
                    merge(insn + 1, current);
                }
            }
            List<TryCatchBlockNode> insnHandlers = handlers[insn];
            if (insnHandlers != null) {
                for (int i = 0; i < insnHandlers.size(); ++i) {
                    TryCatchBlockNode tcb = insnHandlers.get(i);
                    int jump = insns.indexOf(tcb.handler);
                    handler.init(f);
                    handler.clearStack();
                    handler.push(refV);
                    merge(jump, handler);
                }
            }
        } catch (AnalyzerException e) {
            throw new AnalyzerException(e.node, "Error at instruction " + insn + ": " + e.getMessage(), e);
        } catch (Exception e) {
            throw new AnalyzerException(insnNode, "Error at instruction " + insn + ": " + e.getMessage(), e);
        }
    }
    return frames;
}
Also used : Type(org.jetbrains.org.objectweb.asm.Type) List(java.util.List) ArrayList(java.util.ArrayList)

Example 50 with Type

use of org.jetbrains.org.objectweb.asm.Type in project intellij-community by JetBrains.

the class NegationInterpreter method naryOperation.

@Override
public BasicValue naryOperation(AbstractInsnNode insn, List<? extends BasicValue> values) throws AnalyzerException {
    int opCode = insn.getOpcode();
    int shift = opCode == INVOKESTATIC ? 0 : 1;
    int origin = insnIndex(insn);
    switch(opCode) {
        case INVOKESPECIAL:
        case INVOKEINTERFACE:
        case INVOKEVIRTUAL:
            BasicValue receiver = values.get(0);
            if (receiver instanceof NthParamValue) {
                dereferencedParams[((NthParamValue) receiver).n] = true;
            }
            if (receiver instanceof Trackable) {
                dereferencedValues[((Trackable) receiver).getOriginInsnIndex()] = true;
            }
        default:
    }
    switch(opCode) {
        case INVOKESTATIC:
        case INVOKESPECIAL:
        case INVOKEVIRTUAL:
        case INVOKEINTERFACE:
            boolean stable = opCode == INVOKESTATIC || opCode == INVOKESPECIAL;
            MethodInsnNode mNode = (MethodInsnNode) insn;
            Method method = new Method(mNode.owner, mNode.name, mNode.desc);
            Type retType = Type.getReturnType(mNode.desc);
            for (int i = shift; i < values.size(); i++) {
                if (values.get(i) instanceof NthParamValue) {
                    int n = ((NthParamValue) values.get(i)).n;
                    if (opCode == INVOKEINTERFACE) {
                        notNullableParams[n] = true;
                    } else {
                        Set<ParamKey> npKeys = parameterFlow[n];
                        if (npKeys == null) {
                            npKeys = new HashSet<>();
                            parameterFlow[n] = npKeys;
                        }
                        npKeys.add(new ParamKey(method, i - shift, stable));
                    }
                }
            }
            BasicValue receiver = null;
            if (shift == 1) {
                receiver = values.remove(0);
            }
            boolean thisCall = (opCode == INVOKEINTERFACE || opCode == INVOKEVIRTUAL) && receiver == ThisValue;
            return new TrackableCallValue(origin, retType, method, values, stable, thisCall);
        case MULTIANEWARRAY:
            return new NotNullValue(super.naryOperation(insn, values).getType());
        default:
    }
    return track(origin, super.naryOperation(insn, values));
}
Also used : BasicValue(org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue) Type(org.jetbrains.org.objectweb.asm.Type)

Aggregations

Type (org.jetbrains.org.objectweb.asm.Type)104 KotlinType (org.jetbrains.kotlin.types.KotlinType)66 IElementType (com.intellij.psi.tree.IElementType)45 NotNull (org.jetbrains.annotations.NotNull)23 InstructionAdapter (org.jetbrains.org.objectweb.asm.commons.InstructionAdapter)16 Label (org.jetbrains.org.objectweb.asm.Label)12 Type.getObjectType (org.jetbrains.org.objectweb.asm.Type.getObjectType)10 Method (org.jetbrains.org.objectweb.asm.commons.Method)9 Unit (kotlin.Unit)8 LocalVariableDescriptor (org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor)7 ArrayList (java.util.ArrayList)5 JavaClassDescriptor (org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor)5 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)5 PrimitiveType (org.jetbrains.kotlin.builtins.PrimitiveType)4 ValueParameterDescriptor (org.jetbrains.kotlin.descriptors.ValueParameterDescriptor)4 List (java.util.List)3 Nullable (org.jetbrains.annotations.Nullable)3 ScriptDescriptor (org.jetbrains.kotlin.descriptors.ScriptDescriptor)3 InOut (com.intellij.codeInspection.bytecodeAnalysis.Direction.InOut)2 FunctionClassDescriptor (org.jetbrains.kotlin.builtins.functions.FunctionClassDescriptor)2