示例#1
0
        private void attachEnsures(Implementation impl)
        {
            List <Variable> functionInterfaceVars = new List <Variable>();

            foreach (Variable v in BoogieUtil.GetGlobalVariables(vcgen.program))
            {
                functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", v.TypedIdent.Type), true));
            }
            foreach (Variable v in impl.InParams)
            {
                functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", v.TypedIdent.Type), true));
            }
            foreach (Variable v in impl.OutParams)
            {
                functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", v.TypedIdent.Type), true));
            }
            foreach (IdentifierExpr e in impl.Proc.Modifies)
            {
                if (e.Decl == null)
                {
                    continue;
                }
                functionInterfaceVars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", e.Decl.TypedIdent.Type), true));
            }
            Formal returnVar = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", Bpl.Type.Bool), false);
            var    function  = new Function(Token.NoToken, impl.Name + summaryPredSuffix, functionInterfaceVars, returnVar);

            prover.Context.DeclareFunction(function, "");

            List <Expr> exprs = new List <Expr>();

            foreach (Variable v in BoogieUtil.GetGlobalVariables(vcgen.program))
            {
                Contract.Assert(v != null);
                exprs.Add(new OldExpr(Token.NoToken, new IdentifierExpr(Token.NoToken, v)));
            }
            foreach (Variable v in impl.Proc.InParams)
            {
                Contract.Assert(v != null);
                exprs.Add(new IdentifierExpr(Token.NoToken, v));
            }
            foreach (Variable v in impl.Proc.OutParams)
            {
                Contract.Assert(v != null);
                exprs.Add(new IdentifierExpr(Token.NoToken, v));
            }
            foreach (IdentifierExpr ie in impl.Proc.Modifies)
            {
                Contract.Assert(ie != null);
                if (ie.Decl == null)
                {
                    continue;
                }
                exprs.Add(ie);
            }
            Expr postExpr = new NAryExpr(Token.NoToken, new FunctionCall(function), exprs);

            impl.Proc.Ensures.Add(
                new Ensures(Token.NoToken, false, postExpr, ""));
        }
示例#2
0
        static void Main(string[] args)
        {
            var Basket = new Basket();

            var Shirt = new Shirt(); //Adding test data

            Shirt.Name = "Armani";
            Shirt.Size = "l";
            Basket.shirts.Add(Shirt);
            var Golf = new Golfer();

            Golf.Name = "White";
            Golf.Size = "m";
            Basket.golfers.Add(Golf);
            var jean = new Jeans();

            jean.Name = "Skinny";
            jean.Size = "s";
            Basket.jeans.Add(jean);
            var formal = new Formal();

            formal.Name = "Guess";
            formal.Size = "l";
            Basket.formals.Add(formal);


            Console.WriteLine("Your total is : R" + Basket.CalcCost()); //output
            Console.ReadKey();
        }
