001package serp.bytecode;
002
003import serp.bytecode.lowlevel.*;
004import serp.bytecode.visitor.*;
005
006/**
007 * An if instruction such as <code>ifnull, ifeq</code>, etc.
008 *
009 * @author Abe White
010 */
011public class IfInstruction extends JumpInstruction {
012    IfInstruction(Code owner, int opcode) {
013        super(owner, opcode);
014    }
015
016    public int getStackChange() {
017        switch (getOpcode()) {
018        case Constants.IFACMPEQ:
019        case Constants.IFACMPNE:
020        case Constants.IFICMPEQ:
021        case Constants.IFICMPNE:
022        case Constants.IFICMPLT:
023        case Constants.IFICMPGT:
024        case Constants.IFICMPLE:
025        case Constants.IFICMPGE:
026            return -2;
027        case Constants.IFEQ:
028        case Constants.IFNE:
029        case Constants.IFLT:
030        case Constants.IFGT:
031        case Constants.IFLE:
032        case Constants.IFGE:
033        case Constants.IFNULL:
034        case Constants.IFNONNULL:
035            return -1;
036        default:
037            return super.getStackChange();
038        }
039    }
040
041    int getLength() {
042        return super.getLength() + 2;
043    }
044
045    public String getTypeName() {
046        switch (getOpcode()) {
047        case Constants.IFACMPEQ:
048        case Constants.IFACMPNE:
049        case Constants.IFNULL:
050        case Constants.IFNONNULL:
051            return "java.lang.Object";
052        default:
053            return "I";
054        }
055    }
056
057    public void acceptVisit(BCVisitor visit) {
058        visit.enterIfInstruction(this);
059        visit.exitIfInstruction(this);
060    }
061}