1 package gov.nasa.jpf.jvm; 20 21 import org.apache.bcel.classfile.*; 22 23 24 27 public abstract class FieldInfo { 28 31 protected final String name; 32 33 36 protected final String type; 37 38 41 protected final ClassInfo ci; 42 43 46 protected final boolean isStatic; 47 48 51 protected final ConstantValue cv; 52 53 56 int fieldIndex; 57 58 62 int storageOffset; 63 64 68 int attributes = ElementInfo.ATTR_PROP_MASK; 69 70 protected FieldInfo (String name, String type, boolean isStatic, 71 ConstantValue cv, ClassInfo ci, int idx, int off) { 72 this.name = name; 73 this.type = type; 74 this.isStatic = isStatic; 75 this.ci = ci; 76 this.cv = cv; 77 this.fieldIndex = idx; 78 this.storageOffset = off; 79 } 80 81 public static FieldInfo create (Field f, ClassInfo ci, int idx, int off) { 82 return create(f.getName(), f.getSignature(), f.isStatic(), 83 f.getConstantValue(), ci, idx, off); 84 } 85 86 96 public static FieldInfo create (String name, String type, boolean isStatic, 97 ConstantValue cv, ClassInfo ci, int idx, int off) { 98 switch (Types.getBaseType(type)) { 99 case Types.T_CHAR: 100 case Types.T_BYTE: 101 case Types.T_INT: 102 case Types.T_SHORT: 103 case Types.T_BOOLEAN: 104 return new IntegerFieldInfo(name, type, isStatic, cv, ci, idx, off); 105 106 case Types.T_FLOAT: 107 return new FloatFieldInfo(name, type, isStatic, cv, ci, idx, off); 108 109 case Types.T_DOUBLE: 110 return new DoubleFieldInfo(name, type, isStatic, cv, ci, idx, off); 111 112 case Types.T_LONG: 113 return new LongFieldInfo(name, type, isStatic, cv, ci, idx, off); 114 115 case Types.T_ARRAY: 116 case Types.T_REFERENCE: 117 return new ReferenceFieldInfo(name, type, isStatic, cv, ci, idx, off); 118 119 default: 120 throw new InternalError ("bad base type! " + type + " " + 121 Types.getBaseType(type)); 122 } 123 } 124 125 public abstract String valueToString (Fields f); 126 127 130 public ClassInfo getClassInfo () { 131 return ci; 132 } 133 134 public ConstantValue getConstantValue () { 135 return cv; 136 } 137 138 public int getFieldIndex () { 139 return fieldIndex; 140 } 141 142 public boolean isReference () { 143 return false; 144 } 145 146 public boolean isArrayField () { 147 return false; 148 } 149 150 155 public boolean isStatic () { 156 return isStatic; 157 } 158 159 162 public String getName () { 163 return name; 164 } 165 166 169 public int getStorageSize () { 170 return Types.getTypeSize(type); 171 } 172 173 176 public String getType () { 177 return type; 178 } 179 180 183 public abstract void initialize (Fields f); 184 185 188 public String toString () { 189 StringBuffer sb = new StringBuffer (); 190 191 if (isStatic) { 192 sb.append("static "); 193 } 194 195 sb.append(Types.getTypeName(type)); 196 sb.append(" "); 197 sb.append(ci.getName()); 198 sb.append("."); 199 sb.append(name); 200 201 return sb.toString(); 202 } 203 204 void setAttributes (int a) { 205 attributes = a; 206 } 207 208 public int getAttributes () { 209 return attributes; 210 } 211 212 public int getStorageOffset () { 213 return storageOffset; 214 } 215 } 216 | Popular Tags |