示例#3
0
        private CallCmd makeRecordCall(IdentifierExpr v)
        {
            var ins = new List <Expr>();

            ins.Add(v);

            if (v.Type.IsInt)
            {
                return(new CallCmd(Token.NoToken, recordProcNameInt, ins, new List <IdentifierExpr>()));
            }
            else if (v.Type.IsBool)
            {
                return(new CallCmd(Token.NoToken, recordProcNameBool, ins, new List <IdentifierExpr>()));
            }
            else if (v.Type.IsCtor)
            {
                var t = v.Type.AsCtor.Decl.Name;
                if (!typeToRecordProc.ContainsKey(t))
                {
                    var inpVar = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "x", v.Type), true);
                    var reProc = new Procedure(Token.NoToken, recordProcNameCtor + t, new List <TypeVariable>(), new List <Variable> {
                        inpVar
                    }, new List <Variable>(), new List <Requires>(), new List <IdentifierExpr>(), new List <Ensures>());
                    typeToRecordProc.Add(t, reProc);
                }
                return(new CallCmd(Token.NoToken, typeToRecordProc[t].Name, ins, new List <IdentifierExpr>()));
            }
            else
            {
                Debug.Assert(false);
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// Sets the value of the named flag.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <exception cref="ArgumentException">Thrown when name does not exist as flag or when string value cannot be converted to desired type.</exception>
        public void Set(string name, string value)
        {
            var flagExists = Formal.TryGetValue(name, out var flag);

            if (!flagExists)
            {
                throw new ArgumentException("No such flag", nameof(name));
            }

            if (!flag.TrySetValue(value, out var err))
            {
                throw new ArgumentException($"Could not set value: {err}", nameof(value));
            }

            if (Actual == null)
            {
                Actual = new Dictionary <string, IFlag>();
            }

            if (Actual.ContainsKey(name))
            {
                Actual[name] = flag;
            }
            else
            {
                Actual.Add(name, flag);
            }
        }
        public override Node VisitBranch([NotNull] coolgrammarParser.BranchContext context)
        {
            Formal formal = (Formal)Visit(context.formal());
            Expr   exp    = (Expr)Visit(context.expr());

            return(new Branch(formal, exp));
        }
示例#6
0
        private static void replaceFECalls(Program prog)
        {
            prog.AddTopLevelDeclaration(new Procedure(Token.NoToken, "corral_atomic_begin", new List <TypeVariable>(), new List <Variable>(), new List <Variable>(), new List <Requires>(), new List <IdentifierExpr>(), new List <Ensures>()));
            prog.AddTopLevelDeclaration(new Procedure(Token.NoToken, "corral_atomic_end", new List <TypeVariable>(), new List <Variable>(), new List <Variable>(), new List <Requires>(), new List <IdentifierExpr>(), new List <Ensures>()));
            Formal id = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "id", Microsoft.Boogie.Type.Int), false);

            prog.AddTopLevelDeclaration(new Procedure(Token.NoToken, "corral_getThreadID", new List <TypeVariable>(), new List <Variable>(), new List <Variable>(new Variable[] { id }), new List <Requires>(), new List <IdentifierExpr>(), new List <Ensures>()));
            HashSet <Declaration> declsToRemove = new HashSet <Declaration>();

            foreach (Declaration decl in prog.TopLevelDeclarations)
            {
                Procedure proc = decl as Procedure;
                if (proc != null)
                {
                    if (proc.Name == "Poirot.Poirot.BeginAtomic" || proc.Name == "Poirot.Poirot.EndAtomic" || proc.Name == "Poirot.Poirot.CurrentThreadId")
                    {
                        declsToRemove.Add(decl);
                    }
                }
                Implementation impl = decl as Implementation;
                if (impl == null)
                {
                    continue;
                }
                foreach (Block b in impl.Blocks)
                {
                    List <Cmd> newCmds = new List <Cmd>();
                    foreach (Cmd c in b.Cmds)
                    {
                        CallCmd cc = c as CallCmd;
                        if (cc == null)
                        {
                            newCmds.Add(c);
                            continue;
                        }
                        if (cc.callee == "Poirot.Poirot.BeginAtomic")
                        {
                            newCmds.Add(new CallCmd(cc.tok, "corral_atomic_begin", cc.Ins, cc.Outs));
                        }
                        else if (cc.callee == "Poirot.Poirot.EndAtomic")
                        {
                            newCmds.Add(new CallCmd(cc.tok, "corral_atomic_end", cc.Ins, cc.Outs));
                        }
                        else if (cc.callee == "Poirot.Poirot.CurrentThreadId")
                        {
                            newCmds.Add(new CallCmd(cc.tok, "corral_getThreadID", cc.Ins, cc.Outs));
                        }
                        else
                        {
                            newCmds.Add(cc);
                        }
                    }
                    b.Cmds = newCmds;
                }
            }
            foreach (Declaration decl in declsToRemove)
            {
                prog.RemoveTopLevelDeclaration(decl);
            }
        }
