// Remove declarations of globals that are not tracked public override Program VisitProgram(Program node) { /* * Log.Write(Log.Debug, "Tracking variables: "); * foreach (var s in trackedVars) * { * Log.Write(Log.Debug, s + " "); * } * Log.Write(Log.Debug, "\n"); */ HashSet <string> declaredGlobals = new HashSet <string>(); // Partition the list into global declarations and others var globals = node.TopLevelDeclarations.OfType <GlobalVariable>().ToList(); var rest = node.TopLevelDeclarations.Where(decl => !(decl is GlobalVariable)).ToList(); // Gather all declared global variables foreach (Declaration d in globals) { var g = d as GlobalVariable; if (g == null) { continue; } // Store declared global declaredGlobals.Add(g.Name); } if (trackedVars.Contains(new VarSet(declaredGlobals, BoogieUtil.GetAllProcNames(node)))) { return(node); } // Make sure all the vars to track are declared Debug.Assert(declaredGlobals.Contains(trackedVars.Variables)); // Visit declaration other than global variable declarations for (int i = 0, n = rest.Count; i < n; i++) { rest[i] = this.VisitDeclaration(rest[i]); } // Remove globals that are not tracked node.TopLevelDeclarations = globals.Where(x => isTrackedVariable(x as GlobalVariable)); node.AddTopLevelDeclarations(rest); foreach (var proc in slicedEnsures) { if (visitedImplementations.Contains(proc)) { Log.WriteLine(Log.Warning, "Slicing away (non-free) ensures condition"); } } if (slicedRequires.Any()) { Log.WriteLine(Log.Warning, "Slicing away (non-free) requires condition"); } // Remove annotations that won't parse because of dropped variables RemoveVarsFromAttributes.Prune(node); return(node); }