public CatClass(CatClass o, string s, CatKind k) { foreach (KeyValuePair<string, CatKind> kvp in o.GetFields()) mpFields.Add(kvp.Key, kvp.Value); mpFields.Add(s, k); }
public CatKind Rename(CatKind k) { if (k is CatFxnType) return Rename(k as CatFxnType); else if (k is CatTypeKind) return Rename(k as CatTypeKind); else if (k is CatStackVar) return Rename(k as CatStackVar); else if (k is CatTypeVector) return Rename(k as CatTypeVector); else if (k is CatCustomKind) return k; else if (k is CatRecursiveType) return k; else throw new Exception(k.ToString() + " is an unrecognized kind"); }
public Constraint CatKindToConstraint(CatKind k) { if (k is CatTypeVector) { return TypeVectorToConstraintVector(k as CatTypeVector); } else if (k is CatFxnType) { return FxnTypeToRelation(k as CatFxnType); } else if (k.IsKindVar()) { return KindVarToConstraintVar(k); } else { return new Constant(k.ToIdString()); } }
public static bool IsFreeVar(CatKind k, CatFxnType left, CatFxnType right, CatFxnType except) { return !DoesVarOccurIn(k, left, except) && !DoesVarOccurIn(k, right, except); }
public static bool DoesVarOccurIn(CatKind k, CatFxnType ft, CatFxnType except) { if (!k.IsKindVar()) return false; if (k == except) return false; return DoesVarOccurIn(k, ft.GetCons(), except) || DoesVarOccurIn(k, ft.GetProd(), except); }
public static bool DoesVarOccurIn(CatKind k, CatTypeVector vec, CatFxnType except) { foreach (CatKind tmp in vec.GetKinds()) { if (tmp.IsKindVar() && tmp.Equals(k)) return true; if (tmp is CatFxnType) if (DoesVarOccurIn(k, tmp as CatFxnType, except)) return true; } return false; }
public override bool Equals(CatKind k) { return k is CatRecursiveType; }
public CatQuotedType(CatKind k) { GetProd().Add(k); }
public override bool IsSubtypeOf(CatKind k) { if (k.IsAny() || k.IsDynFxn()) return IsRuntimePolymorphic(); if (k is CatTypeVar) return true; if (!(k is CatFxnType)) return false; CatFxnType f = k as CatFxnType; bool ret = GetCons().IsSubtypeOf(f.GetCons()) && GetProd().IsSubtypeOf(f.GetProd()); if (HasSideEffects()) ret = ret && f.HasSideEffects(); return ret; }
/// <summary> /// This is a raw equivalency check: no normalization is done. /// To comparse function type normally you would use CompareFxnTypes, /// which in turn calls this function. /// </summary> public override bool Equals(CatKind k) { if (!(k is CatFxnType)) return false; CatFxnType f = k as CatFxnType; return (GetCons().Equals(f.GetCons()) && GetProd().Equals(f.GetProd()) && HasSideEffects() == f.HasSideEffects()); }
public bool IsFreeVar(CatKind var) { if (!var.IsKindVar()) return false; return mpFreeVars.ContainsKey(var.ToString()); }
private bool IsFreeVar(CatKind k, CatVarScopes scopes) { return scopes.IsFreeVar(this, k); }
public bool DoesVarExist(CatKind k) { Trace.Assert(k.IsKindVar()); foreach (CatKind tmp in GetDescendantKinds()) if (tmp.Equals(k)) return true; return false; }
public Constraint KindVarToConstraintVar(CatKind k) { Trace.Assert(k.IsKindVar()); return CreateVar(k.ToString().Substring(1)); }
public CatClass AddFieldType(string s, CatKind k) { return new CatClass(this, s, k); }