1 19 20 25 26 27 28 29 30 31 package soot.jimple.internal; 32 33 import soot.tagkit.*; 34 import soot.*; 35 import soot.jimple.*; 36 import soot.baf.*; 37 import soot.jimple.*; 38 import soot.util.*; 39 import java.util.*; 40 41 public abstract class AbstractNewMultiArrayExpr implements NewMultiArrayExpr, ConvertToBaf 42 { 43 ArrayType baseType; 44 protected ValueBox[] sizeBoxes; 45 46 public abstract Object clone(); 47 48 protected AbstractNewMultiArrayExpr(ArrayType type, ValueBox[] sizeBoxes) 49 { 50 this.baseType = type; this.sizeBoxes = sizeBoxes; 51 } 52 53 public boolean equivTo(Object o) 54 { 55 if (o instanceof AbstractNewMultiArrayExpr) 56 { 57 AbstractNewMultiArrayExpr ae = (AbstractNewMultiArrayExpr)o; 58 if (!baseType.equals(ae.baseType) || 59 sizeBoxes.length != ae.sizeBoxes.length) 60 return false; 61 for (int i = 0; i < sizeBoxes.length; i++) 62 if (sizeBoxes[i] != ae.sizeBoxes[i]) 63 return false; 64 return true; 65 } 66 return false; 67 } 68 69 70 public int equivHashCode() 71 { 72 return baseType.hashCode(); 73 } 74 75 public String toString() 76 { 77 StringBuffer buffer = new StringBuffer (); 78 79 Type t = baseType.baseType; 80 buffer.append(Jimple.v().NEWMULTIARRAY + " (" + t.toString() + ")"); 81 82 for(int i = 0; i < sizeBoxes.length; i++) 83 buffer.append("[" + sizeBoxes[i].getValue().toString() + "]"); 84 85 for(int i = 0; i < baseType.numDimensions - sizeBoxes.length; i++) 86 buffer.append("[]"); 87 88 return buffer.toString(); 89 } 90 91 public void toString(UnitPrinter up) 92 { 93 Type t = baseType.baseType; 94 95 up.literal(Jimple.v().NEWMULTIARRAY); 96 up.literal(" ("); 97 up.type(t); 98 up.literal(")"); 99 100 for(int i = 0; i < sizeBoxes.length; i++) { 101 up.literal("["); 102 sizeBoxes[i].toString(up); 103 up.literal("]"); 104 } 105 106 for(int i = 0; i < baseType.numDimensions - sizeBoxes.length; i++) { 107 up.literal("[]"); 108 } 109 } 110 111 public ArrayType getBaseType() 112 { 113 return baseType; 114 } 115 116 public void setBaseType(ArrayType baseType) 117 { 118 this.baseType = baseType; 119 } 120 121 public ValueBox getSizeBox(int index) 122 { 123 return sizeBoxes[index]; 124 } 125 126 public int getSizeCount() 127 { 128 return sizeBoxes.length; 129 } 130 131 public Value getSize(int index) 132 { 133 return sizeBoxes[index].getValue(); 134 } 135 136 public List getSizes() 137 { 138 List toReturn = new ArrayList(); 139 140 for(int i = 0; i < sizeBoxes.length; i++) 141 toReturn.add(sizeBoxes[i].getValue()); 142 143 return toReturn; 144 } 145 146 public void setSize(int index, Value size) 147 { 148 sizeBoxes[index].setValue(size); 149 } 150 151 public List getUseBoxes() 152 { 153 List list = new ArrayList(); 154 155 for(int i = 0; i < sizeBoxes.length; i++) 156 { 157 list.addAll(sizeBoxes[i].getValue().getUseBoxes()); 158 list.add(sizeBoxes[i]); 159 } 160 161 return list; 162 } 163 164 public Type getType() 165 { 166 return baseType; 167 } 168 169 public void apply(Switch sw) 170 { 171 ((ExprSwitch) sw).caseNewMultiArrayExpr(this); 172 } 173 174 public void convertToBaf(JimpleToBafContext context, List out) 175 { 176 List sizes = getSizes(); 177 178 for(int i = 0; i < sizes.size(); i++) 179 ((ConvertToBaf)(sizes.get(i))).convertToBaf(context, out); 180 181 Unit u; 182 out.add(u = Baf.v().newNewMultiArrayInst(getBaseType(), sizes.size())); 183 184 Unit currentUnit = context.getCurrentUnit(); 185 Iterator it = currentUnit.getTags().iterator(); 186 while(it.hasNext()) { 187 u.addTag((Tag) it.next()); 188 } 189 190 } 191 } 192 | Popular Tags |