示例#7
0
        public VCExpr ControlFlowFunctionApplication(VCExpr e1, VCExpr e2)
        {
            Contract.Requires(e1 != null);
            Contract.Requires(e2 != null);
            Contract.Ensures(Contract.Result <VCExpr>() != null);

            if (ControlFlowFunction == null)
            {
                Formal /*!*/
                    first = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", Microsoft.Boogie.Type.Int), true);
                Formal /*!*/
                                second = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", Microsoft.Boogie.Type.Int), true);
                List <Variable> inputs = new List <Variable>();
                inputs.Add(first);
                inputs.Add(second);
                Formal /*!*/
                    returnVar = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", Microsoft.Boogie.Type.Int), false);
                ControlFlowFunction = new Function(Token.NoToken, "ControlFlow", inputs, returnVar);
            }

            List <VCExpr /*!*/> args = new List <VCExpr /*!*/>();

            args.Add(e1);
            args.Add(e2);
            return(Function(BoogieFunctionOp(ControlFlowFunction), args));
        }
示例#8
0
        public override Expr VisitNAryExpr(NAryExpr node)
        {
            var nArgs = node.Args.Select(x => base.VisitExpr(x)).ToList();

            node.Args = nArgs;
            var fcall = node.Fun as FunctionCall;

            if (fcall != null && fcall.Func.HasAttribute(ExprMatchVisitor.BoogieKeyWords.MkUniqueFn))
            {
                var formals = new List <Variable>();
                fcall.Func.InParams.Iter(a =>
                {
                    var z = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, a.Name, a.TypedIdent.Type), true);
                    formals.Add(z);
                });
                var r = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "r", fcall.Func.OutParams[0].TypedIdent.Type), false);

                var f = new Function(Token.NoToken, fcall.FunctionName + "__" + uniqFuncs.Count,
                                     formals, r);
                //inherit all attributes other than mkUniqueFn
                f.Attributes = BoogieUtil.removeAttr(ExprMatchVisitor.BoogieKeyWords.MkUniqueFn, fcall.Func.Attributes);
                f.Body       = fcall.Func.Body;
                uniqFuncs.Add(f);
                program.AddTopLevelDeclaration(f);
                node.Fun = new FunctionCall(f);
            }
            return(node);
        }
示例#9
0
 public void Visit(Formal node)
 {
     builder.AppendLine($"Formal({node.Name})");
     builder.Indent();
     node.TypeDeclaration.Accept(this);
     builder.Outdent();
 }
示例#10
0
 internal void AddFlag <T>(Flag <T> flag)
 {
     foreach (var name in flag.Name.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries))
     {
         Formal.Add(name.Trim(), flag);
     }
 }
