Example #1
0
 protected override void ResolveTriggers(ResolutionContext rc)
 {
     //Contract.Requires(rc != null);
     for (Trigger tr = this.Triggers; tr != null; tr = tr.Next)
     {
         int prevErrorCount = rc.ErrorCount;
         tr.Resolve(rc);
         if (prevErrorCount == rc.ErrorCount)
         {
             // for positive triggers, make sure all bound variables are mentioned
             if (tr.Pos)
             {
                 Set /*Variable*/ freeVars = new Set/*Variable*/ ();
                 tr.ComputeFreeVariables(freeVars);
                 foreach (Variable /*!*/ v in Dummies)
                 {
                     Contract.Assert(v != null);
                     if (!freeVars[v])
                     {
                         rc.Error(tr, "trigger must mention all quantified variables, but does not mention: {0}", v);
                     }
                 }
             }
         }
     }
 }
Example #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);
            }

            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);
                            }
                        }
                    }
                }
            }
        }