1/*
2 * ProGuard -- shrinking, optimization, obfuscation, and preverification
3 *             of Java bytecode.
4 *
5 * Copyright (c) 2002-2013 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
23/**
24 * This IntegerValue represents the result of a binary operation on two integer
25 * values.
26 *
27 * @author Eric Lafortune
28 */
29final class CompositeIntegerValue extends SpecificIntegerValue
30{
31    public static final byte ADD                  = '+';
32    public static final byte SUBTRACT             = '-';
33    public static final byte MULTIPLY             = '*';
34    public static final byte DIVIDE               = '/';
35    public static final byte REMAINDER            = '%';
36    public static final byte SHIFT_LEFT           = '<';
37    public static final byte SHIFT_RIGHT          = '>';
38    public static final byte UNSIGNED_SHIFT_RIGHT = '}';
39    public static final byte AND                  = '&';
40    public static final byte OR                   = '|';
41    public static final byte XOR                  = '^';
42
43
44    private final IntegerValue integerValue1;
45    private final byte         operation;
46    private final IntegerValue integerValue2;
47
48
49    /**
50     * Creates a new composite integer value of the two given integer values
51     * and the given operation.
52     */
53    public CompositeIntegerValue(IntegerValue integerValue1,
54                                 byte         operation,
55                                 IntegerValue integerValue2)
56    {
57        this.integerValue1 = integerValue1;
58        this.operation     = operation;
59        this.integerValue2 = integerValue2;
60    }
61
62
63    // Implementations for Object.
64
65    public boolean equals(Object object)
66    {
67        return this == object ||
68               super.equals(object) &&
69               this.integerValue1.equals(((CompositeIntegerValue)object).integerValue1) &&
70               this.operation         == ((CompositeIntegerValue)object).operation      &&
71               this.integerValue2.equals(((CompositeIntegerValue)object).integerValue2);
72    }
73
74
75    public int hashCode()
76    {
77        return super.hashCode() ^
78               integerValue1.hashCode() ^
79               integerValue2.hashCode();
80    }
81
82
83    public String toString()
84    {
85        return "("+integerValue1+((char)operation)+integerValue2+")";
86    }
87}