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

Public Member Functions

SB _str (SB sb, VBitSet dups, boolean debug)
 
String str ()
 
final 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 205 of file HM1.java.

Constructor & Destructor Documentation

◆ HMVar() [1/2]

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

Definition at line 209 of file HM1.java.

209 { this(Type.ANY); }

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

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

Here is the caller graph for this function:

◆ HMVar() [2/2]

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

Member Function Documentation

◆ _fresh()

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

Definition at line 171 of file HM1.java.

171  {
172  HMType t2 = find();
173  if( t2 instanceof HMVar ) {
174  return t2.occurs_in(nongen) //
175  ? t2 // Keep same var
176  : vars.computeIfAbsent(t2, e -> new HMVar(((HMVar)t2)._t));
177  } else {
178  Oper op = (Oper)t2;
179  HMType[] args = new HMType[op._args.length];
180  for( int i=0; i<args.length; i++ )
181  args[i] = op._args[i]._fresh(nongen,vars);
182  return new Oper(op._name,args);
183  }
184  }

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

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

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

◆ _str()

SB com.cliffc.aa.HM.HM1.HMVar._str ( SB  sb,
VBitSet  dups,
boolean  debug 
)

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

Definition at line 213 of file HM1.java.

213  {
214  if( _u!=null && !debug ) return _u._str(sb,dups,debug);
215  sb.p("v").p(_uid);
216  if( dups.tset(_uid) ) return sb.p("$");
217  if( _t!=Type.ANY ) _t.str(sb.p(":"),dups,null,false);
218  if( _u!=null ) _u._str(sb.p(">>"),dups,debug);
219  return sb;
220  }

References com.cliffc.aa.HM.HM1.HMType._str(), com.cliffc.aa.HM.HM1.HMVar._t, com.cliffc.aa.HM.HM1.HMType._u, com.cliffc.aa.HM.HM1.HMVar._uid, com.cliffc.aa.type.Type< T extends Type< T >.ANY, com.cliffc.aa.util.SB.p(), com.cliffc.aa.type.Type< T extends Type< T >.str(), and com.cliffc.aa.util.VBitSet.tset().

Here is the call graph for this function:

◆ find()

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

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

Definition at line 222 of file HM1.java.

222  {
223  HMType u = _u;
224  if( u==null ) return this; // Top of union tree
225  if( u._u==null ) return u; // One-step from top
226  // Classic U-F rollup
227  while( u._u!=null ) u = u._u; // Find the top
228  HMType x = this; // Collapse all to top
229  while( x._u!=u ) { HMType tmp = x._u; x._u=u; x=tmp;}
230  return u;
231  }

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

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

Here is the caller graph for this function:

◆ fresh()

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

Definition at line 167 of file HM1.java.

167  {
168  HashMap<HMType,HMType> vars = new HashMap<>();
169  return _fresh(nongen,vars);
170  }

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

Referenced by com.cliffc.aa.HM.HM1.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.HM1.HMType.is_top ( )
packageinherited

Definition at line 165 of file HM1.java.

165 { return _u==null; }

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

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

Here is the caller graph for this function:

◆ occurs_in() [1/2]

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

Definition at line 186 of file HM1.java.

186  {
187  for( HMVar x : nongen ) if( occurs_in_type(x) ) return true;
188  return false;
189  }

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

Referenced by com.cliffc.aa.HM.HM1.HMType._fresh(), and com.cliffc.aa.HM.HM1.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.HM1.HMType.occurs_in ( HMType[]  args)
packageinherited

Definition at line 190 of file HM1.java.

190  {
191  for( HMType x : args ) if( occurs_in_type(x) ) return true;
192  return false;
193  }

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

Here is the call graph for this function:

◆ occurs_in_type()

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

Definition at line 194 of file HM1.java.

194  {
195  assert is_top();
196  HMType y = v.find();
197  if( y==this )
198  return true;
199  if( y instanceof Oper )
200  return occurs_in(((Oper)y)._args);
201  return false;
202  }

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

