001: /*
002: * ProGuard -- shrinking, optimization, obfuscation, and preverification
003: * of Java bytecode.
004: *
005: * Copyright (c) 2002-2007 Eric Lafortune (eric@graphics.cornell.edu)
006: *
007: * This library is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the Free
009: * Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This library is distributed in the hope that it will be useful, but WITHOUT
013: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public License
018: * along with this library; if not, write to the Free Software Foundation,
019: * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: package proguard.classfile.attribute.preverification;
022:
023: import proguard.classfile.*;
024: import proguard.classfile.attribute.CodeAttribute;
025: import proguard.classfile.attribute.preverification.visitor.*;
026:
027: /**
028: * This StackMapFrame represents a "full frame".
029: *
030: * @author Eric Lafortune
031: */
032: public class FullFrame extends StackMapFrame {
033: public int variablesCount;
034: public VerificationType[] variables;
035: public int stackCount;
036: public VerificationType[] stack;
037:
038: /**
039: * Creates an uninitialized FullFrame.
040: */
041: public FullFrame() {
042: }
043:
044: /**
045: * Creates a FullFrame with the given variables and stack.
046: */
047: public FullFrame(int offsetDelta, VerificationType[] variables,
048: VerificationType[] stack) {
049: this (offsetDelta, variables.length, variables, stack.length,
050: stack);
051: }
052:
053: /**
054: * Creates a FullFrame with the given variables and stack.
055: */
056: public FullFrame(int offsetDelta, int variablesCount,
057: VerificationType[] variables, int stackCount,
058: VerificationType[] stack) {
059: this .u2offsetDelta = offsetDelta;
060: this .variablesCount = variablesCount;
061: this .variables = variables;
062: this .stackCount = stackCount;
063: this .stack = stack;
064: }
065:
066: /**
067: * Applies the given verification type visitor to all variables.
068: */
069: public void variablesAccept(Clazz clazz, Method method,
070: CodeAttribute codeAttribute, int offset,
071: VerificationTypeVisitor verificationTypeVisitor) {
072: for (int index = 0; index < variablesCount; index++) {
073: variables[index].variablesAccept(clazz, method,
074: codeAttribute, offset, index,
075: verificationTypeVisitor);
076: }
077: }
078:
079: /**
080: * Applies the given verification type visitor to all stack.
081: */
082: public void stackAccept(Clazz clazz, Method method,
083: CodeAttribute codeAttribute, int offset,
084: VerificationTypeVisitor verificationTypeVisitor) {
085: for (int index = 0; index < stackCount; index++) {
086: stack[index].stackAccept(clazz, method, codeAttribute,
087: offset, index, verificationTypeVisitor);
088: }
089: }
090:
091: // Implementations for StackMapFrame.
092:
093: public int getTag() {
094: return FULL_FRAME;
095: }
096:
097: public void accept(Clazz clazz, Method method,
098: CodeAttribute codeAttribute, int offset,
099: StackMapFrameVisitor stackMapFrameVisitor) {
100: stackMapFrameVisitor.visitFullFrame(clazz, method,
101: codeAttribute, offset, this );
102: }
103:
104: // Implementations for Object.
105:
106: public boolean equals(Object object) {
107: if (!super .equals(object)) {
108: return false;
109: }
110:
111: FullFrame other = (FullFrame) object;
112:
113: if (this .u2offsetDelta != other.u2offsetDelta
114: || this .variablesCount != other.variablesCount
115: || this .stackCount != other.stackCount) {
116: return false;
117: }
118:
119: for (int index = 0; index < variablesCount; index++) {
120: VerificationType this Type = this .variables[index];
121: VerificationType otherType = other.variables[index];
122:
123: if (!this Type.equals(otherType)) {
124: return false;
125: }
126: }
127:
128: for (int index = 0; index < stackCount; index++) {
129: VerificationType this Type = this .stack[index];
130: VerificationType otherType = other.stack[index];
131:
132: if (!this Type.equals(otherType)) {
133: return false;
134: }
135: }
136:
137: return true;
138: }
139:
140: public int hashCode() {
141: int hashCode = super .hashCode();
142:
143: for (int index = 0; index < variablesCount; index++) {
144: hashCode ^= variables[index].hashCode();
145: }
146:
147: for (int index = 0; index < stackCount; index++) {
148: hashCode ^= stack[index].hashCode();
149: }
150:
151: return hashCode;
152: }
153:
154: public String toString() {
155: StringBuffer buffer = new StringBuffer(super .toString())
156: .append("Var: ");
157:
158: for (int index = 0; index < variablesCount; index++) {
159: buffer = buffer.append('[').append(
160: variables[index].toString()).append(']');
161: }
162:
163: buffer.append(", Stack: ");
164:
165: for (int index = 0; index < stackCount; index++) {
166: buffer = buffer.append('[').append(stack[index].toString())
167: .append(']');
168: }
169:
170: return buffer.toString();
171: }
172: }
|