1 package gov.nasa.jpf.jvm; 20 21 import org.apache.bcel.classfile.*; 22 import gov.nasa.jpf.JPFException; 23 24 25 28 public class ReferenceFieldInfo extends FieldInfo { 29 int init=-1; 30 String sInit; 33 public ReferenceFieldInfo (String name, String type, boolean isStatic, 34 ConstantValue cv, ClassInfo ci, int idx, int off) { 35 super(name, type, isStatic, cv, ci, idx, off); 36 init = computeInitValue(cv); 37 } 38 39 public String valueToString (Fields f) { 40 int i = f.getIntValue(storageOffset); 41 if (i == -1) { 42 return "null"; 43 } else { 44 return DynamicArea.getHeap().get(i).toString(); 45 } 46 } 47 48 public boolean isReference () { 49 return true; 50 } 51 52 public boolean isArrayField () { 53 return ci.isArray; 54 } 55 56 int computeInitValue (ConstantValue cv) { 57 68 if (cv == null) return -1; 69 70 String s = cv.toString(); 73 74 if (s.charAt(0) == '"') { 75 s = s.substring(1,s.length()-1); sInit = s; 77 78 } else { 81 throw new JPFException ("unsupported reference initialization: " + s); 82 } 83 84 return -1; 85 } 86 87 public void initialize (Fields f) { 88 int ref = init; 89 if (sInit != null) { 90 ref = DynamicArea.getHeap().newString(sInit, null); 91 } 92 f.setReferenceValue(storageOffset, ref); 93 } 94 } 95 | Popular Tags |