Package railo.transformer.bytecode.visitor

Examples of railo.transformer.bytecode.visitor.TryFinallyVisitor


    // int count=0; 
    int count=adapter.newLocal(Types.INT_VALUE);
    adapter.push(0);
    adapter.storeLocal(count);
   
    TryFinallyVisitor tfv=new TryFinallyVisitor(new OnFinally() {
      public void writeOut(BytecodeContext bc) {
        bc.getAdapter().loadLocal(br);
        bc.getAdapter().invokeStatic(IO_UTIL, CLOSE_EL);
      }
    },null);
    //TryFinallyVisitor tcfv=new TryFinallyVisitor();
   
    // try
    tfv.visitTryBegin(bc);
    //tcfv.visitTryBegin(bc);
      // while((line=br.readLine())!=null) {
      //WhileVisitor wv=new WhileVisitor();
      whileVisitor.visitBeforeExpression(bc);
        DecisionObjectVisitor dv=new DecisionObjectVisitor();
        dv.visitBegin();
          if(attr!=null) {
            // IOUtil.read(bufferedreader,12)
            adapter.loadLocal(br);
            adapter.loadLocal(carr);
            adapter.arrayLength();
            adapter.invokeStatic(Types.IOUTIL, READ);
          }
          else {
            // br.readLine()
            adapter.loadLocal(br);
            adapter.invokeVirtual(Types.BUFFERED_READER, READ_LINE);
          }
          adapter.dup();
          adapter.storeLocal(line);
         
        dv.visitNEQ();
          adapter.visitInsn(Opcodes.ACONST_NULL);
        dv.visitEnd(bc);
       
      whileVisitor.visitAfterExpressionBeforeBody(bc);
        //if(++count < startLine) continue;
        DecisionIntVisitor dv2=new DecisionIntVisitor();
        dv2.visitBegin();
          adapter.iinc(count, 1);
          adapter.loadLocal(count);
        dv2.visitLT();
          adapter.loadLocal(startline);
        dv2.visitEnd(bc);
        Label end=new Label();
        adapter.ifZCmp(Opcodes.IFEQ, end);
          whileVisitor.visitContinue(bc);
        adapter.visitLabel(end);
       
        // if(endLine!=-1 && count > endLine) break;
        DecisionIntVisitor div=new DecisionIntVisitor();
        div.visitBegin();
          adapter.loadLocal(endline);
        div.visitNEQ();
          adapter.push(-1);
        div.visitEnd(bc);
        Label end2=new Label();
        adapter.ifZCmp(Opcodes.IFEQ, end2);
       
          DecisionIntVisitor div2 = new DecisionIntVisitor();
          div2.visitBegin();
            adapter.loadLocal(count);
          div2.visitGT();
            adapter.loadLocal(endline);
          div2.visitEnd(bc);
          Label end3=new Label();
          adapter.ifZCmp(Opcodes.IFEQ, end3);
            whileVisitor.visitBreak(bc);
          adapter.visitLabel(end3);
        adapter.visitLabel(end2);
       
        // index and item
        if(index!=-1 && item!=-1) {
          // index.set(pc,line);
          adapter.loadLocal(index);
          adapter.loadArg(0);
          adapter.loadLocal(count);
          adapter.cast(Types.INT_VALUE,Types.DOUBLE_VALUE);
          adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_FROM_DOUBLE);
         
          adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
          adapter.pop();
         
          // item.set(pc,line);
          adapter.loadLocal(item);
          adapter.loadArg(0);
          adapter.loadLocal(line);
          adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
          adapter.pop();
         
        }
        // only index
        else if(index!=-1) {
          // index.set(pc,line);
          adapter.loadLocal(index);
          adapter.loadArg(0);
          adapter.loadLocal(line);
          adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
          adapter.pop();
         
        }
        // only item
        else {
          // item.set(pc,line);
          adapter.loadLocal(item);
          adapter.loadArg(0);
          adapter.loadLocal(line);
          adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
          adapter.pop();
        }
       
       
       
       
        getBody().writeOut(bc);
       
      whileVisitor.visitAfterBody(bc,getEnd());
     
    tfv.visitTryEnd(bc);
   
  }
