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.Position; 011 import railo.transformer.bytecode.cast.CastInt; 012 import railo.transformer.bytecode.expression.Expression; 013 import railo.transformer.bytecode.util.Types; 014 import railo.transformer.cfml.evaluator.impl.Argument; 015 016 public final class TagParam extends TagBaseNoFinal { 017 018 // void param(String type, String name, Object defaultValue) 019 private static final Method PARAM_TYPE_NAME_DEFAULTVALUE = new Method( 020 "param", 021 Types.VOID, 022 new Type[]{Types.STRING,Types.STRING,Types.OBJECT} 023 ); 024 private static final Method PARAM_TYPE_NAME_DEFAULTVALUE_REGEX = new Method( 025 "param", 026 Types.VOID, 027 new Type[]{Types.STRING,Types.STRING,Types.OBJECT,Types.STRING} 028 ); 029 private static final Method PARAM_TYPE_NAME_DEFAULTVALUE_MIN_MAX = new Method( 030 "param", 031 Types.VOID, 032 new Type[]{Types.STRING,Types.STRING,Types.OBJECT,Types.DOUBLE_VALUE,Types.DOUBLE_VALUE} 033 ); 034 private static final Method PARAM_TYPE_NAME_DEFAULTVALUE_MAXLENGTH = new Method( 035 "param", 036 Types.VOID, 037 new Type[]{Types.STRING,Types.STRING,Types.OBJECT,Types.INT_VALUE} 038 ); 039 040 public TagParam(Position start,Position end) { 041 super(start,end); 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 Attribute maxLength = getAttribute("maxLength"); 079 080 if(attrMin!=null && attrMax!=null) { 081 attrMin.getValue().writeOut(bc, Expression.MODE_VALUE); 082 attrMax.getValue().writeOut(bc, Expression.MODE_VALUE); 083 adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE_MIN_MAX); 084 } 085 else if(attrPattern!=null) { 086 attrPattern.getValue().writeOut(bc, Expression.MODE_REF); 087 adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE_REGEX); 088 } 089 else if(maxLength!=null) { 090 CastInt.toExprInt(maxLength.getValue()).writeOut(bc, Expression.MODE_VALUE); 091 adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE_MAXLENGTH); 092 } 093 else adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE); 094 095 } 096 097 }