Пример #1
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            foreach (var e in Rhss)
            {
                e.Typecheck(tc);
            }

            Contract.Assert(Dummies.Count == Rhss.Count); // enforced by resolution
            for (var i = 0; i < Dummies.Count; i++)
            {
                var lhs = Dummies[i];
                var rhs = Rhss[i];
                lhs.TypedIdent.Type = rhs.Type;
            }

            for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next)
            {
                kv.Typecheck(tc);
            }

            Body.Typecheck(tc);
            Contract.Assert(Body.Type != null); // follows from postcondition of Expr.Typecheck
            this.Type = Body.Type;
        }
Пример #2
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next)
            {
                kv.Typecheck(tc);
            }
            Body.Typecheck(tc);
            Contract.Assert(Body.Type != null); // follows from postcondition of Expr.Typecheck

            List <Type> /*!*/ argTypes = new List <Type>();

            foreach (Variable /*!*/ v in Dummies)
            {
                Contract.Assert(v != null);
                argTypes.Add(v.TypedIdent.Type);
            }
            this.Type = new MapType(this.tok, this.TypeParameters, argTypes, Body.Type);

            // Check that type parameters occur in the types of the
            // dummies, or otherwise in the triggers. This can only be
            // done after typechecking
            List <TypeVariable> /*!*/ unmentionedParameters = GetUnmentionedTypeParameters();

            Contract.Assert(unmentionedParameters != null);

            if (unmentionedParameters.Count > 0)
            {
                tc.Error(this, "the type variable {0} does not occur in types of the lambda parameters", unmentionedParameters[0]);
            }
        }
Пример #3
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            for (QKeyValue kv = this.Attributes; kv != null; kv = kv.Next)
            {
                kv.Typecheck(tc);
            }

            for (Trigger tr = this.Triggers; tr != null; tr = tr.Next)
            {
                tr.Typecheck(tc);
            }

            Body.Typecheck(tc);
            Contract.Assert(Body.Type != null); // follows from postcondition of Expr.Typecheck
            if (!Body.Type.Unify(Type.Bool))
            {
                tc.Error(this, "quantifier body must be of type bool");
            }

            this.Type = Type.Bool;

            // Check that type parameters occur in the types of the
            // dummies, or otherwise in the triggers. This can only be
            // done after typechecking
            List <TypeVariable> /*!*/
            unmentionedParameters = GetUnmentionedTypeParameters();

            Contract.Assert(unmentionedParameters != null);

            if (unmentionedParameters.Count > 0)
            {
                // all the type parameters that do not occur in dummy types
                // have to occur in triggers

                for (Trigger tr = this.Triggers; tr != null; tr = tr.Next)
                {
                    // for positive triggers, make sure all bound variables are mentioned
                    if (tr.Pos)
                    {
                        Set /*Variable*/
                            freeVars = new Set/*Variable*/ ();
                        tr.ComputeFreeVariables(freeVars);
                        foreach (TypeVariable /*!*/ v in unmentionedParameters)
                        {
                            Contract.Assert(v != null);
                            if (!freeVars[v])
                            {
                                tc.Error(tr,
                                         "trigger does not mention {0}, which does not occur in variables types either",
                                         v);
                            }
                        }
                    }
                }
            }
        }