Ejemplo n.º 1
0
        protected override void LanguageSpecificAnalysis(Method method)
        {
            if (!this.CodeIsWellFormed)
            {
                return;
            }
            if (Cci.Analyzer.Debug)
            {
                ControlFlowGraph cfg = GetCFG(method);
                if (cfg != null)
                {
                    cfg.Display(Console.Out);
                }
            }
            if (method.Name.Name.StartsWith("Microsoft.Contracts"))
            {
                return;
            }
            // Weak Purity and Effects Analysis
            if (this.WeakPurityAnalysis && this.WeakPurityAnalyzer != null)
            {
                this.WeakPurityAnalyzer.VisitMethod(method); // computes points-to and effects
                // processes results from VisitMethod: issues errors and potentially prints out detailed info.
                this.WeakPurityAnalyzer.ProcessResultsMethod(method);

                // Admissibility Check
                PointsToAndWriteEffects ptwe = this.WeakPurityAnalyzer.GetPurityAnalysisWithDefault(method);
                if (method.IsConfined || method.IsStateIndependent)
                {
                    Microsoft.SpecSharp.ReadEffectAdmissibilityChecker reac = new Microsoft.SpecSharp.ReadEffectAdmissibilityChecker(method, typeSystem.ErrorHandler);
                    reac.CheckReadEffectAdmissibility(ptwe.ComputeEffects(ptwe.ReadEffects));
                }
            }

            if (ReentrancyAnalysis)
            {
                if (this.ReentrancyAnalyzer != null)
                {
                    this.ReentrancyAnalyzer.VisitMethod(method);
                }
            }

            if (ObjectExposureAnalysis)
            {
                if (this.ObjectExposureAnalyzer != null)
                {
                    this.ObjectExposureAnalyzer.VisitMethod(method);
                }
            }
        }
 // Copy Constructor
 public PointsToAndWriteEffects(PointsToAndWriteEffects ptWE): base(ptWE)
 {
     writeEffects = new AbstractEffects(ptWE.writeEffects);
     allWriteEffects = ptWE.allWriteEffects;
     readEffects = new AbstractEffects(ptWE.readEffects); ;
     allReadEffects = ptWE.allReadEffects;
     callToNonAnalyzableMethods = new Dictionary<Label, Set<Method>>(ptWE.callToNonAnalyzableMethods);
     
     //if(ptWE.nonNullState!=null)
     //    nonNullState = new NonNullState((NonNullState)ptWE.nonNullState);
 }
        /// <summary>
        /// Create an PTG and effect information for a non analyzable method
        /// </summary>
        /// <param name="vr"></param>
        /// <param name="callee"></param>
        /// <param name="receiver"></param>
        /// <param name="arguments"></param>
        /// <param name="lb"></param>
        /// 
        public override PointsToState CreateSummaryForFakeCallee(Variable vr, Method callee, Variable receiver, ExpressionList arguments, Label lb)
        {
            Variable newReceiver = receiver;

            if(receiver!=null && PTGraph.IsDelegateType(receiver.Type))
            {
                 AttributeList delegateAttributes = GetDelegateAttributes(receiver);
                /*  
                bool isPureDelegate = CheckPureDelegate(receiver);
                
                if (isPureDelegate)
                {
                    PointsToState calleeStateP = new PointsToState(callee, this.pta);
                    PTGraph ptg = PTGraph.CreatePTGraphForStronglyPureMethod(callee);
                    calleeStateP.pointsToGraph = ptg;
                    PointsToAndWriteEffects calleeS = new PointsToAndWriteEffects(calleeStateP);
                    return calleeS;
                }
                */
                DelegateNode dn = receiver.Type as DelegateNode;

                //Method fakeMethod = new Method(Method.DeclaringType, delegateAttributes,
                //                        new Identifier(receiver.Name.Name), dn.Parameters, dn.ReturnType, null);
                // callee = fakeMethod;
                callee.Attributes = delegateAttributes;

            }
            
            PointsToState calleeStatePT = base.CreateSummaryForFakeCallee(vr, callee, receiver, arguments, lb);
            PointsToAndWriteEffects calleeState = new PointsToAndWriteEffects(calleeStatePT);
            
            foreach (Parameter p in calleeState.Parameters)
            {
                bool isWrite = PointsToAndEffectsAnnotations.IsWriteParameter(callee, p);
                bool isWriteConfined = PointsToAndEffectsAnnotations.IsWriteConfinedParameter(callee, p);

                // Faltan los READ EFFECTS!!!
                if (isWrite || isWriteConfined)
                {
                    foreach(IPTAnalysisNode n in calleeState.pointsToGraph.NonAnalyzableLeaves(p))
                    {
                        calleeState.writeEffects.AddEffect(n, PTGraph.allFields, lb);
                        calleeState.allWriteEffects.AddEffect(n, PTGraph.allFields, lb);
                        if (PTGraph.isRef(p.Type))
                        {
                            foreach (IPTAnalysisNode valP in calleeState.pointsToGraph.Values(p))
                            {
                                calleeState.writeEffects.AddEffect(valP, PTGraph.asterisk, lb);
                                calleeState.allWriteEffects.AddEffect(valP, PTGraph.asterisk, lb);
                            }

                        }
                    }
                }
                if (p.IsOut)
                {
                    foreach (IPTAnalysisNode valP in calleeState.pointsToGraph.Values(p))
                    {
                        calleeState.writeEffects.AddEffect(valP, PTGraph.asterisk, lb);
                        calleeState.allWriteEffects.AddEffect(valP, PTGraph.asterisk, lb);
                    }

                }
                
            }
            if (PointsToAndEffectsAnnotations.IsDeclaredWritingGlobals(callee))
            {
                addNonAnalyzableMethod(lb, callee);
                calleeState.writeEffects.AddEffect(GNode.nGBL, PTGraph.allFields, lb);
                calleeState.allWriteEffects.AddEffect(GNode.nGBL, PTGraph.allFields, lb);
                calleeState.readEffects.AddEffect(GNode.nGBL, PTGraph.allFields, lb);
                calleeState.allReadEffects.AddEffect(GNode.nGBL, PTGraph.allFields, lb);
            }
            /*
            if (PointsToAndEffectsAnnotations.IsDeclaredReadingGlobals(callee))
            {
                calleeState.readEffects.AddEffect(GNode.nGBL, PTGraph.asterisk, lb);
                calleeState.allReadEffects.AddEffect(GNode.nGBL, PTGraph.asterisk, lb);
            }
            */
            

            return calleeState;
        }
 private void BindCallerReadEffects(PointsToAndWriteEffects calleePTWE, Label lb, InterProcMapping ipm)
 {
     foreach (AField af in calleePTWE.readEffects)
     {
         // Get the related caller's nodes
         foreach (IPTAnalysisNode n in ipm.RelatedExtended(af.Src))
         {
             if (IsVisibleEffect(n, af.Field))
             {
                 readEffects.AddEffect(n, af.Field, lb);
             }
             allReadEffects.AddEffect(n, af.Field, lb);
         }
     }
 }
 public void SetPurityAnalysys(Method m, PointsToAndWriteEffects ptwe)
 {
     base.SetSummaryForMethod(m, ptwe);
 }