001 package railo.transformer.bytecode.statement.java; 002 003 import org.objectweb.asm.Type; 004 005 import railo.transformer.bytecode.BytecodeContext; 006 import railo.transformer.bytecode.BytecodeException; 007 import railo.transformer.bytecode.expression.ExpressionBase; 008 import railo.transformer.bytecode.util.Types; 009 010 public class VariableDecl extends ExpressionBase { 011 012 private Class type; 013 private String name; 014 private Object value; 015 private DataBag db; 016 017 public VariableDecl(int line,Class type,String name,Object value, DataBag db) { 018 super(line); 019 this.type=type; 020 this.name=name; 021 this.value=value; 022 this.db = db; 023 024 } 025 026 public Type _writeOut(BytecodeContext bc, int mode) throws BytecodeException { 027 Integer oLocal=db.locals.get(name); 028 int local; 029 Type t = null; 030 if(oLocal==null){ 031 032 t = Type.getType(type); 033 local =bc.getAdapter().newLocal(t); 034 db.locals.put(name, Integer.valueOf(local)); 035 036 } 037 else 038 throw new BytecodeException("there is already a variable declared with name ["+name+"]", getLine()); 039 040 041 //bc.getAdapter().visitLocalVariable(name, strType, null, db.start,db.end,x); 042 043 if(value!=null){ 044 Type rtn = Assign.writeOut(db, bc, t,mode, value, getLine(),false); 045 046 bc.getAdapter().storeLocal(local,t); 047 } 048 049 return Types.VOID; 050 } 051 052 053 054 }