1 package gov.nasa.jpf.jvm; 20 21 22 23 26 public class ArrayFields extends Fields { 27 28 private int elementStorageSize; 29 private int length; 30 private String elementType; 31 private boolean isReference; 32 33 public ArrayFields (String type, ClassInfo ci, int storageSize, int length, 34 boolean isReference) { 35 super(type, ci, storageSize); 36 this.length = length; 37 this.isReference = isReference; 38 elementType = type.substring(1); 39 elementStorageSize = Types.getTypeSize(type); 40 41 if (isReference) { 47 for (int i=0; i<length; i++) { 48 values[i] = -1; 49 } 50 } 51 } 52 53 public int arrayLength () { 54 return length; 55 } 56 57 public int getHeapSize () { 58 return Types.getTypeSizeInBytes(elementType) * length; 59 } 60 61 public FieldInfo getFieldInfo(String clsBase, String fname) { 62 return null; 64 } 65 66 public int getNumberOfFields() { 67 return 0; 69 } 70 71 public FieldInfo getFieldInfo(int fieldIndex) { 72 return null; 74 } 75 76 79 public int getFieldIndex (String name, String referenceType) { 80 throw new NoSuchFieldError ("array does not have any fields!" + 82 getClassInfo().getName() + "." + name); 83 } 84 85 public String getFieldName (int index) { 86 return Integer.toString(index / elementStorageSize); 87 } 88 89 public String getFieldType (String name, String referenceType) { 90 throw new NoSuchFieldError ("array does not have any fields!" + 92 getClassInfo().getName() + "." + name); 93 } 94 95 public String getFieldType (int findex) { 96 if (elementType == null) { 97 elementType = getType().substring(1); 98 } 99 100 return elementType; 101 } 102 103 public String getLogChar () { 104 return "*"; 105 } 106 107 public void setLongField (String name, String referenceType, long value) { 108 throw new NoSuchFieldError ("array does not have any fields!" + 109 getClassInfo().getName() + "." + name); 110 } 111 112 public long getLongField (String name, String referenceType) { 113 throw new NoSuchFieldError ("array does not have any fields!" + 114 getClassInfo().getName() + "." + name); 115 } 116 117 public boolean isReferenceArray() { 118 return isReference; 119 } 120 121 public boolean isRef (String name, String referenceType) { 122 throw new NoSuchFieldError ("array does not have any fields!" + 123 getClassInfo().getName() + "." + name); 124 } 125 126 public boolean[] asBooleanArray () { 127 int length = values.length; 129 boolean[] result = new boolean[length]; 130 131 for (int i = 0; i < length; i++) { 132 result[i] = Types.intToBoolean(values[i]); 133 } 134 135 return result; 136 } 137 138 public byte[] asByteArray () { 139 int length = values.length; 141 byte[] result = new byte[length]; 142 143 for (int i = 0; i < length; i++) { 144 result[i] = (byte) values[i]; 145 } 146 147 return result; 148 } 149 150 public char[] asCharArray () { 151 int length = values.length; 153 char[] result = new char[length]; 154 155 for (int i = 0; i < length; i++) { 156 result[i] = (char)values[i]; 157 } 158 159 return result; 160 } 161 162 public short[] asShortArray () { 163 int length = values.length; 165 short[] result = new short[length]; 166 167 for (int i = 0; i < length; i++) { 168 result[i] = (short) values[i]; 169 } 170 171 return result; 172 } 173 174 public int[] asIntArray () { 175 int length = values.length; 177 int[] result = new int[length]; 178 179 for (int i = 0; i < length; i++) { 180 result[i] = values[i]; 181 } 182 183 return result; 184 } 185 186 public long[] asLongArray () { 187 int length = values.length; 189 long[] result = new long[length]; 190 191 length--; 192 for (int i = 0, j=0; i < length; i++, j+=2) { 193 result[i] = Types.intsToLong(values[j + 1], values[j]); 194 } 195 196 return result; 197 } 198 199 public float[] asFloatArray () { 200 int length = values.length; 202 float[] result = new float[length]; 203 204 for (int i = 0; i < length; i++) { 205 result[i] = Types.intToFloat(values[i]); 206 } 207 208 return result; 209 } 210 211 public double[] asDoubleArray () { 212 int length = values.length; 214 double[] result = new double[length]; 215 216 length--; 217 for (int i = 0, j=0; i < length; i++, j+=2) { 218 result[i] = Types.intsToDouble(values[j + 1], values[j]); 219 } 220 221 return result; 222 } 223 224 } 225 | Popular Tags |