Пример #1
0
  public static void leadFlow(BytecodeContext bc, Statement stat, int flowType, String label)
      throws BytecodeException {
    List<FlowControlFinal> finallyLabels = new ArrayList<FlowControlFinal>();

    FlowControl fc;
    String name;
    if (FlowControl.BREAK == flowType) {
      fc = ASMUtil.getAncestorBreakFCStatement(stat, finallyLabels, label);
      name = "break";
    } else if (FlowControl.CONTINUE == flowType) {
      fc = ASMUtil.getAncestorContinueFCStatement(stat, finallyLabels, label);
      name = "continue";
    } else {
      fc = ASMUtil.getAncestorRetryFCStatement(stat, finallyLabels, label);
      name = "retry";
    }

    if (fc == null)
      throw new BytecodeException(
          name + " must be inside a loop (for,while,do-while,<cfloop>,<cfwhile> ...)",
          stat.getStart());

    GeneratorAdapter adapter = bc.getAdapter();

    Label end;
    if (FlowControl.BREAK == flowType) end = ((FlowControlBreak) fc).getBreakLabel();
    else if (FlowControl.CONTINUE == flowType) end = ((FlowControlContinue) fc).getContinueLabel();
    else end = ((FlowControlRetry) fc).getRetryLabel();

    // first jump to all final labels
    FlowControlFinal[] arr = finallyLabels.toArray(new FlowControlFinal[finallyLabels.size()]);
    if (arr.length > 0) {
      FlowControlFinal fcf;
      for (int i = 0; i < arr.length; i++) {
        fcf = arr[i];

        // first
        if (i == 0) {
          adapter.visitJumpInsn(Opcodes.GOTO, fcf.getFinalEntryLabel());
        }

        // last
        if (arr.length == i + 1) fcf.setAfterFinalGOTOLabel(end);
        else fcf.setAfterFinalGOTOLabel(arr[i + 1].getFinalEntryLabel());
      }

    } else bc.getAdapter().visitJumpInsn(Opcodes.GOTO, end);
  }
Пример #2
0
  /**
   * @see
   *     lucee.transformer.bytecode.expression.ExpressionBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter,
   *     int)
   */
  @Override
  public Type _writeOut(BytecodeContext bc, int mode) throws TransformerException {
    GeneratorAdapter adapter = bc.getAdapter();
    if (mode == MODE_REF) {
      _writeOut(bc, MODE_VALUE);
      adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_BOOLEAN_FROM_BOOLEAN);
      return Types.BOOLEAN;
    }

    Label l1 = new Label();
    Label l2 = new Label();

    expr.writeOut(bc, MODE_VALUE);
    adapter.ifZCmp(Opcodes.IFEQ, l1);

    adapter.visitInsn(Opcodes.ICONST_0);
    adapter.visitJumpInsn(Opcodes.GOTO, l2);
    adapter.visitLabel(l1);
    adapter.visitInsn(Opcodes.ICONST_1);
    adapter.visitLabel(l2);

    return Types.BOOLEAN_VALUE;
  }
Пример #3
0
 /**
  * @see
  *     lucee.transformer.bytecode.visitor.LoopVisitor#visitBreak(org.objectweb.asm.commons.GeneratorAdapter)
  */
 @Override
 public void visitBreak(BytecodeContext bc) {
   bc.getAdapter().visitJumpInsn(Opcodes.GOTO, afterBody);
 }
Пример #4
0
 /**
  * @see
  *     lucee.transformer.bytecode.visitor.LoopVisitor#visitContinue(org.objectweb.asm.commons.GeneratorAdapter)
  */
 @Override
 public void visitContinue(BytecodeContext bc) {
   bc.getAdapter().visitJumpInsn(Opcodes.GOTO, beforeUpdate);
 }
Пример #5
0
 public void visitEndBody(BytecodeContext bc, Position line) {
   bc.getAdapter().goTo(beforeUpdate);
   ExpressionUtil.visitLine(bc, line);
   bc.getAdapter().visitLabel(afterBody);
   // adapter.visitLocalVariable("i", "I", null, beforeInit, afterBody, i);
 }
Пример #6
0
 public static void dummy2(BytecodeContext bc) {
   bc.getAdapter().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/System", "nanoTime", "()J");
   bc.getAdapter().visitInsn(Opcodes.POP2);
 }