コード例 #1
0
ファイル: CatVarRenamer.cs プロジェクト: tangentforks/catlang
        public CatTypeKind Rename(CatTypeKind t)
        {
            if (t == null)
            {
                throw new Exception("Invalid null parameter to rename function");
            }
            if (t is CatFxnType)
            {
                return(Rename(t as CatFxnType));
            }
            else if (t is CatTypeVar)
            {
                string sName = t.ToString();
                if (mNames.ContainsKey(sName))
                {
                    CatTypeKind ret = mNames[sName] as CatTypeKind;
                    if (ret == null)
                    {
                        throw new Exception(sName + " is not a type kind");
                    }
                    return(ret);
                }

                CatTypeVar var = GenerateNewVar(sName) as CatTypeVar;
                mNames.Add(sName, var);
                return(var);
            }
            else
            {
                return(t);
            }
        }
コード例 #2
0
ファイル: CatVarRenamer.cs プロジェクト: tangentforks/catlang
        public static CatFxnType RenameFreeVars(CatFxnType left, CatFxnType right, CatFxnType ft)
        {
            CatTypeVarList vars = ft.GetAllVars();

            foreach (string s in vars.Keys)
            {
                CatKind k = vars[s];
                if (IsFreeVar(k, left, right, ft))
                {
                    if (k is CatTypeVar)
                    {
                        vars[s] = CatTypeVar.CreateUnique();
                    }
                    else
                    {
                        vars[s] = CatStackVar.CreateUnique();
                    }
                }
            }
            return(RenameVars(ft, vars));
        }