private IEnumerable <MethodDesc> ComputeAllVirtualMethodsForInstantiatedType(InstantiatedType instantiatedType)
 {
     foreach (var typicalMethod in _virtualMethodLists.GetOrCreateValue(instantiatedType.GetTypeDefinition()).Item2)
     {
         yield return(instantiatedType.Context.GetMethodForInstantiatedType(typicalMethod, instantiatedType));
     }
 }
        /// <summary>
        /// Instantiated type computation for runtime interfaces. Instantiated types
        /// must have the same count of interfaces across all possible instantiations
        /// so the algorithm works by computing the uninstantiated form, and then
        /// specializing each interface as needed.
        /// </summary>
        private DefType[] ComputeRuntimeInterfacesForInstantiatedType(InstantiatedType instantiatedType)
        {
            MetadataType uninstantiatedType = (MetadataType)instantiatedType.GetTypeDefinition();

            DefType[] genericTypeDefinitionInterfaces = uninstantiatedType.RuntimeInterfaces;

            return InstantiatedType.InstantiateTypeArray(uninstantiatedType.RuntimeInterfaces, instantiatedType.Instantiation, new Instantiation());
        }
        /// <summary>
        /// Instantiated type computation for runtime interfaces. Instantiated types
        /// must have the same count of interfaces across all possible instantiations
        /// so the algorithm works by computing the uninstantiated form, and then
        /// specializing each interface as needed.
        /// </summary>
        private DefType[] ComputeRuntimeInterfacesForInstantiatedType(InstantiatedType instantiatedType)
        {
            MetadataType uninstantiatedType = (MetadataType)instantiatedType.GetTypeDefinition();

            DefType[] genericTypeDefinitionInterfaces = uninstantiatedType.RuntimeInterfaces;

            return(InstantiatedType.InstantiateTypeArray(uninstantiatedType.RuntimeInterfaces, instantiatedType.Instantiation, new Instantiation()));
        }
Пример #4
0
        private void InitializeTypeInstance(Cts.InstantiatedType entity, TypeSpecification record)
        {
            var sig = new TypeInstantiationSignature
            {
                GenericType = HandleType(entity.GetTypeDefinition()),
            };

            for (int i = 0; i < entity.Instantiation.Length; i++)
            {
                sig.GenericTypeArguments.Add(HandleType(entity.Instantiation[i]));
            }

            record.Signature = sig;
        }
Пример #5
0
        private void InitializeTypeInstance(Cts.InstantiatedType entity, TypeSpecification record)
        {
            var args = new List <MetadataRecord>(entity.Instantiation.Length);

            for (int i = 0; i < entity.Instantiation.Length; i++)
            {
                args.Add(HandleType(entity.Instantiation[i]));
            }

            record.Signature = new TypeInstantiationSignature
            {
                GenericType          = HandleType(entity.GetTypeDefinition()),
                GenericTypeArguments = args
            };
        }
Пример #6
0
        /// <summary>
        /// Resolve a virtual function call (to a virtual method, not an interface method)
        /// </summary>
        /// <param name="targetMethod"></param>
        /// <param name="objectType"></param>
        /// <returns>The override of the virtual method that should be called</returns>
        private static MethodDesc FindVirtualFunctionTargetMethodOnObjectType(MethodDesc targetMethod, MetadataType objectType)
        {
            // Step 1, convert objectType to uninstantiated form
            MetadataType     uninstantiatedType      = objectType;
            MethodDesc       initialTargetMethod     = targetMethod;
            InstantiatedType initialInstantiatedType = objectType as InstantiatedType;

            if (initialInstantiatedType != null)
            {
                uninstantiatedType = (MetadataType)initialInstantiatedType.GetTypeDefinition();
            }

            // Step 2, convert targetMethod to method in type hierarchy of uninstantiated form
            targetMethod = targetMethod.GetMethodDefinition();
            if (uninstantiatedType != objectType)
            {
                targetMethod = uninstantiatedType.FindMethodOnTypeWithMatchingTypicalMethod(targetMethod);
            }

            // Step 3, find unification group of target method
            UnificationGroup group = new UnificationGroup(FindSlotDefiningMethodForVirtualMethod(targetMethod));

            FindBaseUnificationGroup(uninstantiatedType, group);

            // Step 4, name/sig match virtual function resolve
            MethodDesc resolutionTarget = FindNameSigOverrideForVirtualMethod(group.DefiningMethod, uninstantiatedType);

            if (resolutionTarget == null)
            {
                return(null);
            }

            // Step 5, convert resolution target from uninstantiated form target to objecttype target,
            // and instantiate as appropriate
            if (uninstantiatedType != objectType)
            {
                resolutionTarget = objectType.FindMethodOnTypeWithMatchingTypicalMethod(resolutionTarget);
            }
            if (initialTargetMethod.HasInstantiation)
            {
                resolutionTarget = resolutionTarget.MakeInstantiatedMethod(initialTargetMethod.Instantiation);
            }

            return(resolutionTarget);
        }