1 19 20 25 26 27 28 29 30 package soot.jimple; 31 32 import soot.*; 33 import soot.util.*; 34 import java.util.*; 35 36 public class IntConstant extends ArithmeticConstant 37 { 38 public final int value; 39 40 protected IntConstant(int value) 41 { 42 this.value = value; 43 } 44 45 public static IntConstant v(int value) 46 { 47 return new IntConstant(value); 48 } 49 50 public boolean equals(Object c) 51 { 52 return c instanceof IntConstant && ((IntConstant) c).value == value; 53 } 54 55 public int hashCode() 56 { 57 return value; 58 } 59 60 public NumericConstant add(NumericConstant c) 62 { 63 if (!(c instanceof IntConstant)) 64 throw new IllegalArgumentException ("IntConstant expected"); 65 return IntConstant.v(this.value + ((IntConstant)c).value); 66 } 67 68 public NumericConstant subtract(NumericConstant c) 69 { 70 if (!(c instanceof IntConstant)) 71 throw new IllegalArgumentException ("IntConstant expected"); 72 return IntConstant.v(this.value - ((IntConstant)c).value); 73 } 74 75 public NumericConstant multiply(NumericConstant c) 76 { 77 if (!(c instanceof IntConstant)) 78 throw new IllegalArgumentException ("IntConstant expected"); 79 return IntConstant.v(this.value * ((IntConstant)c).value); 80 } 81 82 public NumericConstant divide(NumericConstant c) 83 { 84 if (!(c instanceof IntConstant)) 85 throw new IllegalArgumentException ("IntConstant expected"); 86 return IntConstant.v(this.value / ((IntConstant)c).value); 87 } 88 89 public NumericConstant remainder(NumericConstant c) 90 { 91 if (!(c instanceof IntConstant)) 92 throw new IllegalArgumentException ("IntConstant expected"); 93 return IntConstant.v(this.value % ((IntConstant)c).value); 94 } 95 96 public NumericConstant equalEqual(NumericConstant c) 97 { 98 if (!(c instanceof IntConstant)) 99 throw new IllegalArgumentException ("IntConstant expected"); 100 return IntConstant.v((this.value == ((IntConstant)c).value) ? 1 : 0); 101 } 102 103 public NumericConstant notEqual(NumericConstant c) 104 { 105 if (!(c instanceof IntConstant)) 106 throw new IllegalArgumentException ("IntConstant expected"); 107 return IntConstant.v((this.value != ((IntConstant)c).value) ? 1 : 0); 108 } 109 110 public NumericConstant lessThan(NumericConstant c) 111 { 112 if (!(c instanceof IntConstant)) 113 throw new IllegalArgumentException ("IntConstant expected"); 114 return IntConstant.v((this.value < ((IntConstant)c).value) ? 1 : 0); 115 } 116 117 public NumericConstant lessThanOrEqual(NumericConstant c) 118 { 119 if (!(c instanceof IntConstant)) 120 throw new IllegalArgumentException ("IntConstant expected"); 121 return IntConstant.v((this.value <= ((IntConstant)c).value) ? 1 : 0); 122 } 123 124 public NumericConstant greaterThan(NumericConstant c) 125 { 126 if (!(c instanceof IntConstant)) 127 throw new IllegalArgumentException ("IntConstant expected"); 128 return IntConstant.v((this.value > ((IntConstant)c).value) ? 1 : 0); 129 } 130 131 public NumericConstant greaterThanOrEqual(NumericConstant c) 132 { 133 if (!(c instanceof IntConstant)) 134 throw new IllegalArgumentException ("IntConstant expected"); 135 return IntConstant.v((this.value >= ((IntConstant)c).value) ? 1 : 0); 136 } 137 138 public NumericConstant negate() 139 { 140 return IntConstant.v(-(this.value)); 141 } 142 143 public ArithmeticConstant and(ArithmeticConstant c) 144 { 145 if (!(c instanceof IntConstant)) 146 throw new IllegalArgumentException ("IntConstant expected"); 147 return IntConstant.v(this.value & ((IntConstant)c).value); 148 } 149 150 public ArithmeticConstant or(ArithmeticConstant c) 151 { 152 if (!(c instanceof IntConstant)) 153 throw new IllegalArgumentException ("IntConstant expected"); 154 return IntConstant.v(this.value | ((IntConstant)c).value); 155 } 156 157 public ArithmeticConstant xor(ArithmeticConstant c) 158 { 159 if (!(c instanceof IntConstant)) 160 throw new IllegalArgumentException ("IntConstant expected"); 161 return IntConstant.v(this.value ^ ((IntConstant)c).value); 162 } 163 164 public ArithmeticConstant shiftLeft(ArithmeticConstant c) 165 { 166 if (!(c instanceof IntConstant)) 167 throw new IllegalArgumentException ("IntConstant expected"); 168 return IntConstant.v(this.value << ((IntConstant)c).value); 169 } 170 171 public ArithmeticConstant shiftRight(ArithmeticConstant c) 172 { 173 if (!(c instanceof IntConstant)) 174 throw new IllegalArgumentException ("IntConstant expected"); 175 return IntConstant.v(this.value >> ((IntConstant)c).value); 176 } 177 178 public ArithmeticConstant unsignedShiftRight(ArithmeticConstant c) 179 { 180 if (!(c instanceof IntConstant)) 181 throw new IllegalArgumentException ("IntConstant expected"); 182 return IntConstant.v(this.value >>> ((IntConstant)c).value); 183 } 184 185 public String toString() 186 { 187 return new Integer (value).toString(); 188 } 189 190 public Type getType() 191 { 192 return IntType.v(); 193 } 194 195 public void apply(Switch sw) 196 { 197 ((ConstantSwitch) sw).caseIntConstant(this); 198 } 199 200 } 201 | Popular Tags |