Beispiel #1
0
        public int GetMaxConsumption()
        {
            int nCnt = 0;

            List <CatKind> list = mCons.GetKinds();

            for (int i = list.Count - 1; i >= 0; --i)
            {
                CatKind k = list[i];
                if (k is CatStackVar)
                {
                    if ((i == 0) && k.Equals(mProd.GetBottom()))
                    {
                        return(nCnt);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                nCnt++;
            }

            return(nCnt);
        }
Beispiel #2
0
        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 Vector TypeVectorToConstraintVector(CatTypeVector x)
        {
            Vector vec = new Vector();

            foreach (CatKind k in x.GetKinds())
            {
                vec.Insert(0, CatKindToConstraint(k));
            }
            return(vec);
        }
Beispiel #4
0
        public CatTypeVector Rename(CatTypeVector s)
        {
            CatTypeVector ret = new CatTypeVector();

            foreach (CatKind k in s.GetKinds())
            {
                ret.Add(Rename(k));
            }
            return(ret);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }