1b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato/* 2b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * ProGuard -- shrinking, optimization, obfuscation, and preverification 3b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * of Java bytecode. 4b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 59f606f95f03a75961498803e24bee6799a7c0885Ying Wang * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) 6b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 7b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This program is free software; you can redistribute it and/or modify it 8b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * under the terms of the GNU General Public License as published by the Free 9b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Software Foundation; either version 2 of the License, or (at your option) 10b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * any later version. 11b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 12b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This program is distributed in the hope that it will be useful, but WITHOUT 13b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * more details. 16b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 17b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * You should have received a copy of the GNU General Public License along 18b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * with this program; if not, write to the Free Software Foundation, Inc., 19b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 21b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopackage proguard.classfile.attribute.preverification; 22b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 23b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.*; 24b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.attribute.CodeAttribute; 25b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport proguard.classfile.attribute.preverification.visitor.StackMapFrameVisitor; 26b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 27b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato/** 28b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This abstract class represents a stack map frame. Specific types 29b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * of entries are subclassed from it. 30b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 31b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * @author Eric Lafortune 32b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 33b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopublic abstract class StackMapFrame implements VisitorAccepter 34b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato{ 35b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static final int SAME_ZERO_FRAME = 0; 36b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static final int SAME_ONE_FRAME = 64; 37b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static final int SAME_ONE_FRAME_EXTENDED = 247; 38b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static final int LESS_ZERO_FRAME = 248; 39b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static final int SAME_ZERO_FRAME_EXTENDED = 251; 40b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static final int MORE_ZERO_FRAME = 252; 41b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public static final int FULL_FRAME = 255; 42b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 43b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 44b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int u2offsetDelta; 45b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 46b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato /** 47b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * An extra field in which visitors can store information. 48b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 49b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public Object visitorInfo; 50b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 51b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 52b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 53b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato /** 54b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Returns the bytecode offset delta relative to the previous stack map 55b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * frame. 56b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 57b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int getOffsetDelta() 58b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 59b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return u2offsetDelta; 60b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 61b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 62b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 63b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Abstract methods to be implemented by extensions. 64b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 65b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato /** 66b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Returns the stack map frame tag that specifies the entry type. 67b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 68b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public abstract int getTag(); 69b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 70b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 71b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato /** 72b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Accepts the given visitor. 73b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 74b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public abstract void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor); 75b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 76b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 77b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementations for VisitorAccepter. 78b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 79b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public Object getVisitorInfo() 80b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 81b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return visitorInfo; 82b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 83b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 84b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public void setVisitorInfo(Object visitorInfo) 85b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 86b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this.visitorInfo = visitorInfo; 87b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 88b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 89b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 90b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementations for Object. 91b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 92b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public boolean equals(Object object) 93b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 94b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato if (object == null || 95b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this.getClass() != object.getClass()) 96b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 97b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return false; 98b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 99b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 100b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato StackMapFrame other = (StackMapFrame)object; 101b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 102b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return this.u2offsetDelta == other.u2offsetDelta; 103b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 104b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 105b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 106b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public int hashCode() 107b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 108b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return getClass().hashCode() ^ 109b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato u2offsetDelta; 110b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 111b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 112b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 113b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public String toString() 114b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 115b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato return "[" + u2offsetDelta + "] "; 116b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 117b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 118