Ejemplo n.º 1
0
        private static ExceptionInfo ScanPlatformNotSupported(IMethodDefinition method, int nestingLevel = 0)
        {
            const int maxNestingLevel = 3;

            if (method is Dummy ||
                method.IsAbstract ||
                method.Attributes.Any(attrb => attrb.FullName().Equals("System.Runtime.CompilerServices.IntrinsicAttribute")))
            {
                return(ExceptionInfo.DoesNotThrow);
            }

            // Not all intrisincs are marked with attributes
            var docId = method.DocId();

            if (docId.StartsWith("M:System.Runtime.Intrinsics") || docId.StartsWith("M:System.ByReference"))
            {
                return(ExceptionInfo.DoesNotThrow);
            }

            foreach (var op in GetOperationsPreceedingThrow(method))
            {
                // throw new PlatformNotSupportedExeption(...)
                if (op.OperationCode == OperationCode.Newobj &&
                    op.Value is IMethodReference m &&
                    IsPlatformNotSupported(m))
                {
                    return(ExceptionInfo.ThrowsAt(nestingLevel, method.DocId()));
                }

                // throw SomeFactoryForPlatformNotSupportedExeption(...);
                if (op.Value is IMethodReference r &&
                    IsFactoryForPlatformNotSupported(r))
                {
                    return(ExceptionInfo.ThrowsAt(nestingLevel, method.DocId()));
                }
            }

            var result = ExceptionInfo.DoesNotThrow;

            if (nestingLevel < maxNestingLevel)
            {
                foreach (var calledMethod in GetCalls(method))
                {
                    var nestedResult = ScanPlatformNotSupported(calledMethod.ResolvedMethod, nestingLevel + 1);
                    result = result.Combine(nestedResult);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private static ExceptionInfo ScanPlatformNotSupported(IMethodDefinition method, int nestingLevel = 0)
        {
            const int maxNestingLevel = 3;

            if (method is Dummy || method.IsAbstract)
            {
                return(ExceptionInfo.DoesNotThrow);
            }

            foreach (var op in GetOperationsPreceedingThrow(method))
            {
                // throw new PlatformNotSupportedExeption(...)
                if (op.OperationCode == OperationCode.Newobj &&
                    op.Value is IMethodReference m &&
                    IsPlatformNotSupported(m))
                {
                    return(ExceptionInfo.ThrowsAt(nestingLevel, method.DocId()));
                }

                // throw SomeFactoryForPlatformNotSupportedExeption(...);
                if (op.Value is IMethodReference r &&
                    IsFactoryForPlatformNotSupported(r))
                {
                    return(ExceptionInfo.ThrowsAt(nestingLevel, method.DocId()));
                }
            }

            var result = ExceptionInfo.DoesNotThrow;

            if (nestingLevel < maxNestingLevel)
            {
                foreach (var calledMethod in GetCalls(method))
                {
                    var nestedResult = ScanPlatformNotSupported(calledMethod.ResolvedMethod, nestingLevel + 1);
                    result = result.Combine(nestedResult);
                }
            }

            return(result);
        }