1 package serp.bytecode; 2 3 import serp.bytecode.visitor.*; 4 5 /*** 6 * Stores a value from the stack into a field. 7 * 8 * @author Abe White 9 */ 10 public class PutFieldInstruction extends FieldInstruction { 11 PutFieldInstruction(Code owner, int opcode) { 12 super(owner, opcode); 13 } 14 15 public int getLogicalStackChange() { 16 if (getFieldTypeName() == null) 17 return 0; 18 if (getOpcode() == Constants.PUTSTATIC) 19 return -1; 20 return -2; 21 } 22 23 public int getStackChange() { 24 String type = getFieldTypeName(); 25 if (type == null) 26 return 0; 27 28 int stack = -2; 29 if (long.class.getName().equals(type) 30 || double.class.getName().equals(type)) 31 stack++; 32 if (getOpcode() == Constants.PUTSTATIC) 33 stack++; 34 return stack; 35 } 36 37 public void acceptVisit(BCVisitor visit) { 38 visit.enterPutFieldInstruction(this); 39 visit.exitPutFieldInstruction(this); 40 } 41 }