MCPcopy Create free account
hub / github.com/SeaOfNodes/Simple / Field

Class Field

chapter13/src/main/java/com/seaofnodes/simple/type/Field.java:9–60  ·  view source on GitHub ↗

Represents a field in a struct. This is not a Type in the type system.

Source from the content-addressed store, hash-verified

7 * Represents a field in a struct. This is not a Type in the type system.
8 */
9public 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 // Make with existing alias
24 public static Field make( String fname, Type type ) {
25 return new Field(fname,type).intern();
26 }
27
28 public static final Field TEST = make("test",TypeInteger.ZERO);
29 public static void gather(ArrayList<Type> ts) { ts.add(TEST); }
30
31 @Override Field xmeet( Type that ) {
32 Field fld = (Field)that; // Invariant
33 assert _fname.equals(fld._fname);
34 return make(_fname,_type.meet(fld._type));
35 }
36
37 @Override
38 public Field dual() { return make(_fname,_type.dual()); }
39
40 @Override
41 public Field glb() {
42 return make(_fname,_type.glb());
43 }
44
45 // Override in subclasses
46 int hash() { return _fname.hashCode() ^ _type.hashCode(); }
47
48 boolean eq(Type t) {
49 Field f = (Field)t;
50 return _fname.equals(f._fname) && _type==f._type;
51 }
52
53
54 @Override
55 public StringBuilder print( StringBuilder sb ) {
56 return _type.print(sb.append(_fname).append(" :"));
57 }
58
59 @Override public String str() { return _fname; }
60}

Callers

nothing calls this directly

Calls 1

makeMethod · 0.95

Tested by

no test coverage detected