View Full Code Here


      adapter.visitInsn(Opcodes.ISUB);
      adapter.storeLocal(current);
     
     
      // Try
      TryFinallyVisitor tfv=new TryFinallyVisitor(new OnFinally() {
        public void writeOut(BytecodeContext bc) {
          // query.reset();
         
          // query.go(startAt);
          adapter.loadLocal(tag.getQuery());
          adapter.loadLocal(startAt);
         
          adapter.loadLocal(tag.getPID());
          //adapter.loadArg(0);
          //adapter.invokeVirtual(Types.PAGE_CONTEXT, TagLoop.GET_ID);
          adapter.invokeInterface(Types.QUERY, TagLoop.GO);
          adapter.pop();
         
         
         
         
          // pc.us().removeQuery();
          adapter.loadArg(0);
          adapter.invokeVirtual(Types.PAGE_CONTEXT, US);
          adapter.invokeInterface(UNDEFINED, REMOVE_QUERY);
         
            // NumberIterator.release(ni);
          adapter.loadLocal(tag.getNumberIterator());
          adapter.invokeStatic(NUMBER_ITERATOR, REALEASE);
        }
      },null);
      tfv.visitTryBegin(bc);
        WhileVisitor wv = new WhileVisitor();
        if(tag instanceof TagLoop) ((TagLoop)tag).setLoopVisitor(wv);
        wv.visitBeforeExpression(bc);
         
          //while(ni.isValid()) {
          adapter.loadLocal(tag.getNumberIterator());
          adapter.loadLocal(current);
          adapter.push(1);
          adapter.visitInsn(Opcodes.IADD);
          adapter.invokeVirtual(NUMBER_ITERATOR, IS_VALID_1);
         
        wv.visitAfterExpressionBeforeBody(bc);
       
          // if(!query.go(ni.current()))break;
          adapter.loadLocal(tag.getQuery());
          adapter.loadLocal(tag.getNumberIterator());
          adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT);
         
          adapter.loadLocal(tag.getPID());
          adapter.invokeInterface(Types.QUERY, TagLoop.GO);
         
          NotVisitor.visitNot(bc);
          Label _if=new Label();
          adapter.ifZCmp(Opcodes.IFEQ, _if);
            wv.visitBreak(bc);
          adapter.visitLabel(_if);
         
          if(attrGroup!=null) {
            // NumberIterator oldNi=numberIterator;
            int oldNi=adapter.newLocal(NUMBER_ITERATOR);
            adapter.loadLocal(tag.getNumberIterator());
            adapter.storeLocal(oldNi);
           
            // numberIterator=NumberIterator.load(ni,query,group,grp_case);
            adapter.loadArg(0);
            adapter.loadLocal(tag.getNumberIterator());
            adapter.loadLocal(tag.getQuery());
            adapter.loadLocal(tag.getGroup());
            adapter.loadLocal(groupCaseSensitive);
            adapter.invokeStatic(NUMBER_ITERATOR, LOAD_5);
            adapter.storeLocal(tag.getNumberIterator());
           
            // current=oldNi.current();
            adapter.loadLocal(oldNi);
            adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT);
            adapter.storeLocal(current);
           
            tag.getBody().writeOut(bc);
           
            //tmp(adapter,current);
           
            // NumberIterator.release(ni);
            adapter.loadLocal(tag.getNumberIterator());
            adapter.invokeStatic(NUMBER_ITERATOR, REALEASE);
           
            // numberIterator=oldNi;
            adapter.loadLocal(oldNi);
            adapter.storeLocal(tag.getNumberIterator());
          }
          else {
            // current=ni.current();
            adapter.loadLocal(tag.getNumberIterator());
            adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT);
            adapter.storeLocal(current);
           
            tag.getBody().writeOut(bc);
          }

          // ni.setCurrent(current+1);
          /*adapter.loadLocal(tag.getNumberIterator());
          adapter.loadLocal(current);
          adapter.push(1);
          adapter.visitInsn(Opcodes.IADD);
          adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT);*/
     
        wv.visitAfterBody(bc,tag.getEnd());
     
        tfv.visitTryEnd(bc);

    adapter.visitLabel(ifRecCount);
   

    if(isOutput)pbv.visitEnd(bc);
 
View Full Code Here

    adapter.loadArg(0);
    adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_SILENT);
    adapter.storeLocal(silentMode);
   
    // call must be
    TryFinallyVisitor tfv=new TryFinallyVisitor(new OnFinally() {
      public void writeOut(BytecodeContext bc) {
        //if(fcf!=null && fcf.getAfterFinalGOTOLabel()!=null)ASMUtil.visitLabel(adapter,fcf.getFinalEntryLabel());
        // if(!silentMode)pc.unsetSilent();
        Label _if=new Label();
        adapter.loadLocal(silentMode);
        NotVisitor.visitNot(bc);
        adapter.ifZCmp(Opcodes.IFEQ, _if);
          adapter.loadArg(0);
          adapter.invokeVirtual(Types.PAGE_CONTEXT, UNSET_SILENT);
          adapter.pop();
       
        adapter.visitLabel(_if);
        /*if(fcf!=null) {
          Label l = fcf.getAfterFinalGOTOLabel();
          if(l!=null)adapter.visitJumpInsn(Opcodes.GOTO, l);
        }*/
      }
    },getFlowControlFinal());
    tfv.visitTryBegin(bc);
      getBody().writeOut(bc);
    tfv.visitTryEnd(bc);

  }
 
