internal ProgramState RemoveSymbols(Func <ISymbol, bool> predicate) { var cleanedValues = Values .Where(kv => !predicate(kv.Key)) .ToImmutableDictionary(); // SVs for live symbols var usedSymbolicValues = cleanedValues.Values .Concat(DistinguishedReferences) .Concat(cleanedValues.Values.OfType <NullableSymbolicValue>().Select(x => x.WrappedValue)) // Do not lose constraints on wrapped SV .ToImmutableHashSet(); var cleanedConstraints = Constraints .Where(kv => usedSymbolicValues.Contains(kv.Key) || ProtectedSymbolicValues.Contains(kv.Key) || ExpressionStack.Contains(kv.Key)) .ToImmutableDictionary(); // Relationships for live symbols (no transitivity, so both of them need to be live in order to hold any information) var cleanedRelationships = Relationships .Where(r => usedSymbolicValues.Contains(r.LeftOperand) || usedSymbolicValues.Contains(r.RightOperand)) .ToImmutableHashSet(); return(new ProgramState(cleanedValues, cleanedConstraints, ProgramPointVisitCounts, ExpressionStack, cleanedRelationships)); }
internal ProgramState Clean(IEnumerable <ISymbol> liveSymbolsToKeep) { var cleanedValues = Values .Where(sv => liveSymbolsToKeep.Contains(sv.Key)) .ToImmutableDictionary(); // SVs for live symbols var usedSymbolicValues = cleanedValues.Values .Concat(DistinguishedReferences) .ToImmutableHashSet(); var cleanedConstraints = Constraints .Where(kv => usedSymbolicValues.Contains(kv.Key) || ProtectedSymbolicValues.Contains(kv.Key) || ExpressionStack.Contains(kv.Key)) .ToImmutableDictionary(); // Relationships for live symbols (no transitivity, so both of them need to be live in order to hold any information) var cleanedRelationships = Relationships .Where(r => usedSymbolicValues.Contains(r.LeftOperand) || usedSymbolicValues.Contains(r.RightOperand)) .ToImmutableHashSet(); return(new ProgramState(cleanedValues, cleanedConstraints, ProgramPointVisitCounts, ExpressionStack, cleanedRelationships)); }