Ejemplo n.º 1
0
        public Set <VariableEffect> ComputePathsFromVariableToHeapLocation(Set <IPTAnalysisNode> ns, Label lb)
        {
            Set <VariableEffect> variableEffects = new Set <VariableEffect>();

            //if (WriteEffects.HasWriteEffects)
            //    Console.Out.WriteLine("Modifies:");

            // Traverse every write effect
            foreach (IPTAnalysisNode n in ns)
            {
                // Get the fields that are backward reachable from the modified field
                Set <List <Edge> > paths = PointsToGraph.DFSPathFrom(n, false, true, true);
                foreach (List <Edge> currentPath in paths)
                {
                    currentPath.Reverse();

                    IPTAnalysisNode rootNode;

                    if (currentPath.Count > 0)
                    {
                        rootNode = currentPath[0].Src;
                    }
                    else
                    {
                        rootNode = n;
                    }

                    Variable v = null;

                    if (rootNode.IsVariableReference)
                    {
                        IVarRefNode vrNode = rootNode as IVarRefNode;
                        v = vrNode.ReferencedVariable;
                        if (!IsLocal(v))
                        {
                            continue;
                        }
                        //if (!(v is Parameter) && !v.Equals(PTGraph.GlobalScope))
                        //    continue;
                    }

                    if (rootNode.Equals(GNode.nGBL))
                    {
                        v = PTGraph.GlobalScope;
                    }

                    /*
                     * if (rootNode.IsParameterNode && ((PNode)rootNode).IsByValue)
                     * {
                     *  bool fieldUpdate = !n.Field.Equals(PTGraph.asterisk);
                     *  foreach (Edge e in currentPath)
                     *      fieldUpdate = fieldUpdate || !e.Field.Equals(PTGraph.asterisk);
                     *  if (!fieldUpdate)
                     *      continue;
                     * }
                     */
                    string nodeName = rootNode.Name;

                    if (v != null)
                    {
                        VariableEffect vEffect = new VariableEffect(v, lb);
                        foreach (Edge e in currentPath)
                        {
                            if (!e.Field.Equals(PTGraph.asterisk))
                            {
                                vEffect.AddField(e.Field);
                                // lastField = e.Field;
                            }
                        }
                        variableEffects.Add(vEffect);
                    }
                }
            }
            return(variableEffects);
        }
 /// <summary>
 /// Compute one Effects using one path from a variable an effect in 
 /// an abstract heap location
 /// </summary>
 /// <param name="af"></param>
 /// <param name="currentPath"></param>
 /// <param name="v"></param>
 /// <returns></returns>
 private static VariableEffect ComputeOneEffectPath(AField af, List<Edge> currentPath, Variable v)
 {
     if (WeakPurityAndWriteEffectsAnalysis.debug)
     {
         if (v == null)
             System.Diagnostics.Debugger.Break();
     }
     VariableEffect vEffect = new VariableEffect(v, af.Label);
     foreach (Edge e in currentPath)
     {
         if (!e.Field.Equals(PTGraph.asterisk))
         {
             vEffect.AddField(e.Field);
             // lastField = e.Field;
             // DIEGO-CHECK: If I have an effect on a omega node i can reach all nodes
             if (e.Src.IsOmega && (e.Field.Equals(PTGraph.allFields) || e.Field.Equals(PTGraph.allFieldsNotOwned)))
               break;
         }
     }
     if (!af.Field.Equals(PTGraph.asterisk) || vEffect.FieldChain.Count == 0)
         vEffect.AddField(af.Field,af.WasNull);
     return vEffect;
 }