Home | History | Annotate | Download | only in value
      1 /*
      2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
      3  *             of Java bytecode.
      4  *
      5  * Copyright (c) 2002-2009 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 import proguard.classfile.ClassConstants;
     24 
     25 /**
     26  * This class represents a partially evaluated float value.
     27  *
     28  * @author Eric Lafortune
     29  */
     30 public abstract class FloatValue extends Category1Value
     31 {
     32     /**
     33      * Returns the specific float value, if applicable.
     34      */
     35     public float value()
     36     {
     37         return 0f;
     38     }
     39 
     40 
     41     // Basic unary methods.
     42 
     43     /**
     44      * Returns the negated value of this FloatValue.
     45      */
     46     public abstract FloatValue negate();
     47 
     48     /**
     49      * Converts this FloatValue to an IntegerValue.
     50      */
     51     public abstract IntegerValue convertToInteger();
     52 
     53     /**
     54      * Converts this FloatValue to a LongValue.
     55      */
     56     public abstract LongValue convertToLong();
     57 
     58     /**
     59      * Converts this FloatValue to a DoubleValue.
     60      */
     61     public abstract DoubleValue convertToDouble();
     62 
     63 
     64     // Basic binary methods.
     65 
     66     /**
     67      * Returns the generalization of this FloatValue and the given other
     68      * FloatValue.
     69      */
     70     public abstract FloatValue generalize(FloatValue other);
     71 
     72 
     73     /**
     74      * Returns the sum of this FloatValue and the given FloatValue.
     75      */
     76     public abstract FloatValue add(FloatValue other);
     77 
     78     /**
     79      * Returns the difference of this FloatValue and the given FloatValue.
     80      */
     81     public abstract FloatValue subtract(FloatValue other);
     82 
     83     /**
     84      * Returns the difference of the given FloatValue and this FloatValue.
     85      */
     86     public abstract FloatValue subtractFrom(FloatValue other);
     87 
     88     /**
     89      * Returns the product of this FloatValue and the given FloatValue.
     90      */
     91     public abstract FloatValue multiply(FloatValue other);
     92 
     93     /**
     94      * Returns the quotient of this FloatValue and the given FloatValue.
     95      */
     96     public abstract FloatValue divide(FloatValue other);
     97 
     98     /**
     99      * Returns the quotient of the given FloatValue and this FloatValue.
    100      */
    101     public abstract FloatValue divideOf(FloatValue other);
    102 
    103     /**
    104      * Returns the remainder of this FloatValue divided by the given FloatValue.
    105      */
    106     public abstract FloatValue remainder(FloatValue other);
    107 
    108     /**
    109      * Returns the remainder of the given FloatValue divided by this FloatValue.
    110      */
    111     public abstract FloatValue remainderOf(FloatValue other);
    112 
    113     /**
    114      * Returns an IntegerValue with value -1, 0, or 1, if this FloatValue is
    115      * less than, equal to, or greater than the given FloatValue, respectively.
    116      */
    117     public abstract IntegerValue compare(FloatValue other);
    118 
    119 
    120     // Derived binary methods.
    121 
    122     /**
    123      * Returns an IntegerValue with value 1, 0, or -1, if this FloatValue is
    124      * less than, equal to, or greater than the given FloatValue, respectively.
    125      */
    126     public final IntegerValue compareReverse(FloatValue other)
    127     {
    128         return compare(other).negate();
    129     }
    130 
    131 
    132     // Similar binary methods, but this time with more specific arguments.
    133 
    134     /**
    135      * Returns the generalization of this FloatValue and the given other
    136      * SpecificFloatValue.
    137      */
    138     public FloatValue generalize(SpecificFloatValue other)
    139     {
    140         return generalize((FloatValue)other);
    141     }
    142 
    143 
    144     /**
    145      * Returns the sum of this FloatValue and the given SpecificFloatValue.
    146      */
    147     public FloatValue add(SpecificFloatValue other)
    148     {
    149         return add((FloatValue)other);
    150     }
    151 
    152     /**
    153      * Returns the difference of this FloatValue and the given SpecificFloatValue.
    154      */
    155     public FloatValue subtract(SpecificFloatValue other)
    156     {
    157         return subtract((FloatValue)other);
    158     }
    159 
    160     /**
    161      * Returns the difference of the given SpecificFloatValue and this FloatValue.
    162      */
    163     public FloatValue subtractFrom(SpecificFloatValue other)
    164     {
    165         return subtractFrom((FloatValue)other);
    166     }
    167 
    168     /**
    169      * Returns the product of this FloatValue and the given SpecificFloatValue.
    170      */
    171     public FloatValue multiply(SpecificFloatValue other)
    172     {
    173         return multiply((FloatValue)other);
    174     }
    175 
    176     /**
    177      * Returns the quotient of this FloatValue and the given SpecificFloatValue.
    178      */
    179     public FloatValue divide(SpecificFloatValue other)
    180     {
    181         return divide((FloatValue)other);
    182     }
    183 
    184     /**
    185      * Returns the quotient of the given SpecificFloatValue and this
    186      * FloatValue.
    187      */
    188     public FloatValue divideOf(SpecificFloatValue other)
    189     {
    190         return divideOf((FloatValue)other);
    191     }
    192 
    193     /**
    194      * Returns the remainder of this FloatValue divided by the given
    195      * SpecificFloatValue.
    196      */
    197     public FloatValue remainder(SpecificFloatValue other)
    198     {
    199         return remainder((FloatValue)other);
    200     }
    201 
    202     /**
    203      * Returns the remainder of the given SpecificFloatValue and this
    204      * FloatValue.
    205      */
    206     public FloatValue remainderOf(SpecificFloatValue other)
    207     {
    208         return remainderOf((FloatValue)other);
    209     }
    210 
    211     /**
    212      * Returns an IntegerValue with value -1, 0, or 1, if this FloatValue is
    213      * less than, equal to, or greater than the given SpecificFloatValue,
    214      * respectively.
    215      */
    216     public IntegerValue compare(SpecificFloatValue other)
    217     {
    218         return compare((FloatValue)other);
    219     }
    220 
    221 
    222     // Derived binary methods.
    223 
    224     /**
    225      * Returns an IntegerValue with value 1, 0, or -1, if this FloatValue is
    226      * less than, equal to, or greater than the given SpecificFloatValue,
    227      * respectively.
    228      */
    229     public final IntegerValue compareReverse(SpecificFloatValue other)
    230     {
    231         return compare(other).negate();
    232     }
    233 
    234 
    235     // Similar binary methods, but this time with particular arguments.
    236 
    237     /**
    238      * Returns the generalization of this FloatValue and the given other
    239      * ParticularFloatValue.
    240      */
    241     public FloatValue generalize(ParticularFloatValue other)
    242     {
    243         return generalize((SpecificFloatValue)other);
    244     }
    245 
    246 
    247     /**
    248      * Returns the sum of this FloatValue and the given ParticularFloatValue.
    249      */
    250     public FloatValue add(ParticularFloatValue other)
    251     {
    252         return add((SpecificFloatValue)other);
    253     }
    254 
    255     /**
    256      * Returns the difference of this FloatValue and the given ParticularFloatValue.
    257      */
    258     public FloatValue subtract(ParticularFloatValue other)
    259     {
    260         return subtract((SpecificFloatValue)other);
    261     }
    262 
    263     /**
    264      * Returns the difference of the given ParticularFloatValue and this FloatValue.
    265      */
    266     public FloatValue subtractFrom(ParticularFloatValue other)
    267     {
    268         return subtractFrom((SpecificFloatValue)other);
    269     }
    270 
    271     /**
    272      * Returns the product of this FloatValue and the given ParticularFloatValue.
    273      */
    274     public FloatValue multiply(ParticularFloatValue other)
    275     {
    276         return multiply((SpecificFloatValue)other);
    277     }
    278 
    279     /**
    280      * Returns the quotient of this FloatValue and the given ParticularFloatValue.
    281      */
    282     public FloatValue divide(ParticularFloatValue other)
    283     {
    284         return divide((SpecificFloatValue)other);
    285     }
    286 
    287     /**
    288      * Returns the quotient of the given ParticularFloatValue and this
    289      * FloatValue.
    290      */
    291     public FloatValue divideOf(ParticularFloatValue other)
    292     {
    293         return divideOf((SpecificFloatValue)other);
    294     }
    295 
    296     /**
    297      * Returns the remainder of this FloatValue divided by the given
    298      * ParticularFloatValue.
    299      */
    300     public FloatValue remainder(ParticularFloatValue other)
    301     {
    302         return remainder((SpecificFloatValue)other);
    303     }
    304 
    305     /**
    306      * Returns the remainder of the given ParticularFloatValue and this
    307      * FloatValue.
    308      */
    309     public FloatValue remainderOf(ParticularFloatValue other)
    310     {
    311         return remainderOf((SpecificFloatValue)other);
    312     }
    313 
    314     /**
    315      * Returns an IntegerValue with value -1, 0, or 1, if this FloatValue is
    316      * less than, equal to, or greater than the given ParticularFloatValue,
    317      * respectively.
    318      */
    319     public IntegerValue compare(ParticularFloatValue other)
    320     {
    321         return compare((SpecificFloatValue)other);
    322     }
    323 
    324 
    325     // Derived binary methods.
    326 
    327     /**
    328      * Returns an IntegerValue with value 1, 0, or -1, if this FloatValue is
    329      * less than, equal to, or greater than the given ParticularFloatValue,
    330      * respectively.
    331      */
    332     public final IntegerValue compareReverse(ParticularFloatValue other)
    333     {
    334         return compare(other).negate();
    335     }
    336 
    337 
    338     // Implementations for Value.
    339 
    340     public final FloatValue floatValue()
    341     {
    342         return this;
    343     }
    344 
    345     public final Value generalize(Value other)
    346     {
    347         return this.generalize(other.floatValue());
    348     }
    349 
    350     public final int computationalType()
    351     {
    352         return TYPE_FLOAT;
    353     }
    354 
    355     public final String internalType()
    356     {
    357         return String.valueOf(ClassConstants.INTERNAL_TYPE_FLOAT);
    358     }
    359 }
    360