1 17 package org.apache.bcel.generic; 18 19 import java.io.DataOutputStream ; 20 import java.io.IOException ; 21 import org.apache.bcel.util.ByteSequence; 22 23 31 public class RET extends Instruction implements IndexedInstruction, TypedInstruction { 32 33 private boolean wide; 34 private int index; 36 37 41 RET() { 42 } 43 44 45 public RET(int index) { 46 super(org.apache.bcel.Constants.RET, (short) 2); 47 setIndex(index); } 49 50 51 55 public void dump( DataOutputStream out ) throws IOException { 56 if (wide) { 57 out.writeByte(org.apache.bcel.Constants.WIDE); 58 } 59 out.writeByte(opcode); 60 if (wide) { 61 out.writeShort(index); 62 } else { 63 out.writeByte(index); 64 } 65 } 66 67 68 private final void setWide() { 69 wide = index > org.apache.bcel.Constants.MAX_BYTE; 70 if (wide) { 71 length = 4; } else { 73 length = 2; 74 } 75 } 76 77 78 81 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException { 82 this.wide = wide; 83 if (wide) { 84 index = bytes.readUnsignedShort(); 85 length = 4; 86 } else { 87 index = bytes.readUnsignedByte(); 88 length = 2; 89 } 90 } 91 92 93 96 public final int getIndex() { 97 return index; 98 } 99 100 101 104 public final void setIndex( int n ) { 105 if (n < 0) { 106 throw new ClassGenException("Negative index value: " + n); 107 } 108 index = n; 109 setWide(); 110 } 111 112 113 116 public String toString( boolean verbose ) { 117 return super.toString(verbose) + " " + index; 118 } 119 120 121 123 public Type getType( ConstantPoolGen cp ) { 124 return ReturnaddressType.NO_TARGET; 125 } 126 127 128 136 public void accept( Visitor v ) { 137 v.visitRET(this); 138 } 139 } 140 | Popular Tags |