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 */ 21 package proguard.evaluation.value; 22 23 import proguard.classfile.Clazz; 24 25 /** 26 * This ReferenceValue represents a partially evaluated array. It has an array 27 * length and possibly array values (up to a fixed maximum number). It is not 28 * immutable. 29 * 30 * @author Eric Lafortune 31 */ 32 class ArrayReferenceValue extends TypedReferenceValue 33 { 34 protected final IntegerValue arrayLength; 35 36 37 /** 38 * Creates a new ArrayReferenceValue. 39 */ ArrayReferenceValue(String type, Clazz referencedClass, IntegerValue arrayLength)40 public ArrayReferenceValue(String type, 41 Clazz referencedClass, 42 IntegerValue arrayLength) 43 { 44 super(type, referencedClass, false); 45 46 this.arrayLength = arrayLength; 47 } 48 49 50 // Implementations for ReferenceValue. 51 arrayLength(ValueFactory valueFactory)52 public IntegerValue arrayLength(ValueFactory valueFactory) 53 { 54 return arrayLength; 55 } 56 57 58 // Implementations of binary methods of ReferenceValue. 59 generalize(ReferenceValue other)60 public ReferenceValue generalize(ReferenceValue other) 61 { 62 return other.generalize(this); 63 } 64 65 equal(ReferenceValue other)66 public int equal(ReferenceValue other) 67 { 68 return other.equal(this); 69 } 70 71 72 // // Implementations of binary ReferenceValue methods with 73 // // IdentifiedReferenceValue arguments. 74 // 75 // public ReferenceValue generalize(IdentifiedReferenceValue other) 76 // { 77 // return generalize((TypedReferenceValue)other); 78 // } 79 // 80 // 81 // public int equal(IdentifiedReferenceValue other) 82 // { 83 // return equal((TypedReferenceValue)other); 84 // } 85 86 87 // Implementations of binary ReferenceValue methods with 88 // ArrayReferenceValue arguments. 89 generalize(ArrayReferenceValue other)90 public ReferenceValue generalize(ArrayReferenceValue other) 91 { 92 return 93 this.equals(other) ? this : 94 this.type != null && 95 this.type.equals(other.type) && 96 this.referencedClass == other.referencedClass ? new ArrayReferenceValue(this.type, 97 this.referencedClass, 98 this.arrayLength.generalize(other.arrayLength)) : 99 generalize((TypedReferenceValue)other); 100 } 101 102 equal(ArrayReferenceValue other)103 public int equal(ArrayReferenceValue other) 104 { 105 if (this.arrayLength.equal(other.arrayLength) == NEVER) 106 { 107 return NEVER; 108 } 109 110 return equal((TypedReferenceValue)other); 111 } 112 113 114 // // Implementations of binary ReferenceValue methods with 115 // // IdentifiedArrayReferenceValue arguments. 116 // 117 // public ReferenceValue generalize(IdentifiedArrayReferenceValue other) 118 // { 119 // return generalize((ArrayReferenceValue)other); 120 // } 121 // 122 // 123 // public int equal(IdentifiedArrayReferenceValue other) 124 // { 125 // return equal((ArrayReferenceValue)other); 126 // } 127 // 128 // 129 // // Implementations of binary ReferenceValue methods with 130 // // DetailedArrayReferenceValue arguments. 131 // 132 // public ReferenceValue generalize(DetailedArrayReferenceValue other) 133 // { 134 // return generalize((IdentifiedArrayReferenceValue)other); 135 // } 136 // 137 // 138 // public int equal(DetailedArrayReferenceValue other) 139 // { 140 // return equal((IdentifiedArrayReferenceValue)other); 141 // } 142 143 144 // Implementations for Object. 145 equals(Object object)146 public boolean equals(Object object) 147 { 148 return this == object || 149 super.equals(object) && 150 this.arrayLength.equals(((ArrayReferenceValue)object).arrayLength); 151 } 152 153 hashCode()154 public int hashCode() 155 { 156 return super.hashCode() ^ 157 arrayLength.hashCode(); 158 } 159 160 toString()161 public String toString() 162 { 163 return super.toString() + '['+arrayLength+']'; 164 } 165 } 166