예제 #1
0
        void ProcessObjcSelector(string fullname, VersionTuple objcVersion)
        {
            var    class_method  = fullname [0] == '+';
            var    n             = fullname.IndexOf("::");
            string objcClassName = fullname.Substring(class_method ? 1: 0, n);
            string selector      = fullname.Substring(n + 2);

            TypeDefinition managedType = ManagedTypes.FirstOrDefault(x => Helpers.GetName(x) == objcClassName);

            if (managedType != null)
            {
                var framework = Helpers.GetFramework(managedType);
                if (framework == null)
                {
                    return;
                }

                // If the entire type is deprecated, call it good enough
                if (AttributeHelpers.HasAnyDeprecationForCurrentPlatform(managedType))
                {
                    return;
                }

                var matchingMethod = managedType.Methods.FirstOrDefault(x => x.GetSelector() == selector && x.IsPublic && x.IsStatic == class_method);
                if (matchingMethod != null)
                {
                    ProcessItem(matchingMethod, fullname, objcVersion, framework);
                }
            }
        }
예제 #2
0
        void ProcessObjcSelector(string fullname, VersionTuple objcVersion)
        {
            string[] nameParts = fullname.Split(new string[] { "::" }, StringSplitOptions.None);

            string objcClassName = nameParts[0];
            string selector      = nameParts[1];

            TypeDefinition managedType = ManagedTypes.FirstOrDefault(x => Helpers.GetName(x) == objcClassName);

            if (managedType != null)
            {
                var framework = Helpers.GetFramework(managedType);
                if (framework == null)
                {
                    return;
                }

                // If the entire type is deprecated, call it good enough
                if (AttributeHelpers.HasAnyDeprecationForCurrentPlatform(managedType))
                {
                    return;
                }

                var matchingMethod = managedType.Methods.FirstOrDefault(x => x.GetSelector() == selector && x.IsPublic);
                if (matchingMethod != null)
                {
                    ProcessItem(matchingMethod, fullname, objcVersion, framework);
                }
            }
        }
예제 #3
0
 public override void VisitFunctionDecl(FunctionDecl decl, VisitKind visitKind)
 {
     if (visitKind == VisitKind.Enter && AttributeHelpers.FindObjcDeprecated(decl.Attrs, out VersionTuple version))
     {
         PlainCDeprecatedFunctions [decl.QualifiedName] = version;
     }
 }
예제 #4
0
 void VisitItem(NamedDecl decl, VisitKind visitKind)
 {
     if (visitKind == VisitKind.Enter && AttributeHelpers.FindObjcDeprecated(decl.Attrs, out VersionTuple version))
     {
         ObjCDeprecatedItems[decl.Name] = version;
     }
 }
예제 #5
0
 public override void VisitObjCMethodDecl(ObjCMethodDecl decl, VisitKind visitKind)
 {
     if (visitKind == VisitKind.Enter && AttributeHelpers.FindObjcDeprecated(decl.Attrs, out VersionTuple version))
     {
         ObjCDeprecatedSelectors[decl.QualifiedName] = version;
     }
 }
예제 #6
0
 public override void VisitObjCMethodDecl(ObjCMethodDecl decl, VisitKind visitKind)
 {
     if (visitKind == VisitKind.Enter && AttributeHelpers.FindObjcDeprecated(decl.Attrs, out VersionTuple version))
     {
         var qn = decl.QualifiedName;
         if (decl.IsClassMethod)
         {
             qn = "+" + qn;
         }
         ObjCDeprecatedSelectors [qn] = version;
     }
 }
예제 #7
0
 void VisitItem(NamedDecl decl, VisitKind visitKind)
 {
     if (visitKind == VisitKind.Enter && AttributeHelpers.FindObjcDeprecated(decl.Attrs, out VersionTuple version))
     {
         // `(anonymous)` has a null name
         var name = decl.Name;
         if (name is not null)
         {
             ObjCDeprecatedItems[name] = version;
         }
     }
 }
예제 #8
0
        public void ProcessItem(ICustomAttributeProvider item, string itemName, VersionTuple objcVersion, string framework)
        {
            // Our bindings do not need have [Deprecated] for ancicent versions we don't support anymore
            if (VersionHelpers.VersionTooOldToCare(objcVersion))
            {
                return;
            }

            // In some cases we've used [Advice] when entire types are deprecated
            // TODO - This is a hack, we shouldn't be doing ^
            if (AttributeHelpers.HasAnyAdvice(item))
            {
                return;
            }

            if (!AttributeHelpers.HasAnyDeprecationForCurrentPlatform(item))
            {
                Log.On(framework).Add($"!deprecated-attribute-missing! {itemName} missing a [Deprecated] attribute");
                return;
            }

            // Don't version check us when Apple does __attribute__((availability(macos, introduced=10.0, deprecated=100000)));
            // #define __API_TO_BE_DEPRECATED 100000
            if (objcVersion.Major == 100000)
            {
                return;
            }

            // Some APIs have both a [Deprecated] and [Obsoleted]. Bias towards [Obsoleted].
            Version managedVersion;
            bool    foundObsoleted = AttributeHelpers.FindObsolete(item, out managedVersion);

            if (foundObsoleted)
            {
                if (managedVersion != null && !ManagedBeforeOrEqualToObjcVersion(objcVersion, managedVersion))
                {
                    Log.On(framework).Add($"!deprecated-attribute-wrong! {itemName} has {managedVersion} not {objcVersion} on [Obsoleted] attribute");
                }
                return;
            }

            bool foundDeprecated = AttributeHelpers.FindDeprecated(item, out managedVersion);

            if (foundDeprecated && managedVersion != null && !ManagedBeforeOrEqualToObjcVersion(objcVersion, managedVersion))
            {
                Log.On(framework).Add($"!deprecated-attribute-wrong! {itemName} has {managedVersion} not {objcVersion} on [Deprecated] attribute");
            }
        }
