1 19 20 25 26 27 28 29 30 31 package soot.jimple.internal; 32 33 import soot.*; 34 import soot.tagkit.*; 35 import soot.jimple.*; 36 import soot.baf.*; 37 import soot.jimple.*; 38 import soot.util.*; 39 import java.util.*; 40 41 public class JArrayRef implements ArrayRef, ConvertToBaf 42 { 43 protected ValueBox baseBox; 44 protected ValueBox indexBox; 45 46 public JArrayRef(Value base, Value index) 47 { 48 this(Jimple.v().newLocalBox(base), 49 Jimple.v().newImmediateBox(index)); 50 } 51 52 protected JArrayRef(ValueBox baseBox, ValueBox indexBox) 53 { 54 this.baseBox = baseBox; 55 this.indexBox = indexBox; 56 } 57 58 public Object clone() 59 { 60 return new JArrayRef(Jimple.cloneIfNecessary(getBase()), Jimple.cloneIfNecessary(getIndex())); 61 } 62 63 public boolean equivTo(Object o) 64 { 65 if (o instanceof ArrayRef) 66 { 67 return (getBase().equivTo(((ArrayRef)o).getBase()) 68 && getIndex().equivTo(((ArrayRef)o).getIndex())); 69 } 70 return false; 71 } 72 73 74 public int equivHashCode() 75 { 76 return getBase().equivHashCode() * 101 + getIndex().equivHashCode() + 17; 77 } 78 79 public String toString() 80 { 81 return baseBox.getValue().toString() + "[" + indexBox.getValue().toString() + "]"; 82 } 83 84 public void toString(UnitPrinter up) { 85 baseBox.toString(up); 86 up.literal("["); 87 indexBox.toString(up); 88 up.literal("]"); 89 } 90 91 public Value getBase() 92 { 93 return baseBox.getValue(); 94 } 95 96 public void setBase(Local base) 97 { 98 baseBox.setValue(base); 99 } 100 101 public ValueBox getBaseBox() 102 { 103 return baseBox; 104 } 105 106 public Value getIndex() 107 { 108 return indexBox.getValue(); 109 } 110 111 public void setIndex(Value index) 112 { 113 indexBox.setValue(index); 114 } 115 116 public ValueBox getIndexBox() 117 { 118 return indexBox; 119 } 120 121 public List getUseBoxes() 122 { 123 List useBoxes = new ArrayList(); 124 125 useBoxes.addAll(baseBox.getValue().getUseBoxes()); 126 useBoxes.add(baseBox); 127 128 useBoxes.addAll(indexBox.getValue().getUseBoxes()); 129 useBoxes.add(indexBox); 130 131 return useBoxes; 132 } 133 134 public Type getType() 135 { 136 Value base = (Value) baseBox.getValue(); 137 Type type = base.getType(); 138 139 if(type.equals(UnknownType.v())) 140 return UnknownType.v(); 141 else if(type.equals(NullType.v())) 142 return NullType.v(); 143 else { 144 ArrayType arrayType = (ArrayType) type; 145 146 if(arrayType.numDimensions == 1) 147 return arrayType.baseType; 148 else 149 return ArrayType.v(arrayType.baseType, arrayType.numDimensions - 1); 150 } 151 } 152 153 public void apply(Switch sw) 154 { 155 ((RefSwitch) sw).caseArrayRef(this); 156 } 157 158 public void convertToBaf(JimpleToBafContext context, List out) 159 { 160 ((ConvertToBaf)getBase()).convertToBaf(context, out); 161 ((ConvertToBaf)getIndex()).convertToBaf(context, out); 162 163 Unit currentUnit = context.getCurrentUnit(); 164 165 Unit x; 166 167 out.add(x = Baf.v().newArrayReadInst(getType())); 168 169 Iterator it = currentUnit.getTags().iterator(); 170 while(it.hasNext()) { 171 x.addTag((Tag) it.next()); 172 } 173 174 } 175 } 176 177 178 179 | Popular Tags |