These types are part of a Monotone Analysis Framework, @see see for example this set of slides . The types form a lattice; @see a symmetric comple
| 21 | */ |
| 22 | |
| 23 | public class Type { |
| 24 | static final HashMap<Type,Type> INTERN = new HashMap<>(); |
| 25 | |
| 26 | // ---------------------------------------------------------- |
| 27 | // Simple types are implemented fully here. "Simple" means: the code and |
| 28 | // type hierarchy are simple, not that the Type is conceptually simple. |
| 29 | static final byte TBOT = 0; // Bottom (ALL) |
| 30 | static final byte TTOP = 1; // Top (ANY) |
| 31 | static final byte TCTRL = 2; // Ctrl flow bottom |
| 32 | static final byte TXCTRL = 3; // Ctrl flow top (mini-lattice: any-xctrl-ctrl-all) |
| 33 | static final byte TSIMPLE = 4; // End of the Simple Types |
| 34 | static final byte TINT = 5; // All Integers; see TypeInteger |
| 35 | static final byte TTUPLE = 6; // Tuples; finite collections of unrelated Types, kept in parallel |
| 36 | |
| 37 | public final byte _type; |
| 38 | |
| 39 | public boolean is_simple() { return _type < TSIMPLE; } |
| 40 | private static final String[] STRS = new String[]{"Bot","Top","Ctrl","~Ctrl"}; |
| 41 | protected Type(byte type) { _type = type; } |
| 42 | |
| 43 | public static final Type BOTTOM = new Type( TBOT ).intern(); // ALL |
| 44 | public static final Type TOP = new Type( TTOP ).intern(); // ANY |
| 45 | public static final Type CONTROL = new Type( TCTRL ).intern(); // Ctrl |
| 46 | public static final Type XCONTROL = new Type( TXCTRL ).intern(); // ~Ctrl |
| 47 | |
| 48 | // Is high or on the lattice centerline. |
| 49 | public boolean isHighOrConst() { return _type==TTOP || _type==TXCTRL; } |
| 50 | |
| 51 | // Strict constant values, things on the lattice centerline. |
| 52 | // Excludes both high and low values |
| 53 | public boolean isConstant() { return false; } |
| 54 | |
| 55 | public StringBuilder print(StringBuilder sb) {return is_simple() ? sb.append(STRS[_type]) : sb;} |
| 56 | |
| 57 | // ---------------------------------------------------------- |
| 58 | |
| 59 | // Factory method which interns "this" |
| 60 | protected <T extends Type> T intern() { |
| 61 | T nnn = (T)INTERN.get(this); |
| 62 | if( nnn==null ) |
| 63 | INTERN.put(nnn=(T)this,this); |
| 64 | return nnn; |
| 65 | } |
| 66 | |
| 67 | private int _hash; // Hash cache; not-zero when set. |
| 68 | @Override |
| 69 | public final int hashCode() { |
| 70 | if( _hash!=0 ) return _hash; |
| 71 | _hash = hash(); |
| 72 | if( _hash==0 ) _hash = 0xDEADBEEF; // Bad hash from subclass; use some junk thing |
| 73 | return _hash; |
| 74 | } |
| 75 | // Override in subclasses |
| 76 | int hash() { return _type; } |
| 77 | |
| 78 | @Override |
| 79 | public final boolean equals( Object o ) { |
| 80 | if( o==this ) return true; |