Package railo.transformer.bytecode.visitor

Examples of railo.transformer.bytecode.visitor.ConditionVisitor


          writeOutCall(statConstr,constr,keys,cw);
        }
       
// udfCall    
        Function[] functions=getFunctions();
        ConditionVisitor cv;
        DecisionIntVisitor div;
    // less/equal than 10 functions
        if(isInterface()){}
        else if(functions.length<=10) {
          adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC+Opcodes.ACC_FINAL , UDF_CALL, null, new Type[]{Types.THROWABLE}, cw);
            BytecodeContext bc = new BytecodeContext(source,statConstr,constr,this,keys,cw,name,adapter,UDF_CALL,writeLog(),supressWSbeforeArg);
            if(functions.length==0){}
            else if(functions.length==1){
            ExpressionUtil.visitLine(bc,functions[0].getStart());
            functions[0].getBody().writeOut(bc);
            ExpressionUtil.visitLine(bc,functions[0].getEnd());
          }
          else writeOutUdfCallInner(bc,functions,0,functions.length);
            adapter.visitInsn(Opcodes.ACONST_NULL);
            adapter.returnValue();
            adapter.endMethod();
        }
   // more than 10 functions
        else {
          adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC+Opcodes.ACC_FINAL , UDF_CALL, null, new Type[]{Types.THROWABLE}, cw);
          BytecodeContext bc = new BytecodeContext(source,statConstr,constr,this,keys,cw,name,adapter,UDF_CALL,writeLog(),supressWSbeforeArg);
            cv = new ConditionVisitor();
            cv.visitBefore();
            int count=0;
            for(int i=0;i<functions.length;i+=10) {
              cv.visitWhenBeforeExpr();
                div=new DecisionIntVisitor();
            div.visitBegin();
              adapter.loadArg(2);
            div.visitLT();
              adapter.push(i+10);
            div.visitEnd(bc);
              cv.visitWhenAfterExprBeforeBody(bc);
               
                adapter.visitVarInsn(Opcodes.ALOAD, 0);
                adapter.visitVarInsn(Opcodes.ALOAD, 1);
                adapter.visitVarInsn(Opcodes.ALOAD, 2);
                adapter.visitVarInsn(Opcodes.ILOAD, 3);
                adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, createFunctionName(++count), "(Lrailo/runtime/PageContext;Lrailo/runtime/type/UDF;I)Ljava/lang/Object;");
                adapter.visitInsn(Opcodes.ARETURN);//adapter.returnValue();
              cv.visitWhenAfterBody(bc);
            }
            cv.visitAfter(bc);
         
          adapter.visitInsn(Opcodes.ACONST_NULL);
          adapter.returnValue();
          adapter.endMethod();
         
          count=0;
          Method innerCall;
          for(int i=0;i<functions.length;i+=10) {
            innerCall = new Method(createFunctionName(++count),Types.OBJECT,new Type[]{Types.PAGE_CONTEXT, USER_DEFINED_FUNCTION, Types.INT_VALUE});
           
            adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE+Opcodes.ACC_FINAL , innerCall, null, new Type[]{Types.THROWABLE}, cw);
            writeOutUdfCallInner(new BytecodeContext(source,statConstr,constr,this,keys,cw,name,adapter,innerCall,writeLog(),supressWSbeforeArg), functions, i, i+10>functions.length?functions.length:i+10);
           
            adapter.visitInsn(Opcodes.ACONST_NULL);
            adapter.returnValue();
            adapter.endMethod();
          }
        }
       

     // threadCall
         TagThread[] threads=getThreads();
         if(true) {
           adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC+Opcodes.ACC_FINAL , THREAD_CALL, null, new Type[]{Types.THROWABLE}, cw);
           if(threads.length>0) writeOutThreadCallInner(new BytecodeContext(source,statConstr,constr,this,keys,cw,name,adapter,THREAD_CALL,writeLog(),supressWSbeforeArg),threads,0,threads.length);
         //adapter.visitInsn(Opcodes.ACONST_NULL);
         adapter.returnValue();
         adapter.endMethod();
         }
       

       
               
