List of usage examples for org.objectweb.asm Opcodes ALOAD
int ALOAD
To view the source code for org.objectweb.asm Opcodes ALOAD.
Click Source Link
From source file:lucee.transformer.bytecode.BodyBase.java
License:Open Source License
private static void addToSubMethod(BytecodeContext bc, Statement... statements) throws BytecodeException { if (statements == null || statements.length == 0) return;/*from w w w.j a v a 2 s .c o m*/ GeneratorAdapter adapter = bc.getAdapter(); String method = ASMUtil.createOverfowMethod(bc.getMethod().getName(), bc.getPage().getMethodCount()); for (int i = 0; i < statements.length; i++) { if (statements[i].getStart() != null) { ExpressionUtil.visitLine(bc, statements[i].getStart()); break; } } //ExpressionUtil.lastLine(bc); Method m = new Method(method, Types.VOID, new Type[] { Types.PAGE_CONTEXT }); GeneratorAdapter a = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, m, null, new Type[] { Types.THROWABLE }, bc.getClassWriter()); BytecodeContext _bc = new BytecodeContext(bc.getStaticConstructor(), bc.getConstructor(), bc.getKeys(), bc, a, m); if (bc.getRoot() != null) _bc.setRoot(bc.getRoot()); else _bc.setRoot(bc); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.visitVarInsn(Opcodes.ALOAD, 1); adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, bc.getClassName(), method, "(Llucee/runtime/PageContext;)V"); for (int i = 0; i < statements.length; i++) { ExpressionUtil.writeOut(statements[i], _bc); } a.returnValue(); a.endMethod(); }
From source file:lucee.transformer.bytecode.BytecodeFactory.java
License:Open Source License
@Override public void registerKey(Context c, Expression name, boolean doUpperCase) throws TransformerException { BytecodeContext bc = (BytecodeContext) c; if (name instanceof Literal) { Literal l = (Literal) name;//from w ww . j a v a2 s.co m LitString ls = name instanceof LitString ? (LitString) l : c.getFactory().createLitString(l.getString()); if (doUpperCase) { ls = ls.duplicate(); ls.upperCase(); } String key = KeyConstants.getFieldName(ls.getString()); if (key != null) { bc.getAdapter().getStatic(KEY_CONSTANTS, key, Types.COLLECTION_KEY); return; } int index = bc.registerKey(ls); bc.getAdapter().visitVarInsn(Opcodes.ALOAD, 0); bc.getAdapter().visitFieldInsn(Opcodes.GETFIELD, bc.getClassName(), "keys", Types.COLLECTION_KEY_ARRAY.toString()); bc.getAdapter().push(index); bc.getAdapter().visitInsn(Opcodes.AALOAD); //ExpressionUtil.writeOutSilent(lit,bc, Expression.MODE_REF); //bc.getAdapter().invokeStatic(Page.KEY_IMPL, Page.KEY_INTERN); return; } name.writeOut(bc, Expression.MODE_REF); bc.getAdapter().invokeStatic(Page.KEY_IMPL, INIT); //bc.getAdapter().invokeStatic(Types.CASTER, TO_KEY); return; }
From source file:lucee.transformer.bytecode.expression.var.Variable.java
License:Open Source License
public static void registerKey(BytecodeContext bc, Expression name, boolean doUpperCase) throws BytecodeException { if (name instanceof Literal) { Literal l = (Literal) name;// w w w . j a v a2 s . com LitString ls = name instanceof LitString ? (LitString) l : LitString.toLitString(l.getString()); if (doUpperCase) { ls = ls.duplicate(); ls.upperCase(); } String key = KeyConstants.getFieldName(ls.getString()); if (key != null) { bc.getAdapter().getStatic(KEY_CONSTANTS, key, Types.COLLECTION_KEY); return; } int index = bc.registerKey(ls); bc.getAdapter().visitVarInsn(Opcodes.ALOAD, 0); bc.getAdapter().visitFieldInsn(Opcodes.GETFIELD, bc.getClassName(), "keys", Types.COLLECTION_KEY_ARRAY.toString()); bc.getAdapter().push(index); bc.getAdapter().visitInsn(Opcodes.AALOAD); return; } name.writeOut(bc, MODE_REF); bc.getAdapter().invokeStatic(Page.KEY_IMPL, INIT); //bc.getAdapter().invokeStatic(Types.CASTER, TO_KEY); return; }
From source file:lucee.transformer.bytecode.literal.LitString.java
License:Open Source License
/** * @see lucee.transformer.bytecode.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) *//*from w ww. ja v a 2s .c om*/ private static Type _writeOut(BytecodeContext bc, int mode, String str) throws BytecodeException { // write to a file instead to the bytecode // str(0,10); //print.ds(str); int externalizeStringGTE = ((ConfigImpl) bc.getPageSource().getMapping().getConfig()) .getExternalizeStringGTE(); if (externalizeStringGTE > -1 && str.length() > externalizeStringGTE && StringUtil.indexOfIgnoreCase(bc.getMethod().getName(), "call") != -1) { try { GeneratorAdapter ga = bc.getAdapter(); Page page = bc.getPage(); Range range = page.registerString(bc, str); ga.visitVarInsn(Opcodes.ALOAD, 0); ga.visitVarInsn(Opcodes.ALOAD, 1); ga.push(range.from); ga.push(range.to); ga.visitMethodInsn(Opcodes.INVOKEVIRTUAL, bc.getClassName(), "str", "(Llucee/runtime/PageContext;II)Ljava/lang/String;"); return Types.STRING; } catch (Throwable t) { } } if (str.length() > MAX_SIZE) { ExprString expr = _toExpr(str); expr.writeOut(bc, mode); } else { bc.getAdapter().push(str); } return Types.STRING; }
From source file:lucee.transformer.bytecode.literal.LitStringImpl.java
License:Open Source License
/** * @see lucee.transformer.expression.Expression#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) *///from ww w . ja v a 2 s . c om private static Type _writeOut(BytecodeContext bc, int mode, String str) throws TransformerException { // write to a file instead to the bytecode // str(0,10); //print.ds(str); int externalizeStringGTE = ((ConfigImpl) bc.getConfig()).getExternalizeStringGTE(); if (externalizeStringGTE > -1 && str.length() > externalizeStringGTE && StringUtil.indexOfIgnoreCase(bc.getMethod().getName(), "call") != -1) { try { GeneratorAdapter ga = bc.getAdapter(); Page page = bc.getPage(); Range range = page.registerString(bc, str); if (range != null) { ga.visitVarInsn(Opcodes.ALOAD, 0); ga.visitVarInsn(Opcodes.ALOAD, 1); ga.push(range.from); ga.push(range.to); ga.visitMethodInsn(Opcodes.INVOKEVIRTUAL, bc.getClassName(), "str", "(Llucee/runtime/PageContext;II)Ljava/lang/String;"); return Types.STRING; } } catch (Throwable t) { ExceptionUtil.rethrowIfNecessary(t); } } if (toBig(str)) { _toExpr(bc.getFactory(), str).writeOut(bc, mode); } else { bc.getAdapter().push(str); } return Types.STRING; }
From source file:lucee.transformer.bytecode.Page.java
License:Open Source License
/** * result byte code as binary array//w w w . j a v a2 s. com * @param classFile * @return byte code * @throws IOException * @throws TemplateException */ public byte[] execute(PageSource source, Resource classFile) throws BytecodeException { /* // this is done that the Page can be executed more than once if(initFunctions==null) initFunctions=(ArrayList<IFunction>) functions.clone(); else functions=initFunctions; if(initThreads==null) initThreads=(ArrayList<TagThread>) threads.clone(); else threads=initThreads; methodCount=0; off=0; staticTextLocation=null; print.e(this.functions); print.e(this.threads);*/ Resource p = classFile.getParentResource().getRealResource(classFile.getName() + ".txt"); List<LitString> keys = new ArrayList<LitString>(); ClassWriter cw = ASMUtil.getClassWriter(); ArrayList<String> imports = new ArrayList<String>(); getImports(imports, this); // parent String parent = "lucee/runtime/PagePlus"; if (isComponent()) parent = "lucee/runtime/ComponentPage"; else if (isInterface()) parent = "lucee/runtime/InterfacePage"; cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, name, null, parent, null); cw.visitSource(this.pageSource.getPhyscalFile().getAbsolutePath(), "rel:" + this.pageSource.getFullRealpath()); // when adding more use ; as delimiter // // static constructor //GeneratorAdapter statConstrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC,STATIC_CONSTRUCTOR,null,null,cw); BytecodeContext statConstr = null;//new BytecodeContext(null,null,this,externalizer,keys,cw,name,statConstrAdapter,STATIC_CONSTRUCTOR,writeLog(),suppressWSbeforeArg); // constructor GeneratorAdapter constrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_PS, null, null, cw); BytecodeContext constr = new BytecodeContext(source, null, null, this, keys, cw, name, constrAdapter, CONSTRUCTOR_PS, writeLog(), suppressWSbeforeArg, output); constrAdapter.loadThis(); Type t = Types.PAGE_PLUS; if (isComponent()) t = Types.COMPONENT_PAGE; else if (isInterface()) t = Types.INTERFACE_PAGE; constrAdapter.invokeConstructor(t, CONSTRUCTOR); // call _init() constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); constrAdapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, constr.getClassName(), "initKeys", "()V"); // private static ImportDefintion[] test=new ImportDefintion[]{...}; { FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "imports", "[Llucee/runtime/component/ImportDefintion;", null, null); fv.visitEnd(); constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); ArrayVisitor av = new ArrayVisitor(); av.visitBegin(constrAdapter, Types.IMPORT_DEFINITIONS, imports.size()); int index = 0; Iterator<String> it = imports.iterator(); while (it.hasNext()) { av.visitBeginItem(constrAdapter, index++); constrAdapter.push(it.next()); ASMConstants.NULL(constrAdapter); constrAdapter.invokeStatic(Types.IMPORT_DEFINITIONS_IMPL, ID_GET_INSTANCE); av.visitEndItem(constrAdapter); } av.visitEnd(); constrAdapter.visitFieldInsn(Opcodes.PUTFIELD, name, "imports", "[Llucee/runtime/component/ImportDefintion;"); } // getVersion GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, VERSION, null, null, cw); adapter.push(version); adapter.returnValue(); adapter.endMethod(); // public ImportDefintion[] getImportDefintions() if (imports.size() > 0) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.visitFieldInsn(Opcodes.GETFIELD, name, "imports", "[Llucee/runtime/component/ImportDefintion;"); adapter.returnValue(); adapter.endMethod(); } else { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw); adapter.visitInsn(Opcodes.ICONST_0); adapter.visitTypeInsn(Opcodes.ANEWARRAY, "lucee/runtime/component/ImportDefintion"); adapter.returnValue(); adapter.endMethod(); } // getSourceLastModified adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, LAST_MOD, null, null, cw); adapter.push(lastModifed); adapter.returnValue(); adapter.endMethod(); // getCompileTime adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, COMPILE_TIME, null, null, cw); adapter.push(System.currentTimeMillis()); adapter.returnValue(); adapter.endMethod(); // newInstance/initComponent/call if (isComponent()) { Tag component = getComponent(); writeOutNewComponent(statConstr, constr, keys, cw, component); writeOutInitComponent(statConstr, constr, keys, cw, component); } else if (isInterface()) { Tag interf = getInterface(); writeOutNewInterface(statConstr, constr, keys, cw, interf); writeOutInitInterface(statConstr, constr, keys, cw, interf); } else { 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(), suppressWSbeforeArg, output); 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(), suppressWSbeforeArg, output); 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), "(Llucee/runtime/PageContext;Llucee/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(), suppressWSbeforeArg, output), 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(), suppressWSbeforeArg, output), 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(), suppressWSbeforeArg, output), 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(), suppressWSbeforeArg, output); 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), "(Llucee/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(); count = 0; Method innerDefaultValue; for (int i = 0; i < functions.length; i += 10) { innerDefaultValue = new Method("udfDefaultValue" + (++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, Types.INT_VALUE, Types.INT_VALUE, Types.OBJECT }); adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerDefaultValue, null, new Type[] { Types.PAGE_EXCEPTION }, cw); writeUdfDefaultValueInner( new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, innerDefaultValue, writeLog(), suppressWSbeforeArg, output), functions, i, i + 10 > functions.length ? functions.length : i + 10); adapter.loadArg(DEFAULT_VALUE); //adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } } // register fields { GeneratorAdapter aInit = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, _INIT, null, null, cw); BytecodeContext bcInit = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, aInit, _INIT, writeLog(), suppressWSbeforeArg, output); registerFields(bcInit, keys); aInit.returnValue(); aInit.endMethod(); } //setPageSource(pageSource); constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); constrAdapter.visitVarInsn(Opcodes.ALOAD, 1); constrAdapter.invokeVirtual(t, SET_PAGE_SOURCE); constrAdapter.returnValue(); constrAdapter.endMethod(); return cw.toByteArray(); }
From source file:lucee.transformer.bytecode.Page.java
License:Open Source License
public static void registerFields(BytecodeContext bc, List<LitString> keys) throws BytecodeException { //if(keys.size()==0) return; GeneratorAdapter ga = bc.getAdapter(); FieldVisitor fv = bc.getClassWriter().visitField(Opcodes.ACC_PRIVATE, "keys", Types.COLLECTION_KEY_ARRAY.toString(), null, null); fv.visitEnd();/*from ww w .j av a 2 s. com*/ int index = 0; LitString value; Iterator<LitString> it = keys.iterator(); ga.visitVarInsn(Opcodes.ALOAD, 0); ga.push(keys.size()); ga.newArray(Types.COLLECTION_KEY); while (it.hasNext()) { value = it.next(); ga.dup(); ga.push(index++); //value.setExternalize(false); ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF); ga.invokeStatic(KEY_IMPL, KEY_INTERN); ga.visitInsn(Opcodes.AASTORE); } ga.visitFieldInsn(Opcodes.PUTFIELD, bc.getClassName(), "keys", Types.COLLECTION_KEY_ARRAY.toString()); }
From source file:lucee.transformer.bytecode.Page.java
License:Open Source License
private void writeOutInitComponent(BytecodeContext statConstr, BytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component) throws BytecodeException { final GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, INIT_COMPONENT, null, new Type[] { Types.PAGE_EXCEPTION }, cw); BytecodeContext bc = new BytecodeContext(null, statConstr, constr, this, keys, cw, name, adapter, INIT_COMPONENT, writeLog(), suppressWSbeforeArg, output); Label methodBegin = new Label(); Label methodEnd = new Label(); adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0); adapter.visitLabel(methodBegin);/*from ww w . j a v a 2s . c o m*/ // Scope oldData=null; 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); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.invokeVirtual(Types.COMPONENT_IMPL, INIT); //int oldCheckArgs= pc.undefinedScope().setMode(Undefined.MODE_NO_LOCAL_AND_ARGUMENTS); final int oldCheckArgs = adapter.newLocal(Types.INT_VALUE); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, UNDEFINED_SCOPE); adapter.push(Undefined.MODE_NO_LOCAL_AND_ARGUMENTS); adapter.invokeInterface(Types.UNDEFINED, SET_MODE); adapter.storeLocal(oldCheckArgs); TryCatchFinallyVisitor tcf = new TryCatchFinallyVisitor(new OnFinally() { public void _writeOut(BytecodeContext bc) { // undefined.setMode(oldMode); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, UNDEFINED_SCOPE); adapter.loadLocal(oldCheckArgs, Types.INT_VALUE); adapter.invokeInterface(Types.UNDEFINED, SET_MODE); adapter.pop(); // c.afterCall(pc,_oldData); adapter.loadArg(1); adapter.loadArg(0); adapter.loadLocal(oldData); adapter.invokeVirtual(Types.COMPONENT_IMPL, AFTER_CALL); } }, null); tcf.visitTryBegin(bc); // oldData=c.beforeCall(pc); adapter.loadArg(1); adapter.loadArg(0); adapter.invokeVirtual(Types.COMPONENT_IMPL, BEFORE_CALL); adapter.storeLocal(oldData); ExpressionUtil.visitLine(bc, component.getStart()); writeOutCallBody(bc, component.getBody(), IFunction.PAGE_TYPE_COMPONENT); ExpressionUtil.visitLine(bc, component.getEnd()); int t = tcf.visitTryEndCatchBeging(bc); // BodyContentUtil.flushAndPop(pc,bc); adapter.loadArg(0); adapter.loadLocal(localBC); adapter.invokeStatic(Types.BODY_CONTENT_UTIL, FLUSH_AND_POP); // throw Caster.toPageException(t); adapter.loadLocal(t); adapter.invokeStatic(Types.CASTER, TO_PAGE_EXCEPTION); adapter.throwException(); tcf.visitCatchEnd(bc); adapter.loadArg(0); adapter.loadLocal(localBC); adapter.invokeStatic(Types.BODY_CONTENT_UTIL, CLEAR_AND_POP); adapter.returnValue(); adapter.visitLabel(methodEnd); adapter.endMethod(); }
From source file:lucee.transformer.bytecode.Page.java
License:Open Source License
private void writeOutNewComponent(BytecodeContext statConstr, BytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag component) throws BytecodeException { GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_COMPONENT_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw); BytecodeContext bc = new BytecodeContext(null, statConstr, constr, this, keys, cw, name, adapter, NEW_COMPONENT_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output); Label methodBegin = new Label(); Label methodEnd = new Label(); adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0); ExpressionUtil.visitLine(bc, component.getStart()); adapter.visitLabel(methodBegin);//from w ww .ja v a 2 s.c o m int comp = adapter.newLocal(Types.COMPONENT_IMPL); adapter.newInstance(Types.COMPONENT_IMPL); adapter.dup(); Attribute attr; // ComponentPage adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.checkCast(Types.COMPONENT_PAGE); // !!! also check CFMLScriptTransformer.addMetaData if you do any change here !!! // Output attr = component.removeAttribute("output"); if (attr != null) { ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); } else ASMConstants.NULL(adapter); // synchronized attr = component.removeAttribute("synchronized"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_VALUE); else adapter.push(false); // extends attr = component.removeAttribute("extends"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // implements attr = component.removeAttribute("implements"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // hint attr = component.removeAttribute("hint"); if (attr != null) { Expression value = attr.getValue(); if (!(value instanceof Literal)) { value = LitString.toExprString("[runtime expression]"); } ExpressionUtil.writeOutSilent(value, bc, Expression.MODE_REF); } else adapter.push(""); // dspName attr = component.removeAttribute("displayname"); if (attr == null) attr = component.getAttribute("display"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // callpath adapter.visitVarInsn(Opcodes.ALOAD, 2); // relpath adapter.visitVarInsn(Opcodes.ILOAD, 3); // style attr = component.removeAttribute("style"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // persistent attr = component.removeAttribute("persistent"); boolean persistent = false; if (attr != null) { persistent = ASMUtil.toBoolean(attr, component.getStart()).booleanValue(); } // persistent attr = component.removeAttribute("accessors"); boolean accessors = false; if (attr != null) { accessors = ASMUtil.toBoolean(attr, component.getStart()).booleanValue(); } adapter.push(persistent); adapter.push(accessors); //ExpressionUtil.writeOutSilent(attr.getValue(),bc, Expression.MODE_VALUE); //adapter.visitVarInsn(Opcodes.ALOAD, 4); createMetaDataStruct(bc, component.getAttributes(), component.getMetaData()); adapter.invokeConstructor(Types.COMPONENT_IMPL, CONSTR_COMPONENT_IMPL); adapter.storeLocal(comp); //Component Impl(ComponentPage componentPage,boolean output, String extend, String hint, String dspName) // initComponent(pc,c); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.loadArg(0); adapter.loadLocal(comp); adapter.invokeVirtual(Types.COMPONENT_PAGE, INIT_COMPONENT); adapter.visitLabel(methodEnd); // return component; adapter.loadLocal(comp); adapter.returnValue(); //ExpressionUtil.visitLine(adapter, component.getEndLine()); adapter.endMethod(); }
From source file:lucee.transformer.bytecode.Page.java
License:Open Source License
private void writeOutNewInterface(BytecodeContext statConstr, BytecodeContext constr, List<LitString> keys, ClassWriter cw, Tag interf) throws BytecodeException { GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, NEW_INTERFACE_IMPL_INSTANCE, null, new Type[] { Types.PAGE_EXCEPTION }, cw); BytecodeContext bc = new BytecodeContext(null, statConstr, constr, this, keys, cw, name, adapter, NEW_INTERFACE_IMPL_INSTANCE, writeLog(), suppressWSbeforeArg, output); Label methodBegin = new Label(); Label methodEnd = new Label(); adapter.visitLocalVariable("this", "L" + name + ";", null, methodBegin, methodEnd, 0); ExpressionUtil.visitLine(bc, interf.getStart()); adapter.visitLabel(methodBegin);//from w w w . j a v a 2 s . c om //ExpressionUtil.visitLine(adapter, interf.getStartLine()); int comp = adapter.newLocal(Types.INTERFACE_IMPL); adapter.newInstance(Types.INTERFACE_IMPL); adapter.dup(); Attribute attr; // Interface Page adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.checkCast(Types.INTERFACE_PAGE); // extened attr = interf.removeAttribute("extends"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // hint attr = interf.removeAttribute("hint"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // dspName attr = interf.removeAttribute("displayname"); if (attr == null) attr = interf.getAttribute("display"); if (attr != null) ExpressionUtil.writeOutSilent(attr.getValue(), bc, Expression.MODE_REF); else adapter.push(""); // callpath adapter.visitVarInsn(Opcodes.ALOAD, 1); // relpath adapter.visitVarInsn(Opcodes.ILOAD, 2); // interface udfs adapter.visitVarInsn(Opcodes.ALOAD, 3); createMetaDataStruct(bc, interf.getAttributes(), interf.getMetaData()); adapter.invokeConstructor(Types.INTERFACE_IMPL, CONSTR_INTERFACE_IMPL); adapter.storeLocal(comp); // initInterface(pc,c); adapter.visitVarInsn(Opcodes.ALOAD, 0); //adapter.loadArg(0); adapter.loadLocal(comp); adapter.invokeVirtual(Types.INTERFACE_PAGE, INIT_INTERFACE); adapter.visitLabel(methodEnd); // return interface; adapter.loadLocal(comp); adapter.returnValue(); //ExpressionUtil.visitLine(adapter, interf.getEndLine()); adapter.endMethod(); }