Exemple #1
0
        public bool TryGetMatchedAccess(EntryPoint ep, Expr access, out Expr matchedAccess)
        {
            matchedAccess = null;

            Expr       larg = null;
            Expr       rarg = null;
            IAppliable fun  = null;

            if (access is NAryExpr)
            {
                larg = (access as NAryExpr).Args[0];
                rarg = (access as NAryExpr).Args[1];
                fun  = (access as NAryExpr).Fun;
            }
            else
            {
                larg = access;
            }

            IdentifierExpr id = null;

            if (ep.Equals(this.EP1) && this.InParamMapEP1.ContainsKey(larg.ToString()))
            {
                id = this.InParamMapEP1[larg.ToString()];
            }
            else if (ep.Equals(this.EP2) && this.InParamMapEP2.ContainsKey(larg.ToString()))
            {
                id = this.InParamMapEP2[larg.ToString()];
            }

            if (id == null)
            {
                matchedAccess = access;
            }
            else if (rarg != null)
            {
                matchedAccess = new NAryExpr(Token.NoToken, fun, new List <Expr> {
                    id, rarg
                });
            }
            else
            {
                matchedAccess = id;
            }

            if (id == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemple #2
0
        public static string PrettyPrintBplExpr(Expr e)
        {
            Contract.Requires(e != null);
            Contract.Ensures(Contract.Result <string>() != null);
            // anything that is unknown will just be printed via ToString
            // OldExpr and QuantifierExpr, BvExtractExpr, BvConcatExpr are ignored for now
            // LiteralExpr is printed as itself by ToString
            if (e is IdentifierExpr)
            {
                string s = e.ToString();
                return(Helpers.BeautifyBplString(s));
            }
            else if (e is NAryExpr)
            {
                NAryExpr   ne   = (NAryExpr)e;
                IAppliable fun  = ne.Fun;
                var        eSeq = ne.Args;
                if (fun != null)
                {
                    if ((fun.FunctionName == "$Length" || fun.FunctionName == "$StringLength") && eSeq.Count == 1)
                    {
                        Expr e0 = eSeq[0];
                        if (e0 != null)
                        {
                            string s0 = PrettyPrintBplExpr(e0);
                            return(s0 + ".Length");
                        }

                        //unexpected, just fall outside to the default
                    }
                    else if (fun.FunctionName == "$typeof" && eSeq.Count == 1)
                    {
                        Expr e0 = eSeq[0];
                        if (e0 != null)
                        {
                            string s0 = PrettyPrintBplExpr(e0);
                            return("(the dynamic type of: " + s0 + ")");
                        }

                        //unexpected, just fall outside to the default
                    }
                    else if (fun.FunctionName == "IntArrayGet" && eSeq.Count == 2)
                    {
                        Expr e0 = eSeq[0];
                        Expr e1 = eSeq[1];
                        if (e0 != null && e1 != null)
                        {
                            string s0 = PrettyPrintBplExpr(e0);
                            string s1 = PrettyPrintBplExpr(e1);
                            return(s0 + "[" + s1 + "]");
                        }

                        //unexpected, just fall outside to the default
                    }
                    else if (fun.FunctionName == "$Is" && eSeq.Count == 2)
                    {
                        Expr e0 = eSeq[0];
                        Expr e1 = eSeq[1];
                        if (e0 != null && e1 != null)
                        {
                            string s0 = PrettyPrintBplExpr(e0);
                            string s1 = PrettyPrintBplExpr(e1);
                            return("(" + s0 + " == null || (" + s0 + " is " + s1 + "))");
                        }

                        //unexpected, just fall outside to the default
                    }
                    else if (fun.FunctionName == "$IsNotNull" && eSeq.Count == 2)
                    {
                        Expr e0 = eSeq[0];
                        Expr e1 = eSeq[1];
                        if (e0 != null && e1 != null)
                        {
                            string s0 = PrettyPrintBplExpr(e0);
                            string s1 = PrettyPrintBplExpr(e1);
                            return("(" + s0 + " is " + s1 + ")");
                        }

                        //unexpected, just fall outside to the default
                    }
                    else if (fun is MapSelect && eSeq.Count <= 3)
                    {
                        // only maps with up to two arguments are supported right now (here)
                        if (cce.NonNull(eSeq[0]).ToString() == "$Heap")
                        {
                            //print Index0.Index1, unless Index1 is "$elements", then just print Index0
                            string s0 = PrettyPrintBplExpr(cce.NonNull(eSeq[1]));
                            if (eSeq.Count > 2)
                            {
                                string s1 = PrettyPrintBplExpr(cce.NonNull(eSeq[2]));
                                if (s1 == "$elements")
                                {
                                    return(s0);
                                }
                                else
                                {
                                    if (eSeq[2] is IdentifierExpr)
                                    {
                                        // strip the class name out of a fieldname
                                        s1 = s1.Substring(s1.LastIndexOf('.') + 1);
                                    }

                                    return(s0 + "." + s1);
                                }
                            }
                        }

                        //unexpected, just fall outside to the default
                    }
                    else if (fun is Microsoft.Boogie.BinaryOperator && eSeq.Count == 2)
                    {
                        Microsoft.Boogie.BinaryOperator f = (Microsoft.Boogie.BinaryOperator)fun;
                        Expr e0 = eSeq[0];
                        Expr e1 = eSeq[1];
                        if (e0 != null && e1 != null)
                        {
                            string s0 = PrettyPrintBplExpr(e0);
                            string s1 = PrettyPrintBplExpr(e1);
                            string op = "";
                            switch (f.Op)
                            {
                            case Microsoft.Boogie.BinaryOperator.Opcode.Add:
                                op = " + ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.And:
                                op = " && ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Div:
                                op = " div ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Eq:
                                op = " == ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Ge:
                                op = " >= ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Gt:
                                op = " > ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Iff:
                                op = " <==> ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Imp:
                                op = " ==> ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Le:
                                op = " <= ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Lt:
                                op = " < ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Mod:
                                op = " mod ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Mul:
                                op = " * ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Neq:
                                op = " != ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Or:
                                op = " || ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Pow:
                                op = " ** ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.RealDiv:
                                op = " / ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Sub:
                                op = " - ";
                                break;

                            case Microsoft.Boogie.BinaryOperator.Opcode.Subtype:
                                op = " <: ";
                                break;

                            default:
                                op = " ";
                                break;
                            }

                            return("(" + s0 + op + s1 + ")");
                        }

                        //unexpected, just fall outside to the default
                    }
                    else
                    {
                        string s = fun.FunctionName + "(";
                        for (int i = 0; i < eSeq.Count; i++)
                        {
                            Expr ex = eSeq[i];
                            Contract.Assume(ex != null);
                            if (i > 0)
                            {
                                s += ", ";
                            }

                            string t = PrettyPrintBplExpr(ex);
                            if (t.StartsWith("(") && t.EndsWith(")"))
                            {
                                t = t.Substring(1, t.Length - 2);
                            }

                            s += t;
                        }

                        s += ")";
                        return(s);
                        //unexpected, just fall outside to the default
                    }
                }
            }

            return(e.ToString());
        }
Exemple #3
0
 private NAryExpr GetNAry(IAppliable fun, List <Expr> args)
 {
     return(new NAryExpr(Token.NoToken, fun, args, Immutable));
 }