Referenced by com.cliffc.aa.HM.HM1.HMType.occurs_in(), and com.cliffc.aa.HM.HM1.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.HM1.HMVar.reset ( )
staticpackage

Definition at line 211 of file HM1.java.

211 { CNT=1; }

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

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

Here is the caller graph for this function:

◆ str()

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

Definition at line 163 of file HM1.java.

163 { return _str(new SB(),new VBitSet(),false).toString(); }

References com.cliffc.aa.HM.HM1.HMType._str(), and com.cliffc.aa.util.SB.toString().

Here is the call graph for this function:

◆ toString()

final String com.cliffc.aa.HM.HM1.HMType.toString ( )
inherited

Definition at line 162 of file HM1.java.

162 { return _str(new SB(),new VBitSet(),true).toString(); }

References com.cliffc.aa.HM.HM1.HMType._str(), and com.cliffc.aa.util.SB.toString().

Here is the call graph for this function:

◆ type()

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

Definition at line 212 of file HM1.java.

212 { assert is_top(); return _t; }

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

Here is the call graph for this function:

◆ union()

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

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

Definition at line 232 of file HM1.java.

232  {
233  if( _u!=null ) return find().union(that);
234  if( that instanceof HMVar ) that = that.find();
235  if( this==that ) return this; // Do nothing
236  if( occurs_in_type(that) )
237  throw new RuntimeException("recursive unification");
238 
239  if( that instanceof HMVar ) {
240  HMVar v2 = (HMVar)that;
241  v2._t = _t.meet(v2._t);
242  }
243  else assert _t==Type.ANY; // Else this var is un-MEETd with any Con
244  return _u = that; // Classic U-F union
245  }

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

Referenced by com.cliffc.aa.HM.HM1.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.HM1.HMType._u
packageinherited

◆ _uid

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

Definition at line 207 of file HM1.java.

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

◆ CNT

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

Definition at line 208 of file HM1.java.

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


The documentation for this class was generated from the following file:
com.cliffc.aa.HM.HM1.HMType._str
abstract SB _str(SB sb, VBitSet vbs, boolean debug)
com.cliffc.aa.HM.HM1.HMType._fresh
HMType _fresh(HashSet< HMVar > nongen, HashMap< HMType, HMType > vars)
Definition: HM1.java:171
com.cliffc.aa.type.Type
an implementation of language AA
Definition: Type.java:94
com.cliffc.aa.HM.HM1.HMVar.HMVar
HMVar()
Definition: HM1.java:209
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.HM.HM1.HMType.occurs_in_type
boolean occurs_in_type(HMType v)
Definition: HM1.java:194
com.cliffc.aa.type.Type.str
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Definition: Type.java:131
com.cliffc.aa.HM.HM1.HMType.is_top
boolean is_top()
Definition: HM1.java:165
com.cliffc.aa.HM.HM1.HMVar._uid
final int _uid
Definition: HM1.java:207
com.cliffc.aa.util.VBitSet.tset
boolean tset(int idx)
Definition: VBitSet.java:7
com.cliffc.aa.HM.HM1.HMVar.CNT
static int CNT
Definition: HM1.java:208
com.cliffc.aa.HM.HM1.HMVar._t
Type _t
Definition: HM1.java:206
com.cliffc.aa.HM.HM1.HMVar.find
HMType find()
Definition: HM1.java:222
com.cliffc.aa.util.VBitSet
Definition: VBitSet.java:5
com.cliffc.aa.util.SB
Tight/tiny StringBuilder wrapper.
Definition: SB.java:8
com.cliffc.aa.util.SB.p
SB p(String s)
Definition: SB.java:13
com.cliffc.aa.HM.HM1.HMType.occurs_in
boolean occurs_in(HashSet< HMVar >nongen)
Definition: HM1.java:186
com.cliffc.aa.HM.HM1.HMType.union
abstract HMType union(HMType t)
com.cliffc.aa.HM.HM1.HMType._u
HMType _u
Definition: HM1.java:159
com.cliffc.aa.util.SB.toString
String toString()
Definition: SB.java:62
com.cliffc.aa.HM.HM1.HMType.find
abstract HMType find()