1 package serp.bytecode; 2 3 import serp.bytecode.lowlevel.*; 4 import serp.bytecode.visitor.*; 5 6 /*** 7 * An if instruction such as <code>ifnull, ifeq</code>, etc. 8 * 9 * @author Abe White 10 */ 11 public class IfInstruction extends JumpInstruction { 12 IfInstruction(Code owner, int opcode) { 13 super(owner, opcode); 14 } 15 16 public int getStackChange() { 17 switch (getOpcode()) { 18 case Constants.IFACMPEQ: 19 case Constants.IFACMPNE: 20 case Constants.IFICMPEQ: 21 case Constants.IFICMPNE: 22 case Constants.IFICMPLT: 23 case Constants.IFICMPGT: 24 case Constants.IFICMPLE: 25 case Constants.IFICMPGE: 26 return -2; 27 case Constants.IFEQ: 28 case Constants.IFNE: 29 case Constants.IFLT: 30 case Constants.IFGT: 31 case Constants.IFLE: 32 case Constants.IFGE: 33 case Constants.IFNULL: 34 case Constants.IFNONNULL: 35 return -1; 36 default: 37 return super.getStackChange(); 38 } 39 } 40 41 int getLength() { 42 return super.getLength() + 2; 43 } 44 45 public String getTypeName() { 46 switch (getOpcode()) { 47 case Constants.IFACMPEQ: 48 case Constants.IFACMPNE: 49 case Constants.IFNULL: 50 case Constants.IFNONNULL: 51 return "java.lang.Object"; 52 default: 53 return "I"; 54 } 55 } 56 57 public void acceptVisit(BCVisitor visit) { 58 visit.enterIfInstruction(this); 59 visit.exitIfInstruction(this); 60 } 61 }