예제 #9
0
        public static bool HasAnyObsoleted(ICustomAttributeProvider item)
        {
            if (Skip(item))
            {
                return(false);
            }

            foreach (var attribute in item.CustomAttributes)
            {
                if (AttributeHelpers.HasObsoleted(attribute, Helpers.Platform))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #10
0
        public override void VisitManagedType(TypeDefinition type)
        {
            // exclude non enum and nested enums, e.g. bunch of Selector enums in CTFont
            if (!type.IsEnum || type.IsNested)
            {
                return;
            }

            var name = type.Name;

            // exclude obsolete enums, presumably we already know there's something wrong with them if they've been obsoleted.
            if (type.IsObsolete())
            {
                obsoleted_enums [name] = type;
                return;
            }

            if (AttributeHelpers.HasAnyObsoleted(type))
            {
                obsoleted_enums [name] = type;
                return;
            }

            // e.g. WatchKit.WKErrorCode and WebKit.WKErrorCode :-(
            if (!enums.TryGetValue(name, out var td))
            {
                enums.Add(name, type);
            }
            else
            {
                var(t1, t2) = Helpers.Sort(type, td);
                if (t1.Namespace.StartsWith("OpenTK.", StringComparison.Ordinal))
                {
                    // OpenTK duplicate a lots of enums between it's versions
                }
                else if (t1.IsNotPublic && String.IsNullOrEmpty(t1.Namespace))
                {
                    // ignore special, non exposed types
                }
                else
                {
                    var framework = Helpers.GetFramework(t1);
                    Log.On(framework).Add($"!duplicate-type-name! {name} enum exists as both {t1.FullName} and {t2.FullName}");
                }
            }
        }
예제 #11
0
        public static bool HasAnyDeprecationForCurrentPlatform(ICustomAttributeProvider item)
        {
            if (Skip(item))
            {
                return(false);
            }

            // This allows us to accept [Deprecated (iOS)] for watch and tv, which many of our bindings currently have
            // If we want to force seperate tv\watch attributes remove GetRelatedPlatforms and just check Helpers.Platform
            Platforms[] platforms = GetRelatedPlatforms();
            foreach (var attribute in item.CustomAttributes)
            {
                if (platforms.Any(x => AttributeHelpers.HasDeprecated(attribute, x)) || platforms.Any(x => AttributeHelpers.HasObsoleted(attribute, x)))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #12
0
        void ProcessCFunction(string fullname, VersionTuple objcVersion)
        {
            if (dllimports.TryGetValue(fullname, out var method))
            {
                var dt        = method.DeclaringType;
                var framework = Helpers.GetFramework(dt);
                if (framework == null)
                {
                    return;
                }

                // If the entire type is deprecated, call it good enough
                if (AttributeHelpers.HasAnyDeprecationForCurrentPlatform(dt))
                {
                    return;
                }

                ProcessItem(method, fullname, objcVersion, framework);
            }
        }
예제 #13
0
        public static bool HasAnyDeprecationForCurrentPlatform(ICustomAttributeProvider item)
        {
            if (Skip(item))
            {
                return(false);
            }

            // This allows us to accept [Deprecated (iOS)] for watch and tv, which many of our bindings currently have
            // If we want to force seperate tv\watch attributes remove GetRelatedPlatforms and just check Helpers.Platform
            if (Helpers.IsDotNet)
            {
                foreach (var attribute in item.CustomAttributes)
                {
                    if (AttributeHelpers.HasObsolete(attribute, Helpers.Platform))
                    {
                        return(true);
                    }
                    // The only related platforms for .NET is iOS for Mac Catalyst
                    if (AttributeHelpers.HasUnsupportedOSPlatform(attribute, Helpers.Platform))
                    {
                        return(true);
                    }
                    if (Helpers.Platform == Platforms.MacCatalyst && AttributeHelpers.HasUnsupportedOSPlatform(attribute, Platforms.iOS))
                    {
                        return(true);
                    }
                }
            }
            else
            {
                Platforms [] platforms = GetRelatedPlatforms();
                foreach (var attribute in item.CustomAttributes)
                {
                    if (platforms.Any(x => AttributeHelpers.HasDeprecated(attribute, x)) || platforms.Any(x => AttributeHelpers.HasObsoleted(attribute, x)))
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }