KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > util > StackMapFrame


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.core.util;
12
13 import org.eclipse.jdt.core.util.ClassFormatException;
14 import org.eclipse.jdt.core.util.IConstantPool;
15 import org.eclipse.jdt.core.util.IStackMapFrame;
16 import org.eclipse.jdt.core.util.IVerificationTypeInfo;
17
18 /**
19  * Default implementation of IStackMapFrame
20  */

21 public class StackMapFrame extends ClassFileStruct implements IStackMapFrame {
22     private static final IVerificationTypeInfo[] EMPTY_LOCALS_OR_STACK_ITEMS = new IVerificationTypeInfo[0];
23
24     private int readOffset;
25     private int frameType;
26     private int numberOfLocals;
27     private int numberOfStackItems;
28     private IVerificationTypeInfo[] locals;
29     private IVerificationTypeInfo[] stackItems;
30     private int offsetDelta;
31     
32     /**
33      * Constructor for StackMapFrame.
34      *
35      * @param classFileBytes
36      * @param constantPool
37      * @param offset
38      * @throws ClassFormatException
39      */

40     public StackMapFrame(
41             byte[] classFileBytes,
42             IConstantPool constantPool,
43             int offset) throws ClassFormatException {
44         
45         final int type = u1At(classFileBytes, 0, offset);
46         this.frameType = type;
47         switch(type) {
48             case 247 : // SAME_LOCALS_1_STACK_ITEM_EXTENDED
49
this.offsetDelta = u2At(classFileBytes, 1, offset);
50                 this.numberOfStackItems = 1;
51                 this.stackItems = new VerificationInfo[1];
52                 this.readOffset = 3;
53                 VerificationInfo info = new VerificationInfo(classFileBytes, constantPool, offset + this.readOffset);
54                 this.stackItems[0] = info;
55                 this.readOffset += info.sizeInBytes();
56                 this.locals = EMPTY_LOCALS_OR_STACK_ITEMS;
57                 this.numberOfLocals = 0;
58                 break;
59             case 248 :
60             case 249 :
61             case 250:
62                 // CHOP
63
this.offsetDelta = u2At(classFileBytes, 1, offset);
64                 this.numberOfStackItems = 0;
65                 this.stackItems = EMPTY_LOCALS_OR_STACK_ITEMS;
66                 this.readOffset = 3;
67                 this.locals = EMPTY_LOCALS_OR_STACK_ITEMS;
68                 this.numberOfLocals = 0;
69                 break;
70             case 251 :
71                 // SAME_FRAME_EXTENDED
72
this.offsetDelta = u2At(classFileBytes, 1, offset);
73                 this.numberOfStackItems = 0;
74                 this.stackItems = EMPTY_LOCALS_OR_STACK_ITEMS;
75                 this.readOffset = 3;
76                 this.locals = EMPTY_LOCALS_OR_STACK_ITEMS;
77                 this.numberOfLocals = 0;
78                 break;
79             case 252 :
80             case 253 :
81             case 254 :
82                 // APPEND
83
this.offsetDelta = u2At(classFileBytes, 1, offset);
84                 this.numberOfStackItems = 0;
85                 this.stackItems = EMPTY_LOCALS_OR_STACK_ITEMS;
86                 this.readOffset = 3;
87                 int diffLocals = type - 251;
88                 this.numberOfLocals = diffLocals;
89                 this.locals = new IVerificationTypeInfo[diffLocals];
90                 for (int i = 0; i < diffLocals; i++) {
91                     VerificationInfo verificationInfo = new VerificationInfo(classFileBytes, constantPool, offset + readOffset);
92                     this.locals[i] = verificationInfo;
93                     this.readOffset += verificationInfo.sizeInBytes();
94                 }
95                 break;
96             case 255 :
97                 // FULL_FRAME
98
this.offsetDelta = u2At(classFileBytes, 1, offset);
99                 int tempLocals = u2At(classFileBytes, 3, offset);
100                 this.numberOfLocals = tempLocals;
101                 this.readOffset = 5;
102                 if (tempLocals != 0) {
103                     this.locals = new IVerificationTypeInfo[tempLocals];
104                     for (int i = 0; i < tempLocals; i++) {
105                         VerificationInfo verificationInfo = new VerificationInfo(classFileBytes, constantPool, offset + this.readOffset);
106                         this.locals[i] = verificationInfo;
107                         this.readOffset += verificationInfo.sizeInBytes();
108                     }
109                 } else {
110                     this.locals = EMPTY_LOCALS_OR_STACK_ITEMS;
111                 }
112                 int tempStackItems = u2At(classFileBytes, readOffset, offset);
113                 this.readOffset += 2;
114                 this.numberOfStackItems = tempStackItems;
115                 if (tempStackItems != 0) {
116                     this.stackItems = new IVerificationTypeInfo[tempStackItems];
117                     for (int i = 0; i < tempStackItems; i++) {
118                         VerificationInfo verificationInfo = new VerificationInfo(classFileBytes, constantPool, offset + this.readOffset);
119                         this.stackItems[i] = verificationInfo;
120                         this.readOffset += verificationInfo.sizeInBytes();
121                     }
122                 } else {
123                     this.stackItems = EMPTY_LOCALS_OR_STACK_ITEMS;
124                 }
125                 break;
126             default:
127                 if (type <= 63) {
128                     // SAME_FRAME
129
this.offsetDelta = type;
130                     this.numberOfStackItems = 0;
131                     this.stackItems = EMPTY_LOCALS_OR_STACK_ITEMS;
132                     this.locals = EMPTY_LOCALS_OR_STACK_ITEMS;
133                     this.numberOfLocals = 0;
134                     this.readOffset = 1;
135                 } else if (type <= 127) {
136                     // SAME_LOCALS_1_STACK_ITEM
137
this.offsetDelta = type - 64;
138                     this.numberOfStackItems = 1;
139                     this.stackItems = new VerificationInfo[1];
140                     this.readOffset = 1;
141                     info = new VerificationInfo(classFileBytes, constantPool, offset + this.readOffset);
142                     this.stackItems[0] = info;
143                     this.readOffset += info.sizeInBytes();
144                     this.locals = EMPTY_LOCALS_OR_STACK_ITEMS;
145                     this.numberOfLocals = 0;
146                 }
147         }
148     }
149     int sizeInBytes() {
150         return this.readOffset;
151     }
152     public int getFrameType() {
153         return this.frameType;
154     }
155     public IVerificationTypeInfo[] getLocals() {
156         return this.locals;
157     }
158     public int getNumberOfLocals() {
159         return this.numberOfLocals;
160     }
161     public int getNumberOfStackItems() {
162         return this.numberOfStackItems;
163     }
164     public int getOffsetDelta() {
165         return this.offsetDelta;
166     }
167     public IVerificationTypeInfo[] getStackItems() {
168         return this.stackItems;
169     }
170 }
171
Popular Tags