aa
com.cliffc.aa.HM.HM2.HMVar Class Reference
Inheritance diagram for com.cliffc.aa.HM.HM2.HMVar:
[legend]
Collaboration diagram for com.cliffc.aa.HM.HM2.HMVar:
[legend]

Public Member Functions

String _str ()
 
String str ()
 
String toString ()
 
Type type ()
 

Package Functions

 HMVar ()
 
 HMVar (Type t)
 
HMType _fresh (HashSet< HMVar > nongen, HashMap< HMType, HMType > vars)
 
HMType find ()
 
HMType fresh (HashSet< HMVar > nongen)
 
boolean is_top ()
 
boolean occurs_in (HashSet< HMVar >nongen)
 
boolean occurs_in (HMType[] args)
 
boolean occurs_in_type (HMType v)
 
HMType union (HMType that)
 

Static Package Functions

static void reset ()
 

Package Attributes

HMType _u
 

Private Attributes

Type _t
 
final int _uid
 

Static Private Attributes

static int CNT
 

Detailed Description

Definition at line 220 of file HM2.java.

Constructor & Destructor Documentation

◆ HMVar() [1/2]

com.cliffc.aa.HM.HM2.HMVar.HMVar ( )
package

Definition at line 224 of file HM2.java.

224 { this(Type.ANY); }

References com.cliffc.aa.type.Type< T extends Type< T >.ANY.

Referenced by com.cliffc.aa.HM.HM2.HMVar.union().

Here is the caller graph for this function:

◆ HMVar() [2/2]

com.cliffc.aa.HM.HM2.HMVar.HMVar ( Type  t)
package

Member Function Documentation

◆ _fresh()

HMType com.cliffc.aa.HM.HM2.HMType._fresh ( HashSet< HMVar nongen,
HashMap< HMType, HMType vars 
)
packageinherited

Definition at line 186 of file HM2.java.

186  {
187  HMType t2 = find();
188  if( t2 instanceof HMVar ) {
189  return t2.occurs_in(nongen) //
190  ? t2 // Keep same var
191  : vars.computeIfAbsent(t2, e -> new HMVar(((HMVar)t2)._t));
192  } else {
193  Oper op = (Oper)t2;
194  HMType[] args = new HMType[op._args.length];
195  for( int i=0; i<args.length; i++ )
196  args[i] = op._args[i]._fresh(nongen,vars);
197  return new Oper(op._name,args);
198  }
199  }

References com.cliffc.aa.HM.HM2.Oper._args, com.cliffc.aa.HM.HM2.HMType._fresh(), com.cliffc.aa.HM.HM2.Oper._name, com.cliffc.aa.HM.HM2.HMType.find(), and com.cliffc.aa.HM.HM2.HMType.occurs_in().

Referenced by com.cliffc.aa.HM.HM2.HMType._fresh(), and com.cliffc.aa.HM.HM2.HMType.fresh().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _str()

String com.cliffc.aa.HM.HM2.HMVar._str ( )

Reimplemented from com.cliffc.aa.HM.HM2.HMType.

Definition at line 233 of file HM2.java.

233  {
234  String s = "v"+_uid;
235  if( _t!=Type.ANY ) s += ":"+_t.str(new SB(),new VBitSet(),null,false);
236  return s;
237  }

References com.cliffc.aa.HM.HM2.HMVar._t, com.cliffc.aa.HM.HM2.HMVar._uid, com.cliffc.aa.type.Type< T extends Type< T >.ANY, and com.cliffc.aa.type.Type< T extends Type< T >.str().

Referenced by com.cliffc.aa.HM.HM2.HMVar.toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find()

HMType com.cliffc.aa.HM.HM2.HMVar.find ( )
package

Reimplemented from com.cliffc.aa.HM.HM2.HMType.

Definition at line 239 of file HM2.java.

239  {
240  HMType u = _u;
241  if( u==null ) return this; // Top of union tree
242  if( u._u==null ) return u; // One-step from top
243  // Classic U-F rollup
244  while( u._u!=null ) u = u._u; // Find the top
245  HMType x = this; // Collapse all to top
246  while( x._u!=u ) { HMType tmp = x._u; x._u=u; x=tmp;}
247  return u;
248  }

