Beispiel #1
0
        // This method is used during FactGeneration. The above CheckAndAdd methods are used during RTAAnalysis.
        // Since we are not modifying invoke statments to invoke methods in stubs (whenever stubs are used), we need the below method.
        public static IMethodDefinition GetMethodToAnalyze(IMethodDefinition m)
        {
            // Three cases: m should completely be ignored, should be analyzed as is, or the equivalent stub should be analyzed.
            IMethodDefinition methToAnalyze = m;
            bool matches = MatchesSuppressM(m);

            if (matches)
            {
                ITypeDefinition containingType = m.ContainingTypeDefinition;
                containingType = Stubs.GetStubType(containingType);
                if (containingType == null)
                {
                    return(null);                        // This entire containingType is to be ignored.
                }
                if (methToAnalyze is IGenericMethodInstance)
                {
                    methToAnalyze = GenericMethods.GetTemplate(m);
                }
                methToAnalyze = Utils.GetMethodSignMatch(containingType, methToAnalyze);
                if (methToAnalyze == null)
                {
                    return(null);                       // containingType itself is stubbed, but the stub does not define a method equivalent to m.
                }
                if (methToAnalyze.IsGeneric)
                {
                    methToAnalyze = GenericMethods.GetInstantiatedMeth(methToAnalyze, m);
                }
            }
            return(methToAnalyze);
        }
Beispiel #2
0
        public static ITypeDefinition CheckAndAdd(ITypeDefinition t)
        {
            if (SuppressF(t))
            {
                return(null);
            }
            if (t is IGenericTypeInstance)
            {
                IGenericTypeInstance         gty     = t as IGenericTypeInstance;
                IEnumerable <ITypeReference> genArgs = gty.GenericArguments;
                foreach (ITypeReference garg in genArgs)
                {
                    CheckAndAdd(garg.ResolvedType);
                }
            }

            ITypeDefinition toAdd   = t;
            bool            matches = MatchesSuppressM(t);

            if (matches)
            {
                ITypeDefinition stubType = Stubs.GetStubType(t);
                if (stubType != null)
                {
                    toAdd = stubType;
                }
            }
            if (!rtaAnalyzer.visitedClasses.Contains(toAdd) && !rtaAnalyzer.classes.Contains(toAdd))
            {
                rtaAnalyzer.rtaLogSW.WriteLine("SRK_DBG: Adding class: {0}", toAdd.FullName());
                rtaAnalyzer.classes.Add(toAdd);
                rtaAnalyzer.classWorkList.Add(toAdd);
            }
            return(toAdd);
        }
Beispiel #3
0
        public static bool SuppressM(ITypeDefinition ty)
        {
            bool retval  = false;
            bool matches = MatchesSuppressM(ty);

            if (matches)
            {
                ITypeDefinition stubType = Stubs.GetStubType(ty);
                retval = stubType == null ? true : false;
            }
            return(retval);
        }
Beispiel #4
0
        /****
        *  Four cases:
        *  1. Ordinary method (not stubbed and not generic)
        *  2. Stubbed but not generic
        *  3. Not stubbed but generic
        *  4. Stubbed and generic
        *  Note that there are two sub-cases for "is stubbed": "stub present" or "stub absent".
        *  So that makes it a total of 6 cases.
        ****/
        public static IMethodDefinition CheckAndAdd(IMethodDefinition m)
        {
            IMethodDefinition lookFor = m;

            if (m is IGenericMethodInstance)
            {
                lookFor = GenericMethods.GetTemplate(m);
            }

            ITypeDefinition containingType = m.ContainingTypeDefinition;

            if (containingType.InternedKey == 0)
            {
                return(m);                                 // Ignore methods from Cci's Dummy typeref.
            }
            bool matches = MatchesSuppressM(m);

            if (matches)
            {
                containingType = Stubs.GetStubType(containingType);
                if (containingType == null)
                {
                    return(null);                        // This entire containingType is to be ignored.
                }
                lookFor = Utils.GetMethodSignMatch(containingType, lookFor);
                if (lookFor == null)
                {
                    return(null);                 // containingType itself is stubbed, but the stub does not define a method equivalent to m.
                }
            }

            IMethodDefinition methToAdd;

            if (m is IGenericMethodInstance)
            {
                // Here, lookFor is a template method
                methToAdd = GenericMethods.RecordInfo(lookFor, m, matches);
            }
            else
            {
                methToAdd = lookFor;
            }
            if (!rtaAnalyzer.visitedMethods.Contains(methToAdd) && !rtaAnalyzer.methods.Contains(methToAdd))
            {
                rtaAnalyzer.rtaLogSW.WriteLine("SRK_DBG: Adding method: {0}", methToAdd.FullName());
                rtaAnalyzer.methods.Add(methToAdd);
            }
            return(methToAdd);
        }
Beispiel #5
0
        public static ITypeDefinition GetTypeToAnalyze(ITypeDefinition ty)
        {
            ITypeDefinition retTy   = ty;
            bool            matches = MatchesSuppressM(ty);

            if (matches)
            {
                ITypeDefinition stubType = Stubs.GetStubType(ty);
                if (stubType != null)
                {
                    retTy = stubType;
                }
                else
                {
                    retTy = null;
                }
            }
            return(retTy);
        }
Beispiel #6
0
        public static bool TypeMatch(ITypeReference t1, ITypeReference t2)
        {
            ITypeDefinition tdef1 = t1.ResolvedType;
            ITypeDefinition tdef2 = t2.ResolvedType;

            if (tdc.Equals(tdef1, tdef2))
            {
                return(true);
            }

            if (Stubber.MatchesSuppressM(tdef1))
            {
                tdef1 = Stubs.GetStubType(tdef1);
            }
            if (Stubber.MatchesSuppressM(tdef2))
            {
                tdef2 = Stubs.GetStubType(tdef2);
            }
            // return (tdef1 != null && tdef2 != null && tdc.Equals(tdef1, tdef2));
            if (tdef1 != null && tdef2 != null)
            {
                if (tdef1 is IGenericTypeInstance)
                {
                    tdef1 = (tdef1 as IGenericTypeInstance).GenericType.ResolvedType;
                }
                if (tdef2 is IGenericTypeInstance)
                {
                    tdef2 = (tdef2 as IGenericTypeInstance).GenericType.ResolvedType;
                }
                return(tdc.Equals(tdef1, tdef2));
            }
            else
            {
                return(false);
            }
        }