public static bool Process(Expr expr) { var v = new HasNonOldExpr(); v.VisitExpr(expr); return(v.flag); }
private static void addAtomsFromDualityOutput(string filename) { var pwd = Environment.CurrentDirectory; var dualityOutputFiles = System.IO.Directory.GetFiles(pwd, "cp.*").ToList(); dualityOutputFiles.RemoveAll(fname => fname == System.IO.Path.Combine(pwd, "cp.tmp")); if (System.IO.File.Exists("fp.bpl")) { dualityOutputFiles.Add("fp.bpl"); } //foreach (var file in dualityOutputFiles) // Console.WriteLine("file: {0}", file); if (!dualityOutputFiles.Any()) { return; } // Get the set of variables with annotation {:environment}. var slicVars = new HashSet <string>(); var testBpl = BoogieUtil.ParseProgram(filename); testBpl.TopLevelDeclarations.OfType <Variable>() .Where(g => QKeyValue.FindBoolAttribute(g.Attributes, "environment")) .Iter(g => slicVars.Add(g.Name)); var outatoms = new HashSet <string>(); var summaries = new AtomDictionary(); foreach (var file in dualityOutputFiles) { // Parse the procedure summary file fp.bpl generated by Duality. var program = BoogieUtil.ParseProgram(file); // Collect atomic propositions that talk about slic variables. var literalVisitor = new LiteralVisitor(); foreach (var proc in program.TopLevelDeclarations.OfType <Procedure>()) { foreach (var ens in proc.Ensures) { literalVisitor.VisitEnsures(ens); } } // Filter literals that talk about SLIC variables only. var literals = new HashSet <Expr>(); foreach (var lit in literalVisitor.literals) { var fv = new VarsInExpr(); fv.VisitExpr(lit); bool allVarsAreSlicVars = true; foreach (var v in fv.Vars) { if (!slicVars.Contains(v)) { allVarsAreSlicVars = false; } } if (allVarsAreSlicVars) { literals.Add(lit); } } // Get pre/post annotation var GetAtomFromLiteral = new Func <Expr, Tuple <string, Expr> >(e => { if (HasNonOldExpr.Process(e)) { return(Tuple.Create("{:post}", e)); } else { return(Tuple.Create("{:pre}", e)); } }); literals.Select(l => GetAtomFromLiteral(l)) .Iter(t => { summaries.Add(t.Item1, t.Item2); outatoms.Add(t.Item1 + " " + t.Item2); }); } var atomDatabasePath = CommonLib.GlobalConfig.util_result_file; Debug.Assert(!System.IO.File.Exists(atomDatabasePath)); TrainerDB.Driver.WriteDB(summaries, atomDatabasePath); if (debugging) { foreach (var atom in outatoms) { Console.WriteLine("Dumped atom: {0}", atom); } Console.WriteLine("Dumped atoms to db."); } }