1 19 20 25 26 27 package soot.jimple.internal; 28 29 import soot.tagkit.*; 30 import soot.*; 31 import soot.jimple.*; 32 import soot.baf.*; 33 import soot.jimple.*; 34 import soot.util.*; 35 import java.util.*; 36 37 public abstract class AbstractNewArrayExpr implements NewArrayExpr, ConvertToBaf 38 { 39 Type baseType; 40 ValueBox sizeBox; 41 42 protected AbstractNewArrayExpr(Type type, ValueBox sizeBox) 43 { 44 this.baseType = type; this.sizeBox = sizeBox; 45 } 46 47 public boolean equivTo(Object o) 48 { 49 if (o instanceof AbstractNewArrayExpr) 50 { 51 AbstractNewArrayExpr ae = (AbstractNewArrayExpr)o; 52 return sizeBox.getValue().equivTo(ae.sizeBox.getValue()) && 53 baseType.equals(ae.baseType); 54 } 55 return false; 56 } 57 58 59 public int equivHashCode() 60 { 61 return sizeBox.getValue().equivHashCode() * 101 + baseType.hashCode() * 17; 62 } 63 64 public abstract Object clone(); 65 66 public String toString() 67 { 68 StringBuffer buffer = new StringBuffer (); 69 70 buffer.append(Jimple.v().NEWARRAY + " (" + getBaseTypeString() + ")"); 71 buffer.append("[" + sizeBox.getValue().toString() + "]"); 72 73 return buffer.toString(); 74 } 75 76 public void toString(UnitPrinter up) { 77 up.literal(Jimple.v().NEWARRAY); 78 up.literal(" "); 79 up.literal("("); 80 up.type(baseType); 81 up.literal(")"); 82 up.literal("["); 83 sizeBox.toString(up); 84 up.literal("]"); 85 } 86 87 private String getBaseTypeString() 88 { 89 return baseType.toString(); 90 } 91 92 public Type getBaseType() 93 { 94 return baseType; 95 } 96 97 public void setBaseType(Type type) 98 { 99 baseType = type; 100 } 101 102 public ValueBox getSizeBox() 103 { 104 return sizeBox; 105 } 106 107 public Value getSize() 108 { 109 return sizeBox.getValue(); 110 } 111 112 public void setSize(Value size) 113 { 114 sizeBox.setValue(size); 115 } 116 117 public List getUseBoxes() 118 { 119 List useBoxes = new ArrayList(); 120 121 useBoxes.addAll(sizeBox.getValue().getUseBoxes()); 122 useBoxes.add(sizeBox); 123 124 return useBoxes; 125 } 126 127 128 public Type getType() 129 { 130 if(baseType instanceof ArrayType) 131 return ArrayType.v(((ArrayType) baseType).baseType, ((ArrayType) baseType).numDimensions + 1); 132 else 133 return ArrayType.v(baseType, 1); 134 } 135 136 public void apply(Switch sw) 137 { 138 ((ExprSwitch) sw).caseNewArrayExpr(this); 139 } 140 141 public void convertToBaf(JimpleToBafContext context, List out) 142 { 143 ((ConvertToBaf)(getSize())).convertToBaf(context, out); 144 145 146 Unit u; 147 out.add(u = Baf.v().newNewArrayInst(getBaseType())); 148 149 Unit currentUnit = context.getCurrentUnit(); 150 151 Iterator it = currentUnit.getTags().iterator(); 152 while(it.hasNext()) { 153 u.addTag((Tag) it.next()); 154 } 155 156 } 157 } 158 | Popular Tags |