List of usage examples for org.objectweb.asm Opcodes GOTO
int GOTO
To view the source code for org.objectweb.asm Opcodes GOTO.
Click Source Link
From source file:lucee.transformer.bytecode.statement.ForEach.java
License:Open Source License
@Override public void _writeOut(BytecodeContext bc) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); final int it = adapter.newLocal(Types.ITERATOR); final int item = adapter.newLocal(Types.REFERENCE); //Value/*ww w. j a v a2 s .c om*/ // ForEachUtil.toIterator(value) 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); }
From source file:lucee.transformer.bytecode.statement.tag.TagIf.java
License:Open Source License
private static void writeOutElseIfEnd(GeneratorAdapter adapter, Label endIf, Label end) { adapter.visitJumpInsn(Opcodes.GOTO, end); adapter.visitLabel(endIf); }
From source file:lucee.transformer.bytecode.statement.tag.TagLoop.java
License:Open Source License
/** * write out index loop/*from w w w. jav a 2 s .co m*/ * @param adapter * @throws TemplateException */ private void writeOutTypeFromTo(BytecodeContext bc) throws BytecodeException { ForDoubleVisitor forDoubleVisitor = new ForDoubleVisitor(); loopVisitor = forDoubleVisitor; GeneratorAdapter adapter = bc.getAdapter(); // int from=(int)@from; int from = adapter.newLocal(Types.DOUBLE_VALUE); ExpressionUtil.writeOutSilent(getAttribute("from").getValue(), bc, Expression.MODE_VALUE); adapter.storeLocal(from); // int to=(int)@to; int to = adapter.newLocal(Types.DOUBLE_VALUE); ExpressionUtil.writeOutSilent(getAttribute("to").getValue(), bc, Expression.MODE_VALUE); adapter.storeLocal(to); // int step=(int)@step; int step = adapter.newLocal(Types.DOUBLE_VALUE); Attribute attrStep = getAttribute("step"); if (attrStep != null) { ExpressionUtil.writeOutSilent(attrStep.getValue(), bc, Expression.MODE_VALUE); } else { adapter.push(1D); } adapter.storeLocal(step); // boolean dirPlus=(step > 0); int dirPlus = adapter.newLocal(Types.BOOLEAN_VALUE); DecisionDoubleVisitor div = new DecisionDoubleVisitor(); div.visitBegin(); adapter.loadLocal(step); div.visitGT(); adapter.push(0D); div.visitEnd(bc); adapter.storeLocal(dirPlus); //if(step!=0) { div = new DecisionDoubleVisitor(); div.visitBegin(); adapter.loadLocal(step); div.visitNEQ(); adapter.push(0D); div.visitEnd(bc); Label ifEnd = new Label(); adapter.ifZCmp(Opcodes.IFEQ, ifEnd); // VariableReference index>=VariableInterpreter.getVariableReference(pc,@index)); int index = adapter.newLocal(Types.VARIABLE_REFERENCE); adapter.loadArg(0); Attribute attr = getAttribute("index"); if (attr == null) attr = getAttribute("item"); ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE); adapter.storeLocal(index); // index.set(from); adapter.loadLocal(index); adapter.loadLocal(from); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE); // for //int i=forConditionVisitor.visitBeforeExpression(adapter,from,step,true); // init adapter.visitLabel(forDoubleVisitor.beforeInit); forDoubleVisitor.forInit(adapter, from, true); adapter.goTo(forDoubleVisitor.beforeExpr); // update adapter.visitLabel(forDoubleVisitor.beforeUpdate); adapter.loadLocal(index); //forConditionVisitor.forUpdate(adapter, step, true); adapter.visitVarInsn(Opcodes.DLOAD, forDoubleVisitor.i); adapter.loadLocal(step); adapter.visitInsn(Opcodes.DADD); adapter.visitInsn(Opcodes.DUP2); adapter.visitVarInsn(Opcodes.DSTORE, forDoubleVisitor.i); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE); // expression adapter.visitLabel(forDoubleVisitor.beforeExpr); int i = forDoubleVisitor.i; adapter.loadLocal(dirPlus); Label l1 = new Label(); adapter.visitJumpInsn(Opcodes.IFEQ, l1); div = new DecisionDoubleVisitor(); div.visitBegin(); adapter.visitVarInsn(Opcodes.DLOAD, i); div.visitLTE(); adapter.loadLocal(to); div.visitEnd(bc); Label l2 = new Label(); adapter.visitJumpInsn(Opcodes.GOTO, l2); adapter.visitLabel(l1); div = new DecisionDoubleVisitor(); div.visitBegin(); adapter.visitVarInsn(Opcodes.DLOAD, i); div.visitGTE(); adapter.loadLocal(to); div.visitEnd(bc); adapter.visitLabel(l2); forDoubleVisitor.visitAfterExpressionBeginBody(adapter); //adapter.loadLocal(index); //adapter.visitVarInsn(Opcodes.DLOAD, i); //adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE); getBody().writeOut(bc); forDoubleVisitor.visitEndBody(bc, getEnd()); ////// set i after usage //adapter.loadLocal(index); //adapter.visitVarInsn(Opcodes.DLOAD, i); //adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET_DOUBLE); adapter.visitLabel(ifEnd); }
From source file:lucee.transformer.bytecode.statement.tag.TagTry.java
License:Open Source License
/** * * @see lucee.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter) *//*ww w. ja va2s.c om*/ public void _writeOut(BytecodeContext bc) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); adapter.visitLabel(begin); Body tryBody = new BodyBase(); List<Tag> catches = new ArrayList<Tag>(); Tag tmpFinal = null; tryBody.setParent(getBody().getParent()); List<Statement> statements = getBody().getStatements(); Statement stat; Tag tag; { Iterator<Statement> it = statements.iterator(); while (it.hasNext()) { stat = it.next(); if (stat instanceof Tag) { tag = (Tag) stat; if (tag.getTagLibTag().getTagClassName().equals("lucee.runtime.tag.Catch")) { catches.add(tag); continue; } else if (tag.getTagLibTag().getTagClassName().equals("lucee.runtime.tag.Finally")) { tmpFinal = tag; continue; } } tryBody.addStatement(stat); } ; } final Tag _finally = tmpFinal; // has no try body, if there is no try body, no catches are executed, only finally if (!tryBody.hasStatements()) { if (_finally != null && _finally.getBody() != null) { BodyBase.writeOut(bc, _finally.getBody()); //ExpressionUtil.writeOut(_finally.getBody(), bc); } return; } TryCatchFinallyVisitor tcfv = new TryCatchFinallyVisitor(new OnFinally() { public void _writeOut(BytecodeContext bc) throws BytecodeException { if (_finally != null) { ExpressionUtil.visitLine(bc, _finally.getStart()); BodyBase.writeOut(bc, _finally.getBody()); //ExpressionUtil.writeOut(_finally.getBody(), bc); } } }, getFlowControlFinal()); // Try tcfv.visitTryBegin(bc); BodyBase.writeOut(bc, tryBody); //ExpressionUtil.writeOut(tryBody, bc); int e = tcfv.visitTryEndCatchBeging(bc); // if(e instanceof lucee.runtime.exp.Abort) throw e; Label abortEnd = new Label(); adapter.loadLocal(e); // Abort.isAbort(t); adapter.invokeStatic(Types.ABORT, TryCatchFinally.IS_ABORT); //adapter.instanceOf(Types.ABORT); adapter.ifZCmp(Opcodes.IFEQ, abortEnd); adapter.loadLocal(e); adapter.throwException(); adapter.visitLabel(abortEnd); // PageExceptionImpl old=pc.getCatch(); int old = adapter.newLocal(Types.PAGE_EXCEPTION); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_CATCH); adapter.storeLocal(old); // PageException pe=Caster.toPageEception(e); int pe = adapter.newLocal(Types.PAGE_EXCEPTION); adapter.loadLocal(e); adapter.invokeStatic(Types.CASTER, TO_PAGE_EXCEPTION); adapter.storeLocal(pe); Iterator<Tag> it = catches.iterator(); Attribute attrType; Expression type; Label endAllIfs = new Label(); Tag tagElse = null; while (it.hasNext()) { tag = it.next(); Label endIf = new Label(); attrType = tag.getAttribute("type"); type = ANY; if (attrType != null) type = attrType.getValue(); if (type instanceof LitString && ((LitString) type).getString().equalsIgnoreCase("any")) { tagElse = tag; continue; } ExpressionUtil.visitLine(bc, tag.getStart()); // if(pe.typeEqual(@type) adapter.loadLocal(pe); type.writeOut(bc, Expression.MODE_REF); adapter.invokeVirtual(Types.PAGE_EXCEPTION, TYPE_EQUAL); adapter.ifZCmp(Opcodes.IFEQ, endIf); catchBody(bc, adapter, tag, pe, true, true); adapter.visitJumpInsn(Opcodes.GOTO, endAllIfs); adapter.visitLabel(endIf); } // else if (tagElse != null) { catchBody(bc, adapter, tagElse, pe, true, true); } else { // pc.setCatch(pe,true); adapter.loadArg(0); adapter.loadLocal(pe); adapter.push(false); adapter.push(true); adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_CATCH3); //throw pe; adapter.loadLocal(pe); adapter.throwException(); } adapter.visitLabel(endAllIfs); // PageExceptionImpl old=pc.getCatch(); adapter.loadArg(0); adapter.loadLocal(old); adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_CATCH_PE); tcfv.visitCatchEnd(bc); }
From source file:lucee.transformer.bytecode.statement.tag.TagTry2.java
License:Open Source License
@Override public void _writeOut(BytecodeContext bc) throws TransformerException { GeneratorAdapter adapter = bc.getAdapter(); adapter.visitLabel(begin);/* ww w . j ava 2 s . c o m*/ Body tryBody = new BodyBase(getFactory()); List<Tag> catches = new ArrayList<Tag>(); Tag tmpFinal = null; tryBody.setParent(getBody().getParent()); List<Statement> statements = getBody().getStatements(); Statement stat; Tag tag; { Iterator<Statement> it = statements.iterator(); while (it.hasNext()) { stat = it.next(); if (stat instanceof Tag) { tag = (Tag) stat; if (tag.getTagLibTag().getTagClassDefinition().isClassNameEqualTo("lucee.runtime.tag.Catch")) { catches.add(tag); continue; } else if (tag.getTagLibTag().getTagClassDefinition() .isClassNameEqualTo("lucee.runtime.tag.Finally")) { tmpFinal = tag; continue; } } tryBody.addStatement(stat); } ; } final Tag _finally = tmpFinal; // has no try body, if there is no try body, no catches are executed, only finally if (!tryBody.hasStatements()) { if (_finally != null && _finally.getBody() != null) { BodyBase.writeOut(bc, _finally.getBody()); //ExpressionUtil.writeOut(_finally.getBody(), bc); } return; } TryCatchFinallyVisitor tcfv = new TryCatchFinallyVisitor(new OnFinally() { @Override public void _writeOut(BytecodeContext bc) throws TransformerException { if (_finally != null) { ExpressionUtil.visitLine(bc, _finally.getStart()); BodyBase.writeOut(bc, _finally.getBody()); //ExpressionUtil.writeOut(_finally.getBody(), bc); } } }, getFlowControlFinal()); // Try tcfv.visitTryBegin(bc); BodyBase.writeOut(bc, tryBody); //ExpressionUtil.writeOut(tryBody, bc); int e = tcfv.visitTryEndCatchBeging(bc); // if(e instanceof lucee.runtime.exp.Abort) throw e; Label abortEnd = new Label(); adapter.loadLocal(e); // Abort.isAbort(t); adapter.invokeStatic(Types.ABORT, TryCatchFinally.IS_ABORT); //adapter.instanceOf(Types.ABORT); adapter.ifZCmp(Opcodes.IFEQ, abortEnd); adapter.loadLocal(e); adapter.throwException(); adapter.visitLabel(abortEnd); // PageExceptionImpl old=pc.getCatch(); int oldPE = adapter.newLocal(Types.PAGE_EXCEPTION); int oldName = adapter.newLocal(Types.STRING); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_CATCH); adapter.storeLocal(oldPE); adapter.loadArg(0); adapter.checkCast(Types.PAGE_CONTEXT_IMPL); adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, GET_CATCH_NAME); adapter.storeLocal(oldName); // PageException pe=Caster.toPageEception(e); int pe = adapter.newLocal(Types.PAGE_EXCEPTION); adapter.loadLocal(e); adapter.invokeStatic(Types.CASTER, TO_PAGE_EXCEPTION); adapter.storeLocal(pe); Iterator<Tag> it = catches.iterator(); Attribute attrType; Expression type; Label endAllIfs = new Label(); Tag tagElse = null; while (it.hasNext()) { tag = it.next(); Label endIf = new Label(); // type attrType = tag.getAttribute("type"); type = bc.getFactory().createLitString("any"); if (attrType != null) type = attrType.getValue(); if (type instanceof LitString && ((LitString) type).getString().equalsIgnoreCase("any")) { tagElse = tag; continue; } ExpressionUtil.visitLine(bc, tag.getStart()); // if(pe.typeEqual(@type) adapter.loadLocal(pe); type.writeOut(bc, Expression.MODE_REF); adapter.invokeVirtual(Types.PAGE_EXCEPTION, TYPE_EQUAL); adapter.ifZCmp(Opcodes.IFEQ, endIf); catchBody(bc, adapter, tag, pe, true, true, extractName(tag)); adapter.visitJumpInsn(Opcodes.GOTO, endAllIfs); adapter.visitLabel(endIf); } // else if (tagElse != null) { catchBody(bc, adapter, tagElse, pe, true, true, extractName(tagElse)); } else { // pc.setCatch(pe,true); adapter.loadArg(0); adapter.loadLocal(pe); adapter.push(false); adapter.push(true); adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_CATCH3); //throw pe; adapter.loadLocal(pe); adapter.throwException(); } adapter.visitLabel(endAllIfs); adapter.loadLocal(oldName); Label notNull = new Label(); adapter.visitJumpInsn(Opcodes.IFNONNULL, notNull); // NULL adapter.loadArg(0); adapter.loadLocal(oldPE); adapter.invokeVirtual(Types.PAGE_CONTEXT, SET_CATCH_PE); Label end = new Label(); adapter.visitJumpInsn(Opcodes.GOTO, end); adapter.visitLabel(notNull); // NOT NULL adapter.loadArg(0); adapter.checkCast(Types.PAGE_CONTEXT_IMPL); adapter.loadLocal(oldPE); adapter.loadLocal(oldName); adapter.invokeVirtual(Types.PAGE_CONTEXT_IMPL, SET_CATCH_PE2); adapter.visitLabel(end); tcfv.visitCatchEnd(bc); }
From source file:lucee.transformer.bytecode.statement.TryCatchFinally.java
License:Open Source License
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);/*from ww w. java2s. com*/ 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); }
From source file:lucee.transformer.bytecode.statement.While.java
License:Open Source License
@Override public void _writeOut(BytecodeContext bc) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); adapter.visitLabel(begin);/*from w w w . j a va 2 s .c o m*/ expr.writeOut(bc, Expression.MODE_VALUE); adapter.ifZCmp(Opcodes.IFEQ, end); body.writeOut(bc); adapter.visitJumpInsn(Opcodes.GOTO, begin); adapter.visitLabel(end); }
From source file:lucee.transformer.bytecode.util.ASMUtil.java
License:Open Source License
public static void leadFlow(BytecodeContext bc, Statement stat, int flowType, String label) throws BytecodeException { List<FlowControlFinal> finallyLabels = new ArrayList<FlowControlFinal>(); FlowControl fc;// w w w . j a va2 s. c o m String name; if (FlowControl.BREAK == flowType) { fc = ASMUtil.getAncestorBreakFCStatement(stat, finallyLabels, label); name = "break"; } else if (FlowControl.CONTINUE == flowType) { fc = ASMUtil.getAncestorContinueFCStatement(stat, finallyLabels, label); name = "continue"; } else { fc = ASMUtil.getAncestorRetryFCStatement(stat, finallyLabels, label); name = "retry"; } if (fc == null) throw new BytecodeException(name + " must be inside a loop (for,while,do-while,<cfloop>,<cfwhile> ...)", stat.getStart()); GeneratorAdapter adapter = bc.getAdapter(); Label end; if (FlowControl.BREAK == flowType) end = ((FlowControlBreak) fc).getBreakLabel(); else if (FlowControl.CONTINUE == flowType) end = ((FlowControlContinue) fc).getContinueLabel(); else end = ((FlowControlRetry) fc).getRetryLabel(); // first jump to all final labels FlowControlFinal[] arr = finallyLabels.toArray(new FlowControlFinal[finallyLabels.size()]); if (arr.length > 0) { FlowControlFinal fcf; for (int i = 0; i < arr.length; i++) { fcf = arr[i]; // first if (i == 0) { adapter.visitJumpInsn(Opcodes.GOTO, fcf.getFinalEntryLabel()); } // last if (arr.length == i + 1) fcf.setAfterFinalGOTOLabel(end); else fcf.setAfterFinalGOTOLabel(arr[i + 1].getFinalEntryLabel()); } } else bc.getAdapter().visitJumpInsn(Opcodes.GOTO, end); }
From source file:lucee.transformer.bytecode.visitor.AndVisitor.java
License:Open Source License
public void visitEnd(BytecodeContext bc) { GeneratorAdapter adapter = bc.getAdapter(); adapter.ifZCmp(Opcodes.IFEQ, end);/*from w w w .j a v a 2 s. co m*/ adapter.push(true); adapter.visitJumpInsn(Opcodes.GOTO, l2); adapter.visitLabel(end); adapter.push(false); adapter.visitLabel(l2); }
From source file:lucee.transformer.bytecode.visitor.ConditionVisitor.java
License:Open Source License
public void visitWhenAfterBody(BytecodeContext bc) { bc.getAdapter().visitJumpInsn(Opcodes.GOTO, end); bc.getAdapter().visitLabel(endIf); }