001 package railo.transformer.bytecode.expression.var; 002 003 import org.objectweb.asm.Type; 004 import org.objectweb.asm.commons.GeneratorAdapter; 005 import org.objectweb.asm.commons.Method; 006 007 import railo.transformer.bytecode.BytecodeContext; 008 import railo.transformer.bytecode.BytecodeException; 009 import railo.transformer.bytecode.expression.ExpressionBase; 010 import railo.transformer.bytecode.util.TypeScope; 011 import railo.transformer.bytecode.util.Types; 012 013 public final class VariableRef extends ExpressionBase { 014 015 016 private Variable variable; 017 // Object touch (Object,String) 018 private final static Method TOUCH = new Method("touch", 019 Types.OBJECT, 020 new Type[]{Types.OBJECT,Types.STRING}); 021 // railo.runtime.type.ref.Reference getReference (Object,String) 022 private final static Method GET_REFERENCE = new Method("getReference", 023 Types.REFERENCE, 024 new Type[]{Types.OBJECT,Types.STRING}); 025 026 // Object touch (Object,Key) 027 private final static Method TOUCH_KEY = new Method("touch", 028 Types.OBJECT, 029 new Type[]{Types.OBJECT,Types.COLLECTION_KEY}); 030 // railo.runtime.type.ref.Reference getReference (Object,Key) 031 private final static Method GET_REFERENCE_KEY = new Method("getReference", 032 Types.REFERENCE, 033 new Type[]{Types.OBJECT,Types.COLLECTION_KEY}); 034 035 public VariableRef(Variable variable) { 036 super(variable.getStart(),variable.getEnd()); 037 this.variable=variable; 038 } 039 040 /** 041 * 042 * @see railo.transformer.bytecode.expression.ExpressionBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter, int) 043 */ 044 public Type _writeOut(BytecodeContext bc, int mode) throws BytecodeException { 045 GeneratorAdapter adapter = bc.getAdapter(); 046 int count=variable.countFM+variable.countDM; 047 048 for(int i=0;i<=count;i++) { 049 adapter.loadArg(0); 050 } 051 TypeScope.invokeScope(adapter, variable.scope); 052 053 boolean isLast; 054 for(int i=0;i<count;i++) { 055 isLast=(i+1)==count; 056 if(Variable.registerKey(bc,((DataMember)variable.members.get(i)).getName())) 057 adapter.invokeVirtual(Types.PAGE_CONTEXT,isLast?GET_REFERENCE_KEY:TOUCH_KEY); 058 else 059 adapter.invokeVirtual(Types.PAGE_CONTEXT,isLast?GET_REFERENCE:TOUCH); 060 //((DataMember)variable.members.get(i)).getName().writeOut(bc, MODE_REF); 061 //adapter.invokeVirtual(Types.PAGE_CONTEXT,isLast?GET_REFERENCE:TOUCH); 062 } 063 return Types.REFERENCE; 064 } 065 066 /* * 067 * 068 * @see railo.transformer.bytecode.expression.Expression#getType() 069 * / 070 public int getType() { 071 return Types._OBJECT; 072 }*/ 073 074 }