Exemplo n.º 1
0
        /// <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);
                    }
                }
            }
        }
Exemplo n.º 2
0
 public Relation FxnTypeToRelation(CatFxnType ft)
 {
     Vector cons = TypeVectorToConstraintVector(ft.GetCons());
     Vector prod = TypeVectorToConstraintVector(ft.GetProd());
     Relation r = new Relation(cons, prod);
     return r;
 }
Exemplo n.º 3
0
        public Relation FxnTypeToRelation(CatFxnType ft)
        {
            Vector   cons = TypeVectorToConstraintVector(ft.GetCons());
            Vector   prod = TypeVectorToConstraintVector(ft.GetProd());
            Relation r    = new Relation(cons, prod);

            return(r);
        }
Exemplo n.º 4
0
 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()));
 }
Exemplo n.º 5
0
        /// <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());
        }
Exemplo n.º 6
0
 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()));
 }
Exemplo n.º 7
0
 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));
 }
Exemplo n.º 8
0
 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;
 }
Exemplo n.º 9
0
 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);
         }
     }
 }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
0
 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);
 }
Exemplo n.º 14
0
 static CatFxnType RenameVars(CatFxnType ft, CatTypeVarList vars)
 {
     return(new CatFxnType(RenameVars(ft.GetCons(), vars), RenameVars(ft.GetProd(), vars), ft.HasSideEffects()));
 }
Exemplo n.º 15
0
        /// <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);
                    }                
                }
            }
        }
Exemplo n.º 16
0
        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;
        }
Exemplo n.º 17
0
 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());
 }
Exemplo n.º 18
0
 static CatFxnType RenameVars(CatFxnType ft, CatTypeVarList vars)
 {
     return new CatFxnType(RenameVars(ft.GetCons(), vars), RenameVars(ft.GetProd(), vars), ft.HasSideEffects());
 }
Exemplo n.º 19
0
 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());                    
 }
Exemplo n.º 20
0
 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); 
     }
 }