References com.cliffc.aa.HM.HM2.HMType._u.

Referenced by com.cliffc.aa.HM.HM2.HMVar.union().

Here is the caller graph for this function:

◆ fresh()

HMType com.cliffc.aa.HM.HM2.HMType.fresh ( HashSet< HMVar nongen)
packageinherited

Definition at line 182 of file HM2.java.

182  {
183  HashMap<HMType,HMType> vars = new HashMap<>();
184  return _fresh(nongen,vars);
185  }

References com.cliffc.aa.HM.HM2.HMType._fresh().

Referenced by com.cliffc.aa.HM.HM2.Ident.hm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_top()

boolean com.cliffc.aa.HM.HM2.HMType.is_top ( )
packageinherited

Definition at line 180 of file HM2.java.

180 { return _u==null; }

References com.cliffc.aa.HM.HM2.HMType._u.

Referenced by com.cliffc.aa.HM.HM2.HMType.occurs_in_type(), and com.cliffc.aa.HM.HM2.HMVar.type().

Here is the caller graph for this function:

◆ occurs_in() [1/2]

boolean com.cliffc.aa.HM.HM2.HMType.occurs_in ( HashSet< HMVar nongen)
packageinherited

Definition at line 201 of file HM2.java.

201  {
202  for( HMVar x : nongen ) if( occurs_in_type(x) ) return true;
203  return false;
204  }

References com.cliffc.aa.HM.HM2.HMType.occurs_in_type().

Referenced by com.cliffc.aa.HM.HM2.HMType._fresh(), and com.cliffc.aa.HM.HM2.HMType.occurs_in_type().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ occurs_in() [2/2]

boolean com.cliffc.aa.HM.HM2.HMType.occurs_in ( HMType[]  args)
packageinherited

Definition at line 205 of file HM2.java.

205  {
206  for( HMType x : args ) if( occurs_in_type(x) ) return true;
207  return false;
208  }

References com.cliffc.aa.HM.HM2.HMType.occurs_in_type().

Here is the call graph for this function:

◆ occurs_in_type()

boolean com.cliffc.aa.HM.HM2.HMType.occurs_in_type ( HMType  v)
packageinherited

Definition at line 209 of file HM2.java.

209  {
210  assert is_top();
211  HMType y = v.find();
212  if( y==this )
213  return true;
214  if( y instanceof Oper )
215  return occurs_in(((Oper)y)._args);
216  return false;
217  }

References com.cliffc.aa.HM.HM2.HMType.find(), com.cliffc.aa.HM.HM2.HMType.is_top(), and com.cliffc.aa.HM.HM2.HMType.occurs_in().

Referenced by com.cliffc.aa.HM.HM2.HMType.occurs_in(), and com.cliffc.aa.HM.HM2.HMVar.union().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset()

static void com.cliffc.aa.HM.HM2.HMVar.reset ( )
staticpackage

Definition at line 226 of file HM2.java.

226 { CNT=1; }

References com.cliffc.aa.HM.HM2.HMVar.CNT.

Referenced by com.cliffc.aa.HM.HM2.reset().

Here is the caller graph for this function:

◆ str()

String com.cliffc.aa.HM.HM2.HMType.str ( )
inherited

Definition at line 178 of file HM2.java.

178 { return find()._str(); }

References com.cliffc.aa.HM.HM2.HMType._str(), and com.cliffc.aa.HM.HM2.HMType.find().

Referenced by com.cliffc.aa.HM.HM2.Oper._str().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

String com.cliffc.aa.HM.HM2.HMVar.toString ( )

Definition at line 228 of file HM2.java.

228  {
229  String s = _str();
230  if( _u!=null ) s += ">>"+_u;
231  return s;
232  }

References com.cliffc.aa.HM.HM2.HMVar._str(), and com.cliffc.aa.HM.HM2.HMType._u.

Here is the call graph for this function:

◆ type()

Type com.cliffc.aa.HM.HM2.HMVar.type ( )

Definition at line 227 of file HM2.java.

227 { assert is_top(); return _t; }

References com.cliffc.aa.HM.HM2.HMVar._t, and com.cliffc.aa.HM.HM2.HMType.is_top().

Here is the call graph for this function:

◆ union()

HMType com.cliffc.aa.HM.HM2.HMVar.union ( HMType  that)
package

