1 package serp.bytecode; 2 3 import serp.bytecode.visitor.*; 4 5 /*** 6 * Store a value from the stack into an array. 7 * 8 * @author Abe White 9 */ 10 public class ArrayStoreInstruction extends ArrayInstruction { 11 private static final Class[][] _mappings = new Class[][] { 12 { boolean.class, int.class }, 13 { void.class, int.class }, 14 }; 15 16 ArrayStoreInstruction(Code owner) { 17 super(owner); 18 } 19 20 ArrayStoreInstruction(Code owner, int opcode) { 21 super(owner, opcode); 22 } 23 24 public int getLogicalStackChange() { 25 switch (getOpcode()) { 26 case Constants.NOP: 27 return 0; 28 default: 29 return -3; 30 } 31 } 32 33 public int getStackChange() { 34 switch (getOpcode()) { 35 case Constants.DASTORE: 36 case Constants.LASTORE: 37 return -4; 38 case Constants.NOP: 39 return 0; 40 default: 41 return -3; 42 } 43 } 44 45 public String getTypeName() { 46 switch (getOpcode()) { 47 case Constants.IASTORE: 48 return int.class.getName(); 49 case Constants.LASTORE: 50 return long.class.getName(); 51 case Constants.FASTORE: 52 return float.class.getName(); 53 case Constants.DASTORE: 54 return double.class.getName(); 55 case Constants.AASTORE: 56 return Object.class.getName(); 57 case Constants.BASTORE: 58 return byte.class.getName(); 59 case Constants.CASTORE: 60 return char.class.getName(); 61 case Constants.SASTORE: 62 return short.class.getName(); 63 default: 64 return null; 65 } 66 } 67 68 public TypedInstruction setType(String type) { 69 type = mapType(type, _mappings, true); 70 if (type == null) 71 return (TypedInstruction) setOpcode(Constants.NOP); 72 73 switch (type.charAt(0)) { 74 case 'i': 75 return (TypedInstruction) setOpcode(Constants.IASTORE); 76 case 'l': 77 return (TypedInstruction) setOpcode(Constants.LASTORE); 78 case 'f': 79 return (TypedInstruction) setOpcode(Constants.FASTORE); 80 case 'd': 81 return (TypedInstruction) setOpcode(Constants.DASTORE); 82 case 'b': 83 return (TypedInstruction) setOpcode(Constants.BASTORE); 84 case 'c': 85 return (TypedInstruction) setOpcode(Constants.CASTORE); 86 case 's': 87 return (TypedInstruction) setOpcode(Constants.SASTORE); 88 default: 89 return (TypedInstruction) setOpcode(Constants.AASTORE); 90 } 91 } 92 93 public void acceptVisit(BCVisitor visit) { 94 visit.enterArrayStoreInstruction(this); 95 visit.exitArrayStoreInstruction(this); 96 } 97 }