Represents a field in a struct. This is not a Type in the type system.
| 7 | * Represents a field in a struct. This is not a Type in the type system. |
| 8 | */ |
| 9 | public class Field extends Type { |
| 10 | |
| 11 | // The pair {fieldName,type} uniquely identifies a field. |
| 12 | |
| 13 | // Field name |
| 14 | public final String _fname; |
| 15 | // Type of the field |
| 16 | public final Type _type; |
| 17 | |
| 18 | private Field(String fname, Type type ) { |
| 19 | super(TFLD); |
| 20 | _fname = fname; |
| 21 | _type = type; |
| 22 | } |
| 23 | public static Field make( String fname, Type type ) { |
| 24 | return new Field(fname,type).intern(); |
| 25 | } |
| 26 | |
| 27 | public static final Field TEST = make("test",TypeInteger.ZERO); |
| 28 | public static void gather(ArrayList<Type> ts) { ts.add(TEST); } |
| 29 | |
| 30 | @Override Field xmeet( Type that ) { |
| 31 | Field fld = (Field)that; // Invariant |
| 32 | assert _fname.equals(fld._fname); |
| 33 | return make(_fname,_type.meet(fld._type)); |
| 34 | } |
| 35 | |
| 36 | @Override |
| 37 | public Field dual() { return make(_fname,_type.dual()); } |
| 38 | |
| 39 | @Override |
| 40 | public Field glb() { |
| 41 | return make(_fname,_type.glb()); |
| 42 | } |
| 43 | |
| 44 | // Override in subclasses |
| 45 | int hash() { return _fname.hashCode() ^ _type.hashCode(); } |
| 46 | |
| 47 | boolean eq(Type t) { |
| 48 | Field f = (Field)t; |
| 49 | return Utils.eq(_fname,f._fname) && _type==f._type; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | @Override |
| 54 | public StringBuilder print( StringBuilder sb ) { |
| 55 | return _type.print(sb.append(_fname).append(":")); |
| 56 | } |
| 57 | |
| 58 | @Override public String str() { return _fname; } |
| 59 | } |