Search in sources :

Example 1 with FieldInsnNode

use of org.jetbrains.org.objectweb.asm.tree.FieldInsnNode in project kotlin by JetBrains.

the class LintDriver method isSuppressed.

// Unfortunately, ASMs nodes do not extend a common DOM node type with parent
// pointers, so we have to have multiple methods which pass in each type
// of node (class, method, field) to be checked.
/**
     * Returns whether the given issue is suppressed in the given method.
     *
     * @param issue the issue to be checked, or null to just check for "all"
     * @param classNode the class containing the issue
     * @param method the method containing the issue
     * @param instruction the instruction within the method, if any
     * @return true if there is a suppress annotation covering the specific
     *         issue on this method
     */
public boolean isSuppressed(@Nullable Issue issue, @NonNull ClassNode classNode, @NonNull MethodNode method, @Nullable AbstractInsnNode instruction) {
    if (method.invisibleAnnotations != null) {
        @SuppressWarnings("unchecked") List<AnnotationNode> annotations = method.invisibleAnnotations;
        return isSuppressed(issue, annotations);
    }
    // for members and <clinit> for static fields).
    if (instruction != null && method.name.charAt(0) == '<') {
        AbstractInsnNode next = LintUtils.getNextInstruction(instruction);
        if (next != null && next.getType() == AbstractInsnNode.FIELD_INSN) {
            FieldInsnNode fieldRef = (FieldInsnNode) next;
            FieldNode field = findField(classNode, fieldRef.owner, fieldRef.name);
            if (field != null && isSuppressed(issue, field)) {
                return true;
            }
        } else if (classNode.outerClass != null && classNode.outerMethod == null && isAnonymousClass(classNode)) {
            if (isSuppressed(issue, classNode)) {
                return true;
            }
        }
    }
    return false;
}
Also used : FieldNode(org.jetbrains.org.objectweb.asm.tree.FieldNode) AnnotationNode(org.jetbrains.org.objectweb.asm.tree.AnnotationNode) FieldInsnNode(org.jetbrains.org.objectweb.asm.tree.FieldInsnNode) AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)

Example 2 with FieldInsnNode

use of org.jetbrains.org.objectweb.asm.tree.FieldInsnNode in project kotlin by JetBrains.

the class RemapVisitor method visitFieldInsn.

@Override
public void visitFieldInsn(int opcode, @NotNull String owner, @NotNull String name, @NotNull String desc) {
    if (name.startsWith("$$$") && (nodeRemapper instanceof RegeneratedLambdaFieldRemapper || nodeRemapper.isRoot())) {
        FieldInsnNode fin = new FieldInsnNode(opcode, owner, name, desc);
        StackValue inline = nodeRemapper.getFieldForInline(fin, null);
        assert inline != null : "Captured field should have not null stackValue " + fin;
        inline.put(inline.type, this);
        return;
    }
    super.visitFieldInsn(opcode, owner, name, desc);
}
Also used : StackValue(org.jetbrains.kotlin.codegen.StackValue) FieldInsnNode(org.jetbrains.org.objectweb.asm.tree.FieldInsnNode)

Example 3 with FieldInsnNode

use of org.jetbrains.org.objectweb.asm.tree.FieldInsnNode in project kotlin by JetBrains.

the class FieldRemapper method foldFieldAccessChainIfNeeded.

@Nullable
private AbstractInsnNode foldFieldAccessChainIfNeeded(@NotNull List<AbstractInsnNode> capturedFieldAccess, int currentInstruction, @NotNull MethodNode node) {
    boolean checkParent = !isRoot() && currentInstruction < capturedFieldAccess.size() - 1;
    if (checkParent) {
        AbstractInsnNode transformed = parent.foldFieldAccessChainIfNeeded(capturedFieldAccess, currentInstruction + 1, node);
        if (transformed != null) {
            return transformed;
        }
    }
    FieldInsnNode insnNode = (FieldInsnNode) capturedFieldAccess.get(currentInstruction);
    if (canProcess(insnNode.owner, insnNode.name, true)) {
        insnNode.name = "$$$" + insnNode.name;
        insnNode.setOpcode(Opcodes.GETSTATIC);
        AbstractInsnNode next = capturedFieldAccess.get(0);
        while (next != insnNode) {
            AbstractInsnNode toDelete = next;
            next = next.getNext();
            node.instructions.remove(toDelete);
        }
        return capturedFieldAccess.get(capturedFieldAccess.size() - 1);
    }
    return null;
}
Also used : FieldInsnNode(org.jetbrains.org.objectweb.asm.tree.FieldInsnNode) AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with FieldInsnNode

use of org.jetbrains.org.objectweb.asm.tree.FieldInsnNode in project kotlin by JetBrains.

the class LambdaInfo method addAllParameters.

