Esempio n. 1
0
        public ParamMap Filter(Predicate <HDuple <string> > f)
        {
            var npm = new ParamMap();

            foreach (var m in this)
            {
                if (f(m))
                {
                    npm.Add(m);
                }
            }
            return(npm);
        }
Esempio n. 2
0
        public static ParamMap OfArray(string[] ps)
        {
            ParamMap m = new ParamMap();

            try
            {
                foreach (string p in ps)
                {
                    var pr = HDuple <string> .OfArray(p.Split(','));

                    if (pr != null)
                    {
                        m.Add(pr);
                    }
                }
            }
            catch
            {
                return(null);
            }
            return((ParamMap)m.Maybe());
        }
Esempio n. 3
0
        public static int GuessConfig(string[] args)
        {
            string boogieOptions = Options.BoogieUserOpts;

            //Log.Out(Log.Normal, "Initializing Boogie");
            if (SDiff.Boogie.Process.InitializeBoogie(boogieOptions))
            {
                return(1);
            }


            string
                first  = args[0],
                second = args[1];

            // First program
            Program p = BoogieUtils.ParseProgram(first);

            if (p == null)
            {
                return(1);
            }

            BoogieUtils.ResolveProgram(p, first);
            BoogieUtils.TypecheckProgram(p, first);

            // Second program
            Program q = BoogieUtils.ParseProgram(second);

            if (q == null)
            {
                return(1);
            }

            BoogieUtils.ResolveProgram(q, second);
            BoogieUtils.TypecheckProgram(q, second);


            first  = first.Substring(0, first.LastIndexOf('.') + 1);
            second = second.Substring(0, second.LastIndexOf('.') + 1);

            Config config = new Config();

            //store the procs of q by name
            Dictionary <string, Declaration>       qProcs = new Dictionary <string, Declaration>();
            Dictionary <string, HashSet <string> > qLoops = new Dictionary <string, HashSet <string> >();

            foreach (Declaration d in q.TopLevelDeclarations)
            {
                var proc = d as Procedure;
                if (proc != null)
                {
                    qProcs.Add(proc.Name, proc);
                    if (proc.Name.Contains("_loop_"))
                    {
                        int    indx     = proc.Name.IndexOf("_loop_");
                        string loopProc = proc.Name.Substring(0, indx);
                        if (!qLoops.ContainsKey(loopProc))
                        {
                            qLoops.Add(loopProc, new HashSet <string>());
                        }
                        qLoops[loopProc].Add(proc.Name);
                    }
                }
            }

            foreach (Declaration d in p.TopLevelDeclarations)
            {
                var proc = d as Procedure;
                if (proc != null)
                {
                    if (Util.IsInlinedProc(proc))
                    {
                        continue;
                    }

                    var pmap = new ParamMap();
                    foreach (Variable v in proc.InParams)
                    {
                        pmap.Add(new HDuple <string>(v.Name, v.Name));
                    }
                    foreach (Variable v in proc.OutParams)
                    {
                        pmap.Add(new HDuple <string>(v.Name, v.Name));
                    }

                    //config.AddProcedure(new Duple<HDuple<string>, ParamMap>(new HDuple<string>(first + proc.Name, second + proc.Name), pmap));

                    if (qProcs.ContainsKey(proc.Name))
                    {
                        config.AddProcedure(new Duple <HDuple <string>, ParamMap>(new HDuple <string>(first + proc.Name, second + proc.Name), pmap));
                    }
                    else //match loops (A BIG HACK that pretends that the enclosing procedure has only one loop and the mappings are same)
                    {
                        if (proc.Name.Contains("_loop_"))
                        {
                            int    indx     = proc.Name.IndexOf("_loop_");
                            string loopProc = proc.Name.Substring(0, indx);
                            if (qLoops.ContainsKey(loopProc) &&
                                qLoops[loopProc].Count == 1)
                            {
                                HashSet <string> matchQProcs = qLoops[loopProc];
                                string           qProcName   = "";
                                foreach (string s in matchQProcs) //ugly way to get the singleton string
                                {
                                    qProcName = s;
                                }

                                config.AddProcedure(new Duple <HDuple <string>, ParamMap>(new HDuple <string>(first + proc.Name, second + qProcName), pmap));
                            }
                        }
                    }
                }

                var global = d as GlobalVariable;
                if (global != null)
                {
                    config.AddGlobal(new HDuple <string>(first + global.Name, second + global.Name));
                }

                var constant = d as Constant;
                if (constant != null)
                {
                    config.AddConstant(new HDuple <string>(first + constant.Name, second + constant.Name));
                }

                var function = d as Function;
                if (function != null)
                {
                    var pmap = new ParamMap();
                    int i    = 0;
                    foreach (Variable v in function.InParams)
                    {
                        if (v.Name.Trim().Equals(""))
                        {
                            v.Name = "arg_" + i++;
                        }
                        pmap.Add(new HDuple <string>(v.Name, v.Name));
                    }
                    if (function.OutParams[0].Name.Equals(""))
                    {
                        function.OutParams[0].Name = "out_ret";
                    }
                    pmap.Add(new HDuple <string>(function.OutParams[0].Name, function.OutParams[0].Name));

                    config.AddFunction(new Duple <HDuple <string>, ParamMap>(new HDuple <string>(first + function.Name, second + function.Name), pmap));
                }

                var typector = d as TypeCtorDecl;
                if (typector != null)
                {
                    config.AddType(new HDuple <string>(first + typector.Name, second + typector.Name));
                }

                var typesyn = d as TypeSynonymDecl;
                if (typesyn != null)
                {
                    config.AddType(new HDuple <string>(first + typesyn.Name, second + typesyn.Name));
                }
            }

            Console.WriteLine(config.ToString());
            return(0);
        }
Esempio n. 4
0
 public void AddConstant(HDuple <string> mapping)
 {
     constMap.Add(mapping);
 }
Esempio n. 5
0
 public void AddType(HDuple <string> mapping)
 {
     typeMap.Add(mapping);
 }
Esempio n. 6
0
 public void AddGlobal(HDuple <string> mapping)
 {
     globalMap.Add(mapping);
 }