示例#1
0
  /**
   * @see
   *     railo.transformer.bytecode.statement.StatementBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
   */
  public void _writeOut(BytecodeContext bc) throws BytecodeException {
    GeneratorAdapter adapter = bc.getAdapter();

    adapter.visitLabel(begin);

    // Reference ref=null;
    final int lRef = adapter.newLocal(Types.REFERENCE);
    adapter.visitInsn(Opcodes.ACONST_NULL);
    adapter.storeLocal(lRef);

    // has no try body, if there is no try body, no catches are executed, only finally
    if (!tryBody.hasStatements()) {
      if (finallyBody != null) finallyBody.writeOut(bc);
      return;
    }

    TryCatchFinallyVisitor tcfv =
        new TryCatchFinallyVisitor(
            new OnFinally() {

              public void writeOut(BytecodeContext bc) throws BytecodeException {
                _writeOutFinally(bc, lRef);
              }
            },
            getFlowControlFinal());

    // try
    tcfv.visitTryBegin(bc);
    tryBody.writeOut(bc);
    int lThrow = tcfv.visitTryEndCatchBeging(bc);
    _writeOutCatch(bc, lRef, lThrow);
    tcfv.visitCatchEnd(bc);
  }
示例#2
0
 private void forUpdate(GeneratorAdapter adapter, int step, boolean isLocal) {
   if (isLocal) {
     adapter.visitVarInsn(ILOAD, i);
     adapter.loadLocal(step);
     adapter.visitInsn(IADD);
     adapter.visitVarInsn(ISTORE, i);
   } else adapter.visitIincInsn(i, step);
 }
示例#3
0
  private static void createProperty(ClassWriter cw, String classType, ASMProperty property)
      throws PageException {
    String name = property.getName();
    Type type = property.getASMType();
    Class clazz = property.getClazz();

    cw.visitField(Opcodes.ACC_PRIVATE, name, type.toString(), null, null).visitEnd();

    int load = loadFor(type);
    // int sizeOf=sizeOf(type);

    // get<PropertyName>():<type>
    Type[] types = new Type[0];
    Method method =
        new Method(
            (clazz == boolean.class ? "get" : "get") + StringUtil.ucFirst(name), type, types);
    GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, method, null, null, cw);

    Label start = new Label();
    adapter.visitLabel(start);

    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.visitFieldInsn(Opcodes.GETFIELD, classType, name, type.toString());
    adapter.returnValue();

    Label end = new Label();
    adapter.visitLabel(end);
    adapter.visitLocalVariable("this", "L" + classType + ";", null, start, end, 0);
    adapter.visitEnd();

    adapter.endMethod();

    // set<PropertyName>(object):void
    types = new Type[] {type};
    method = new Method("set" + StringUtil.ucFirst(name), Types.VOID, types);
    adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, method, null, null, cw);

    start = new Label();
    adapter.visitLabel(start);
    adapter.visitVarInsn(Opcodes.ALOAD, 0);
    adapter.visitVarInsn(load, 1);
    adapter.visitFieldInsn(Opcodes.PUTFIELD, classType, name, type.toString());

    adapter.visitInsn(Opcodes.RETURN);
    end = new Label();
    adapter.visitLabel(end);
    adapter.visitLocalVariable("this", "L" + classType + ";", null, start, end, 0);
    adapter.visitLocalVariable(name, type.toString(), null, start, end, 1);
    // adapter.visitMaxs(0, 0);//.visitMaxs(sizeOf+1, sizeOf+1);// hansx
    adapter.visitEnd();

    adapter.endMethod();
  }
示例#4
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;
  }