1 // ASM: a very small and fast Java bytecode manipulation framework 2 // Copyright (c) 2000-2011 INRIA, France Telecom 3 // All rights reserved. 4 // 5 // Redistribution and use in source and binary forms, with or without 6 // modification, are permitted provided that the following conditions 7 // are met: 8 // 1. Redistributions of source code must retain the above copyright 9 // notice, this list of conditions and the following disclaimer. 10 // 2. Redistributions in binary form must reproduce the above copyright 11 // notice, this list of conditions and the following disclaimer in the 12 // documentation and/or other materials provided with the distribution. 13 // 3. Neither the name of the copyright holders nor the names of its 14 // contributors may be used to endorse or promote products derived from 15 // this software without specific prior written permission. 16 // 17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 27 // THE POSSIBILITY OF SUCH DAMAGE. 28 package org.objectweb.asm.tree.analysis; 29 30 import java.util.Set; 31 import org.objectweb.asm.tree.AbstractInsnNode; 32 33 /** 34 * A {@link Value} which keeps track of the bytecode instructions that can produce it. 35 * 36 * @author Eric Bruneton 37 */ 38 public class SourceValue implements Value { 39 40 /** 41 * The size of this value, in 32 bits words. This size is 1 for byte, boolean, char, short, int, 42 * float, object and array types, and 2 for long and double. 43 */ 44 public final int size; 45 46 /** 47 * The instructions that can produce this value. For example, for the Java code below, the 48 * instructions that can produce the value of {@code i} at line 5 are the two ISTORE instructions 49 * at line 1 and 3: 50 * 51 * <pre> 52 * 1: i = 0; 53 * 2: if (...) { 54 * 3: i = 1; 55 * 4: } 56 * 5: return i; 57 * </pre> 58 */ 59 public final Set<AbstractInsnNode> insns; 60 61 /** 62 * Constructs a new {@link SourceValue}. 63 * 64 * @param size the size of this value, in 32 bits words. This size is 1 for byte, boolean, char, 65 * short, int, float, object and array types, and 2 for long and double. 66 */ SourceValue(final int size)67 public SourceValue(final int size) { 68 this(size, new SmallSet<>()); 69 } 70 71 /** 72 * Constructs a new {@link SourceValue}. 73 * 74 * @param size the size of this value, in 32 bits words. This size is 1 for byte, boolean, char, 75 * short, int, float, object and array types, and 2 for long and double. 76 * @param insnNode an instruction that can produce this value. 77 */ SourceValue(final int size, final AbstractInsnNode insnNode)78 public SourceValue(final int size, final AbstractInsnNode insnNode) { 79 this.size = size; 80 this.insns = new SmallSet<>(insnNode); 81 } 82 83 /** 84 * Constructs a new {@link SourceValue}. 85 * 86 * @param size the size of this value, in 32 bits words. This size is 1 for byte, boolean, char, 87 * short, int, float, object and array types, and 2 for long and double. 88 * @param insnSet the instructions that can produce this value. 89 */ SourceValue(final int size, final Set<AbstractInsnNode> insnSet)90 public SourceValue(final int size, final Set<AbstractInsnNode> insnSet) { 91 this.size = size; 92 this.insns = insnSet; 93 } 94 95 /** 96 * Returns the size of this value. 97 * 98 * @return the size of this value, in 32 bits words. This size is 1 for byte, boolean, char, 99 * short, int, float, object and array types, and 2 for long and double. 100 */ 101 @Override getSize()102 public int getSize() { 103 return size; 104 } 105 106 @Override equals(final Object value)107 public boolean equals(final Object value) { 108 if (!(value instanceof SourceValue)) { 109 return false; 110 } 111 SourceValue sourceValue = (SourceValue) value; 112 return size == sourceValue.size && insns.equals(sourceValue.insns); 113 } 114 115 @Override hashCode()116 public int hashCode() { 117 return insns.hashCode(); 118 } 119 } 120