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

Class Field

chapter16/src/main/java/com/seaofnodes/simple/type/Field.java:9–71  ·  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 // Unique memory alias, not sensibly part of a "type" but very convenient here.
18 public final int _alias;
19 // Field must be written to exactly once, no more, no less
20 public final boolean _final;
21
22 private Field(String fname, Type type, int alias, boolean xfinal ) {
23 super(TFLD);
24 _fname = fname;
25 _type = type;
26 _alias = alias;
27 _final = xfinal;
28 }
29 // Make with existing alias
30 public static Field make( String fname, Type type, int alias, boolean xfinal ) {
31 return new Field(fname,type,alias,xfinal).intern();
32 }
33 public Field makeFrom( Type type ) {
34 return new Field(_fname,type,_alias,_final).intern();
35 }
36
37 public static final Field TEST = make("test",TypeInteger.ZERO,-2,false);
38 public static void gather(ArrayList<Type> ts) { ts.add(TEST); }
39
40 @Override Field xmeet( Type that ) {
41 Field fld = (Field)that; // Invariant
42 assert _fname.equals(fld._fname);
43 assert _alias==fld._alias;
44 assert _final==fld._final;
45 return make(_fname,_type.meet(fld._type),_alias,_final);
46 }
47
48 @Override
49 public Field dual() { return make(_fname,_type.dual(),_alias,_final); }
50
51 @Override
52 public Field glb() {
53 return make(_fname,_type.glb(),_alias,_final);
54 }
55
56 // Override in subclasses
57 int hash() { return _fname.hashCode() ^ _type.hashCode() ^ _alias ^ (_final ? 1024 : 0); }
58
59 boolean eq(Type t) {
60 Field f = (Field)t;
61 return _fname.equals(f._fname) && _type==f._type && _alias==f._alias && _final==f._final;
62 }
63
64
65 @Override
66 public StringBuilder print( StringBuilder sb ) {

Callers

nothing calls this directly

Calls 1

makeMethod · 0.95

Tested by

no test coverage detected