示例#11
0
    private void GenerateRecordFunctions()
    {
      foreach (var proc in program.Procedures)
      {
        if (!proc.Name.StartsWith(recordProcName)) continue;
        Contract.Assert(proc.InParams.Count == 1);

        // Make a new function
        TypedIdent ti = new TypedIdent(Token.NoToken, "", Bpl.Type.Bool);
        Contract.Assert(ti != null);
        Formal returnVar = new Formal(Token.NoToken, ti, false);
        Contract.Assert(returnVar != null);

        // Get record type
        var argtype = proc.InParams[0].TypedIdent.Type;

        var ins = new List<Variable>();
        ins.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "x", argtype), true));

        var recordFunc = new Function(Token.NoToken, proc.Name, ins, returnVar);
        prover.Context.DeclareFunction(recordFunc, "");

        var exprs = new List<Expr>();
        exprs.Add(new IdentifierExpr(Token.NoToken, proc.InParams[0]));

        Expr freePostExpr = new NAryExpr(Token.NoToken, new FunctionCall(recordFunc), exprs);
        proc.Ensures.Add(new Ensures(true, freePostExpr));
      }
    }
        private AtomicActionDuplicator(string prefix, AtomicAction action)
        {
            this.prefix = prefix;
            subst       = new Dictionary <Variable, Expr>();
            bound       = new Dictionary <Variable, Expr>();

            inParamsCopy  = new List <Variable>();
            outParamsCopy = new List <Variable>();
            localsCopy    = new List <Variable>();


            foreach (Variable x in action.impl.InParams)
            {
                Variable xCopy = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, prefix + x.Name, x.TypedIdent.Type), true, x.Attributes);
                inParamsCopy.Add(xCopy);
                subst[x] = Expr.Ident(xCopy);
            }
            foreach (Variable x in action.impl.OutParams)
            {
                Variable xCopy = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, prefix + x.Name, x.TypedIdent.Type), false, x.Attributes);
                outParamsCopy.Add(xCopy);
                subst[x] = Expr.Ident(xCopy);
            }

            foreach (Variable x in action.impl.LocVars)
            {
                Variable xCopy = new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, prefix + x.Name, x.TypedIdent.Type));
                subst[x] = Expr.Ident(xCopy);
                localsCopy.Add(xCopy);
            }
        }
        public static Expr Extract(Expr expr, Program program, List <Axiom> axioms)
        {
            Contract.Requires(expr != null && program != null && !program.TopLevelDeclarationsAreFrozen && axioms != null);

            if (expr is LiteralExpr)
            {
                return(expr);
            }

            var extractor = new FunctionExtractor();

            var body = extractor.VisitExpr(expr);

            var name         = program.FreshExtractedFunctionName();
            var originalVars = extractor.Substitutions.Keys.ToList();
            var formalInArgs = originalVars.Select(v => new Formal(Token.NoToken, new TypedIdent(Token.NoToken, extractor.Substitutions[v].Name, extractor.Substitutions[v].TypedIdent.Type), true)).ToList <Variable>();
            var formalOutArg = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, name + "$result$", expr.Type), false);
            var func         = new Function(Token.NoToken, name, formalInArgs, formalOutArg);

            func.AddAttribute("never_pattern");

            var boundVars = originalVars.Select(k => extractor.Substitutions[k]);
            var axiomCall = new NAryExpr(Token.NoToken, new FunctionCall(func), boundVars.Select(b => new IdentifierExpr(Token.NoToken, b)).ToList <Expr>());

            axiomCall.Type           = expr.Type;
            axiomCall.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
            var eq = LiteralExpr.Eq(axiomCall, body);

            eq.Type           = body.Type;
            eq.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
            if (0 < formalInArgs.Count)
            {
                var forallExpr = new ForallExpr(Token.NoToken, boundVars.ToList <Variable>(), new Trigger(Token.NoToken, true, new List <Expr> {
                    axiomCall
                }), eq);
                body = forallExpr;
                forallExpr.Attributes = new QKeyValue(Token.NoToken, "weight", new List <object> {
                    new LiteralExpr(Token.NoToken, Basetypes.BigNum.FromInt(30))
                }, null);
                body.Type = Type.Bool;
            }
            else
            {
                body = eq;
            }

            var axiom = new Axiom(Token.NoToken, body);

            func.DefinitionAxiom = axiom;
            program.AddTopLevelDeclaration(func);
            program.AddTopLevelDeclaration(axiom);
            axioms.Add(axiom);

            var call = new NAryExpr(Token.NoToken, new FunctionCall(func), originalVars.Select(v => new IdentifierExpr(Token.NoToken, v)).ToList <Expr>());

            call.Type           = expr.Type;
            call.TypeParameters = SimpleTypeParamInstantiation.EMPTY;
            return(call);
        }
示例#14
0
        public void ParseFormalTest()
        {
            FunctionParser functionParser = new FunctionParser(Init("param1"));
            Formal         parsedFormal   = functionParser.ParseFormal();

            //Test identifier
            Assert.AreEqual("param1", parsedFormal.ToString());
        }
示例#15
0
    public Formal AddFormal(InputElement id, MessageWriter msg)
    {
        Formal f = new Formal(id, locals);

        f.Add(id, msg);
        signature.Add(f);
        return(f);
    }
示例#16
0
        /// <summary>
        /// Parser for Formal
        /// </summary>
        /// <returns>Parsed Formal</returns>
        public Formal ParseFormal()
        {
            Formal formal = new Formal();

            CurrentToken = TokenStream.NextToken();
            formal.SetIdentifier(CurrentToken.GetValue().ToString());

            return(formal);
        }
示例#17
0
        public void Formal_ShouldPrint()
        {
            var ast = new Formal(identifier: new Identifier(0, "arg1"), typeDeclaration: new BooleanTypeDeclaration(0));

            Assert.That(PrettyPrinter.ToString(ast), Is.EqualTo(
                            @"Formal(arg1)
    Type(Boolean)
"));
        }
示例#18
0
        // replace havoc statements by calls to nondets
        public static void ReplaceHavocsWithNonDet(Program program)
        {
            var nonDetProcs = new HashSet <Procedure>();

            var mkOrLookupNonDetProc = new Func <Variable, Procedure>(d =>
            {
                var dt       = ((Variable)d).TypedIdent.Type;
                var op       = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "o", dt), false);
                var procName = "havocNonDetAvh." + dt.ToString();
                var found    = nonDetProcs.Where(x => x.Name == procName).FirstOrDefault();
                if (found != null)
                {
                    return(found);
                }
                var proc = new Procedure(Token.NoToken, procName,
                                         new List <TypeVariable>(), new List <Variable>(), new List <Variable>()
                {
                    op
                },
                                         new List <Requires>(), new List <IdentifierExpr>(), new List <Ensures>());
                nonDetProcs.Add(proc);
                return(proc);
            });

            foreach (Implementation impl in program.TopLevelDeclarations.OfType <Implementation>())
            {
                foreach (Block blk in impl.Blocks)
                {
                    var newCmds = new List <Cmd>();

                    foreach (Cmd cmd in blk.Cmds)
                    {
                        if (!(cmd is HavocCmd))
                        {
                            newCmds.Add(cmd);
                        }
                        else
                        {
                            var hVars = ((HavocCmd)cmd).Vars;
                            hVars.Iter(hv =>
                            {
                                var cCmd = new CallCmd(Token.NoToken, mkOrLookupNonDetProc(hv.Decl).ToString(),
                                                       new List <Expr>(), new List <IdentifierExpr>()
                                {
                                    hv
                                });
                                newCmds.Add(cCmd);
                            });
                        }
                    }
                    blk.Cmds = newCmds;
                }
            }
            nonDetProcs.Iter(x => program.AddTopLevelDeclaration(x));
        }
示例#19
0
        internal void Set <T>(string name, T value)
        {
            if (!Formal.ContainsKey(name))
            {
                throw new MissingFlagException(name);
            }
            var flag = Formal[name];

            ((IFlag <T>)flag).Value = value;

            Actual[name] = flag;
        }
示例#20
0
        internal void Set(string name, string value)
        {
            if (!Formal.ContainsKey(name))
            {
                throw new MissingFlagException(name);
            }

            var flag = Formal[name];

            flag.Set(value);
            Actual[name] = flag;
        }
示例#21
0
            private void MakeNewCopy(Variable v)
            {
                varLastCopyId[v] = varLastCopyId.ContainsKey(v) ? varLastCopyId[v] + 1 : 0;
                int id      = varLastCopyId[v];
                var copyVar = new Formal(
                    Token.NoToken,
                    new TypedIdent(Token.NoToken, string.Format(copierFormat, v.Name, id), v.TypedIdent.Type),
                    false, null);

                varCopies[id][v]           = copyVar;
                copyToOriginalVar[copyVar] = v;
            }
