Examples of WhileVisitor


Examples of railo.transformer.bytecode.visitor.WhileVisitor

    }
    boolean hasIndexAndItem=index!=-1 && item!=-1;
   
   
   
    WhileVisitor whileVisitor = new WhileVisitor();
    loopVisitor=whileVisitor;
    // java.util.Iterator it=Caster.toIterator(@collection');
    int it=adapter.newLocal(Types.ITERATOR);
    getAttribute("collection").getValue().writeOut(bc,Expression.MODE_REF);
   
    // item and index
    int entry=-1;
    if(hasIndexAndItem) {
      entry = adapter.newLocal(Types.MAP_ENTRY);
      // Caster.toCollection(collection)
      adapter.invokeStatic(Types.CASTER,Methods_Caster.TO_COLLECTION);
      //coll.entryIterator();
      adapter.invokeInterface(Types.COLLECTION, ENTRY_ITERATOR);
    }
    else {
      adapter.invokeStatic(Types.CASTER,ForEach.TO_ITERATOR);
    }
   
   
    adapter.storeLocal(it);
   

   
   
    // while(it.hasNext()) {
    whileVisitor.visitBeforeExpression(bc);
      adapter.loadLocal(it);
      adapter.invokeInterface(Types.ITERATOR, HAS_NEXT);
   
    whileVisitor.visitAfterExpressionBeforeBody(bc);
      if(hasIndexAndItem) {
        // entry=it.next();
        adapter.loadLocal(it);
        adapter.invokeInterface(Types.ITERATOR, NEXT);
        adapter.storeLocal(entry);

        // keyRef.set(pc,entry.getKey())
        adapter.loadLocal(index);
        adapter.loadArg(0);
        adapter.loadLocal(entry);
        adapter.invokeInterface(Types.MAP_ENTRY, GET_KEY);
        adapter.invokeStatic(Types.CASTER,Methods.METHOD_TO_STRING);
        adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
        adapter.pop();

        // valueRef.set(pc,entry.getKey())
        adapter.loadLocal(item);
        adapter.loadArg(0);
        adapter.loadLocal(entry);
        adapter.invokeInterface(Types.MAP_ENTRY, GET_VALUE);
        adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
        adapter.pop();
   
      }
      else {
        if(index==-1) adapter.loadLocal(item);
        else adapter.loadLocal(index);
       
        adapter.loadArg(0);
        adapter.loadLocal(it);
        adapter.invokeInterface(Types.ITERATOR, NEXT);
       
        adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET);
        adapter.pop();
      }
     
     
     
     
     
     
      getBody().writeOut(bc);
    whileVisitor.visitAfterBody(bc,getEnd());
   
  }
View Full Code Here

Examples of railo.transformer.bytecode.visitor.WhileVisitor

   * write out condition loop
   * @param adapter
   * @throws TemplateException
   */
  private void writeOutTypeCondition(BytecodeContext bc) throws BytecodeException {
    WhileVisitor whileVisitor = new WhileVisitor();
    loopVisitor=whileVisitor;
    whileVisitor.visitBeforeExpression(bc);
      CastBoolean.toExprBoolean(getAttribute("condition").getValue()).writeOut(bc, Expression.MODE_VALUE);
    whileVisitor.visitAfterExpressionBeforeBody(bc);
      getBody().writeOut(bc);
    whileVisitor.visitAfterBody(bc,getEnd());
   
  }
View Full Code Here

