org.objectweb.asm.tree.AbstractInsnNode.getPrevious()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(10.3k)|赞(0)|评价(0)|浏览(101)

本文整理了Java中org.objectweb.asm.tree.AbstractInsnNode.getPrevious()方法的一些代码示例,展示了AbstractInsnNode.getPrevious()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractInsnNode.getPrevious()方法的具体详情如下:
包路径:org.objectweb.asm.tree.AbstractInsnNode
类名称:AbstractInsnNode
方法名:getPrevious

AbstractInsnNode.getPrevious介绍

[英]Returns the previous instruction in the list to which this instruction belongs, if any.
[中]返回此指令所属列表中的上一条指令(如果有)。

代码示例

代码示例来源:origin: jooby-project/jooby

public static AbstractInsnNode first(AbstractInsnNode node) {
 AbstractInsnNode result = node;
 AbstractInsnNode it = node;
 while (it != null) {
  result = it;
  it = it.getPrevious();
 }
 return result;
}

代码示例来源:origin: pxb1988/dex2jar

Object[] readArgumentValues(MethodInsnNode mn, Method jmethod, int pSize) {
  AbstractInsnNode q = mn;
  Object[] as = new Object[pSize];
  for (int i = pSize - 1; i >= 0; i--) {
    q = q.getPrevious();
    Object object = readCst(q);
    as[i] = convert(object, jmethod.getParameterTypes()[i]);
  }
  return as;
}

代码示例来源:origin: jooby-project/jooby

