Пример #1
0
  @Override
  public Type _writeOut(BytecodeContext bc, int mode) throws BytecodeException {

    int form = VALUE;
    int type = STRING;
    if (name instanceof Variable && !((Variable) name).fromHash()) {
      GeneratorAdapter adapter = bc.getAdapter();
      String[] arr = VariableString.variableToStringArray((Variable) name, true);
      if (arr.length > 1) {
        form = ARRAY;
        ArrayVisitor av = new ArrayVisitor();
        av.visitBegin(adapter, Types.STRING, arr.length);
        for (int y = 0; y < arr.length; y++) {
          av.visitBeginItem(adapter, y);
          adapter.push(varKeyUpperCase ? arr[y].toUpperCase() : arr[y]);
          av.visitEndItem(bc.getAdapter());
        }
        av.visitEnd();
      } else {
        // VariableString.toExprString(name).writeOut(bc, MODE_REF);
        String str = VariableString.variableToString((Variable) name, true);
        name = LitString.toExprString(varKeyUpperCase ? str.toUpperCase() : str);
        type = Variable.registerKey(bc, VariableString.toExprString(name)) ? KEY : STRING;
      }
    } else {
      // CastString.toExprString(name).writeOut(bc, MODE_REF);
      type = Variable.registerKey(bc, CastString.toExprString(name)) ? KEY : STRING;
    }
    // name.writeOut(bc, MODE_REF);
    super._writeOut(bc, MODE_REF);
    // bc.getAdapter().push(variableString);
    bc.getAdapter().invokeStatic(TYPE_FUNCTION_VALUE, NEW_INSTANCE[type][form]);
    return Types.FUNCTION_VALUE;
  }
Пример #2
0
  private void _writeOutFinally(BytecodeContext bc, int lRef) throws BytecodeException {
    // ref.remove(pc);
    // Reference r=null;
    GeneratorAdapter adapter = bc.getAdapter();

    // if(fcf!=null &&
    // fcf.getAfterFinalGOTOLabel()!=null)ASMUtil.visitLabel(adapter,fcf.getFinalEntryLabel());
    ExpressionUtil.visitLine(bc, finallyLine);

    // if (reference != null)
    //    reference.removeEL(pagecontext);
    Label removeEnd = new Label();
    adapter.loadLocal(lRef);
    adapter.ifNull(removeEnd);
    adapter.loadLocal(lRef);
    adapter.loadArg(0);
    adapter.invokeInterface(Types.REFERENCE, REMOVE_EL);
    adapter.pop();
    adapter.visitLabel(removeEnd);

    if (finallyBody != null) finallyBody.writeOut(bc); // finally
    /*if(fcf!=null){
    	Label l = fcf.getAfterFinalGOTOLabel();
    	if(l!=null)adapter.visitJumpInsn(Opcodes.GOTO, l);
    }*/
  }
Пример #3
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);
  }
Пример #4
0
  private void _writeOutCatch(BytecodeContext bc, int lRef, int lThrow) throws BytecodeException {
    GeneratorAdapter adapter = bc.getAdapter();
    int pe = adapter.newLocal(Types.PAGE_EXCEPTION);

    // instance of Abort
    Label abortEnd = new Label();
    adapter.loadLocal(lThrow);
    adapter.invokeStatic(Types.ABORT, TryCatchFinally.IS_ABORT);
    // adapter.instanceOf(Types.ABORT);
    adapter.ifZCmp(Opcodes.IFEQ, abortEnd);
    adapter.loadLocal(lThrow);
    adapter.throwException();
    adapter.visitLabel(abortEnd);

    // PageExceptionImpl old=pc.getCatch();
    int old = adapter.newLocal(Types.PAGE_EXCEPTION);
    adapter.loadArg(0);
    adapter.invokeVirtual(Types.PAGE_CONTEXT, TagTry.GET_CATCH);
    adapter.storeLocal(old);

    // cast to PageException  Caster.toPagException(t);
    adapter.loadLocal(lThrow);
    adapter.invokeStatic(Types.CASTER, TO_PAGE_EXCEPTION);

    // PageException pe=...
    adapter.storeLocal(pe);

    // catch loop
    Label endAllIf = new Label();
    Iterator<Catch> it = catches.iterator();
    Catch ctElse = null;
    while (it.hasNext()) {
      Catch ct = it.next();
      // store any for else
      if (ct.type != null
          && ct.type instanceof LitString
          && ((LitString) ct.type).getString().equalsIgnoreCase("any")) {
        ctElse = ct;
        continue;
      }

      ExpressionUtil.visitLine(bc, ct.line);

      // pe.typeEqual(type)
      if (ct.type == null) {
        LitBoolean.TRUE.writeOut(bc, Expression.MODE_VALUE);
      } else {
        adapter.loadLocal(pe);
        ct.type.writeOut(bc, Expression.MODE_REF);
        adapter.invokeVirtual(Types.PAGE_EXCEPTION, TYPE_EQUAL);
      }

      Label endIf = new Label();
      adapter.ifZCmp(Opcodes.IFEQ, endIf);

      catchBody(bc, adapter, ct, pe, lRef, true, true);

      adapter.visitJumpInsn(Opcodes.GOTO, endAllIf);
      adapter.visitLabel(endIf);
    }

    if (ctElse != null) {
      catchBody(bc, adapter, ctElse, pe, lRef, true, true);
    } else {
      // pc.setCatch(pe,true);
      adapter.loadArg(0);
      adapter.loadLocal(pe);
      adapter.push(false);
      adapter.push(false);
      adapter.invokeVirtual(Types.PAGE_CONTEXT, TagTry.SET_CATCH3);

      adapter.loadLocal(pe);
      adapter.throwException();
    }
    adapter.visitLabel(endAllIf);

    // PageExceptionImpl old=pc.setCatch(old);
    adapter.loadArg(0);
    adapter.loadLocal(old);
    adapter.invokeVirtual(Types.PAGE_CONTEXT, TagTry.SET_CATCH_PE);
  }