001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
015: * more details.
016: *
017: * You should have received a copy of the GNU General Public License along
018: * with this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.evaluation.value;
022:
023: /**
024: * This abstract class represents a partially evaluated value.
025: *
026: * @author Eric Lafortune
027: */
028: public abstract class Value {
029: public static final int NEVER = -1;
030: public static final int MAYBE = 0;
031: public static final int ALWAYS = 1;
032:
033: public static final int TYPE_INTEGER = 1;
034: public static final int TYPE_LONG = 2;
035: public static final int TYPE_FLOAT = 3;
036: public static final int TYPE_DOUBLE = 4;
037: public static final int TYPE_REFERENCE = 5;
038: public static final int TYPE_INSTRUCTION_OFFSET = 6;
039: public static final int TYPE_TOP = 7;
040:
041: /**
042: * Returns this Value as a Category1Value.
043: */
044: public Category1Value category1Value() {
045: throw new IllegalArgumentException(
046: "Value is not a Category 1 value ["
047: + this .getClass().getName() + "]");
048: }
049:
050: /**
051: * Returns this Value as a Category2Value.
052: */
053: public Category2Value category2Value() {
054: throw new IllegalArgumentException(
055: "Value is not a Category 2 value ["
056: + this .getClass().getName() + "]");
057: }
058:
059: /**
060: * Returns this Value as an IntegerValue.
061: */
062: public IntegerValue integerValue() {
063: throw new IllegalArgumentException(
064: "Value is not an integer value ["
065: + this .getClass().getName() + "]");
066: }
067:
068: /**
069: * Returns this Value as a LongValue.
070: */
071: public LongValue longValue() {
072: throw new IllegalArgumentException(
073: "Value is not a long value ["
074: + this .getClass().getName() + "]");
075: }
076:
077: /**
078: * Returns this Value as a FloatValue.
079: */
080: public FloatValue floatValue() {
081: throw new IllegalArgumentException(
082: "Value is not a float value ["
083: + this .getClass().getName() + "]");
084: }
085:
086: /**
087: * Returns this Value as a DoubleValue.
088: */
089: public DoubleValue doubleValue() {
090: throw new IllegalArgumentException(
091: "Value is not a double value ["
092: + this .getClass().getName() + "]");
093: }
094:
095: /**
096: * Returns this Value as a ReferenceValue.
097: */
098: public ReferenceValue referenceValue() {
099: throw new IllegalArgumentException(
100: "Value is not a reference value ["
101: + this .getClass().getName() + "]");
102: }
103:
104: /**
105: * Returns this Value as a InstructionOffsetValue.
106: */
107: public InstructionOffsetValue instructionOffsetValue() {
108: throw new IllegalArgumentException(
109: "Value is not an instruction offset value ["
110: + this .getClass().getName() + "]");
111: }
112:
113: /**
114: * Returns whether this Value represents a single specific value.
115: */
116: public boolean isSpecific() {
117: return false;
118: }
119:
120: /**
121: * Returns the generalization of this Value and the given other Value.
122: */
123: public abstract Value generalize(Value other);
124:
125: /**
126: * Returns whether the computational type of this Value is a category 2 type.
127: * This means that it takes up the space of two category 1 types on the
128: * stack, for instance.
129: */
130: public abstract boolean isCategory2();
131:
132: /**
133: * Returns the computational type of this Value.
134: * @return <code>TYPE_INTEGER</code>,
135: * <code>TYPE_LONG</code>,
136: * <code>TYPE_FLOAT</code>,
137: * <code>TYPE_DOUBLE</code>,
138: * <code>TYPE_REFERENCE</code>, or
139: * <code>TYPE_INSTRUCTION_OFFSET</code>.
140: */
141: public abstract int computationalType();
142:
143: /**
144: * Returns the internal type of this Value.
145: * @return <code>ClassConstants.INTERNAL_TYPE_BOOLEAN</code>,
146: * <code>ClassConstants.INTERNAL_TYPE_BYTE</code>,
147: * <code>ClassConstants.INTERNAL_TYPE_CHAR</code>,
148: * <code>ClassConstants.INTERNAL_TYPE_SHORT</code>,
149: * <code>ClassConstants.INTERNAL_TYPE_INT</code>,
150: * <code>ClassConstants.INTERNAL_TYPE_LONG</code>,
151: * <code>ClassConstants.INTERNAL_TYPE_FLOAT</code>,
152: * <code>ClassConstants.INTERNAL_TYPE_DOUBLE</code>,
153: * <code>ClassConstants.INTERNAL_TYPE_CLASS_START ... ClassConstants.INTERNAL_TYPE_CLASS_END</code>, or
154: * an array type containing any of these types (always as String).
155: */
156: public abstract String internalType();
157: }
|