Examples of railo.transformer.bytecode.visitor.WhileVisitor

   * write out file loop
   * @param adapter
   * @throws TemplateException
   */
  private void writeOutTypeFile(BytecodeContext bc) throws BytecodeException {
    WhileVisitor whileVisitor = new WhileVisitor();
    loopVisitor=whileVisitor;
    GeneratorAdapter adapter = bc.getAdapter();
   
    // charset=@charset
    int charset=adapter.newLocal(Types.STRING);
    Attribute attrCharset = getAttribute("charset");
    if(attrCharset==null) adapter.visitInsn(Opcodes.ACONST_NULL);
    else attrCharset.getValue().writeOut(bc, Expression.MODE_REF);
    adapter.storeLocal(charset);
   
    // startline=@startline
    int startline=adapter.newLocal(Types.INT_VALUE);
    Attribute attrStartLine = getAttribute("startline");
    if(attrStartLine==null) attrStartLine = getAttribute("from"); // CF8
    if(attrStartLine==null) adapter.push(1);
    else {
      attrStartLine.getValue().writeOut(bc, Expression.MODE_VALUE);
      adapter.visitInsn(Opcodes.D2I);
    }
    adapter.storeLocal(startline);
   
    // endline=@endline
    int endline=adapter.newLocal(Types.INT_VALUE);
    Attribute attrEndLine = getAttribute("endline");
    if(attrEndLine==null) attrEndLine = getAttribute("to");
    if(attrEndLine==null) adapter.push(-1);
    else {
      attrEndLine.getValue().writeOut(bc, Expression.MODE_VALUE);
      adapter.visitInsn(Opcodes.D2I);
    }
    adapter.storeLocal(endline);

   
    //VariableReference index=VariableInterpreter.getVariableReference(pc,@index);
    int index=-1,item=-1;
   
    // item
    Attribute attrItem = getAttribute("item");
    if(attrItem!=null) {
      item = adapter.newLocal(Types.VARIABLE_REFERENCE);
      adapter.loadArg(0);
      attrItem.getValue().writeOut(bc, Expression.MODE_REF);
      adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE);
      adapter.storeLocal(item);
    }

    // index
    Attribute attrIndex = getAttribute("index");
    if(attrIndex!=null) {
      index = adapter.newLocal(Types.VARIABLE_REFERENCE);
      adapter.loadArg(0);
      attrIndex.getValue().writeOut(bc, Expression.MODE_REF);
      adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE);
      adapter.storeLocal(index);
    }
   
    //java.io.File file=FileUtil.toResourceExisting(pc,@file);
    int resource=adapter.newLocal(Types.RESOURCE);
    adapter.loadArg(0);
    getAttribute("file").getValue().writeOut(bc, Expression.MODE_REF);
    adapter.invokeStatic(RESOURCE_UTIL, TO_RESOURCE_EXISTING);
    adapter.storeLocal(resource);
   
    // pc.getConfig().getSecurityManager().checkFileLocation(resource);
    adapter.loadArg(0);
    adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_CONFIG);
    adapter.invokeInterface(Types.CONFIG_WEB, GET_SECURITY_MANAGER);
    adapter.loadLocal(resource);
    adapter.invokeInterface(Types.SECURITY_MANAGER, CHECK_FILE_LOCATION);
   
    // char[] carr=new char[characters];
    Attribute attr = getAttribute("characters");
    int carr=-1;
    if(attr!=null) {
      carr=adapter.newLocal(Types.CHAR_ARRAY);
      attr.getValue().writeOut(bc, Expression.MODE_VALUE);
      adapter.cast(Types.DOUBLE_VALUE, Types.INT_VALUE);
      adapter.newArray(Types.CHAR);
      adapter.storeLocal(carr);
    }
   
    // BufferedReader reader = IOUtil.getBufferedReader(resource,charset);
    final int br=adapter.newLocal(Types.BUFFERED_READER);
    adapter.loadLocal(resource);
    adapter.loadLocal(charset);
    adapter.invokeStatic(IO_UTIL, GET_BUFFERED_READER);
    adapter.storeLocal(br);
   
    // String line;
    int line=adapter.newLocal(Types.STRING);
   
    // 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

Examples of railo.transformer.bytecode.visitor.WhileVisitor

          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);
   
 
View Full Code Here

Examples of railo.transformer.bytecode.visitor.WhileVisitor

    adapter.push(1);
    adapter.visitInsn(Opcodes.ISUB);
    adapter.storeLocal(icurrent);
   
   
    WhileVisitor wv = new WhileVisitor();
    if(tag instanceof TagLoop) ((TagLoop)tag).setLoopVisitor(wv);
    wv.visitBeforeExpression(bc);
     
      //while(ni.isValid()) {
      adapter.loadLocal(tag.getNumberIterator());
      adapter.loadLocal(icurrent);
      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.loadArg(0);
      adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_ID);
      adapter.invokeInterface(Types.QUERY, TagLoop.GO);
     
      NotVisitor.visitNot(bc);
      Label _if=new Label();
      adapter.ifZCmp(Opcodes.IFEQ, _if);
        wv.visitBreak(bc);
      adapter.visitLabel(_if);
   
      // 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(icurrent);
     
      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());
   
      // ni.setCurrent(current+1);
      /*adapter.loadLocal(tag.getNumberIterator());
      adapter.loadLocal(icurrent);
      adapter.push(1);
      adapter.visitInsn(Opcodes.IADD);
      adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT);
      */
    wv.visitAfterBody(bc,tag.getEnd());
 

    //query.go(ni.current(),pc.getId())
    resetCurrentrow(adapter,tag,current);
   
 