示例#22
0
 protected override void EmitDestructor(string source, Formal dtor, int formalNonGhostIndex, DatatypeCtor ctor, List <Type> typeArgs, TargetWriter wr)
 {
     if (ctor.EnclosingDatatype is TupleTypeDecl)
     {
         wr.Write("({0})[{1}]", source, formalNonGhostIndex);
     }
     else
     {
         var dtorName = FormalName(dtor, formalNonGhostIndex);
         wr.Write("({0}).{1}", source, dtorName);
     }
 }
示例#23
0
        private Formal ReplaceOutVarwithIn(Formal outV, List <Formal> ins)
        {
            int n;

            for (int j = 0; j < ins.Count; j++)
            {
                if (ins[j].Name.Contains(outV.Name) && int.TryParse(ins[j].Name.Substring(outV.Name.Length), out n))
                {
                    return(ins[j]);
                }
            }
            return(outV);
        }
示例#24
0
        private Procedure GetInitLocalsProc(Microsoft.Boogie.Type ty)
        {
            var typeToStr = ty.ToString().Replace('[', '_').Replace(']', '_');

            if (!typeToInitLocalsProc.ContainsKey(typeToStr))
            {
                var outVar = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "x", ty), false);
                var reProc = new Procedure(Token.NoToken, initLocProcName + typeToStr, new List <TypeVariable>(), new List <Variable>(), new List <Variable> {
                    outVar
                }, new List <Requires>(), new List <IdentifierExpr>(), new List <Ensures>());
                typeToInitLocalsProc.Add(typeToStr, reProc);
            }
            return(typeToInitLocalsProc[typeToStr]);
        }
        // No caching
        public FunctionCall CreateUninterpretedFunctionCall(string Name, Microsoft.Boogie.Type returnType, IList <Microsoft.Boogie.Type> argTypes)
        {
            var returnVar = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", returnType), false);
            var vars      = new List <Variable>();

            foreach (var T in argTypes)
            {
                vars.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "", T), true));
            }

            // Finally build the function and the function call
            var funcCall = new FunctionCall(new Function(Token.NoToken, Name, vars, returnVar));

            return(funcCall);
        }
示例#26
0
 /// <summary>
 /// Pass a user-implemented IFlag directly to the FlagSet
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="flag"></param>
 /// <returns></returns>
 public T Var <T>(T flag) where T : IFlag
 {
     if (Formal != null && Formal.ContainsKey(flag.Name))
     {
         var msg = Name == "" ? $"flag redefined: {flag.Name}" : $"{Name} flag redefined: {flag.Name}";
         Output().WriteLine(msg);
         throw new InvalidOperationException(msg);
     }
     if (Formal == null)
     {
         Formal = new Dictionary <string, IFlag>();
     }
     Formal.Add(flag.Name, flag);
     return(flag);
 }
示例#27
0
        public override string Print(int depth)
        {
            if (IsEmpty)
            {
                return("");
            }

            if (Tail.IsEmpty)
            {
                return(Formal.Print(depth).ToString());
            }
            else
            {
                return(Formal.Print(depth) + "," + Tail.Print(depth));
            }
        }
示例#28
0
        ////////////////////////////////////////////////////////////////////////////

        // Used to axiomatise the disjoint-sub-dag specs that are
        // described by parents with the "unique" flag


        private Function OneStepFunFor(Type t)
        {
            Contract.Requires(t != null);
            Contract.Ensures(Contract.Result <Function>() != null);

            if (!OneStepFuns.TryGetValue(t, out var res))
            {
                List <Variable> args = new List <Variable>();
                args.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "arg0", t), true));
                args.Add(new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "arg1", t), true));
                Formal result = new Formal(Token.NoToken, new TypedIdent(Token.NoToken, "res", t), false);
                res = new Function(Token.NoToken, "oneStep", new List <TypeVariable>(), args, result);
                OneStepFuns.Add(t, res);
            }

            return(cce.NonNull(res));
        }
