01: /*
02: * ProGuard -- shrinking, optimization, obfuscation, and preverification
03: * of Java bytecode.
04: *
05: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
06: *
07: * This program is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU General Public License as published by the Free
09: * 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 class provides methods to create and reuse IntegerValue objects.
25: *
26: * @author Eric Lafortune
27: */
28: public class SpecificValueFactory extends ValueFactory {
29: // Shared copies of Value objects, to avoid creating a lot of objects.
30: static final IntegerValue INTEGER_VALUE_M1 = new SpecificIntegerValue(
31: -1);
32: static final IntegerValue INTEGER_VALUE_0 = new SpecificIntegerValue(
33: 0);
34: static final IntegerValue INTEGER_VALUE_1 = new SpecificIntegerValue(
35: 1);
36: static final IntegerValue INTEGER_VALUE_2 = new SpecificIntegerValue(
37: 2);
38: static final IntegerValue INTEGER_VALUE_3 = new SpecificIntegerValue(
39: 3);
40: static final IntegerValue INTEGER_VALUE_4 = new SpecificIntegerValue(
41: 4);
42: static final IntegerValue INTEGER_VALUE_5 = new SpecificIntegerValue(
43: 5);
44: static final LongValue LONG_VALUE_0 = new SpecificLongValue(0);
45: static final LongValue LONG_VALUE_1 = new SpecificLongValue(1);
46: static final FloatValue FLOAT_VALUE_0 = new SpecificFloatValue(0.0f);
47: static final FloatValue FLOAT_VALUE_1 = new SpecificFloatValue(1.0f);
48: static final FloatValue FLOAT_VALUE_2 = new SpecificFloatValue(2.0f);
49: static final DoubleValue DOUBLE_VALUE_0 = new SpecificDoubleValue(
50: 0.0);
51: static final DoubleValue DOUBLE_VALUE_1 = new SpecificDoubleValue(
52: 1.0);
53:
54: // Implementations for ValueFactory.
55:
56: public IntegerValue createIntegerValue(int value) {
57: switch (value) {
58: case -1:
59: return INTEGER_VALUE_M1;
60: case 0:
61: return INTEGER_VALUE_0;
62: case 1:
63: return INTEGER_VALUE_1;
64: case 2:
65: return INTEGER_VALUE_2;
66: case 3:
67: return INTEGER_VALUE_3;
68: case 4:
69: return INTEGER_VALUE_4;
70: case 5:
71: return INTEGER_VALUE_5;
72: default:
73: return new SpecificIntegerValue(value);
74: }
75: }
76:
77: public LongValue createLongValue(long value) {
78: return value == 0 ? LONG_VALUE_0 : value == 1 ? LONG_VALUE_1
79: : new SpecificLongValue(value);
80: }
81:
82: public FloatValue createFloatValue(float value) {
83: return value == 0.0f ? FLOAT_VALUE_0
84: : value == 1.0f ? FLOAT_VALUE_1
85: : value == 2.0f ? FLOAT_VALUE_2
86: : new SpecificFloatValue(value);
87: }
88:
89: public DoubleValue createDoubleValue(double value) {
90: return value == 0.0 ? DOUBLE_VALUE_0
91: : value == 1.0 ? DOUBLE_VALUE_1
92: : new SpecificDoubleValue(value);
93: }
94: }
|