public override bool IsSubtypeOf(CatKind k) { if (k.IsAny()) { return(true); } if (k is CatStackVar) { return(true); } if (!(k is CatTypeVector)) { return(false); } CatTypeVector v1 = this; CatTypeVector v2 = k as CatTypeVector; while (!v1.IsEmpty() && !v2.IsEmpty()) { CatKind t1 = v1.GetTop(); CatKind t2 = v2.GetTop(); if (!t1.IsSubtypeOf(t2)) { return(false); } v1 = v1.GetRest(); v2 = v2.GetRest(); } // v1 has to be at least as long to be a subtype if (v1.IsEmpty() && !v2.IsEmpty()) { return(false); } return(true); }
public override bool Equals(CatKind k) { if (!(k is CatTypeVector)) { return(false); } CatTypeVector v1 = this; CatTypeVector v2 = k as CatTypeVector; while (!v1.IsEmpty() && !v2.IsEmpty()) { CatKind t1 = v1.GetTop(); CatKind t2 = v2.GetTop(); if (!t1.Equals(t2)) { return(false); } v1 = v1.GetRest(); v2 = v2.GetRest(); } if (!v1.IsEmpty()) { return(false); } if (!v2.IsEmpty()) { return(false); } return(true); }
static CatTypeVector RenameVars(CatTypeVector vec, CatTypeVarList vars) { CatTypeVector ret = new CatTypeVector(); foreach (CatKind k in vec.GetKinds()) { if (k.IsKindVar() && vars.ContainsKey(k.ToString())) { ret.Add(vars[k.ToString()]); } else if (k is CatFxnType) { ret.Add(RenameVars(ret, vars)); } else if (k is CatTypeVector) { throw new Exception("unexpected type vector in function during renaming"); } else { ret.Add(k); } } return(ret); }
public CatFxnType() { mbSideEffects = false; mCons = new CatTypeVector(); mProd = new CatTypeVector(); SetChildFxnParents(); ComputeFreeVars(); }
public CatFxnType(AstFxnType node) { mbSideEffects = node.HasSideEffects(); mCons = new CatTypeVector(node.mCons); mProd = new CatTypeVector(node.mProd); SetChildFxnParents(); ComputeFreeVars(); }
public CatFxnType(CatTypeVector cons, CatTypeVector prod, bool bSideEffects) { mCons = new CatTypeVector(cons); mProd = new CatTypeVector(prod); mbSideEffects = bSideEffects; SetChildFxnParents(); ComputeFreeVars(); }
public CatFxnType CatFxnTypeFromRelation(Relation rel) { CatTypeVector cons = CatTypeVectorFromVec(rel.GetLeft()); CatTypeVector prod = CatTypeVectorFromVec(rel.GetRight()); // TODO: add the boolean as a third value in the vector. // it becomes a variable when unknown, and is resolved otherwise. return(new CatFxnType(cons, prod, false)); }
public CatTypeVector CatTypeVectorFromVec(Vector vec) { CatTypeVector ret = new CatTypeVector(); foreach (Constraint c in vec) { ret.PushKindBottom(ConstraintToCatKind(c)); } return(ret); }
public Vector TypeVectorToConstraintVector(CatTypeVector x) { Vector vec = new Vector(); foreach (CatKind k in x.GetKinds()) { vec.Insert(0, CatKindToConstraint(k)); } return(vec); }
public CatTypeVector Clone() { CatTypeVector ret = new CatTypeVector(); foreach (CatKind k in GetKinds()) { ret.Add(k); } return(ret); }
public CatTypeVector Rename(CatTypeVector s) { CatTypeVector ret = new CatTypeVector(); foreach (CatKind k in s.GetKinds()) { ret.Add(Rename(k)); } return(ret); }
public virtual CatFxnType AddImplicitRhoVariables() { CatTypeVector cons = AddImplicitRhoVariables(GetCons()); CatTypeVector prod = AddImplicitRhoVariables(GetProd()); if (!(cons.GetBottom() is CatStackVar)) { CatStackVar rho = CatStackVar.CreateUnique(); cons.PushKindBottom(rho); prod.PushKindBottom(rho); } return(new CatFxnType(cons, prod, HasSideEffects())); }
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); }
private CatTypeVector AddImplicitRhoVariables(CatTypeVector v) { CatTypeVector ret = new CatTypeVector(); foreach (CatKind k in v.GetKinds()) { if (k is CatFxnType) { ret.Add((k as CatFxnType).AddImplicitRhoVariables()); } else if (k is CatTypeVector) { ret.Add(AddImplicitRhoVariables(k as CatTypeVector)); } else { ret.Add(k); } } return(ret); }
public static string ToPrettyString(CatTypeVector vec, Dictionary <string, string> dic) { string s = ""; for (int i = 0; i < vec.GetKinds().Count; ++i) { if (i > 0) { s += " "; } CatKind k = vec.GetKinds()[i]; if (k.IsKindVar()) { if (!dic.ContainsKey(k.ToString())) { string sNew = IntToPrettyString(dic.Count); if (k is CatStackVar) { sNew = sNew.ToUpper(); } dic.Add(k.ToString(), sNew); } s += dic[k.ToString()]; } else if (k is CatFxnType) { s += "(" + ToPrettyString(k as CatFxnType, dic) + ")"; } else if (k is CatTypeVector) { s += ToPrettyString(k as CatFxnType, dic); } else { s += k.ToString(); } } return(s); }
public bool IsValidProduction(List <string> varNames, CatTypeVector prod) { foreach (CatKind k in prod.GetKinds()) { if (k is CatFxnType) { GetConsVarNames(varNames, k as CatFxnType); } } foreach (CatKind k in prod.GetKinds()) { if (k.IsKindVar()) { if (!varNames.Contains(k.ToString())) { return(false); } } } return(true); }
public CatTypeVector(CatTypeVector k) { mList = new List <CatKind>(k.mList); }