View Full Code Here

    adapter.push(tlt.getTagClassName());
    adapter.invokeVirtual(Types.PAGE_CONTEXT, USE);
    adapter.checkCast(currType);
    adapter.storeLocal(currLocal);
 
  TryFinallyVisitor outerTcfv=new TryFinallyVisitor(new OnFinally() {
    public void writeOut(BytecodeContext bc) {

      adapter.loadArg(0);
      adapter.loadLocal(currLocal);
      adapter.invokeVirtual(Types.PAGE_CONTEXT, RE_USE);
    }
  },null);
  if(doReuse)outerTcfv.visitTryBegin(bc);
   
  // appendix
    if(tlt.hasAppendix()) {
      adapter.loadLocal(currLocal);
      adapter.push(tag.getAppendix());
      adapter.invokeVirtual(currType, SET_APPENDIX);
    }
 
  // hasBody
    boolean hasBody=tag.getBody()!=null;
    if(tlt.isBodyFree() && tlt.hasBodyMethodExists()) {
      adapter.loadLocal(currLocal);
      adapter.push(hasBody);
      adapter.invokeVirtual(currType, HAS_BODY);
    }
   
  // attributes
    Attribute attr;
   
    // attributeCollection
    attr=tag.getAttribute("attributecollection");
    if(attr!=null){
      int attrType = tag.getTagLibTag().getAttributeType();
      if(TagLibTag.ATTRIBUTE_TYPE_NONAME!=attrType) {
        tag.removeAttribute("attributecollection");
        // TagUtil.setAttributeCollection(Tag, Struct)
        adapter.loadArg(0);
        adapter.loadLocal(currLocal);
        adapter.cast(currType, TAG);
       
        ///
        Map missings = tag.getMissingAttributes();
        if(missings.size()>0) {
          ArrayVisitor av=new ArrayVisitor();
                av.visitBegin(adapter,MISSING_ATTRIBUTE,missings.size());
                Map.Entry entry;
                int count=0;
                Iterator it = missings.entrySet().iterator();
                while(it.hasNext()){
                  entry=(Entry) it.next();
              av.visitBeginItem(adapter, count++);
                Variable.registerKey(bc, LitString.toExprString((String)entry.getKey()));
                adapter.push((String)entry.getValue());
                adapter.invokeStatic(MISSING_ATTRIBUTE, NEW_INSTANCE_MAX);
              av.visitEndItem(bc.getAdapter());
                }
                av.visitEnd();
        }
        else {
          ASMConstants.NULL(adapter);
        }
        ///
        attr.getValue().writeOut(bc, Expression.MODE_REF);
       
        adapter.push(attrType);
        adapter.invokeStatic(TAG_UTIL, SET_ATTRIBUTE_COLLECTION);
      }
    }


    // metadata
    Map<String, Attribute> metadata = tag.getMetaData();
    if(metadata!=null){
      Iterator<Attribute> it = metadata.values().iterator();
      while(it.hasNext()) {
        attr=it.next();
          adapter.loadLocal(currLocal);
          adapter.push(attr.getName());
          attr.getValue().writeOut(bc, Expression.MODE_REF);
          adapter.invokeVirtual(currType, SET_META_DATA);
      }
    }
   
   
   
    String methodName;
    Map attributes = tag.getAttributes();

    // static attributes
    Iterator it = attributes.values().iterator();
    while(it.hasNext()) {
      attr=(Attribute) it.next();
      if(!attr.isDynamicType()){
        Type type = CastOther.getType(attr.getType());
        methodName=tag.getTagLibTag().getSetter(attr,type);
        adapter.loadLocal(currLocal);
        attr.getValue().writeOut(bc, Types.isPrimitiveType(type)?Expression.MODE_VALUE:Expression.MODE_REF);
        adapter.invokeVirtual(currType, new Method(methodName,Type.VOID_TYPE,new Type[]{type}));
      }
    }
   
    // dynamic attributes
    it = attributes.values().iterator();
    while(it.hasNext()) {
      attr=(Attribute) it.next();
      if(attr.isDynamicType()){
        adapter.loadLocal(currLocal);
        adapter.visitInsn(Opcodes.ACONST_NULL);
        //adapter.push(attr.getName());
        Variable.registerKey(bc, LitString.toExprString(attr.getName()));
        attr.getValue().writeOut(bc, Expression.MODE_REF);
        adapter.invokeVirtual(currType, SET_DYNAMIC_ATTRIBUTE);
      }
    }
   
   
  // Body
    if(hasBody){
      final int state=adapter.newLocal(Types.INT_VALUE);
     
      // int state=tag.doStartTag();
      adapter.loadLocal(currLocal);
      adapter.invokeVirtual(currType, DO_START_TAG);
      adapter.storeLocal(state);
     
      // if (state!=Tag.SKIP_BODY)
      Label endBody=new Label();
      adapter.loadLocal(state);
      adapter.push(javax.servlet.jsp.tagext.Tag.SKIP_BODY);
      adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endBody);
        // pc.initBody(tag, state);
        adapter.loadArg(0);
        adapter.loadLocal(currLocal);
        adapter.loadLocal(state);
        adapter.invokeVirtual(Types.PAGE_CONTEXT, INIT_BODY);
       
       
        OnFinally onFinally = new OnFinally() {
         
          public void writeOut(BytecodeContext bc) {
            Label endIf = new Label();
            /*if(tlt.handleException() && fcf!=null && fcf.getAfterFinalGOTOLabel()!=null){
              ASMUtil.visitLabel(adapter, fcf.getFinalEntryLabel());
            }*/
            adapter.loadLocal(state);
            adapter.push(javax.servlet.jsp.tagext.Tag.EVAL_BODY_INCLUDE);
            adapter.visitJumpInsn(Opcodes.IF_ICMPEQ, endIf);
              // ... pc.popBody();
              adapter.loadArg(0);
              adapter.invokeVirtual(Types.PAGE_CONTEXT, POP_BODY);
              adapter.pop();
            adapter.visitLabel(endIf);
         
            // tag.doFinally();
            if(tlt.handleException()) {
              adapter.loadLocal(currLocal);
              adapter.invokeVirtual(currType, DO_FINALLY);
            }
            // GOTO after execution body, used when a continue/break was called before
            /*if(fcf!=null) {
              Label l = fcf.getAfterFinalGOTOLabel();
              if(l!=null)adapter.visitJumpInsn(Opcodes.GOTO, l);
            }*/
           
          }
        };
       
       
        if(tlt.handleException()) {
          TryCatchFinallyVisitor tcfv=new TryCatchFinallyVisitor(onFinally,fcf);
          tcfv.visitTryBegin(bc);
            doTry(bc,adapter,tag,currLocal,currType);
          int t=tcfv.visitTryEndCatchBeging(bc);
            // tag.doCatch(t);
            adapter.loadLocal(currLocal);
            adapter.loadLocal(t);
            //adapter.visitVarInsn(Opcodes.ALOAD,t);
            adapter.invokeVirtual(currType, DO_CATCH);
          tcfv.visitCatchEnd(bc);
        }
        else {
          TryFinallyVisitor tfv=new TryFinallyVisitor(onFinally,fcf);
          tfv.visitTryBegin(bc);
            doTry(bc,adapter,tag,currLocal,currType);
          tfv.visitTryEnd(bc);
        }
       

      adapter.visitLabel(endBody);
       
