1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2014 Eric Lafortune (eric@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 */
21package proguard.evaluation.value;
22
23import proguard.classfile.*;
24
25/**
26 * This particular value factory attaches a unique ID to any unknown values.
27 *
28 * @author Eric Lafortune
29 */
30public class IdentifiedValueFactory
31extends      ParticularValueFactory
32{
33    protected int integerID;
34    protected int longID;
35    protected int floatID;
36    protected int doubleID;
37    protected int referenceID;
38
39
40    // Implementations for ValueFactory.
41
42    public IntegerValue createIntegerValue()
43    {
44        return new IdentifiedIntegerValue(this, integerID++);
45    }
46
47
48    public LongValue createLongValue()
49    {
50        return new IdentifiedLongValue(this, longID++);
51    }
52
53
54    public FloatValue createFloatValue()
55    {
56        return new IdentifiedFloatValue(this, floatID++);
57    }
58
59
60    public DoubleValue createDoubleValue()
61    {
62        return new IdentifiedDoubleValue(this, doubleID++);
63    }
64
65
66    public ReferenceValue createReferenceValue(String  type,
67                                               Clazz   referencedClass,
68                                               boolean mayBeNull)
69    {
70        return type == null ?
71            REFERENCE_VALUE_NULL :
72            new IdentifiedReferenceValue(type,
73                                         referencedClass,
74                                         mayBeNull,
75                                         this,
76                                         referenceID++);
77    }
78
79
80    public ReferenceValue createArrayReferenceValue(String       type,
81                                                    Clazz        referencedClass,
82                                                    IntegerValue arrayLength)
83    {
84        return type == null ?
85            REFERENCE_VALUE_NULL :
86            new IdentifiedArrayReferenceValue(ClassConstants.TYPE_ARRAY + type,
87                                              referencedClass,
88                                              arrayLength,
89                                              this,
90                                              referenceID++);
91    }
92}