Ejemplo n.º 1
0
        public TypeSpec Verify()
        {
            var baseType = VarTab.Get(Id);

            if (baseType.ArrayCount < ArrayIndex.Count)
            {
                throw new ArgumentException();
            }

            return(new TypeSpec
            {
                ArrayCount = baseType.ArrayCount - ArrayIndex.Count,
                Base = baseType.Base
            });
        }
Ejemplo n.º 2
0
        public TypeSpec Verify()
        {
            var baseType = VarTab.Get(Id);

            if (baseType.ArrayCount > 0 || !(baseType.Base is Function func))
            {
                throw new ArgumentException();
            }

            var argIds = Args.Select(x => x.Id).ToHashSet();
            var parIds = func.Types.Select(x => x.Id).ToHashSet();

            if (!parIds.IsSupersetOf(argIds))
            {
                throw new ArgumentException();
            }

            if (!func.Types.Where(par => par.Default != null).Select(par => par.Id).ToHashSet()
                .IsSupersetOf(parIds.Except(argIds)))
            {
                throw new ArgumentException();
            }

            (from arg in Args
             join par in func.Types on arg.Id equals par.Id
             select(arg, par)).ForEach(tup =>
            {
                var(arg, par) = tup;
                if (arg.Expr.Verify() != par.Type)
                {
                    throw new ArgumentException();
                }
            });

            return(func.ReturnType);
        }
Ejemplo n.º 3
0
        public TypeSpec Verify()
        {
            FuncState.PushFunc(ReturnType);
            VarTab.PushScope();
            Params.ForEach(par => VarTab.Add(par.Id, par.Type));
            Stmts.ForEach(stmt => stmt.Verify());
            VarTab.PopScope();
            FuncState.PopFunc();

            Params.ForEach(par => par.Verify());
            if (Params.Select(x => x.Id).ToList().Count != Params.Select(x => x.Id).ToHashSet().Count)
            {
                throw new ArgumentException();
            }

            return(new TypeSpec
            {
                Base = new Function
                {
                    ReturnType = ReturnType,
                    Types = Params
                }
            });
        }