summaryrefslogtreecommitdiffstats
path: root/src/proguard/evaluation/value/ReferenceValue.java
blob: 1f87382082ddc79b7beecdfcf03d47d14c4a5d72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/*
 * ProGuard -- shrinking, optimization, obfuscation, and preverification
 *             of Java bytecode.
 *
 * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
package proguard.evaluation.value;

import proguard.classfile.Clazz;

/**
 * This class represents a partially evaluated reference value.
 *
 * @author Eric Lafortune
 */
public abstract class ReferenceValue extends Category1Value
{
    /**
     * Returns the type.
     */
    public abstract String getType();
;

    /**
     * Returns the class that is referenced by the type.
     */
    public abstract Clazz getReferencedClass();


    // Basic unary methods.

    /**
     * Returns whether the type is <code>null</code>.
     */
    public abstract int isNull();


    /**
     * Returns whether the type is an instance of the given type.
     */
    public abstract int instanceOf(String otherType, Clazz otherReferencedClass);


    /**
     * Returns a generalization of this ReferenceValue that may be null,
     * depending on the flag.
     */
    public abstract ReferenceValue generalizeMayBeNull(boolean mayBeNull);


    /**
     * Returns the length of the array, assuming this type is an array.
     */
    public IntegerValue arrayLength(ValueFactory valueFactory)
    {
        return valueFactory.createIntegerValue();
    }


    /**
     * Returns the value of the array at the given index, assuming this type
     * is an integer array.
     */
    public IntegerValue integerArrayLoad(IntegerValue indexValue, ValueFactory valueFactory)
    {
        return valueFactory.createIntegerValue();
    }


    /**
     * Returns the value of the array at the given index, assuming this type
     * is an long array.
     */
    public LongValue longArrayLoad(IntegerValue indexValue, ValueFactory valueFactory)
    {
        return valueFactory.createLongValue();
    }


    /**
     * Returns the value of the array at the given index, assuming this type
     * is an float array.
     */
    public FloatValue floatArrayLoad(IntegerValue indexValue, ValueFactory valueFactory)
    {
        return valueFactory.createFloatValue();
    }


    /**
     * Returns the value of the array at the given index, assuming this type
     * is an double array.
     */
    public DoubleValue doubleArrayLoad(IntegerValue indexValue, ValueFactory valueFactory)
    {
        return valueFactory.createDoubleValue();
    }


    /**
     * Returns the value of the array at the given index, assuming this type
     * is a reference array.
     */
    public abstract ReferenceValue referenceArrayLoad(IntegerValue indexValue, ValueFactory valueFactory);


    /**
     * Stores the given value at the given index in the given array, assuming
     * this type is an array.
     */
    public void arrayStore(IntegerValue indexValue, Value value)
    {
    }


    // Basic binary methods.

    /**
     * Returns the generalization of this ReferenceValue and the given other
     * ReferenceValue.
     */
    public abstract ReferenceValue generalize(ReferenceValue other);


    /**
     * Returns whether this ReferenceValue is equal to the given other
     * ReferenceValue.
     * @return <code>NEVER</code>, <code>MAYBE</code>, or <code>ALWAYS</code>.
     */
    public abstract int equal(ReferenceValue other);


    // Derived unary methods.

    /**
     * Returns whether this ReferenceValue is not <code>null</code>.
     * @return <code>NEVER</code>, <code>MAYBE</code>, or <code>ALWAYS</code>.
     */
    public final int isNotNull()
    {
        return -isNull();
    }


    // Derived binary methods.

    /**
     * Returns whether this ReferenceValue and the given ReferenceValue are different.
     * @return <code>NEVER</code>, <code>MAYBE</code>, or <code>ALWAYS</code>.
     */
    public final int notEqual(ReferenceValue other)
    {
        return -equal(other);
    }


    // Similar binary methods, but this time with typed reference arguments.

    /**
     * Returns the generalization of this ReferenceValue and the given other
     * TypedReferenceValue.
     */
    public ReferenceValue generalize(TypedReferenceValue other)
    {
        return generalize((ReferenceValue)other);
    }


    /**
     * Returns whether this ReferenceValue is equal to the given other
     * TypedReferenceValue.
     * @return <code>NEVER</code>, <code>MAYBE</code>, or <code>ALWAYS</code>.
     */
    public int equal(TypedReferenceValue other)
    {
        return equal((ReferenceValue)other);
    }


    // Similar binary methods, but this time with identified reference
    // arguments.

    /**
     * Returns the generalization of this ReferenceValue and the given other
     * IdentifiedReferenceValue.
     */
    public ReferenceValue generalize(IdentifiedReferenceValue other)
    {
        return generalize((TypedReferenceValue)other);
    }


    /**
     * Returns whether this ReferenceValue is equal to the given other
     * IdentifiedReferenceValue.
     * @return <code>NEVER</code>, <code>MAYBE</code>, or <code>ALWAYS</code>.
     */
    public int equal(IdentifiedReferenceValue other)
    {
        return equal((TypedReferenceValue)other);
    }


    // Similar binary methods, but this time with array reference arguments.

    /**
     * Returns the generalization of this ReferenceValue and the given other
     * ArrayReferenceValue.
     */
    public ReferenceValue generalize(ArrayReferenceValue other)
    {
        return generalize((TypedReferenceValue)other);
    }


    /**
     * Returns whether this ReferenceValue is equal to the given other
     * ArrayReferenceValue.
     * @return <code>NEVER</code>, <code>MAYBE</code>, or <code>ALWAYS</code>.
     */
    public int equal(ArrayReferenceValue other)
    {
        return equal((TypedReferenceValue)other);
    }


    // Similar binary methods, but this time with identified array reference
    // arguments.

    /**
     * Returns the generalization of this ReferenceValue and the given other
     * IdentifiedArrayReferenceValue.
     */
    public ReferenceValue generalize(IdentifiedArrayReferenceValue other)
    {
        return generalize((ArrayReferenceValue)other);
    }


    /**
     * Returns whether this ReferenceValue is equal to the given other
     * IdentifiedArrayReferenceValue.
     * @return <code>NEVER</code>, <code>MAYBE</code>, or <code>ALWAYS</code>.
     */
    public int equal(IdentifiedArrayReferenceValue other)
    {
        return equal((ArrayReferenceValue)other);
    }


    // Similar binary methods, but this time with detailed array reference
    // arguments.

    /**
     * Returns the generalization of this ReferenceValue and the given other
     * DetailedArrayReferenceValue.
     */
    public ReferenceValue generalize(DetailedArrayReferenceValue other)
    {
        return generalize((IdentifiedArrayReferenceValue)other);
    }


    /**
     * Returns whether this ReferenceValue is equal to the given other
     * DetailedArrayReferenceValue.
     * @return <code>NEVER</code>, <code>MAYBE</code>, or <code>ALWAYS</code>.
     */
    public int equal(DetailedArrayReferenceValue other)
    {
        return equal((IdentifiedArrayReferenceValue)other);
    }


    // Implementations for Value.

    public final ReferenceValue referenceValue()
    {
        return this;
    }

    public final Value generalize(Value other)
    {
        return this.generalize(other.referenceValue());
    }

    public final int computationalType()
    {
        return TYPE_REFERENCE;
    }
}