Esempio n. 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);
                }
            }
        }
Esempio n. 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);
                }
            }
        }
Esempio n. 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;
     }
 }
Esempio n. 4
0
 void VisitItem(NamedDecl decl, VisitKind visitKind)
 {
     if (visitKind == VisitKind.Enter && AttributeHelpers.FindObjcDeprecated(decl.Attrs, out VersionTuple version))
     {
         ObjCDeprecatedItems[decl.Name] = version;
     }
 }
Esempio n. 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;
     }
 }
Esempio n. 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;
     }
 }
Esempio n. 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;
         }
     }
 }
Esempio n. 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");
            }
        }
Esempio n. 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);
        }
Esempio n. 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}");
                }
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
        }