コード例 #1
0
ファイル: RdXmlRootProvider.cs プロジェクト: yaram/corert
        private void RootMethod(IRootingServiceProvider rootProvider, MethodDesc method)
        {
            try
            {
                LibraryRootProvider.CheckCanGenerateMethod(method);

                // Virtual methods should be rooted as if they were called virtually
                if (method.IsVirtual)
                {
                    MethodDesc slotMethod = MetadataVirtualMethodAlgorithm.FindSlotDefiningMethodForVirtualMethod(method);
                    rootProvider.RootVirtualMethodForReflection(slotMethod, "RD.XML root");
                }

                if (!method.IsAbstract)
                {
                    rootProvider.AddCompilationRoot(method, "RD.XML root");
                }
            }
            catch (TypeSystemException)
            {
                // TODO: fail compilation if a switch was passed

                // Individual methods can fail to load types referenced in their signatures.
                // Skip them in library mode since they're not going to be callable.
                return;

                // TODO: Log as a warning
            }
        }
コード例 #2
0
        public static void RootMethod(IRootingServiceProvider rootProvider, MethodDesc method, string reason)
        {
            // Make sure we're not putting something into the graph that will crash later.
            LibraryRootProvider.CheckCanGenerateMethod(method);

            rootProvider.AddReflectionRoot(method, reason);
        }
コード例 #3
0
        private void RootType(IRootingServiceProvider rootProvider, TypeDesc type)
        {
            rootProvider.AddCompilationRoot(type, "RD.XML root");

            if (type.IsGenericDefinition)
            {
                return;
            }

            if (type.IsDefType)
            {
                foreach (var method in type.GetMethods())
                {
                    // We don't know what to instantiate generic methods over
                    if (method.HasInstantiation)
                    {
                        continue;
                    }

                    try
                    {
                        LibraryRootProvider.CheckCanGenerateMethod(method);

                        // Virtual methods should be rooted as if they were called virtually
                        if (method.IsVirtual)
                        {
                            MethodDesc slotMethod = MetadataVirtualMethodAlgorithm.FindSlotDefiningMethodForVirtualMethod(method);
                            rootProvider.RootVirtualMethodForReflection(slotMethod, "RD.XML root");
                        }

                        if (!method.IsAbstract)
                        {
                            rootProvider.AddCompilationRoot(method, "RD.XML root");
                        }
                    }
                    catch (TypeSystemException)
                    {
                        // TODO: fail compilation if a switch was passed

                        // Individual methods can fail to load types referenced in their signatures.
                        // Skip them in library mode since they're not going to be callable.
                        continue;

                        // TODO: Log as a warning
                    }
                }
            }
        }
コード例 #4
0
        public static void RootMethod(IRootingServiceProvider rootProvider, MethodDesc method, string reason)
        {
            // Make sure we're not putting something into the graph that will crash later.
            LibraryRootProvider.CheckCanGenerateMethod(method);

            // Virtual methods should be rooted as if they were called virtually
            if (method.IsVirtual)
            {
                rootProvider.RootVirtualMethodForReflection(method, reason);
            }

            if (!method.IsAbstract)
            {
                rootProvider.AddCompilationRoot(method, reason);
            }
        }
コード例 #5
0
        public static bool TryGetDependenciesForReflectedMethod(ref DependencyList dependencies, NodeFactory factory, MethodDesc method, string reason)
        {
            MethodDesc typicalMethod = method.GetTypicalMethodDefinition();

            if (factory.MetadataManager.IsReflectionBlocked(typicalMethod))
            {
                return(false);
            }

            // If this is a generic method, make sure we at minimum have the metadata
            // for it. This hedges against the risk that we fail to figure out a code body
            // for it below.
            if (typicalMethod.IsGenericMethodDefinition || typicalMethod.OwningType.IsGenericDefinition)
            {
                dependencies ??= new DependencyList();
                dependencies.Add(factory.ReflectableMethod(typicalMethod), reason);
            }

            // If there's any genericness involved, try to create a fitting instantiation that would be usable at runtime.
            // This is not a complete solution to the problem.
            // If we ever decide that MakeGenericType/MakeGenericMethod should simply be considered unsafe, this code can be deleted
            // and instantiations that are not fully closed can be ignored.
            if (method.OwningType.IsGenericDefinition || method.OwningType.ContainsSignatureVariables(treatGenericParameterLikeSignatureVariable: true))
            {
                TypeDesc      owningType = method.OwningType.GetTypeDefinition();
                Instantiation inst       = TypeExtensions.GetInstantiationThatMeetsConstraints(owningType.Instantiation, allowCanon: false);
                if (inst.IsNull)
                {
                    return(false);
                }

                method = method.Context.GetMethodForInstantiatedType(
                    method.GetTypicalMethodDefinition(),
                    ((MetadataType)owningType).MakeInstantiatedType(inst));
            }

            if (method.IsGenericMethodDefinition || method.Instantiation.ContainsSignatureVariables())
            {
                method = method.GetMethodDefinition();

                Instantiation inst = TypeExtensions.GetInstantiationThatMeetsConstraints(method.Instantiation, allowCanon: false);
                if (inst.IsNull)
                {
                    return(false);
                }

                method = method.MakeInstantiatedMethod(inst);
            }

            try
            {
                // Make sure we're not putting something into the graph that will crash later.
                LibraryRootProvider.CheckCanGenerateMethod(method);
            }
            catch (TypeSystemException)
            {
                return(false);
            }

            dependencies ??= new DependencyList();
            dependencies.Add(factory.ReflectableMethod(method), reason);

            return(true);
        }