// udfDefaultValue
    // less/equal than 10 functions
        if(isInterface()) {}
        else if(functions.length<=10) {
          adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC+Opcodes.ACC_FINAL , UDF_DEFAULT_VALUE, null, new Type[]{Types.PAGE_EXCEPTION}, cw);
          if(functions.length>0)
            writeUdfDefaultValueInner(new BytecodeContext(source,statConstr,constr,this,keys,cw,name,adapter,UDF_DEFAULT_VALUE,writeLog(),supressWSbeforeArg),functions,0,functions.length);
           
            adapter.loadArg(DEFAULT_VALUE);
          adapter.returnValue();
            adapter.endMethod();
        }
        else {
          adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC+Opcodes.ACC_FINAL , UDF_DEFAULT_VALUE, null, new Type[]{Types.PAGE_EXCEPTION}, cw);
            BytecodeContext bc = new BytecodeContext(source,statConstr,constr,this,keys,cw,name,adapter,UDF_DEFAULT_VALUE,writeLog(),supressWSbeforeArg);
          cv = new ConditionVisitor();
          cv.visitBefore();
          int count=0;
          for(int i=0;i<functions.length;i+=10) {
            cv.visitWhenBeforeExpr();
              div=new DecisionIntVisitor();
          div.visitBegin();
            adapter.loadArg(1);
          div.visitLT();
            adapter.push(i+10);
          div.visitEnd(bc);
            cv.visitWhenAfterExprBeforeBody(bc);
             
              adapter.visitVarInsn(Opcodes.ALOAD, 0);
              adapter.visitVarInsn(Opcodes.ALOAD, 1);
              adapter.visitVarInsn(Opcodes.ILOAD, 2);
              adapter.visitVarInsn(Opcodes.ILOAD, 3);
              adapter.visitVarInsn(Opcodes.ALOAD, 4);
             
              adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, "udfDefaultValue"+(++count), "(Lrailo/runtime/PageContext;IILjava/lang/Object;)Ljava/lang/Object;");
              adapter.visitInsn(Opcodes.ARETURN);//adapter.returnValue();
             
            cv.visitWhenAfterBody(bc);
          }
          cv.visitAfter(bc);
       
        adapter.visitInsn(Opcodes.ACONST_NULL);
        adapter.returnValue();
        adapter.endMethod();
       
View Full Code Here


    ga.visitFieldInsn(Opcodes.PUTFIELD, bc.getClassName(), "keys", Types.COLLECTION_KEY_ARRAY.toString());
  }

  private void writeUdfDefaultValueInner(BytecodeContext bc, Function[] functions, int offset, int length) throws BytecodeException {
    GeneratorAdapter adapter = bc.getAdapter();
    ConditionVisitor cv = new ConditionVisitor();
    DecisionIntVisitor div;
        cv.visitBefore();
        for(int i=offset;i<length;i++) {
          cv.visitWhenBeforeExpr();
            div = new DecisionIntVisitor();
        div.visitBegin();
          adapter.loadArg(1);
        div.visitEQ();
          adapter.push(i);
        div.visitEnd(bc);
          cv.visitWhenAfterExprBeforeBody(bc);
            writeOutFunctionDefaultValueInnerInner(bc, functions[i]);
          cv.visitWhenAfterBody(bc);
        }
        cv.visitAfter(bc);
  }
View Full Code Here

  }


  private void writeOutUdfCallInnerIf(BytecodeContext bc,Function[] functions, int offset, int length) throws BytecodeException {
    GeneratorAdapter adapter = bc.getAdapter();
    ConditionVisitor cv=new ConditionVisitor();
        DecisionIntVisitor div;
        cv.visitBefore();
        for(int i=offset;i<length;i++) {
          cv.visitWhenBeforeExpr();
            div=new DecisionIntVisitor();
        div.visitBegin();
          adapter.loadArg(2);
        div.visitEQ();
          adapter.push(i);
        div.visitEnd(bc);
          cv.visitWhenAfterExprBeforeBody(bc);
            ExpressionUtil.visitLine(bc, functions[i].getStart());
            functions[i].getBody().writeOut(bc);
            ExpressionUtil.visitLine(bc, functions[i].getEnd());
          cv.visitWhenAfterBody(bc);
        }
        cv.visitAfter(bc);
  }
View Full Code Here

 
 

  private void writeOutThreadCallInner(BytecodeContext bc,TagThread[] threads, int offset, int length) throws BytecodeException {
    GeneratorAdapter adapter = bc.getAdapter();
    ConditionVisitor cv=new ConditionVisitor();
        DecisionIntVisitor div;
        cv.visitBefore();
        //print.ln("functions:"+functions.length);
          for(int i=offset;i<length;i++) {
            cv.visitWhenBeforeExpr();
              div=new DecisionIntVisitor();
          div.visitBegin();
            adapter.loadArg(1);
          div.visitEQ();
            adapter.push(i);
          div.visitEnd(bc);
            cv.visitWhenAfterExprBeforeBody(bc);
              Body body = threads[i].getRealBody();
              if(body!=null)body.writeOut(bc);
            cv.visitWhenAfterBody(bc);
          }
        cv.visitAfter(bc);
  }
