001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jdt.internal.compiler.codegen;
011:
012: import org.eclipse.jdt.core.compiler.CharOperation;
013: import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
014: import org.eclipse.jdt.internal.compiler.lookup.TypeIds;
015:
016: public class VerificationTypeInfo {
017: /**
018: * The tag value representing top variable info
019: * @since 3.2
020: */
021: public static final int ITEM_TOP = 0;
022: /**
023: * The tag value representing integer variable info
024: * @since 3.2
025: */
026: public static final int ITEM_INTEGER = 1;
027: /**
028: * The tag value representing float variable info
029: * @since 3.2
030: */
031: public static final int ITEM_FLOAT = 2;
032: /**
033: * The tag value representing double variable info
034: * @since 3.2
035: */
036: public static final int ITEM_DOUBLE = 3;
037: /**
038: * The tag value representing long variable info
039: * @since 3.2
040: */
041: public static final int ITEM_LONG = 4;
042: /**
043: * The tag value representing null variable info
044: * @since 3.2
045: */
046: public static final int ITEM_NULL = 5;
047: /**
048: * The tag value representing uninitialized this variable info
049: * @since 3.2
050: */
051: public static final int ITEM_UNINITIALIZED_THIS = 6;
052: /**
053: * The tag value representing object variable info
054: * @since 3.2
055: */
056: public static final int ITEM_OBJECT = 7;
057: /**
058: * The tag value representing uninitialized variable info
059: * @since 3.2
060: */
061: public static final int ITEM_UNINITIALIZED = 8;
062:
063: public int tag;
064: private int id;
065: private char[] constantPoolName;
066: public int offset;
067:
068: private VerificationTypeInfo() {
069: // for duplication
070: }
071:
072: public VerificationTypeInfo(int id, char[] constantPoolName) {
073: this (id, VerificationTypeInfo.ITEM_OBJECT, constantPoolName);
074: }
075:
076: public VerificationTypeInfo(int id, int tag, char[] constantPoolName) {
077: this .id = id;
078: this .tag = tag;
079: this .constantPoolName = constantPoolName;
080: }
081:
082: public VerificationTypeInfo(int tag, TypeBinding binding) {
083: this (binding);
084: this .tag = tag;
085: }
086:
087: public VerificationTypeInfo(TypeBinding binding) {
088: this .id = binding.id;
089: switch (binding.id) {
090: case TypeIds.T_boolean:
091: case TypeIds.T_byte:
092: case TypeIds.T_char:
093: case TypeIds.T_int:
094: case TypeIds.T_short:
095: this .tag = VerificationTypeInfo.ITEM_INTEGER;
096: break;
097: case TypeIds.T_float:
098: this .tag = VerificationTypeInfo.ITEM_FLOAT;
099: break;
100: case TypeIds.T_long:
101: this .tag = VerificationTypeInfo.ITEM_LONG;
102: break;
103: case TypeIds.T_double:
104: this .tag = VerificationTypeInfo.ITEM_DOUBLE;
105: break;
106: case TypeIds.T_null:
107: this .tag = VerificationTypeInfo.ITEM_NULL;
108: break;
109: default:
110: this .tag = VerificationTypeInfo.ITEM_OBJECT;
111: this .constantPoolName = binding.constantPoolName();
112: }
113: }
114:
115: public void setBinding(TypeBinding binding) {
116: this .constantPoolName = binding.constantPoolName();
117: final int typeBindingId = binding.id;
118: this .id = typeBindingId;
119: switch (typeBindingId) {
120: case TypeIds.T_boolean:
121: case TypeIds.T_byte:
122: case TypeIds.T_char:
123: case TypeIds.T_int:
124: case TypeIds.T_short:
125: this .tag = VerificationTypeInfo.ITEM_INTEGER;
126: break;
127: case TypeIds.T_float:
128: this .tag = VerificationTypeInfo.ITEM_FLOAT;
129: break;
130: case TypeIds.T_long:
131: this .tag = VerificationTypeInfo.ITEM_LONG;
132: break;
133: case TypeIds.T_double:
134: this .tag = VerificationTypeInfo.ITEM_DOUBLE;
135: break;
136: case TypeIds.T_null:
137: this .tag = VerificationTypeInfo.ITEM_NULL;
138: break;
139: default:
140: this .tag = VerificationTypeInfo.ITEM_OBJECT;
141: }
142: }
143:
144: public int id() {
145: return this .id;
146: }
147:
148: public String toString() {
149: StringBuffer buffer = new StringBuffer();
150: switch (this .tag) {
151: case VerificationTypeInfo.ITEM_UNINITIALIZED_THIS:
152: buffer
153: .append("uninitialized_this(").append(this .readableName()).append(")"); //$NON-NLS-1$//$NON-NLS-2$
154: break;
155: case VerificationTypeInfo.ITEM_UNINITIALIZED:
156: buffer
157: .append("uninitialized(").append(this .readableName()).append(")"); //$NON-NLS-1$//$NON-NLS-2$
158: break;
159: case VerificationTypeInfo.ITEM_OBJECT:
160: buffer.append(this .readableName());
161: break;
162: case VerificationTypeInfo.ITEM_DOUBLE:
163: buffer.append('D');
164: break;
165: case VerificationTypeInfo.ITEM_FLOAT:
166: buffer.append('F');
167: break;
168: case VerificationTypeInfo.ITEM_INTEGER:
169: buffer.append('I');
170: break;
171: case VerificationTypeInfo.ITEM_LONG:
172: buffer.append('J');
173: break;
174: case VerificationTypeInfo.ITEM_NULL:
175: buffer.append("null"); //$NON-NLS-1$
176: break;
177: case VerificationTypeInfo.ITEM_TOP:
178: buffer.append("top"); //$NON-NLS-1$
179: break;
180: }
181: return String.valueOf(buffer);
182: }
183:
184: public VerificationTypeInfo duplicate() {
185: final VerificationTypeInfo verificationTypeInfo = new VerificationTypeInfo();
186: verificationTypeInfo.id = this .id;
187: verificationTypeInfo.tag = this .tag;
188: verificationTypeInfo.constantPoolName = this .constantPoolName;
189: verificationTypeInfo.offset = this .offset;
190: return verificationTypeInfo;
191: }
192:
193: public boolean equals(Object obj) {
194: if (obj instanceof VerificationTypeInfo) {
195: VerificationTypeInfo info1 = (VerificationTypeInfo) obj;
196: return info1.tag == this .tag
197: && CharOperation.equals(info1.constantPoolName(),
198: this .constantPoolName());
199: }
200: return false;
201: }
202:
203: public int hashCode() {
204: return this .tag + this .id + this .constantPoolName.length
205: + this .offset;
206: }
207:
208: public char[] constantPoolName() {
209: return this .constantPoolName;
210: }
211:
212: public char[] readableName() {
213: return this .constantPoolName;
214: }
215:
216: public void replaceWithElementType() {
217: if (this .constantPoolName[1] == 'L') {
218: this .constantPoolName = CharOperation.subarray(
219: this .constantPoolName, 2,
220: this .constantPoolName.length - 1);
221: } else {
222: this .constantPoolName = CharOperation.subarray(
223: this .constantPoolName, 1,
224: this .constantPoolName.length);
225: if (this .constantPoolName.length == 1) {
226: switch (this .constantPoolName[0]) {
227: case 'I':
228: this .id = TypeIds.T_int;
229: break;
230: case 'B':
231: this .id = TypeIds.T_byte;
232: break;
233: case 'S':
234: this .id = TypeIds.T_short;
235: break;
236: case 'C':
237: this .id = TypeIds.T_char;
238: break;
239: case 'J':
240: this .id = TypeIds.T_long;
241: break;
242: case 'F':
243: this .id = TypeIds.T_float;
244: break;
245: case 'D':
246: this .id = TypeIds.T_double;
247: break;
248: case 'Z':
249: this .id = TypeIds.T_boolean;
250: break;
251: case 'N':
252: this .id = TypeIds.T_null;
253: break;
254: case 'V':
255: this.id = TypeIds.T_void;
256: break;
257: }
258: }
259: }
260: }
261: }
|