1 11 package org.eclipse.jdt.internal.compiler.codegen; 12 13 import org.eclipse.jdt.core.compiler.CharOperation; 14 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; 15 import org.eclipse.jdt.internal.compiler.lookup.TypeIds; 16 17 public class VerificationTypeInfo implements Cloneable { 18 22 public static final int ITEM_TOP = 0; 23 27 public static final int ITEM_INTEGER = 1; 28 32 public static final int ITEM_FLOAT = 2; 33 37 public static final int ITEM_DOUBLE = 3; 38 42 public static final int ITEM_LONG = 4; 43 47 public static final int ITEM_NULL = 5; 48 52 public static final int ITEM_UNINITIALIZED_THIS = 6; 53 57 public static final int ITEM_OBJECT = 7; 58 62 public static final int ITEM_UNINITIALIZED = 8; 63 64 public int tag; 65 private int id; 66 private char[] constantPoolName; 67 public int offset; 68 69 public VerificationTypeInfo(int id, char[] constantPoolName) { 70 this(id, VerificationTypeInfo.ITEM_OBJECT, constantPoolName); 71 } 72 public VerificationTypeInfo(int id, int tag, char[] constantPoolName) { 73 this.id = id; 74 this.constantPoolName = constantPoolName; 75 this.tag = tag; 76 } 77 public VerificationTypeInfo(int tag, TypeBinding binding) { 78 this(binding); 79 this.tag = tag; 80 } 81 public VerificationTypeInfo(TypeBinding binding) { 82 this.id = binding.id; 83 switch(binding.id) { 84 case TypeIds.T_boolean : 85 case TypeIds.T_byte : 86 case TypeIds.T_char : 87 case TypeIds.T_int : 88 case TypeIds.T_short : 89 this.tag = VerificationTypeInfo.ITEM_INTEGER; 90 break; 91 case TypeIds.T_float : 92 this.tag = VerificationTypeInfo.ITEM_FLOAT; 93 break; 94 case TypeIds.T_long : 95 this.tag = VerificationTypeInfo.ITEM_LONG; 96 break; 97 case TypeIds.T_double : 98 this.tag = VerificationTypeInfo.ITEM_DOUBLE; 99 break; 100 case TypeIds.T_null : 101 this.tag = VerificationTypeInfo.ITEM_NULL; 102 break; 103 default: 104 this.tag = VerificationTypeInfo.ITEM_OBJECT; 105 } 106 this.constantPoolName = binding.constantPoolName(); 107 } 108 public void setBinding(TypeBinding binding) { 109 this.constantPoolName = binding.constantPoolName(); 110 final int typeBindingId = binding.id; 111 this.id = typeBindingId; 112 switch(typeBindingId) { 113 case TypeIds.T_boolean : 114 case TypeIds.T_byte : 115 case TypeIds.T_char : 116 case TypeIds.T_int : 117 case TypeIds.T_short : 118 this.tag = VerificationTypeInfo.ITEM_INTEGER; 119 break; 120 case TypeIds.T_float : 121 this.tag = VerificationTypeInfo.ITEM_FLOAT; 122 break; 123 case TypeIds.T_long : 124 this.tag = VerificationTypeInfo.ITEM_LONG; 125 break; 126 case TypeIds.T_double : 127 this.tag = VerificationTypeInfo.ITEM_DOUBLE; 128 break; 129 case TypeIds.T_null : 130 this.tag = VerificationTypeInfo.ITEM_NULL; 131 break; 132 default: 133 this.tag = VerificationTypeInfo.ITEM_OBJECT; 134 } 135 } 136 public int id() { 137 return this.id; 138 } 139 public String toString() { 140 StringBuffer buffer = new StringBuffer (); 141 switch(this.tag) { 142 case VerificationTypeInfo.ITEM_UNINITIALIZED_THIS : 143 buffer.append("uninitialized_this(").append(this.readableName()).append(")"); break; 145 case VerificationTypeInfo.ITEM_UNINITIALIZED : 146 buffer.append("uninitialized(").append(this.readableName()).append(")"); break; 148 default: 149 buffer.append(this.readableName()); 150 } 151 return String.valueOf(buffer); 152 } 153 protected Object clone() throws CloneNotSupportedException { 154 final VerificationTypeInfo verificationTypeInfo = (VerificationTypeInfo) super.clone(); 155 verificationTypeInfo.id = this.id; 156 verificationTypeInfo.tag = this.tag; 157 verificationTypeInfo.constantPoolName = this.constantPoolName; 158 verificationTypeInfo.offset = this.offset; 159 return verificationTypeInfo; 160 } 161 public boolean equals(Object obj) { 162 if (obj instanceof VerificationTypeInfo) { 163 VerificationTypeInfo info1 = (VerificationTypeInfo) obj; 164 return info1.tag == this.tag && CharOperation.equals(info1.constantPoolName(), this.constantPoolName()); 165 } 166 return false; 167 } 168 public char[] constantPoolName() { 169 return this.constantPoolName; 170 } 171 public char[] readableName() { 172 return this.constantPoolName; 173 } 174 public void replaceWithElementType() { 175 if (this.constantPoolName[1] == 'L') { 176 this.constantPoolName = CharOperation.subarray(this.constantPoolName, 2, this.constantPoolName.length - 1); 177 } else { 178 this.constantPoolName = CharOperation.subarray(this.constantPoolName, 1, this.constantPoolName.length); 179 if (this.constantPoolName.length == 1) { 180 switch(this.constantPoolName[0]) { 181 case 'I' : 182 this.id = TypeIds.T_int; 183 break; 184 case 'B' : 185 this.id = TypeIds.T_byte; 186 break; 187 case 'S' : 188 this.id = TypeIds.T_short; 189 break; 190 case 'C' : 191 this.id = TypeIds.T_char; 192 break; 193 case 'J' : 194 this.id = TypeIds.T_long; 195 break; 196 case 'F' : 197 this.id = TypeIds.T_float; 198 break; 199 case 'D' : 200 this.id = TypeIds.T_double; 201 break; 202 case 'Z' : 203 this.id = TypeIds.T_boolean; 204 break; 205 case 'N' : 206 this.id = TypeIds.T_null; 207 break; 208 case 'V' : 209 this.id = TypeIds.T_void; 210 break; 211 } 212 } 213 } 214 } 215 } 216 | Popular Tags |