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 CatFxnType() { mbSideEffects = false; mCons = new CatTypeVector(); mProd = new CatTypeVector(); SetChildFxnParents(); ComputeFreeVars(); }
public CatFxnType(CatTypeVector cons, CatTypeVector prod, bool bSideEffects) { mCons = new CatTypeVector(cons); mProd = new CatTypeVector(prod); mbSideEffects = bSideEffects; SetChildFxnParents(); ComputeFreeVars(); }
public CatTypeVector Rename(CatTypeVector s) { CatTypeVector ret = new CatTypeVector(); foreach (CatKind k in s.GetKinds()) ret.Add(Rename(k)); return ret; }
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 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 CatFxnType(AstFxnType node) { mbSideEffects = node.HasSideEffects(); mCons = new CatTypeVector(node.mCons); mProd = new CatTypeVector(node.mProd); SetChildFxnParents(); ComputeFreeVars(); }
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 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; }