/// <summary> /// This function modifies the function /// </summary> public void RemoveImplicitRhoVariables(CatFxnType ft) { foreach (CatKind k in ft.GetChildKinds()) { if (k is CatFxnType) { RemoveImplicitRhoVariables(k as CatFxnType); } } if (!ft.GetCons().IsEmpty() && !ft.GetProd().IsEmpty()) { CatKind k1 = ft.GetCons().GetBottom(); CatKind k2 = ft.GetProd().GetBottom(); // Does both consumption and production share the same // stack variable at the bottom, if so, then we might have // an implicit Rho variables if (k1 is CatStackVar && k1.Equals(k2)) { // try removing the stack variable ft.GetCons().GetKinds().RemoveAt(0); ft.GetProd().GetKinds().RemoveAt(0); // is the variable used anywhere else? // if so, then we have to restore it // otherwise we leave it taken away if (DoesVarExist(k1)) { ft.GetCons().GetKinds().Insert(0, k1); ft.GetProd().GetKinds().Insert(0, k2); } } } }
public Relation FxnTypeToRelation(CatFxnType ft) { Vector cons = TypeVectorToConstraintVector(ft.GetCons()); Vector prod = TypeVectorToConstraintVector(ft.GetProd()); Relation r = new Relation(cons, prod); return r; }
public Relation FxnTypeToRelation(CatFxnType ft) { Vector cons = TypeVectorToConstraintVector(ft.GetCons()); Vector prod = TypeVectorToConstraintVector(ft.GetProd()); Relation r = new Relation(cons, prod); return(r); }
public CatFxnType Rename(CatFxnType f) { if (f == null) { throw new Exception("Invalid null parameter to rename function"); } return(new CatFxnType(Rename(f.GetCons()), Rename(f.GetProd()), f.HasSideEffects())); }
/// <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 IsValidChildFxn(List <string> varNames, CatFxnType ft) { foreach (CatKind k in ft.GetCons().GetKinds()) { if (k.IsKindVar()) { varNames.Add(k.ToString()); } } return(IsValidProduction(varNames, ft.GetProd())); }
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 CatFxnType Unquote(CatFxnType ft) { if (ft == null) return null; if (ft.GetCons().GetKinds().Count > 0) throw new Exception("Can't unquote a function type with a consumption size greater than zero"); if (ft.GetProd().GetKinds().Count != 1) throw new Exception("Can't unquote a function type which does not produce a single function"); CatKind k = ft.GetProd().GetKinds()[0]; if (!(k is CatFxnType)) throw new Exception("Can't unquote a function type which does not produce a single function"); return k as CatFxnType; }
public void GetConsVarNames(List <string> varNames, CatFxnType ft) { foreach (CatKind k in ft.GetCons().GetKinds()) { if (k.IsKindVar()) { varNames.Add(k.ToString()); } if (k is CatFxnType) { GetConsVarNames(varNames, k as CatFxnType); } } }
public static string ToPrettyString(CatFxnType ft, Dictionary <string, string> dic) { // remove rho variables ft = ft.Clone(); ft.RemoveImplicitRhoVariables(); string s = ToPrettyString(ft.GetCons(), dic); if (ft.HasSideEffects()) { s += " ~> "; } else { s += " -> "; } s += ToPrettyString(ft.GetProd(), dic); return(s); }
public static CatFxnType Unquote(CatFxnType ft) { if (ft == null) { return(null); } if (ft.GetCons().GetKinds().Count > 0) { throw new Exception("Can't unquote a function type with a consumption size greater than zero"); } if (ft.GetProd().GetKinds().Count != 1) { throw new Exception("Can't unquote a function type which does not produce a single function"); } CatKind k = ft.GetProd().GetKinds()[0]; if (!(k is CatFxnType)) { throw new Exception("Can't unquote a function type which does not produce a single function"); } return(k as CatFxnType); }
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); }
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); }
static CatFxnType RenameVars(CatFxnType ft, CatTypeVarList vars) { return(new CatFxnType(RenameVars(ft.GetCons(), vars), RenameVars(ft.GetProd(), vars), ft.HasSideEffects())); }
/// <summary> /// This function modifies the function /// </summary> public void RemoveImplicitRhoVariables(CatFxnType ft) { foreach (CatKind k in ft.GetChildKinds()) if (k is CatFxnType) RemoveImplicitRhoVariables(k as CatFxnType); if (!ft.GetCons().IsEmpty() && !ft.GetProd().IsEmpty()) { CatKind k1 = ft.GetCons().GetBottom(); CatKind k2 = ft.GetProd().GetBottom(); // Does both consumption and production share the same // stack variable at the bottom, if so, then we might have // an implicit Rho variables if (k1 is CatStackVar && k1.Equals(k2)) { // try removing the stack variable ft.GetCons().GetKinds().RemoveAt(0); ft.GetProd().GetKinds().RemoveAt(0); // is the variable used anywhere else? // if so, then we have to restore it // otherwise we leave it taken away if (DoesVarExist(k1)) { ft.GetCons().GetKinds().Insert(0, k1); ft.GetProd().GetKinds().Insert(0, k2); } } } }
public static string ToPrettyString(CatFxnType ft, Dictionary<string, string> dic) { // remove rho variables ft = ft.Clone(); ft.RemoveImplicitRhoVariables(); string s = ToPrettyString(ft.GetCons(), dic); if (ft.HasSideEffects()) s += " ~> "; else s += " -> "; s += ToPrettyString(ft.GetProd(), dic); return s; }
public CatFxnType Rename(CatFxnType f) { if (f == null) throw new Exception("Invalid null parameter to rename function"); return new CatFxnType(Rename(f.GetCons()), Rename(f.GetProd()), f.HasSideEffects()); }
static CatFxnType RenameVars(CatFxnType ft, CatTypeVarList vars) { return new CatFxnType(RenameVars(ft.GetCons(), vars), RenameVars(ft.GetProd(), vars), ft.HasSideEffects()); }
public bool IsValidChildFxn(List<string> varNames, CatFxnType ft) { foreach (CatKind k in ft.GetCons().GetKinds()) { if (k.IsKindVar()) varNames.Add(k.ToString()); } return IsValidProduction(varNames, ft.GetProd()); }
public void GetConsVarNames(List<string> varNames, CatFxnType ft) { foreach (CatKind k in ft.GetCons().GetKinds()) { if (k.IsKindVar()) varNames.Add(k.ToString()); if (k is CatFxnType) GetConsVarNames(varNames, k as CatFxnType); } }