.filter(Filters.is(TypeInsnNode.class))
.flatMap(n -> {
 if (n.getPrevious() instanceof LdcInsnNode) {
  return Stream.of(n.getPrevious());

代码示例来源:origin: nuls-io/nuls

public static int getLine(AbstractInsnNode abstractInsnNode) {
  while (!(abstractInsnNode instanceof LineNumberNode)) {
    abstractInsnNode = abstractInsnNode.getPrevious();
  }
  return ((LineNumberNode) abstractInsnNode).line;
}

代码示例来源:origin: nuls-io/nuls

public int getLine() {
  AbstractInsnNode abstractInsnNode = this.currentInsnNode;
  while (!(abstractInsnNode instanceof LineNumberNode)) {
    abstractInsnNode = abstractInsnNode.getPrevious();
  }
  return ((LineNumberNode) abstractInsnNode).line;
}

代码示例来源:origin: org.jacoco/org.jacoco.core

private void start(final AbstractInsnNode start) {
  this.start = start;
  cursor = start.getPrevious();
  vars.clear();
  expectedOwner = null;
}

代码示例来源:origin: org.jacoco/org.jacoco.core

private void start(final AbstractInsnNode start) {
  this.start = start;
  cursor = start.getPrevious();
  vars.clear();
  labels.clear();
  owners.clear();
}

代码示例来源:origin: squeek502/VeganOption

public LabelNode findEndLabel(MethodNode method)
  {
    for (AbstractInsnNode instruction = method.instructions.getLast(); instruction != null; instruction = instruction.getPrevious())
    {
      if (instruction instanceof LabelNode)
        return (LabelNode) instruction;
    }
    return null;
  }
}

代码示例来源:origin: net.tascalate.javaflow/net.tascalate.javaflow.providers.asm5

private boolean isVarBetweenBounds(AbstractInsnNode var, LabelNode lo, LabelNode hi) {
  AbstractInsnNode x;
  boolean loFound = false;
  for (x = var; !(x == null || loFound); x = x.getPrevious()) {
    loFound = x == lo;
  }
  if (!loFound)
    return false;
  boolean hiFound = false;
  for (x = var; !(x == null || hiFound); x = x.getNext()) {
    hiFound = x == hi;
  }
  return hiFound;
}

代码示例来源:origin: vsilaev/tascalate-javaflow

protected boolean isVarBetweenBounds(AbstractInsnNode var, LabelNode lo, LabelNode hi) {
  AbstractInsnNode x;
  boolean loFound = false;
  for (x = var; !(x == null || loFound); x = x.getPrevious()) {
    loFound = x == lo;
  }
  if (!loFound)
    return false;
  boolean hiFound = false;
  for (x = var; !(x == null || hiFound); x = x.getNext()) {
    hiFound = x == hi;
  }
  return hiFound;
}

代码示例来源:origin: vsilaev/tascalate-javaflow

protected boolean isVarBetweenBounds(AbstractInsnNode var, LabelNode lo, LabelNode hi) {
  AbstractInsnNode x;
  boolean loFound = false;
  for (x = var; !(x == null || loFound); x = x.getPrevious()) {
    loFound = x == lo;
  }
  if (!loFound)
    return false;
  boolean hiFound = false;
  for (x = var; !(x == null || hiFound); x = x.getNext()) {
    hiFound = x == hi;
  }
  return hiFound;
}

代码示例来源:origin: org.ow2.asm/asm-debug-all

@Override
public AnnotationVisitor visitInsnAnnotation(int typeRef,
    TypePath typePath, String desc, boolean visible) {
  // Finds the last real instruction, i.e. the instruction targeted by
  // this annotation.
  AbstractInsnNode insn = instructions.getLast();
  while (insn.getOpcode() == -1) {
    insn = insn.getPrevious();
  }
  // Adds the annotation to this instruction.
  TypeAnnotationNode an = new TypeAnnotationNode(typeRef, typePath, desc);
  if (visible) {
    if (insn.visibleTypeAnnotations == null) {
      insn.visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(
          1);
    }
    insn.visibleTypeAnnotations.add(an);
  } else {
    if (insn.invisibleTypeAnnotations == null) {
      insn.invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(
          1);
    }
    insn.invisibleTypeAnnotations.add(an);
  }
  return an;
}

代码示例来源:origin: org.ow2.asm/asm-tree

@Override
public AnnotationVisitor visitInsnAnnotation(
  final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
 // Find the last real instruction, i.e. the instruction targeted by this annotation.
 AbstractInsnNode currentInsn = instructions.getLast();
 while (currentInsn.getOpcode() == -1) {
  currentInsn = currentInsn.getPrevious();
 }
 // Add the annotation to this instruction.
 TypeAnnotationNode typeAnnotation = new TypeAnnotationNode(typeRef, typePath, descriptor);
 if (visible) {
  if (currentInsn.visibleTypeAnnotations == null) {
   currentInsn.visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
  }
  currentInsn.visibleTypeAnnotations.add(typeAnnotation);
 } else {
  if (currentInsn.invisibleTypeAnnotations == null) {
   currentInsn.invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
  }
  currentInsn.invisibleTypeAnnotations.add(typeAnnotation);
 }
 return typeAnnotation;
}

代码示例来源:origin: squeek502/VeganOption

public AbstractInsnNode getOrFindInstruction(AbstractInsnNode firstInsnToCheck, boolean reverseDirection)
{
  for (AbstractInsnNode instruction = firstInsnToCheck; instruction != null; instruction = reverseDirection ? instruction.getPrevious() : instruction.getNext())
  {
    if (instruction.getType() != AbstractInsnNode.LABEL && instruction.getType() != AbstractInsnNode.LINE)
      return instruction;
  }
  return null;
}

代码示例来源:origin: com.android.tools.lint/lint-api

/**
 * Returns the previous instruction prior to the given node, ignoring label
 * and line number nodes.
 *
 * @param node the node to look up the previous instruction for
 * @return the previous instruction, or null if no previous node was found
 */
@Nullable
public static AbstractInsnNode getPrevInstruction(@NonNull AbstractInsnNode node) {
  AbstractInsnNode prev = node;
  while (true) {
    prev = prev.getPrevious();
    if (prev == null) {
      return null;
    } else {
      int type = prev.getType();
      if (type != AbstractInsnNode.LINE && type != AbstractInsnNode.LABEL
          && type != AbstractInsnNode.FRAME) {
        return prev;
      }
    }
  }
}

代码示例来源:origin: fge/grappa

@Override
public void process(@Nonnull final ParserClassNode classNode,
  @Nonnull final RuleMethod method)
  throws Exception
{
  Objects.requireNonNull(classNode, "classNode");
  Objects.requireNonNull(method, "method");
  final InsnList instructions = method.instructions;
  AbstractInsnNode ret = instructions.getLast();
  while (ret.getOpcode() != ARETURN)
    ret = ret.getPrevious();
  final CodeBlock block = CodeBlock.newCodeBlock();
  block.newobj(CodegenUtils.p(VarFramingMatcher.class))
    .dup_x1()
    .swap();
  createVarFieldArray(block, method);
  block.invokespecial(CodegenUtils.p(VarFramingMatcher.class), "<init>",
    CodegenUtils.sig(void.class, Rule.class, Var[].class));
  instructions.insertBefore(ret, block.getInstructionList());
  method.setBodyRewritten();
}

代码示例来源:origin: org.parboiled/parboiled-java

public void process(ParserClassNode classNode, RuleMethod method) throws Exception {
  checkArgNotNull(classNode, "classNode");
  checkArgNotNull(method, "method");
  if (method.getNumberOfReturns() == 1) return;
  checkState(method.getNumberOfReturns() > 1);
  AbstractInsnNode current = method.instructions.getLast();
  // find last return
  while (current.getOpcode() != ARETURN) {
    current = current.getPrevious();
  }
  LabelNode lastReturnLabel = new LabelNode();
  method.instructions.insertBefore(current, lastReturnLabel);
  // iterate backwards up to first instructions
  while ((current = current.getPrevious()) != null) {
    // replace returns with gotos
    if (current.getOpcode() == ARETURN) {
      JumpInsnNode gotoInstruction = new JumpInsnNode(GOTO, lastReturnLabel);
      method.instructions.set(current, gotoInstruction);
      current = gotoInstruction;
    }
  }
}

代码示例来源:origin: org.parboiled/parboiled-java

public void process(ParserClassNode classNode, RuleMethod method) throws Exception {
  checkArgNotNull(classNode, "classNode");
  checkArgNotNull(method, "method");
  InsnList instructions = method.instructions;
  AbstractInsnNode ret = instructions.getLast();
  while (ret.getOpcode() != ARETURN) {
    ret = ret.getPrevious();
  }
  // stack: <Matcher>
  instructions.insertBefore(ret, new TypeInsnNode(NEW, VAR_FRAMING_MATCHER.getInternalName()));
  // stack: <Matcher> :: <VarFramingMatcher>
  instructions.insertBefore(ret, new InsnNode(DUP_X1));
  // stack: <VarFramingMatcher> :: <Matcher> :: <VarFramingMatcher>
  instructions.insertBefore(ret, new InsnNode(SWAP));
  // stack: <VarFramingMatcher> :: <VarFramingMatcher> :: <Matcher>
  createVarFieldArray(method, instructions, ret);
  // stack: <VarFramingMatcher> :: <VarFramingMatcher> :: <Matcher> :: <VarFieldArray>
  instructions.insertBefore(ret, new MethodInsnNode(INVOKESPECIAL, VAR_FRAMING_MATCHER.getInternalName(),
      "<init>", '(' + RULE_DESC + '[' + VAR_DESC + ")V", false));
  // stack: <VarFramingMatcher>
  method.setBodyRewritten();
}

代码示例来源:origin: org.jacoco/org.jacoco.core

void match(final AbstractInsnNode start, final IFilterOutput output) {
    if (start.getType() != InsnNode.LABEL) {
      return;
    }
    cursor = start;
    nextIsType(Opcodes.NEW, EXCEPTION);
    nextIs(Opcodes.DUP);
    nextIsInvokeSuper(EXCEPTION, "()V");
    nextIs(Opcodes.ATHROW);
    for (AbstractInsnNode i = cursor; i != null; i = i.getPrevious()) {
      if (i.getOpcode() == Opcodes.IFEQ
          && ((JumpInsnNode) i).label == start) {
        output.ignore(i, i);
        output.ignore(start, cursor);
        return;
      } else if (getDefaultLabel(i) == start) {
        ignoreDefaultBranch(i, output);
        output.ignore(start, cursor);
        return;
      }
    }
  }
}

代码示例来源:origin: org.parboiled/parboiled-java

public void process(ParserClassNode classNode, RuleMethod method) throws Exception {
  checkArgNotNull(classNode, "classNode");
  checkArgNotNull(method, "method");
  checkState(!method.isSuperMethod()); // super methods have flag moved to the overriding method
  InsnList instructions = method.instructions;
  AbstractInsnNode ret = instructions.getLast();
  while (ret.getOpcode() != ARETURN) {
    ret = ret.getPrevious();
  }
  // stack: <rule>
  instructions.insertBefore(ret, new InsnNode(DUP));
  // stack: <rule> :: <rule>
  LabelNode isNullLabel = new LabelNode();
  instructions.insertBefore(ret, new JumpInsnNode(IFNULL, isNullLabel));
  // stack: <rule>
  if (method.hasSuppressNodeAnnotation()) generateMarkerCall(instructions, ret, "suppressNode");
  if (method.hasSuppressSubnodesAnnotation()) generateMarkerCall(instructions, ret, "suppressSubnodes");
  if (method.hasSkipNodeAnnotation()) generateMarkerCall(instructions, ret, "skipNode");
  if (method.hasMemoMismatchesAnnotation()) generateMarkerCall(instructions, ret, "memoMismatches");
  // stack: <rule>
  instructions.insertBefore(ret, isNullLabel);
  // stack: <rule>
}

相关文章