Reimplemented from com.cliffc.aa.HM.HM2.HMType.

Definition at line 249 of file HM2.java.

249  {
250  if( _u!=null ) return find().union(that);
251  if( that instanceof HMVar ) that = that.find();
252  if( this==that ) return this; // Do nothing
253  if( occurs_in_type(that) )
254  throw new RuntimeException("recursive unification");
255 
256  if( that instanceof HMVar ) {
257  HMVar v2 = (HMVar)that;
258  v2._t = _t.meet(v2._t);
259  }
260  else assert _t==Type.ANY; // Else this var is un-MEETd with any Con
261  return _u = that; // Classic U-F union
262  }

References com.cliffc.aa.HM.HM2.HMVar._t, com.cliffc.aa.HM.HM2.HMType._u, com.cliffc.aa.type.Type< T extends Type< T >.ANY, com.cliffc.aa.HM.HM2.HMType.find(), com.cliffc.aa.HM.HM2.HMVar.find(), com.cliffc.aa.HM.HM2.HMVar.HMVar(), com.cliffc.aa.type.Type< T extends Type< T >.meet(), com.cliffc.aa.HM.HM2.HMType.occurs_in_type(), and com.cliffc.aa.HM.HM2.HMType.union().

Referenced by com.cliffc.aa.HM.HM2.Let.hm().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _t

◆ _u

HMType com.cliffc.aa.HM.HM2.HMType._u
packageinherited

◆ _uid

final int com.cliffc.aa.HM.HM2.HMVar._uid
private

Definition at line 222 of file HM2.java.

Referenced by com.cliffc.aa.HM.HM2.HMVar._str(), and com.cliffc.aa.HM.HM2.HMVar.HMVar().

◆ CNT

int com.cliffc.aa.HM.HM2.HMVar.CNT
staticprivate

Definition at line 223 of file HM2.java.

Referenced by com.cliffc.aa.HM.HM2.HMVar.HMVar(), and com.cliffc.aa.HM.HM2.HMVar.reset().


The documentation for this class was generated from the following file:
com.cliffc.aa.HM.HM2.HMVar.CNT
static int CNT
Definition: HM2.java:223
com.cliffc.aa.HM.HM2.HMType._u
HMType _u
Definition: HM2.java:175
com.cliffc.aa.type.Type
an implementation of language AA
Definition: Type.java:94
com.cliffc.aa.HM.HM2.HMType.is_top
boolean is_top()
Definition: HM2.java:180
com.cliffc.aa.type.Type.ANY
static final Type ANY
Definition: Type.java:325
com.cliffc.aa.type.Type.meet
final Type meet(Type t)
Definition: Type.java:412
com.cliffc.aa.type.Type.str
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Definition: Type.java:131
com.cliffc.aa.HM.HM2.HMType.union
abstract HMType union(HMType t)
com.cliffc.aa.HM.HM2.HMType._fresh
HMType _fresh(HashSet< HMVar > nongen, HashMap< HMType, HMType > vars)
Definition: HM2.java:186
com.cliffc.aa.HM.HM2.HMVar.HMVar
HMVar()
Definition: HM2.java:224
com.cliffc.aa.HM.HM2.HMType.occurs_in
boolean occurs_in(HashSet< HMVar >nongen)
Definition: HM2.java:201
com.cliffc.aa.HM.HM2.HMType.find
abstract HMType find()
com.cliffc.aa.HM.HM2.HMVar._uid
final int _uid
Definition: HM2.java:222
com.cliffc.aa.HM.HM2.HMType.occurs_in_type
boolean occurs_in_type(HMType v)
Definition: HM2.java:209
com.cliffc.aa.util.VBitSet
Definition: VBitSet.java:5
com.cliffc.aa.HM.HM2.HMVar._t
Type _t
Definition: HM2.java:221
com.cliffc.aa.util.SB
Tight/tiny StringBuilder wrapper.
Definition: SB.java:8
com.cliffc.aa.HM.HM2.HMVar._str
String _str()
Definition: HM2.java:233
com.cliffc.aa.HM.HM2.HMType._str
abstract String _str()
com.cliffc.aa.HM.HM2.HMVar.find
HMType find()
Definition: HM2.java:239