@NotNull
public Parameters addAllParameters(@NotNull FieldRemapper remapper) {
    Method asmMethod = typeMapper.mapAsmMethod(getFunctionDescriptor());
    ParametersBuilder builder = ParametersBuilder.initializeBuilderFrom(AsmTypes.OBJECT_TYPE, asmMethod.getDescriptor(), this);
    for (CapturedParamDesc info : getCapturedVars()) {
        CapturedParamInfo field = remapper.findField(new FieldInsnNode(0, info.getContainingLambdaName(), info.getFieldName(), ""));
        assert field != null : "Captured field not found: " + info.getContainingLambdaName() + "." + info.getFieldName();
        builder.addCapturedParam(field, info.getFieldName());
    }
    return builder.buildParameters();
}
Also used : FieldInsnNode(org.jetbrains.org.objectweb.asm.tree.FieldInsnNode) Method(org.jetbrains.org.objectweb.asm.commons.Method) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with FieldInsnNode

use of org.jetbrains.org.objectweb.asm.tree.FieldInsnNode in project kotlin by JetBrains.

the class ControlFlowGraph method dotDescribe.

private static String dotDescribe(Node node) {
    AbstractInsnNode instruction = node.instruction;
    if (instruction instanceof LabelNode) {
        return "Label";
    } else if (instruction instanceof LineNumberNode) {
        LineNumberNode lineNode = (LineNumberNode) instruction;
        return "Line " + lineNode.line;
    } else if (instruction instanceof FrameNode) {
        return "Stack Frame";
    } else if (instruction instanceof MethodInsnNode) {
        MethodInsnNode method = (MethodInsnNode) instruction;
        String cls = method.owner.substring(method.owner.lastIndexOf('/') + 1);
        cls = cls.replace('$', '.');
        return "Call " + cls + "#" + method.name;
    } else if (instruction instanceof FieldInsnNode) {
        FieldInsnNode field = (FieldInsnNode) instruction;
        String cls = field.owner.substring(field.owner.lastIndexOf('/') + 1);
        cls = cls.replace('$', '.');
        return "Field " + cls + "#" + field.name;
    } else if (instruction instanceof TypeInsnNode && instruction.getOpcode() == Opcodes.NEW) {
        return "New " + ((TypeInsnNode) instruction).desc;
    }
    StringBuilder sb = new StringBuilder();
    String opcodeName = getOpcodeName(instruction.getOpcode());
    sb.append(opcodeName);
    if (instruction instanceof IntInsnNode) {
        IntInsnNode in = (IntInsnNode) instruction;
        sb.append(" ").append(Integer.toString(in.operand));
    } else if (instruction instanceof LdcInsnNode) {
        LdcInsnNode ldc = (LdcInsnNode) instruction;
        sb.append(" ");
        if (ldc.cst instanceof String) {
            sb.append("\\\"");
        }
        sb.append(ldc.cst);
        if (ldc.cst instanceof String) {
            sb.append("\\\"");
        }
    }
    return sb.toString();
}
Also used : LabelNode(org.jetbrains.org.objectweb.asm.tree.LabelNode) FrameNode(org.jetbrains.org.objectweb.asm.tree.FrameNode) LdcInsnNode(org.jetbrains.org.objectweb.asm.tree.LdcInsnNode) MethodInsnNode(org.jetbrains.org.objectweb.asm.tree.MethodInsnNode) FieldInsnNode(org.jetbrains.org.objectweb.asm.tree.FieldInsnNode) IntInsnNode(org.jetbrains.org.objectweb.asm.tree.IntInsnNode) LineNumberNode(org.jetbrains.org.objectweb.asm.tree.LineNumberNode) TypeInsnNode(org.jetbrains.org.objectweb.asm.tree.TypeInsnNode) AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)

Aggregations

FieldInsnNode (org.jetbrains.org.objectweb.asm.tree.FieldInsnNode)6 AbstractInsnNode (org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode)3 Nullable (org.jetbrains.annotations.Nullable)2 StackValue (org.jetbrains.kotlin.codegen.StackValue)2 NotNull (org.jetbrains.annotations.NotNull)1 Method (org.jetbrains.org.objectweb.asm.commons.Method)1 AnnotationNode (org.jetbrains.org.objectweb.asm.tree.AnnotationNode)1 FieldNode (org.jetbrains.org.objectweb.asm.tree.FieldNode)1 FrameNode (org.jetbrains.org.objectweb.asm.tree.FrameNode)1 IntInsnNode (org.jetbrains.org.objectweb.asm.tree.IntInsnNode)1 LabelNode (org.jetbrains.org.objectweb.asm.tree.LabelNode)1 LdcInsnNode (org.jetbrains.org.objectweb.asm.tree.LdcInsnNode)1 LineNumberNode (org.jetbrains.org.objectweb.asm.tree.LineNumberNode)1 MethodInsnNode (org.jetbrains.org.objectweb.asm.tree.MethodInsnNode)1 TypeInsnNode (org.jetbrains.org.objectweb.asm.tree.TypeInsnNode)1