public ApplicableIsaVisitor(TypeParamInstantiation typeInst,
                             IList <Term> args,
                             IVariableTranslation <TypeVariable> typeVarTranslation)
 {
     _typeInst      = typeInst;
     _args          = args;
     typeIsaVisitor = new TypeIsaVisitor(typeVarTranslation);
 }
Example #2
0
    private void CheckTypeParams(Absy node, TypeParamInstantiation insts) {
      Contract.Requires(insts != null);
      Contract.Requires(node != null);
      foreach (TypeVariable/*!*/ var in insts.FormalTypeParams) {
        Contract.Assert(var != null);
        Type/*!*/ inst = insts[var];
        Contract.Assert(inst != null);

        inTypeSeeker.FoundAmbiguity = false;
        inTypeSeeker.Visit(inst);
        if (inTypeSeeker.FoundAmbiguity)
          TC.Warning(node,
                     "type parameter {0} is ambiguous, instantiating to {1}",
                     var, inst);
      }
    }
Example #3
0
        private void CheckTypeParams(Absy node, TypeParamInstantiation insts)
        {
            Contract.Requires(insts != null);
            Contract.Requires(node != null);
            foreach (TypeVariable /*!*/ var in insts.FormalTypeParams)
            {
                Contract.Assert(var != null);
                Type /*!*/ inst = insts[var];
                Contract.Assert(inst != null);

                inTypeSeeker.FoundAmbiguity = false;
                inTypeSeeker.Visit(inst);
                if (inTypeSeeker.FoundAmbiguity)
                {
                    TC.Warning(node,
                               "type parameter {0} is ambiguous, instantiating to {1}",
                               var, inst);
                }
            }
        }
Example #4
0
        public Microsoft.Boogie.Type Typecheck(IList <Expr> args, out TypeParamInstantiation tpInstantiation, TypecheckingContext tc)
        {
            Debug.Assert(args.Count == ArgumentCount);
            // We can assume the expressions in args have already been type checked for us by NAryExpr.TypeCheck()

            // I'm not sure if this is right
            tpInstantiation = SimpleTypeParamInstantiation.EMPTY;
            var firstExpr = args[0];

            for (int index = 1; index < args.Count; ++index)
            {
                Debug.Assert(args[index].Type != null);
                if (!firstExpr.Type.Unify(args[index].Type))
                {
                    // Type checking failed
                    tc.Error(Token, String.Format("Failed to unify type {0} with {1} (argument index {2}",
                                                  firstExpr.Type.ToString(), args[index].Type.ToString(), index));
                    return(null);
                }
            }

            return(this.ShallowType(args));
        }
Example #5
0
        public override void Typecheck(TypecheckingContext tc)
        {
            Map.Typecheck(tc);
              foreach (Expr/*!*/ e in Indexes) {
            Contract.Assert(e != null);
            e.Typecheck(tc);
              }

              // we use the same typechecking code as in MapSelect
              List<Expr>/*!*/ selectArgs = new List<Expr>();
              foreach (Expr/*!*/ e in Indexes) {
            Contract.Assert(e != null);
            selectArgs.Add(e);
              }
              TypeParamInstantiation/*!*/ tpInsts;
              TypeAttr =
            MapSelect.Typecheck(cce.NonNull(Map.Type), Map,
                            selectArgs, out tpInsts, tc, tok, "map assignment");
              TypeParameters = tpInsts;
        }
Example #6
0
        public override void Typecheck(TypecheckingContext tc)
        {
            //Contract.Requires(tc != null);
            Contract.Assume(this.Proc != null);  // we assume the CallCmd has been successfully resolved before calling this Typecheck method

            TypecheckAttributes(Attributes, tc);

            // typecheck in-parameters
            foreach (Expr e in Ins)
            if (e != null)
                e.Typecheck(tc);
            foreach (Expr e in Outs)
            if (e != null)
                e.Typecheck(tc);
            this.CheckAssignments(tc);

            List<Type>/*!*/ formalInTypes = new List<Type>();
            List<Type>/*!*/ formalOutTypes = new List<Type>();
            List<Expr>/*!*/ actualIns = new List<Expr>();
            List<IdentifierExpr>/*!*/ actualOuts = new List<IdentifierExpr>();
            for (int i = 0; i < Ins.Count; ++i)
            {
            if (Ins[i] != null)
            {
                formalInTypes.Add(cce.NonNull(Proc.InParams[i]).TypedIdent.Type);
                actualIns.Add(Ins[i]);
            }
            }
            for (int i = 0; i < Outs.Count; ++i)
            {
            if (Outs[i] != null)
            {
                formalOutTypes.Add(cce.NonNull(Proc.OutParams[i]).TypedIdent.Type);
                actualOuts.Add(Outs[i]);
            }
            }

            // match actuals with formals
            List<Type/*!*/>/*!*/ actualTypeParams;
            Type.CheckArgumentTypes(Proc.TypeParameters,
                                out actualTypeParams,
                                formalInTypes, actualIns,
                                formalOutTypes, actualOuts,
                                this.tok,
                                "call to " + callee,
                                tc);
            Contract.Assert(cce.NonNullElements(actualTypeParams));
            TypeParameters = SimpleTypeParamInstantiation.From(Proc.TypeParameters,
                                                           actualTypeParams);

            if (!CommandLineOptions.Clo.DoModSetAnalysis && IsAsync)
            {
            if (!tc.Yields)
            {
                tc.Error(this, "enclosing procedure of an async call must yield");
            }
            if (!QKeyValue.FindBoolAttribute(Proc.Attributes, "yields"))
            {
                tc.Error(this, "target procedure of an async call must yield");
            }
            if (!QKeyValue.FindBoolAttribute(Proc.Attributes, "stable"))
            {
                tc.Error(this, "target procedure of an async call must be stable");
            }
            }
        }