View Full Code Here

      value.writeOut(bc, Expression.MODE_REF);
      adapter.invokeStatic(FOR_EACH_UTIL, TO_ITERATOR);
      //adapter.invokeStatic(COLLECTION_UTIL, TO_ITERATOR);
      // Iterator it=...
      adapter.storeLocal(it);
      TryFinallyVisitor tfv=new TryFinallyVisitor(new OnFinally() {
       
        @Override
        public void writeOut(BytecodeContext bc) throws BytecodeException {
          GeneratorAdapter a = bc.getAdapter();
          //if(fcf!=null && fcf.getAfterFinalGOTOLabel()!=null)ASMUtil.visitLabel(a,fcf.getFinalEntryLabel());
          a.loadLocal(it);
          a.invokeStatic(FOR_EACH_UTIL, RESET);
          /*if(fcf!=null){
            Label l=fcf.getAfterFinalGOTOLabel();
            if(l!=null)a.visitJumpInsn(Opcodes.GOTO, l);
          }*/
        }
      },getFlowControlFinal());
      tfv.visitTryBegin(bc);
      // Key
        // new VariableReference(...)
        key.writeOut(bc, Expression.MODE_REF);
        // VariableReference item=...
        adapter.storeLocal(item);
     
      // while
        ExpressionUtil.visitLine(bc, getStart());
        adapter.visitLabel(begin);
       
        // hasNext
        adapter.loadLocal(it);
        adapter.invokeInterface(Types.ITERATOR, HAS_NEXT);
        adapter.ifZCmp(Opcodes.IFEQ, end);
       
        // item.set(pc,it.next());
        adapter.loadLocal(item);
        adapter.loadArg(0);
        adapter.loadLocal(it);
        adapter.invokeInterface(Types.ITERATOR, NEXT);
        adapter.invokeInterface(Types.REFERENCE, SET);
        adapter.pop();
       
        // Body
        body.writeOut(bc);
        adapter.visitJumpInsn(Opcodes.GOTO, begin);
        adapter.visitLabel(end);
      tfv.visitTryEnd(bc);
   
  }
View Full Code Here

TOP

Related Classes of railo.transformer.bytecode.visitor.TryFinallyVisitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.