コード例 #1
0
        static MethodDefinition GetMethod(ObjCMethodDecl decl)
        {
            MethodDefinition md;

            methods.TryGetValue(decl.GetName(), out md);
            return(md);
        }
コード例 #2
0
ファイル: SimdCheck.cs プロジェクト: wbsabc/xamarin-macios
        public override void VisitObjCMethodDecl(ObjCMethodDecl decl, VisitKind visitKind)
        {
            if (visitKind != VisitKind.Enter)
            {
                return;
            }

            // don't process methods (or types) that are unavailable for the current platform
            if (!decl.IsAvailable() || !(decl.DeclContext as Decl).IsAvailable())
            {
                return;
            }

            var framework = Helpers.GetFramework(decl);

            if (framework == null)
            {
                return;
            }

            var simd_type = string.Empty;
            var requires_marshal_directive = false;
            var native_simd = ContainsSimdTypes(decl, ref simd_type, ref requires_marshal_directive);

            ManagedSimdInfo info;

            managed_methods.TryGetValue(decl.GetName(), out info);
            var method = info?.Method;

            if (!native_simd)
            {
                if (method != null)
                {
                    // The managed method uses types that were incorrectly used in place of the correct Simd types,
                    // but the native method doesn't use the native Simd types. This means the binding is correct.
                }
                else
                {
                    // Neither the managed nor the native method have anything to do with Simd types.
                }
                return;
            }

            if (method == null)
            {
                // Could not map the native method to a managed method.
                // This needs investigation, to see why the native method couldn't be mapped.

                // Check if this is new API, in which case it probably couldn't be mapped because we haven't bound it.
                var is_new      = false;
                var attrs       = decl.Attrs.ToList();
                var parentClass = decl.DeclContext as Decl;
                if (parentClass != null)
                {
                    attrs.AddRange(parentClass.Attrs);
                }

                foreach (var attr in attrs)
                {
                    var av_attr = attr as AvailabilityAttr;
                    if (av_attr == null)
                    {
                        continue;
                    }
                    if (av_attr.Platform.Name != "ios")
                    {
                        continue;
                    }
                    if (av_attr.Introduced.Major >= 11)
                    {
                        is_new = true;
                        break;
                    }
                }
                if (is_new && !very_strict)
                {
                    return;
                }
                if (!strict)
                {
                    return;
                }
                Log.On(framework).Add($"!missing-simd-managed-method! {decl}: could not find a managed method for the native method {decl.GetName ()} (selector: {decl.Selector}). Found the simd type '{simd_type}' in the native signature.");
                return;
            }

            if (!info.ContainsInvalidMappingForSimd)
            {
                // The managed method does not have any types that are incorrect for Simd.
                if (requires_marshal_directive)
                {
                    CheckMarshalDirective(method, simd_type);
                }
                return;
            }

            if (method.IsObsolete())
            {
                // We have a potentially broken managed method, but it's obsolete. That's fine.
                return;
            }

            if (requires_marshal_directive)
            {
                CheckMarshalDirective(method, simd_type);
            }

            // We have a potentially broken managed method. This needs fixing/investigation.
            Log.On(framework).Add($"!unknown-simd-type-in-signature! {method}: the native signature has a simd type ({simd_type}), while the corresponding managed method is using an incorrect (non-simd) type.");
        }