public void AssignHeapTraceables(SimplePTGNode SimplePTGNode, IFieldReference field, IEnumerable <Traceable> traceables) { var newTraceables = new HashSet <Traceable>(traceables); // If it is a scalar field we modify A3_Field if (!field.Type.IsClassOrStruct()) { var location = new Location(SimplePTGNode, field); //this.Dependencies.A3_Fields[location] = new HashSet<Traceable>(traceables); // TODO: a weak update this.Dependencies.A3_Fields[location] = newTraceables; } // This should be only for references // we modify A2_Refs(n) where n \in PT(SimplePTGNode, field) if (field.Type.IsClassOrStruct()) { var targets = PTG.GetTargets(SimplePTGNode, field);// .Except(new HashSet<SimplePTGNode>() { SimplePointsToGraph.NullNode } ); if (targets.Any()) { foreach (var targetNode in targets) { if (targetNode != SimplePointsToGraph.NullNode) { // TODO: Change for Add this.Dependencies.A2_References[targetNode] = newTraceables; //this.Dependencies.A2_References[targetNode] = new HashSet<Traceable>(traceables); } } } else { } } }
public IEnumerable <Traceable> GetHeapTraceables(SimplePTGNode node, IFieldReference field) { var location = new Location(node, field); var originalTraceables = GetLocationTraceables(location); var traceables = new HashSet <Traceable>(); if (field.Type.IsClassOrStruct()) { foreach (var target in PTG.GetTargets(node, field)) { if (Dependencies.A2_References.ContainsKey(target) && target != SimplePointsToGraph.NullNode) { traceables.UnionWith(Dependencies.A2_References[target]); } } } if (traceables.Count > originalTraceables.Count) { } originalTraceables.UnionWith(traceables); return(originalTraceables); }
public void ProcessStore(SimplePointsToGraph ptg, uint offset, IVariable instance, IFieldReference field, IVariable src) { if (!field.Type.IsClassOrStruct() || !src.Type.IsClassOrStruct()) { return; } var nodes = ptg.GetTargets(instance, false); var targets = ptg.GetTargets(src).Except(new HashSet <SimplePTGNode>() { SimplePointsToGraph.NullNode }); if (targets.Any()) { foreach (var node in nodes) { foreach (var target in targets) { ptg.PointsTo(node, field, target); } } } else { // Create a fake node for the target var ptgID = new PTGID(new MethodContex(this.method), (int)offset); var fakeNode = new SimplePTGNode(ptgID, src.Type); foreach (var node in nodes) { ptg.PointsTo(node, field, fakeNode); } } }
public SimplePTGNode ProcessGetEnum(SimplePointsToGraph ptg, uint offset, IVariable collectionVariable, IVariable result) { var ptgId = new PTGID(new MethodContex(this.method), (int)offset); var enumNode = this.NewNode(ptg, ptgId, MyLoader.PlatformTypes.SystemCollectionsIEnumerator); ptg.RemoveRootEdges(result); ptg.PointsTo(result, enumNode); var nodes = ptg.GetTargets(collectionVariable); if (nodes.Count == 1 && nodes.Single() == SimplePointsToGraph.NullNode) { var collectionNode = new SimplePTGNode(ptgId, collectionVariable.Type); ptg.PointsTo(collectionVariable, collectionNode); } var collecitonField = new FieldReference("$collection", MyLoader.PlatformTypes.SystemObject, this.method.ContainingType); this.ProcessStore(ptg, offset, result, collecitonField, collectionVariable); //foreach (var colNode in ptg.GetTargets(collectionVariable)) //{ // ptg.PointsTo(enumNode, collecitonField, colNode); //} return(enumNode); }
private SimplePTGNode NewNode(SimplePointsToGraph ptg, PTGID ptgID, ITypeReference type, SimplePTGNodeKind kind = SimplePTGNodeKind.Object) { SimplePTGNode node; node = new SimplePTGNode(ptgID, type, kind); //node = ptg.GetNode(ptgID, type, kind); return(node); }
private static string Serialize(SimplePTGNode node) { string result; switch (node.Kind) { case SimplePTGNodeKind.Null: result = "null"; break; default: result = TypeHelper.GetTypeName(node.Type); break; } return(result); }
private bool MayReacheableFromParameter(SimplePointsToGraph ptg, SimplePTGNode n) { var body = MethodBodyProvider.Instance.GetBody(method); var rootNodes = body.Parameters.SelectMany(p => ptg.GetTargets(p)).Union(new HashSet <SimplePTGNode>() { SimplePointsToGraph.GlobalNode }); var reachable = ptg.ReachableNodes(rootNodes).Contains(n); // This version does not need the inverted mapping of nodes-> variables (which may be expensive to maintain) // var result = method.Body.Parameters.Any(p =>ptg.GetTargets(p).Contains(n)); return(reachable); ; }
private ICollection <int> InternalGetLastDefs(SimplePTGNode SimplePTGNode, IFieldReference f) { IDictionary <IFieldReference, ICollection <int> > lastDefsDict = new Dictionary <IFieldReference, ICollection <int> >(); ICollection <int> lastDefs = new HashSet <int>(); if (LastDefsPtg.ContainsKey(SimplePTGNode)) { lastDefsDict = LastDefsPtg[SimplePTGNode]; } else { LastDefsPtg[SimplePTGNode] = lastDefsDict; } if (lastDefsDict.ContainsKey(f)) { lastDefs = lastDefsDict[f]; } else { lastDefsDict[f] = lastDefs; } return(lastDefs); }
public DependencyInfo(SimplePTGNode symObj, string traceable) { SymbolicObject = symObj; Traceable = traceable; }
private ICollection <int> LastDefGet(SimplePTGNode SimplePTGNode, IFieldReference f) { ICollection <int> lastDefs = InternalGetLastDefs(SimplePTGNode, f); return(lastDefs); }
private void LastDefSet(SimplePTGNode SimplePTGNode, IFieldReference f, IEnumerable <int> locations) { ICollection <int> lastDefs = InternalGetLastDefs(SimplePTGNode, f); lastDefs.AddRange(locations); }
private void LastDefSet(SimplePTGNode SimplePTGNode, IFieldReference f, int location) { ICollection <int> lastDefs = InternalGetLastDefs(SimplePTGNode, f); lastDefs.Add(location); }
//private void Flow(SimplePointsToGraph ptg, Instruction instruction) //{ // var ptaVisitor = new PTAVisitor(ptg, this); // ptaVisitor.Visit(instruction); //} private void CreateInitialGraph(bool createNodeForParams = true, SimplePointsToGraph initialGraph = null) { this.ReturnVariable = new LocalVariable(this.method.Name + "_" + "$RV", method) { Type = this.method.Type.PlatformType.SystemObject }; //IteratorPointsToAnalysis.GlobalVariable= new LocalVariable("$Global"); //IteratorPointsToAnalysis.GlobalVariable.Type = MyLoader.PlatformTypes.SystemObject; var ptg = initialGraph == null ? new SimplePointsToGraph() : initialGraph.Clone(); var variables = cfg.GetVariables(); var body = MethodBodyProvider.Instance.GetBody(this.method); var parameters = body.Parameters; if (parameters != null) { variables.AddRange(parameters); } int counter = -1; IVariable thisVariable = null; SimplePTGNode thisNode = null; foreach (var variable in variables) { // TODO: replace when Egdardo fixes type inferece if (variable.Type == null || !variable.Type.IsClassOrStruct()) { continue; } // if (variable.Type.TypeKind == TypeKind.ValueType) continue; if (variable.IsParameter) { var isThisParameter = variable.Name == "this"; var kind = isThisParameter ? SimplePTGNodeKind.Object : SimplePTGNodeKind.Unknown; if (createNodeForParams) { var ptgId = new PTGID(new MethodContex(this.method), counter--); var node = new ParameterNode(ptgId, variable.Name, variable.Type); ptg.Add(node); ptg.PointsTo(variable, node); if (isThisParameter) { thisVariable = variable; thisNode = node; } } if (isThisParameter) { this.ThisVariable = variable; } ptg.Add(variable); } else { //ptg.Add(variable); ptg.PointsTo(variable, SimplePointsToGraph.NullNode); } } //foreach(var specialField in specialFields) //{ // counter = -1000; // var variable = specialField.Value; // var fieldName = specialField.Key; // var ptgId = new PTGID(new MethodContex(this.method), counter--); // var node = new SimplePTGNode(ptgId, variable.Type); // ptg.Add(node); // ptg.PointsTo(thisNode, new FieldReference(fieldName, variable.Type, method.ContainingType), node); //} ptg.Add(this.ReturnVariable); ptg.Add(SimplePointsToAnalysis.GlobalVariable); ptg.PointsTo(SimplePointsToAnalysis.GlobalVariable, SimplePointsToGraph.GlobalNode); this.initialGraph = ptg; }