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];
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        // 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"));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
 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);
         }
     }
 }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
 public static bool IsNSObject(this TypeReference type, DerivedLinkContext link_context)
 {
     return(type.Resolve().IsNSObject(link_context));
 }
Ejemplo n.º 12
0
 static bool HasGeneratedCodeAttribute(ICustomAttributeProvider provider, DerivedLinkContext context)
 {
     return(provider.HasCustomAttribute(context, "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"));
 }
Ejemplo n.º 13
0
        // 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);
        }
Ejemplo n.º 14
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")));
        }