Home | History | Annotate | Download | only in value
      1 /*
      2  * ProGuard -- shrinking, optimization, obfuscation, and preverification
      3  *             of Java bytecode.
      4  *
      5  * Copyright (c) 2002-2013 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 abstract class represents a partially evaluated value.
     25  *
     26  * @author Eric Lafortune
     27  */
     28 public abstract class Value
     29 {
     30     public static final int NEVER  = -1;
     31     public static final int MAYBE  = 0;
     32     public static final int ALWAYS = 1;
     33 
     34     public static final int TYPE_INTEGER            = 1;
     35     public static final int TYPE_LONG               = 2;
     36     public static final int TYPE_FLOAT              = 3;
     37     public static final int TYPE_DOUBLE             = 4;
     38     public static final int TYPE_REFERENCE          = 5;
     39     public static final int TYPE_INSTRUCTION_OFFSET = 6;
     40     public static final int TYPE_TOP                = 7;
     41 
     42 
     43     /**
     44      * Returns this Value as a Category1Value.
     45      */
     46     public Category1Value category1Value()
     47     {
     48         throw new IllegalArgumentException("Value is not a Category 1 value [" + this.getClass().getName() + "]");
     49     }
     50 
     51     /**
     52      * Returns this Value as a Category2Value.
     53      */
     54     public Category2Value category2Value()
     55     {
     56         throw new IllegalArgumentException("Value is not a Category 2 value [" + this.getClass().getName() + "]");
     57     }
     58 
     59 
     60     /**
     61      * Returns this Value as an IntegerValue.
     62      */
     63     public IntegerValue integerValue()
     64     {
     65         throw new IllegalArgumentException("Value is not an integer value [" + this.getClass().getName() + "]");
     66     }
     67 
     68     /**
     69      * Returns this Value as a LongValue.
     70      */
     71     public LongValue longValue()
     72     {
     73         throw new IllegalArgumentException("Value is not a long value [" + this.getClass().getName() + "]");
     74     }
     75 
     76     /**
     77      * Returns this Value as a FloatValue.
     78      */
     79     public FloatValue floatValue()
     80     {
     81         throw new IllegalArgumentException("Value is not a float value [" + this.getClass().getName() + "]");
     82     }
     83 
     84     /**
     85      * Returns this Value as a DoubleValue.
     86      */
     87     public DoubleValue doubleValue()
     88     {
     89         throw new IllegalArgumentException("Value is not a double value [" + this.getClass().getName() + "]");
     90     }
     91 
     92     /**
     93      * Returns this Value as a ReferenceValue.
     94      */
     95     public ReferenceValue referenceValue()
     96     {
     97         throw new IllegalArgumentException("Value is not a reference value [" + this.getClass().getName() + "]");
     98     }
     99 
    100     /**
    101      * Returns this Value as an InstructionOffsetValue.
    102      */
    103     public InstructionOffsetValue instructionOffsetValue()
    104     {
    105         throw new IllegalArgumentException("Value is not an instruction offset value [" + this.getClass().getName() + "]");
    106     }
    107 
    108 
    109     /**
    110      * Returns whether this Value represents a single specific (but possibly
    111      * unknown) value.
    112      */
    113     public boolean isSpecific()
    114     {
    115         return false;
    116     }
    117 
    118 
    119     /**
    120      * Returns whether this Value represents a single particular (known)
    121      * value.
    122      */
    123     public boolean isParticular()
    124     {
    125         return false;
    126     }
    127 
    128 
    129     /**
    130      * Returns the generalization of this Value and the given other Value.
    131      */
    132     public abstract Value generalize(Value other);
    133 
    134 
    135     /**
    136      * Returns whether the computational type of this Value is a category 2 type.
    137      * This means that it takes up the space of two category 1 types on the
    138      * stack, for instance.
    139      */
    140     public abstract boolean isCategory2();
    141 
    142 
    143     /**
    144      * Returns the computational type of this Value.
    145      * @return <code>TYPE_INTEGER</code>,
    146      *         <code>TYPE_LONG</code>,
    147      *         <code>TYPE_FLOAT</code>,
    148      *         <code>TYPE_DOUBLE</code>,
    149      *         <code>TYPE_REFERENCE</code>, or
    150      *         <code>TYPE_INSTRUCTION_OFFSET</code>.
    151      */
    152     public abstract int computationalType();
    153 
    154 
    155     /**
    156      * Returns the internal type of this Value.
    157      * @return <code>ClassConstants.INTERNAL_TYPE_BOOLEAN</code>,
    158      *         <code>ClassConstants.INTERNAL_TYPE_BYTE</code>,
    159      *         <code>ClassConstants.INTERNAL_TYPE_CHAR</code>,
    160      *         <code>ClassConstants.INTERNAL_TYPE_SHORT</code>,
    161      *         <code>ClassConstants.INTERNAL_TYPE_INT</code>,
    162      *         <code>ClassConstants.INTERNAL_TYPE_LONG</code>,
    163      *         <code>ClassConstants.INTERNAL_TYPE_FLOAT</code>,
    164      *         <code>ClassConstants.INTERNAL_TYPE_DOUBLE</code>,
    165      *         <code>ClassConstants.INTERNAL_TYPE_CLASS_START ... ClassConstants.INTERNAL_TYPE_CLASS_END</code>, or
    166      *         an array type containing any of these types (always as String).
    167      */
    168     public abstract String internalType();
    169 }
    170