1 11 package org.eclipse.jdt.internal.debug.eval.ast.instructions; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.debug.core.model.IVariable; 20 import org.eclipse.jdt.debug.core.IJavaArrayType; 21 import org.eclipse.jdt.debug.core.IJavaClassObject; 22 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 23 import org.eclipse.jdt.debug.core.IJavaObject; 24 import org.eclipse.jdt.debug.core.IJavaReferenceType; 25 import org.eclipse.jdt.debug.core.IJavaType; 26 import org.eclipse.jdt.debug.core.IJavaValue; 27 import org.eclipse.jdt.debug.core.IJavaVariable; 28 import org.eclipse.jdt.internal.debug.core.JDIDebugPlugin; 29 import org.eclipse.jdt.internal.debug.eval.ast.engine.IRuntimeContext; 30 import org.eclipse.jdt.internal.debug.eval.ast.engine.Interpreter; 31 32 35 public abstract class Instruction { 36 37 private Interpreter fInterpreter; 38 39 public abstract int getSize(); 40 41 public void setInterpreter(Interpreter interpreter) { 42 fInterpreter= interpreter; 43 } 44 45 public void setLastValue(IJavaValue value) { 46 fInterpreter.setLastValue(value); 47 } 48 49 public void stop() { 50 fInterpreter.stop(); 51 } 52 53 public static int getBinaryPromotionType(int left, int right) { 54 return fTypeTable[left][right]; 55 } 56 public abstract void execute() throws CoreException; 57 58 protected IRuntimeContext getContext() { 59 return fInterpreter.getContext(); 60 } 61 62 protected IJavaDebugTarget getVM() { 63 return getContext().getVM(); 64 } 65 66 71 protected IVariable getInternalVariable(String name) { 72 return fInterpreter.getInternalVariable(name); 73 } 74 75 81 protected IVariable createInternalVariable(String name, IJavaType referencType) { 82 return fInterpreter.createInternalVariable(name, referencType); 83 } 84 85 86 89 protected IJavaObject getClassObject(IJavaType type) throws CoreException { 90 if (type instanceof IJavaReferenceType) { 91 return ((IJavaReferenceType)type).getClassObject(); 92 } 93 return null; 94 } 95 96 protected void jump(int offset) { 97 fInterpreter.jump(offset); 98 } 99 100 protected void push(Object object) { 101 fInterpreter.push(object); 102 } 103 104 protected Object pop() { 105 return fInterpreter.pop(); 106 } 107 108 protected IJavaValue popValue() throws CoreException { 109 Object element = fInterpreter.pop(); 110 if (element instanceof IJavaVariable) { 111 return (IJavaValue)((IJavaVariable)element).getValue(); 112 } 113 return (IJavaValue)element; 114 } 115 116 protected void pushNewValue(boolean value) { 117 fInterpreter.push(newValue(value)); 118 } 119 120 protected IJavaValue newValue(boolean value) { 121 return getVM().newValue(value); 122 } 123 124 protected void pushNewValue(byte value) { 125 fInterpreter.push(newValue(value)); 126 } 127 128 protected IJavaValue newValue(byte value) { 129 return getVM().newValue(value); 130 } 131 132 protected void pushNewValue(short value) { 133 fInterpreter.push(newValue(value)); 134 } 135 136 protected IJavaValue newValue(short value) { 137 return getVM().newValue(value); 138 } 139 140 protected void pushNewValue(int value) { 141 fInterpreter.push(newValue(value)); 142 } 143 144 protected IJavaValue newValue(int value) { 145 return getVM().newValue(value); 146 } 147 148 protected void pushNewValue(long value) { 149 fInterpreter.push(newValue(value)); 150 } 151 152 protected IJavaValue newValue(long value) { 153 return getVM().newValue(value); 154 } 155 156 protected void pushNewValue(char value) { 157 fInterpreter.push(newValue(value)); 158 } 159 160 protected IJavaValue newValue(char value) { 161 return getVM().newValue(value); 162 } 163 164 protected void pushNewValue(float value) { 165 fInterpreter.push(newValue(value)); 166 } 167 168 protected IJavaValue newValue(float value) { 169 return getVM().newValue(value); 170 } 171 172 protected void pushNewValue(double value) { 173 fInterpreter.push(newValue(value)); 174 } 175 176 protected IJavaValue newValue(double value) { 177 return getVM().newValue(value); 178 } 179 180 protected void pushNewValue(String value) { 181 fInterpreter.push(newValue(value)); 182 } 183 184 protected IJavaValue newValue(String value) { 185 return getVM().newValue(value); 186 } 187 188 protected void pushNullValue() { 189 fInterpreter.push(nullValue()); 190 } 191 192 protected IJavaValue nullValue() { 193 return getVM().nullValue(); 194 } 195 196 public static int getUnaryPromotionType(int typeId) { 197 return fTypeTable[typeId][T_int]; 198 } 199 200 protected IJavaType getType(String qualifiedName) throws CoreException { 201 IJavaClassObject classReference= getContext().classForName(qualifiedName); 204 if (classReference == null) { 206 throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String []{qualifiedName}), null)); 207 } 208 return classReference.getInstanceType(); 209 } 210 211 protected IJavaArrayType getArrayType(String typeSignature, int dimension) throws CoreException { 212 String qualifiedName = RuntimeSignature.toString(typeSignature); 213 String braces = ""; for (int i = 0; i < dimension; i++) { 215 qualifiedName += "[]"; braces += "["; } 218 String signature = braces + typeSignature; 219 IJavaObject classReference= getContext().classForName(signature); 222 if (classReference == null) { 223 throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String []{qualifiedName}), null)); 224 } 225 IJavaType[] types= getVM().getJavaTypes(qualifiedName); 226 checkTypes(types, qualifiedName); 227 if (types.length == 1) { 228 return (IJavaArrayType)types[0]; 230 } 231 for(int i= 0, length= types.length; i < length; i++) { 233 IJavaType type= types[i]; 234 if (classReference.equals(getClassObject(type))) { 235 return (IJavaArrayType)type; 236 } 237 } 238 239 244 throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String []{qualifiedName}), null)); 245 } 246 247 protected void checkTypes(IJavaType[] types, String qualifiedName) throws CoreException { 248 if (types == null || types.length == 0) { 249 throw new CoreException(new Status(IStatus.ERROR, JDIDebugPlugin.getUniqueIdentifier(), IStatus.OK, MessageFormat.format(InstructionsEvaluationMessages.Instruction_No_type, new String []{qualifiedName}), null)); 250 } 251 } 252 253 static public final int T_undefined =0; 254 static public final int T_Object =1; 255 static public final int T_char =2; 256 static public final int T_byte =3; 257 static public final int T_short =4; 258 static public final int T_boolean =5; 259 static public final int T_void =6; 260 static public final int T_long =7; 261 static public final int T_double =8; 262 static public final int T_float =9; 263 static public final int T_int =10; 264 static public final int T_String =11; 265 static public final int T_null =12; 266 267 private static final int[][] fTypeTable= { 268 {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined}, 269 {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_String, T_undefined}, 270 {T_undefined, T_undefined, T_int, T_int, T_int, T_undefined, T_undefined, T_long, T_double, T_float, T_int, T_String, T_undefined}, 271 {T_undefined, T_undefined, T_int, T_int, T_int, T_undefined, T_undefined, T_long, T_double, T_float, T_int, T_String, T_undefined}, 272 {T_undefined, T_undefined, T_int, T_int, T_int, T_undefined, T_undefined, T_long, T_double, T_float, T_int, T_String, T_undefined}, 273 {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_boolean, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_String, T_undefined}, 274 {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined}, 275 {T_undefined, T_undefined, T_long, T_long, T_long, T_undefined, T_undefined, T_long, T_double, T_float, T_long, T_String, T_undefined}, 276 {T_undefined, T_undefined, T_double, T_double, T_double, T_undefined, T_undefined, T_double, T_double, T_double, T_double, T_String, T_undefined}, 277 {T_undefined, T_undefined, T_float, T_float, T_float, T_undefined, T_undefined, T_float, T_double, T_float, T_float, T_String, T_undefined}, 278 {T_undefined, T_undefined, T_int, T_int, T_int, T_undefined, T_undefined, T_long, T_double, T_float, T_int, T_String, T_undefined}, 279 {T_undefined, T_String, T_String, T_String, T_String, T_String, T_undefined, T_String, T_String, T_String, T_String, T_String, T_String}, 280 {T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_undefined, T_String, T_undefined}, 281 }; 282 } 283 284 | Popular Tags |