示例#29
0
    Method GetMethod(Method m, MethodBase info)
    {
        m.Modifiers = GetMethodModifiers(info);
        if (info is MethodInfo)
        {
            m.Type = GetType(((MethodInfo)info).ReturnType);
        }
        else
        {
            m.Type = global.Types.Void;
        }
        Formal f = null;

        foreach (ParameterInfo x in info.GetParameters())
        {
            f      = m.AddFormal(new InputElement(x.Name), msg);
            f.Type = GetType(x.ParameterType);
            if (x.IsOut)
            {
                f.modifier = new InputElement("out");
            }
            else if (f.Type is ManagedPointerType)
            {
                f.modifier = new InputElement("ref");
            }
            if (f.Type is ManagedPointerType)
            {
                f.Type = ((ManagedPointerType)f.Type).elementType;
            }
            else
            {
                object[] attrs = x.GetCustomAttributes(paramArrayType, false);
                if (attrs.Length > 0)
                {
                    Debug.Assert(attrs.Length == 1);
                    f.IsParams = true;
                }
            }
        }
        if (f != null && m.Name == "set_Item")
        {
            m.signature.formals.Remove(f);
        }
        return(m);
    }
示例#30
0
        public static void Predicate(Program p,
                                     bool createCandidateInvariants = true,
                                     bool useProcedurePredicates    = true)
        {
            foreach (var decl in p.TopLevelDeclarations.ToList())
            {
                if (useProcedurePredicates && decl is DeclWithFormals && !(decl is Function))
                {
                    var dwf   = (DeclWithFormals)decl;
                    var fpVar = new Formal(Token.NoToken,
                                           new TypedIdent(Token.NoToken, "_P",
                                                          Microsoft.Boogie.Type.Bool),
                                           /*incoming=*/ true);
                    dwf.InParams = new List <Variable>(
                        (new Variable[] { fpVar }.Concat(dwf.InParams.Cast <Variable>()))
                        .ToArray());

                    if (dwf is Procedure)
                    {
                        var proc        = (Procedure)dwf;
                        var newRequires = new List <Requires>();
                        foreach (Requires r in proc.Requires)
                        {
                            newRequires.Add(new Requires(r.Free,
                                                         new EnabledReplacementVisitor(new IdentifierExpr(Token.NoToken, fpVar), Expr.True).VisitExpr(r.Condition)));
                        }
                        var newEnsures = new List <Ensures>();
                        foreach (Ensures e in proc.Ensures)
                        {
                            newEnsures.Add(new Ensures(e.Free,
                                                       new EnabledReplacementVisitor(new IdentifierExpr(Token.NoToken, fpVar), Expr.True).VisitExpr(e.Condition)));
                        }
                    }
                }

                try {
                    var impl = decl as Implementation;
                    if (impl != null)
                    {
                        new BlockPredicator(p, impl, createCandidateInvariants, useProcedurePredicates).PredicateImplementation();
                    }
                }
                catch (Program.IrreducibleLoopException) { }
            }
        }
示例#31
0
文件: Cloner.cs 项目: ggrov/tacny
 public Formal CloneFormal(Formal formal) {
   Formal f = new Formal(Tok(formal.tok), formal.Name, CloneType(formal.Type), formal.InParam, formal.IsGhost);
   //if (f.Type is UserDefinedType && formal.Type is UserDefinedType)
   //    ((UserDefinedType)f.Type).ResolvedClass = ((UserDefinedType)(formal.Type)).ResolvedClass;
   return f;
 }
示例#32
0
    public void visit(Formal n) {

        ClassRec c;

        Class astType = n.t.getClass();

        // If the formal type is object type, we must check that the class definition exists
        if (astType == ObjType.class) {

            String s = ((ObjType)n.t).cid.s;
            if (null == (c = symTable.getClass(new Id(s)))) {
                throw new TypeException("Class " + s + " not defined");
            }
        }
    }