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 import soot.grimp.PrecedenceTest; 37 38 abstract public class AbstractCastExpr implements CastExpr, ConvertToBaf 39 { 40 ValueBox opBox; 41 Type type; 42 43 AbstractCastExpr(Value op, Type type) 44 { 45 this(Jimple.v().newImmediateBox(op), type); 46 } 47 48 public abstract Object clone(); 49 50 protected AbstractCastExpr(ValueBox opBox, Type type) 51 { 52 this.opBox = opBox; this.type = type; 53 } 54 55 public boolean equivTo(Object o) 56 { 57 if (o instanceof AbstractCastExpr) 58 { 59 AbstractCastExpr ace = (AbstractCastExpr)o; 60 return opBox.getValue().equivTo(ace.opBox.getValue()) && 61 type.equals(ace.type); 62 } 63 return false; 64 } 65 66 67 public int equivHashCode() 68 { 69 return opBox.getValue().equivHashCode() * 101 + type.hashCode() + 17; 70 } 71 72 public String toString() 73 { 74 return "(" + type.toString() + ") " + opBox.getValue().toString(); 75 } 76 77 public void toString(UnitPrinter up) { 78 up.literal("("); 79 up.type(type); 80 up.literal(") "); 81 if( PrecedenceTest.needsBrackets( opBox, this ) ) up.literal("("); 82 opBox.toString(up); 83 if( PrecedenceTest.needsBrackets( opBox, this ) ) up.literal(")"); 84 } 85 86 public Value getOp() 87 { 88 return opBox.getValue(); 89 } 90 91 public void setOp(Value op) 92 { 93 opBox.setValue(op); 94 } 95 96 public ValueBox getOpBox() 97 { 98 return opBox; 99 } 100 101 public List getUseBoxes() 102 { 103 List list = new ArrayList(); 104 105 list.addAll(opBox.getValue().getUseBoxes()); 106 list.add(opBox); 107 108 return list; 109 } 110 111 public Type getCastType() 112 { 113 return type; 114 } 115 116 public void setCastType(Type castType) 117 { 118 this.type = castType; 119 } 120 121 public Type getType() 122 { 123 return type; 124 } 125 126 public void apply(Switch sw) 127 { 128 ((ExprSwitch) sw).caseCastExpr(this); 129 } 130 131 public void convertToBaf(JimpleToBafContext context, List out) 132 { 133 final Type toType = getCastType(); 134 final Type fromType = getOp().getType(); 135 136 ((ConvertToBaf)getOp()).convertToBaf(context, out); 137 138 Unit u; 139 if (toType instanceof ArrayType || toType instanceof RefType) 140 u = Baf.v().newInstanceCastInst(toType); 141 else 142 u = Baf.v().newPrimitiveCastInst(fromType, toType); 143 144 out.add(u); 145 146 Unit currentUnit = context.getCurrentUnit(); 147 148 Iterator it = currentUnit.getTags().iterator(); 149 while(it.hasNext()) { 150 u.addTag((Tag) it.next()); 151 } 152 } 153 } 154 | Popular Tags |