001 package railo.transformer.bytecode.statement.tag; 002 003 import org.objectweb.asm.Opcodes; 004 import org.objectweb.asm.Type; 005 import org.objectweb.asm.commons.GeneratorAdapter; 006 import org.objectweb.asm.commons.Method; 007 008 import railo.transformer.bytecode.BytecodeContext; 009 import railo.transformer.bytecode.BytecodeException; 010 import railo.transformer.bytecode.expression.Expression; 011 import railo.transformer.bytecode.util.Types; 012 import railo.transformer.cfml.evaluator.impl.Argument; 013 014 public final class TagParam extends TagBase { 015 016 // void param(String type, String name, Object defaultValue) 017 private static final Method PARAM_TYPE_NAME_DEFAULTVALUE = new Method( 018 "param", 019 Types.VOID, 020 new Type[]{Types.STRING,Types.STRING,Types.OBJECT} 021 ); 022 private static final Method PARAM_TYPE_NAME_DEFAULTVALUE_REGEX = new Method( 023 "param", 024 Types.VOID, 025 new Type[]{Types.STRING,Types.STRING,Types.OBJECT,Types.STRING} 026 ); 027 private static final Method PARAM_TYPE_NAME_DEFAULTVALUE_MIN_MAX = new Method( 028 "param", 029 Types.VOID, 030 new Type[]{Types.STRING,Types.STRING,Types.OBJECT,Types.DOUBLE_VALUE,Types.DOUBLE_VALUE} 031 ); 032 033 /** 034 * Constructor of the class 035 * @param line 036 */ 037 public TagParam(int line) { 038 super(line); 039 } 040 public TagParam(int sl,int el) { 041 super(sl,el); 042 } 043 044 /** 045 * 046 * @see railo.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter) 047 */ 048 public void _writeOut(BytecodeContext bc) throws BytecodeException { 049 GeneratorAdapter adapter = bc.getAdapter(); 050 //PageContextImpl pc=null; 051 //pc.param("", "", ""); 052 053 Argument.checkDefaultValue(this); 054 055 // pc 056 adapter.loadArg(0); 057 058 // type 059 Attribute attrType = getAttribute("type"); 060 if(attrType!=null) { 061 attrType.getValue().writeOut(bc, Expression.MODE_REF); 062 } 063 else adapter.push("any"); 064 065 // name 066 getAttribute("name").getValue().writeOut(bc, Expression.MODE_REF); 067 068 // default 069 Attribute attrDefault = getAttribute("default"); 070 if(attrDefault!=null) { 071 attrDefault.getValue().writeOut(bc, Expression.MODE_REF); 072 } 073 else adapter.visitInsn(Opcodes.ACONST_NULL); 074 075 Attribute attrMin = getAttribute("min"); 076 Attribute attrMax = getAttribute("max"); 077 Attribute attrPattern = getAttribute("pattern"); 078 079 if(attrMin!=null && attrMax!=null) { 080 attrMin.getValue().writeOut(bc, Expression.MODE_VALUE); 081 attrMax.getValue().writeOut(bc, Expression.MODE_VALUE); 082 adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE_MIN_MAX); 083 } 084 else if(attrPattern!=null) { 085 attrPattern.getValue().writeOut(bc, Expression.MODE_REF); 086 adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE_REGEX); 087 } 088 else adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE); 089 090 } 091 092 }