LinkerConfiguration(string linker_file)
        {
            if (!File.Exists(linker_file))
            {
                throw new FileNotFoundException($"The custom linker file {linker_file} does not exist.");
            }

            Profile            = new BaseProfile(this);
            DerivedLinkContext = new DerivedLinkContext {
                LinkerConfiguration = this,
            };
            Application   = new Application(this);
            Target        = new Target(Application);
            CompilerFlags = new CompilerFlags(Target);

            var lines            = File.ReadAllLines(linker_file);
            var significantLines = new List <string> ();            // This is the input the cache uses to verify if the cache is still valid

            for (var i = 0; i < lines.Length; i++)
            {
                var line = lines [i].TrimStart();
                if (line.Length == 0 || line [0] == '#')
                {
                    continue;                     // Allow comments
                }
                var eq = line.IndexOf('=');
                if (eq == -1)
                {
                    throw new InvalidOperationException($"Invalid syntax for line {i + 1} in {linker_file}: No equals sign.");
                }

                significantLines.Add(line);

                var key   = line [..eq];
Beispiel #2
0
        // type has a "public .ctor (IntPtr)" with a [CompilerGenerated] attribute
        static bool IsGeneratedBindings(TypeDefinition type, DerivedLinkContext link_context)
        {
            if (type.IsNested)
            {
                return(IsGeneratedBindings(type.DeclaringType, link_context));
            }

            if (!type.HasMethods)
            {
                return(false);
            }

            foreach (MethodDefinition m in type.Methods)
            {
                if (!m.IsConstructor)
                {
                    continue;
                }
                if (!m.HasParameters)
                {
                    continue;
                }
                if (m.Parameters.Count != 1)
                {
                    continue;
                }
                if (!m.Parameters [0].ParameterType.Is("System", "IntPtr"))
                {
                    continue;
                }
                return(m.IsGeneratedCode(link_context));
            }
            return(false);
        }
        // warning: *Is* means does 'type' inherits from MonoTouch.Foundation.NSObject ?
        public static bool IsNSObject(this TypeDefinition type, DerivedLinkContext link_context)
        {
            if (link_context?.CachedIsNSObject != null)
            {
                return(link_context.CachedIsNSObject.Contains(type));
            }

            return(type.Inherits(Namespaces.Foundation, "NSObject"));
        }
Beispiel #4
0
        public static bool IsDirectBindingCheckRequired(this TypeDefinition type, DerivedLinkContext link_context)
        {
            if (link_context.NeedsIsDirectBindingCheck == null)
            {
                return(true);
            }

            return(link_context.NeedsIsDirectBindingCheck.Contains(type));
        }
        public static bool IsNSObject(this TypeReference type, DerivedLinkContext link_context)
        {
            return
                (#if NET
                 link_context.LinkerConfiguration.Context.Resolve(type)
#else
                 type.Resolve()
#endif
                 .IsNSObject(link_context));
        }
 public static bool IsGeneratedCode(this MethodDefinition self, DerivedLinkContext link_context)
 {
     // check the property too
     if (self.IsGetter || self.IsSetter)
     {
         if (HasGeneratedCodeAttribute(GetPropertyByAccessor(self), link_context))
         {
             return(true);
         }
     }
     return(HasGeneratedCodeAttribute(self, link_context));
 }
 void ProcessType(TypeDefinition type, DerivedLinkContext context)
 {
     if (type.IsNSObject(context))
     {
         ProcessNSObject(type);
     }
     else if (type.HasNestedTypes)
     {
         foreach (var nested in type.NestedTypes)
         {
             ProcessType(nested, context);
         }
     }
 }
        public static bool IsOptimizableCode(this MethodDefinition self, DerivedLinkContext link_context)
        {
            if (IsBindingImplOptimizableCode(self, link_context))
            {
                return(true);
            }

            if (!Driver.IsXAMCORE_4_0 && IsGeneratedCode(self, link_context))
            {
                return(true);
            }

            return(false);
        }
Beispiel #9
0
        public static bool?GetIsDirectBindingConstant(this TypeDefinition type, DerivedLinkContext link_context)
        {
            if (link_context?.IsDirectBindingValue == null)
            {
                return(null);
            }

            bool?value;

            if (link_context.IsDirectBindingValue.TryGetValue(type, out value))
            {
                return(value);
            }

            return(null);
        }
        public static bool IsBindingImplOptimizableCode(this MethodDefinition self, DerivedLinkContext link_context)
        {
            var attrib = GetBindingImplAttribute(self, link_context);

            if ((attrib & BindingImplOptions.Optimizable) == BindingImplOptions.Optimizable)
            {
                return(true);
            }

            // Check the property too
            if (self.IsGetter || self.IsSetter)
            {
                attrib = GetBindingImplAttribute(GetPropertyByAccessor(self), link_context);
                if ((attrib & BindingImplOptions.Optimizable) == BindingImplOptions.Optimizable)
                {
                    return(true);
                }
            }

            return(false);
        }
 public static bool IsNSObject(this TypeReference type, DerivedLinkContext link_context)
 {
     return(type.Resolve().IsNSObject(link_context));
 }
 static bool HasGeneratedCodeAttribute(ICustomAttributeProvider provider, DerivedLinkContext context)
 {
     return(provider.HasCustomAttribute(context, "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"));
 }
        // This method will look in any stored attributes in the link context as well as the provider itself.
        public static bool HasCustomAttribute(this ICustomAttributeProvider provider, DerivedLinkContext context, string @namespace, string name)
        {
            if (provider?.HasCustomAttribute(@namespace, name) == true)
            {
                return(true);
            }

            return(context?.GetCustomAttributes(provider, @namespace, name)?.Count > 0);
        }
        static BindingImplOptions?GetBindingImplAttribute(ICustomAttributeProvider provider, DerivedLinkContext context)
        {
            if (provider != null && provider.HasCustomAttributes)
            {
                var rv = GetBindingImplAttribute(provider, provider.CustomAttributes);
                if (rv != null)
                {
                    return(rv);
                }
            }

            return(GetBindingImplAttribute(provider, context?.GetCustomAttributes(provider, Namespaces.ObjCRuntime, "BindingImplAttribute")));
        }