• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.classfile.attribute.preverification;
22 
23 import proguard.classfile.*;
24 import proguard.classfile.attribute.CodeAttribute;
25 import proguard.classfile.attribute.preverification.visitor.*;
26 
27 /**
28  * This StackMapFrame represents a "same locals 1 stack item frame" or a
29  * "same locals 1 stack item frame extended".
30  *
31  * @author Eric Lafortune
32  */
33 public class SameOneFrame extends StackMapFrame
34 {
35     public VerificationType stackItem;
36 
37 
38     /**
39      * Creates an uninitialized SameOneFrame.
40      */
SameOneFrame()41     public SameOneFrame()
42     {
43     }
44 
45 
46     /**
47      * Creates a SameOneFrame with the given tag.
48      */
SameOneFrame(int tag)49     public SameOneFrame(int tag)
50     {
51         u2offsetDelta = tag - SAME_ONE_FRAME;
52     }
53 
54 
55     /**
56      * Creates a SameOneFrame with the given stack verification type.
57      */
SameOneFrame(VerificationType stackItem)58     public SameOneFrame(VerificationType stackItem)
59     {
60         this.stackItem = stackItem;
61     }
62 
63 
64     /**
65      * Applies the given verification type visitor to the stack item.
66      */
stackItemAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationTypeVisitor verificationTypeVisitor)67     public void stackItemAccept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationTypeVisitor verificationTypeVisitor)
68     {
69         stackItem.accept(clazz, method, codeAttribute, offset, verificationTypeVisitor);
70     }
71 
72 
73     // Implementations for StackMapFrame.
74 
getTag()75     public int getTag()
76     {
77         return u2offsetDelta < 64 ?
78             SAME_ONE_FRAME + u2offsetDelta :
79             SAME_ONE_FRAME_EXTENDED;
80     }
81 
82 
accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor)83     public void accept(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrameVisitor stackMapFrameVisitor)
84     {
85         stackMapFrameVisitor.visitSameOneFrame(clazz, method, codeAttribute, offset, this);
86     }
87 
88 
89     // Implementations for Object.
90 
equals(Object object)91     public boolean equals(Object object)
92     {
93         if (!super.equals(object))
94         {
95             return false;
96         }
97 
98         SameOneFrame other = (SameOneFrame)object;
99 
100         return this.u2offsetDelta == other.u2offsetDelta &&
101                this.stackItem.equals(other.stackItem);
102     }
103 
104 
hashCode()105     public int hashCode()
106     {
107         return super.hashCode() ^ stackItem.hashCode();
108     }
109 
110 
toString()111     public String toString()
112     {
113         return super.toString()+"Var: ..., Stack: ["+stackItem.toString()+"]";
114     }
115 }
116