001 package serp.bytecode; 002 003 import serp.bytecode.visitor.*; 004 005 /** 006 * Stores a value from the stack into a field. 007 * 008 * @author Abe White 009 */ 010 public class PutFieldInstruction extends FieldInstruction { 011 PutFieldInstruction(Code owner, int opcode) { 012 super(owner, opcode); 013 } 014 015 public int getLogicalStackChange() { 016 if (getFieldTypeName() == null) 017 return 0; 018 if (getOpcode() == Constants.PUTSTATIC) 019 return -1; 020 return -2; 021 } 022 023 public int getStackChange() { 024 String type = getFieldTypeName(); 025 if (type == null) 026 return 0; 027 028 int stack = -2; 029 if (long.class.getName().equals(type) 030 || double.class.getName().equals(type)) 031 stack++; 032 if (getOpcode() == Constants.PUTSTATIC) 033 stack++; 034 return stack; 035 } 036 037 public void acceptVisit(BCVisitor visit) { 038 visit.enterPutFieldInstruction(this); 039 visit.exitPutFieldInstruction(this); 040 } 041 }