Example #1
0
    /// <summary>
    /// Apply the inter-procedural analysis, binding information from caller and callee
    /// </summary>
    /// <param name="vr"></param>
    /// <param name="callee"></param>
    /// <param name="receiver"></param>
    /// <param name="arguments"></param>
    /// <param name="calleecState"></param>
    /// <param name="lb"></param>
    public virtual void ApplyAnalyzableCall(Variable vr, Method callee, Variable receiver,
        ExpressionList arguments, PointsToState calleecState, Label lb, out InterProcMapping ipm)
    {

      // Apply the binding between the pointsToGraph of the caller and the callee
      // Returns also the mapping used during the parameter-arguments nodes binding 

      if (PointsToAnalysis.debug)
      {
        Console.Out.WriteLine("before call to {0}", callee.Name);
        //pointsToGraph.Dump();
        this.Dump();
      }

      if (this.Method.Name.Name.StartsWith("UsingFoo"))
      {
      }  

      ipm = InterProcMapping.ComputeInterProgMapping(this.pointsToGraph, calleecState.pointsToGraph,
          receiver, arguments, vr, lb);

      BeforeBindCallWithCallee(this, calleecState, receiver, arguments, vr, lb, ipm);

      PTGraph interProcPTG = ipm.ComputeInterProgGraph(this.pointsToGraph, calleecState.pointsToGraph,
          receiver, arguments, vr, lb);

      pointsToGraph = interProcPTG;

      AfterBindCallWithCallee(this, calleecState, receiver, arguments, vr, lb, ipm);


      if (PointsToAnalysis.debug)
      {
        Console.Out.WriteLine("after call to {0}", callee.Name);
        Console.Out.WriteLine(ipm);
        Console.Out.WriteLine("Callee:");
        calleecState.Dump();

        Console.Out.WriteLine("Caller:");
        this.Dump();
      }

      // Update the set of write effects considering the writeffects of the callee
      // in nodes that will stay in the caller
      Set<LNode> removedLoadNodes = ipm.removedLoadNodes;
      // Join the set of non-analyzable calls
      //joinCalledMethod(callToNonAnalyzableMethods, calleecState.callToNonAnalyzableMethods);
    }
Example #2
0
      /// <summary>
    /// The old support for non Analyzables. TO DELETE
    /// </summary>
    /// <param name="vr"></param>
    /// <param name="callee"></param>
    /// <param name="receiver"></param>
    /// <param name="arguments"></param>
    /// <param name="lb"></param>
    /// <param name="ipm"></param>
    public virtual void ApplyNonAnalyzableCallOld(Variable vr, Method callee, Variable receiver,
        ExpressionList arguments, Label lb, out InterProcMapping ipm)
    {
      bool isPure = false;
      bool isReturnFresh = false;
      bool isReadingGlobals = true;
      bool isWritingGlobals = true;
      Set<Parameter> freshOutParameters = new Set<Parameter>();
      Set<Parameter> escapingParameters = new Set<Parameter>();
      Set<Parameter> capturedParameters = new Set<Parameter>();
      Set<Variable> outArguments = new Set<Variable>();

      isPure = PointsToAndEffectsAnnotations.IsAssumedPureMethod(callee);
      isReadingGlobals = PointsToAndEffectsAnnotations.IsDeclaredReadingGlobals(callee);
      isWritingGlobals = PointsToAndEffectsAnnotations.IsDeclaredWritingGlobals(callee);
      if (PointsToAnalysis.debug)
      {
        Console.Out.WriteLine("before NON call to {0}", callee.Name);
        pointsToGraph.Dump();
      }
      if (!callee.ReturnType.IsPrimitive && !CciHelper.IsVoid(callee.ReturnType))
      {
        isReturnFresh = PointsToAndEffectsAnnotations.IsDeclaredFresh(callee);
      }
      else
        if (CciHelper.IsConstructor(callee))
          isReturnFresh = true;

      if (!callee.IsStatic && callee.ThisParameter != null)
      {
        bool captured;
        if (PointsToAndEffectsAnnotations.IsDeclaredEscaping(callee.ThisParameter, out captured))
        {
          escapingParameters.Add(callee.ThisParameter);
          if (captured)
            capturedParameters.Add(callee.ThisParameter);
        }
      }
      if (callee.Parameters != null)
      {
        for (int i = 0; i < callee.Parameters.Count; i++)
        {
          Parameter p = callee.Parameters[i];
          if (p.IsOut)
          {
            if (PointsToAndEffectsAnnotations.IsDeclaredFresh(p))
            {
              freshOutParameters.Add(p);
            }
            outArguments.Add(arguments[i] as Variable);
          }
          bool captured;
          if (PointsToAndEffectsAnnotations.IsDeclaredEscaping(p, out captured))
          {
            escapingParameters.Add(p);
            if (captured)
              capturedParameters.Add(p);
          }
        }
      }

      //if (isWritingGlobals)
      //{
      //    addNonAnalyzableMethod(lb, callee);
      //}

     
      if (callee.Name.Name.Equals("Hola") || callee.Name.Name.Equals("GetEnumerator2"))
      {
      }

        PTGraph calleFakePTG = null;
        // Create a fake PTG for the calle using annotations...
        calleFakePTG = PTGraph.PTGraphFromAnnotations(callee);
        // , isPure, isReturnFresh, isWritingGlobals, isReadingGlobals);


          // calleFakePTG.GenerateDotGraph(callee.FullName + ".dot");      

        NonAnalyzableCallBeforeUpdatingPTG(vr, callee, receiver, arguments, lb,
          isPure, isReturnFresh, isWritingGlobals, isReadingGlobals,
          escapingParameters, capturedParameters, freshOutParameters);


          /*InterProcMapping */ 
           ipm = InterProcMapping.ComputeInterProgMapping(this.pointsToGraph, calleFakePTG,
               receiver, arguments, vr, lb);
            

          PTGraph interProcPTG = ipm.ComputeInterProgGraph(this.pointsToGraph, calleFakePTG,
              receiver, arguments, vr, lb);

          pointsToGraph = interProcPTG;

       
      NonAnalyzableCallAfterUpdatingPTG(vr, callee, receiver, arguments, lb,
           isPure, isReturnFresh, isWritingGlobals, isReadingGlobals,
           escapingParameters, capturedParameters, freshOutParameters);
      if (PointsToAnalysis.debug)
      {
        Console.Out.WriteLine("after NON call to {0}", callee.Name);
        pointsToGraph.Dump();
      }
    }