1 19 20 25 26 27 package soot.jimple.internal; 28 29 import soot.*; 30 import soot.jimple.*; 31 import soot.util.*; 32 import java.util.*; 33 import soot.grimp.PrecedenceTest; 34 35 public abstract class AbstractBinopExpr implements Expr 36 { 37 protected ValueBox op1Box; 38 protected ValueBox op2Box; 39 40 public Value getOp1() 41 { 42 return op1Box.getValue(); 43 } 44 45 public Value getOp2() 46 { 47 return op2Box.getValue(); 48 } 49 50 public ValueBox getOp1Box() 51 { 52 return op1Box; 53 } 54 55 public ValueBox getOp2Box() 56 { 57 return op2Box; 58 } 59 60 public void setOp1(Value op1) 61 { 62 op1Box.setValue(op1); 63 } 64 65 public void setOp2(Value op2) 66 { 67 op2Box.setValue(op2); 68 } 69 70 public List getUseBoxes() 71 { 72 List list = new ArrayList(); 73 74 list.addAll(op1Box.getValue().getUseBoxes()); 75 list.add(op1Box); 76 list.addAll(op2Box.getValue().getUseBoxes()); 77 list.add(op2Box); 78 79 return list; 80 } 81 82 public boolean equivTo(Object o) 83 { 84 if (o instanceof AbstractBinopExpr) 85 { 86 AbstractBinopExpr abe = (AbstractBinopExpr)o; 87 return op1Box.getValue().equivTo(abe.op1Box.getValue()) && 88 op2Box.getValue().equivTo(abe.op2Box.getValue()) && 89 getSymbol().equals(abe.getSymbol()); 90 } 91 return false; 92 } 93 94 95 public int equivHashCode() 96 { 97 return op1Box.getValue().equivHashCode() * 101 + op2Box.getValue().equivHashCode() + 17 98 ^ getSymbol().hashCode(); 99 } 100 101 102 abstract protected String getSymbol(); 103 abstract public Object clone(); 104 105 public String toString() 106 { 107 Value op1 = op1Box.getValue(), op2 = op2Box.getValue(); 108 String leftOp = op1.toString(), rightOp = op2.toString(); 109 110 return leftOp + getSymbol() + rightOp; 111 } 112 113 public void toString( UnitPrinter up ) { 114 Value val1 = op1Box.getValue(); 115 Value val2 = op2Box.getValue(); 116 117 if( PrecedenceTest.needsBrackets( op1Box, this ) ) up.literal("("); 118 op1Box.toString(up); 119 if( PrecedenceTest.needsBrackets( op1Box, this ) ) up.literal(")"); 120 121 up.literal(getSymbol()); 122 123 if( PrecedenceTest.needsBracketsRight( op2Box, this ) ) up.literal("("); 124 op2Box.toString(up); 125 if( PrecedenceTest.needsBracketsRight( op2Box, this ) ) up.literal(")"); 126 } 127 } 128 | Popular Tags |