Home | History | Annotate | Download | only in value
      1 /*
      2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
      3  *             of Java bytecode.
      4  *
      5  * Copyright (c) 2002-2014 Eric Lafortune (eric (at) graphics.cornell.edu)
      6  *
      7  * This program is free software; you can redistribute it and/or modify it
      8  * under the terms of the GNU General Public License as published by the Free
      9  * Software Foundation; either version 2 of the License, or (at your option)
     10  * any later version.
     11  *
     12  * This program is distributed in the hope that it will be useful, but WITHOUT
     13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
     14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
     15  * more details.
     16  *
     17  * You should have received a copy of the GNU General Public License along
     18  * with this program; if not, write to the Free Software Foundation, Inc.,
     19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
     20  */
     21 package proguard.evaluation.value;
     22 
     23 /**
     24  * This IntegerValue represents a specific integer value.
     25  *
     26  * @author Eric Lafortune
     27  */
     28 abstract class SpecificIntegerValue extends IntegerValue
     29 {
     30     // Implementations of unary methods of IntegerValue.
     31 
     32     public IntegerValue negate()
     33     {
     34         return new NegatedIntegerValue(this);
     35     }
     36 
     37     public IntegerValue convertToByte()
     38     {
     39         return new ConvertedByteValue(this);
     40     }
     41 
     42     public IntegerValue convertToCharacter()
     43     {
     44         return new ConvertedCharacterValue(this);
     45     }
     46 
     47     public IntegerValue convertToShort()
     48     {
     49         return new ConvertedShortValue(this);
     50     }
     51 
     52     public LongValue convertToLong()
     53     {
     54         return new ConvertedLongValue(this);
     55     }
     56 
     57     public FloatValue convertToFloat()
     58     {
     59         return new ConvertedFloatValue(this);
     60     }
     61 
     62     public DoubleValue convertToDouble()
     63     {
     64         return new ConvertedDoubleValue(this);
     65     }
     66 
     67 
     68     // Implementations of binary methods of IntegerValue.
     69 
     70     public IntegerValue generalize(IntegerValue other)
     71     {
     72         return other.generalize(this);
     73     }
     74 
     75     public IntegerValue add(IntegerValue other)
     76     {
     77         return other.add(this);
     78     }
     79 
     80     public IntegerValue subtract(IntegerValue other)
     81     {
     82         return other.subtractFrom(this);
     83     }
     84 
     85     public IntegerValue subtractFrom(IntegerValue other)
     86     {
     87         return other.subtract(this);
     88     }
     89 
     90     public IntegerValue multiply(IntegerValue other)
     91     {
     92         return other.multiply(this);
     93     }
     94 
     95     public IntegerValue divide(IntegerValue other)
     96     throws ArithmeticException
     97     {
     98         return other.divideOf(this);
     99     }
    100 
    101     public IntegerValue divideOf(IntegerValue other)
    102     throws ArithmeticException
    103     {
    104         return other.divide(this);
    105     }
    106 
    107     public IntegerValue remainder(IntegerValue other)
    108     throws ArithmeticException
    109     {
    110         return other.remainderOf(this);
    111     }
    112 
    113     public IntegerValue remainderOf(IntegerValue other)
    114     throws ArithmeticException
    115     {
    116         return other.remainder(this);
    117     }
    118 
    119     public IntegerValue shiftLeft(IntegerValue other)
    120     {
    121         return other.shiftLeftOf(this);
    122     }
    123 
    124     public IntegerValue shiftLeftOf(IntegerValue other)
    125     {
    126         return other.shiftLeft(this);
    127     }
    128 
    129     public IntegerValue shiftRight(IntegerValue other)
    130     {
    131         return other.shiftRightOf(this);
    132     }
    133 
    134     public IntegerValue shiftRightOf(IntegerValue other)
    135     {
    136         return other.shiftRight(this);
    137     }
    138 
    139     public IntegerValue unsignedShiftRight(IntegerValue other)
    140     {
    141         return other.unsignedShiftRightOf(this);
    142     }
    143 
    144     public IntegerValue unsignedShiftRightOf(IntegerValue other)
    145     {
    146         return other.unsignedShiftRight(this);
    147     }
    148 
    149     public LongValue shiftLeftOf(LongValue other)
    150     {
    151         return other.shiftLeft(this);
    152     }
    153 
    154     public LongValue shiftRightOf(LongValue other)
    155     {
    156         return other.shiftRight(this);
    157     }
    158 
    159     public LongValue unsignedShiftRightOf(LongValue other)
    160     {
    161         return other.unsignedShiftRight(this);
    162     }
    163 
    164     public IntegerValue and(IntegerValue other)
    165     {
    166         return other.and(this);
    167     }
    168 
    169     public IntegerValue or(IntegerValue other)
    170     {
    171         return other.or(this);
    172     }
    173 
    174     public IntegerValue xor(IntegerValue other)
    175     {
    176         return other.xor(this);
    177     }
    178 
    179     public int equal(IntegerValue other)
    180     {
    181         return other.equal(this);
    182     }
    183 
    184     public int lessThan(IntegerValue other)
    185     {
    186         return other.greaterThan(this);
    187     }
    188 
    189     public int lessThanOrEqual(IntegerValue other)
    190     {
    191         return other.greaterThanOrEqual(this);
    192     }
    193 
    194 
    195     // Implementations of binary IntegerValue methods with SpecificIntegerValue
    196     // arguments.
    197 
    198     public IntegerValue generalize(SpecificIntegerValue other)
    199     {
    200         return this.equals(other) ? this : ValueFactory.INTEGER_VALUE;
    201     }
    202 
    203     public IntegerValue add(SpecificIntegerValue other)
    204     {
    205         return new CompositeIntegerValue(this, CompositeIntegerValue.ADD, other);
    206     }
    207 
    208     public IntegerValue subtract(SpecificIntegerValue other)
    209     {
    210         return this.equals(other) ?
    211             ParticularValueFactory.INTEGER_VALUE_0 :
    212             new CompositeIntegerValue(this, CompositeIntegerValue.SUBTRACT, other);
    213     }
    214 
    215     public IntegerValue subtractFrom(SpecificIntegerValue other)
    216     {
    217         return this.equals(other) ?
    218             ParticularValueFactory.INTEGER_VALUE_0 :
    219             new CompositeIntegerValue(other, CompositeIntegerValue.SUBTRACT, this);
    220     }
    221 
    222     public IntegerValue multiply(SpecificIntegerValue other)
    223     {
    224         return new CompositeIntegerValue(this, CompositeIntegerValue.MULTIPLY, other);
    225     }
    226 
    227     public IntegerValue divide(SpecificIntegerValue other)
    228     throws ArithmeticException
    229     {
    230         return new CompositeIntegerValue(this, CompositeIntegerValue.DIVIDE, other);
    231     }
    232 
    233     public IntegerValue divideOf(SpecificIntegerValue other)
    234     throws ArithmeticException
    235     {
    236         return new CompositeIntegerValue(other, CompositeIntegerValue.DIVIDE, this);
    237     }
    238 
    239     public IntegerValue remainder(SpecificIntegerValue other)
    240     throws ArithmeticException
    241     {
    242         return new CompositeIntegerValue(this, CompositeIntegerValue.REMAINDER, other);
    243     }
    244 
    245     public IntegerValue remainderOf(SpecificIntegerValue other)
    246     throws ArithmeticException
    247     {
    248         return new CompositeIntegerValue(other, CompositeIntegerValue.REMAINDER, this);
    249     }
    250 
    251     public IntegerValue shiftLeft(SpecificIntegerValue other)
    252     {
    253         return new CompositeIntegerValue(this, CompositeIntegerValue.SHIFT_LEFT, other);
    254     }
    255 
    256     public IntegerValue shiftRight(SpecificIntegerValue other)
    257     {
    258         return new CompositeIntegerValue(this, CompositeIntegerValue.SHIFT_RIGHT, other);
    259     }
    260 
    261     public IntegerValue unsignedShiftRight(SpecificIntegerValue other)
    262     {
    263         return new CompositeIntegerValue(this, CompositeIntegerValue.UNSIGNED_SHIFT_RIGHT, other);
    264     }
    265 
    266     public IntegerValue shiftLeftOf(SpecificIntegerValue other)
    267     {
    268         return new CompositeIntegerValue(other, CompositeIntegerValue.SHIFT_LEFT, this);
    269     }
    270 
    271     public IntegerValue shiftRightOf(SpecificIntegerValue other)
    272     {
    273         return new CompositeIntegerValue(other, CompositeIntegerValue.SHIFT_RIGHT, this);
    274     }
    275 
    276     public IntegerValue unsignedShiftRightOf(SpecificIntegerValue other)
    277     {
    278         return new CompositeIntegerValue(other, CompositeIntegerValue.UNSIGNED_SHIFT_RIGHT, this);
    279     }
    280 
    281     public LongValue shiftLeftOf(SpecificLongValue other)
    282     {
    283         return new CompositeLongValue(other, CompositeLongValue.SHIFT_LEFT, this);
    284     }
    285 
    286     public LongValue shiftRightOf(SpecificLongValue other)
    287     {
    288         return new CompositeLongValue(other, CompositeLongValue.SHIFT_RIGHT, this);
    289     }
    290 
    291     public LongValue unsignedShiftRightOf(SpecificLongValue other)
    292     {
    293         return new CompositeLongValue(other, CompositeLongValue.UNSIGNED_SHIFT_RIGHT, this);
    294     }
    295 
    296     public IntegerValue and(SpecificIntegerValue other)
    297     {
    298         return this.equals(other) ?
    299             this :
    300             new CompositeIntegerValue(other, CompositeIntegerValue.AND, this);
    301     }
    302 
    303     public IntegerValue or(SpecificIntegerValue other)
    304     {
    305         return this.equals(other) ?
    306             this :
    307             new CompositeIntegerValue(other, CompositeIntegerValue.OR, this);
    308     }
    309 
    310     public IntegerValue xor(SpecificIntegerValue other)
    311     {
    312         return this.equals(other) ?
    313             ParticularValueFactory.INTEGER_VALUE_0 :
    314             new CompositeIntegerValue(other, CompositeIntegerValue.XOR, this);
    315     }
    316 
    317     public int equal(SpecificIntegerValue other)
    318     {
    319         return this.equals(other) ? ALWAYS : MAYBE;
    320     }
    321 
    322     public int lessThan(SpecificIntegerValue other)
    323     {
    324         return this.equals(other) ? NEVER : MAYBE;
    325     }
    326 
    327     public int lessThanOrEqual(SpecificIntegerValue other)
    328     {
    329         return this.equals(other) ? ALWAYS : MAYBE;
    330     }
    331 
    332 
    333     // Implementations for Value.
    334 
    335     public boolean isSpecific()
    336     {
    337         return true;
    338     }
    339 
    340 
    341     // Implementations for Object.
    342 
    343     public boolean equals(Object object)
    344     {
    345         return object != null &&
    346                this.getClass() == object.getClass();
    347     }
    348 
    349 
    350     public int hashCode()
    351     {
    352         return this.getClass().hashCode();
    353     }
    354 }
    355