001    package railo.transformer.bytecode.visitor;
002    
003    import org.objectweb.asm.Label;
004    import org.objectweb.asm.Opcodes;
005    import org.objectweb.asm.commons.GeneratorAdapter;
006    
007    import railo.transformer.bytecode.BytecodeContext;
008    import railo.transformer.bytecode.util.ExpressionUtil;
009    import railo.transformer.bytecode.util.Types;
010    
011    /**
012     * @deprecated replaced with ForIntVisitor
013     */
014    public final class ForConditionIntVisitor implements Opcodes, LoopVisitor {
015    
016            private Label l0;
017            private Label l1;
018            private Label l2;
019            private Label l3;
020            private int i;
021            private Label lend;
022            private Label lbegin;
023            public int visitBegin(GeneratorAdapter adapter, int start, boolean isLocal) {
024                    
025                    lend = new Label();
026                    lbegin = new Label();
027                    
028                    i=adapter.newLocal(Types.INT_VALUE); 
029                    
030                    l0 = new Label();
031                    adapter.visitLabel(l0);
032                    if(isLocal)adapter.loadLocal(start,Types.INT_VALUE);
033                    else adapter.push(start);
034                    //mv.visitInsn(ICONST_1);
035                    adapter.visitVarInsn(ISTORE, i);
036                     l1 = new Label();
037                    adapter.visitLabel(l1);
038                     l2 = new Label();
039                    adapter.visitJumpInsn(GOTO, l2);
040                     l3 = new Label();
041                    adapter.visitLabel(l3);
042                    
043                    return i;
044            }
045            public void visitEndBeforeCondition(BytecodeContext bc, int step, boolean isLocal,int startline) {
046                    GeneratorAdapter adapter = bc.getAdapter();
047    
048                    
049                    adapter.visitLabel(lbegin);
050                    if(isLocal) {
051                            adapter.visitVarInsn(ILOAD, i);
052                            //adapter.loadLocal(i);
053                            adapter.loadLocal(step);
054                            adapter.visitInsn(IADD);
055                            //adapter.dup();
056                            adapter.visitVarInsn(ISTORE, i);
057                            
058                    }
059                    else adapter.visitIincInsn(i, step);
060                    ExpressionUtil.visitLine(bc, startline);
061                    adapter.visitLabel(l2);
062            }
063            
064            public void visitEndAfterCondition(BytecodeContext bc) {
065                    GeneratorAdapter adapter = bc.getAdapter();
066    
067                    adapter.ifZCmp(Opcodes.IFNE, l3);
068                    
069                    adapter.visitLabel(lend);
070    
071                    adapter.visitLocalVariable("i", "I", null, l1, lend, i);
072    
073            }
074            
075    
076            /**
077             *
078             * @see railo.transformer.bytecode.visitor.LoopVisitor#visitContinue(org.objectweb.asm.commons.GeneratorAdapter)
079             */
080            public void visitContinue(BytecodeContext bc) {
081                    bc.getAdapter().visitJumpInsn(Opcodes.GOTO, lbegin);
082            }
083            
084            /**
085             *
086             * @see railo.transformer.bytecode.visitor.LoopVisitor#visitBreak(org.objectweb.asm.commons.GeneratorAdapter)
087             */
088            public void visitBreak(BytecodeContext bc) {
089                    bc.getAdapter().visitJumpInsn(Opcodes.GOTO, lend);
090            }
091    
092            /**
093             *
094             * @see railo.transformer.bytecode.visitor.LoopVisitor#getContinueLabel()
095             */
096            public Label getContinueLabel() {
097                    return lbegin;
098            }
099    
100            /**
101             *
102             * @see railo.transformer.bytecode.visitor.LoopVisitor#getBreakLabel()
103             */
104            public Label getBreakLabel() {
105                    return lend;
106            }
107    }