View Full Code Here

    final int oldData=adapter.newLocal(Types.VARIABLES);
    ASMConstants.NULL(adapter);
    adapter.storeLocal(oldData);
   
    int localBC=adapter.newLocal(Types.BODY_CONTENT);
    ConditionVisitor cv=new ConditionVisitor();
    cv.visitBefore();
      cv.visitWhenBeforeExpr();
        adapter.loadArg(1);
        adapter.invokeVirtual(Types.COMPONENT_IMPL, GET_OUTPUT);
      cv.visitWhenAfterExprBeforeBody(bc);
        ASMConstants.NULL(adapter);
      cv.visitWhenAfterBody(bc);

      cv.visitOtherviseBeforeBody();
        adapter.loadArg(0);
        adapter.invokeVirtual(Types.PAGE_CONTEXT, PUSH_BODY);
      cv.visitOtherviseAfterBody();
    cv.visitAfter(bc);
    adapter.storeLocal(localBC);
   
    // c.init(pc,this);
    adapter.loadArg(1);
    adapter.loadArg(0);
View Full Code Here

      return;
    }
     
    Iterator<Argument> it = args.iterator();
    Argument arg;
    ConditionVisitor cv=new ConditionVisitor();
    DecisionIntVisitor div;
    cv.visitBefore();
    int count=0;
    while(it.hasNext()) {
      arg=it.next();
      cv.visitWhenBeforeExpr();
        div=new DecisionIntVisitor();
        div.visitBegin();
          adapter.loadArg(2);
        div.visitEQ();
          adapter.push(count++);
        div.visitEnd(bc);
      cv.visitWhenAfterExprBeforeBody(bc);
        Expression defaultValue = arg.getDefaultValue();
        if(defaultValue!=null) {
          /*if(defaultValue instanceof Null) {
            adapter.invokeStatic(NULL, GET_INSTANCE);
          }
          else*/
          defaultValue.writeOut(bc, Expression.MODE_REF);
        }
        else
          adapter.loadArg(DEFAULT_VALUE);
          //adapter.visitInsn(Opcodes.ACONST_NULL);
        adapter.returnValue();
      cv.visitWhenAfterBody(bc);
    }
    cv.visitOtherviseBeforeBody();
      //adapter.visitInsn(ACONST_NULL);
      //adapter.returnValue();
    cv.visitOtherviseAfterBody();
    cv.visitAfter(bc);
  }
View Full Code Here

   

    public void _writeOut(BytecodeContext bc) throws BytecodeException {
      Iterator<Pair> it = ifs.iterator();
        Pair pair;
        ConditionVisitor cv=new ConditionVisitor();
        cv.visitBefore();
          // ifs
          while(it.hasNext()) {
            pair=it.next();
            ExpressionUtil.visitLine(bc, pair.start);
            cv.visitWhenBeforeExpr();
              pair. condition.writeOut(bc,Expression.MODE_VALUE);
            cv.visitWhenAfterExprBeforeBody(bc);
              pair.body.writeOut(bc);
            cv.visitWhenAfterBody(bc);
            if(pair.end!=null)ExpressionUtil.visitLine(bc, pair.end);
          }
          // else
          if(_else!=null && _else.body!=null) {
            cv.visitOtherviseBeforeBody();
              _else.body.writeOut(bc);
            cv.visitOtherviseAfterBody();
          }
         
        cv.visitAfter(bc);
    }
View Full Code Here

   
    List statements = getBody().getStatements();
    Statement stat;
    Tag tag;

    ConditionVisitor cv=new ConditionVisitor();
    cv.visitBefore();

    // cases
    Iterator it = statements.iterator();
    Tag def=null;
    while(it.hasNext()) {
      stat=(Statement) it.next();
      if(stat instanceof Tag) {
        tag=(Tag) stat;
        if(tag.getTagLibTag().getTagClassName().equals("railo.runtime.tag.Case"))  {
          addCase(bc,cv,tag,expression);
          continue;
        }
        else if(tag.getTagLibTag().getTagClassName().equals("railo.runtime.tag.Defaultcase"))  {
          if(def!=null)
            throw new BytecodeException("multiple defaultcases are not allowed",getStart());
          def=tag;
          //setDefaultCase(bc,cv,tag);
          //break;
        }
      }
    }

    // default
    if(def!=null)setDefaultCase(bc,cv,def);
   
    cv.visitAfter(bc);
   
   
    /*
    
<!-- cases -->
View Full Code Here

TOP

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

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.