View Full Code Here

Examples of railo.transformer.bytecode.visitor.WhileVisitor

    adapter.visitInsn(Opcodes.ISUB);
    adapter.storeLocal(icurrent);
   
   
   
    WhileVisitor wv = new WhileVisitor();
    if(tag instanceof TagLoop) ((TagLoop)tag).setLoopVisitor(wv);
    wv.visitBeforeExpression(bc);
     
      //while(ni.isValid()) {
      adapter.loadLocal(tag.getNumberIterator());
      adapter.loadLocal(icurrent);
      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.loadArg(0);
      adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_ID);
      adapter.invokeInterface(Types.QUERY, TagLoop.GO);
     
      /*OLD
      adapter.invokeInterface(Types.QUERY, TagLoop.GO_1);
      */
      NotVisitor.visitNot(bc);
      Label _if=new Label();
      adapter.ifZCmp(Opcodes.IFEQ, _if);
        wv.visitBreak(bc);
      adapter.visitLabel(_if);
   
      // current=ni.current();
      adapter.loadLocal(tag.getNumberIterator());
      adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT);
      adapter.storeLocal(icurrent);
     
      tag.getBody().writeOut(bc);
     
      // ni.setCurrent(current+1);
      /*adapter.loadLocal(tag.getNumberIterator());
      adapter.loadLocal(icurrent);
      adapter.push(1);
      adapter.visitInsn(Opcodes.IADD);
      adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT);*/
 
    wv.visitAfterBody(bc,tag.getEnd());
 
    resetCurrentrow(adapter,tag,current);
   
   
    // ni.first();
View Full Code Here

Examples of railo.transformer.bytecode.visitor.WhileVisitor

    adapter.push(1);
    adapter.visitInsn(Opcodes.ISUB);
    adapter.storeLocal(icurrent);
   
   
    WhileVisitor wv = new WhileVisitor();
    if(tag instanceof TagLoop) ((TagLoop)tag).setLoopVisitor(wv);
    wv.visitBeforeExpression(bc);
     
      //while(ni.isValid()) {
      adapter.loadLocal(tag.getNumberIterator());
      adapter.loadLocal(icurrent);
      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);
   
      // current=ni.current();
      adapter.loadLocal(tag.getNumberIterator());
      adapter.invokeVirtual(NUMBER_ITERATOR, CURRENT);
      adapter.storeLocal(icurrent);
     
      tag.getBody().writeOut(bc);
     
      // ni.setCurrent(current+1);
      /*adapter.loadLocal(tag.getNumberIterator());
      adapter.loadLocal(icurrent);
      adapter.push(1);
      adapter.visitInsn(Opcodes.IADD);
      adapter.invokeVirtual(NUMBER_ITERATOR, SET_CURRENT);*/
 
    wv.visitAfterBody(bc,tag.getEnd());
 
   
    // ni.setCurrent(currentOuter);
    adapter.loadLocal(tag.getNumberIterator());
    adapter.loadLocal(current);
View Full Code Here

Examples of railo.transformer.bytecode.visitor.WhileVisitor

  /**
   * @see railo.transformer.bytecode.statement.StatementBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter)
   */
  public void _writeOut(BytecodeContext bc) throws BytecodeException {
    wv = new WhileVisitor();
    wv.visitBeforeExpression(bc);
      getAttribute("condition").getValue().writeOut(bc, Expression.MODE_VALUE);
    wv.visitAfterExpressionBeforeBody(bc);
      getBody().writeOut(bc);
    wv.visitAfterBody(bc,getEnd());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.